public function preDisplay() { parent::preDisplay(); // settings for disable smarty php tags $this->ss->security_settings['PHP_TAGS'] = false; $this->ss->security = true; if (defined('SUGAR_SHADOW_PATH')) { $this->ss->secure_dir[] = SUGAR_SHADOW_PATH; } // header/footer settings $this->setPrintHeader(false); $this->setPrintFooter(true); // always print page number at least if (!empty($_REQUEST['pdf_template_id'])) { $pdfTemplate = BeanFactory::newBean('PdfManager'); if ($pdfTemplate->retrieve($_REQUEST['pdf_template_id'], false) !== null) { $previewMode = FALSE; if (!empty($_REQUEST['pdf_preview']) && $_REQUEST['pdf_preview'] == 1) { $previewMode = true; $this->bean = BeanFactory::newBean($pdfTemplate->base_module); } $this->SetCreator(PDF_CREATOR); $this->SetAuthor($pdfTemplate->author); $this->SetTitle($pdfTemplate->title); $this->SetSubject($pdfTemplate->subject); $this->SetKeywords($pdfTemplate->keywords); $this->templateLocation = $this->buildTemplateFile($pdfTemplate, $previewMode); $headerLogo = ''; if (!empty($pdfTemplate->header_logo)) { // Create a temporary copy of the header logo // and append the original filename, so TCPDF can figure the extension $headerLogo = 'upload/' . $pdfTemplate->id . $pdfTemplate->header_logo; copy('upload/' . $pdfTemplate->id, $headerLogo); } if (!empty($pdfTemplate->header_logo) || !empty($pdfTemplate->header_title) || !empty($pdfTemplate->header_text)) { $this->setHeaderData($headerLogo, PDF_HEADER_LOGO_WIDTH, $pdfTemplate->header_title, $pdfTemplate->header_text); $this->setPrintHeader(true); } if (!empty($pdfTemplate->footer_text)) { $this->footerText = $pdfTemplate->footer_text; } $filenameParts = array(); if (!empty($this->bean) && !empty($this->bean->name)) { $filenameParts[] = $this->bean->name; } if (!empty($pdfTemplate->name)) { $filenameParts[] = $pdfTemplate->name; } $cr = array(' ', "\r", "\n", "/"); $this->pdfFilename = str_replace($cr, '_', implode("_", $filenameParts) . ".pdf"); } } if ($previewMode === FALSE) { require_once 'modules/PdfManager/PdfManagerHelper.php'; $fields = PdfManagerHelper::parseBeanFields($this->bean, true); } else { $fields = array(); } if ($this->module == 'Quotes' && $previewMode === FALSE) { global $locale; require_once 'modules/Quotes/Quote.php'; require_once 'modules/Quotes/config.php'; require_once 'modules/Currencies/Currency.php'; $currency = BeanFactory::getBean('Currencies'); $format_number_array = array('currency_symbol' => true, 'type' => 'sugarpdf', 'currency_id' => $this->bean->currency_id, 'charset_convert' => true); $currency->retrieve($this->bean->currency_id); $fields['currency_iso'] = $currency->iso4217; // Adding Tax Rate Field $fields['taxrate_value'] = format_number_sugarpdf($this->bean->taxrate_value, $locale->getPrecision(), $locale->getPrecision(), array('percentage' => true)); $this->bean->load_relationship('product_bundles'); $product_bundle_list = $this->bean->product_bundles->getBeans(); usort($product_bundle_list, array('ProductBundle', 'compareProductBundlesByIndex')); $bundles = array(); $count = 0; foreach ($product_bundle_list as $ordered_bundle) { $bundleFields = PdfManagerHelper::parseBeanFields($ordered_bundle, true); $bundleFields['products'] = array(); $product_bundle_line_items = $ordered_bundle->get_product_bundle_line_items(); foreach ($product_bundle_line_items as $product_bundle_line_item) { $bundleFields['products'][$count] = PdfManagerHelper::parseBeanFields($product_bundle_line_item, true); if ($product_bundle_line_item->object_name == "ProductBundleNote") { $bundleFields['products'][$count]['name'] = $bundleFields['products'][$count]['description']; } else { // Special case about discount amount if ($product_bundle_line_item->discount_select) { $bundleFields['products'][$count]['discount_amount'] = format_number($product_bundle_line_item->discount_amount, $locale->getPrecision(), $locale->getPrecision()) . '%'; } // Special case about ext price $bundleFields['products'][$count]['ext_price'] = format_number_sugarpdf($product_bundle_line_item->discount_price * $product_bundle_line_item->quantity, $locale->getPrecision(), $locale->getPrecision(), $format_number_array); } $count++; } $bundles[] = $bundleFields; } $this->ss->assign('product_bundles', $bundles); } $this->ss->assign('fields', $fields); }
/** * Make array from bean * * @param array $module_instance -- Instance of module * @param boolean $recursive -- If TRUE parse related one-to-many fields * @return array -- key : field Name * value : field Value */ public static function parseBeanFields($module_instance, $recursive = FALSE) { global $app_list_strings; $module_instance->ACLFilterFields(); $fields_module = array(); foreach ($module_instance->toArray() as $name => $value) { if (isset($module_instance->field_defs[$name]['type']) && ($module_instance->field_defs[$name]['type'] == 'enum' || $module_instance->field_defs[$name]['type'] == 'radio' || $module_instance->field_defs[$name]['type'] == 'radioenum') && isset($module_instance->field_defs[$name]['options']) && isset($app_list_strings[$module_instance->field_defs[$name]['options']]) && isset($app_list_strings[$module_instance->field_defs[$name]['options']][$value])) { $fields_module[$name] = $app_list_strings[$module_instance->field_defs[$name]['options']][$value]; $fields_module[$name] = str_replace(array(''', '''), "'", $fields_module[$name]); } elseif (isset($module_instance->field_defs[$name]['type']) && $module_instance->field_defs[$name]['type'] == 'multienum' && isset($module_instance->field_defs[$name]['options']) && isset($app_list_strings[$module_instance->field_defs[$name]['options']])) { $multienums = unencodeMultienum($value); $multienums_value = array(); foreach ($multienums as $multienum) { if (isset($app_list_strings[$module_instance->field_defs[$name]['options']][$multienum])) { $multienums_value[] = $app_list_strings[$module_instance->field_defs[$name]['options']][$multienum]; } else { $multienums_value[] = $multienum; } } $fields_module[$name] = implode(', ', $multienums_value); $fields_module[$name] = str_replace(array(''', '''), "'", $fields_module[$name]); } elseif ($recursive && isset($module_instance->field_defs[$name]['type']) && $module_instance->field_defs[$name]['type'] == 'link' && $module_instance->load_relationship($name) && self::hasOneRelationship($module_instance, $name) && count($module_instance->{$name}->get()) == 1) { $related_module = $module_instance->{$name}->getRelatedModuleName(); $related_instance = BeanFactory::getBean($related_module); $related_instance_id = $module_instance->{$name}->get(); if ($related_instance->retrieve($related_instance_id[0]) === null) { $GLOBALS['log']->fatal(__FILE__ . ' Failed loading module ' . $related_module . ' with id ' . $related_instance_id[0]); } $fields_module[$name] = self::parseBeanFields($related_instance, FALSE); } elseif (isset($module_instance->field_defs[$name]['type']) && $module_instance->field_defs[$name]['type'] == 'currency' && isset($module_instance->currency_id)) { global $locale; $format_number_array = array('currency_symbol' => true, 'currency_id' => !empty($module_instance->field_defs[$name]['currency_id']) ? $module_instance->field_defs[$name]['currency_id'] : $module_instance->currency_id, 'type' => 'sugarpdf', 'charset_convert' => true); $fields_module[$name] = format_number_sugarpdf($module_instance->{$name}, $locale->getPrecision(), $locale->getPrecision(), $format_number_array); } elseif (isset($module_instance->field_defs[$name]['type']) && $module_instance->field_defs[$name]['type'] == 'decimal') { global $locale; $format_number_array = array('convert' => false); if (!isset($module_instance->{$name})) { $module_instance->{$name} = 0; } $fields_module[$name] = format_number_sugarpdf($module_instance->{$name}, $locale->getPrecision(), $locale->getPrecision(), $format_number_array); } elseif (isset($module_instance->field_defs[$name]['type']) && $module_instance->field_defs[$name]['type'] == 'image') { $fields_module[$name] = $GLOBALS['sugar_config']['upload_dir'] . "/" . $value; } elseif (is_string($value)) { $value = nl2br(stripslashes($value)); if (isset($module_instance->field_defs[$name]['type']) && $module_instance->field_defs[$name]['type'] === 'html') { $value = htmlspecialchars_decode($value, ENT_QUOTES); } $fields_module[$name] = $value; } } return $fields_module; }
function display() { global $mod_strings, $app_strings, $app_list_strings; global $locale; require_once 'modules/Quotes/Quote.php'; require 'modules/Quotes/config.php'; parent::display(); // cn: bug 8587 handle strings for export /*$mod_strings = $locale->translateStringPack($mod_strings, $locale->getExportCharset()); $app_strings = $locale->translateStringPack($app_strings, $locale->getExportCharset()); $app_list_strings = $locale->translateStringPack($app_list_strings, $locale->getExportCharset()); */ $GLOBALS['log']->info("Quote layout view: Invoice"); $addressBS[0][$mod_strings['LBL_PDF_BILLING_ADDRESS']] = $this->bean->billing_contact_name; $addressBS[1][$mod_strings['LBL_PDF_BILLING_ADDRESS']] = $this->bean->billing_account_name; $addressBS[2][$mod_strings['LBL_PDF_BILLING_ADDRESS']] = $this->bean->billing_address_street; if (!empty($this->bean->billing_address_city) || !empty($this->bean->billing_address_state) || !empty($this->bean->billing_address_postalcode)) { $addressBS[3][$mod_strings['LBL_PDF_BILLING_ADDRESS']] = $this->bean->billing_address_city . ", " . $this->bean->billing_address_state . " " . $this->bean->billing_address_postalcode; } else { $addressBS[3][$mod_strings['LBL_PDF_BILLING_ADDRESS']] = ''; } $addressBS[4][$mod_strings['LBL_PDF_BILLING_ADDRESS']] = $this->bean->billing_address_country; $addressBS[0][$mod_strings['LBL_PDF_SHIPPING_ADDRESS']] = $this->bean->shipping_contact_name; $addressBS[1][$mod_strings['LBL_PDF_SHIPPING_ADDRESS']] = $this->bean->shipping_account_name; $addressBS[2][$mod_strings['LBL_PDF_SHIPPING_ADDRESS']] = $this->bean->shipping_address_street; if (!empty($this->bean->shipping_address_city) || !empty($this->bean->shipping_address_state) || !empty($this->bean->shipping_address_postalcode)) { $addressBS[3][$mod_strings['LBL_PDF_SHIPPING_ADDRESS']] = $this->bean->shipping_address_city . ", " . $this->bean->shipping_address_state . " " . $this->bean->shipping_address_postalcode; } else { $addressBS[3][$mod_strings['LBL_PDF_SHIPPING_ADDRESS']] = ''; } $addressBS[4][$mod_strings['LBL_PDF_SHIPPING_ADDRESS']] = $this->bean->shipping_address_country; // Write the Billing/Shipping array $this->writeHTMLTable($addressBS, false, $this->addressOptions); require_once 'modules/Currencies/Currency.php'; $currency = BeanFactory::getBean('Currencies'); //// settings $format_number_array = array('currency_symbol' => true, 'type' => 'sugarpdf', 'currency_id' => $this->bean->currency_id, 'charset_convert' => true); $currency->retrieve($this->bean->currency_id); $this->bean->load_relationship('product_bundles'); $product_bundle_list = $this->bean->product_bundles->getBeans(); usort($product_bundle_list, array('ProductBundle', 'compareProductBundlesByIndex')); if (is_array($product_bundle_list)) { foreach ($product_bundle_list as $product_bundle) { if (isset($this->bean->show_line_nums) && $this->bean->show_line_nums == 1) { //$options['showRowCount']=1; } if (key_exists($product_bundle->bundle_stage, $in_total_group_stages)) { $count = 0; $item = array(); $product_list = $product_bundle->get_products(); if (is_array($product_list)) { $bundle_list = $product_bundle->get_product_bundle_line_items(); if (is_array($bundle_list)) { while (list($key, $line_item) = each($bundle_list)) { if ($line_item->object_name == "Product") { $item[$count][$mod_strings['LBL_PDF_ITEM_QUANTITY']] = format_number_sugarpdf($line_item->quantity, $locale->getPrecision(), $locale->getPrecision()); $item[$count][$mod_strings['LBL_PDF_PART_NUMBER']] = $line_item->mft_part_num; $item[$count][$mod_strings['LBL_PDF_ITEM_PRODUCT']] = stripslashes($line_item->name); if (!empty($line_item->description)) { $item[$count][$mod_strings['LBL_PDF_ITEM_PRODUCT']] .= "\n" . stripslashes($line_item->description); } $item[$count][$mod_strings['LBL_PDF_ITEM_LIST_PRICE']]['value'] = format_number_sugarpdf($line_item->list_usdollar, $locale->getPrecision(), $locale->getPrecision(), array_merge($format_number_array, array('convert' => true))); $item[$count][$mod_strings['LBL_PDF_ITEM_UNIT_PRICE']]['value'] = format_number_sugarpdf($line_item->discount_usdollar, $locale->getPrecision(), $locale->getPrecision(), array_merge($format_number_array, array('convert' => true))); $item[$count][$mod_strings['LBL_PDF_ITEM_EXT_PRICE']]['value'] = format_number_sugarpdf($line_item->discount_usdollar * $line_item->quantity, $locale->getPrecision(), $locale->getPrecision(), array_merge($format_number_array, array('convert' => true))); if (format_number($product_bundle->deal_tot, $locale->getPrecision(), $locale->getPrecision()) != 0.0) { if ($line_item->discount_select) { $item[$count][$mod_strings['LBL_PDF_ITEM_DISCOUNT']]['value'] = format_number($line_item->discount_amount, $locale->getPrecision(), $locale->getPrecision()) . "%"; } else { $item[$count][$mod_strings['LBL_PDF_ITEM_DISCOUNT']]['value'] = format_number_sugarpdf($line_item->discount_amount, $locale->getPrecision(), $locale->getPrecision(), array_merge($format_number_array, array('convert' => false))); } $item[$count][$mod_strings['LBL_PDF_ITEM_DISCOUNT']]['options'] = array("align" => "R"); } $item[$count][$mod_strings['LBL_PDF_ITEM_LIST_PRICE']]['options'] = array("align" => "R"); $item[$count][$mod_strings['LBL_PDF_ITEM_UNIT_PRICE']]['options'] = array("align" => "R"); $item[$count][$mod_strings['LBL_PDF_ITEM_EXT_PRICE']]['options'] = array("align" => "R"); $count++; } else { if ($line_item->object_name == "ProductBundleNote") { $item[$count][$mod_strings['LBL_PDF_ITEM_QUANTITY']] = ""; $item[$count][$mod_strings['LBL_PDF_PART_NUMBER']] = ""; $item[$count][$mod_strings['LBL_PDF_ITEM_PRODUCT']] = stripslashes($line_item->description); $item[$count][$mod_strings['LBL_PDF_ITEM_LIST_PRICE']] = ""; $item[$count][$mod_strings['LBL_PDF_ITEM_UNIT_PRICE']] = ""; $item[$count][$mod_strings['LBL_PDF_ITEM_EXT_PRICE']] = ""; $item[$count][$mod_strings['LBL_PDF_ITEM_DISCOUNT']] = ""; //$item[$count][$mod_strings['LBL_PDF_ITEM_SELECT_DISCOUNT']] = ""; $count++; } } } } } $this->MultiCell(0, 0, "<b>" . $product_bundle->name . "</b>", 0, 'L', 0, 1, "", "", true, 0, true); if (format_number($product_bundle->deal_tot, $locale->getPrecision(), $locale->getPrecision()) == 0.0) { $this->itemOptions["width"][$mod_strings["LBL_PDF_PART_NUMBER"]] = "30%"; $this->itemOptions["width"][$mod_strings["LBL_PDF_ITEM_PRODUCT"]] = "30%"; } else { // If you change these two values, change the values above in the _initOptions() function to match these $this->itemOptions["width"][$mod_strings["LBL_PDF_PART_NUMBER"]] = "25%"; $this->itemOptions["width"][$mod_strings["LBL_PDF_ITEM_PRODUCT"]] = "25%"; } if (count($item) > 0) { $this->writeCellTable($item, $this->itemOptions); } if ($pdf_group_subtotal) { $total = array(); $total[0]['BLANK'] = ' '; $total[0]['TITLE'] = $mod_strings['LBL_PDF_SUBTOTAL']; $total[0]['VALUE']['value'] = format_number_sugarpdf($product_bundle->subtotal, $locale->getPrecision(), $locale->getPrecision(), $format_number_array); $total[0]['VALUE']['options'] = array("align" => "R"); $i = 1; if (format_number_sugarpdf($product_bundle->deal_tot, $locale->getPrecision(), $locale->getPrecision()) != 0.0) { $total[1]['BLANK'] = ' '; $total[1]['TITLE'] = $mod_strings['LBL_PDF_DISCOUNT']; $total[1]['VALUE']['value'] = format_number_sugarpdf($product_bundle->deal_tot, $locale->getPrecision(), $locale->getPrecision(), $format_number_array); $total[1]['VALUE']['options'] = array("align" => "R"); $total[2]['BLANK'] = ' '; $total[2]['TITLE'] = $mod_strings['LBL_PDF_NEW_SUB']; $total[2]['VALUE']['value'] = format_number_sugarpdf($product_bundle->new_sub, $locale->getPrecision(), $locale->getPrecision(), $format_number_array); $total[2]['VALUE']['options'] = array("align" => "R"); $i = 3; } $total[$i]['BLANK'] = ' '; $total[$i]['TITLE'] = $mod_strings['LBL_PDF_TAX']; $total[$i]['VALUE']['value'] = format_number_sugarpdf($product_bundle->tax, $locale->getPrecision(), $locale->getPrecision(), $format_number_array); $total[$i]['VALUE']['options'] = array("align" => "R"); $i++; $total[$i]['BLANK'] = ' '; $total[$i]['TITLE'] = $mod_strings['LBL_PDF_SHIPPING']; $total[$i]['VALUE']['value'] = format_number_sugarpdf($product_bundle->shipping, $locale->getPrecision(), $locale->getPrecision(), $format_number_array); $total[$i]['VALUE']['options'] = array("align" => "R"); $i++; $total[$i]['BLANK'] = ' '; $total[$i]['TITLE'] = $mod_strings['LBL_PDF_TOTAL']; $total[$i]['VALUE']['value'] = format_number_sugarpdf($product_bundle->total, $locale->getPrecision(), $locale->getPrecision(), $format_number_array); $total[$i]['VALUE']['options'] = array("align" => "R"); $this->drawLine(); $this->writeCellTable($total, $this->totalOptions); } } } } if (isset($this->bean->calc_grand_total) && $this->bean->calc_grand_total == 1) { $total = array(); $total[0]['BLANK'] = ' '; $total[0]['TITLE0'] = $mod_strings['LBL_PDF_CURRENCY']; $total[0]['VALUE0'] = $currency->iso4217; $total[0]['TITLE'] = $mod_strings['LBL_PDF_SUBTOTAL']; $total[0]['VALUE']['value'] = format_number_sugarpdf($this->bean->subtotal, $locale->getPrecision(), $locale->getPrecision(), $format_number_array); $total[0]['VALUE']['options'] = array("align" => "R"); $i = 1; if (format_number_sugarpdf($this->bean->deal_tot, $locale->getPrecision(), $locale->getPrecision()) != 0.0) { $total[1]['BLANK'] = ' '; $total[1]['TITLE0'] = ''; $total[1]['VALUE0'] = ''; $total[1]['TITLE'] = $mod_strings['LBL_PDF_DISCOUNT']; $total[1]['VALUE']['value'] = format_number_sugarpdf($this->bean->deal_tot, $locale->getPrecision(), $locale->getPrecision(), $format_number_array); $total[1]['VALUE']['options'] = array("align" => "R"); $total[2]['BLANK'] = ' '; $total[2]['TITLE0'] = ''; $total[2]['VALUE0'] = ''; $total[2]['TITLE'] = $mod_strings['LBL_PDF_NEW_SUB']; $total[2]['VALUE']['value'] = format_number_sugarpdf($this->bean->new_sub, $locale->getPrecision(), $locale->getPrecision(), $format_number_array); $total[2]['VALUE']['options'] = array("align" => "R"); $i = 3; } $total[$i]['BLANK'] = ' '; $total[$i]['TITLE0'] = $mod_strings['LBL_PDF_TAX_RATE']; $total[$i]['VALUE0'] = format_number_sugarpdf($this->bean->taxrate_value, $locale->getPrecision(), $locale->getPrecision(), array('percentage' => true)); $total[$i]['TITLE'] = $mod_strings['LBL_PDF_TAX']; $total[$i]['VALUE']['value'] = format_number_sugarpdf($this->bean->tax, $locale->getPrecision(), $locale->getPrecision(), $format_number_array); $total[$i]['VALUE']['options'] = array("align" => "R"); $i++; $total[$i]['BLANK'] = ' '; $total[$i]['TITLE0'] = $mod_strings['LBL_PDF_SHIPPING_COMPANY']; $total[$i]['VALUE0'] = $this->bean->shipper_name; $total[$i]['TITLE'] = $mod_strings['LBL_PDF_SHIPPING']; $total[$i]['VALUE']['value'] = format_number_sugarpdf($this->bean->shipping, $locale->getPrecision(), $locale->getPrecision(), $format_number_array); $total[$i]['VALUE']['options'] = array("align" => "R"); $i++; $total[$i]['BLANK'] = ' '; $total[$i]['TITLE0'] = ''; $total[$i]['VALUE0'] = ''; $total[$i]['TITLE'] = $mod_strings['LBL_PDF_TOTAL']; $total[$i]['VALUE']['value'] = format_number_sugarpdf($this->bean->total, $locale->getPrecision(), $locale->getPrecision(), $format_number_array); $total[$i]['VALUE']['options'] = array("align" => "R"); $this->Ln1(); $this->drawLine(); $this->MultiCell(0, 0, "<b>" . $mod_strings['LBL_PDF_GRAND_TOTAL'] . "</b>", 0, 'C', 0, 1, "", "", true, 0, true); $this->writeCellTable($total, $this->grandTotalOptions); $this->drawLine(); } }