Initial commit

This commit is contained in:
2019-11-20 07:44:43 +01:00
commit 5bf49c4a81
41188 changed files with 5459177 additions and 0 deletions

View File

@@ -0,0 +1,243 @@
<?php
/**
* 2007-2018 PrestaShop.
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2018 PrestaShop SA
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
/**
* @since 1.5
*/
abstract class HTMLTemplateCore
{
public $title;
public $date;
public $available_in_your_account = true;
/** @var Smarty */
public $smarty;
/** @var Shop */
public $shop;
/**
* Returns the template's HTML header.
*
* @return string HTML header
*/
public function getHeader()
{
$this->assignCommonHeaderData();
return $this->smarty->fetch($this->getTemplate('header'));
}
/**
* Returns the template's HTML footer.
*
* @return string HTML footer
*/
public function getFooter()
{
$shop_address = $this->getShopAddress();
$id_shop = (int) $this->shop->id;
$this->smarty->assign(array(
'available_in_your_account' => $this->available_in_your_account,
'shop_address' => $shop_address,
'shop_fax' => Configuration::get('PS_SHOP_FAX', null, null, $id_shop),
'shop_phone' => Configuration::get('PS_SHOP_PHONE', null, null, $id_shop),
'shop_email' => Configuration::get('PS_SHOP_EMAIL', null, null, $id_shop),
'free_text' => Configuration::get('PS_INVOICE_FREE_TEXT', (int) Context::getContext()->language->id, null, $id_shop),
));
return $this->smarty->fetch($this->getTemplate('footer'));
}
/**
* Returns the shop address.
*
* @return string
*/
protected function getShopAddress()
{
$shop_address = '';
$shop_address_obj = $this->shop->getAddress();
if (isset($shop_address_obj) && $shop_address_obj instanceof Address) {
$shop_address = AddressFormat::generateAddress($shop_address_obj, array(), ' - ', ' ');
}
return $shop_address;
}
/**
* Returns the invoice logo.
*/
protected function getLogo()
{
$logo = '';
$id_shop = (int) $this->shop->id;
if (Configuration::get('PS_LOGO_INVOICE', null, null, $id_shop) != false && file_exists(_PS_IMG_DIR_ . Configuration::get('PS_LOGO_INVOICE', null, null, $id_shop))) {
$logo = _PS_IMG_DIR_ . Configuration::get('PS_LOGO_INVOICE', null, null, $id_shop);
} elseif (Configuration::get('PS_LOGO', null, null, $id_shop) != false && file_exists(_PS_IMG_DIR_ . Configuration::get('PS_LOGO', null, null, $id_shop))) {
$logo = _PS_IMG_DIR_ . Configuration::get('PS_LOGO', null, null, $id_shop);
}
return $logo;
}
/**
* Assign common header data to smarty variables.
*/
public function assignCommonHeaderData()
{
$this->setShopId();
$id_shop = (int) $this->shop->id;
$shop_name = Configuration::get('PS_SHOP_NAME', null, null, $id_shop);
$path_logo = $this->getLogo();
$width = 0;
$height = 0;
if (!empty($path_logo)) {
list($width, $height) = getimagesize($path_logo);
}
// Limit the height of the logo for the PDF render
$maximum_height = 100;
if ($height > $maximum_height) {
$ratio = $maximum_height / $height;
$height *= $ratio;
$width *= $ratio;
}
$this->smarty->assign(array(
'logo_path' => $path_logo,
'img_ps_dir' => 'http://' . Tools::getMediaServer(_PS_IMG_) . _PS_IMG_,
'img_update_time' => Configuration::get('PS_IMG_UPDATE_TIME'),
'date' => $this->date,
'title' => $this->title,
'shop_name' => $shop_name,
'shop_details' => Configuration::get('PS_SHOP_DETAILS', null, null, (int) $id_shop),
'width_logo' => $width,
'height_logo' => $height,
));
}
/**
* Assign hook data.
*
* @param ObjectModel $object generally the object used in the constructor
*/
public function assignHookData($object)
{
$template = ucfirst(str_replace('HTMLTemplate', '', get_class($this)));
$hook_name = 'displayPDF' . $template;
$this->smarty->assign(array(
'HOOK_DISPLAY_PDF' => Hook::exec($hook_name, array('object' => $object)),
));
}
/**
* Returns the template's HTML content.
*
* @return string HTML content
*/
abstract public function getContent();
/**
* Returns the template filename.
*
* @return string filename
*/
abstract public function getFilename();
/**
* Returns the template filename when using bulk rendering.
*
* @return string filename
*/
abstract public function getBulkFilename();
/**
* If the template is not present in the theme directory, it will return the default template
* in _PS_PDF_DIR_ directory.
*
* @param $template_name
*
* @return string
*/
protected function getTemplate($template_name)
{
$template = false;
$default_template = rtrim(_PS_PDF_DIR_, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $template_name . '.tpl';
$overridden_template = _PS_ALL_THEMES_DIR_ . $this->shop->theme->getName() . DIRECTORY_SEPARATOR . 'pdf' . DIRECTORY_SEPARATOR . $template_name . '.tpl';
if (file_exists($overridden_template)) {
$template = $overridden_template;
} elseif (file_exists($default_template)) {
$template = $default_template;
}
return $template;
}
/**
* Translation method.
*
* @param string $string
*
* @return string translated text
*/
protected static function l($string)
{
return Translate::getPdfTranslation($string);
}
protected function setShopId()
{
if (isset($this->order) && Validate::isLoadedObject($this->order)) {
$id_shop = (int) $this->order->id_shop;
} else {
$id_shop = (int) Context::getContext()->shop->id;
}
$this->shop = new Shop($id_shop);
if (Validate::isLoadedObject($this->shop)) {
Shop::setContext(Shop::CONTEXT_SHOP, (int) $this->shop->id);
}
}
/**
* Returns the template's HTML pagination block.
*
* @return string HTML pagination block
*/
public function getPagination()
{
return $this->smarty->fetch($this->getTemplate('pagination'));
}
}

View File

@@ -0,0 +1,161 @@
<?php
/**
* 2007-2018 PrestaShop.
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2018 PrestaShop SA
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
/**
* @since 1.5
*/
class HTMLTemplateDeliverySlipCore extends HTMLTemplate
{
public $order;
/**
* @param OrderInvoice $order_invoice
* @param $smarty
*
* @throws PrestaShopException
*/
public function __construct(OrderInvoice $order_invoice, $smarty, $bulk_mode = false)
{
$this->order_invoice = $order_invoice;
$this->order = new Order($this->order_invoice->id_order);
$this->smarty = $smarty;
// If shop_address is null, then update it with current one.
// But no DB save required here to avoid massive updates for bulk PDF generation case.
// (DB: bug fixed in 1.6.1.1 with upgrade SQL script to avoid null shop_address in old orderInvoices)
if (!isset($this->order_invoice->shop_address) || !$this->order_invoice->shop_address) {
$this->order_invoice->shop_address = OrderInvoice::getCurrentFormattedShopAddress((int) $this->order->id_shop);
if (!$bulk_mode) {
OrderInvoice::fixAllShopAddresses();
}
}
// header informations
$this->date = Tools::displayDate($order_invoice->date_add);
$prefix = Configuration::get('PS_DELIVERY_PREFIX', Context::getContext()->language->id);
$this->title = sprintf(HTMLTemplateDeliverySlip::l('%1$s%2$06d'), $prefix, $this->order_invoice->delivery_number);
// footer informations
$this->shop = new Shop((int) $this->order->id_shop);
}
/**
* Returns the template's HTML header.
*
* @return string HTML header
*/
public function getHeader()
{
$this->assignCommonHeaderData();
$this->smarty->assign(array('header' => Context::getContext()->getTranslator()->trans('Delivery', array(), 'Shop.Pdf')));
return $this->smarty->fetch($this->getTemplate('header'));
}
/**
* Returns the template's HTML content.
*
* @return string HTML content
*/
public function getContent()
{
$delivery_address = new Address((int) $this->order->id_address_delivery);
$formatted_delivery_address = AddressFormat::generateAddress($delivery_address, array(), '<br />', ' ');
$formatted_invoice_address = '';
if ($this->order->id_address_delivery != $this->order->id_address_invoice) {
$invoice_address = new Address((int) $this->order->id_address_invoice);
$formatted_invoice_address = AddressFormat::generateAddress($invoice_address, array(), '<br />', ' ');
}
$carrier = new Carrier($this->order->id_carrier);
$carrier->name = ($carrier->name == '0' ? Configuration::get('PS_SHOP_NAME') : $carrier->name);
$order_details = $this->order_invoice->getProducts();
if (Configuration::get('PS_PDF_IMG_DELIVERY')) {
foreach ($order_details as &$order_detail) {
if ($order_detail['image'] != null) {
$name = 'product_mini_' . (int) $order_detail['product_id'] . (isset($order_detail['product_attribute_id']) ? '_' . (int) $order_detail['product_attribute_id'] : '') . '.jpg';
$path = _PS_PROD_IMG_DIR_ . $order_detail['image']->getExistingImgPath() . '.jpg';
$order_detail['image_tag'] = preg_replace(
'/\.*' . preg_quote(__PS_BASE_URI__, '/') . '/',
_PS_ROOT_DIR_ . DIRECTORY_SEPARATOR,
ImageManager::thumbnail($path, $name, 45, 'jpg', false),
1
);
if (file_exists(_PS_TMP_IMG_DIR_ . $name)) {
$order_detail['image_size'] = getimagesize(_PS_TMP_IMG_DIR_ . $name);
} else {
$order_detail['image_size'] = false;
}
}
}
}
$this->smarty->assign(array(
'order' => $this->order,
'order_details' => $order_details,
'delivery_address' => $formatted_delivery_address,
'invoice_address' => $formatted_invoice_address,
'order_invoice' => $this->order_invoice,
'carrier' => $carrier,
'display_product_images' => Configuration::get('PS_PDF_IMG_DELIVERY'),
));
$tpls = array(
'style_tab' => $this->smarty->fetch($this->getTemplate('delivery-slip.style-tab')),
'addresses_tab' => $this->smarty->fetch($this->getTemplate('delivery-slip.addresses-tab')),
'summary_tab' => $this->smarty->fetch($this->getTemplate('delivery-slip.summary-tab')),
'product_tab' => $this->smarty->fetch($this->getTemplate('delivery-slip.product-tab')),
'payment_tab' => $this->smarty->fetch($this->getTemplate('delivery-slip.payment-tab')),
);
$this->smarty->assign($tpls);
return $this->smarty->fetch($this->getTemplate('delivery-slip'));
}
/**
* Returns the template filename when using bulk rendering.
*
* @return string filename
*/
public function getBulkFilename()
{
return 'deliveries.pdf';
}
/**
* Returns the template filename.
*
* @return string filename
*/
public function getFilename()
{
return Configuration::get('PS_DELIVERY_PREFIX', Context::getContext()->language->id, null, $this->order->id_shop) . sprintf('%06d', $this->order->delivery_number) . '.pdf';
}
}

View File

@@ -0,0 +1,519 @@
<?php
/**
* 2007-2018 PrestaShop.
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2018 PrestaShop SA
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
/**
* @since 1.5
*/
class HTMLTemplateInvoiceCore extends HTMLTemplate
{
public $order;
public $order_invoice;
public $available_in_your_account = false;
/**
* @param OrderInvoice $order_invoice
* @param $smarty
*
* @throws PrestaShopException
*/
public function __construct(OrderInvoice $order_invoice, $smarty, $bulk_mode = false)
{
$this->order_invoice = $order_invoice;
$this->order = new Order((int) $this->order_invoice->id_order);
$this->smarty = $smarty;
// If shop_address is null, then update it with current one.
// But no DB save required here to avoid massive updates for bulk PDF generation case.
// (DB: bug fixed in 1.6.1.1 with upgrade SQL script to avoid null shop_address in old orderInvoices)
if (!isset($this->order_invoice->shop_address) || !$this->order_invoice->shop_address) {
$this->order_invoice->shop_address = OrderInvoice::getCurrentFormattedShopAddress((int) $this->order->id_shop);
if (!$bulk_mode) {
OrderInvoice::fixAllShopAddresses();
}
}
// header informations
$this->date = Tools::displayDate($order_invoice->date_add);
$id_lang = Context::getContext()->language->id;
$this->title = $order_invoice->getInvoiceNumberFormatted($id_lang);
$this->shop = new Shop((int) $this->order->id_shop);
}
/**
* Returns the template's HTML header.
*
* @return string HTML header
*/
public function getHeader()
{
$this->assignCommonHeaderData();
$this->smarty->assign(array('header' => Context::getContext()->getTranslator()->trans('Invoice', array(), 'Shop.Pdf')));
return $this->smarty->fetch($this->getTemplate('header'));
}
/**
* Compute layout elements size.
*
* @param $params Array Layout elements
*
* @return array Layout elements columns size
*/
protected function computeLayout($params)
{
$layout = array(
'reference' => array(
'width' => 15,
),
'product' => array(
'width' => 40,
),
'quantity' => array(
'width' => 8,
),
'tax_code' => array(
'width' => 8,
),
'unit_price_tax_excl' => array(
'width' => 0,
),
'total_tax_excl' => array(
'width' => 0,
),
);
if (isset($params['has_discount']) && $params['has_discount']) {
$layout['before_discount'] = array('width' => 0);
$layout['product']['width'] -= 7;
$layout['reference']['width'] -= 3;
}
$total_width = 0;
$free_columns_count = 0;
foreach ($layout as $data) {
if ($data['width'] === 0) {
++$free_columns_count;
}
$total_width += $data['width'];
}
$delta = 100 - $total_width;
foreach ($layout as $row => $data) {
if ($data['width'] === 0) {
$layout[$row]['width'] = $delta / $free_columns_count;
}
}
$layout['_colCount'] = count($layout);
return $layout;
}
/**
* Returns the template's HTML content.
*
* @return string HTML content
*/
public function getContent()
{
$invoiceAddressPatternRules = json_decode(Configuration::get('PS_INVCE_INVOICE_ADDR_RULES'), true);
$deliveryAddressPatternRules = json_decode(Configuration::get('PS_INVCE_DELIVERY_ADDR_RULES'), true);
$invoice_address = new Address((int) $this->order->id_address_invoice);
$country = new Country((int) $invoice_address->id_country);
$formatted_invoice_address = AddressFormat::generateAddress($invoice_address, $invoiceAddressPatternRules, '<br />', ' ');
$delivery_address = null;
$formatted_delivery_address = '';
if (isset($this->order->id_address_delivery) && $this->order->id_address_delivery) {
$delivery_address = new Address((int) $this->order->id_address_delivery);
$formatted_delivery_address = AddressFormat::generateAddress($delivery_address, $deliveryAddressPatternRules, '<br />', ' ');
}
$customer = new Customer((int) $this->order->id_customer);
$carrier = new Carrier((int) $this->order->id_carrier);
$order_details = $this->order_invoice->getProducts();
$has_discount = false;
foreach ($order_details as $id => &$order_detail) {
// Find out if column 'price before discount' is required
if ($order_detail['reduction_amount_tax_excl'] > 0) {
$has_discount = true;
$order_detail['unit_price_tax_excl_before_specific_price'] = $order_detail['unit_price_tax_excl_including_ecotax'] + $order_detail['reduction_amount_tax_excl'];
} elseif ($order_detail['reduction_percent'] > 0) {
$has_discount = true;
if ($order_detail['reduction_percent'] == 100) {
$order_detail['unit_price_tax_excl_before_specific_price'] = 0;
} else {
$order_detail['unit_price_tax_excl_before_specific_price'] = (100 * $order_detail['unit_price_tax_excl_including_ecotax']) / (100 - $order_detail['reduction_percent']);
}
}
// Set tax_code
$taxes = OrderDetail::getTaxListStatic($id);
$tax_temp = array();
foreach ($taxes as $tax) {
$obj = new Tax($tax['id_tax']);
$translator = Context::getContext()->getTranslator();
$tax_temp[] = $translator->trans(
'%taxrate%%space%%',
array(
'%taxrate%' => ($obj->rate + 0),
'%space%' => '&nbsp;',
),
'Shop.Pdf'
);
}
$order_detail['order_detail_tax'] = $taxes;
$order_detail['order_detail_tax_label'] = implode(', ', $tax_temp);
}
unset($tax_temp);
unset($order_detail);
if (Configuration::get('PS_PDF_IMG_INVOICE')) {
foreach ($order_details as &$order_detail) {
if ($order_detail['image'] != null) {
$name = 'product_mini_' . (int) $order_detail['product_id'] . (isset($order_detail['product_attribute_id']) ? '_' . (int) $order_detail['product_attribute_id'] : '') . '.jpg';
$path = _PS_PROD_IMG_DIR_ . $order_detail['image']->getExistingImgPath() . '.jpg';
$order_detail['image_tag'] = preg_replace(
'/\.*' . preg_quote(__PS_BASE_URI__, '/') . '/',
_PS_ROOT_DIR_ . DIRECTORY_SEPARATOR,
ImageManager::thumbnail($path, $name, 45, 'jpg', false),
1
);
if (file_exists(_PS_TMP_IMG_DIR_ . $name)) {
$order_detail['image_size'] = getimagesize(_PS_TMP_IMG_DIR_ . $name);
} else {
$order_detail['image_size'] = false;
}
}
}
unset($order_detail); // don't overwrite the last order_detail later
}
$cart_rules = $this->order->getCartRules($this->order_invoice->id);
$free_shipping = false;
foreach ($cart_rules as $key => $cart_rule) {
if ($cart_rule['free_shipping']) {
$free_shipping = true;
/*
* Adjust cart rule value to remove the amount of the shipping.
* We're not interested in displaying the shipping discount as it is already shown as "Free Shipping".
*/
$cart_rules[$key]['value_tax_excl'] -= $this->order_invoice->total_shipping_tax_excl;
$cart_rules[$key]['value'] -= $this->order_invoice->total_shipping_tax_incl;
/*
* Don't display cart rules that are only about free shipping and don't create
* a discount on products.
*/
if ($cart_rules[$key]['value'] == 0) {
unset($cart_rules[$key]);
}
}
}
$product_taxes = 0;
foreach ($this->order_invoice->getProductTaxesBreakdown($this->order) as $details) {
$product_taxes += $details['total_amount'];
}
$product_discounts_tax_excl = $this->order_invoice->total_discount_tax_excl;
$product_discounts_tax_incl = $this->order_invoice->total_discount_tax_incl;
if ($free_shipping) {
$product_discounts_tax_excl -= $this->order_invoice->total_shipping_tax_excl;
$product_discounts_tax_incl -= $this->order_invoice->total_shipping_tax_incl;
}
$products_after_discounts_tax_excl = $this->order_invoice->total_products - $product_discounts_tax_excl;
$products_after_discounts_tax_incl = $this->order_invoice->total_products_wt - $product_discounts_tax_incl;
$shipping_tax_excl = $free_shipping ? 0 : $this->order_invoice->total_shipping_tax_excl;
$shipping_tax_incl = $free_shipping ? 0 : $this->order_invoice->total_shipping_tax_incl;
$shipping_taxes = $shipping_tax_incl - $shipping_tax_excl;
$wrapping_taxes = $this->order_invoice->total_wrapping_tax_incl - $this->order_invoice->total_wrapping_tax_excl;
$total_taxes = $this->order_invoice->total_paid_tax_incl - $this->order_invoice->total_paid_tax_excl;
$footer = array(
'products_before_discounts_tax_excl' => $this->order_invoice->total_products,
'product_discounts_tax_excl' => $product_discounts_tax_excl,
'products_after_discounts_tax_excl' => $products_after_discounts_tax_excl,
'products_before_discounts_tax_incl' => $this->order_invoice->total_products_wt,
'product_discounts_tax_incl' => $product_discounts_tax_incl,
'products_after_discounts_tax_incl' => $products_after_discounts_tax_incl,
'product_taxes' => $product_taxes,
'shipping_tax_excl' => $shipping_tax_excl,
'shipping_taxes' => $shipping_taxes,
'shipping_tax_incl' => $shipping_tax_incl,
'wrapping_tax_excl' => $this->order_invoice->total_wrapping_tax_excl,
'wrapping_taxes' => $wrapping_taxes,
'wrapping_tax_incl' => $this->order_invoice->total_wrapping_tax_incl,
'ecotax_taxes' => $total_taxes - $product_taxes - $wrapping_taxes - $shipping_taxes,
'total_taxes' => $total_taxes,
'total_paid_tax_excl' => $this->order_invoice->total_paid_tax_excl,
'total_paid_tax_incl' => $this->order_invoice->total_paid_tax_incl,
);
foreach ($footer as $key => $value) {
$footer[$key] = Tools::ps_round($value, _PS_PRICE_COMPUTE_PRECISION_, $this->order->round_mode);
}
/**
* Need the $round_mode for the tests.
*/
$round_type = null;
switch ($this->order->round_type) {
case Order::ROUND_TOTAL:
$round_type = 'total';
break;
case Order::ROUND_LINE:
$round_type = 'line';
break;
case Order::ROUND_ITEM:
$round_type = 'item';
break;
default:
$round_type = 'line';
break;
}
$display_product_images = Configuration::get('PS_PDF_IMG_INVOICE');
$tax_excluded_display = Group::getPriceDisplayMethod($customer->id_default_group);
$layout = $this->computeLayout(array('has_discount' => $has_discount));
$legal_free_text = Hook::exec('displayInvoiceLegalFreeText', array('order' => $this->order));
if (!$legal_free_text) {
$legal_free_text = Configuration::get('PS_INVOICE_LEGAL_FREE_TEXT', (int) Context::getContext()->language->id, null, (int) $this->order->id_shop);
}
$data = array(
'order' => $this->order,
'order_invoice' => $this->order_invoice,
'order_details' => $order_details,
'carrier' => $carrier,
'cart_rules' => $cart_rules,
'delivery_address' => $formatted_delivery_address,
'invoice_address' => $formatted_invoice_address,
'addresses' => array('invoice' => $invoice_address, 'delivery' => $delivery_address),
'tax_excluded_display' => $tax_excluded_display,
'display_product_images' => $display_product_images,
'layout' => $layout,
'tax_tab' => $this->getTaxTabContent(),
'customer' => $customer,
'footer' => $footer,
'ps_price_compute_precision' => _PS_PRICE_COMPUTE_PRECISION_,
'round_type' => $round_type,
'legal_free_text' => $legal_free_text,
);
if (Tools::getValue('debug')) {
die(json_encode($data));
}
$this->smarty->assign($data);
$tpls = array(
'style_tab' => $this->smarty->fetch($this->getTemplate('invoice.style-tab')),
'addresses_tab' => $this->smarty->fetch($this->getTemplate('invoice.addresses-tab')),
'summary_tab' => $this->smarty->fetch($this->getTemplate('invoice.summary-tab')),
'product_tab' => $this->smarty->fetch($this->getTemplate('invoice.product-tab')),
'tax_tab' => $this->getTaxTabContent(),
'payment_tab' => $this->smarty->fetch($this->getTemplate('invoice.payment-tab')),
'note_tab' => $this->smarty->fetch($this->getTemplate('invoice.note-tab')),
'total_tab' => $this->smarty->fetch($this->getTemplate('invoice.total-tab')),
'shipping_tab' => $this->smarty->fetch($this->getTemplate('invoice.shipping-tab')),
);
$this->smarty->assign($tpls);
return $this->smarty->fetch($this->getTemplateByCountry($country->iso_code));
}
/**
* Returns the tax tab content.
*
* @return string Tax tab html content
*/
public function getTaxTabContent()
{
$debug = Tools::getValue('debug');
$address = new Address((int) $this->order->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
$tax_exempt = Configuration::get('VATNUMBER_MANAGEMENT')
&& !empty($address->vat_number)
&& $address->id_country != Configuration::get('VATNUMBER_COUNTRY');
$carrier = new Carrier($this->order->id_carrier);
$tax_breakdowns = $this->getTaxBreakdown();
$data = array(
'tax_exempt' => $tax_exempt,
'use_one_after_another_method' => $this->order_invoice->useOneAfterAnotherTaxComputationMethod(),
'display_tax_bases_in_breakdowns' => $this->order_invoice->displayTaxBasesInProductTaxesBreakdown(),
'product_tax_breakdown' => $this->order_invoice->getProductTaxesBreakdown($this->order),
'shipping_tax_breakdown' => $this->order_invoice->getShippingTaxesBreakdown($this->order),
'ecotax_tax_breakdown' => $this->order_invoice->getEcoTaxTaxesBreakdown(),
'wrapping_tax_breakdown' => $this->order_invoice->getWrappingTaxesBreakdown(),
'tax_breakdowns' => $tax_breakdowns,
'order' => $debug ? null : $this->order,
'order_invoice' => $debug ? null : $this->order_invoice,
'carrier' => $debug ? null : $carrier,
);
if ($debug) {
return $data;
}
$this->smarty->assign($data);
return $this->smarty->fetch($this->getTemplate('invoice.tax-tab'));
}
/**
* Returns different tax breakdown elements.
*
* @return array Different tax breakdown elements
*/
protected function getTaxBreakdown()
{
$breakdowns = array(
'product_tax' => $this->order_invoice->getProductTaxesBreakdown($this->order),
'shipping_tax' => $this->order_invoice->getShippingTaxesBreakdown($this->order),
'ecotax_tax' => $this->order_invoice->getEcoTaxTaxesBreakdown(),
'wrapping_tax' => $this->order_invoice->getWrappingTaxesBreakdown(),
);
foreach ($breakdowns as $type => $bd) {
if (empty($bd)) {
unset($breakdowns[$type]);
}
}
if (empty($breakdowns)) {
$breakdowns = false;
}
if (isset($breakdowns['product_tax'])) {
foreach ($breakdowns['product_tax'] as &$bd) {
$bd['total_tax_excl'] = $bd['total_price_tax_excl'];
}
}
if (isset($breakdowns['ecotax_tax'])) {
foreach ($breakdowns['ecotax_tax'] as &$bd) {
$bd['total_tax_excl'] = $bd['ecotax_tax_excl'];
$bd['total_amount'] = $bd['ecotax_tax_incl'] - $bd['ecotax_tax_excl'];
}
}
return $breakdowns;
}
/*
protected function getTaxLabel($tax_breakdowns)
{
$tax_label = '';
$all_taxes = array();
foreach ($tax_breakdowns as $type => $bd)
foreach ($bd as $line)
if(isset($line['id_tax']))
$all_taxes[] = $line['id_tax'];
$taxes = array_unique($all_taxes);
foreach ($taxes as $id_tax) {
$tax = new Tax($id_tax);
$tax_label .= $tax->id.': '.$tax->name[$this->order->id_lang].' ('.$tax->rate.'%) ';
}
return $tax_label;
}
*/
/**
* Returns the invoice template associated to the country iso_code.
*
* @param string $iso_country
*/
protected function getTemplateByCountry($iso_country)
{
$file = Configuration::get('PS_INVOICE_MODEL');
// try to fetch the iso template
$template = $this->getTemplate($file . '.' . $iso_country);
// else use the default one
if (!$template) {
$template = $this->getTemplate($file);
}
return $template;
}
/**
* Returns the template filename when using bulk rendering.
*
* @return string filename
*/
public function getBulkFilename()
{
return 'invoices.pdf';
}
/**
* Returns the template filename.
*
* @return string filename
*/
public function getFilename()
{
$id_lang = Context::getContext()->language->id;
$id_shop = (int) $this->order->id_shop;
$format = '%1$s%2$06d';
if (Configuration::get('PS_INVOICE_USE_YEAR')) {
$format = Configuration::get('PS_INVOICE_YEAR_POS') ? '%1$s%3$s-%2$06d' : '%1$s%2$06d-%3$s';
}
return sprintf(
$format,
Configuration::get('PS_INVOICE_PREFIX', $id_lang, null, $id_shop),
$this->order_invoice->number,
date('Y', strtotime($this->order_invoice->date_add))
) . '.pdf';
}
}

View File

@@ -0,0 +1,124 @@
<?php
/**
* 2007-2018 PrestaShop.
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2018 PrestaShop SA
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
/**
* @since 1.5
*/
class HTMLTemplateOrderReturnCore extends HTMLTemplate
{
public $order_return;
public $order;
/**
* @param OrderReturn $order_return
* @param $smarty
*
* @throws PrestaShopException
*/
public function __construct(OrderReturn $order_return, $smarty)
{
$this->order_return = $order_return;
$this->smarty = $smarty;
$this->order = new Order($order_return->id_order);
// header informations
$this->date = Tools::displayDate($this->order->invoice_date);
$prefix = Configuration::get('PS_RETURN_PREFIX', Context::getContext()->language->id);
$this->title = sprintf(HTMLTemplateOrderReturn::l('%1$s%2$06d'), $prefix, $this->order_return->id);
$this->shop = new Shop((int) $this->order->id_shop);
}
/**
* Returns the template's HTML content.
*
* @return string HTML content
*/
public function getContent()
{
$delivery_address = new Address((int) $this->order->id_address_delivery);
$formatted_delivery_address = AddressFormat::generateAddress($delivery_address, array(), '<br />', ' ');
$formatted_invoice_address = '';
if ($this->order->id_address_delivery != $this->order->id_address_invoice) {
$invoice_address = new Address((int) $this->order->id_address_invoice);
$formatted_invoice_address = AddressFormat::generateAddress($invoice_address, array(), '<br />', ' ');
}
$this->smarty->assign(array(
'order_return' => $this->order_return,
'return_nb_days' => (int) Configuration::get('PS_ORDER_RETURN_NB_DAYS'),
'products' => OrderReturn::getOrdersReturnProducts((int) $this->order_return->id, $this->order),
'delivery_address' => $formatted_delivery_address,
'invoice_address' => $formatted_invoice_address,
'shop_address' => AddressFormat::generateAddress($this->shop->getAddress(), array(), '<br />', ' '),
));
$tpls = array(
'style_tab' => $this->smarty->fetch($this->getTemplate('invoice.style-tab')),
'addresses_tab' => $this->smarty->fetch($this->getTemplate('order-return.addresses-tab')),
'summary_tab' => $this->smarty->fetch($this->getTemplate('order-return.summary-tab')),
'product_tab' => $this->smarty->fetch($this->getTemplate('order-return.product-tab')),
'conditions_tab' => $this->smarty->fetch($this->getTemplate('order-return.conditions-tab')),
);
$this->smarty->assign($tpls);
return $this->smarty->fetch($this->getTemplate('order-return'));
}
/**
* Returns the template filename.
*
* @return string filename
*/
public function getFilename()
{
return Configuration::get('PS_RETURN_PREFIX', Context::getContext()->language->id, null, $this->order->id_shop) . sprintf('%06d', $this->order_return->id) . '.pdf';
}
/**
* Returns the template filename when using bulk rendering.
*
* @return string filename
*/
public function getBulkFilename()
{
return 'invoices.pdf';
}
/**
* Returns the template's HTML header.
*
* @return string HTML header
*/
public function getHeader()
{
$this->assignCommonHeaderData();
$this->smarty->assign(array('header' => Context::getContext()->getTranslator()->trans('Order return', array(), 'Shop.Pdf')));
return $this->smarty->fetch($this->getTemplate('header'));
}
}

View File

@@ -0,0 +1,328 @@
<?php
/**
* 2007-2018 PrestaShop.
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2018 PrestaShop SA
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
/**
* @since 1.5
*/
class HTMLTemplateOrderSlipCore extends HTMLTemplateInvoice
{
public $order;
public $order_slip;
/**
* @param OrderSlip $order_slip
* @param $smarty
*
* @throws PrestaShopException
*/
public function __construct(OrderSlip $order_slip, $smarty)
{
$this->order_slip = $order_slip;
$this->order = new Order((int) $order_slip->id_order);
$this->id_cart = $this->order->id_cart;
$products = OrderSlip::getOrdersSlipProducts($this->order_slip->id, $this->order);
foreach ($products as $product) {
$customized_datas = Product::getAllCustomizedDatas($this->id_cart, null, true, null, (int) $product['id_customization']);
Product::addProductCustomizationPrice($product, $customized_datas);
}
$this->order->products = $products;
$this->smarty = $smarty;
// header informations
$this->date = Tools::displayDate($this->order_slip->date_add);
$prefix = Configuration::get('PS_CREDIT_SLIP_PREFIX', Context::getContext()->language->id);
$this->title = sprintf(HTMLTemplateOrderSlip::l('%1$s%2$06d'), $prefix, (int) $this->order_slip->id);
$this->shop = new Shop((int) $this->order->id_shop);
}
/**
* Returns the template's HTML header.
*
* @return string HTML header
*/
public function getHeader()
{
$this->assignCommonHeaderData();
$this->smarty->assign(array('header' => Context::getContext()->getTranslator()->trans('Credit slip', array(), 'Shop.Pdf')));
return $this->smarty->fetch($this->getTemplate('header'));
}
/**
* Returns the template's HTML content.
*
* @return string HTML content
*/
public function getContent()
{
$delivery_address = $invoice_address = new Address((int) $this->order->id_address_invoice);
$formatted_invoice_address = AddressFormat::generateAddress($invoice_address, array(), '<br />', ' ');
$formatted_delivery_address = '';
if ($this->order->id_address_delivery != $this->order->id_address_invoice) {
$delivery_address = new Address((int) $this->order->id_address_delivery);
$formatted_delivery_address = AddressFormat::generateAddress($delivery_address, array(), '<br />', ' ');
}
$customer = new Customer((int) $this->order->id_customer);
$this->order->total_paid_tax_excl = $this->order->total_paid_tax_incl = $this->order->total_products = $this->order->total_products_wt = 0;
if ($this->order_slip->amount > 0) {
foreach ($this->order->products as &$product) {
$product['total_price_tax_excl'] = $product['unit_price_tax_excl'] * $product['product_quantity'];
$product['total_price_tax_incl'] = $product['unit_price_tax_incl'] * $product['product_quantity'];
if ($this->order_slip->partial == 1) {
$order_slip_detail = Db::getInstance()->getRow('
SELECT * FROM `' . _DB_PREFIX_ . 'order_slip_detail`
WHERE `id_order_slip` = ' . (int) $this->order_slip->id . '
AND `id_order_detail` = ' . (int) $product['id_order_detail']);
$product['total_price_tax_excl'] = $order_slip_detail['amount_tax_excl'];
$product['total_price_tax_incl'] = $order_slip_detail['amount_tax_incl'];
}
$this->order->total_products += $product['total_price_tax_excl'];
$this->order->total_products_wt += $product['total_price_tax_incl'];
$this->order->total_paid_tax_excl = $this->order->total_products;
$this->order->total_paid_tax_incl = $this->order->total_products_wt;
}
} else {
$this->order->products = null;
}
unset($product); // remove reference
if ($this->order_slip->shipping_cost == 0) {
$this->order->total_shipping_tax_incl = $this->order->total_shipping_tax_excl = 0;
}
$tax = new Tax();
$tax->rate = $this->order->carrier_tax_rate;
$tax_calculator = new TaxCalculator(array($tax));
$tax_excluded_display = Group::getPriceDisplayMethod((int) $customer->id_default_group);
$this->order->total_shipping_tax_incl = $this->order_slip->total_shipping_tax_incl;
$this->order->total_shipping_tax_excl = $this->order_slip->total_shipping_tax_excl;
$this->order_slip->shipping_cost_amount = $tax_excluded_display ? $this->order_slip->total_shipping_tax_excl : $this->order_slip->total_shipping_tax_incl;
$this->order->total_paid_tax_incl += $this->order->total_shipping_tax_incl;
$this->order->total_paid_tax_excl += $this->order->total_shipping_tax_excl;
$total_cart_rule = 0;
if ($this->order_slip->order_slip_type == 1 && is_array($cart_rules = $this->order->getCartRules($this->order_invoice->id))) {
foreach ($cart_rules as $cart_rule) {
if ($tax_excluded_display) {
$total_cart_rule += $cart_rule['value_tax_excl'];
} else {
$total_cart_rule += $cart_rule['value'];
}
}
}
$this->smarty->assign(array(
'order' => $this->order,
'order_slip' => $this->order_slip,
'order_details' => $this->order->products,
'cart_rules' => $this->order_slip->order_slip_type == 1 ? $this->order->getCartRules($this->order_invoice->id) : false,
'amount_choosen' => $this->order_slip->order_slip_type == 2 ? true : false,
'delivery_address' => $formatted_delivery_address,
'invoice_address' => $formatted_invoice_address,
'addresses' => array('invoice' => $invoice_address, 'delivery' => $delivery_address),
'tax_excluded_display' => $tax_excluded_display,
'total_cart_rule' => $total_cart_rule,
));
$tpls = array(
'style_tab' => $this->smarty->fetch($this->getTemplate('invoice.style-tab')),
'addresses_tab' => $this->smarty->fetch($this->getTemplate('invoice.addresses-tab')),
'summary_tab' => $this->smarty->fetch($this->getTemplate('order-slip.summary-tab')),
'product_tab' => $this->smarty->fetch($this->getTemplate('order-slip.product-tab')),
'total_tab' => $this->smarty->fetch($this->getTemplate('order-slip.total-tab')),
'payment_tab' => $this->smarty->fetch($this->getTemplate('order-slip.payment-tab')),
'tax_tab' => $this->getTaxTabContent(),
);
$this->smarty->assign($tpls);
return $this->smarty->fetch($this->getTemplate('order-slip'));
}
/**
* Returns the template filename when using bulk rendering.
*
* @return string filename
*/
public function getBulkFilename()
{
return 'order-slips.pdf';
}
/**
* Returns the template filename.
*
* @return string filename
*/
public function getFilename()
{
return Configuration::get('PS_CREDIT_SLIP_PREFIX', Context::getContext()->language->id, null, $this->order->id_shop) . sprintf('%06d', $this->order_slip->id) . '.pdf';
}
/**
* Returns the tax tab content.
*
* @return string Tax tab html content
*/
public function getTaxTabContent()
{
$address = new Address((int) $this->order->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
$tax_exempt = Configuration::get('VATNUMBER_MANAGEMENT')
&& !empty($address->vat_number)
&& $address->id_country != Configuration::get('VATNUMBER_COUNTRY');
$this->smarty->assign(array(
'tax_exempt' => $tax_exempt,
'product_tax_breakdown' => $this->getProductTaxesBreakdown(),
'shipping_tax_breakdown' => $this->getShippingTaxesBreakdown(),
'order' => $this->order,
'ecotax_tax_breakdown' => $this->order_slip->getEcoTaxTaxesBreakdown(),
'is_order_slip' => true,
'tax_breakdowns' => $this->getTaxBreakdown(),
'display_tax_bases_in_breakdowns' => false,
));
return $this->smarty->fetch($this->getTemplate('invoice.tax-tab'));
}
/**
* Returns different tax breakdown elements.
*
* @return array Different tax breakdown elements
*/
protected function getTaxBreakdown()
{
$breakdowns = array(
'product_tax' => $this->getProductTaxesBreakdown(),
'shipping_tax' => $this->getShippingTaxesBreakdown(),
'ecotax_tax' => $this->order_slip->getEcoTaxTaxesBreakdown(),
);
foreach ($breakdowns as $type => $bd) {
if (empty($bd)) {
unset($breakdowns[$type]);
}
}
if (empty($breakdowns)) {
$breakdowns = false;
}
if (isset($breakdowns['product_tax'])) {
foreach ($breakdowns['product_tax'] as &$bd) {
$bd['total_tax_excl'] = $bd['total_price_tax_excl'];
}
}
if (isset($breakdowns['ecotax_tax'])) {
foreach ($breakdowns['ecotax_tax'] as &$bd) {
$bd['total_tax_excl'] = $bd['ecotax_tax_excl'];
$bd['total_amount'] = $bd['ecotax_tax_incl'] - $bd['ecotax_tax_excl'];
}
}
return $breakdowns;
}
public function getProductTaxesBreakdown()
{
// $breakdown will be an array with tax rates as keys and at least the columns:
// - 'total_price_tax_excl'
// - 'total_amount'
$breakdown = array();
$details = $this->order->getProductTaxesDetails($this->order->products);
foreach ($details as $row) {
$rate = sprintf('%.3f', $row['tax_rate']);
if (!isset($breakdown[$rate])) {
$breakdown[$rate] = array(
'total_price_tax_excl' => 0,
'total_amount' => 0,
'id_tax' => $row['id_tax'],
'rate' => $rate,
);
}
$breakdown[$rate]['total_price_tax_excl'] += $row['total_tax_base'];
$breakdown[$rate]['total_amount'] += $row['total_amount'];
}
foreach ($breakdown as $rate => $data) {
$breakdown[$rate]['total_price_tax_excl'] = Tools::ps_round($data['total_price_tax_excl'], _PS_PRICE_COMPUTE_PRECISION_, $this->order->round_mode);
$breakdown[$rate]['total_amount'] = Tools::ps_round($data['total_amount'], _PS_PRICE_COMPUTE_PRECISION_, $this->order->round_mode);
}
ksort($breakdown);
return $breakdown;
}
/**
* Returns Shipping tax breakdown elements.
*
* @return array Shipping tax breakdown elements
*/
public function getShippingTaxesBreakdown()
{
$taxes_breakdown = array();
$tax = new Tax();
$tax->rate = $this->order->carrier_tax_rate;
$tax_calculator = new TaxCalculator(array($tax));
$customer = new Customer((int) $this->order->id_customer);
$tax_excluded_display = Group::getPriceDisplayMethod((int) $customer->id_default_group);
if ($tax_excluded_display) {
$total_tax_excl = $this->order_slip->shipping_cost_amount;
$shipping_tax_amount = $tax_calculator->addTaxes($this->order_slip->shipping_cost_amount) - $total_tax_excl;
} else {
$total_tax_excl = $tax_calculator->removeTaxes($this->order_slip->shipping_cost_amount);
$shipping_tax_amount = $this->order_slip->shipping_cost_amount - $total_tax_excl;
}
if ($shipping_tax_amount > 0) {
$taxes_breakdown[] = array(
'rate' => $this->order->carrier_tax_rate,
'total_amount' => $shipping_tax_amount,
'total_tax_excl' => $total_tax_excl,
);
}
return $taxes_breakdown;
}
}

View File

@@ -0,0 +1,242 @@
<?php
/**
* 2007-2018 PrestaShop.
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2018 PrestaShop SA
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
/**
* @since 1.5
*/
class HTMLTemplateSupplyOrderFormCore extends HTMLTemplate
{
public $supply_order;
public $warehouse;
public $address_warehouse;
public $address_supplier;
public $context;
/**
* @param SupplyOrder $supply_order
* @param $smarty
*
* @throws PrestaShopException
*/
public function __construct(SupplyOrder $supply_order, $smarty)
{
$this->supply_order = $supply_order;
$this->smarty = $smarty;
$this->context = Context::getContext();
$this->warehouse = new Warehouse((int) $supply_order->id_warehouse);
$this->address_warehouse = new Address((int) $this->warehouse->id_address);
$this->address_supplier = new Address(Address::getAddressIdBySupplierId((int) $supply_order->id_supplier));
// header informations
$this->date = Tools::displayDate($supply_order->date_add);
$this->title = Context::getContext()->getTranslator()->trans('Supply order form', array(), 'Shop.Pdf');
$this->shop = new Shop((int) $this->order->id_shop);
}
/**
* @see HTMLTemplate::getContent()
*/
public function getContent()
{
$supply_order_details = $this->supply_order->getEntriesCollection((int) $this->supply_order->id_lang);
$this->roundSupplyOrderDetails($supply_order_details);
$this->roundSupplyOrder($this->supply_order);
$tax_order_summary = $this->getTaxOrderSummary();
$currency = new Currency((int) $this->supply_order->id_currency);
$this->smarty->assign(array(
'warehouse' => $this->warehouse,
'address_warehouse' => $this->address_warehouse,
'address_supplier' => $this->address_supplier,
'supply_order' => $this->supply_order,
'supply_order_details' => $supply_order_details,
'tax_order_summary' => $tax_order_summary,
'currency' => $currency,
));
$tpls = array(
'style_tab' => $this->smarty->fetch($this->getTemplate('invoice.style-tab')),
'addresses_tab' => $this->smarty->fetch($this->getTemplate('supply-order.addresses-tab')),
'product_tab' => $this->smarty->fetch($this->getTemplate('supply-order.product-tab')),
'tax_tab' => $this->smarty->fetch($this->getTemplate('supply-order.tax-tab')),
'total_tab' => $this->smarty->fetch($this->getTemplate('supply-order.total-tab')),
);
$this->smarty->assign($tpls);
return $this->smarty->fetch($this->getTemplate('supply-order'));
}
/**
* Returns the invoice logo.
*
* @return string Logo path
*/
protected function getLogo()
{
$logo = '';
if (Configuration::get('PS_LOGO_INVOICE', null, null, (int) Shop::getContextShopID()) != false && file_exists(_PS_IMG_DIR_ . Configuration::get('PS_LOGO_INVOICE', null, null, (int) Shop::getContextShopID()))) {
$logo = _PS_IMG_DIR_ . Configuration::get('PS_LOGO_INVOICE', null, null, (int) Shop::getContextShopID());
} elseif (Configuration::get('PS_LOGO', null, null, (int) Shop::getContextShopID()) != false && file_exists(_PS_IMG_DIR_ . Configuration::get('PS_LOGO', null, null, (int) Shop::getContextShopID()))) {
$logo = _PS_IMG_DIR_ . Configuration::get('PS_LOGO', null, null, (int) Shop::getContextShopID());
}
return $logo;
}
/**
* @see HTMLTemplate::getBulkFilename()
*/
public function getBulkFilename()
{
return 'supply_order.pdf';
}
/**
* @see HTMLTemplate::getFileName()
*/
public function getFilename()
{
return 'supply-order-form-' . sprintf('%06d', $this->supply_order->reference) . '.pdf';
}
/**
* Get order taxes summary.
*
* @return array|false|mysqli_result|null|PDOStatement|resource
*
* @throws PrestaShopDatabaseException
*/
protected function getTaxOrderSummary()
{
$query = new DbQuery();
$query->select('
SUM(price_with_order_discount_te) as base_te,
tax_rate,
SUM(tax_value_with_order_discount) as total_tax_value
');
$query->from('supply_order_detail');
$query->where('id_supply_order = ' . (int) $this->supply_order->id);
$query->groupBy('tax_rate');
$results = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query);
foreach ($results as &$result) {
$result['base_te'] = Tools::ps_round($result['base_te'], 2);
$result['tax_rate'] = Tools::ps_round($result['tax_rate'], 2);
$result['total_tax_value'] = Tools::ps_round($result['total_tax_value'], 2);
}
unset($result); // remove reference
return $results;
}
/**
* @see HTMLTemplate::getHeader()
*/
public function getHeader()
{
$shop_name = Configuration::get('PS_SHOP_NAME');
$path_logo = $this->getLogo();
$width = $height = 0;
if (!empty($path_logo)) {
list($width, $height) = getimagesize($path_logo);
}
$this->smarty->assign(array(
'logo_path' => $path_logo,
'img_ps_dir' => 'http://' . Tools::getMediaServer(_PS_IMG_) . _PS_IMG_,
'img_update_time' => Configuration::get('PS_IMG_UPDATE_TIME'),
'title' => $this->title,
'reference' => $this->supply_order->reference,
'date' => $this->date,
'shop_name' => $shop_name,
'width_logo' => $width,
'height_logo' => $height,
));
return $this->smarty->fetch($this->getTemplate('supply-order-header'));
}
/**
* @see HTMLTemplate::getFooter()
*/
public function getFooter()
{
$this->address = $this->address_warehouse;
$free_text = array();
$free_text[] = Context::getContext()->getTranslator()->trans('TE: Tax excluded', array(), 'Shop.Pdf');
$free_text[] = Context::getContext()->getTranslator()->trans('TI: Tax included', array(), 'Shop.Pdf');
$this->smarty->assign(array(
'shop_address' => $this->getShopAddress(),
'shop_fax' => Configuration::get('PS_SHOP_FAX'),
'shop_phone' => Configuration::get('PS_SHOP_PHONE'),
'shop_details' => Configuration::get('PS_SHOP_DETAILS'),
'free_text' => $free_text,
));
return $this->smarty->fetch($this->getTemplate('supply-order-footer'));
}
/**
* Rounds values of a SupplyOrderDetail object.
*
* @param array|PrestaShopCollection $collection
*/
protected function roundSupplyOrderDetails(&$collection)
{
foreach ($collection as $supply_order_detail) {
/* @var SupplyOrderDetail $supply_order_detail */
$supply_order_detail->unit_price_te = Tools::ps_round($supply_order_detail->unit_price_te, 2);
$supply_order_detail->price_te = Tools::ps_round($supply_order_detail->price_te, 2);
$supply_order_detail->discount_rate = Tools::ps_round($supply_order_detail->discount_rate, 2);
$supply_order_detail->price_with_discount_te = Tools::ps_round($supply_order_detail->price_with_discount_te, 2);
$supply_order_detail->tax_rate = Tools::ps_round($supply_order_detail->tax_rate, 2);
$supply_order_detail->price_ti = Tools::ps_round($supply_order_detail->price_ti, 2);
}
}
/**
* Rounds values of a SupplyOrder object.
*
* @param SupplyOrder $supply_order
*/
protected function roundSupplyOrder(SupplyOrder &$supply_order)
{
$supply_order->total_te = Tools::ps_round($supply_order->total_te, 2);
$supply_order->discount_value_te = Tools::ps_round($supply_order->discount_value_te, 2);
$supply_order->total_with_discount_te = Tools::ps_round($supply_order->total_with_discount_te, 2);
$supply_order->total_tax = Tools::ps_round($supply_order->total_tax, 2);
$supply_order->total_ti = Tools::ps_round($supply_order->total_ti, 2);
}
}

171
web/classes/pdf/PDF.php Normal file
View File

@@ -0,0 +1,171 @@
<?php
/**
* 2007-2018 PrestaShop.
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2018 PrestaShop SA
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
/**
* @since 1.5
*/
class PDFCore
{
public $filename;
public $pdf_renderer;
public $objects;
public $template;
public $send_bulk_flag = false;
const TEMPLATE_INVOICE = 'Invoice';
const TEMPLATE_ORDER_RETURN = 'OrderReturn';
const TEMPLATE_ORDER_SLIP = 'OrderSlip';
const TEMPLATE_DELIVERY_SLIP = 'DeliverySlip';
const TEMPLATE_SUPPLY_ORDER_FORM = 'SupplyOrderForm';
/**
* @param $objects
* @param $template
* @param $smarty
* @param string $orientation
*/
public function __construct($objects, $template, $smarty, $orientation = 'P')
{
$this->pdf_renderer = new PDFGenerator((bool) Configuration::get('PS_PDF_USE_CACHE'), $orientation);
$this->template = $template;
/*
* We need a Smarty instance that does NOT escape HTML.
* Since in BO Smarty does not autoescape
* and in FO Smarty does autoescape, we use
* a new Smarty of which we're sure it does not escape
* the HTML.
*/
$this->smarty = clone $smarty;
$this->smarty->escape_html = false;
/* We need to get the old instance of the LazyRegister
* because some of the functions are already defined
* and we need to check in the old one first
*/
$original_lazy_register = SmartyLazyRegister::getInstance($smarty);
/* For PDF we restore some functions from Smarty
* they've been removed in PrestaShop 1.7 so
* new themes don't use them. Although PDF haven't been
* reworked so every PDF controller must extend this class.
*/
smartyRegisterFunction($this->smarty, 'function', 'convertPrice', array('Product', 'convertPrice'), true, $original_lazy_register);
smartyRegisterFunction($this->smarty, 'function', 'convertPriceWithCurrency', array('Product', 'convertPriceWithCurrency'), true, $original_lazy_register);
smartyRegisterFunction($this->smarty, 'function', 'displayWtPrice', array('Product', 'displayWtPrice'), true, $original_lazy_register);
smartyRegisterFunction($this->smarty, 'function', 'displayWtPriceWithCurrency', array('Product', 'displayWtPriceWithCurrency'), true, $original_lazy_register);
smartyRegisterFunction($this->smarty, 'function', 'displayPrice', array('Tools', 'displayPriceSmarty'), true, $original_lazy_register);
smartyRegisterFunction($this->smarty, 'modifier', 'convertAndFormatPrice', array('Product', 'convertAndFormatPrice'), true, $original_lazy_register); // used twice
smartyRegisterFunction($this->smarty, 'function', 'displayAddressDetail', array('AddressFormat', 'generateAddressSmarty'), true, $original_lazy_register);
smartyRegisterFunction($this->smarty, 'function', 'getWidthSize', array('Image', 'getWidth'), true, $original_lazy_register);
smartyRegisterFunction($this->smarty, 'function', 'getHeightSize', array('Image', 'getHeight'), true, $original_lazy_register);
$this->objects = $objects;
if (!($objects instanceof Iterator) && !is_array($objects)) {
$this->objects = array($objects);
}
if (count($this->objects) > 1) { // when bulk mode only
$this->send_bulk_flag = true;
}
}
/**
* Render PDF.
*
* @param bool $display
*
* @return mixed
*
* @throws PrestaShopException
*/
public function render($display = true)
{
$render = false;
$this->pdf_renderer->setFontForLang(Context::getContext()->language->iso_code);
foreach ($this->objects as $object) {
$this->pdf_renderer->startPageGroup();
$template = $this->getTemplateObject($object);
if (!$template) {
continue;
}
if (empty($this->filename)) {
$this->filename = $template->getFilename();
if (count($this->objects) > 1) {
$this->filename = $template->getBulkFilename();
}
}
$template->assignHookData($object);
$this->pdf_renderer->createHeader($template->getHeader());
$this->pdf_renderer->createFooter($template->getFooter());
$this->pdf_renderer->createPagination($template->getPagination());
$this->pdf_renderer->createContent($template->getContent());
$this->pdf_renderer->writePage();
$render = true;
unset($template);
}
if ($render) {
// clean the output buffer
if (ob_get_level() && ob_get_length() > 0) {
ob_clean();
}
return $this->pdf_renderer->render($this->filename, $display);
}
}
/**
* Get correct PDF template classes.
*
* @param mixed $object
*
* @return HTMLTemplate|false
*
* @throws PrestaShopException
*/
public function getTemplateObject($object)
{
$class = false;
$class_name = 'HTMLTemplate' . $this->template;
if (class_exists($class_name)) {
// Some HTMLTemplateXYZ implementations won't use the third param but this is not a problem (no warning in PHP),
// the third param is then ignored if not added to the method signature.
$class = new $class_name($object, $this->smarty, $this->send_bulk_flag);
if (!($class instanceof HTMLTemplate)) {
throw new PrestaShopException('Invalid class. It should be an instance of HTMLTemplate');
}
}
return $class;
}
}

View File

@@ -0,0 +1,263 @@
<?php
/**
* 2007-2018 PrestaShop.
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2018 PrestaShop SA
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
/**
* @since 1.5
*/
class PDFGeneratorCore extends TCPDF
{
const DEFAULT_FONT = 'helvetica';
public $header;
public $footer;
public $pagination;
public $content;
public $font;
public $font_by_lang = array(
'ja' => 'cid0jp',
'bg' => 'freeserif',
'ru' => 'freeserif',
'uk' => 'freeserif',
'mk' => 'freeserif',
'el' => 'freeserif',
'en' => 'dejavusans',
'vn' => 'dejavusans',
'pl' => 'dejavusans',
'ar' => 'dejavusans',
'fa' => 'dejavusans',
'ur' => 'dejavusans',
'az' => 'dejavusans',
'ca' => 'dejavusans',
'gl' => 'dejavusans',
'hr' => 'dejavusans',
'sr' => 'dejavusans',
'si' => 'dejavusans',
'cs' => 'dejavusans',
'sk' => 'dejavusans',
'ka' => 'dejavusans',
'he' => 'dejavusans',
'lo' => 'dejavusans',
'lt' => 'dejavusans',
'lv' => 'dejavusans',
'tr' => 'dejavusans',
'ko' => 'cid0kr',
'zh' => 'cid0cs',
'tw' => 'cid0cs',
'th' => 'freeserif',
);
/**
* @param bool $use_cache
* @param string $orientation
*/
public function __construct($use_cache = false, $orientation = 'P')
{
parent::__construct($orientation, 'mm', 'A4', true, 'UTF-8', $use_cache, false);
$this->setRTL(Context::getContext()->language->is_rtl);
}
/**
* set the PDF encoding.
*
* @param string $encoding
*/
public function setEncoding($encoding)
{
$this->encoding = $encoding;
}
/**
* set the PDF header.
*
* @param string $header HTML
*/
public function createHeader($header)
{
$this->header = $header;
}
/**
* set the PDF footer.
*
* @param string $footer HTML
*/
public function createFooter($footer)
{
$this->footer = $footer;
}
/**
* create the PDF content.
*
* @param string $content HTML
*/
public function createContent($content)
{
$this->content = $content;
}
/**
* create the PDF pagination.
*
* @param string $pagination HTML
*/
public function createPagination($pagination)
{
$this->pagination = $pagination;
}
/**
* Change the font.
*
* @param string $iso_lang
*/
public function setFontForLang($iso_lang)
{
if (array_key_exists($iso_lang, $this->font_by_lang)) {
$this->font = $this->font_by_lang[$iso_lang];
} else {
$this->font = self::DEFAULT_FONT;
}
$this->setHeaderFont(array($this->font, '', PDF_FONT_SIZE_MAIN, '', false));
$this->setFooterFont(array($this->font, '', PDF_FONT_SIZE_MAIN, '', false));
$this->setFont($this->font, '', PDF_FONT_SIZE_MAIN, '', false);
}
/**
* @see TCPDF::Header()
*/
public function Header()
{
$this->writeHTML($this->header);
}
/**
* @see TCPDF::Footer()
*/
public function Footer()
{
$this->writeHTML($this->footer);
$this->FontFamily = self::DEFAULT_FONT;
$this->writeHTML($this->pagination);
}
/**
* Render HTML template.
*
* @param string $filename
* @param bool $display true:display to user, false:save, 'I','D','S' as fpdf display
*
* @throws PrestaShopException
*
* @return string HTML rendered
*/
public function render($filename, $display = true)
{
if (empty($filename)) {
throw new PrestaShopException('Missing filename.');
}
$this->lastPage();
if ($display === true) {
$output = 'D';
} elseif ($display === false) {
$output = 'S';
} elseif ($display == 'D') {
$output = 'D';
} elseif ($display == 'S') {
$output = 'S';
} elseif ($display == 'F') {
$output = 'F';
} else {
$output = 'I';
}
return $this->output($filename, $output);
}
/**
* Write a PDF page.
*/
public function writePage()
{
$this->SetHeaderMargin(5);
$this->SetFooterMargin(21);
$this->setMargins(10, 40, 10);
$this->AddPage();
$this->writeHTML($this->content, true, false, true, false, '');
}
/**
* Override of TCPDF::getRandomSeed() - getmypid() is blocked on several hosting.
*/
protected function getRandomSeed($seed = '')
{
$seed .= microtime();
if (function_exists('openssl_random_pseudo_bytes') && (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN')) {
// this is not used on windows systems because it is very slow for a know bug
$seed .= openssl_random_pseudo_bytes(512);
} else {
for ($i = 0; $i < 23; ++$i) {
$seed .= uniqid('', true);
}
}
$seed .= uniqid('', true);
$seed .= rand();
$seed .= __FILE__;
$seed .= $this->bufferlen;
if (isset($_SERVER['REMOTE_ADDR'])) {
$seed .= $_SERVER['REMOTE_ADDR'];
}
if (isset($_SERVER['HTTP_USER_AGENT'])) {
$seed .= $_SERVER['HTTP_USER_AGENT'];
}
if (isset($_SERVER['HTTP_ACCEPT'])) {
$seed .= $_SERVER['HTTP_ACCEPT'];
}
if (isset($_SERVER['HTTP_ACCEPT_ENCODING'])) {
$seed .= $_SERVER['HTTP_ACCEPT_ENCODING'];
}
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
$seed .= $_SERVER['HTTP_ACCEPT_LANGUAGE'];
}
if (isset($_SERVER['HTTP_ACCEPT_CHARSET'])) {
$seed .= $_SERVER['HTTP_ACCEPT_CHARSET'];
}
$seed .= rand();
$seed .= uniqid('', true);
$seed .= microtime();
return $seed;
}
}

34
web/classes/pdf/index.php Normal file
View File

@@ -0,0 +1,34 @@
<?php
/**
* 2007-2018 PrestaShop.
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2018 PrestaShop SA
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Location: ../../');
exit;