// Code Review Invoices V&V

This commit is contained in:
vChabot
2012-02-03 15:55:53 +00:00
parent 1d6a012c57
commit 35c01bb36d
9 changed files with 189 additions and 202 deletions
+23 -25
View File
@@ -32,7 +32,7 @@ include(_PS_ADMIN_DIR_.'/../config/config.inc.php');
if (!Context::getContext()->employee->id)
Tools::redirectAdmin('index.php?controller=AdminLogin');
$functionArray = array(
$function_array = array(
'pdf' => 'generateInvoicePDF',
'id_order_slip' => 'generateOrderSlipPDF',
'id_delivery' => 'generateDeliverySlipPDF',
@@ -44,7 +44,7 @@ $functionArray = array(
'id_supply_order' => 'generateSupplyOrderFormPDF'
);
foreach ($functionArray as $var => $function)
foreach ($function_array as $var => $function)
if (isset($_GET[$var]))
{
call_user_func($function);
@@ -53,16 +53,16 @@ foreach ($functionArray as $var => $function)
function generateSupplyOrderFormPDF()
{
if (!isset($_GET['id_supply_order']))
if (!Tools::isSubmit('id_supply_order'))
die (Tools::displayError('Missing supply order ID'));
$id_supply_order = (int)$_GET['id_supply_order'];
$id_supply_order = (int)Tools::getValue('id_supply_order');
$supply_order = new SupplyOrder($id_supply_order);
if (!Validate::isLoadedObject($supply_order))
die(Tools::displayError('Cannot find this supply order in the database'));
generatePDF($supply_order, PDF::TEMPLATE_SUPPLY_ORDER_FORM);
generatePDF($supply_order, PDF::TEMPLATE_SUPPLY_ORDER_FORM);
}
function generateInvoicePDF()
@@ -78,7 +78,7 @@ function generateInvoicePDF()
function generateInvoicePDFByIdOrder($id_order)
{
$order = new Order($id_order);
$order = new Order((int)$id_order);
if (!Validate::isLoadedObject($order))
die(Tools::displayError('Cannot find order in database'));
@@ -89,7 +89,7 @@ function generateInvoicePDFByIdOrder($id_order)
function generateInvoicePDFByIdOrderInvoice($id_order_invoice)
{
$order_invoice = new OrderInvoice($id_order_invoice);
$order_invoice = new OrderInvoice((int)$id_order_invoice);
if (!Validate::isLoadedObject($order_invoice))
die(Tools::displayError('Cannot find order invoice in database'));
@@ -99,26 +99,25 @@ function generateInvoicePDFByIdOrderInvoice($id_order_invoice)
function generateOrderSlipPDF()
{
$orderSlip = new OrderSlip((int)($_GET['id_order_slip']));
$order = new Order((int)($orderSlip->id_order));
$orderSlip = new OrderSlip((int)Tools::getValue('id_order_slip'));
$order = new Order((int)$orderSlip->id_order);
if (!Validate::isLoadedObject($order))
die(Tools::displayError('Cannot find order in database'));
$order->products = OrderSlip::getOrdersSlipProducts($orderSlip->id, $order);
$tmp = NULL;
generatePDF($orderSlip, PDF::TEMPLATE_ORDER_SLIP);
generatePDF($orderSlip, PDF::TEMPLATE_ORDER_SLIP);
}
function generateDeliverySlipPDF()
{
if (Tools::isSubmit('id_order'))
generateDeliverySlipPDFByIdOrder(Tools::getValue('id_order'));
generateDeliverySlipPDFByIdOrder((int)Tools::getValue('id_order'));
elseif (Tools::isSubmit('id_order_invoice'))
generateDeliverySlipPDFByIdOrderInvoice(Tools::getValue('id_order_invoice'));
generateDeliverySlipPDFByIdOrderInvoice((int)Tools::getValue('id_order_invoice'));
elseif (Tools::isSubmit('id_delivery'))
{
$order = Order::getByDelivery(Tools::getValue('id_delivery'));
generateDeliverySlipPDFByIdOrder($order->id);
$order = Order::getByDelivery((int)Tools::getValue('id_delivery'));
generateDeliverySlipPDFByIdOrder((int)$order->id);
}
else
die (Tools::displayError('Missing order ID or invoice order ID'));
@@ -127,7 +126,7 @@ function generateDeliverySlipPDF()
function generateDeliverySlipPDFByIdOrder($id_order)
{
$order = new Order($id_order);
$order = new Order((int)$id_order);
if (!Validate::isLoadedObject($order))
throw new PrestaShopException('Can\'t load Order object');
@@ -137,7 +136,7 @@ function generateDeliverySlipPDFByIdOrder($id_order)
function generateDeliverySlipPDFByIdOrderInvoice($id_order_invoice)
{
$order_invoice = new OrderInvoice($id_order_invoice);
$order_invoice = new OrderInvoice((int)$id_order_invoice);
if (!Validate::isLoadedObject($order_invoice))
throw new PrestaShopException('Can\'t load Order Invoice object');
@@ -146,9 +145,9 @@ function generateDeliverySlipPDFByIdOrderInvoice($id_order_invoice)
function generateInvoicesPDF()
{
$order_invoice_collection = OrderInvoice::getByDateInterval($_GET['date_from'], $_GET['date_to']);
$order_invoice_collection = OrderInvoice::getByDateInterval(Tools::getValue('date_from'), Tools::getValue('date_to'));
if (!sizeof($order_invoice_collection))
if (!count($order_invoice_collection))
die(Tools::displayError('No invoices found'));
generatePDF($order_invoice_collection, PDF::TEMPLATE_INVOICE);
@@ -158,10 +157,10 @@ function generateInvoicesPDF2()
{
$order_invoice_collection = array();
foreach (explode('-', Tools::getValue('id_order_state')) as $id_order_state)
if (is_array($order_invoices = OrderInvoice::getByStatus($id_order_state)))
if (is_array($order_invoices = OrderInvoice::getByStatus((int)$id_order_state)))
$order_invoice_collection = array_merge($order_invoices, $order_invoice_collection);
if (!sizeof($order_invoice_collection))
if (!count($order_invoice_collection))
die(Tools::displayError('No invoices found'));
generatePDF($order_invoice_collection, PDF::TEMPLATE_INVOICE);
@@ -169,7 +168,7 @@ function generateInvoicesPDF2()
function generateOrderSlipsPDF()
{
$id_order_slips_list = OrderSlip::getSlipsIdByDate($_GET['date_from'], $_GET['date_to']);
$id_order_slips_list = OrderSlip::getSlipsIdByDate(Tools::getValue('date_from'), Tools::getValue('date_to'));
if (!count($id_order_slips_list))
die (Tools::displayError('No order slips found'));
@@ -184,7 +183,7 @@ function generateDeliverySlipsPDF()
{
$order_invoice_collection = OrderInvoice::getByDeliveryDateInterval(Tools::getValue('date_from'), Tools::getValue('date_to'));
if (!sizeof($order_invoice_collection))
if (!count($order_invoice_collection))
die(Tools::displayError('No invoices found'));
generatePDF($order_invoice_collection, PDF::TEMPLATE_DELIVERY_SLIP);
@@ -192,7 +191,6 @@ function generateDeliverySlipsPDF()
function generatePDF($object, $template)
{
global $smarty;
$pdf = new PDF($object, $template, $smarty);
$pdf = new PDF($object, $template, Context::getContext()->smarty);
$pdf->render();
}
+35 -36
View File
@@ -35,7 +35,7 @@ abstract class HTMLTemplateCore
public $date;
public $available_in_your_account = true;
public $smarty;
public $shop;
public $shop;
/**
* Returns the template's HTML header
@@ -43,9 +43,9 @@ abstract class HTMLTemplateCore
*/
public function getHeader()
{
$shop_name = '';
if (Validate::isLoadedObject($this->shop))
$shop_name = $this->shop->name;
$shop_name = '';
if (Validate::isLoadedObject($this->shop))
$shop_name = $this->shop->name;
$this->smarty->assign(array(
'logo_path' => $this->getLogo(),
@@ -65,7 +65,7 @@ abstract class HTMLTemplateCore
*/
public function getFooter()
{
$shop_address = $this->getShopAddress();
$shop_address = $this->getShopAddress();
$this->smarty->assign(array(
'available_in_your_account' => $this->available_in_your_account,
@@ -75,32 +75,33 @@ abstract class HTMLTemplateCore
'shop_details' => Configuration::get('PS_SHOP_DETAILS'),
'free_text' => Configuration::get('PS_INVOICE_FREE_TEXT')
));
return $this->smarty->fetch(_PS_THEME_DIR_.'/pdf/footer.tpl');
}
/**
* Returns the shop address
* @return string
*/
protected function getShopAddress()
{
$shop_address = '';
if (Validate::isLoadedObject($this->shop))
{
$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 shop address
* @return string
*/
protected function getShopAddress()
{
$shop_address = '';
if (Validate::isLoadedObject($this->shop))
{
$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;
}
return $shop_address;
}
return $shop_address;
}
/**
/**
* Returns the invoice logo
*/
protected function getLogo()
{
protected function getLogo()
{
$logo = '';
if (file_exists(_PS_IMG_DIR_.'logo_invoice.jpg'))
@@ -109,7 +110,7 @@ abstract class HTMLTemplateCore
$logo = _PS_IMG_.'logo.jpg';
return $logo;
}
}
/**
* Assign hook data
@@ -122,7 +123,7 @@ abstract class HTMLTemplateCore
$hook_name = 'displayPDF'.$template;
$this->smarty->assign(array(
'HOOK_DISPLAY_PDF' => Hook::exec($hook_name, array('object' => $object)),
'HOOK_DISPLAY_PDF' => Hook::exec($hook_name, array('object' => $object))
));
}
@@ -137,16 +138,13 @@ abstract class HTMLTemplateCore
* Returns the template filename
* @return string filename
*/
abstract public function getFilename();
abstract public function getFilename();
/**
* Returns the template filename when using bulk rendering
* @return string filename
*/
abstract public function getBulkFilename();
abstract public function getBulkFilename();
/**
* Translatation method
@@ -157,15 +155,16 @@ abstract class HTMLTemplateCore
{
$iso = Context::getContext()->language->iso_code;
if (!Validate::isLangIsoCode($iso))
die('Invalid iso lang ('.$iso.')');
if (!Validate::isLangIsoCode($iso))
Tools::displayError(sprintf('Invalid iso lang (%s)', Tools::safeOutput($iso)));
if (@!include(_PS_THEME_DIR_.'pdf/lang/'.$iso.'.php'))
die('Cannot include PDF translation language file : '._PS_THEME_DIR_.'pdf/lang/'.$iso.'.php');
$file_name = _PS_THEME_DIR_.'pdf/lang/'.$iso.'.php';
if (!file_exists($file_name) || !include($file_name))
Tools::displayError(sprintf('Cannot include PDF translation language file : %s', $file_name));
if (!isset($_LANGPDF) || !is_array($_LANGPDF))
return str_replace('"', '"', $string);
$key = md5(str_replace('\'', '\\\'', $string));
$key = md5(str_replace('\'', '\\\'', $string));
$str = (key_exists('PDF'.$key, $_LANGPDF) ? $_LANGPDF['PDF'.$key] : $string);
return $str;
+9 -13
View File
@@ -52,20 +52,16 @@ class HTMLTemplateDeliverySlipCore extends HTMLTemplate
*/
public function getContent()
{
$country = new Country((int)$this->order->id_address_invoice);
$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)$id_address_invoice);
$invoice_address = new Address((int)$this->order->id_address_invoice);
$formatted_invoice_address = AddressFormat::generateAddress($invoice_address, array(), '<br />', ' ');
}
$customer = new Customer($this->order->id_customer);
$this->smarty->assign(array(
'order' => $this->order,
'order_details' => $this->order_invoice->getProducts(),
@@ -81,18 +77,18 @@ class HTMLTemplateDeliverySlipCore extends HTMLTemplate
* Returns the template filename when using bulk rendering
* @return string filename
*/
public function getBulkFilename()
{
return 'deliveries.pdf';
}
public function getBulkFilename()
{
return 'deliveries.pdf';
}
/**
* Returns the template filename
* @return string filename
*/
public function getFilename()
{
return Configuration::get('PS_DELIVERY_PREFIX').sprintf('%06d', $this->order->invoice_number).'.pdf';
}
public function getFilename()
{
return Configuration::get('PS_DELIVERY_PREFIX').sprintf('%06d', $this->order->invoice_number).'.pdf';
}
}
+21 -21
View File
@@ -31,19 +31,19 @@
class HTMLTemplateInvoiceCore extends HTMLTemplate
{
public $order;
public $available_in_your_account = false;
public $available_in_your_account = false;
public function __construct(OrderInvoice $order_invoice, $smarty)
{
$this->order_invoice = $order_invoice;
$this->order = new Order($this->order_invoice->id_order);
$this->order = new Order((int)$this->order_invoice->id_order);
$this->smarty = $smarty;
// header informations
$this->date = Tools::displayDate($order_invoice->date_add, (int)$this->order->id_lang);
$this->title = HTMLTemplateInvoice::l('Invoice ').' #'.Configuration::get('PS_INVOICE_PREFIX', Context::getContext()->language->id).sprintf('%06d', $order_invoice->number);
$id_lang = Context::getContext()->language->id;
$this->title = HTMLTemplateInvoice::l('Invoice ').' #'.Configuration::get('PS_INVOICE_PREFIX', $id_lang).sprintf('%06d', $order_invoice->number);
// footer informations
$this->shop = new Shop((int)$this->order->id_shop);
}
@@ -61,11 +61,11 @@ class HTMLTemplateInvoiceCore extends HTMLTemplate
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 />', ' ');
$delivery_address = new Address((int)$this->order->id_address_delivery);
$formatted_delivery_address = AddressFormat::generateAddress($delivery_address, array(), '<br />', ' ');
}
$customer = new Customer($this->order->id_customer);
$customer = new Customer((int)$this->order->id_customer);
$this->smarty->assign(array(
'order' => $this->order,
@@ -73,7 +73,7 @@ class HTMLTemplateInvoiceCore extends HTMLTemplate
'delivery_address' => $formatted_delivery_address,
'invoice_address' => $formatted_invoice_address,
'tax_excluded_display' => Group::getPriceDisplayMethod($customer->id_default_group),
'tax_tab' => $this->getTaxTabContent(),
'tax_tab' => $this->getTaxTabContent(),
'customer' => $customer
));
@@ -83,12 +83,12 @@ class HTMLTemplateInvoiceCore extends HTMLTemplate
/**
* Returns the tax tab content
*/
public function getTaxTabContent()
{
public function getTaxTabContent()
{
$invoice_address = new Address((int)$this->order->id_address_invoice);
$tax_exempt = Configuration::get('VATNUMBER_MANAGEMENT')
&& !empty($invoiceAddress->vat_number)
&& $invoiceAddress->id_country != Configuration::get('VATNUMBER_COUNTRY');
&& !empty($invoice_address->vat_number)
&& $invoice_address->id_country != Configuration::get('VATNUMBER_COUNTRY');
$this->smarty->assign(array(
'tax_exempt' => $tax_exempt,
@@ -101,7 +101,7 @@ class HTMLTemplateInvoiceCore extends HTMLTemplate
));
return $this->smarty->fetch(_PS_THEME_DIR_.'/pdf/invoice.tax-tab.tpl');
}
}
/**
* Returns the invoice template associated to the country iso_code
@@ -123,18 +123,18 @@ class HTMLTemplateInvoiceCore extends HTMLTemplate
* Returns the template filename when using bulk rendering
* @return string filename
*/
public function getBulkFilename()
{
return 'invoices.pdf';
}
public function getBulkFilename()
{
return 'invoices.pdf';
}
/**
* Returns the template filename
* @return string filename
*/
public function getFilename()
{
return Configuration::get('PS_INVOICE_PREFIX').sprintf('%06d', $this->order_invoice->number).'.pdf';
}
public function getFilename()
{
return Configuration::get('PS_INVOICE_PREFIX').sprintf('%06d', $this->order_invoice->number).'.pdf';
}
}
+22 -23
View File
@@ -30,22 +30,22 @@
*/
class HTMLTemplateOrderReturnCore extends HTMLTemplate
{
public $order_return;
public $order;
public $order_return;
public $order;
public function __construct(OrderReturn $order_return, $smarty)
{
public function __construct(OrderReturn $order_return, $smarty)
{
$this->order_return = $order_return;
$this->smarty = $smarty;
$this->order = new Order($order_return->id_order);
$this->smarty = $smarty;
$this->order = new Order($order_return->id_order);
// header informations
$this->date = Tools::displayDate($this->order->invoice_date, (int)$this->order->id_lang);
$this->title = HTMLTemplateOrderReturn::l('Order Return '.sprintf('%06d', $this->order_return->id)); // TODO
$this->title = HTMLTemplateOrderReturn::l('Order Return '.sprintf('%06d', $this->order_return->id));
// footer informations
$this->shop = new Shop((int)$this->order->id_shop);
}
}
/**
* Returns the template's HTML content
@@ -59,37 +59,36 @@ class HTMLTemplateOrderReturnCore extends HTMLTemplate
if ($this->order->id_address_delivery != $this->order->id_address_invoice)
{
$invoice_address = new Address((int)$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,
'order_return' => $this->order_return,
'return_nb_days' => (int)Configuration::get('PS_ORDER_RETURN_NB_DAYS'),
'products' => OrderReturn::getOrdersReturnProducts($this->order_return->id, $this->order),
'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->address, array(), '<br />', ' ')
));
return $this->smarty->fetch(_PS_THEME_DIR_.'/pdf/order-return.tpl');
'shop_address' => AddressFormat::generateAddress($this->address, array(), '<br />', ' ')
));
return $this->smarty->fetch(_PS_THEME_DIR_.'/pdf/order-return.tpl');
}
/**
* Returns the template filename
* @return string filename
*/
public function getFilename()
{
return sprintf('%06d', $this->order_return->id).'.pdf'; // TODO
}
public function getFilename()
{
return sprintf('%06d', $this->order_return->id).'.pdf';
}
/**
* Returns the template filename when using bulk rendering
* @return string filename
*/
public function getBulkFilename()
{
return 'invoices.pdf';
}
public function getBulkFilename()
{
return 'invoices.pdf';
}
}
+24 -28
View File
@@ -39,15 +39,15 @@ class HTMLTemplateOrderSlipCore extends HTMLTemplateInvoice
$this->order = new Order((int)$order_slip->id_order);
$products = OrderSlip::getOrdersSlipProducts($this->order_slip->id, $this->order);
$customizedDatas = Product::getAllCustomizedDatas((int)($this->order->id_cart));
Product::addCustomizationPrice($products, $customizedDatas);
$customized_datas = Product::getAllCustomizedDatas((int)$this->order->id_cart);
Product::addCustomizationPrice($products, $customized_datas);
$this->order->products = $products;
$this->smarty = $smarty;
// header informations
$this->date = Tools::displayDate($this->order->invoice_date, (int)$this->order->id_lang);
$this->title = HTMLTemplateOrderSlip::l('Slip #').sprintf('%06d', $this->order_slip->id);
$this->title = HTMLTemplateOrderSlip::l('Slip #').sprintf('%06d', (int)$this->order_slip->id);
// footer informations
$this->shop = new Shop((int)$this->order->id_shop);
@@ -59,7 +59,6 @@ class HTMLTemplateOrderSlipCore extends HTMLTemplateInvoice
*/
public function getContent()
{
$country = new Country((int)$this->order->id_address_invoice);
$invoice_address = new Address((int)$this->order->id_address_invoice);
$formatted_invoice_address = AddressFormat::generateAddress($invoice_address, array(), '<br />', ' ');
$formatted_delivery_address = '';
@@ -70,36 +69,34 @@ class HTMLTemplateOrderSlipCore extends HTMLTemplateInvoice
$formatted_delivery_address = AddressFormat::generateAddress($delivery_address, array(), '<br />', ' ');
}
$customer = new Customer($this->order->id_customer);
$customer = new Customer((int)$this->order->id_customer);
$this->order->total_products = 0;
$this->order->total_products_wt = 0;
foreach ($this->order->products as $k => $p)
$this->order->total_products = $this->order->total_products_wt = 0;
foreach ($this->order->products as &$product)
{
$this->order->products[$k]['total_price_tax_excl'] = $this->order->products[$k]['unit_price_tax_excl'] * $this->order->products[$k]['product_quantity'];
$this->order->products[$k]['total_price_tax_incl'] = $this->order->products[$k]['unit_price_tax_incl'] * $this->order->products[$k]['product_quantity'];
$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)$p['id_order_detail']);
$this->order->products[$k]['total_price_tax_excl'] = $order_slip_detail['amount_tax_excl'];
$this->order->products[$k]['total_price_tax_incl'] = $order_slip_detail['amount_tax_incl'];
$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 += $this->order->products[$k]['total_price_tax_excl'];
$this->order->total_products_wt += $this->order->products[$k]['total_price_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;
}
unset($product); // remove reference
if ($this->order_slip->shipping_cost == 0)
{
$this->order->total_shipping_tax_incl = 0;
$this->order->total_shipping_tax_excl = 0;
}
$this->order->total_shipping_tax_incl = $this->order->total_shipping_tax_excl = 0;
if ($this->order_slip->partial == 1 && $this->order_slip->shipping_cost_amount > 0)
{
$this->order->total_shipping_tax_incl = $this->order_slip->shipping_cost_amount;
$this->order->total_shipping_tax_excl = $this->order_slip->shipping_cost_amount;
}
$this->order->total_shipping_tax_incl = $this->order->total_shipping_tax_excl = $this->order_slip->shipping_cost_amount;
$this->order->total_paid_tax_incl += $this->order->total_shipping_tax_incl;
$this->order->total_paid_tax_excl += $this->order->total_shipping_tax_excl;
@@ -109,8 +106,8 @@ class HTMLTemplateOrderSlipCore extends HTMLTemplateInvoice
'order_details' => $this->order->products,
'delivery_address' => $formatted_delivery_address,
'invoice_address' => $formatted_invoice_address,
'tax_excluded_display' => Group::getPriceDisplayMethod($customer->id_default_group),
'tax_tab' => '',
'tax_excluded_display' => Group::getPriceDisplayMethod((int)$customer->id_default_group),
'tax_tab' => '',
));
return $this->smarty->fetch(_PS_THEME_DIR_.'/pdf/order-slip.tpl');
@@ -133,5 +130,4 @@ class HTMLTemplateOrderSlipCore extends HTMLTemplateInvoice
{
return 'order-slip-'.sprintf('%06d', $this->order_slip->id).'.pdf';
}
}
}
+40 -39
View File
@@ -39,13 +39,13 @@ class HTMLTemplateSupplyOrderFormCore extends HTMLTemplate
public function __construct(SupplyOrder $supply_order, $smarty)
{
$this->supply_order = $supply_order;
$this->smarty = $smarty;
$this->context = Context::getContext();
$this->warehouse = new Warehouse($supply_order->id_warehouse);
$this->address_warehouse = new Address($this->warehouse->id_address);
$this->address_supplier = new Address(Address::getAddressIdBySupplierId($supply_order->id_supplier));
$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
// header informations
$this->date = Tools::displayDate($supply_order->date_add, (int)$this->supply_order->id_lang);
$this->title = HTMLTemplateSupplyOrderForm::l('Supply order form').sprintf(' %s', $supply_order->reference);
}
@@ -55,13 +55,13 @@ class HTMLTemplateSupplyOrderFormCore extends HTMLTemplate
*/
public function getContent()
{
$supply_order_details = $this->supply_order->getEntriesCollection($this->supply_order->id_lang);
$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($this->supply_order->id_currency);
$currency = new Currency((int)$this->supply_order->id_currency);
$this->smarty->assign(array(
'warehouse' => $this->warehouse,
@@ -78,46 +78,47 @@ class HTMLTemplateSupplyOrderFormCore extends HTMLTemplate
/**
* @see HTMLTemplate::getBulkFilename()
*/
public function getBulkFilename()
{
return 'supply_order.pdf';
}
public function getBulkFilename()
{
return 'supply_order.pdf';
}
/**
* @see HTMLTemplate::getFileName()
*/
public function getFilename()
{
return (self::l('SupplyOrderForm').sprintf('_%s', $this->supply_order->reference).'.pdf');
}
public function getFilename()
{
return self::l('SupplyOrderForm').sprintf('_%s', $this->supply_order->reference).'.pdf';
}
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');
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);
$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);
}
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;
}
return $results;
}
/**
* @see HTMLTemplate::getFooter()
*/
/**
* @see HTMLTemplate::getFooter()
*/
public function getFooter()
{
$this->address = $this->address_warehouse;
+8 -9
View File
@@ -81,13 +81,13 @@ class PDFCore
}
if ($render)
return $this->pdf_renderer->render($this->filename, $display);
return $this->pdf_renderer->render($this->filename, $display);
}
public function getTemplateObject($object)
{
$class = false;
$classname = 'HTMLTemplate'.$this->template;
public function getTemplateObject($object)
{
$class = false;
$classname = 'HTMLTemplate'.$this->template;
if (class_exists($classname))
{
@@ -96,7 +96,6 @@ class PDFCore
throw new PrestaShopException('Invalid class. It should be an instance of HTMLTemplate');
}
return $class;
}
}
return $class;
}
}
+7 -8
View File
@@ -94,7 +94,7 @@ class PDFGeneratorCore extends TCPDF
*/
public function setFontForLang($iso_lang)
{
$this->font = self::DEFAULT_FONT;
$this->font = PDFGenerator::DEFAULT_FONT;
if (array_key_exists($iso_lang, $this->font_by_lang))
$this->font = $this->font_by_lang[$iso_lang];
@@ -106,7 +106,7 @@ class PDFGeneratorCore extends TCPDF
*/
public function Header()
{
$this->writehtml($this->header);
$this->writeHTML($this->header);
}
/**
@@ -114,7 +114,7 @@ class PDFGeneratorCore extends TCPDF
*/
public function Footer()
{
$this->writehtml($this->footer);
$this->writeHTML($this->footer);
}
/**
@@ -131,8 +131,8 @@ class PDFGeneratorCore extends TCPDF
$this->lastPage();
$output = $display ? 'I' : 'S';
return $this->output($filename, $output);
$output = $display ? 'I' : 'S';
return $this->output($filename, $output);
}
/**
@@ -147,7 +147,6 @@ class PDFGeneratorCore extends TCPDF
$this->AddPage();
$this->writehtml($this->content, true, false, true, false, '');
$this->writeHTML($this->content, true, false, true, false, '');
}
}
}