Merge branch 'evo-9386' into develop

This commit is contained in:
Marion Muszynski 2016-08-24 12:34:54 +02:00
commit 4756a312ac

View File

@ -1,12 +1,26 @@
<?php
class PDF extends PDFCore {
// PDF column width for the table of ordered products
private $cell_widths = [
'with_ecotax' => [85, 15, 30, 30, 15, 15],
'no_ecotax' => [100, 15, 30, 15, 30],
'delivery' => [120, 30, 10]
];
private function hasProductWithEcotax($products)
{
foreach($products as $product) {
if (!empty($product['ecotax']) && $product['ecotax']>0) {
return true;
}
}
return false;
}
public function ProdTab($delivery = false, $tri = false)
{
if (!$delivery)
$w = array(100, 15, 30, 15, 30);
else
$w = array(120, 30, 10);
self::ProdTabHeader($delivery);
if (!self::$orderSlip)
{
if (isset(self::$order->products) AND sizeof(self::$order->products))
@ -16,6 +30,23 @@ class PDF extends PDFCore {
}
else
$products = self::$orderSlip->getOrdersSlipProducts(self::$orderSlip->id, self::$order);
$hasEcotax = $this->hasProductWithEcotax($products);
if ($hasEcotax) {
$this->ProdTabHeaderWithEcotax($delivery);
}
else {
$this->ProdTabHeader($delivery);
}
if (!$delivery) {
$w = &$this->cell_widths[$hasEcotax?'with_ecotax':'no_ecotax'];
}
else {
$w = &$this->cell_widths['delivery'];
}
$customizedDatas = Product::getAllCustomizedDatas((int)(self::$order->id_cart));
Product::addCustomizationPrice($products, $customizedDatas);
@ -101,11 +132,24 @@ class PDF extends PDFCore {
$lineSize = $this->GetY() - $before;
$this->SetXY($this->GetX() + $w[0] + ($delivery ? 15 : 0), $this->GetY() - $lineSize);
$this->Cell($w[++$i], $lineSize, $product['product_reference'], 'B');
if (!$delivery)
if (!$delivery) {
$this->Cell($w[++$i], $lineSize, (self::$orderSlip ? '-' : '').self::convertSign(Tools::displayPrice($unit_price, self::$currency, true)), 'B', 0, 'R');
if ($hasEcotax) {
if (!empty($product['ecotax']) && $product['ecotax']>0) {
$this->Cell($w[++$i], $lineSize, (self::$orderSlip ? '-' : '').self::convertSign(Tools::displayPrice($product['ecotax'], self::$currency, true)), 'BT', 0, 'R');
}
else {
$this->Cell($w[++$i], $lineSize, '-', 'BT', 0, 'R');
}
}
}
$this->Cell($w[++$i], $lineSize, (int)($product['customizationQuantityTotal']), 'B', 0, 'C');
if (!$delivery)
if (!$delivery) {
$this->Cell($w[++$i], $lineSize, (self::$orderSlip ? '-' : '').self::convertSign(Tools::displayPrice($unit_price * (int)($product['customizationQuantityTotal']), self::$currency, true)), 'B', 0, 'R');
}
$this->Ln();
$i = -1;
$total_with_tax = $unit_with_tax * $productQuantity;
@ -129,9 +173,19 @@ class PDF extends PDFCore {
$lineSize = $this->GetY() - $before;
$this->SetXY($this->GetX() + $w[0] + ($delivery ? 15 : 0), $this->GetY() - $lineSize);
$this->Cell($w[++$i], $lineSize, ($product['product_reference'] ? Tools::iconv('utf-8', self::encoding(), $product['product_reference']) : '--'), 'BT');
if (!$delivery)
if (!$delivery) {
$this->Cell($w[++$i], $lineSize, (self::$orderSlip ? '-' : '').self::convertSign(Tools::displayPrice($unit_price, self::$currency, true)), 'BT', 0, 'R');
if ($hasEcotax) {
if (!empty($product['ecotax']) && $product['ecotax']>0) {
$this->Cell($w[++$i], $lineSize, (self::$orderSlip ? '-' : '').self::convertSign(Tools::displayPrice($product['ecotax'], self::$currency, true)), 'BT', 0, 'R');
}
else {
$this->Cell($w[++$i], $lineSize, '-', 'BT', 0, 'R');
}
}
}
global $cookie;
error_log("logt" . serialize($cookie));
if(method_exists($cookie, 'isLoggedBack') && $cookie->isLoggedBack()) {
@ -149,4 +203,38 @@ class PDF extends PDFCore {
if (!sizeof(self::$order->getDiscounts()) AND !$delivery)
$this->Cell(array_sum($w), 0, '');
}
private function ProdTabHeaderWithEcotax($delivery = false)
{
// label, alignment (L: left, R: right, C: center)
if (!$delivery) {
$header = array(
array(self::l('Description'), 'L'),
array(self::l('Reference'), 'L'),
array(self::l('U. price'), 'R'),
array(self::l('Ecotax incl.'), 'R'),
array(self::l('Qty'), 'C'),
array(self::l('Total'), 'R')
);
$w = &$this->cell_widths['with_ecotax'];
}
else {
$header = array(
array(self::l('Description'), 'L'),
array(self::l('Reference'), 'L'),
array(self::l('Qty'), 'C'),
);
$w = &$this->cell_widths['delivery'];
}
$this->SetFont(self::fontname(), 'B', 8);
$this->SetFillColor(240, 240, 240);
if ($delivery)
$this->SetX(25);
for ($i = 0; $i < sizeof($header); $i++)
$this->Cell($w[$i], 5, $header[$i][0], 'T', 0, $header[$i][1], 1);
$this->Ln();
$this->SetFont(self::fontname(), '', 8);
}
}