function buildFooterModel() { $footerModel = new Vtiger_PDF_Model(); $termsconditionLabel = getTranslatedString('Description', $this->moduleName); $footerModel->set('title', $termsconditionLabel); $footerModel->set('content', from_html($this->focusColumnValue("description"))); return $footerModel; }
protected function getUserList(Vtiger_PDF_Model $pdf, $moduleName) { $users = []; $db = PearDatabase::getInstance(); foreach ($pdf->getRecordIds() as $recordId) { $recordModel = Vtiger_Record_Model::getInstanceById($recordId, $moduleName); $user = $recordModel->getDisplayValue('assigned_user_id', $recordId, true); $time = (isset($users[$user]['time']) ? $users[$user]['time'] : 0) + $recordModel->get('sum_time'); $users[$user] = ['time' => $time, 'role' => vtranslate($this->getRoleName($recordModel->get('assigned_user_id')), $moduleName)]; } return $users; }
public function process(Vtiger_Request $request) { $recordId = $request->get('record'); $step = $request->get('step'); $moduleName = $request->get('module_name'); if ($recordId) { $pdfModel = Vtiger_PDF_Model::getInstanceById($recordId, $moduleName); } else { $pdfModel = Settings_PDF_Record_Model::getCleanInstance($moduleName); } $stepFields = Settings_PDF_Module_Model::getFieldsByStep($step); foreach ($stepFields as $field) { $value = $request->get($field); if (is_array($value)) { $value = implode(',', $value); } if ($field === 'module_name' && $pdfModel->get('module_name') != $value) { // change of main module, overwrite existing conditions $pdfModel->deleteConditions(); } $pdfModel->set($field, $value); } $pdfModel->set('conditions', $request->get('conditions')); Settings_PDF_Record_Model::transformAdvanceFilterToWorkFlowFilter($pdfModel); Settings_PDF_Record_Model::save($pdfModel, $step); $response = new Vtiger_Response(); $response->setResult(['id' => $pdfModel->get('pdfid')]); $response->emit(); }
public function process($moduleName, $id, Vtiger_PDF_Model $pdf) { $moduleModel = Vtiger_Module_Model::getInstance($moduleName); $fields = $moduleModel->getFields(); $ids = $pdf->getRecordIds(); if (!is_array($ids)) { $ids = [$ids]; } $html = '<br><style>' . '.table {width: 100%; border-collapse: collapse;}' . '.table thead th {border-bottom: 1px solid grey;}' . '.table tbody tr {border-bottom: 1px solid grey}' . '.table tbody tr:nth-child(even) {background-color: #F7F7F7;}' . '.center {text-align: center;}' . '.summary {border-top: 1px solid grey;}' . '</style>'; $html .= '<table class="table"><thead><tr>'; foreach ($this->columnNames as $column) { $fieldModel = $fields[$column]; $html .= '<th><span>' . vtranslate($fieldModel->get('label'), $moduleName) . '</span> </th>'; } $html .= '</tr></thead><tbody>'; $summary = []; foreach ($ids as $recordId) { $html .= '<tr>'; $recordModel = Vtiger_Record_Model::getInstanceById($recordId, $moduleName); foreach ($this->columnNames as $key => $column) { $fieldModel = $fields[$column]; $class = ''; if (in_array($column, ['time_start', 'time_end', 'due_date', 'date_start', 'sum_time'])) { $class = 'class="center"'; } $html .= '<td ' . $class . '>' . $recordModel->getDisplayValue($fieldModel->getName(), $recordId, true) . '</td>'; if ($column == 'sum_time') { $summary['sum_time'] += $recordModel->get($fieldModel->getName()); } } $html .= '</tr>'; } $html .= '</tbody><tfoot><tr>'; foreach ($this->columnNames as $key => $column) { $class = $content = ''; if ($column == 'sum_time') { $time = Vtiger_Functions::decimalTimeFormat($summary['sum_time']); $content = '<strong>' . $time['short'] . '</strong>'; $class = 'center'; } elseif ($column == 'name') { $content = '<strong>' . vtranslate('LBL_SUMMARY', $moduleName) . ':' . '</strong>'; } $html .= '<td class="summary ' . $class . '">' . $content . '</td>'; } $html .= '</tr></tfoot></table>'; return $html; }
public function Delete(Vtiger_Request $request) { $recordId = $request->get('id'); $pdfModel = Vtiger_PDF_Model::getInstanceById($recordId); $output = Settings_PDF_Record_Model::deleteWatermark($pdfModel); $response = new Vtiger_Response(); $response->setResult($output); $response->emit(); }
public function process(Vtiger_Request $request) { $recordId = $request->get('record'); $response = new Vtiger_Response(); $recordModel = Vtiger_PDF_Model::getInstanceById($recordId); if (Settings_PDF_Record_Model::delete($recordModel)) { $response->setResult(array('success' => 'true')); } else { $response->setResult(array('success' => 'false')); } $response->emit(); }
public function process(Vtiger_Request $request) { $recordId = $request->get('id'); $pdfModel = Vtiger_PDF_Model::getInstanceById($recordId); header('content-type: application/xml; charset=utf-8'); header('Pragma: public'); header('Cache-Control: private'); header('Content-Disposition: attachment; filename=' . $recordId . '_pdftemplate.xml'); header('Content-Description: PHP Generated Data'); $xml = new DOMDocument('1.0', 'utf-8'); $xml->preserveWhiteSpace = false; $xml->formatOutput = true; $xmlTemplate = $xml->createElement('pdf_template'); $xmlFields = $xml->createElement('fields'); $xmlField = $xml->createElement('field'); $cDataColumns = ['header_content', 'body_content', 'footer_content', 'conditions']; foreach (Settings_PDF_Module_Model::$allFields as $field) { if (in_array($field, $cDataColumns)) { $name = $xmlField->appendChild($xml->createElement($field)); $name->appendChild($xml->createCDATASection(html_entity_decode($pdfModel->getRaw($field)))); } elseif ($field === 'watermark_image') { if (file_exists($pdfModel->get($field))) { $watermarkPath = $pdfModel->get($field); //$watermarkName = basename($watermarkPath); $im = file_get_contents($watermarkPath); $imData = base64_encode($im); $xmlColumn = $xml->createElement('imageblob', $imData); $xmlField->appendChild($xmlColumn); $value = $watermarkPath; //$watermarkName; } else { $value = ''; } $xmlColumn = $xml->createElement($field, $value); } else { $value = $pdfModel->get($field); $xmlColumn = $xml->createElement($field, html_entity_decode($value, ENT_COMPAT, 'UTF-8')); } $xmlField->appendChild($xmlColumn); } $xmlFields->appendChild($xmlField); $xmlTemplate->appendChild($xmlFields); $xml->appendChild($xmlTemplate); print $xml->saveXML(); }
function buildSummaryModel() { if (isset($this->focus->column_fields['currency_id'])) { $currencyInfo = getCurrencyInfo($this->focus->column_fields['currency_id']); $currency = $currencyInfo['code']; } else { $currency = 'RUB'; } $associated_products = $this->associated_products; $final_details = $associated_products[1]['final_details']; $summaryModel = new Vtiger_PDF_Model(); $netTotal = $netTotalGoods = $netTotalServices = $discount = $handlingCharges = $handlingTaxes = 0; $adjustment = $grandTotal = 0; $productLineItemIndex = 0; $sh_tax_percent = 0; foreach ($associated_products as $productLineItem) { ++$productLineItemIndex; $netTotal += $productLineItem["netPrice{$productLineItemIndex}"]; if ($productLineItem["entityType{$productLineItemIndex}"] == 'Products') { $netTotalGoods += $productLineItem["netPrice{$productLineItemIndex}"]; } if ($productLineItem["entityType{$productLineItemIndex}"] == 'Services') { $netTotalServices += $productLineItem["netPrice{$productLineItemIndex}"]; } } $summaryModel->set("summaryNetTotal", $this->formatPrice($netTotal)); $summaryModel->set("summaryNetTotalGoods", $this->formatPrice($netTotalGoods)); $summaryModel->set("summaryNetTotalServices", $this->formatPrice($netTotalServices)); $discount_amount = $final_details["discount_amount_final"]; $discount_percent = $final_details["discount_percentage_final"]; $discount = 0.0; $discountGoods = 0.0; $discountServices = 0.0; if (!empty($discount_amount)) { $discount = $discount_amount; $discountGoods = $discount_amount; $discountServices = $discount_amount; } if (!empty($discount_percent)) { $discount = $discount_percent * $final_details["hdnSubTotal"] / 100; $discountGoods = $discount_percent * $netTotalGoods / 100; $discountServices = $discount_percent * $netTotalServices / 100; } $summaryModel->set("summaryDiscount", $this->formatPrice($discount)); $summaryModel->set("summaryDiscountGoods", $this->formatPrice($discountGoods)); $summaryModel->set("summaryDiscountServices", $this->formatPrice($discountServices)); $group_total_tax_percent = '0.00'; $overall_tax = 0; $overall_tax_goods = 0; $overall_tax_services = 0; //To calculate the group tax amount if ($final_details['taxtype'] == 'group') { $group_tax_details = $final_details['taxes']; for ($i = 0; $i < count($group_tax_details); $i++) { $group_total_tax_percent += $group_tax_details[$i]['percentage']; } $summaryModel->set("summaryTax", $this->formatPrice($final_details['tax_totalamount'])); $summaryModel->set("summaryTaxLiteral", $this->num2str($final_details['tax_totalamount'], false, $currency)); $summaryModel->set("summaryTaxPercent", $group_total_tax_percent); $overall_tax += $final_details['tax_totalamount']; $summaryModel->set("summaryTaxGoods", $this->formatPrice(($netTotalGoods - $discountGoods) * $group_total_tax_percent / 100.0)); $summaryModel->set("summaryTaxGoodsLiteral", $this->num2str(($netTotalGoods - $discountGoods) * $group_total_tax_percent / 100.0, false, $currency)); $summaryModel->set("summaryTaxGoodsPercent", $group_total_tax_percent); $overall_tax_goods += ($netTotalGoods - $discountGoods) * $group_total_tax_percent / 100.0; $summaryModel->set("summaryTaxServices", $this->formatPrice(($netTotalServices - $discountServices) * $group_total_tax_percent / 100.0)); $summaryModel->set("summaryTaxServicesLiteral", $this->num2str(($netTotalServices - $discountServices) * $group_total_tax_percent / 100.0, false, $currency)); $summaryModel->set("summaryTaxServicesPercent", $group_total_tax_percent); $overall_tax_services += ($netTotalServices - $discountServices) * $group_total_tax_percent / 100.0; } else { if ($final_details['taxtype'] == 'group_tax_inc') { $group_tax_details = $final_details['taxes']; for ($i = 0; $i < count($group_tax_details); $i++) { $group_total_tax_percent += $group_tax_details[$i]['percentage']; } $summaryModel->set("summaryTax", $this->formatPrice($final_details['tax_totalamount'])); $summaryModel->set("summaryTaxLiteral", $this->num2str($final_details['tax_totalamount'], false, $currency)); $summaryModel->set("summaryTaxPercent", $group_total_tax_percent); $overall_tax += $final_details['tax_totalamount']; $summaryModel->set("summaryNetTotal", $this->formatPrice($netTotal - $final_details['tax_totalamount'])); $summaryModel->set("summaryTaxGoods", $this->formatPrice(($netTotalGoods - $discountGoods) * $group_total_tax_percent / (100.0 + $group_total_tax_percent))); $summaryModel->set("summaryTaxGoodsLiteral", $this->num2str(($netTotalGoods - $discountGoods) * $group_total_tax_percent / (100.0 + $group_total_tax_percent), false, $currency)); $summaryModel->set("summaryTaxGoodsPercent", $group_total_tax_percent); $overall_tax_goods += ($netTotalGoods - $discountGoods) * $group_total_tax_percent / (100.0 + $group_total_tax_percent); $summaryModel->set("summaryNetTotalGoods", $this->formatPrice($netTotalGoods - ($netTotalGoods - $discountGoods) * $group_total_tax_percent / (100.0 + $group_total_tax_percent))); $summaryModel->set("summaryTaxServices", $this->formatPrice(($netTotalServices - $discountServices) * $group_total_tax_percent / (100.0 + $group_total_tax_percent))); $summaryModel->set("summaryTaxServicesLiteral", $this->num2str(($netTotalServices - $discountServices) * $group_total_tax_percent / (100.0 + $group_total_tax_percent), false, $currency)); $summaryModel->set("summaryTaxServicesPercent", $group_total_tax_percent); $overall_tax_services += ($netTotalServices - $discountServices) * $group_total_tax_percent / (100.0 + $group_total_tax_percent); $summaryModel->set("summaryNetTotalServices", $this->formatPrice($netTotalServices - ($netTotalServices - $discountServices) * $group_total_tax_percent / (100.0 + $group_total_tax_percent))); } else { $summaryModel->set("summaryTax", $this->formatPrice($this->totaltaxes)); $summaryModel->set("summaryTaxLiteral", $this->num2str($this->totaltaxes, false, $currency)); if ($netTotal > 0) { $summaryModel->set("summaryTaxPercent", $this->totaltaxes / $netTotal * 100); } else { $summaryModel->set("summaryTaxPercent", 0); } $overall_tax += $this->totaltaxes; $summaryModel->set("summaryTaxGoods", $this->formatPrice($this->totaltaxesGoods)); $summaryModel->set("summaryTaxGoodsLiteral", $this->num2str($this->totaltaxesGoods, false, $currency)); if ($netTotalGoods > 0) { $summaryModel->set("summaryTaxGoodsPercent", $this->totaltaxesGoods / $netTotalGoods * 100); } else { $summaryModel->set("summaryTaxGoodsPercent", 0); } $overall_tax_goods += $this->totaltaxesGoods; $summaryModel->set("summaryTaxServices", $this->formatPrice($this->totaltaxesServices)); $summaryModel->set("summaryTaxServicesLiteral", $this->num2str($this->totaltaxesServices, false, $currency)); if ($netTotalServices > 0) { $summaryModel->set("summaryTaxServicesPercent", $this->totaltaxesServices / $netTotalServices * 100); } else { $summaryModel->set("summaryTaxServicesPercent", 0); } $overall_tax_services += $this->totaltaxesServices; } } //Shipping & Handling taxes $sh_tax_details = $final_details['sh_taxes']; for ($i = 0; $i < count($sh_tax_details); $i++) { $sh_tax_percent = $sh_tax_percent + $sh_tax_details[$i]['percentage']; } //obtain the Currency Symbol $currencySymbol = $this->buildCurrencySymbol(); $summaryModel->set("summaryShipping", $this->formatPrice($final_details['shipping_handling_charge'])); $summaryModel->set("summaryShippingTax", $this->formatPrice($final_details['shtax_totalamount'])); $summaryModel->set("summaryShippingTaxPercent", $sh_tax_percent); $summaryModel->set("summaryAdjustment", $this->formatPrice($final_details['adjustment'])); $summaryModel->set("summaryGrandTotal", $this->formatPrice($final_details['grandTotal'])); // TODO add currency string $summaryModel->set("summaryGrandTotalLiteral", $this->num2str($final_details['grandTotal'], false, $currency)); $overall_tax += $final_details['shtax_totalamount']; $overall_tax_goods += $final_details['shtax_totalamount']; $summaryModel->set("summaryOverallTax", $this->formatPrice(round($overall_tax))); $summaryModel->set("summaryOverallTaxLiteral", $this->num2str(round($overall_tax), false, $currency)); $summaryModel->set("summaryOverallTaxGoods", $this->formatPrice(round($overall_tax_goods))); $summaryModel->set("summaryOverallTaxGoodsLiteral", $this->num2str(round($overall_tax_goods), false, $currency)); $summaryModel->set("summaryOverallTaxServices", $this->formatPrice(round($overall_tax_services))); $summaryModel->set("summaryOverallTaxServicesLiteral", $this->num2str(round($overall_tax_services), false, $currency)); if ($final_details['taxtype'] == 'group_tax_inc') { $summaryModel->set("summaryGrandTotalGoods", $this->formatPrice($netTotalGoods - $discountGoods + $final_details['shipping_handling_charge'] + $final_details['adjustment'])); $summaryModel->set("summaryGrandTotalGoodsLiteral", $this->num2str($netTotalGoods - $discountGoods + $final_details['shipping_handling_charge'] + $final_details['adjustment'], false, $currency)); $summaryModel->set("summaryGrandTotalServices", $this->formatPrice($netTotalServices - $discountServices + $final_details['adjustment'])); $summaryModel->set("summaryGrandTotalServicesLiteral", $this->num2str($netTotalServices - $discountServices + $final_details['adjustment'], false, $currency)); } else { $summaryModel->set("summaryGrandTotalGoods", $this->formatPrice($netTotalGoods - $discountGoods + $overall_tax_goods + $final_details['shipping_handling_charge'] + $final_details['adjustment'])); $summaryModel->set("summaryGrandTotalGoodsLiteral", $this->num2str($netTotalGoods - $discountGoods + $overall_tax_goods + $final_details['shipping_handling_charge'] + $final_details['adjustment'], false, $currency)); $summaryModel->set("summaryGrandTotalServices", $this->formatPrice($netTotalServices - $discountServices + $overall_tax_services + $final_details['adjustment'])); $summaryModel->set("summaryGrandTotalServicesLiteral", $this->num2str($netTotalServices - $discountServices + $overall_tax_services + $final_details['adjustment'], false, $currency)); } return $summaryModel; }
/** * Export record to PDF file * @param int $recordId - id of a record * @param string $moduleName - name of records module * @param int $templateId - id of pdf template * @param string $filePath - path name for saving pdf file * @param string $saveFlag - save option flag */ public function export($recordId, $moduleName, $templateId, $filePath = '', $saveFlag = '') { $template = Vtiger_PDF_Model::getInstanceById($templateId, $moduleName); $template->setMainRecordId($recordId); $pageOrientation = $template->get('page_orientation') == 'PLL_PORTRAIT' ? 'P' : 'L'; $pdf = new self('c', $template->get('page_format'), 0, '', $template->get('margin_left'), $template->get('margin_right'), $template->get('margin_top'), $template->get('margin_bottom'), $template->get('margin_top'), $template->get('margin_bottom'), $pageOrientation); $pdf->setTemplateId($templateId); $pdf->setRecordId($recordId); $pdf->setModuleName($moduleName); $pdf->setLanguage($template->get('language')); $pdf->setFileName($template->get('filename')); $origLanguage = vglobal('default_language'); vglobal('default_language', $template->get('language')); $pdf->parseParams($template->getParameters()); $pdf->setHeader('Header', $template->getHeader()); $pdf->setFooter('Footer', $template->getFooter()); $html = $template->getBody(); $pdf->loadHTML($html); vglobal('default_language', $origLanguage); $pdf->output($filePath, $saveFlag); }
function buildWatermarkModel() { $watermarkModel = new Vtiger_PDF_Model(); $watermarkModel->set('content', $this->getWatermarkContent()); return $watermarkModel; }
/** * Checks if given record has valid pdf template * @param Vtiger_Request $request * @return boolean true if valid template exists for this record */ function hasValidTemplate(Vtiger_Request $request) { $recordId = $request->get('record'); $moduleName = $request->get('modulename'); $view = $request->get('view'); $pdfModel = new Vtiger_PDF_Model(); $pdfModel->setMainRecordId($recordId); $valid = $pdfModel->checkActiveTemplates($recordId, $moduleName, $view); $output = ['valid' => $valid]; $response = new Vtiger_Response(); $response->setResult($output); $response->emit(); }
/** * Returns template records by module name * @param string $moduleName - module name for which template was created * @return array of template record models */ public function getTemplatesByModule($moduleName) { return Vtiger_PDF_Model::getTemplatesByModule($moduleName); }
public function step($step, Vtiger_Request $request) { $viewer = $this->getViewer($request); $moduleName = $request->getModule(); $qualifiedModuleName = $request->getModule(false); $recordId = $request->get('record'); if ($recordId) { $pdfModel = Vtiger_PDF_Model::getInstanceById($recordId); $viewer->assign('RECORDID', $recordId); $viewer->assign('MODE', 'edit'); $selectedModuleName = $pdfModel->get('module_name'); } else { $selectedModuleName = $request->get('source_module'); $pdfModel = Settings_PDF_Record_Model::getCleanInstance(); } $viewer->assign('SELECTED_MODULE', $selectedModuleName); $viewer->assign('PDF_MODEL', $pdfModel); $allModules = Settings_PDF_Module_Model::getSupportedModules(); $viewer->assign('ALL_MODULES', $allModules); $viewer->assign('MODULE', $moduleName); $viewer->assign('QUALIFIED_MODULE', $qualifiedModuleName); $viewer->assign('SOURCE_MODULE', $selectedModuleName); switch ($step) { case 'step8': $viewer->view('Step8.tpl', $qualifiedModuleName); break; case 'step7': $viewer->view('Step7.tpl', $qualifiedModuleName); break; case 'step6': $moduleModel = Vtiger_Module_Model::getInstance($pdfModel->get('module_name')); $recordStructureInstance = Vtiger_RecordStructure_Model::getInstanceForModule($moduleModel); $viewer->assign('RECORD_STRUCTURE', $recordStructureInstance->getStructure()); $viewer->assign('ADVANCE_CRITERIA', Vtiger_AdvancedFilter_Helper::transformToAdvancedFilterCondition($pdfModel->get('conditions'))); $viewer->view('Step6.tpl', $qualifiedModuleName); break; case 'step5': $relatedModules = Settings_PDF_Module_Model::getRelatedModules($pdfModel->get('module_name')); if (count($relatedModules) > 0) { $relatedFields = Settings_PDF_Module_Model::getMainModuleFields(reset($relatedModules)); } else { $relatedFields = []; } $specialFunctions = Vtiger_PDF_Model::getSpecialFunctions($allModules[key($allModules)]->getName()); $viewer->assign('RELATED_MODULES', $relatedModules); $viewer->assign('RELATED_FIELDS', $relatedFields); $viewer->assign('SPECIAL_FUNCTIONS', $specialFunctions); $viewer->view('Step5.tpl', $qualifiedModuleName); break; case 'step4': $relatedModules = Settings_PDF_Module_Model::getRelatedModules($pdfModel->get('module_name')); if (count($relatedModules) > 0) { $relatedFields = Settings_PDF_Module_Model::getMainModuleFields(reset($relatedModules)); } else { $relatedFields = []; } $specialFunctions = Vtiger_PDF_Model::getSpecialFunctions($allModules[key($allModules)]->getName()); $viewer->assign('RELATED_MODULES', $relatedModules); $viewer->assign('RELATED_FIELDS', $relatedFields); $viewer->assign('SPECIAL_FUNCTIONS', $specialFunctions); $viewer->view('Step4.tpl', $qualifiedModuleName); break; case 'step3': $relatedModules = Settings_PDF_Module_Model::getRelatedModules($pdfModel->get('module_name')); if (count($relatedModules) > 0) { $relatedFields = Settings_PDF_Module_Model::getMainModuleFields(reset($relatedModules)); } else { $relatedFields = []; } $specialFunctions = Vtiger_PDF_Model::getSpecialFunctions($allModules[key($allModules)]->getName()); $viewer->assign('RELATED_MODULES', $relatedModules); $viewer->assign('RELATED_FIELDS', $relatedFields); $viewer->assign('SPECIAL_FUNCTIONS', $specialFunctions); $viewer->view('Step3.tpl', $qualifiedModuleName); break; case 'step2': $viewer->view('Step2.tpl', $qualifiedModuleName); break; case 'step1': default: $viewer->view('Step1.tpl', $qualifiedModuleName); break; } }
function generate(Vtiger_Request $request) { $moduleName = $request->getModule(); $recordId = $request->get('record'); $templateIds = $request->get('template'); $singlePdf = $request->get('single_pdf') == 1 ? true : false; $emailPdf = $request->get('email_pdf') == 1 ? true : false; if (!is_array($recordId)) { $recordId = [$recordId]; } if (count($templateIds) == 1 && count($recordId) == 1) { if ($emailPdf) { $filePath = 'cache/pdf/' . $recordId[0] . '_' . time() . '.pdf'; Vtiger_PDF_Model::exportToPdf($recordId[0], $moduleName, $templateIds[0], $filePath, 'F'); if (file_exists($filePath)) { header('Location: index.php?module=OSSMail&view=compose&pdf_path=' . $filePath); exit; } else { throw new AppException(vtranslate('LBL_EXPORT_ERROR', 'Settings:PDF')); } } else { Vtiger_PDF_Model::exportToPdf($recordId[0], $moduleName, $templateIds[0]); } } else { if (count($templateIds) == 1 && count($recordId) > 1) { Vtiger_PDF_Model::exportToPdf($recordId, $moduleName, $templateIds[0]); } else { // save multiple templates as pdf files if ($singlePdf) { $handlerClass = Vtiger_Loader::getComponentClassName('Pdf', 'mPDF', $moduleName); $pdf = new $handlerClass(); $styles = ''; $headers = ''; $footers = ''; $classes = ''; $body = ''; $origLanguage = vglobal('default_language'); foreach ($recordId as $index => $record) { $templateIdsTemp = $templateIds; $pdf->setRecordId($recordId[0]); $pdf->setModuleName($moduleName); $firstTemplate = array_shift($templateIdsTemp); $template = Vtiger_PDF_Model::getInstanceById($firstTemplate); $template->setMainRecordId($record); $pdf->setLanguage($template->get('language')); vglobal('default_language', $template->get('language')); $template->getParameters(); //$pdf->parseParams($template->getParameters()); $styles .= " @page template_{$record}_{$firstTemplate} {\n\t\t\t\t\t\tsheet-size: {$template->getFormat()};\n\t\t\t\t\t\tmargin-top: {$template->get('margin_top')}mm;\n\t\t\t\t\t\tmargin-left: {$template->get('margin_left')}mm;\n\t\t\t\t\t\tmargin-right: {$template->get('margin_right')}mm;\n\t\t\t\t\t\tmargin-bottom: {$template->get('margin_bottom')}mm;\n\t\t\t\t\t\todd-header-name: html_Header_{$record}_{$firstTemplate};\n\t\t\t\t\t\todd-footer-name: html_Footer_{$record}_{$firstTemplate};\n\t\t\t\t\t}"; $html = ''; $headers .= ' <htmlpageheader name="Header_' . $record . '_' . $firstTemplate . '">' . $template->getHeader() . '</htmlpageheader>'; $footers .= ' <htmlpagefooter name="Footer_' . $record . '_' . $firstTemplate . '">' . $template->getFooter() . '</htmlpagefooter>'; $classes .= ' div.page_' . $record . '_' . $firstTemplate . ' { page-break-before: always; page: template_' . $record . '_' . $firstTemplate . '; }'; $body .= '<div class="page_' . $record . '_' . $firstTemplate . '">' . $template->getBody() . '</div>'; foreach ($templateIdsTemp as $id) { $template = Vtiger_PDF_Model::getInstanceById($id); $template->setMainRecordId($record); $pdf->setLanguage($template->get('language')); vglobal('default_language', $template->get('language')); // building parameters $parameters = $template->getParameters(); //$pdf->parseParams($parameters); $styles .= " @page template_{$record}_{$id} {\n\t\t\t\t\t\t\tsheet-size: {$template->getFormat()};\n\t\t\t\t\t\t\tmargin-top: {$template->get('margin_top')}mm;\n\t\t\t\t\t\t\tmargin-left: {$template->get('margin_left')}mm;\n\t\t\t\t\t\t\tmargin-right: {$template->get('margin_right')}mm;\n\t\t\t\t\t\t\tmargin-bottom: {$template->get('margin_bottom')}mm;\n\t\t\t\t\t\t\todd-header-name: html_Header_{$record}_{$id};\n\t\t\t\t\t\t\todd-footer-name: html_Footer_{$record}_{$id};\n\t\t\t\t\t\t}"; $html = ''; $headers .= ' <htmlpageheader name="Header_' . $record . '_' . $id . '">' . $template->getHeader() . '</htmlpageheader>'; $footers .= ' <htmlpagefooter name="Footer_' . $record . '_' . $id . '">' . $template->getFooter() . '</htmlpagefooter>'; $classes .= ' div.page_' . $record . '_' . $id . ' { page-break-before: always; page: template_' . $record . '_' . $id . '; }'; $body .= '<div class="page_' . $record . '_' . $id . '">' . $template->getBody() . '</div>'; } } vglobal('default_language', $origLanguage); $html = "<html><head><style>{$styles} {$classes}</style></head><body>{$headers} {$footers} {$body}</body></html>"; $pdf->loadHTML($html); $pdf->setFileName(vtranslate('LBL_PDF_MANY_IN_ONE')); $pdf->output(); } else { mt_srand(time()); $postfix = time() . '_' . mt_rand(0, 1000); $pdfFiles = []; $origLanguage = vglobal('default_language'); foreach ($templateIds as $id) { foreach ($recordId as $record) { $handlerClass = Vtiger_Loader::getComponentClassName('Pdf', 'mPDF', $moduleName); $pdf = new $handlerClass(); $pdf->setTemplateId($id); $pdf->setRecordId($record); $pdf->setModuleName($moduleName); $template = Vtiger_PDF_Model::getInstanceById($id); $template->setMainRecordId($record); $pdf->setLanguage($template->get('language')); $pdf->setFileName($template->get('filename')); vglobal('default_language', $template->get('language')); $pdf->parseParams($template->getParameters()); $html = ''; $pdf->setHeader('Header', $template->getHeader()); $pdf->setFooter('Footer', $template->getFooter()); $html = $template->getBody(); $pdf->loadHTML($html); $pdfFileName = 'cache/pdf/' . $record . '_' . $pdf->getFileName() . '_' . $postfix . '.pdf'; $pdf->output($pdfFileName, 'F'); if (file_exists($pdfFileName)) { $pdfFiles[] = $pdfFileName; } unset($pdf, $template); } } vglobal('default_language', $origLanguage); if (!empty($pdfFiles)) { if (!empty($emailPdf)) { Vtiger_PDF_Model::attachToEmail($postfix); } else { Vtiger_PDF_Model::zipAndDownload($pdfFiles); } } } } } }
/** * Function transforms Advance filter to workflow conditions */ function transformAdvanceFilterToWorkFlowFilter(Vtiger_PDF_Model &$pdfModel) { $conditions = $pdfModel->get('conditions'); $wfCondition = []; if (!empty($conditions)) { foreach ($conditions as $index => $condition) { $columns = $condition['columns']; if ($index == '1' && empty($columns)) { $wfCondition[] = array('fieldname' => '', 'operation' => '', 'value' => '', 'valuetype' => '', 'joincondition' => '', 'groupid' => '0'); } if (!empty($columns) && is_array($columns)) { foreach ($columns as $column) { $wfCondition[] = array('fieldname' => $column['columnname'], 'operation' => $column['comparator'], 'value' => $column['value'], 'valuetype' => $column['valuetype'], 'joincondition' => $column['column_condition'], 'groupjoin' => $condition['condition'], 'groupid' => $column['groupid']); } } } } $pdfModel->set('conditions', $wfCondition); }
/** * Export record to PDF file * @param int $recordId - id of a record * @param string $moduleName - name of records module * @param int $templateId - id of pdf template * @param string $filePath - path name for saving pdf file * @param string $saveFlag - save option flag */ public function export($recordId, $moduleName, $templateId, $filePath = '', $saveFlag = '') { $pdf = new self(); $pdf->setTemplateId($templateId); $pdf->setRecordId($recordId); $pdf->setModuleName($moduleName); $template = Vtiger_PDF_Model::getInstanceById($templateId, $moduleName); $template->setMainRecordId($recordId); $pdf->setLanguage($template->get('language')); $pdf->setFileName($template->get('filename')); $origLanguage = vglobal('default_language'); vglobal('default_language', $template->get('language')); $pdf->parseParams($template->getParameters()); $html = ''; $pdf->setHeader('Header', $template->getHeader()); $pdf->setFooter('Footer', $template->getFooter()); $html = $template->getBody(); $pdf->loadHTML($html); vglobal('default_language', $origLanguage); $pdf->output($filePath, $saveFlag); }