[*] PDF : PDF is now rendered by TCPDF throught HTML template

git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@10231 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
fBrignoli
2011-11-17 17:15:23 +00:00
parent ab22eaf449
commit e5f3c3ca2a
33 changed files with 1917 additions and 213 deletions
+159 -1
View File
@@ -55,7 +55,7 @@ class OrderCore extends ObjectModel
/** @var string Secure key */
public $secure_key;
/** @var string Payment method id */
/** @var string Payment method */
public $payment;
/** @var string Payment module */
@@ -79,9 +79,18 @@ class OrderCore extends ObjectModel
/** @var float Discounts total */
public $total_discounts;
public $total_discounts_tax_incl;
public $total_discounts_tax_excl;
/** @var float Total to pay */
public $total_paid;
/** @var float Total to pay tax included */
public $total_paid_tax_incl;
/** @var float Total to pay tax excluded */
public $total_paid_tax_excl;
/** @var float Total really paid */
public $total_paid_real;
@@ -94,12 +103,24 @@ class OrderCore extends ObjectModel
/** @var float Shipping total */
public $total_shipping;
/** @var float Shipping total tax included */
public $total_shipping_tax_incl;
/** @var float Shipping total tax excluded */
public $total_shipping_tax_excl;
/** @var float Shipping tax rate */
public $carrier_tax_rate;
/** @var float Wrapping total */
public $total_wrapping;
/** @var float Wrapping total tax included */
public $total_wrapping_tax_incl;
/** @var float Wrapping total tax excluded */
public $total_wrapping_tax_excl;
/** @var integer Invoice number */
public $invoice_number;
@@ -219,13 +240,21 @@ class OrderCore extends ObjectModel
$fields['gift_message'] = pSQL($this->gift_message);
$fields['shipping_number'] = pSQL($this->shipping_number);
$fields['total_discounts'] = (float)($this->total_discounts);
$fields['total_discounts_tax_incl'] = (float)($this->total_discounts_tax_incl);
$fields['total_discounts_tax_excl'] = (float)($this->total_discounts_tax_excl);
$fields['total_paid'] = (float)($this->total_paid);
$fields['total_paid_tax_incl'] = (float)($this->total_paid_tax_incl);
$fields['total_paid_tax_excl'] = (float)($this->total_paid_tax_excl);
$fields['total_paid_real'] = (float)($this->total_paid_real);
$fields['total_products'] = (float)($this->total_products);
$fields['total_products_wt'] = (float)($this->total_products_wt);
$fields['total_shipping'] = (float)($this->total_shipping);
$fields['total_shipping_tax_incl'] = (float)($this->total_shipping_tax_incl);
$fields['total_shipping_tax_excl'] = (float)($this->total_shipping_tax_excl);
$fields['carrier_tax_rate'] = (float)($this->carrier_tax_rate);
$fields['total_wrapping'] = (float)($this->total_wrapping);
$fields['total_wrapping_tax_incl'] = (float)($this->total_wrapping_tax_incl);
$fields['total_wrapping_tax_excl'] = (float)($this->total_wrapping_tax_excl);
$fields['invoice_number'] = (int)($this->invoice_number);
$fields['delivery_number'] = (int)($this->delivery_number);
$fields['invoice_date'] = pSQL($this->invoice_date);
@@ -1146,4 +1175,133 @@ class OrderCore extends ObjectModel
return false;
}
/**
* This method returns true if at least one order details uses the
* One After Another tax computation method.
*
* @since 1.5.0.1
* @return boolean
*/
public function useOneAfterAnotherTaxComputationMethod()
{
// if one of the order details use the tax computation method the display will be different
return Db::getInstance()->getValue('
SELECT od.`tax_computation_method`
FROM `'._DB_PREFIX_.'order_detail_tax` odt
LEFT JOIN `'._DB_PREFIX_.'order_detail` od ON (od.`id_order_detail` = odt.`id_order_detail`)
WHERE od.`id_order` = '.(int)$this->id.'
AND od.`tax_computation_method` = '.(int)TaxCalculator::ONE_AFTER_ANOTHER_METHOD
);
}
/**
* Returns the correct product taxes breakdown.
*
* @since 1.5.0.1
* @return array
*/
public function getProductTaxesBreakdown()
{
$tmp_tax_infos = array();
if ($this->useOneAfterAnotherTaxComputationMethod())
{
// sum by taxes
$taxes_by_tax = Db::getInstance()->executeS('
SELECT odt.`id_order_detail`, t.`name`, t.`rate`, SUM(`total_amount`) AS `total_amount`
FROM `'._DB_PREFIX_.'order_detail_tax` odt
LEFT JOIN `'._DB_PREFIX_.'tax` t ON (t.`id_tax` = odt.`id_tax`)
LEFT JOIN `'._DB_PREFIX_.'order_detail` od ON (od.`id_order_detail` = odt.`id_order_detail`)
WHERE od.`id_order` = '.(int)$this->id.'
GROUP BY odt.`id_tax`
');
// format response
$tmp_tax_infos = array();
foreach ($taxes_infos as $tax_infos)
{
$tmp_tax_infos[$tax_infos['rate']]['total_amount'] = $tax_infos['tax_amount'];
$tmp_tax_infos[$tax_infos['rate']]['name'] = $tax_infos['name'];
}
}
else
{
// sum by order details in order to retrieve real taxes rate
$taxes_infos = Db::getInstance()->executeS('
SELECT odt.`id_order_detail`, t.`rate` AS `name`, SUM(od.`total_price_tax_excl`) AS total_price_tax_excl, SUM(t.`rate`) AS rate, SUM(`total_amount`) AS `total_amount`
FROM `'._DB_PREFIX_.'order_detail_tax` odt
LEFT JOIN `'._DB_PREFIX_.'tax` t ON (t.`id_tax` = odt.`id_tax`)
LEFT JOIN `'._DB_PREFIX_.'order_detail` od ON (od.`id_order_detail` = odt.`id_order_detail`)
WHERE od.`id_order` = '.(int)$this->id.'
GROUP BY odt.`id_order_detail`
');
// sum by taxes
$tmp_tax_infos = array();
foreach ($taxes_infos as $tax_infos)
{
if (!isset($tmp_tax_infos[$tax_infos['rate']]))
$tmp_tax_infos[$tax_infos['rate']] = array('total_amount' => 0,
'name' => 0,
'total_price_tax_excl' => 0);
$tmp_tax_infos[$tax_infos['rate']]['total_amount'] += $tax_infos['total_amount'];
$tmp_tax_infos[$tax_infos['rate']]['name'] = $tax_infos['name'];
$tmp_tax_infos[$tax_infos['rate']]['total_price_tax_excl'] += $tax_infos['total_price_tax_excl'];
}
}
return $tmp_tax_infos;
}
/**
* Returns the shipping taxes breakdown
*
* @since 1.5.0.1
* @return array
*/
public function getShippingTaxesBreakdown()
{
$taxes_breakdown = array();
$shipping_tax_amount = $this->total_shipping_tax_incl - $this->total_shipping_tax_excl;
if ($shipping_tax_amount > 0)
$taxes_breakdown[] = array(
'rate' => $this->carrier_tax_rate,
'total_amount' => $shipping_tax_amount
);
return $taxes_breakdown;
}
/**
* Returns the wrapping taxes breakdown
* @todo
* @since 1.5.0.1
* @return array
*/
public function getWrappingTaxesBreakdown()
{
$taxes_breakdown = array();
return $taxes_breakdown;
}
/**
* Returns the ecotax taxes breakdown
*
* @since 1.5.0.1
* @return array
*/
public function getEcoTaxTaxesBreakdown()
{
return Db::getInstance()->executeS('
SELECT `ecotax_tax_rate`, SUM(`ecotax`) as `ecotax_tax_excl`, SUM(`ecotax`) as `ecotax_tax_incl`
FROM `'._DB_PREFIX_.'order_detail`
WHERE `id_order` = '.(int)$this->id
);
}
}
+119 -79
View File
@@ -60,6 +60,18 @@ class OrderDetailCore extends ObjectModel
/** @var float */
public $product_price;
/** @var float */
public $unit_price_tax_incl;
/** @var float */
public $unit_price_tax_excl;
/** @var float */
public $total_price_tax_incl;
/** @var float */
public $total_price_tax_excl;
/** @var float */
public $reduction_percent;
@@ -87,12 +99,6 @@ class OrderDetailCore extends ObjectModel
/** @var float */
public $product_weight;
/** @var string */
public $tax_name;
/** @var float */
public $tax_rate;
/** @var float */
public $ecotax;
@@ -111,12 +117,18 @@ class OrderDetailCore extends ObjectModel
/** @var date */
public $download_deadline;
/** @var string $tax_name **/
public $tax_name;
/** @var float $tax_rate **/
public $tax_rate;
protected $tables = array('order_detail');
protected $fieldsRequired = array(
'id_order',
'product_name',
'product_quantity',
'id_order',
'product_name',
'product_quantity',
'product_price');
protected $fieldsValidate = array(
@@ -146,7 +158,11 @@ class OrderDetailCore extends ObjectModel
'discount_quantity_applied' => 'isInt',
'download_hash' => 'isGenericName',
'download_nb' => 'isInt',
'download_deadline' => 'isDateFormat'
'download_deadline' => 'isDateFormat',
'unit_price_tax_incl' => 'isPrice',
'unit_price_tax_excl' => 'isPrice',
'total_price_tax_incl' => 'isPrice',
'total_price_tax_excl' => 'isPrice'
);
protected $table = 'order_detail';
@@ -164,22 +180,22 @@ class OrderDetailCore extends ObjectModel
'download_deadline' => array()
)
);
/** @var bool */
protected $outOfStock = false;
/** @var TaxCalculator object */
protected $tax_calculator = null;
/** @var Address object */
protected $vat_address = null;
/** @var Address object */
protected $specificPrice = null;
/** @var Customer object */
protected $customer = null;
/** @var Context object */
protected $context = null;
@@ -187,7 +203,7 @@ class OrderDetailCore extends ObjectModel
{
$this->context = $context;
}
public function getFields()
{
$this->validateFields();
@@ -218,6 +234,10 @@ class OrderDetailCore extends ObjectModel
$fields['download_hash'] = pSQL($this->download_hash);
$fields['download_nb'] = (int)$this->download_nb;
$fields['download_deadline'] = pSQL($this->download_deadline);
$fields['unit_price_tax_incl'] = (float)$this->unit_price_tax_incl;
$fields['unit_price_tax_excl'] = (float)$this->unit_price_tax_excl;
$fields['total_price_tax_incl'] = (float)$this->total_price_tax_incl;
$fields['total_price_tax_excl'] = (float)$this->total_price_tax_excl;
return $fields;
}
@@ -245,6 +265,7 @@ class OrderDetailCore extends ObjectModel
/**
* Returns the tax calculator associated to this order detail.
* @since 1.5.0.1
* @return TaxCalculator
*/
public function getTaxCalculator()
@@ -254,6 +275,7 @@ class OrderDetailCore extends ObjectModel
/**
* Return the tax calculator associated to this order_detail
* @since 1.5.0.1
* @param int $id_order_detail
* @return TaxCalculator
*/
@@ -279,26 +301,36 @@ class OrderDetailCore extends ObjectModel
/**
* Save the tax calculator
* @param int $id_order_detail
* @param TaxCalculator $tax_calculator
* @since 1.5.0.1
* @return boolean
*/
public static function saveTaxCalculatorStatic($id_order_detail, TaxCalculator $tax_calculator)
public function saveTaxCalculator()
{
if (count($tax_calculator->taxes) == 0)
// Nothing to save
if ($this->tax_calculator == null)
return true;
if (!($this->tax_calculator instanceOf TaxCalculator))
return false;
if (count($this->tax_calculator->taxes) == 0)
return true;
$values = '';
foreach ($tax_calculator->taxes as $tax)
$values .= '('.(int)$id_order_detail.','.(float)$tax->id.'),';
foreach ($this->tax_calculator->getTaxesAmount($this->unit_price_tax_excl) as $id_tax => $amount)
{
$unit_amount = (float)Tools::ps_round($amount, 2);
$total_amount = $unit_amount * $this->product_quantity;
$values .= '('.(int)$this->id.','.(float)$id_tax.','.$unit_amount.','.(float)$total_amount.'),';
}
$values = rtrim($values, ',');
$sql = 'INSERT INTO `'._DB_PREFIX_.'order_detail_tax` (id_order_detail, id_tax)
$sql = 'INSERT INTO `'._DB_PREFIX_.'order_detail_tax` (id_order_detail, id_tax, unit_amount, total_amount)
VALUES '.$values;
return Db::getInstance()->execute($sql);
}
}
/**
* Get a detailed order list of an id_order
* @param int $id_order
@@ -308,14 +340,14 @@ class OrderDetailCore extends ObjectModel
{
$sql = '
SELECT *
FROM `'._DB_PREFIX_.'`order_detail
FROM `'._DB_PREFIX_.'order_detail`
WHERE `id_order` = '.(int)$id_order;
return Db::getInstance()->executeS($sql);
}
/*
* Set virtual product information
* Set virtual product information
* @param array $product
*/
protected function setVirtualProductInformation($product)
@@ -323,17 +355,17 @@ class OrderDetailCore extends ObjectModel
// Add some informations for virtual products
$this->download_deadline = '0000-00-00 00:00:00';
$this->download_hash = null;
if ($id_product_download = ProductDownload::getIdFromIdProduct((int)($product['id_product'])))
{
$productDownload = new ProductDownload((int)($id_product_download));
$this->download_deadline = $productDownload->getDeadLine();
$this->download_hash = $productDownload->getHash();
unset($productDownload);
}
}
/**
* Check the order state
* @param array $product
@@ -350,7 +382,7 @@ class OrderDetailCore extends ObjectModel
Product::updateDefaultAttribute($product['id_product']);
}
}
/**
* Apply tax to the product
* @param object $order
@@ -359,7 +391,7 @@ class OrderDetailCore extends ObjectModel
protected function setProductTax(Order $order, $product)
{
$this->ecotax = Tools::convertPrice(floatval($product['ecotax']), intval($order->id_currency));
// Exclude VAT
if (!Tax::excludeTaxeOption())
{
@@ -372,19 +404,19 @@ class OrderDetailCore extends ObjectModel
$this->ecotax_tax_rate = 0;
if (!empty($product['ecotax']))
$this->ecotax_tax_rate = Tax::getProductEcotaxRate($order->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
$this->tax_computation_method = (int)$this->tax_calculator->computation_method;
}
/**
* Set specific price of the product
* @param object $order
*/
protected function setSpecificPrice(Order $order)
{
$this->reduction_amont = 0.00;
$this->reduction_amount = 0.00;
$this->reduction_percent = 0.00;
if ($this->specificPrice)
switch($this->specificPrice['reduction_type'])
{
@@ -393,11 +425,11 @@ class OrderDetailCore extends ObjectModel
break;
case 'amount':
$price = Tools::convertPrice($this->specificPrice['reduction'], $order->id_currency);
$this->reduction_amont = (float)(!$this->specificPrice['id_currency'] ?
$this->reduction_amount = (float)(!$this->specificPrice['id_currency'] ?
$price : $this->specificPrice['reduction']);
}
}
/**
* Set detailed product price to the order detail
* @param object $order
@@ -406,34 +438,42 @@ class OrderDetailCore extends ObjectModel
*/
protected function setDetailProductPrice(Order $order, Cart $cart, $product)
{
$this->specificPrice = null;
$this->product_price = (float)Product::getPriceStatic((int)($product['id_product']), false,
($product['id_product_attribute'] ? (int)($product['id_product_attribute']) : null),
(Product::getTaxCalculationMethod((int)($order->id_customer)) == PS_TAX_EXC ? 2 : 6),
null, false, false, $product['cart_quantity'], false, (int)($order->id_customer),
(int)($order->id_cart), (int)($order->{Configuration::get('PS_TAX_ADDRESS_TYPE')}), $this->specificPrice, false, false);
$customer = new Customer((int)$order->id_customer);
$customer_address = new Address((int)$order->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
$this->specificPrice = SpecificPrice::getSpecificPrice((int)$product['id_product'],
(int)$order->id_shop,
(int)$order->id_currency,
(int)$customer_address->id_country,
(int)$customer->id_default_group,
(int)$product['cart_quantity']);
$this->product_price = (float)$product['price'];
$this->unit_price_tax_incl = (float)$product['price_wt'];
$this->unit_price_tax_excl = (float)$product['price'];
$this->total_price_tax_incl = (float)$product['total_wt'];
$this->total_price_tax_excl = (float)$product['total'];
$this->setSpecificPrice($order);
$this->group_reduction = (float)(Group::getReduction((int)($order->id_customer)));
$quantityDiscount = SpecificPrice::getQuantityDiscount((int)$product['id_product'], $this->context->shop->getID(),
$quantityDiscount = SpecificPrice::getQuantityDiscount((int)$product['id_product'], $this->context->shop->getID(),
(int)$cart->id_currency, (int)$this->vat_address->id_country,
(int)$this->customer->id_default_group, (int)$product['cart_quantity']);
$unitPrice = Product::getPriceStatic((int)$product['id_product'], true,
($product['id_product_attribute'] ? intval($product['id_product_attribute']) : null),
$unitPrice = Product::getPriceStatic((int)$product['id_product'], true,
($product['id_product_attribute'] ? intval($product['id_product_attribute']) : null),
2, null, false, true, 1, false, (int)$order->id_customer, null, (int)$order->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
$this->product_quantity_discount = (float)($quantityDiscount ?
((Product::getTaxCalculationMethod((int)$order->id_customer) == PS_TAX_EXC ?
Tools::ps_round($unitPrice, 2) : $unitPrice) - $this->tax_calculator->addTaxes($quantityDiscount['price'])) :
$this->product_quantity_discount = (float)($quantityDiscount ?
((Product::getTaxCalculationMethod((int)$order->id_customer) == PS_TAX_EXC ?
Tools::ps_round($unitPrice, 2) : $unitPrice) - $this->tax_calculator->addTaxes($quantityDiscount['price'])) :
0.00);
$this->discount_quantity_applied = (($this->specificPrice && $this->specificPrice['from_quantity'] > 1) ? 1 : 0);
}
/**
* Create an order detail liable to an id_order
* @param object $order
@@ -444,38 +484,38 @@ class OrderDetailCore extends ObjectModel
protected function create(Order $order, Cart $cart, $product, $id_order_state)
{
$this->tax_calculator = new TaxCalculator();
$this->id = null;
$this->product_id = (int)($product['id_product']);
$this->product_attribute_id = (int)($product['id_product_attribute'] ? (int)($product['id_product_attribute']) : null);
$this->product_name = pSQL($product['name'].
((isset($product['attributes']) && $product['attributes'] != null) ?
((isset($product['attributes']) && $product['attributes'] != null) ?
' - '.$product['attributes'] : ''));
$this->product_quantity = (int)($product['cart_quantity']);
$this->product_ean13 = empty($product['ean13']) ? null : pSQL($product['ean13']);
$this->product_upc = empty($product['upc']) ? null : pSQL($product['upc']);
$this->product_reference = empty($product['reference']) ? null : pSQL($product['reference']);
$this->product_supplier_reference = empty($product['supplier_reference']) ? null : pSQL($product['supplier_reference']);
$this->product_weight = (float)$product['id_product_attribute'] ? $product['weight_attribute'] : $product['weight'];
$productQuantity = (int)(Product::getQuantity($this->product_id, $this->product_attribute_id));
$this->product_quantity_in_stock = ($productQuantity - (int)($product['cart_quantity']) < 0) ?
$this->product_quantity_in_stock = ($productQuantity - (int)($product['cart_quantity']) < 0) ?
$productQuantity : (int)($product['cart_quantity']);
$this->setVirtualProductInformation($product);
$this->checkProductStock($product, $id_order_state);
$this->setProductTax($order, $product);
$this->setDetailProductPrice($order, $cart, $product);
// Add new entry to the table
$this->save();
$this->setDetailProductPrice($order, $cart, $product);
OrderDetail::saveTaxCalculatorStatic($this->id, $this->tax_calculator);
// Add new entry to the table
$this->save();
$this->saveTaxCalculator();
unset($this->tax_calculator);
}
/**
* Create a list of order detail for a specified id_order using cart
* @param object $order
@@ -483,22 +523,22 @@ class OrderDetailCore extends ObjectModel
* @param int $id_order_status
*/
public function createList(Order $order, Cart $cart, $id_order_state)
{
{
$this->vat_address = new Address((int)($order->{Configuration::get('PS_TAX_ADDRESS_TYPE')}));
$this->customer = new Customer((int)($order->id_customer));
$this->id_order = $order->id;
$products = $cart->getProducts();
$this->outOfStock = false;
foreach ($products as $product)
$this->create($order, $cart, $product, $id_order_state);
unset($this->vat_address);
unset($products);
unset($this->customer);
}
/**
* Get the state of the current stock product
* @return array
+151
View File
@@ -0,0 +1,151 @@
<?php
/*
* 2007-2011 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:
* http://opensource.org/licenses/osl-3.0.php
* 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-2011 PrestaShop SA
* @version Release: $Revision: 8797 $
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
/**
* @since 1.5
*/
abstract class HTMLTemplateCore
{
public $title;
public $date;
public $address;
public $available_in_your_account = true;
public $smarty;
/**
* Returns the template's HTML header
* @return string HTML header
*/
public function getHeader()
{
$this->assignHookData();
$this->smarty->assign(array(
'logo_path' => $this->getLogo(),
'img_ps_dir' => 'http://'.Tools::getMediaServer(_PS_IMG_)._PS_IMG_,
'img_update_time' => Configuration::get('PS_IMG_UPDATE_TIME'),
'title' => $this->title,
'date' => $this->date,
'shop_name' => Configuration::get('PS_SHOP_NAME')
));
return $this->smarty->fetch(_PS_THEME_DIR_.'/pdf/header.tpl');
}
/**
* Returns the template's HTML footer
* @return string HTML footer
*/
public function getFooter()
{
$shop_address = '';
if (isset($this->address) && $this->address instanceof Address)
$shop_address = AddressFormat::generateAddress($this->address, array(), ' - ', ' ');
$this->smarty->assign(array(
'available_in_your_account' => $this->available_in_your_account,
'shop_address' => $shop_address,
'shop_fax' => Configuration::get('PS_SHOP_FAX'),
'shop_phone' => Configuration::get('PS_SHOP_PHONE'),
'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 invoice logo
*/
protected function getLogo()
{
$logo = '';
if (file_exists(_PS_IMG_DIR_.'logo_invoice.jpg'))
$logo = 'img/logo_invoice.jpg';
else if (file_exists(_PS_IMG_DIR_.'logo.jpg'))
$logo = 'img/logo.jpg';
return Tools::getShopDomain(true).__PS_BASE_URI__.'/'.$logo;
}
/**
* Returns the HTML content of the template's footer
*/
public function assignHookData()
{
$data = array('title' => 'cool',
'delivery' => array('date' => '25/11/11', 'delay' => '3'));
foreach ($data as $key => $value)
$this->smarty->assign($key, $value);
}
/**
* 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();
/**
* Translatation method
* @param string $string
* @return string translated text
*/
protected static function l($string)
{
$iso = Context::getContext()->language->iso_code;
if (!Validate::isLangIsoCode($iso))
die('Invalid iso lang ('.$iso.')');
if (@!include(_PS_THEME_DIR_.'pdf/'.'fr'.'.php'))
die('Cannot include PDF translation language file : '._PS_THEME_DIR_.'pdf/'.$iso.'.php');
if (!isset($_LANGPDF) OR !is_array($_LANGPDF))
return str_replace('"', '&quot;', $string);
$key = md5(str_replace('\'', '\\\'', $string));
$str = (key_exists('PDF_invoice'.$key, $_LANGPDF) ? $_LANGPDF['PDF_invoice'.$key] : $string);
return $str;
}
}
+97
View File
@@ -0,0 +1,97 @@
<?php
/*
* 2007-2011 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:
* http://opensource.org/licenses/osl-3.0.php
* 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-2011 PrestaShop SA
* @version Release: $Revision: 8797 $
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
/**
* @since 1.5
*/
class HTMLTemplateDeliverySlipCore extends HTMLTemplate
{
public $order;
public function __construct(Order $order, $smarty)
{
$this->order = $order;
$this->smarty = $smarty;
// header informations
$this->date = Tools::displayDate($order->invoice_date, (int)$order->id_lang);
$this->title = 'Invoice '.Configuration::get('PS_INVOICE_PREFIX').sprintf('%06d', $order->invoice_number);
// footer informations
$shop = new Shop((int)$order->id_shop);
$this->address = $shop->getAddress();
}
/**
* Returns the template's HTML content
* @return string HTML content
*/
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);
$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->getProducts(),
'delivery_address' => $formatted_delivery_address,
'invoice_address' => $formatted_invoice_address,
));
return $this->smarty->fetch(_PS_THEME_DIR_.'/pdf/delivery-slip.tpl');
}
/**
* 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').sprintf('%06d', $this->order->invoice_number).'.pdf';
}
}
+137
View File
@@ -0,0 +1,137 @@
<?php
/*
* 2007-2011 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:
* http://opensource.org/licenses/osl-3.0.php
* 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-2011 PrestaShop SA
* @version Release: $Revision: 8797 $
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
/**
* @since 1.5
*/
class HTMLTemplateInvoiceCore extends HTMLTemplate
{
public $order;
public $available_in_your_account = false;
public function __construct(Order $order, $smarty)
{
$this->order = $order;
$this->smarty = $smarty;
// header informations
$this->date = Tools::displayDate($order->invoice_date, (int)$order->id_lang);
$this->title = self::l('Invoice ').Configuration::get('PS_INVOICE_PREFIX').sprintf('%06d', $order->invoice_number);
// footer informations
$shop = new Shop((int)$order->id_shop);
$this->address = $shop->getAddress();
}
/**
* Returns the template's HTML content
* @return string HTML content
*/
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 = '';
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($this->order->id_customer);
$this->smarty->assign(array(
'order' => $this->order,
'order_details' => $this->order->getProducts(),
'delivery_address' => $formatted_delivery_address,
'invoice_address' => $formatted_invoice_address,
'tax_excluded_display' => Group::getPriceDisplayMethod($customer->id_default_group),
'tax_tab' => $this->getTaxTabContent()
));
return $this->smarty->fetch($this->getTemplate($country->iso_code));
}
/**
* Returns the tax tab content
*/
public function getTaxTabContent()
{
$invoice_address = new Address((int)$this->order->id_address_invoice);
$tax_exempt = Configuration::get('VATNUMBER_MANAGEMENT')
AND !empty($invoiceAddress->vat_number)
AND $invoiceAddress->id_country != Configuration::get('VATNUMBER_COUNTRY');
$this->smarty->assign(array(
'tax_exempt' => $tax_exempt,
'use_one_after_another_method' => $this->order->useOneAfterAnotherTaxComputationMethod(),
'product_tax_breakdown' => $this->order->getProductTaxesBreakdown(),
'shipping_tax_breakdown' => $this->order->getShippingTaxesBreakdown(),
'ecotax_tax_breakdown' => $this->order->getEcoTaxTaxesBreakdown(),
'order' => $this->order,
));
return $this->smarty->fetch(_PS_THEME_DIR_.'/pdf/invoice.tax-tab.tpl');
}
/**
* Returns the invoice template associated to the country iso_code
* @param string $iso_country
*/
protected function getTemplate($iso_country)
{
$template = _PS_THEME_DIR_.'/pdf/invoice.tpl';
$iso_template = _PS_THEME_DIR_.'/pdf/invoice.'.$iso_country.'.tpl';
if (file_exists($iso_template))
$template = $iso_template;
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()
{
return Configuration::get('PS_INVOICE_PREFIX').sprintf('%06d', $this->order->invoice_number).'.pdf';
}
}
+96
View File
@@ -0,0 +1,96 @@
<?php
/*
* 2007-2011 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:
* http://opensource.org/licenses/osl-3.0.php
* 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-2011 PrestaShop SA
* @version Release: $Revision: 8797 $
* @license http://opensource.org/licenses/osl-3.0.php 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;
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, (int)$this->order->id_lang);
$this->title = 'Order Return '.sprintf('%06d', $this->order_return->id); // TODO
// footer informations
$shop = new Shop((int)$this->order->id_shop);
$this->address = $shop->getAddress();
}
/**
* 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)$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($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');
}
/**
* Returns the template filename
* @return string filename
*/
public function getFilename()
{
return sprintf('%06d', $this->order_return->id).'.pdf'; // TODO
}
/**
* Returns the template filename when using bulk rendering
* @return string filename
*/
public function getBulkFilename()
{
return 'invoices.pdf';
}
}
+106
View File
@@ -0,0 +1,106 @@
<?php
/*
* 2007-2011 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:
* http://opensource.org/licenses/osl-3.0.php
* 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-2011 PrestaShop SA
* @version Release: $Revision: 8797 $
* @license http://opensource.org/licenses/osl-3.0.php 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;
public function __construct(OrderSlip $order_slip, $smarty)
{
$this->order_slip = $order_slip;
$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);
$this->order->products = $products;
$this->smarty = $smarty;
// header informations
$this->date = Tools::displayDate($this->order->invoice_date, (int)$this->order->id_lang);
$this->title = self::l('Slip #').sprintf('%06d', $this->order_slip->id);
// footer informations
$shop = new Shop((int)$this->order->id_shop);
$this->address = $shop->getAddress();
}
/**
* Returns the template's HTML content
* @return string HTML content
*/
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 = '';
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($this->order->id_customer);
$this->smarty->assign(array(
'order' => $this->order,
'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' => '',
));
return $this->smarty->fetch(_PS_THEME_DIR_.'/pdf/invoice.tpl');
}
/**
* 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 'order-slip-'.sprintf('%06d', $this->order_slip->id).'.pdf';
}
}
+101
View File
@@ -0,0 +1,101 @@
<?php
/*
* 2007-2011 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:
* http://opensource.org/licenses/osl-3.0.php
* 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-2011 PrestaShop SA
* @version Release: $Revision: 8797 $
* @license http://opensource.org/licenses/osl-3.0.php 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;
const TEMPLATE_INVOICE = 'Invoice';
const TEMPLATE_ORDER_RETURN = 'OrderReturn';
const TEMPLATE_ORDER_SLIP = 'OrderSlip';
const TEMPLATE_DELIVERY_SLIP = 'DeliverySlip';
public function __construct($objects, $template, $smarty)
{
$this->pdf_renderer = new PDFGenerator();
$this->template = $template;
$this->smarty = $smarty;
$this->objects = $objects;
if (!is_array($objects))
$this->objects = array($objects);
}
public function render()
{
$render = false;
$this->pdf_renderer->setFontForLang('fr');
foreach ($this->objects as $object)
{
$template = $this->getTemplateObject($object);
if (!$template)
continue;
if (empty($this->filename))
{
$this->filename = $template->getFilename();
if (count($this->objects) > 1)
$this->filename = $template->getBulkFilename();
}
$this->pdf_renderer->createHeader($template->getHeader());
$this->pdf_renderer->createFooter($template->getFooter());
$this->pdf_renderer->createContent($template->getContent());
$this->pdf_renderer->writePage();
$render = true;
unset($template);
}
if ($render)
$this->pdf_renderer->render($this->filename);
}
public function getTemplateObject($object)
{
$class = false;
$classname = 'HTMLTemplate'.$this->template;
if (class_exists($classname))
{
$class = new $classname($object, $this->smarty);
if (!($class instanceof HTMLTemplate))
throw new PrestashopException('Invalid class. It should be an instance of HTMLTemplate');
}
return $class;
}
}
+145
View File
@@ -0,0 +1,145 @@
<?php
require_once(_PS_TOOL_DIR_.'tcpdf/config/lang/eng.php');
require_once(_PS_TOOL_DIR_.'tcpdf/tcpdf.php');
/*
* 2007-2011 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:
* http://opensource.org/licenses/osl-3.0.php
* 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-2011 PrestaShop SA
* @version Release: $Revision: 8797 $
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
/**
* @since 1.5
*/
class PDFGeneratorCore extends TCPDF
{
const DEFAULT_FONT = 'dejavusans';
public $header;
public $footer;
public $content;
public $font;
public $font_by_lang = array('jp' => 'cid0jp');
/**
* 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;
}
/**
* Change the font
* @param unknown_type $iso_lang
*/
public function setFontForLang($iso_lang)
{
$this->font = self::DEFAULT_FONT;
if (array_key_exists($iso_lang, $this->font_by_lang))
$this->font = $this->font_by_lang[$iso_lang];
}
/**
* @see TCPDF::Header()
*/
public function Header()
{
$this->setFont($this->font);
$this->writehtml($this->header);
}
/**
* @see TCPDF::Footer()
*/
public function Footer()
{
$this->setFont($this->font);
$this->writehtml($this->footer);
}
/**
* Render the pdf file
*
* @param string $filename
* @throws PrestashopException
*/
public function render($filename)
{
if (empty($filename))
throw new PrestashopException('Missing filename.');
$this->lastPage();
$this->output($filename, 'I');
}
/**
* Write a PDF page
*/
public function writePage()
{
$this->SetHeaderMargin(5);
$this->SetFooterMargin(18);
$this->setMargins(10, 40, 10);
$this->SetAutoPageBreak(true, PDF_MARGIN_BOTTOM);
$this->AddPage();
$this->writehtml($this->content, true, false, true, false, '');
}
}
+2 -2
View File
@@ -131,11 +131,11 @@ class TaxCalculatorCore
{
if ($this->computation_method == TaxCalculator::ONE_AFTER_ANOTHER_METHOD)
{
$taxes_amounts[$tax->rate] = $price_te * (abs($tax->rate) / 100);
$taxes_amounts[$tax->id] = $price_te * (abs($tax->rate) / 100);
$price_te = $price_te + $taxes_amounts[$tax->rate];
}
else
$taxes_amounts[$tax->rate] = ($price_te * (abs($tax->rate) / 100));
$taxes_amounts[$tax->id] = ($price_te * (abs($tax->rate) / 100));
}
return $taxes_amounts;