Merge branch 'ticket-11208-FactureCadeau' into develop

This commit is contained in:
Marion Muszynski 2016-12-21 12:24:48 +01:00
commit 9a9d363b87
3 changed files with 134 additions and 264 deletions

View File

@ -149,9 +149,9 @@ class AdminInvoices extends AdminTab
echo '</td>*/
echo '</td>
<td align="center">
<a title="Facture - Avec prix" onclick="this.target=\'_blank\'" href="'.$currentIndex.'&printM1=1&id_sale='. $sale['id_sale'] .'&token='.$this->token.'">
<!--a title="Facture - Avec prix" onclick="this.target=\'_blank\'" href="'.$currentIndex.'&printM1=1&id_sale='. $sale['id_sale'] .'&token='.$this->token.'">
<span class="text-green-light anticon anticon-file-pdf" style="cursor:pointer;"></span>
</a>
</a-->
<a title="Facture cadeau - Sans prix" onclick="this.target=\'_blank\'" href="'.$currentIndex.'&printM1=1&id_sale='. $sale['id_sale'] .'&gift=1&token='.$this->token.'">
<span class="text-rose anticon anticon-file-pdf" style="cursor:pointer;"></span>
</a>
@ -165,9 +165,9 @@ class AdminInvoices extends AdminTab
echo '<td align="center"><input id="multi_'. $sale['id_sale'].'" type="checkbox" name="multi2[]" value="'.$sale['id_sale'].'" '.(in_array((int)$sale['id_sale'], $id_sales)?'checked':'').'/></td>
<td align="center"><input id="multi_plus_'. $sale['id_sale'].'" type="checkbox" name="multiPlus[]" value="'.$sale['id_sale'].'"/></td>
<td align="center">
<a onclick="this.target=\'_blank\'" href="'.$currentIndex.'&printAll=1&id_sale='. $sale['id_sale'] .'&token='.$this->token.'">
<!--a onclick="this.target=\'_blank\'" href="'.$currentIndex.'&printAll=1&id_sale='. $sale['id_sale'] .'&token='.$this->token.'">
<span class="text-green-light anticon anticon-file-pdf" style="cursor:pointer;"></span>
</a>
</a-->
<a onclick="this.target=\'_blank\'" href="'.$currentIndex.'&printAll=1&id_sale='. $sale['id_sale'] .'&gift=1&token='.$this->token.'">
<span class="text-rose anticon anticon-file-pdf" style="cursor:pointer;"></span>
</a>
@ -178,12 +178,13 @@ class AdminInvoices extends AdminTab
}
// <td align="center"><input id="m2_'. $sale['id_sale'].'" type="checkbox" name="m2[]" value="'.$sale['id_sale'].'" /></td>
echo '<tr>
<td colspan="4" style="padding:5px;">
<input type="hidden" name="date_to" value="'. Tools::getValue('date_to') .'" />
<input type="hidden" name="date_from" value="'. Tools::getValue('date_from') .'" />
<label style="float:none;" class="text-green-light "><span class="anticon anticon-file-pdf"></span> '.$this->l('Avec prix').'</label>
<label style="float:none;" class="text-rose "><span class="anticon anticon-file-pdf"></span> '.$this->l('Sans prix').'</label>
</td>';
<td colspan="4" style="padding:5px;"></td>';
// <td colspan="4" style="padding:5px;">
// <input type="hidden" name="date_to" value="'. Tools::getValue('date_to') .'" />
// <input type="hidden" name="date_from" value="'. Tools::getValue('date_from') .'" />
// <label style="float:none;" class="text-green-light "><span class="anticon anticon-file-pdf"></span> '.$this->l('Avec prix').'</label>
// <label style="float:none;" class="text-rose "><span class="anticon anticon-file-pdf"></span> '.$this->l('Sans prix').'</label>
// </td>';
/*<td align="center">
<input type="submit" name="submitPrintM2Bis" class="button" value="'.$this->l('Print M2\'').'" />
</td>*/

View File

