Add Reduction value in pdf

Add value of %reduction in pdf
This commit is contained in:
Andrelec1 2014-08-01 14:49:42 +02:00
parent e18caccdc9
commit 0b5707c1cf
3 changed files with 4580 additions and 4525 deletions

View File

@ -12,6 +12,7 @@
* Copyright (C) 2012 Marcos García <marcosgdf@gmail.com> * Copyright (C) 2012 Marcos García <marcosgdf@gmail.com>
* Copyright (C) 2013 Cedric Gross <c.gross@kreiz-it.fr> * Copyright (C) 2013 Cedric Gross <c.gross@kreiz-it.fr>
* Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro> * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
* Copyright (C) 2014 Teddy Andreotti <125155@supinfo.com>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -1908,7 +1909,7 @@ class Facture extends CommonInvoice
* @param array $array_option extrafields array * @param array $array_option extrafields array
* @return int <0 if KO, Id of line if OK * @return int <0 if KO, Id of line if OK
*/ */
function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txlocaltax2=0, $fk_product=0, $remise_percent=0, $date_start='', $date_end='', $ventil=0, $info_bits=0, $fk_remise_except='', $price_base_type='HT', $pu_ttc=0, $type=self::TYPE_STANDARD, $rang=-1, $special_code=0, $origin='', $origin_id=0, $fk_parent_line=0, $fk_fournprice=null, $pa_ht=0, $label='', $array_option=0) function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txlocaltax2=0, $fk_product=0, $remise_percent=0, $remise_amount=0, $date_start='', $date_end='', $ventil=0, $info_bits=0, $fk_remise_except='', $price_base_type='HT', $pu_ttc=0, $type=self::TYPE_STANDARD, $rang=-1, $special_code=0, $origin='', $origin_id=0, $fk_parent_line=0, $fk_fournprice=null, $pa_ht=0, $label='', $array_option=0)
{ {
global $mysoc, $conf, $langs; global $mysoc, $conf, $langs;
@ -1917,6 +1918,7 @@ class Facture extends CommonInvoice
// Clean parameters // Clean parameters
if (empty($remise_percent)) $remise_percent=0; if (empty($remise_percent)) $remise_percent=0;
if (empty($remise_amount)) $remise_amount=0;
if (empty($qty)) $qty=0; if (empty($qty)) $qty=0;
if (empty($info_bits)) $info_bits=0; if (empty($info_bits)) $info_bits=0;
if (empty($rang)) $rang=0; if (empty($rang)) $rang=0;
@ -1927,6 +1929,7 @@ class Facture extends CommonInvoice
if (empty($fk_parent_line) || $fk_parent_line < 0) $fk_parent_line=0; if (empty($fk_parent_line) || $fk_parent_line < 0) $fk_parent_line=0;
$remise_percent=price2num($remise_percent); $remise_percent=price2num($remise_percent);
$remise_amount=price2num($remise_amount);
$qty=price2num($qty); $qty=price2num($qty);
$pu_ht=price2num($pu_ht); $pu_ht=price2num($pu_ht);
$pu_ttc=price2num($pu_ttc); $pu_ttc=price2num($pu_ttc);
@ -2001,6 +2004,7 @@ class Facture extends CommonInvoice
$this->line->fk_product=$fk_product; $this->line->fk_product=$fk_product;
$this->line->product_type=$product_type; $this->line->product_type=$product_type;
$this->line->remise_percent=$remise_percent; $this->line->remise_percent=$remise_percent;
$this->line->remise_amount=$remise_amount;
$this->line->subprice= ($this->type==self::TYPE_CREDIT_NOTE?-abs($pu_ht):$pu_ht); // For credit note, unit price always negative, always positive otherwise $this->line->subprice= ($this->type==self::TYPE_CREDIT_NOTE?-abs($pu_ht):$pu_ht); // For credit note, unit price always negative, always positive otherwise
$this->line->date_start=$date_start; $this->line->date_start=$date_start;
$this->line->date_end=$date_end; $this->line->date_end=$date_end;
@ -3144,7 +3148,7 @@ class Facture extends CommonInvoice
{ {
$sql = 'SELECT l.rowid, l.label as custom_label, l.description, l.fk_product, l.product_type, l.qty, l.tva_tx,'; $sql = 'SELECT l.rowid, l.label as custom_label, l.description, l.fk_product, l.product_type, l.qty, l.tva_tx,';
$sql.= ' l.fk_remise_except, l.localtax1_tx, l.localtax2_tx,'; $sql.= ' l.fk_remise_except, l.localtax1_tx, l.localtax2_tx,';
$sql.= ' l.remise_percent, l.subprice, l.info_bits, l.rang, l.special_code, l.fk_parent_line,'; $sql.= ' l.remise_percent, l.remise_amount, l.subprice, l.info_bits, l.rang, l.special_code, l.fk_parent_line,';
$sql.= ' l.total_ht, l.total_tva, l.total_ttc, l.fk_product_fournisseur_price as fk_fournprice, l.buy_price_ht as pa_ht,'; $sql.= ' l.total_ht, l.total_tva, l.total_ttc, l.fk_product_fournisseur_price as fk_fournprice, l.buy_price_ht as pa_ht,';
$sql.= ' l.date_start, l.date_end,'; $sql.= ' l.date_start, l.date_end,';
$sql.= ' p.ref as product_ref, p.fk_product_type, p.label as product_label,'; $sql.= ' p.ref as product_ref, p.fk_product_type, p.label as product_label,';
@ -3247,6 +3251,7 @@ class FactureLigne extends CommonInvoiceLine
var $localtax2_type; // Local tax 2 type var $localtax2_type; // Local tax 2 type
var $subprice; // P.U. HT (example 100) var $subprice; // P.U. HT (example 100)
var $remise_percent; // % de la remise ligne (example 20%) var $remise_percent; // % de la remise ligne (example 20%)
var $remise_amount; // montant de la remise ligne
var $fk_remise_except; // Link to line into llx_remise_except var $fk_remise_except; // Link to line into llx_remise_except
var $rang = 0; var $rang = 0;
@ -3313,7 +3318,7 @@ class FactureLigne extends CommonInvoiceLine
function fetch($rowid) function fetch($rowid)
{ {
$sql = 'SELECT fd.rowid, fd.fk_facture, fd.fk_parent_line, fd.fk_product, fd.product_type, fd.label as custom_label, fd.description, fd.price, fd.qty, fd.tva_tx,'; $sql = 'SELECT fd.rowid, fd.fk_facture, fd.fk_parent_line, fd.fk_product, fd.product_type, fd.label as custom_label, fd.description, fd.price, fd.qty, fd.tva_tx,';
$sql.= ' fd.localtax1_tx, fd. localtax2_tx, fd.remise, fd.remise_percent, fd.fk_remise_except, fd.subprice,'; $sql.= ' fd.localtax1_tx, fd. localtax2_tx, fd.remise, fd.remise_percent, fd.remise_amount, fd.fk_remise_except, fd.subprice,';
$sql.= ' fd.date_start as date_start, fd.date_end as date_end, fd.fk_product_fournisseur_price as fk_fournprice, fd.buy_price_ht as pa_ht,'; $sql.= ' fd.date_start as date_start, fd.date_end as date_end, fd.fk_product_fournisseur_price as fk_fournprice, fd.buy_price_ht as pa_ht,';
$sql.= ' fd.info_bits, fd.special_code, fd.total_ht, fd.total_tva, fd.total_ttc, fd.total_localtax1, fd.total_localtax2, fd.rang,'; $sql.= ' fd.info_bits, fd.special_code, fd.total_ht, fd.total_tva, fd.total_ttc, fd.total_localtax1, fd.total_localtax2, fd.rang,';
$sql.= ' fd.fk_code_ventilation,'; $sql.= ' fd.fk_code_ventilation,';
@ -3338,6 +3343,7 @@ class FactureLigne extends CommonInvoiceLine
$this->localtax1_tx = $objp->localtax1_tx; $this->localtax1_tx = $objp->localtax1_tx;
$this->localtax2_tx = $objp->localtax2_tx; $this->localtax2_tx = $objp->localtax2_tx;
$this->remise_percent = $objp->remise_percent; $this->remise_percent = $objp->remise_percent;
$this->remise_amount = $objp->remise_amount;
$this->fk_remise_except = $objp->fk_remise_except; $this->fk_remise_except = $objp->fk_remise_except;
$this->fk_product = $objp->fk_product; $this->fk_product = $objp->fk_product;
$this->product_type = $objp->product_type; $this->product_type = $objp->product_type;
@ -3397,6 +3403,7 @@ class FactureLigne extends CommonInvoiceLine
if (empty($this->total_localtax2)) $this->total_localtax2=0; if (empty($this->total_localtax2)) $this->total_localtax2=0;
if (empty($this->rang)) $this->rang=0; if (empty($this->rang)) $this->rang=0;
if (empty($this->remise_percent)) $this->remise_percent=0; if (empty($this->remise_percent)) $this->remise_percent=0;
if (empty($this->remise_amount)) $this->remise_amount=0;
if (empty($this->info_bits)) $this->info_bits=0; if (empty($this->info_bits)) $this->info_bits=0;
if (empty($this->subprice)) $this->subprice=0; if (empty($this->subprice)) $this->subprice=0;
if (empty($this->special_code)) $this->special_code=0; if (empty($this->special_code)) $this->special_code=0;
@ -3433,7 +3440,7 @@ class FactureLigne extends CommonInvoiceLine
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'facturedet'; $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'facturedet';
$sql.= ' (fk_facture, fk_parent_line, label, description, qty,'; $sql.= ' (fk_facture, fk_parent_line, label, description, qty,';
$sql.= ' tva_tx, localtax1_tx, localtax2_tx, localtax1_type, localtax2_type,'; $sql.= ' tva_tx, localtax1_tx, localtax2_tx, localtax1_type, localtax2_type,';
$sql.= ' fk_product, product_type, remise_percent, subprice, fk_remise_except,'; $sql.= ' fk_product, product_type, remise_percent, remise_amount, subprice, fk_remise_except,';
$sql.= ' date_start, date_end, fk_code_ventilation, '; $sql.= ' date_start, date_end, fk_code_ventilation, ';
$sql.= ' rang, special_code, fk_product_fournisseur_price, buy_price_ht,'; $sql.= ' rang, special_code, fk_product_fournisseur_price, buy_price_ht,';
$sql.= ' info_bits, total_ht, total_tva, total_ttc, total_localtax1, total_localtax2)'; $sql.= ' info_bits, total_ht, total_tva, total_ttc, total_localtax1, total_localtax2)';
@ -3450,6 +3457,7 @@ class FactureLigne extends CommonInvoiceLine
$sql.= ' '.(! empty($this->fk_product)?$this->fk_product:"null").','; $sql.= ' '.(! empty($this->fk_product)?$this->fk_product:"null").',';
$sql.= " ".$this->product_type.","; $sql.= " ".$this->product_type.",";
$sql.= " ".price2num($this->remise_percent).","; $sql.= " ".price2num($this->remise_percent).",";
$sql.= " ".price2num($this->remise_amount).",";
$sql.= " ".price2num($this->subprice).","; $sql.= " ".price2num($this->subprice).",";
$sql.= ' '.(! empty($this->fk_remise_except)?$this->fk_remise_except:"null").','; $sql.= ' '.(! empty($this->fk_remise_except)?$this->fk_remise_except:"null").',';
$sql.= " ".(! empty($this->date_start)?"'".$this->db->idate($this->date_start)."'":"null").","; $sql.= " ".(! empty($this->date_start)?"'".$this->db->idate($this->date_start)."'":"null").",";
@ -3578,6 +3586,7 @@ class FactureLigne extends CommonInvoiceLine
if (empty($this->total_localtax1)) $this->total_localtax1=0; if (empty($this->total_localtax1)) $this->total_localtax1=0;
if (empty($this->total_localtax2)) $this->total_localtax2=0; if (empty($this->total_localtax2)) $this->total_localtax2=0;
if (empty($this->remise_percent)) $this->remise_percent=0; if (empty($this->remise_percent)) $this->remise_percent=0;
if (empty($this->remise_amount)) $this->remise_amount=0;
if (empty($this->info_bits)) $this->info_bits=0; if (empty($this->info_bits)) $this->info_bits=0;
if (empty($this->special_code)) $this->special_code=0; if (empty($this->special_code)) $this->special_code=0;
if (empty($this->product_type)) $this->product_type=0; if (empty($this->product_type)) $this->product_type=0;
@ -3602,6 +3611,7 @@ class FactureLigne extends CommonInvoiceLine
$sql.= ",label=".(! empty($this->label)?"'".$this->db->escape($this->label)."'":"null"); $sql.= ",label=".(! empty($this->label)?"'".$this->db->escape($this->label)."'":"null");
$sql.= ",subprice=".price2num($this->subprice).""; $sql.= ",subprice=".price2num($this->subprice)."";
$sql.= ",remise_percent=".price2num($this->remise_percent).""; $sql.= ",remise_percent=".price2num($this->remise_percent)."";
$sql.= ",remise_amount=".price2num($this->remise_amount)."";
if ($this->fk_remise_except) $sql.= ",fk_remise_except=".$this->fk_remise_except; if ($this->fk_remise_except) $sql.= ",fk_remise_except=".$this->fk_remise_except;
else $sql.= ",fk_remise_except=null"; else $sql.= ",fk_remise_except=null";
$sql.= ",tva_tx=".price2num($this->tva_tx).""; $sql.= ",tva_tx=".price2num($this->tva_tx)."";

View File

@ -1425,6 +1425,38 @@ function pdf_getlineremisepercent($object,$i,$outputlangs,$hidedetails=0)
} }
} }
/**
* Return line remise value
*
* @param Object $object Object
* @param int $i Current line number
* @param Translate $outputlangs Object langs for output
* @param int $hidedetails Hide details (0=no, 1=yes, 2=just special lines)
* @return string
*/
function pdf_getlineremisevalue($object,$i,$outputlangs,$hidedetails=0)
{
global $hookmanager;
include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
if ($object->lines[$i]->special_code != 3)
{
if (is_object($hookmanager) && ( ($object->lines[$i]->product_type == 9 && !empty($object->lines[$i]->special_code) ) || ! empty($object->lines[$i]->fk_parent_line) ) )
{
$special_code = $object->lines[$i]->special_code;
if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
$parameters = array('i'=>$i,'outputlangs'=>$outputlangs,'hidedetails'=>$hidedetails,'special_code'=>$special_code);
$action='';
return $hookmanager->executeHooks('pdf_getlineremisevalue',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
}
else
{
if (empty($hidedetails) || $hidedetails > 1) return price($object->lines[$i]->subprice * $object->lines[$i]->qty - $object->lines[$i]->total_ht);
}
}
}
/** /**
* Return line total excluding tax * Return line total excluding tax
* *

View File

@ -103,10 +103,10 @@ class pdf_crabe extends ModelePDFFactures
// Define position of columns // Define position of columns
$this->posxdesc=$this->marge_gauche+1; $this->posxdesc=$this->marge_gauche+1;
$this->posxtva=112; $this->posxtva=95;
$this->posxup=126; $this->posxup=109;
$this->posxqty=145; $this->posxqty=128;
$this->posxdiscount=162; $this->posxdiscount=148;
$this->postotalht=174; $this->postotalht=174;
if (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) $this->posxtva=$this->posxup; if (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) $this->posxtva=$this->posxup;
$this->posxpicture=$this->posxtva - (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH)?20:$conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH); // width of images $this->posxpicture=$this->posxtva - (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH)?20:$conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH); // width of images
@ -308,7 +308,7 @@ class pdf_crabe extends ModelePDFFactures
$showpricebeforepagebreak=1; $showpricebeforepagebreak=1;
$pdf->startTransaction(); $pdf->startTransaction();
pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxtva-$curX,3,$curX,$curY,$hideref,$hidedesc); pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxtva-$curX,8,$curX,$curY,$hideref,$hidedesc);
$pageposafter=$pdf->getPage(); $pageposafter=$pdf->getPage();
if ($pageposafter > $pageposbefore) // There is a pagebreak if ($pageposafter > $pageposbefore) // There is a pagebreak
{ {
@ -372,14 +372,14 @@ class pdf_crabe extends ModelePDFFactures
$pdf->SetXY($this->posxqty, $curY); $pdf->SetXY($this->posxqty, $curY);
$pdf->MultiCell($this->posxdiscount-$this->posxqty-0.8, 3, $qty, 0, 'R'); // Enough for 6 chars $pdf->MultiCell($this->posxdiscount-$this->posxqty-0.8, 3, $qty, 0, 'R'); // Enough for 6 chars
// Discount on line // Discount % on line
if ($object->lines[$i]->remise_percent) if ($object->lines[$i]->remise_percent)
{ {
$pdf->SetXY($this->posxdiscount-2, $curY); $pdf->SetXY($this->posxdiscount-2, $curY);
$remise_percent = pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails); $remise_amount = pdf_getlineremisevalue($object, $i, $outputlangs, $hidedetails);
$remise_percent = pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails)."\n Soit : ".$remise_amount;
$pdf->MultiCell($this->postotalht-$this->posxdiscount+2, 3, $remise_percent, 0, 'R'); $pdf->MultiCell($this->postotalht-$this->posxdiscount+2, 3, $remise_percent, 0, 'R');
} }
// Total HT line // Total HT line
$total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails); $total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails);
$pdf->SetXY($this->postotalht, $curY); $pdf->SetXY($this->postotalht, $curY);
@ -1058,6 +1058,19 @@ class pdf_crabe extends ModelePDFFactures
$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index); $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
$pdf->MultiCell($largcol2, $tab2_hl, price($sign * $object->total_ttc, 0, $outputlangs), $useborder, 'R', 1); $pdf->MultiCell($largcol2, $tab2_hl, price($sign * $object->total_ttc, 0, $outputlangs), $useborder, 'R', 1);
if($this->atleastonediscount){
// Total Discount
$index++;
$index++;
$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
$pdf->SetTextColor(0,0,60);
$pdf->SetFillColor(224,224,224);
$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalDiscount"), $useborder, 'L', 1);
$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
$pdf->MultiCell($largcol2, $tab2_hl, price($sign * $object->total_ttc, 0, $outputlangs), $useborder, 'R', 1);
}
} }
} }