This commit is contained in:
Laurent Destailleur 2019-11-07 14:07:50 +01:00
parent cd5c359b83
commit 1fa61077a0
3 changed files with 129 additions and 88 deletions

View File

@ -39,7 +39,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
/** /**
* Class to manage PDF invoice template Crabe * Class to generate the customer invoice PDF with template Crabe
*/ */
class pdf_crabe extends ModelePDFFactures class pdf_crabe extends ModelePDFFactures
{ {
@ -235,7 +235,7 @@ class pdf_crabe extends ModelePDFFactures
public function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0) public function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
{ {
// phpcs:enable // phpcs:enable
global $user,$langs,$conf,$mysoc,$db,$hookmanager,$nblines; global $user,$langs,$conf,$mysoc,$hookmanager,$nblines;
dol_syslog("write_file outputlangs->defaultlang=".(is_object($outputlangs) ? $outputlangs->defaultlang : 'null')); dol_syslog("write_file outputlangs->defaultlang=".(is_object($outputlangs) ? $outputlangs->defaultlang : 'null'));
@ -243,7 +243,7 @@ class pdf_crabe extends ModelePDFFactures
// For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1'; if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1';
// Load traductions files required by page // Load translation files required by the page
$outputlangs->loadLangs(array("main", "bills", "products", "dict", "companies")); $outputlangs->loadLangs(array("main", "bills", "products", "dict", "companies"));
$nblines = count($object->lines); $nblines = count($object->lines);
@ -769,7 +769,7 @@ class pdf_crabe extends ModelePDFFactures
/** /**
* Show payments table * Show payments table
* *
* @param PDF $pdf Object PDF * @param PDF $pdf Object PDF
* @param Object $object Object invoice * @param Object $object Object invoice
* @param int $posy Position y in PDF * @param int $posy Position y in PDF
* @param Translate $outputlangs Object langs for output * @param Translate $outputlangs Object langs for output
@ -1116,9 +1116,9 @@ class pdf_crabe extends ModelePDFFactures
/** /**
* Show total to pay * Show total to pay
* *
* @param PDF $pdf Object PDF * @param PDF $pdf Object PDF
* @param Facture $object Object invoice * @param Facture $object Object invoice
* @param int $deja_regle Montant deja regle * @param int $deja_regle Amount already paid (in the currency of invoice)
* @param int $posy Position depart * @param int $posy Position depart
* @param Translate $outputlangs Objet langs * @param Translate $outputlangs Objet langs
* @return int Position pour suite * @return int Position pour suite
@ -1402,7 +1402,7 @@ class pdf_crabe extends ModelePDFFactures
$depositsamount=$object->getSumDepositsUsed(($conf->multicurrency->enabled && $object->multicurrency_tx != 1) ? 1 : 0); $depositsamount=$object->getSumDepositsUsed(($conf->multicurrency->enabled && $object->multicurrency_tx != 1) ? 1 : 0);
//print "x".$creditnoteamount."-".$depositsamount;exit; //print "x".$creditnoteamount."-".$depositsamount;exit;
$resteapayer = price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 'MT'); $resteapayer = price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 'MT');
if ($object->paye) $resteapayer=0; if (! empty($object->paye)) $resteapayer=0;
if (($deja_regle > 0 || $creditnoteamount > 0 || $depositsamount > 0) && empty($conf->global->INVOICE_NO_PAYMENT_DETAILS)) if (($deja_regle > 0 || $creditnoteamount > 0 || $depositsamount > 0) && empty($conf->global->INVOICE_NO_PAYMENT_DETAILS))
{ {

View File

@ -33,7 +33,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
/** /**
* Class to generate the supplier invoices with the canelle model * Class to generate the supplier invoices PDF with the template canelle
*/ */
class pdf_canelle extends ModelePDFSuppliersInvoices class pdf_canelle extends ModelePDFSuppliersInvoices
{ {
@ -53,6 +53,11 @@ class pdf_canelle extends ModelePDFSuppliersInvoices
public $description; public $description;
/** /**
* @var int Save the name of generated file as the main doc when generating a doc with this template
*/
public $update_main_doc_field;
/**
* @var string document type * @var string document type
*/ */
public $type; public $type;
@ -121,14 +126,14 @@ class pdf_canelle extends ModelePDFSuppliersInvoices
{ {
global $conf, $langs, $mysoc; global $conf, $langs, $mysoc;
// Load translation files required by the page // Translations
$langs->loadLangs(array("main", "bills")); $langs->loadLangs(array("main", "bills"));
$this->db = $db; $this->db = $db;
$this->name = "canelle"; $this->name = "canelle";
$this->description = $langs->trans('SuppliersInvoiceModel'); $this->description = $langs->trans('SuppliersInvoiceModel');
// Page size for A4 format // Dimension page
$this->type = 'pdf'; $this->type = 'pdf';
$formatarray=pdf_getFormat(); $formatarray=pdf_getFormat();
$this->page_largeur = $formatarray['width']; $this->page_largeur = $formatarray['width'];
@ -188,7 +193,7 @@ class pdf_canelle extends ModelePDFSuppliersInvoices
/** /**
* Function to build pdf onto disk * Function to build pdf onto disk
* *
* @param FactureFournisseur $object Id of object to generate * @param FactureFournisseur $object Object to generate
* @param Translate $outputlangs Lang output object * @param Translate $outputlangs Lang output object
* @param string $srctemplatepath Full path of source filename for generator using a template file * @param string $srctemplatepath Full path of source filename for generator using a template file
* @param int $hidedetails Do not show line details * @param int $hidedetails Do not show line details
@ -214,13 +219,15 @@ class pdf_canelle extends ModelePDFSuppliersInvoices
// Load translation files required by the page // Load translation files required by the page
$outputlangs->loadLangs(array("main", "dict", "companies", "bills", "products")); $outputlangs->loadLangs(array("main", "dict", "companies", "bills", "products"));
$nblines = count($object->lines);
if ($conf->fournisseur->facture->dir_output) if ($conf->fournisseur->facture->dir_output)
{ {
$object->fetch_thirdparty(); $object->fetch_thirdparty();
$deja_regle = $object->getSommePaiement(); $deja_regle = $object->getSommePaiement(($conf->multicurrency->enabled && $object->multicurrency_tx != 1) ? 1 : 0);
//$amount_credit_notes_included = $object->getSumCreditNotesUsed(); $amount_credit_notes_included = $object->getSumCreditNotesUsed(($conf->multicurrency->enabled && $object->multicurrency_tx != 1) ? 1 : 0);
//$amount_deposits_included = $object->getSumDepositsUsed(); $amount_deposits_included = $object->getSumDepositsUsed(($conf->multicurrency->enabled && $object->multicurrency_tx != 1) ? 1 : 0);
// Definition of $dir and $file // Definition of $dir and $file
if ($object->specimen) if ($object->specimen)
@ -259,15 +266,19 @@ class pdf_canelle extends ModelePDFSuppliersInvoices
global $action; global $action;
$reshook=$hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks $reshook=$hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
// Set nblines with the new facture lines content after hook
$nblines = count($object->lines); $nblines = count($object->lines);
$nbpayments = count($object->getListOfPayments());
// Create pdf instance
$pdf=pdf_getInstance($this->format); $pdf=pdf_getInstance($this->format);
$default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
$heightforinfotot = 50; // Height reserved to output the info and total part $pdf->SetAutoPageBreak(1, 0);
$heightforinfotot = 50+(4*$nbpayments); // Height reserved to output the info and total part and payment part
$heightforfreetext= (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT)?$conf->global->MAIN_PDF_FREETEXT_HEIGHT:5); // Height reserved to output the free text on last page $heightforfreetext= (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT)?$conf->global->MAIN_PDF_FREETEXT_HEIGHT:5); // Height reserved to output the free text on last page
$heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin) $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin)
if ($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS >0) $heightforfooter+= 6; if ($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS >0) $heightforfooter+= 6;
$pdf->SetAutoPageBreak(1, 0);
if (class_exists('TCPDF')) if (class_exists('TCPDF'))
{ {
@ -278,7 +289,7 @@ class pdf_canelle extends ModelePDFSuppliersInvoices
// Set path to the background PDF File // Set path to the background PDF File
if (! empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) if (! empty($conf->global->MAIN_ADD_PDF_BACKGROUND))
{ {
$pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND); $pagecount = $pdf->setSourceFile($conf->mycompany->multidir_output[$object->entity].'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
$tplidx = $pdf->importPage(1); $tplidx = $pdf->importPage(1);
} }
@ -287,15 +298,15 @@ class pdf_canelle extends ModelePDFSuppliersInvoices
$pdf->SetDrawColor(128, 128, 128); $pdf->SetDrawColor(128, 128, 128);
$pdf->SetTitle($outputlangs->convToOutputCharset($object->ref)); $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
$pdf->SetSubject($outputlangs->transnoentities("Invoice")); $pdf->SetSubject($outputlangs->transnoentities("PdfInvoiceTitle"));
$pdf->SetCreator("Dolibarr ".DOL_VERSION); $pdf->SetCreator("Dolibarr ".DOL_VERSION);
$pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs))); $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
$pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("Order")." ".$outputlangs->convToOutputCharset($object->thirdparty->name)); $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("PdfInvoiceTitle")." ".$outputlangs->convToOutputCharset($object->thirdparty->name));
if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false); if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false);
$pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
// Positionne $this->atleastonediscount si on a au moins une remise // Set $this->atleastonediscount if you have at least one discount
for ($i = 0 ; $i < $nblines ; $i++) for ($i = 0 ; $i < $nblines ; $i++)
{ {
if ($object->lines[$i]->remise_percent) if ($object->lines[$i]->remise_percent)
@ -348,11 +359,16 @@ class pdf_canelle extends ModelePDFSuppliersInvoices
} }
} }
// Affiche notes // Display notes
if (! empty($object->note_public)) if (! empty($object->note_public))
{ {
$tab_top -= 2; $tab_top -= 2;
$substitutionarray=pdf_getSubstitutionArray($outputlangs, null, $object);
complete_substitutions_array($substitutionarray, $outputlangs, $object);
$notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs);
$notetoshow = convertBackOfficeMediasLinksToPublicLinks($notetoshow);
$pdf->SetFont('', '', $default_font_size - 1); $pdf->SetFont('', '', $default_font_size - 1);
$pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top-1, dol_htmlentitiesbr($object->note_public), 0, 1); $pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top-1, dol_htmlentitiesbr($object->note_public), 0, 1);
$nexY = $pdf->GetY(); $nexY = $pdf->GetY();
@ -376,13 +392,18 @@ class pdf_canelle extends ModelePDFSuppliersInvoices
$pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
$pdf->SetTextColor(0, 0, 0); $pdf->SetTextColor(0, 0, 0);
// Define size of image if we need it
$imglinesize=array();
if (! empty($realpatharray[$i])) $imglinesize=pdf_getSizeForImage($realpatharray[$i]);
$pdf->setTopMargin($tab_top_newpage); $pdf->setTopMargin($tab_top_newpage);
$pdf->setPageOrientation('', 1, $heightforfooter+$heightforfreetext+$heightforinfotot); // The only function to edit the bottom margin of current page to set it. $pdf->setPageOrientation('', 1, $heightforfooter+$heightforfreetext+$heightforinfotot); // The only function to edit the bottom margin of current page to set it.
$pageposbefore=$pdf->getPage(); $pageposbefore=$pdf->getPage();
$showpricebeforepagebreak=1;
// Description of product line // Description of product line
$curX = $this->posxdesc-1; $curX = $this->posxdesc-1;
$showpricebeforepagebreak=1;
$pdf->startTransaction(); $pdf->startTransaction();
pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxtva-$curX, 3, $curX, $curY, $hideref, $hidedesc, 1); pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxtva-$curX, 3, $curX, $curY, $hideref, $hidedesc, 1);
@ -415,6 +436,7 @@ class pdf_canelle extends ModelePDFSuppliersInvoices
{ {
$pdf->commitTransaction(); $pdf->commitTransaction();
} }
$posYAfterDescription=$pdf->GetY();
$nexY = $pdf->GetY(); $nexY = $pdf->GetY();
$pageposafter=$pdf->getPage(); $pageposafter=$pdf->getPage();
@ -422,12 +444,12 @@ class pdf_canelle extends ModelePDFSuppliersInvoices
$pdf->setTopMargin($this->marge_haute); $pdf->setTopMargin($this->marge_haute);
$pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it. $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
// We suppose that a too long description is moved completely on next page // We suppose that a too long description or photo were moved completely on next page
if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) { if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
$pdf->setPage($pageposafter); $curY = $tab_top_newpage; $pdf->setPage($pageposafter); $curY = $tab_top_newpage;
} }
$pdf->SetFont('', '', $default_font_size - 1); // On repositionne la police par defaut $pdf->SetFont('', '', $default_font_size - 1); // We reposition the default font
// VAT Rate // VAT Rate
if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT))
@ -442,18 +464,13 @@ class pdf_canelle extends ModelePDFSuppliersInvoices
$pdf->SetXY($this->posxup, $curY); $pdf->SetXY($this->posxup, $curY);
$pdf->MultiCell($this->posxqty-$this->posxup-0.8, 3, $up_excl_tax, 0, 'R', 0); $pdf->MultiCell($this->posxqty-$this->posxup-0.8, 3, $up_excl_tax, 0, 'R', 0);
// Unit price before discount
$up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails);
$pdf->SetXY($this->posxup, $curY);
$pdf->MultiCell($this->posxqty-$this->posxup-0.8, 3, $up_excl_tax, 0, 'R', 0);
// Quantity // Quantity
$qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails); $qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails);
$pdf->SetXY($this->posxqty, $curY); $pdf->SetXY($this->posxqty, $curY);
$pdf->MultiCell($this->posxunit-$this->posxqty-0.8, 4, $qty, 0, 'R'); // Enough for 6 chars $pdf->MultiCell($this->posxunit-$this->posxqty-0.8, 4, $qty, 0, 'R'); // Enough for 6 chars
// Unit // Unit
if($conf->global->PRODUCT_USE_UNITS) if (! empty($conf->global->PRODUCT_USE_UNITS))
{ {
$unit = pdf_getlineunit($object, $i, $outputlangs, $hidedetails, $hookmanager); $unit = pdf_getlineunit($object, $i, $outputlangs, $hidedetails, $hookmanager);
$pdf->SetXY($this->posxunit, $curY); $pdf->SetXY($this->posxunit, $curY);
@ -461,15 +478,15 @@ class pdf_canelle extends ModelePDFSuppliersInvoices
} }
// Discount on line // Discount on line
$pdf->SetXY($this->posxdiscount, $curY);
if ($object->lines[$i]->remise_percent) if ($object->lines[$i]->remise_percent)
{ {
$pdf->SetXY($this->posxdiscount-2, $curY);
$remise_percent = pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails); $remise_percent = pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails);
$pdf->MultiCell($this->postotalht-$this->posxdiscount-1, 3, $remise_percent, 0, 'R'); $pdf->MultiCell($this->postotalht-$this->posxdiscount-1, 3, $remise_percent, 0, 'R');
} }
// Total HT line // Total HT line
$total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs); $total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails);
$pdf->SetXY($this->postotalht, $curY); $pdf->SetXY($this->postotalht, $curY);
$pdf->MultiCell($this->page_largeur-$this->marge_droite-$this->postotalht, 3, $total_excl_tax, 0, 'R', 0); $pdf->MultiCell($this->page_largeur-$this->marge_droite-$this->postotalht, 3, $total_excl_tax, 0, 'R', 0);
@ -494,6 +511,8 @@ class pdf_canelle extends ModelePDFSuppliersInvoices
$this->localtax1[$localtax1rate]+=$localtax1ligne; $this->localtax1[$localtax1rate]+=$localtax1ligne;
$this->localtax2[$localtax2rate]+=$localtax2ligne; $this->localtax2[$localtax2rate]+=$localtax2ligne;
if ($posYAfterImage > $posYAfterDescription) $nexY=$posYAfterImage;
// Add line // Add line
if (! empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblines - 1)) if (! empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblines - 1))
{ {
@ -555,18 +574,19 @@ class pdf_canelle extends ModelePDFSuppliersInvoices
$bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1; $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
} }
// Affiche zone totaux // Display total area
$posy=$this->_tableau_tot($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs); $posy=$this->_tableau_tot($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs);
$amount_credit_notes_included=0; $amount_credit_notes_included=0;
$amount_deposits_included=0; $amount_deposits_included=0;
if ($deja_regle || $amount_credit_notes_included || $amount_deposits_included) // Display Payments area
if (($deja_regle || $amount_credit_notes_included || $amount_deposits_included) && empty($conf->global->SUPPLIER_INVOICE_NO_PAYMENT_DETAILS))
{ {
$posy=$this->_tableau_versements($pdf, $object, $posy, $outputlangs); $posy=$this->_tableau_versements($pdf, $object, $posy, $outputlangs, $heightforfooter);
} }
// Pied de page // Pagefoot
$this->_pagefoot($pdf, $object, $outputlangs); $this->_pagefoot($pdf, $object, $outputlangs);
if (method_exists($pdf, 'AliasNbPages')) $pdf->AliasNbPages(); if (method_exists($pdf, 'AliasNbPages')) $pdf->AliasNbPages();
@ -594,13 +614,13 @@ class pdf_canelle extends ModelePDFSuppliersInvoices
} }
else else
{ {
$this->error=$langs->trans("ErrorCanNotCreateDir", $dir); $this->error=$langs->transnoentities("ErrorCanNotCreateDir", $dir);
return 0; return 0;
} }
} }
else else
{ {
$this->error=$langs->trans("ErrorConstantNotDefined", "SUPPLIER_OUTPUTDIR"); $this->error=$langs->transnoentities("ErrorConstantNotDefined", "SUPPLIER_OUTPUTDIR");
return 0; return 0;
} }
} }
@ -610,9 +630,9 @@ class pdf_canelle extends ModelePDFSuppliersInvoices
/** /**
* Show total to pay * Show total to pay
* *
* @param PDF $pdf Object PDF * @param PDF $pdf Object PDF
* @param Facture $object Object invoice * @param Object $object Object invoice
* @param int $deja_regle Montant deja regle * @param int $deja_regle Amount already paid (in the currency of invoice)
* @param int $posy Position depart * @param int $posy Position depart
* @param Translate $outputlangs Objet langs * @param Translate $outputlangs Objet langs
* @return int Position pour suite * @return int Position pour suite
@ -622,20 +642,16 @@ class pdf_canelle extends ModelePDFSuppliersInvoices
// phpcs:enable // phpcs:enable
global $conf,$mysoc; global $conf,$mysoc;
$default_font_size = pdf_getPDFFontSize($outputlangs); $sign=1;
if ($object->type == 2 && ! empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) $sign=-1;
$default_font_size = pdf_getPDFFontSize($outputlangs);
$tab2_top = $posy; $tab2_top = $posy;
$tab2_hl = 4; $tab2_hl = 4;
$pdf->SetFont('', '', $default_font_size - 1); $pdf->SetFont('', '', $default_font_size - 1);
$pdf->SetXY($this->marge_gauche, $tab2_top + 0); // Total table
// If France, show VAT mention if not applicable
if ($this->emetteur->country_code == 'FR' && $this->franchise == 1)
{
$pdf->MultiCell(100, $tab2_hl, $outputlangs->transnoentities("VATIsNotUsedForInvoice"), 0, 'L', 0);
}
// Tableau total
$col1x = 120; $col2x = 170; $col1x = 120; $col2x = 170;
if ($this->page_largeur < 210) // To work with US executive format if ($this->page_largeur < 210) // To work with US executive format
{ {
@ -643,6 +659,7 @@ class pdf_canelle extends ModelePDFSuppliersInvoices
} }
$largcol2 = ($this->page_largeur - $this->marge_droite - $col2x); $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
$useborder=0;
$index=0; $index=0;
// Total HT // Total HT
@ -652,11 +669,14 @@ class pdf_canelle extends ModelePDFSuppliersInvoices
$total_ht = (($conf->multicurrency->enabled && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ht : $object->total_ht); $total_ht = (($conf->multicurrency->enabled && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ht : $object->total_ht);
$pdf->SetXY($col2x, $tab2_top + 0); $pdf->SetXY($col2x, $tab2_top + 0);
$pdf->MultiCell($largcol2, $tab2_hl, price($total_ht + $object->remise), 0, 'R', 1); $pdf->MultiCell($largcol2, $tab2_hl, price($sign * ($total_ht + (! empty($object->remise)?$object->remise:0)), 0, $outputlangs), 0, 'R', 1);
// Show VAT by rates and total // Show VAT by rates and total
$pdf->SetFillColor(248, 248, 248); $pdf->SetFillColor(248, 248, 248);
$total_ttc = ($conf->multicurrency->enabled && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ttc : $object->total_ttc;
$this->atleastoneratenotnull=0;
foreach($this->tva as $tvakey => $tvaval) foreach($this->tva as $tvakey => $tvaval)
{ {
if ($tvakey > 0) // On affiche pas taux 0 if ($tvakey > 0) // On affiche pas taux 0
@ -674,12 +694,12 @@ class pdf_canelle extends ModelePDFSuppliersInvoices
$tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")"; $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
} }
$totalvat =$outputlangs->transcountrynoentities("TotalVAT", $mysoc->country_code).' '; $totalvat = $outputlangs->transcountrynoentities("TotalVAT", $mysoc->country_code).' ';
$totalvat.=vatrate($tvakey, 1).$tvacompl; $totalvat.=vatrate($tvakey, 1).$tvacompl;
$pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1); $pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index); $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
$pdf->MultiCell($largcol2, $tab2_hl, price($tvaval), 0, 'R', 1); $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
} }
} }
if (! $this->atleastoneratenotnull) // If no vat at all if (! $this->atleastoneratenotnull) // If no vat at all
@ -688,7 +708,7 @@ class pdf_canelle extends ModelePDFSuppliersInvoices
$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index); $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transcountrynoentities("TotalVAT", $mysoc->country_code), 0, 'L', 1); $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transcountrynoentities("TotalVAT", $mysoc->country_code), 0, 'L', 1);
$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index); $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
$pdf->MultiCell($largcol2, $tab2_hl, price($object->total_tva), 0, 'R', 1); $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_tva, 0, $outputlangs), 0, 'R', 1);
// Total LocalTax1 // Total LocalTax1
if (! empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on' && $object->total_localtax1>0) if (! empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on' && $object->total_localtax1>0)
@ -697,7 +717,7 @@ class pdf_canelle extends ModelePDFSuppliersInvoices
$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index); $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code), 0, 'L', 1); $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code), 0, 'L', 1);
$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index); $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
$pdf->MultiCell($largcol2, $tab2_hl, price($object->total_localtax1), 0, 'R', 1); $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_localtax1, 0, $outputlangs), 0, 'R', 1);
} }
// Total LocalTax2 // Total LocalTax2
@ -707,7 +727,7 @@ class pdf_canelle extends ModelePDFSuppliersInvoices
$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index); $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code), 0, 'L', 1); $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code), 0, 'L', 1);
$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index); $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
$pdf->MultiCell($largcol2, $tab2_hl, price($object->total_localtax2), 0, 'R', 1); $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_localtax2, 0, $outputlangs), 0, 'R', 1);
} }
} }
else else
@ -734,7 +754,7 @@ class pdf_canelle extends ModelePDFSuppliersInvoices
$pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1); $pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index); $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
$pdf->MultiCell($largcol2, $tab2_hl, price($tvaval), 0, 'R', 1); $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
} }
} }
//} //}
@ -761,14 +781,12 @@ class pdf_canelle extends ModelePDFSuppliersInvoices
$pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1); $pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index); $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
$pdf->MultiCell($largcol2, $tab2_hl, price($tvaval), 0, 'R', 1); $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
} }
} }
//} //}
} }
$useborder=0;
// Total TTC // Total TTC
$index++; $index++;
$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index); $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
@ -776,35 +794,58 @@ class pdf_canelle extends ModelePDFSuppliersInvoices
$pdf->SetFillColor(224, 224, 224); $pdf->SetFillColor(224, 224, 224);
$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalTTC"), $useborder, 'L', 1); $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalTTC"), $useborder, 'L', 1);
$total_ttc = ($conf->multicurrency->enabled && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ttc : $object->total_ttc;
$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index); $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
$pdf->MultiCell($largcol2, $tab2_hl, price($total_ttc), $useborder, 'R', 1); $pdf->MultiCell($largcol2, $tab2_hl, price($sign * $total_ttc, 0, $outputlangs), $useborder, 'R', 1);
$creditnoteamount=0; $pdf->SetTextColor(0, 0, 0);
$depositsamount=0; $creditnoteamount=$object->getSumCreditNotesUsed(($conf->multicurrency->enabled && $object->multicurrency_tx != 1) ? 1 : 0); // Warning, this also include excess received
//$creditnoteamount=$object->getSumCreditNotesUsed(); $depositsamount=$object->getSumDepositsUsed(($conf->multicurrency->enabled && $object->multicurrency_tx != 1) ? 1 : 0);
//$depositsamount=$object->getSumDepositsUsed();
//print "x".$creditnoteamount."-".$depositsamount;exit; //print "x".$creditnoteamount."-".$depositsamount;exit;
$resteapayer = price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 'MT'); $resteapayer = price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 'MT');
if (! empty($object->paye)) $resteapayer=0; if (! empty($object->paye)) $resteapayer=0;
if ($deja_regle > 0) if (($deja_regle > 0 || $creditnoteamount > 0 || $depositsamount > 0) && empty($conf->global->INVOICE_NO_PAYMENT_DETAILS))
{ {
// Already paid + Deposits
$index++; $index++;
$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index); $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("AlreadyPaid"), 0, 'L', 0); $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("Paid"), 0, 'L', 0);
$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index); $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
$pdf->MultiCell($largcol2, $tab2_hl, price($deja_regle), 0, 'R', 0); $pdf->MultiCell($largcol2, $tab2_hl, price($deja_regle + $depositsamount, 0, $outputlangs), 0, 'R', 0);
// Credit note
if ($creditnoteamount)
{
$labeltouse = ($outputlangs->transnoentities("CreditNotesOrExcessReceived") != "CreditNotesOrExcessReceived") ? $outputlangs->transnoentities("CreditNotesOrExcessReceived") : $outputlangs->transnoentities("CreditNotes");
$index++;
$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
$pdf->MultiCell($col2x-$col1x, $tab2_hl, $labeltouse, 0, 'L', 0);
$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
$pdf->MultiCell($largcol2, $tab2_hl, price($creditnoteamount, 0, $outputlangs), 0, 'R', 0);
}
// Escompte
if ($object->close_code == Facture::CLOSECODE_DISCOUNTVAT)
{
$index++;
$pdf->SetFillColor(255, 255, 255);
$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("EscompteOfferedShort"), $useborder, 'L', 1);
$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
$pdf->MultiCell($largcol2, $tab2_hl, price($object->total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 0, $outputlangs), $useborder, 'R', 1);
$resteapayer=0;
}
$index++; $index++;
$pdf->SetTextColor(0, 0, 60); $pdf->SetTextColor(0, 0, 60);
$pdf->SetFillColor(224, 224, 224);
$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index); $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("RemainderToPay"), $useborder, 'L', 1); $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("RemainderToPay"), $useborder, 'L', 1);
$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index); $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
$pdf->MultiCell($largcol2, $tab2_hl, price($resteapayer), $useborder, 'R', 1); $pdf->MultiCell($largcol2, $tab2_hl, price($resteapayer, 0, $outputlangs), $useborder, 'R', 1);
$pdf->SetFont('', '', $default_font_size - 1); $pdf->SetFont('', '', $default_font_size - 1);
$pdf->SetTextColor(0, 0, 0); $pdf->SetTextColor(0, 0, 0);
} }
@ -822,7 +863,7 @@ class pdf_canelle extends ModelePDFSuppliersInvoices
* @param string $tab_height Height of table (rectangle) * @param string $tab_height Height of table (rectangle)
* @param int $nexY Y (not used) * @param int $nexY Y (not used)
* @param Translate $outputlangs Langs object * @param Translate $outputlangs Langs object
* @param int $hidetop Hide top bar of array * @param int $hidetop 1=Hide top bar of array and title, 0=Hide nothing, -1=Hide only title
* @param int $hidebottom Hide bottom bar of array * @param int $hidebottom Hide bottom bar of array
* @param string $currency Currency code * @param string $currency Currency code
* @return void * @return void
@ -866,7 +907,7 @@ class pdf_canelle extends ModelePDFSuppliersInvoices
$pdf->MultiCell(108, 2, $outputlangs->transnoentities("Designation"), '', 'L'); $pdf->MultiCell(108, 2, $outputlangs->transnoentities("Designation"), '', 'L');
} }
if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) && empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN))
{ {
$pdf->line($this->posxtva-1, $tab_top, $this->posxtva-1, $tab_top + $tab_height); $pdf->line($this->posxtva-1, $tab_top, $this->posxtva-1, $tab_top + $tab_height);
if (empty($hidetop)) if (empty($hidetop))
@ -890,7 +931,8 @@ class pdf_canelle extends ModelePDFSuppliersInvoices
$pdf->MultiCell($this->posxunit-$this->posxqty-1, 2, $outputlangs->transnoentities("Qty"), '', 'C'); $pdf->MultiCell($this->posxunit-$this->posxqty-1, 2, $outputlangs->transnoentities("Qty"), '', 'C');
} }
if($conf->global->PRODUCT_USE_UNITS) { if (! empty($conf->global->PRODUCT_USE_UNITS))
{
$pdf->line($this->posxunit - 1, $tab_top, $this->posxunit - 1, $tab_top + $tab_height); $pdf->line($this->posxunit - 1, $tab_top, $this->posxunit - 1, $tab_top + $tab_height);
if (empty($hidetop)) { if (empty($hidetop)) {
$pdf->SetXY($this->posxunit - 1, $tab_top + 1); $pdf->SetXY($this->posxunit - 1, $tab_top + 1);
@ -899,20 +941,17 @@ class pdf_canelle extends ModelePDFSuppliersInvoices
} }
} }
$pdf->line($this->posxdiscount-1, $tab_top, $this->posxdiscount-1, $tab_top + $tab_height); if ($this->atleastonediscount)
if (empty($hidetop))
{ {
if ($this->atleastonediscount) $pdf->line($this->posxdiscount-1, $tab_top, $this->posxdiscount-1, $tab_top + $tab_height);
if (empty($hidetop))
{ {
$pdf->SetXY($this->posxdiscount-1, $tab_top+1); $pdf->SetXY($this->posxdiscount-1, $tab_top+1);
$pdf->MultiCell($this->postotalht-$this->posxdiscount+1, 2, $outputlangs->transnoentities("ReductionShort"), '', 'C'); $pdf->MultiCell($this->postotalht-$this->posxdiscount+1, 2, $outputlangs->transnoentities("ReductionShort"), '', 'C');
} }
} }
if ($this->atleastonediscount) $pdf->line($this->postotalht, $tab_top, $this->postotalht, $tab_top + $tab_height);
{
$pdf->line($this->postotalht, $tab_top, $this->postotalht, $tab_top + $tab_height);
}
if (empty($hidetop)) if (empty($hidetop))
{ {
$pdf->SetXY($this->postotalht-1, $tab_top+1); $pdf->SetXY($this->postotalht-1, $tab_top+1);
@ -926,7 +965,7 @@ class pdf_canelle extends ModelePDFSuppliersInvoices
* Show payments table * Show payments table
* *
* @param PDF $pdf Object PDF * @param PDF $pdf Object PDF
* @param FactureFournisseur $object Object invoice * @param Object $object Object to show
* @param int $posy Position y in PDF * @param int $posy Position y in PDF
* @param Translate $outputlangs Object langs for output * @param Translate $outputlangs Object langs for output
* @return int <0 if KO, >0 if OK * @return int <0 if KO, >0 if OK

View File

@ -506,7 +506,9 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
/* /*
* All unpayed supplier invoices * All unpayed supplier invoices
*/ */
$sql = 'SELECT f.rowid as facid, f.ref, f.ref_supplier, f.type, f.total_ht, f.total_ttc, f.multicurrency_total_ttc, f.datef as df, f.date_lim_reglement as dlr,'; $sql = 'SELECT f.rowid as facid, f.ref, f.ref_supplier, f.type, f.total_ht, f.total_ttc,';
$sql.= ' f.multicurrency_code, f.multicurrency_tx, f.multicurrency_total_ht, f.multicurrency_total_tva, f.multicurrency_total_ttc,';
$sql.= ' f.datef as df, f.date_lim_reglement as dlr,';
$sql.= ' SUM(pf.amount) as am, SUM(pf.multicurrency_amount) as multicurrency_am'; $sql.= ' SUM(pf.amount) as am, SUM(pf.multicurrency_amount) as multicurrency_am';
$sql.= ' FROM '.MAIN_DB_PREFIX.'facture_fourn as f'; $sql.= ' FROM '.MAIN_DB_PREFIX.'facture_fourn as f';
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf ON pf.fk_facturefourn = f.rowid'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf ON pf.fk_facturefourn = f.rowid';