@ -570,6 +570,7 @@ class PDFCore extends PDF_PageGroupCore
if (!Validate::isLoadedObject($order) OR (!$cookie->id_employee AND (!OrderState::invoiceAvailable($order->getCurrentState()) AND !$order->invoice_number)))
die('Invalid order or invalid order state');
/* @Override Antadis */
if($gift && $order->gift == 1) {
self::invoiceWithoutPrice($order, $mode = 'D', $multiple, $pdf, $slip, $delivery, $multi, $tri, $expe48);
} else {
@ -795,6 +796,7 @@ class PDFCore extends PDF_PageGroupCore
}
/**
* @Add Antadis
* invoiceWithoutPrice
*
* @param object $order Order
@ -912,6 +914,7 @@ class PDFCore extends PDF_PageGroupCore
/* Exit if delivery */
if (!self::$delivery)
{
/* @Override Antadis */
if(!empty(self::$order->gift_message)) {
$pdf->Ln(15);
$pdf->SetFont(self::fontname(), 'B', 10);
@ -967,25 +970,73 @@ class PDFCore extends PDF_PageGroupCore
$this->SetFont(self::fontname(), '', 8);
}
/* @Override Antadis */
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 = array(85, 15, 30, 30, 15, 15);
}
else {
$header = array(
array(self::l('Description'), 'L'),
array(self::l('Reference'), 'L'),
array(self::l('Qty'), 'C'),
);
$w = array(120, 30, 10);
}
$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);
}
/**
* Product table with price, quantities...
*/
public function ProdTab($delivery = false, $tri=false, $gift=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))
$products = self::$order->products;
else
$products = self::$order->getProducts(false,false,false,true);
$products = self::$order->getProducts(false, false, false, $tri);
}
else
$products = self::$orderSlip->getOrdersSlipProducts(self::$orderSlip->id, self::$order);
/* @Override Antadis */
$hasEcotax = $this->hasProductWithEcotax($products);
if ($hasEcotax) {
$this->ProdTabHeaderWithEcotax($delivery);
}
else {
self::ProdTabHeader($delivery);
}
if (!$delivery) {
$w = $hasEcotax?array(85, 15, 30, 30, 15, 15):array(100, 15, 30, 15, 30);
}
else {
$w = array(120, 30, 10);
}
$customizedDatas = Product::getAllCustomizedDatas((int)(self::$order->id_cart));
Product::addCustomizationPrice($products, $customizedDatas);
@ -997,6 +1048,10 @@ class PDFCore extends PDF_PageGroupCore
foreach($products AS $product)
if ((!$delivery || ($delivery && $gift)) || ((int)($product['product_quantity']) - (int)($product['product_quantity_refunded']) > 0))
{
if ($product['sended'] == 1) {
$product['product_name'] = '* '.$product['product_name'];
}
if ($counter >= $lines)
{
$this->AddPage();
@ -1062,15 +1117,29 @@ class PDFCore extends PDF_PageGroupCore
if ($delivery)
$this->SetX(25);
$before = $this->GetY();
$this->MultiCell($w[++$i], 5, Tools::iconv('utf-8', self::encoding(), $product['product_name']).' - '.self::l('Customized')." \n".Tools::iconv('utf-8', self::encoding(), $custoLabel), 'B');
$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');
/* @Override Antadis */
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;
@ -1081,15 +1150,45 @@ class PDFCore extends PDF_PageGroupCore
if ($productQuantity)
{
$before = $this->GetY();
$this->MultiCell($w[++$i], 5, Tools::iconv('utf-8', self::encoding(), $product['product_name']), 'B');
$fill = false;
if($productQuantity > 1) {
$this->SetFont(self::fontname(), 'B', 7);
$this->SetFillColor(240, 240, 240);
$fill = true;
} else {
$this->SetFont(self::fontname(), '', 7);
}
$this->MultiCell($w[++$i], 5, Tools::iconv('utf-8', self::encoding(), $product['product_name']), 'BT', 'L');
$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']) : '--'), 'B');
$this->Cell($w[++$i], $lineSize, ($product['product_reference'] ? Tools::iconv('utf-8', self::encoding(), $product['product_reference']) : '--'), 'BT');
if (!$delivery) {
$this->Cell($w[++$i], $lineSize, (self::$orderSlip ? '-' : '').self::convertSign(Tools::displayPrice($unit_price, self::$currency, true)), 'BT', 0, 'R');
/* @Override Antadis */
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');
}
}
}
/* @Override Antadis */
if(!$delivery) {
global $cookie;
error_log("logt" . serialize($cookie));
if(method_exists($cookie, 'isLoggedBack') && $cookie->isLoggedBack()) {
$this->Cell($w[++$i], $lineSize, $productQuantity.(self::$orderSlip? '': ($product['product_quantity_return'] > 0? ' (-'.$product['product_quantity_return'].')': ($product['product_quantity_refunded'] > 0? ' (-'.$product['product_quantity_refunded'].')': '' ))), 'BT', 0, 'C', $fill);
} else {
$this->Cell($w[++$i], $lineSize, $productQuantity, 'BT', 0, 'C', $fill);
}
}
$this->Cell($w[++$i], $lineSize, $productQuantity, 'BT', 0, 'C');
if (!$delivery)
$this->Cell($w[++$i], $lineSize, (self::$orderSlip ? '-' : '').self::convertSign(Tools::displayPrice($unit_price, self::$currency, true)), 'B', 0, 'R');
$this->Cell($w[++$i], $lineSize, $productQuantity, 'B', 0, 'C');
if (!$delivery)
$this->Cell($w[++$i], $lineSize, (self::$orderSlip ? '-' : '').self::convertSign(Tools::displayPrice($final_price, self::$currency, true)), 'B', 0, 'R');
$this->Cell($w[++$i], $lineSize, (self::$orderSlip ? '-' : '').self::convertSign(Tools::displayPrice($final_price, self::$currency, true)), 'BT', 0, 'R');
$this->Ln();
}
}
@ -1394,5 +1493,15 @@ class PDFCore extends PDF_PageGroupCore
return $font ? $font : 'Arial';
}
private function hasProductWithEcotax($products)
{
foreach($products as $product) {
if (!empty($product['ecotax']) && $product['ecotax']>0) {
return true;
}
}
return false;
}
}

