function showTaxes(Vtiger_Request $request) { $moduleName = $request->getModule(); $record = $request->get('record'); $recordModule = $request->get('recordModule'); $currency = $request->get('currency'); $sourceRecord = $request->get('sourceRecord'); $taxType = $request->get('taxType'); $totalPrice = $request->get('totalPrice'); $inventoryModel = Vtiger_Inventory_Model::getInstance($moduleName); $accountTaxs = $inventoryModel->getAccountTax($moduleName, $sourceRecord); $config = $inventoryModel->getTaxesConfig(); $viewer = $this->getViewer($request); $viewer->assign('MODULE', $moduleName); $viewer->assign('RECORD', $record); $viewer->assign('RECORD_MODULE', $recordModule); $viewer->assign('GLOBAL_TAXS', $inventoryModel->getGlobalTaxs()); $viewer->assign('CURRENCY_SYMBOL', Vtiger_Functions::getCurrencySymbolandRate($currency)['symbol']); $viewer->assign('TOTAL_PRICE', $totalPrice); $viewer->assign('CONFIG', $config); $viewer->assign('TAX_TYPE', $taxType); $viewer->assign('TAX_FIELD', Vtiger_InventoryField_Model::getTaxField($recordModule)); $viewer->assign('AGGREGATION_TYPE', $config['aggregation']); $viewer->assign('AGGREGATION_INPUT_TYPE', $config['aggregation'] == 0 ? 'radio' : 'checkbox'); $viewer->assign('GROUP_TAXS', $accountTaxs['taxs']); $viewer->assign('ACCOUNT_NAME', $accountTaxs['name']); echo $viewer->view('InventoryTaxes.tpl', $moduleName, true); }
/** * Function exports the data based on the mode * @param Vtiger_Request $request */ function ExportData(Vtiger_Request $request) { $db = PearDatabase::getInstance(); $moduleName = $request->get('source_module'); $this->moduleInstance = Vtiger_Module_Model::getInstance($moduleName); $this->moduleFieldInstances = $this->moduleInstance->getFields(); $this->focus = CRMEntity::getInstance($moduleName); $query = $this->getExportQuery($request); $result = $db->query($query); $headers = []; //Query generator set this when generating the query if (!empty($this->accessibleFields)) { $accessiblePresenceValue = [0, 2]; foreach ($this->accessibleFields as $fieldName) { $fieldModel = $this->moduleFieldInstances[$fieldName]; // Check added as querygenerator is not checking this for admin users if (isset($fieldModel) && in_array($fieldModel->get('presence'), $accessiblePresenceValue)) { $headers[] = $fieldModel->get('label'); } } } else { foreach ($this->moduleFieldInstances as $field) { $headers[] = $field->get('label'); } } $isInventory = $this->moduleInstance->isInventory(); if ($isInventory) { //Get inventory headers $inventoryFieldModel = Vtiger_InventoryField_Model::getInstance($moduleName); $inventoryFields = $inventoryFieldModel->getFields(); foreach ($inventoryFields as $field) { $headers[] = $field->get('label'); } $table = $inventoryFieldModel->getTableName('data'); } $translatedHeaders = []; foreach ($headers as $header) { $translatedHeaders[] = vtranslate(html_entity_decode($header, ENT_QUOTES), $moduleName); } $entries = []; while ($row = $db->fetch_array($result)) { $sanitizedRow = $this->sanitizeValues($row); if ($isInventory) { $resultInventory = $db->pquery('SELECT * FROM ' . $table . ' WHERE id = ? ORDER BY seq', [$row[$this->focus->table_index]]); if ($db->getRowCount($resultInventory)) { while ($inventoryRow = $db->fetch_array($resultInventory)) { $sanitizedInventoryRow = $this->sanitizeInventoryValues($inventoryRow, $inventoryFields); $entries[] = array_merge($sanitizedRow, $sanitizedInventoryRow); } } else { $entries[] = $sanitizedRow; } } else { $entries[] = $sanitizedRow; } } $this->output($request, $translatedHeaders, $entries); }
public function process($module, $id, Vtiger_PDF_Model $pdf) { $html = ''; $recordId = $id; $record = Vtiger_Record_Model::getInstanceById($recordId); $moduleModel = $record->getModule(); if (!$moduleModel->isInventory()) { return $html; } $inventoryField = Vtiger_InventoryField_Model::getInstance($module); $fields = $inventoryField->getFields(true); if ($fields[0] != 0) { $columns = $inventoryField->getColumns(); $inventoryRows = $record->getInventoryData(); $mainParams = $inventoryField->getMainParams($fields[1]); $countFields0 = count($fields[0]); $countFields1 = count($fields[1]); $countFields2 = count($fields[2]); $baseCurrency = Vtiger_Util_Helper::getBaseCurrency(); } if (in_array("currency", $columns)) { if (count($inventoryRows) > 0 && $inventoryRows[0]['currency'] != NULL) { $currency = $inventoryRows[0]['currency']; } else { $currency = $baseCurrency['id']; } $currencySymbolRate = Vtiger_Functions::getCurrencySymbolandRate($currency); } $html .= '<style>' . '.productTable{color:#000; font-size:10px}' . '.productTable th {text-transform: uppercase;font-weight:normal}' . '.productTable tbody tr:nth-child(odd){background:#eee}' . '.productTable tbody tr td{border-bottom: 1px solid #ddd; padding:5px}' . '.colapseBorder {border-collapse: collapse;}' . '.productTable td, th {padding-left: 5px; padding-right: 5px;}' . '.productTable .summaryContainer{background:#ccc;}' . '</style>'; if (count($fields[0]) != 0) { $discount = 0; foreach ($inventoryRows as $key => &$inventoryRow) { $taxes = $inventoryField->getTaxParam($inventoryRow['taxparam'], $inventoryRow['net'], $taxes); } if (in_array('discount', $columns) && in_array('discountmode', $columns)) { $html .= '<table class="productTable colapseBorder"> <thead> <tr> <th class="tBorder noBottomBorder tHeader"> <strong>' . vtranslate('LBL_DISCOUNTS_SUMMARY', $module) . '</strong> </th> </tr> </thead> <tbody> <tr> <td class="textAlignRight tBorder">' . CurrencyField::convertToUserFormat($discount, null, true) . ' ' . $currencySymbolRate['symbol'] . '</td> </tr> </tbody> </table>'; } } return $html; }
public function delete(Vtiger_Request $request) { $param = $request->get('param'); $moduleName = $param['module']; $inventoryField = Vtiger_InventoryField_Model::getInstance($moduleName); $status = $inventoryField->delete($param); if ($status) { $status = true; } $response = new Vtiger_Response(); $response->setResult(['success' => $status]); $response->emit(); }
public function step2(Vtiger_Request $request) { $qualifiedModuleName = $request->getModule(false); $type = $request->get('mtype'); $moduleName = $request->get('type'); $id = $request->get('id'); if ($id) { $instance = Vtiger_InventoryField_Model::getInstance($moduleName); $fieldInstance = $instance->getFields(false, [$id]); } else { $models = Vtiger_InventoryField_Model::getAllFields($moduleName); $fieldInstance = $models[$type]; } $viewer = $this->getViewer($request); $viewer->assign('MODULE_MODEL', $fieldInstance); $viewer->assign('QUALIFIED_MODULE', $qualifiedModuleName); $viewer->assign('MODULE_NAME', $moduleName); $viewer->assign('ID', $request->get('id')); $viewer->view('CreateInventoryFieldsStep2.tpl', $qualifiedModuleName); }
public function showFieldLayout(Vtiger_Request $request) { $sourceModule = $request->get('sourceModule'); $supportedModulesList = Settings_LayoutEditor_Module_Model::getSupportedModules(); if (empty($sourceModule)) { //To get the first element $sourceModule = reset($supportedModulesList); } $moduleModel = Settings_LayoutEditor_Module_Model::getInstanceByName($sourceModule); $fieldModels = $moduleModel->getFields(); $blockModels = $moduleModel->getBlocks(); $blockIdFieldMap = array(); $inactiveFields = array(); foreach ($fieldModels as $fieldModel) { $blockIdFieldMap[$fieldModel->getBlockId()][$fieldModel->getName()] = $fieldModel; if (!$fieldModel->isActiveField()) { $inactiveFields[$fieldModel->getBlockId()][$fieldModel->getId()] = vtranslate($fieldModel->get('label'), $sourceModule); } } foreach ($blockModels as $blockLabel => $blockModel) { $fieldModelList = $blockIdFieldMap[$blockModel->get('id')]; $blockModel->setFields($fieldModelList); } $qualifiedModule = $request->getModule(false); $viewer = $this->getViewer($request); $viewer->assign('SELECTED_MODULE_NAME', $sourceModule); $viewer->assign('SUPPORTED_MODULES', $supportedModulesList); $viewer->assign('SELECTED_MODULE_MODEL', $moduleModel); $viewer->assign('BLOCKS', $blockModels); $viewer->assign('ADD_SUPPORTED_FIELD_TYPES', $moduleModel->getAddSupportedFieldTypes()); $viewer->assign('DISPLAY_TYPE_LIST', Vtiger_Field_Model::showDisplayTypeList()); $viewer->assign('USER_MODEL', Users_Record_Model::getCurrentUserModel()); $viewer->assign('QUALIFIED_MODULE', $qualifiedModule); $viewer->assign('IN_ACTIVE_FIELDS', $inactiveFields); $viewer->assign('IS_INVENTORY', $moduleModel->isInventory()); $viewer->assign('INVENTORY_MODAL', Vtiger_InventoryField_Model::getInstance($sourceModule)); $viewer->view('Index.tpl', $qualifiedModule); }
public function saveInventoryField(Vtiger_Request $request) { $param = $request->get('param'); $moduleName = $param['module']; $name = $param['name']; $id = $param['id']; $edit = false; $inventoryField = Vtiger_InventoryField_Model::getInstance($moduleName); if ($id) { $return = $inventoryField->saveField($param); $edit = true; } else { $return = $inventoryField->addField($name, $param); $id = $return['id']; } $arrayInstane = $inventoryField->getFields(false, [$id]); if (current($arrayInstane)) { $data = current($arrayInstane)->getData(); } $response = new Vtiger_Response(); $response->setResult(['data' => $data, 'edit' => $edit]); $response->emit(); }
public function process($module, $id, Vtiger_PDF_Model $pdf) { $html = ''; $recordId = $id; $record = Vtiger_Record_Model::getInstanceById($recordId); $moduleModel = $record->getModule(); if (!$moduleModel->isInventory()) { return $html; } $inventoryField = Vtiger_InventoryField_Model::getInstance($module); $fields = $inventoryField->getFields(true); if ($fields[0] != 0) { $columns = $inventoryField->getColumns(); $inventoryRows = $record->getInventoryData(); $mainParams = $inventoryField->getMainParams($fields[1]); $countFields0 = count($fields[0]); $countFields1 = count($fields[1]); $countFields2 = count($fields[2]); $baseCurrency = Vtiger_Util_Helper::getBaseCurrency(); } if (in_array("currency", $columns)) { if (count($inventoryRows) > 0 && $inventoryRows[0]['currency'] != NULL) { $currency = $inventoryRows[0]['currency']; } else { $currency = $baseCurrency['id']; } $currencySymbolRate = Vtiger_Functions::getCurrencySymbolandRate($currency); } $html .= '<style>' . '.colapseBorder {border-collapse: collapse;}' . '.tBorder {border: 1px solid grey;}' . '.tHeader {background-color: lightgrey;}' . '.summaryBorder {border-left: 1px solid grey; border-bottom: 1px solid grey; border-right: 1px solid grey;}' . '.pTable td, th {padding-left: 5px; padding-right: 5px;}' . '.noBottomBorder {border-bottom: none;}' . '.noBorder {border: none !important;}' . '</style>'; if (count($fields[0]) != 0) { $html .= '<table class="pTable colapseBorder"> <thead> <tr> <th style="width: 65%;"></th>'; foreach ($fields[0] as $field) { $html .= '<th colspan="' . $field->get('colspan') . '" class="tBorder noBottomBorder tHeader"> <span>' . vtranslate($field->get('label'), $module) . ':</span> '; switch ($field->getTemplateName('DetailView', $module)) { case 'DetailViewBase.tpl': $html .= $field->getDisplayValue($inventoryRows[0][$field->get('columnname')]); break; case 'DetailViewTaxMode.tpl': case 'DetailViewDiscountMode.tpl': $html .= vtranslate($field->getDisplayValue($inventoryRows[0][$field->get('columnname')]), $MODULE); break; } $html .= '</th>'; } $html .= '</tr> </thead> </table>'; $fieldsTextAlignRight = ['TotalPrice', 'Tax', 'MarginP', 'Margin', 'Purchase', 'Discount', 'NetPrice', 'GrossPrice', 'UnitPrice', 'Quantity']; $html .= '<table class="pTable colapseBorder"> <thead> <tr>'; foreach ($fields[1] as $field) { if ($field->isVisible($inventoryRows)) { $html .= '<th colspan="' . $field->get('colspan') . '" class="textAlignCenter tBorder tHeader">' . vtranslate($field->get('label'), $module) . '</th>'; } } $html .= '</tr> </thead> <tbody>'; // for($i=0; $i<100; $i++) { foreach ($inventoryRows as $key => &$inventoryRow) { $rowNo = $key + 1; $html .= '<tr>'; foreach ($fields[1] as $field) { if ($field->isVisible($inventoryRows)) { $itemValue = $inventoryRow[$field->get('columnname')]; $html .= '<td ' . ($field->getName() == 'Name' ? 'width="40%;" ' : '') . ' class="' . (in_array($field->getName(), $fieldsTextAlignRight) ? 'textAlignRight ' : '') . 'tBorder">'; switch ($field->getTemplateName('DetailView', $module)) { case 'DetailViewName.tpl': $html .= '<strong>' . $field->getDisplayValue($itemValue) . '</strong>'; if (isset($fields[2]['comment' . $rowNo])) { $COMMENT_FIELD = $fields[2]['comment' . $rowNo]; $html .= '<br/>' . $COMMENT_FIELD->getDisplayValue($inventoryRow[$COMMENT_FIELD->get('columnname')]); } break; case 'DetailViewBase.tpl': $html .= $field->getDisplayValue($itemValue); break; } $html .= '</td>'; } } $html .= '</tr>'; } // } $html .= '</tbody> <tfoot> <tr>'; foreach ($fields[1] as $field) { if ($field->isVisible($inventoryRows)) { $html .= '<td colspan="' . $field->get('colspan') . '" class="textAlignRight '; if ($field->isSummary()) { $html .= 'summaryBorder'; } $html .= '">'; if ($field->isSummary()) { $sum = 0; foreach ($inventoryRows as $key => &$inventoryRow) { $sum += $inventoryRow[$field->get('columnname')]; } $html .= CurrencyField::convertToUserFormat($sum, null, true); } $html .= '</td>'; } } $html .= '</tr> </tfoot> </table>'; $discount = 0; $taxes = 0; foreach ($inventoryRows as $key => &$inventoryRow) { $discount += $inventoryRow['discount']; $taxes = $inventoryField->getTaxParam($inventoryRow['taxparam'], $inventoryRow['net'], $taxes); } $html .= '<br /><table width="100%" style="vertical-align: top; text-align: center;"> <tr> <td>'; if (in_array('discount', $columns) && in_array('discountmode', $columns)) { $html .= '<table class="pTable colapseBorder"> <thead> <tr> <th class="tBorder noBottomBorder tHeader"> <strong>' . vtranslate('LBL_DISCOUNTS_SUMMARY', $module) . '</strong> </th> </tr> </thead> <tbody> <tr> <td class="textAlignRight tBorder">' . CurrencyField::convertToUserFormat($discount, null, true) . ' ' . $currencySymbolRate['symbol'] . '</td> </tr> </tbody> </table>'; } $html .= '</td><td>'; if (in_array('tax', $columns) && in_array('taxmode', $columns)) { $html .= ' <table class="pTable colapseBorder"> <thead> <tr> <th colspan="2" class="tBorder noBottomBorder tHeader"> <strong>' . vtranslate('LBL_TAX_SUMMARY', $module) . '</strong> </th> </tr> </thead> <tbody>'; foreach ($taxes as $key => &$tax) { $tax_AMOUNT += $tax; $html .= '<tr> <td class="textAlignRight tBorder" width="70px">' . $key . '%</td> <td class="textAlignRight tBorder">' . CurrencyField::convertToUserFormat($tax, null, true) . ' ' . $currencySymbolRate['symbol'] . '</td> </tr>'; } $html .= '<tr> <td class="textAlignRight tBorder" width="70px">' . vtranslate('LBL_AMOUNT', $module) . '</td> <td class="textAlignRight tBorder">' . CurrencyField::convertToUserFormat($tax_AMOUNT, null, true) . ' ' . $currencySymbolRate['symbol'] . '</td> </tr> </tbody> </table> </div>'; if (in_array('currency', $columns) && $baseCurrency['id'] != $currency) { $RATE = $baseCurrency['conversion_rate'] / $currencySymbolRate['rate']; $html .= '<br /><table class="pTable colapseBorder"> <thead> <tr> <th colspan="2" class="tBorder noBottomBorder tHeader"> <strong>' . vtranslate('LBL_CURRENCIES_SUMMARY', $module) . '</strong> </th> </tr> </thead> <tbody>'; foreach ($taxes as $key => &$tax) { $currencyAmount += $tax; $html .= '<tr> <td class="textAlignRight tBorder" width="70px">' . $key . '%</td> <td class="textAlignRight tBorder">' . CurrencyField::convertToUserFormat($tax * $RATE, null, true) . ' ' . $baseCurrency['currency_symbol'] . '</td> </tr>'; } $html .= '<tr> <td class="textAlignRight tBorder" width="70px">' . vtranslate('LBL_AMOUNT', $module) . '</td> <td class="textAlignRight tBorder">' . CurrencyField::convertToUserFormat($currencyAmount * $RATE, null, true) . ' ' . $baseCurrency['currency_symbol'] . '</td> </tr> </tbody> </table>'; } } $html .= '</td></tr></table>'; } return $html; }
/** * Function to get instance * @param <String/Integer> $value * @param <String> $module * @param <String> $type * @return <Settings_MappedFields_Field_Model> field model */ public static function getInstance($value, $module, $type = '') { switch ($type) { case 'SELF': $fieldModel = parent::getInstance($value, $module); if (!$fieldModel) { $fields = Settings_MappedFields_Module_Model::getSpecialFields(); $fieldModel = $fields[$value]; } break; case 'INVENTORY': $inventoryFieldModel = Vtiger_InventoryField_Model::getInstance($module->getName()); $inventoryFields = $inventoryFieldModel->getFields(); return self::getInstanceFromInventoryFieldObject($inventoryFields[$value]); default: $fieldModel = parent::getInstance($value, $module); break; } if ($fieldModel) { $objectProperties = get_object_vars($fieldModel); $fieldModel = new self(); foreach ($objectProperties as $properName => $propertyValue) { $fieldModel->{$properName} = $propertyValue; } } return $fieldModel; }
/** * Get tax from the account * @param string $moduleName Module name * @param int $record Record ID * @return array */ public function getAccountTax($moduleName, $record) { $inventoryField = Vtiger_InventoryField_Model::getInstance($moduleName); $accountField = $inventoryField->getReferenceField(); $accountTaxs = []; $name = ''; $taxField = Vtiger_InventoryField_Model::getTaxField('Accounts'); if ($accountField != '' && $taxField != false) { $recordModel = Vtiger_Record_Model::getInstanceById($record, $moduleName); $relationFieldValue = $recordModel->get($accountField); if ($relationFieldValue != 0) { $accountRecordModel = Vtiger_Record_Model::getInstanceById($relationFieldValue, 'Accounts'); $accountTaxs = Vtiger_Taxs_UIType::getValues($accountRecordModel->get($taxField)); $name = $accountRecordModel->getName(); } } return ['taxs' => $accountTaxs, 'name' => $name]; }
/** * Save the inventory data */ public function saveInventoryData() { $db = PearDatabase::getInstance(); $log = vglobal('log'); $log->debug('Entering ' . __CLASS__ . '::' . __METHOD__); $moduleName = $this->getModuleName(); $inventory = Vtiger_InventoryField_Model::getInstance($moduleName); $fields = $inventory->getColumns(); $table = $inventory->getTableName('data'); $request = new Vtiger_Request($_REQUEST, $_REQUEST); $numRow = $request->get('inventoryItemsNo'); $db->pquery("delete from {$table} where id = ?", [$this->getId()]); for ($i = 1; $i <= $numRow; $i++) { if (!$request->has(reset($fields)) && !$request->has(reset($fields) . $i)) { continue; } $insertData = ['id' => $this->getId(), 'seq' => $request->get('seq' . $i)]; foreach ($fields as $field) { $insertData[$field] = $inventory->getValueForSave($request, $field, $i); } $db->insert($table, $insertData); } $log->debug('Exiting ' . __CLASS__ . '::' . __METHOD__); }
/** * Save the inventory data */ public function saveInventoryData() { //Event triggering code require_once "include/events/include.inc"; $db = PearDatabase::getInstance(); $log = vglobal('log'); $log->debug('Entering ' . __CLASS__ . '::' . __METHOD__); $moduleName = $this->getModuleName(); $inventory = Vtiger_InventoryField_Model::getInstance($moduleName); $table = $inventory->getTableName('data'); if ($this->has('inventoryData')) { $request = $this->get('inventoryData'); } else { $request = new Vtiger_Request($_REQUEST, $_REQUEST); } $numRow = $request->get('inventoryItemsNo'); //In Bulk mode stop triggering events if (!CRMEntity::isBulkSaveMode()) { $em = new VTEventsManager($adb); // Initialize Event trigger cache $em->initTriggerCache(); $em->triggerEvent('entity.inventory.beforesave', [$this, $inventory, $this->inventoryData]); } $db->delete($table, 'id = ?', [$this->getId()]); foreach ($this->inventoryData as $insertData) { $insertData['id'] = $this->getId(); $db->insert($table, $insertData); } if ($em) { //Event triggering code $em->triggerEvent('entity.inventory.aftersave', [$this, $inventory, $this->inventoryData]); } $log->debug('Exiting ' . __CLASS__ . '::' . __METHOD__); }
/** * Function returns fields of module * @return <Array of Vtiger_Field> */ public function getFields($source = false) { $log = vglobal('log'); $log->debug('Entering ' . __CLASS__ . '::' . __METHOD__ . '() method ...'); $moduleModel = Vtiger_Module_Model::getInstance($this->getName()); $moduleMeta = $moduleModel->getModuleMeta(); $moduleFields = $moduleMeta->getAccessibleFields($this->getName()); $fields = []; foreach ($moduleFields as $fieldName => $fieldInstance) { if ($moduleMeta->isEditableField($fieldInstance) && !in_array($fieldInstance->getUIType(), $this->getRestrictedUitypes())) { $blockName = $fieldInstance->getBlockName(); if (!$blockName) { $blockName = 'LBL_NOT_ASSIGNET_TO_BLOCK'; } $fields[$blockName][$fieldInstance->getFieldId()] = Settings_MappedFields_Field_Model::getInstanceFromWebserviceFieldObject($fieldInstance); } } if ($source) { foreach ($this->getSpecialFields() as $fieldName => $fieldInstance) { $fields['LBL_NOT_ASSIGNET_TO_BLOCK'][$fieldName] = $fieldInstance; } } $isInventory = $moduleModel->isInventory(); if ($isInventory) { $inventoryFieldModel = Vtiger_InventoryField_Model::getInstance($this->getName()); $inventoryFields = $inventoryFieldModel->getFields(); $blockName = 'LBL_ADVANCED_BLOCK'; foreach ($inventoryFields as $field) { $fields[$blockName][$field->get('columnname')] = Settings_MappedFields_Field_Model::getInstanceFromInventoryFieldObject($field); } } $log->debug('Exiting ' . __CLASS__ . '::' . __METHOD__ . ' method ...'); return $fields; }
public function getRecordDetail($recordId, $currencyId, $moduleName) { $conversionRate = 1; $unitPriceValues = $taxes = []; $unitPrice = false; $recordModel = Vtiger_Record_Model::getInstanceById($recordId); $recordModuleName = $recordModel->getModuleName(); if (in_array($recordModuleName, ['Products', 'Services'])) { $unitPriceValues = $recordModel->getListPriceValues($recordModel->getId()); $priceDetails = $recordModel->getPriceDetails(); foreach ($priceDetails as $currencyDetails) { if ($currencyId == $currencyDetails['curid']) { $conversionRate = $currencyDetails['conversionrate']; } } $unitPrice = (double) $recordModel->get('unit_price') * (double) $conversionRate; } $inventoryField = Vtiger_InventoryField_Model::getInstance($moduleName); $autoCompleteField = $inventoryField->getAutoCompleteField($recordModuleName); $autoFields = []; if ($autoCompleteField) { foreach ($autoCompleteField as $field) { if ($recordModel->has($field['field']) && $recordModel->get($field['field']) != '') { $autoFields[$field['tofield']] = $recordModel->get($field['field']); } } } $info = [$recordId => ['id' => $recordId, 'name' => decode_html($recordModel->getName()), 'price' => $unitPrice, 'unitPriceValues' => $unitPriceValues, 'description' => decode_html($recordModel->get('description')), 'autoFields' => $autoFields]]; return $info; }
/** * Save the inventory data */ public function saveInventoryData() { //Event triggering code require_once "include/events/include.inc"; $db = PearDatabase::getInstance(); $log = vglobal('log'); $log->debug('Entering ' . __CLASS__ . '::' . __METHOD__); $moduleName = $this->getModuleName(); $inventory = Vtiger_InventoryField_Model::getInstance($moduleName); $fields = $inventory->getColumns(); $table = $inventory->getTableName('data'); $summaryFields = $inventory->getSummaryFields(); $insertDataTemp = $summary = []; $request = new Vtiger_Request($_REQUEST, $_REQUEST); $numRow = $request->get('inventoryItemsNo'); //In Bulk mode stop triggering events if (!CRMEntity::isBulkSaveMode()) { $em = new VTEventsManager($adb); // Initialize Event trigger cache $em->initTriggerCache(); $em->triggerEvent('entity.inventory.beforesave', [$this, $inventory]); } $db->pquery("delete from {$table} where id = ?", [$this->getId()]); for ($i = 1; $i <= $numRow; $i++) { if (!$request->has(reset($fields)) && !$request->has(reset($fields) . $i)) { continue; } $insertData = ['id' => $this->getId(), 'seq' => $request->get('seq' . $i)]; foreach ($fields as $field) { $value = $insertData[$field] = $inventory->getValueForSave($request, $field, $i); if (in_array($field, $summaryFields)) { $summary[$field] += $value; } } $db->insert($table, $insertData); $insertDataTemp[] = $insertData; } foreach ($summary as $fieldName => $fieldValue) { if ($this->has($fieldName)) { $this->set($fieldName, CurrencyField::convertToUserFormat($fieldValue, null, true)); } } if ($em) { //Event triggering code $em->triggerEvent('entity.inventory.aftersave', [$this, $inventory, $insertDataTemp, $summary]); } $log->debug('Exiting ' . __CLASS__ . '::' . __METHOD__); }
public function process($module, $id, Vtiger_PDF_Model $pdf) { $html = ''; $recordId = $id; $record = Vtiger_Record_Model::getInstanceById($recordId); $moduleModel = $record->getModule(); if (!$moduleModel->isInventory()) { return $html; } $inventoryField = Vtiger_InventoryField_Model::getInstance($module); $fields = $inventoryField->getFields(true); $inventoryRows = $record->getInventoryData(); $html .= '<style>' . '.productTable{color:#000; font-size:10px; width:100%}' . '.productTable th {text-transform: uppercase;font-weight:normal}' . '.productTable tbody tr:nth-child(odd){background:#eee}' . '.productTable tr td{border-bottom: 1px solid #ddd; padding:5px;text-align:center; }' . '.colapseBorder {border-collapse: collapse;}' . '.productTable td, th {padding-left: 5px; padding-right: 5px;}' . '.productTable .summaryContainer{background:#ccc;padding:5px}' . '</style>'; if (count($fields[1]) != 0) { $fieldsTextAlignRight = ['TotalPrice', 'Tax', 'MarginP', 'Margin', 'Purchase', 'Discount', 'NetPrice', 'GrossPrice', 'UnitPrice', 'Quantity']; $html .= '<table border="0" cellpadding="0" cellspacing="0" class="productTable"> <thead> <tr><td>' . vtranslate('LBL_NR') . '</td>'; foreach ($fields[1] as $field) { if ($field->isVisible($inventoryRows)) { $html .= '<th colspan="' . $field->get('colspan') . '" class="textAlignCenter tBorder tHeader">' . vtranslate($field->get('label'), $module) . '</th>'; } } $html .= '</tr> </thead> <tbody>'; foreach ($inventoryRows as $key => &$inventoryRow) { $rowNo = $key + 1; $html .= '<tr><td><strong>' . $rowNo . '</strong></td>'; foreach ($fields[1] as $field) { if ($field->isVisible($inventoryRows)) { $itemValue = $inventoryRow[$field->get('columnname')]; $html .= '<td ' . ($field->getName() == 'Name' ? 'width="40%;" ' : '') . ' class="' . (in_array($field->getName(), $fieldsTextAlignRight) ? 'textAlignRight ' : '') . 'tBorder">'; switch ($field->getTemplateName('DetailView', $module)) { case 'DetailViewName.tpl': $html .= '<strong>' . $field->getDisplayValue($itemValue) . '</strong>'; if (isset($fields[2]['comment' . $rowNo])) { $COMMENT_FIELD = $fields[2]['comment' . $rowNo]; $html .= '<br/>' . $COMMENT_FIELD->getDisplayValue($inventoryRow[$COMMENT_FIELD->get('columnname')]); } break; case 'DetailViewBase.tpl': $html .= $field->getDisplayValue($itemValue); break; } $html .= '</td>'; } } $html .= '</tr>'; } $html .= '</tbody> <tfoot> <tr><td></td>'; foreach ($fields[1] as $field) { if ($field->isVisible($inventoryRows)) { $html .= '<td colspan="' . $field->get('colspan') . '" class="textAlignRight '; if ($field->isSummary()) { $html .= 'summaryContainer'; } $html .= '">'; if ($field->isSummary()) { $sum = 0; foreach ($inventoryRows as $key => &$inventoryRow) { $sum += $inventoryRow[$field->get('columnname')]; } $html .= CurrencyField::convertToUserFormat($sum, null, true); } $html .= '</td>'; } } $html .= '</tr> </tfoot> </table>'; } return $html; }