function process(Vtiger_Request $request) { $recordId = $request->get('record'); $idList = $request->get('idlist'); $currencyId = $request->get('currency_id'); $currencies = Inventory_Module_Model::getAllCurrencies(); $conversionRate = 1; $response = new Vtiger_Response(); if (empty($idList)) { $recordModel = Vtiger_Record_Model::getInstanceById($recordId); $taxes = $recordModel->getTaxes(); $listPriceValues = $recordModel->getListPriceValues($recordModel->getId()); $priceDetails = $recordModel->getPriceDetails(); foreach ($priceDetails as $currencyDetails) { if ($currencyId == $currencyDetails['curid']) { $conversionRate = $currencyDetails['conversionrate']; } } $listPrice = (double) $recordModel->get('unit_price') * (double) $conversionRate; if ($recordModel->has('usageunit')) { $usageUnit = vtranslate($recordModel->get('usageunit'), 'Products'); } else { $usageUnit = vtranslate($recordModel->get('service_usageunit'), 'Services'); } $response->setResult(array($recordId => array('id' => $recordId, 'name' => decode_html($recordModel->getName()), 'taxes' => $taxes, 'listprice' => $listPrice, 'listpricevalues' => $listPriceValues, 'description' => decode_html($recordModel->get('description')), 'quantityInStock' => $recordModel->get('qtyinstock'), 'usageunit' => $usageUnit))); } else { foreach ($idList as $id) { $recordModel = Vtiger_Record_Model::getInstanceById($id); $taxes = $recordModel->getTaxes(); $listPriceValues = $recordModel->getListPriceValues($recordModel->getId()); $priceDetails = $recordModel->getPriceDetails(); foreach ($priceDetails as $currencyDetails) { if ($currencyId == $currencyDetails['curid']) { $conversionRate = $currencyDetails['conversionrate']; } } $listPrice = (double) $recordModel->get('unit_price') * (double) $conversionRate; if ($recordModel->has('usageunit')) { $usageUnit = vtranslate($recordModel->get('usageunit'), 'Products'); } else { $usageUnit = vtranslate($recordModel->get('service_usageunit'), 'Services'); } $info[] = array($id => array('id' => $id, 'name' => decode_html($recordModel->getName()), 'taxes' => $taxes, 'listprice' => $listPrice, 'listpricevalues' => $listPriceValues, 'description' => decode_html($recordModel->get('description')), 'quantityInStock' => $recordModel->get('qtyinstock'), 'usageunit' => $usageUnit)); } $response->setResult($info); } $response->emit(); }
public function process(Vtiger_Request $request) { $viewer = $this->getViewer($request); $moduleName = $request->getModule(); $record = $request->get('record'); $sourceRecord = $request->get('sourceRecord'); $sourceModule = $request->get('sourceModule'); if (!empty($record) && $request->get('isDuplicate') == true) { $recordModel = Inventory_Record_Model::getInstanceById($record, $moduleName); $currencyInfo = $recordModel->getCurrencyInfo(); $taxes = $recordModel->getProductTaxes(); $relatedProducts = $recordModel->getProducts(); $viewer->assign('MODE', ''); //While Duplicating record, If the related record is deleted then we are removing related record info in record model $mandatoryFieldModels = $recordModel->getModule()->getMandatoryFieldModels(); foreach ($mandatoryFieldModels as $fieldModel) { if ($fieldModel->isReferenceField()) { $fieldName = $fieldModel->get('name'); if (Vtiger_Util_Helper::checkRecordExistance($recordModel->get($fieldName))) { $recordModel->set($fieldName, ''); } } } } elseif (!empty($record)) { $recordModel = Inventory_Record_Model::getInstanceById($record, $moduleName); $currencyInfo = $recordModel->getCurrencyInfo(); $taxes = $recordModel->getProductTaxes(); $relatedProducts = $recordModel->getProducts(); $viewer->assign('RECORD_ID', $record); $viewer->assign('MODE', 'edit'); } elseif ($request->get('salesorder_id') || $request->get('quote_id')) { if ($request->get('salesorder_id')) { $referenceId = $request->get('salesorder_id'); } else { $referenceId = $request->get('quote_id'); } $parentRecordModel = Inventory_Record_Model::getInstanceById($referenceId); $currencyInfo = $parentRecordModel->getCurrencyInfo(); $taxes = $parentRecordModel->getProductTaxes(); $relatedProducts = $parentRecordModel->getProducts(); $recordModel = Vtiger_Record_Model::getCleanInstance($moduleName); $recordModel->setRecordFieldValues($parentRecordModel); } else { $taxes = Inventory_Module_Model::getAllProductTaxes(); $recordModel = Vtiger_Record_Model::getCleanInstance($moduleName); $viewer->assign('MODE', ''); //The creation of Inventory record from action and Related list of product/service detailview the product/service details will calculated by following code if ($request->get('product_id') || $sourceModule === 'Products') { if ($sourceRecord) { $productRecordModel = Products_Record_Model::getInstanceById($sourceRecord); } else { $productRecordModel = Products_Record_Model::getInstanceById($request->get('product_id')); } $relatedProducts = $productRecordModel->getDetailsForInventoryModule($recordModel); } elseif ($request->get('service_id') || $sourceModule === 'Services') { if ($sourceRecord) { $serviceRecordModel = Services_Record_Model::getInstanceById($sourceRecord); } else { $serviceRecordModel = Services_Record_Model::getInstanceById($request->get('service_id')); } $relatedProducts = $serviceRecordModel->getDetailsForInventoryModule($recordModel); } elseif ($sourceRecord && ($sourceModule === 'Accounts' || $sourceModule === 'Contacts' || $sourceModule === 'Potentials' || $sourceModule === 'Vendors' && $moduleName === 'PurchaseOrder')) { $parentRecordModel = Vtiger_Record_Model::getInstanceById($sourceRecord, $sourceModule); $recordModel->setParentRecordData($parentRecordModel); } } $moduleModel = $recordModel->getModule(); $fieldList = $moduleModel->getFields(); $requestFieldList = array_intersect_key($request->getAll(), $fieldList); //get the inventory terms and conditions $inventoryRecordModel = Inventory_Record_Model::getCleanInstance($moduleName); $termsAndConditions = $inventoryRecordModel->getInventoryTermsandConditions(); foreach ($requestFieldList as $fieldName => $fieldValue) { $fieldModel = $fieldList[$fieldName]; if ($fieldModel->isEditable()) { $recordModel->set($fieldName, $fieldModel->getDBInsertValue($fieldValue)); } } $recordStructureInstance = Vtiger_RecordStructure_Model::getInstanceFromRecordModel($recordModel, Vtiger_RecordStructure_Model::RECORD_STRUCTURE_MODE_EDIT); $viewer->assign('VIEW_MODE', "fullForm"); $isRelationOperation = $request->get('relationOperation'); //if it is relation edit $viewer->assign('IS_RELATION_OPERATION', $isRelationOperation); if ($isRelationOperation) { $viewer->assign('SOURCE_MODULE', $sourceModule); $viewer->assign('SOURCE_RECORD', $sourceRecord); } if (!empty($record) && $request->get('isDuplicate') == true) { $viewer->assign('IS_DUPLICATE', true); } else { $viewer->assign('IS_DUPLICATE', false); } $currencies = Inventory_Module_Model::getAllCurrencies(); $picklistDependencyDatasource = Vtiger_DependencyPicklist::getPicklistDependencyDatasource($moduleName); $viewer->assign('PICKIST_DEPENDENCY_DATASOURCE', Zend_Json::encode($picklistDependencyDatasource)); $mappingRelatedField = $moduleModel->getMappingRelatedField($moduleName); $viewer->assign('MAPPING_RELATED_FIELD', Zend_Json::encode($mappingRelatedField)); $viewer->assign('RECORD', $recordModel); $viewer->assign('RECORD_STRUCTURE_MODEL', $recordStructureInstance); $viewer->assign('RECORD_STRUCTURE', $recordStructureInstance->getStructure()); $viewer->assign('MODULE', $moduleName); $viewer->assign('BLOCK_LIST', $moduleModel->getBlocks()); $viewer->assign('CURRENTDATE', date('Y-n-j')); $viewer->assign('USER_MODEL', Users_Record_Model::getCurrentUserModel()); $viewer->assign('RELATED_PRODUCTS', $relatedProducts); $viewer->assign('TAXES', $taxes); $viewer->assign('CURRENCINFO', $currencyInfo); $viewer->assign('CURRENCIES', $currencies); $viewer->assign('TERMSANDCONDITIONS', $termsAndConditions); $productModuleModel = Vtiger_Module_Model::getInstance('Products'); $viewer->assign('PRODUCT_ACTIVE', $productModuleModel->isActive()); $serviceModuleModel = Vtiger_Module_Model::getInstance('Services'); $viewer->assign('SERVICE_ACTIVE', $serviceModuleModel->isActive()); $viewer->assign('APIADDRESS', Settings_ApiAddress_Module_Model::getInstance('Settings:ApiAddress')->getConfig(false)); $viewer->view('EditView.tpl', 'Inventory'); }
public function process(Vtiger_Request $request) { $viewer = $this->getViewer($request); $moduleName = $request->getModule(); $record = $request->get('record'); $sourceRecord = $request->get('sourceRecord'); $sourceModule = $request->get('sourceModule'); if (!empty($record) && $request->get('isDuplicate') == true) { $recordModel = Inventory_Record_Model::getInstanceById($record, $moduleName); $currencyInfo = $recordModel->getCurrencyInfo(); $taxes = $recordModel->getProductTaxes(); $shippingTaxes = $recordModel->getShippingTaxes(); $relatedProducts = $recordModel->getProducts(); $viewer->assign('MODE', ''); //While Duplicating record, If the related record is deleted then we are removing related record info in record model $mandatoryFieldModels = $recordModel->getModule()->getMandatoryFieldModels(); foreach ($mandatoryFieldModels as $fieldModel) { if ($fieldModel->isReferenceField()) { $fieldName = $fieldModel->get('name'); if (Vtiger_Util_Helper::checkRecordExistance($recordModel->get($fieldName))) { $recordModel->set($fieldName, ''); } } } } elseif (!empty($record)) { $recordModel = Inventory_Record_Model::getInstanceById($record, $moduleName); $currencyInfo = $recordModel->getCurrencyInfo(); $taxes = $recordModel->getProductTaxes(); $shippingTaxes = $recordModel->getShippingTaxes(); $relatedProducts = $recordModel->getProducts(); $viewer->assign('RECORD_ID', $record); $viewer->assign('MODE', 'edit'); // SalesPlatform.ru begin Relation between Invoice & Consignment } elseif ($request->get('salesorder_id') || $request->get('quote_id') || $request->get('invoice_id')) { //} elseif ($request->get('salesorder_id') || $request->get('quote_id') || $request->get('invoice_id')) { // SalesPlatform.ru end if ($request->get('salesorder_id')) { $referenceId = $request->get('salesorder_id'); // SalesPlatform.ru begin Relation between Invoice & Consignment } elseif ($request->get('invoice_id')) { $referenceId = $request->get('invoice_id'); // SalesPlatform.ru end } else { $referenceId = $request->get('quote_id'); } $parentRecordModel = Inventory_Record_Model::getInstanceById($referenceId); $currencyInfo = $parentRecordModel->getCurrencyInfo(); $taxes = $parentRecordModel->getProductTaxes(); $shippingTaxes = $parentRecordModel->getShippingTaxes(); $relatedProducts = $parentRecordModel->getProducts(); $recordModel = Vtiger_Record_Model::getCleanInstance($moduleName); $recordModel->setRecordFieldValues($parentRecordModel); /** EventHandler START */ $recordModel = EventHandler_Module_Model::do_filter('vtiger.filter.' . strtolower($moduleName) . '.convert', $recordModel, $parentRecordModel); /** EventHandler ENDE */ } else { $taxes = Inventory_Module_Model::getAllProductTaxes(); $shippingTaxes = Inventory_Module_Model::getAllShippingTaxes(); $recordModel = Vtiger_Record_Model::getCleanInstance($moduleName); $viewer->assign('MODE', ''); //The creation of Inventory record from action and Related list of product/service detailview the product/service details will calculated by following code if ($request->get('product_id') || $sourceModule === 'Products') { if ($sourceRecord) { $productRecordModel = Products_Record_Model::getInstanceById($sourceRecord); } else { $productRecordModel = Products_Record_Model::getInstanceById($request->get('product_id')); } $relatedProducts = $productRecordModel->getDetailsForInventoryModule($recordModel); } elseif ($request->get('service_id') || $sourceModule === 'Services') { if ($sourceRecord) { $serviceRecordModel = Services_Record_Model::getInstanceById($sourceRecord); } else { $serviceRecordModel = Services_Record_Model::getInstanceById($request->get('service_id')); } $relatedProducts = $serviceRecordModel->getDetailsForInventoryModule($recordModel); } elseif ($sourceRecord && ($sourceModule === 'Accounts' || $sourceModule === 'Contacts' || $sourceModule === 'Potentials' || $sourceModule === 'Vendors' && $moduleName === 'PurchaseOrder')) { $parentRecordModel = Vtiger_Record_Model::getInstanceById($sourceRecord, $sourceModule); $recordModel->setParentRecordData($parentRecordModel); } } $moduleModel = $recordModel->getModule(); $fieldList = $moduleModel->getFields(); $requestFieldList = array_intersect_key($request->getAll(), $fieldList); //get the inventory terms and conditions $inventoryRecordModel = Inventory_Record_Model::getCleanInstance($moduleName); $termsAndConditions = $inventoryRecordModel->getInventoryTermsandConditions(); foreach ($requestFieldList as $fieldName => $fieldValue) { $fieldModel = $fieldList[$fieldName]; if ($fieldModel->isEditable()) { $recordModel->set($fieldName, $fieldModel->getDBInsertValue($fieldValue)); } } // SalesPlatform.ru begin Set default invoice status for SalesOrder if ($moduleName == "SalesOrder") { if (empty($record)) { $recordModel->set("invoicestatus", "AutoCreated"); } else { $checkbox = $recordModel->get("enable_recurring"); if ($checkbox != 1) { $recordModel->set("invoicestatus", "AutoCreated"); } } } // SalesPlatform.ru end // SalesPlatform.ru begin Unifying method for EditView preparing $recordModel = prepareEditView($recordModel, $_REQUEST, $viewer); // SalesPlatform.ru end $recordStructureInstance = Vtiger_RecordStructure_Model::getInstanceFromRecordModel($recordModel, Vtiger_RecordStructure_Model::RECORD_STRUCTURE_MODE_EDIT); // SalesPlatform.ru begin Field Validation Information $tabid = getTabid($moduleName); $validationData = getDBValidationData($recordModel->get('tab_name'), $tabid); $validationArray = split_validationdataArray($validationData); $viewer->assign("VALIDATION_DATA_FIELDNAME", $validationArray['fieldname']); $viewer->assign("VALIDATION_DATA_FIELDDATATYPE", $validationArray['datatype']); $viewer->assign("VALIDATION_DATA_FIELDLABEL", $validationArray['fieldlabel']); $viewer->assign('ID', $record); // SalesPlatform.ru end $viewer->assign('VIEW_MODE', "fullForm"); $isRelationOperation = $request->get('relationOperation'); //if it is relation edit //SalesPlatform.ru begin add relation create for Act from Invoice $isFromInvoiceCreate = $request->get('convertFromInvoice'); $viewer->assign('IS_FROM_INVOICE_CREATE', $isFromInvoiceCreate); //SalesPlatform.ru end $viewer->assign('IS_RELATION_OPERATION', $isRelationOperation); //SalesPlatform.ru begin add relation create for Act from Invoice if ($isRelationOperation || $isFromInvoiceCreate) { //if($isRelationOperation) //SalesPlatform.ru end $viewer->assign('SOURCE_MODULE', $sourceModule); $viewer->assign('SOURCE_RECORD', $sourceRecord); } if (!empty($record) && $request->get('isDuplicate') == true) { $viewer->assign('IS_DUPLICATE', true); } else { $viewer->assign('IS_DUPLICATE', false); } $currencies = Inventory_Module_Model::getAllCurrencies(); $picklistDependencyDatasource = Vtiger_DependencyPicklist::getPicklistDependencyDatasource($moduleName); $viewer->assign('PICKIST_DEPENDENCY_DATASOURCE', Zend_Json::encode($picklistDependencyDatasource)); $viewer->assign('RECORD', $recordModel); $viewer->assign('RECORD_STRUCTURE_MODEL', $recordStructureInstance); $viewer->assign('RECORD_STRUCTURE', $recordStructureInstance->getStructure()); $viewer->assign('MODULE', $moduleName); $viewer->assign('CURRENTDATE', date('Y-n-j')); $viewer->assign('USER_MODEL', Users_Record_Model::getCurrentUserModel()); $viewer->assign('RELATED_PRODUCTS', $relatedProducts); $viewer->assign('SHIPPING_TAXES', $shippingTaxes); $viewer->assign('TAXES', $taxes); $viewer->assign('CURRENCINFO', $currencyInfo); $viewer->assign('CURRENCIES', $currencies); $viewer->assign('TERMSANDCONDITIONS', $termsAndConditions); $productModuleModel = Vtiger_Module_Model::getInstance('Products'); $viewer->assign('PRODUCT_ACTIVE', $productModuleModel->isActive()); $serviceModuleModel = Vtiger_Module_Model::getInstance('Services'); $viewer->assign('SERVICE_ACTIVE', $serviceModuleModel->isActive()); $viewer->view('EditView.tpl', 'Inventory'); }
public function getSettingLinks() { $settingsLinks = parent::getSettingLinks(); $settingsLinks[] = array('linktype' => 'LISTVIEWSETTING', 'linklabel' => 'LBL_MODULE_CONFIGURATION', 'linkurl' => 'index.php?module=OSSCosts&parent=Settings&view=index', 'linkicon' => ''); return $settingsLinks; }