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 checkLimits(Vtiger_Request $request) { $moduleName = $request->getModule(); $record = $request->get('record'); $currency = $request->get('currency'); $price = $request->get('price'); $limitConfig = $request->get('limitConfig'); $limitFieldName = 'creditlimit'; $balanceFieldName = 'inventorybalance'; $moduleInstance = Vtiger_Module_Model::getInstance('Accounts'); $limitField = Vtiger_Field_Model::getInstance($limitFieldName, $moduleInstance); $balanceField = Vtiger_Field_Model::getInstance($balanceFieldName, $moduleInstance); if (!$limitField->isActiveField() || !$balanceField->isActiveField()) { $response = new Vtiger_Response(); $response->setResult(['status' => true]); $response->emit(); return; } $recordModel = Vtiger_Record_Model::getInstanceById($record, 'Accounts'); $limitID = $recordModel->get($limitFieldName); $balance = $recordModel->get($balanceFieldName); $limit = reset(Vtiger_InventoryLimit_UIType::getValues($limitID))['value']; $baseCurrency = Vtiger_Util_Helper::getBaseCurrency(); $symbol = $baseCurrency['currency_symbol']; if ($baseCurrency['id'] != $currency) { $selectedCurrency = Vtiger_Functions::getCurrencySymbolandRate($currency); $price = floatval($price) * $selectedCurrency['rate']; $symbol = $selectedCurrency['symbol']; } $totalPrice = $price + $balance; $status = $totalPrice > $limit ? false : true; if (!$status) { $viewer = new Vtiger_Viewer(); $viewer->assign('PRICE', $price); $viewer->assign('BALANCE', $balance); $viewer->assign('SYMBOL', $symbol); $viewer->assign('LIMIT', $limit); $viewer->assign('TOTALS', $totalPrice); $viewer->assign('LIMIT_CONFIG', $limitConfig); $html = $viewer->view('InventoryLimitAlert.tpl', $moduleName, true); } $response = new Vtiger_Response(); $response->setResult([ 'status' => $status, 'html' => $html ]); $response->emit(); }
public function process(Vtiger_Request $request) { $viewer = $this->getViewer($request); $moduleName = $request->getModule(); $qualifiedModuleName = $request->getModule(false); $id = $request->get('id'); $type = $request->get('type'); if (empty($id)) { $recordModel = new Settings_Inventory_Record_Model(); } else { $recordModel = Settings_Inventory_Record_Model::getInstanceById($id, $type); } $viewer->assign('PAGE_LABELS', $this->getPageLabels($request)); $viewer->assign('QUALIFIED_MODULE', $qualifiedModuleName); $viewer->assign('RECORD_MODEL', $recordModel); $viewer->assign('TYPE', $type); $viewer->assign('CURRENCY', Vtiger_Util_Helper::getBaseCurrency()); echo $viewer->view('Modal.tpl', $qualifiedModuleName, true); }
public function process(Vtiger_Request $request) { $mode = $request->getMode(); if (!empty($mode)) { echo $this->invokeExposedMethod($mode, $request); return; } $view = $this->getView(); $recordModel = new Settings_Inventory_Record_Model(); $recordModel->setType($view); $allData = Settings_Inventory_Record_Model::getDataAll($view); $qualifiedModuleName = $request->getModule(false); $viewer = $this->getViewer($request); $viewer->assign('PAGE_LABELS', $this->getPageLabels($request)); $viewer->assign('RECORD_MODEL', $recordModel); $viewer->assign('INVENTORY_DATA', $allData); $viewer->assign('VIEW', $view); $viewer->assign('CURRENCY', Vtiger_Util_Helper::getBaseCurrency()); $viewer->view('Index.tpl', $qualifiedModuleName); }
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 content_54e7656f35028($_smarty_tpl) { if (!is_callable('smarty_modifier_replace')) { include '/var/www/vhosts/registro.tuagencia24.com/vtigercrm/libraries/Smarty/libs/plugins/modifier.replace.php'; } ?> <div class="contents-topscroll"><div class="topscroll-div container-fluid"> </div></div><div id="reportDetails" class="container-fluid contents-bottomscroll"><div class="bottomscroll-div"><input type="hidden" id="updatedCount" value="<?php echo $_smarty_tpl->tpl_vars['NEW_COUNT']->value; ?> " /><?php if (!empty($_smarty_tpl->tpl_vars['CALCULATION_FIELDS']->value)) { ?> <table class=" table-bordered table-condensed marginBottom10px" width="100%"><thead><tr class="blockHeader"><th><?php echo vtranslate('LBL_FIELD_NAMES', $_smarty_tpl->tpl_vars['MODULE']->value); ?> </th><th><?php echo vtranslate('LBL_SUM', $_smarty_tpl->tpl_vars['MODULE']->value); ?> </th><th><?php echo vtranslate('LBL_AVG', $_smarty_tpl->tpl_vars['MODULE']->value); ?> </th><th><?php echo vtranslate('LBL_MIN', $_smarty_tpl->tpl_vars['MODULE']->value); ?> </th><th><?php echo vtranslate('LBL_MAX', $_smarty_tpl->tpl_vars['MODULE']->value); ?> </th></tr></thead><?php $_smarty_tpl->tpl_vars['ESCAPE_CHAR'] = new Smarty_variable(array('_SUM', '_AVG', '_MIN', '_MAX'), null, 0); $_smarty_tpl->tpl_vars['CALCULATION_FIELD'] = new Smarty_Variable(); $_smarty_tpl->tpl_vars['CALCULATION_FIELD']->_loop = false; $_smarty_tpl->tpl_vars['index'] = new Smarty_Variable(); $_from = $_smarty_tpl->tpl_vars['CALCULATION_FIELDS']->value; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array'); } foreach ($_from as $_smarty_tpl->tpl_vars['CALCULATION_FIELD']->key => $_smarty_tpl->tpl_vars['CALCULATION_FIELD']->value) { $_smarty_tpl->tpl_vars['CALCULATION_FIELD']->_loop = true; $_smarty_tpl->tpl_vars['index']->value = $_smarty_tpl->tpl_vars['CALCULATION_FIELD']->key; ?> <tr><?php $_smarty_tpl->tpl_vars['CALCULATION_FIELD_KEYS'] = new Smarty_variable(array_keys($_smarty_tpl->tpl_vars['CALCULATION_FIELD']->value), null, 0); $_smarty_tpl->tpl_vars['CALCULATION_FIELD_KEYS'] = new Smarty_variable(smarty_modifier_replace($_smarty_tpl->tpl_vars['CALCULATION_FIELD_KEYS']->value, $_smarty_tpl->tpl_vars['ESCAPE_CHAR']->value, ''), null, 0); $_smarty_tpl->tpl_vars['FIELD_IMPLODE'] = new Smarty_variable(explode('_', $_smarty_tpl->tpl_vars['CALCULATION_FIELD_KEYS']->value['0']), null, 0); $_smarty_tpl->tpl_vars['MODULE_NAME'] = new Smarty_variable($_smarty_tpl->tpl_vars['FIELD_IMPLODE']->value['0'], null, 0); $_smarty_tpl->tpl_vars['FIELD_LABEL'] = new Smarty_variable(implode(" ", $_smarty_tpl->tpl_vars['FIELD_IMPLODE']->value), null, 0); $_smarty_tpl->tpl_vars['FIELD_LABEL'] = new Smarty_variable(smarty_modifier_replace($_smarty_tpl->tpl_vars['FIELD_LABEL']->value, $_smarty_tpl->tpl_vars['MODULE_NAME']->value, ''), null, 0); ?> <td><?php echo vtranslate($_smarty_tpl->tpl_vars['MODULE_NAME']->value, $_smarty_tpl->tpl_vars['MODULE']->value); ?> <?php echo vtranslate($_smarty_tpl->tpl_vars['FIELD_LABEL']->value, $_smarty_tpl->tpl_vars['MODULE']->value); ?> </td><?php $_smarty_tpl->tpl_vars['CALCULATION_VALUE'] = new Smarty_Variable(); $_smarty_tpl->tpl_vars['CALCULATION_VALUE']->_loop = false; $_from = $_smarty_tpl->tpl_vars['CALCULATION_FIELD']->value; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array'); } foreach ($_from as $_smarty_tpl->tpl_vars['CALCULATION_VALUE']->key => $_smarty_tpl->tpl_vars['CALCULATION_VALUE']->value) { $_smarty_tpl->tpl_vars['CALCULATION_VALUE']->_loop = true; ?> <td width="15%"><?php echo $_smarty_tpl->tpl_vars['CALCULATION_VALUE']->value; ?> </td><?php } ?> </tr><?php } ?> </table><?php if ($_smarty_tpl->tpl_vars['PRIMARY_MODULE']->value == 'Invoice' || $_smarty_tpl->tpl_vars['PRIMARY_MODULE']->value == 'Quotes' || $_smarty_tpl->tpl_vars['PRIMARY_MODULE']->value == 'SalesOrder' || $_smarty_tpl->tpl_vars['PRIMARY_MODULE']->value == 'PurchaseOrder') { $_smarty_tpl->tpl_vars['BASE_CURRENCY_INFO'] = new Smarty_variable(Vtiger_Util_Helper::getBaseCurrency(), null, 0); ?> <div class="alert alert-info"><?php echo vtranslate('LBL_NOTE', 'Vtiger'); ?> : <?php echo vtranslate('LBL_CALCULATION_CONVERSION_MESSAGE', 'Reports'); ?> - <?php echo $_smarty_tpl->tpl_vars['BASE_CURRENCY_INFO']->value['currency_name']; ?> (<?php echo $_smarty_tpl->tpl_vars['BASE_CURRENCY_INFO']->value['currency_code']; ?> )</div><?php } } if ($_smarty_tpl->tpl_vars['DATA']->value != '') { $_smarty_tpl->tpl_vars['HEADERS'] = new Smarty_variable($_smarty_tpl->tpl_vars['DATA']->value[0], null, 0); ?> <table class="table table-bordered table-striped"><thead><tr class="blockHeader"><?php $_smarty_tpl->tpl_vars['HEADER'] = new Smarty_Variable(); $_smarty_tpl->tpl_vars['HEADER']->_loop = false; $_smarty_tpl->tpl_vars['NAME'] = new Smarty_Variable(); $_from = $_smarty_tpl->tpl_vars['HEADERS']->value; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array'); } foreach ($_from as $_smarty_tpl->tpl_vars['HEADER']->key => $_smarty_tpl->tpl_vars['HEADER']->value) { $_smarty_tpl->tpl_vars['HEADER']->_loop = true; $_smarty_tpl->tpl_vars['NAME']->value = $_smarty_tpl->tpl_vars['HEADER']->key; ?> <th nowrap><?php echo vtranslate($_smarty_tpl->tpl_vars['NAME']->value, $_smarty_tpl->tpl_vars['MODULE']->value); ?> </th><?php } ?> </tr></thead><?php $_smarty_tpl->tpl_vars['VALUES'] = new Smarty_Variable(); $_smarty_tpl->tpl_vars['VALUES']->_loop = false; $_from = $_smarty_tpl->tpl_vars['DATA']->value; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array'); } foreach ($_from as $_smarty_tpl->tpl_vars['VALUES']->key => $_smarty_tpl->tpl_vars['VALUES']->value) { $_smarty_tpl->tpl_vars['VALUES']->_loop = true; ?> <tr><?php $_smarty_tpl->tpl_vars['VALUE'] = new Smarty_Variable(); $_smarty_tpl->tpl_vars['VALUE']->_loop = false; $_smarty_tpl->tpl_vars['NAME'] = new Smarty_Variable(); $_from = $_smarty_tpl->tpl_vars['VALUES']->value; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array'); } foreach ($_from as $_smarty_tpl->tpl_vars['VALUE']->key => $_smarty_tpl->tpl_vars['VALUE']->value) { $_smarty_tpl->tpl_vars['VALUE']->_loop = true; $_smarty_tpl->tpl_vars['NAME']->value = $_smarty_tpl->tpl_vars['VALUE']->key; ?> <td><?php echo $_smarty_tpl->tpl_vars['VALUE']->value; ?> </td><?php } ?> </tr><?php } ?> </table><?php if ($_smarty_tpl->tpl_vars['LIMIT_EXCEEDED']->value) { ?> <center><?php echo vtranslate('LBL_LIMIT_EXCEEDED', $_smarty_tpl->tpl_vars['MODULE']->value); ?> <span class="pull-right"><a href="#top" ><?php echo vtranslate('LBL_TOP', $_smarty_tpl->tpl_vars['MODULE']->value); ?> </a></span></center><?php } } else { echo vtranslate('LBL_NO_DATA_AVAILABLE', $_smarty_tpl->tpl_vars['MODULE']->value); } ?> </div></div></div> <?php }