示例#1
0
 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', '');
     } 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');
     } 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();
         $shippingTaxes = $parentRecordModel->getShippingTaxes();
         $relatedProducts = $parentRecordModel->getProducts();
         $recordModel = Vtiger_Record_Model::getCleanInstance($moduleName);
         $recordModel->setRecordFieldValues($parentRecordModel);
     } 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));
         }
     }
     $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));
     $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');
 }
示例#2
0
文件: Edit.php 项目: Wasage/werpa
 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');
 }