View File

@ -1,240 +0,0 @@
<?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 (!self::$orderSlip)
{
if (isset(self::$order->products) AND sizeof(self::$order->products))
$products = self::$order->products;
else
$products = self::$order->getProducts(false, false, false, $tri);
}
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);
$counter = 0;
$lines = 25;
$lineSize = 0;
$line = 0;
foreach($products AS $product)
if (!$delivery OR ((int)($product['product_quantity']) - (int)($product['product_quantity_refunded']) > 0))
{
if ($product['sended'] == 1) {
$product['product_name'] = '* '.$product['product_name'];
}
if ($counter >= $lines)
{
$this->AddPage();
$this->Ln();
self::ProdTabHeader($delivery);
$lineSize = 0;
$counter = 0;
$lines = 40;
$line++;
}
$counter = $counter + ($lineSize / 5) ;
$i = -1;
// Unit vars
$unit_without_tax = $product['product_price'] + $product['ecotax'];
$unit_with_tax = $product['product_price_wt'];
if (self::$_priceDisplayMethod == PS_TAX_EXC)
$unit_price = &$unit_without_tax;
else
$unit_price = &$unit_with_tax;
$productQuantity = $delivery ? ((int)($product['product_quantity']) - (int)($product['product_quantity_refunded'])) : (int)($product['product_quantity']);
if ($productQuantity <= 0)
continue ;
// Total prices
$total_with_tax = $unit_with_tax * $productQuantity;
$total_without_tax = $unit_without_tax * $productQuantity;
// Spec
if (self::$_priceDisplayMethod == PS_TAX_EXC)
$final_price = &$total_without_tax;
else
$final_price = &$total_with_tax;
// End Spec
if (isset($customizedDatas[$product['product_id']][$product['product_attribute_id']]))
{
$custoLabel = '';
foreach($customizedDatas[$product['product_id']][$product['product_attribute_id']] as $customizedData)
{
$customizationGroup = $customizedData['datas'];
$nb_images = 0;
if (array_key_exists(_CUSTOMIZE_FILE_, $customizationGroup))
$nb_images = sizeof($customizationGroup[_CUSTOMIZE_FILE_]);
if (array_key_exists(_CUSTOMIZE_TEXTFIELD_, $customizationGroup))
foreach($customizationGroup[_CUSTOMIZE_TEXTFIELD_] as $customization)
if (!empty($customization['name'])) $custoLabel .= '- '.$customization['name'].': '.$customization['value']."\n";
if ($nb_images > 0)
$custoLabel .= '- '.$nb_images. ' '. self::l('image(s)')."\n";
$custoLabel .= "---\n";
}
$custoLabel = rtrim($custoLabel, "---\n");
$productQuantity = (int)($product['product_quantity']) - (int)($product['customizationQuantityTotal']);
if ($delivery)
$this->SetX(25);
$before = $this->GetY();
$this->MultiCell($w[++$i], 5, Tools::iconv('utf-8', self::encoding(), $product['product_name']).' - '.self::l('Customized')." \n".Tools::iconv('utf-8', self::encoding(), $custoLabel), 'B');
$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) {
$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) {
$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;
$total_without_tax = $unit_without_tax * $productQuantity;
}
if ($delivery)
$this->SetX(25);
if ($productQuantity)
{
$before = $this->GetY();
$fill = FALSE;
if($productQuantity > 1) {
$this->SetFont(self::fontname(), 'B', 7);
$this->SetFillColor(240, 240, 240);
$fill = TRUE;
} else {
$this->SetFont(self::fontname(), '', 7);
}
$this->MultiCell($w[++$i], 5, Tools::iconv('utf-8', self::encoding(), $product['product_name']), 'BT', 'L', $fill);
$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) {
$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()) {
$this->Cell($w[++$i], $lineSize, $productQuantity.(self::$orderSlip? '': ($product['product_quantity_return'] > 0? ' (-'.$product['product_quantity_return'].')': ($product['product_quantity_refunded'] > 0? ' (-'.$product['product_quantity_refunded'].')': '' ))), 'BT', 0, 'C', $fill);
} else {
$this->Cell($w[++$i], $lineSize, $productQuantity, 'BT', 0, 'C', $fill);
}
if (!$delivery)
$this->Cell($w[++$i], $lineSize, (self::$orderSlip ? '-' : '').self::convertSign(Tools::displayPrice($final_price, self::$currency, true)), 'BT', 0, 'R');
$this->Ln();
}
}
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);
}
}