28 require_once DOL_DOCUMENT_ROOT.
'/core/modules/supplier_invoice/modules_facturefournisseur.php';
29 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
30 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
31 require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
32 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
33 require_once DOL_DOCUMENT_ROOT.
'/core/lib/pdf.lib.php';
59 public $update_main_doc_field;
70 public $phpmin = array(7, 0);
76 public $version =
'dolibarr';
101 public $marge_droite;
128 global $conf, $langs, $mysoc;
131 $langs->loadLangs(array(
"main",
"bills"));
134 $this->
name =
"canelle";
135 $this->
description = $langs->trans(
'SuppliersInvoiceModel');
136 $this->update_main_doc_field = 1;
141 $this->page_largeur = $formatarray[
'width'];
142 $this->page_hauteur = $formatarray[
'height'];
143 $this->format = array($this->page_largeur, $this->page_hauteur);
149 $this->option_logo = 1;
150 $this->option_tva = 1;
151 $this->option_modereg = 1;
152 $this->option_condreg = 1;
153 $this->option_multilang = 1;
156 $this->posxdesc = $this->marge_gauche + 1;
158 if (!empty($conf->global->PRODUCT_USE_UNITS)) {
161 $this->posxqty = 130;
162 $this->posxunit = 147;
164 $this->posxtva = 106;
166 $this->posxqty = 145;
167 $this->posxunit = 162;
169 $this->posxdiscount = 162;
170 $this->postotalht = 174;
175 $this->posxpicture = $this->posxtva - (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH) ? 20 : $conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH);
176 if ($this->page_largeur < 210) {
177 $this->posxpicture -= 20;
178 $this->posxtva -= 20;
180 $this->posxqty -= 20;
181 $this->posxunit -= 20;
182 $this->posxdiscount -= 20;
183 $this->postotalht -= 20;
186 $this->tva = array();
187 $this->tva_array = array();
188 $this->localtax1 = array();
189 $this->localtax2 = array();
190 $this->atleastoneratenotnull = 0;
191 $this->atleastonediscount = 0;
207 public function write_file($object, $outputlangs =
'', $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
210 global $user, $langs, $conf, $mysoc, $hookmanager, $nblines;
213 if (!is_object($object->thirdparty)) {
214 $object->fetch_thirdparty();
216 if (!is_object($object->thirdparty)) {
217 $object->thirdparty = $mysoc;
220 $this->emetteur = $object->thirdparty;
221 if (!$this->emetteur->country_code) {
222 $this->emetteur->country_code = substr($langs->defaultlang, -2);
225 if (!is_object($outputlangs)) {
226 $outputlangs = $langs;
229 if (!empty($conf->global->MAIN_USE_FPDF)) {
230 $outputlangs->charset_output =
'ISO-8859-1';
234 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"bills",
"products"));
236 $nblines = count($object->lines);
238 if ($conf->fournisseur->facture->dir_output) {
239 $deja_regle = $object->getSommePaiement((
isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
240 $amount_credit_notes_included = $object->getSumCreditNotesUsed((
isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
241 $amount_deposits_included = $object->getSumDepositsUsed((
isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
244 if ($object->specimen) {
245 $dir = $conf->fournisseur->facture->dir_output;
246 $file = $dir.
"/SPECIMEN.pdf";
250 $dir = $conf->fournisseur->facture->dir_output.
'/'.
get_exdir($object->id, 2, 0, 0, $object,
'invoice_supplier').$objectref;
251 $file = $dir.
"/".$objectref.
".pdf";
252 if (!empty($conf->global->SUPPLIER_REF_IN_NAME)) {
253 $file = $dir.
"/".$objectref.($objectrefsupplier ?
"_".$objectrefsupplier :
"").
".pdf";
257 if (!file_exists($dir)) {
259 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
264 if (file_exists($dir)) {
266 if (!is_object($hookmanager)) {
267 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
270 $hookmanager->initHooks(array(
'pdfgeneration'));
271 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
273 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters, $object, $action);
276 $nblines = count($object->lines);
277 $nbpayments = count($object->getListOfPayments());
282 $pdf->SetAutoPageBreak(1, 0);
284 $heightforinfotot = 50 + (4 * $nbpayments);
285 if ($heightforinfotot > 220) {
286 $heightforinfotot = 220;
288 $heightforfreetext = (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->MAIN_PDF_FREETEXT_HEIGHT : 5);
289 $heightforfooter = $this->marge_basse + 8;
290 if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS)) {
291 $heightforfooter += 6;
294 if (class_exists(
'TCPDF')) {
295 $pdf->setPrintHeader(
false);
296 $pdf->setPrintFooter(
false);
300 if (!empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) {
301 $pagecount = $pdf->setSourceFile($conf->mycompany->multidir_output[$object->entity].
'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
302 $tplidx = $pdf->importPage(1);
307 $pdf->SetDrawColor(128, 128, 128);
309 $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
310 $pdf->SetSubject($outputlangs->transnoentities(
"PdfInvoiceTitle"));
311 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
312 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
313 $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref).
" ".$outputlangs->transnoentities(
"PdfInvoiceTitle").
" ".$outputlangs->convToOutputCharset($object->thirdparty->name));
315 $pdf->SetCompression(
false);
318 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
321 for ($i = 0; $i < $nblines; $i++) {
322 if ($object->lines[$i]->remise_percent) {
323 $this->atleastonediscount++;
326 if (empty($this->atleastonediscount)) {
327 $delta = ($this->postotalht - $this->posxdiscount);
328 $this->posxpicture += $delta;
329 $this->posxtva += $delta;
330 $this->posxup += $delta;
331 $this->posxqty += $delta;
332 $this->posxunit += $delta;
333 $this->posxdiscount += $delta;
339 if (!empty($tplidx)) {
340 $pdf->useTemplate($tplidx);
343 $top_shift = $this->
_pagehead($pdf, $object, 1, $outputlangs);
344 $pdf->SetFont(
'',
'', $default_font_size - 1);
345 $pdf->MultiCell(0, 3,
'');
346 $pdf->SetTextColor(0, 0, 0);
348 $tab_top = 90 + $top_shift;
349 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
353 $desc_incoterms = $object->getIncotermsForPDF();
354 if ($desc_incoterms) {
357 $pdf->SetFont(
'',
'', $default_font_size - 1);
358 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1,
dol_htmlentitiesbr($desc_incoterms), 0, 1);
359 $nexY = $pdf->GetY();
360 $height_incoterms = $nexY - $tab_top;
363 $pdf->SetDrawColor(192, 192, 192);
364 $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_incoterms + 1);
366 $tab_top = $nexY + 6;
371 $notetoshow = empty($object->note_public) ?
'' : $object->note_public;
381 $pdf->SetFont(
'',
'', $default_font_size - 1);
382 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1,
dol_htmlentitiesbr($notetoshow), 0, 1);
383 $nexY = $pdf->GetY();
384 $height_note = $nexY - $tab_top;
387 $pdf->SetDrawColor(192, 192, 192);
388 $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1);
390 $tab_top = $nexY + 6;
393 $iniY = $tab_top + 7;
394 $curY = $tab_top + 7;
395 $nexY = $tab_top + 7;
398 for ($i = 0; $i < $nblines; $i++) {
400 $pdf->SetFont(
'',
'', $default_font_size - 1);
401 $pdf->SetTextColor(0, 0, 0);
404 $imglinesize = array();
405 if (!empty($realpatharray[$i])) {
409 $pdf->setTopMargin($tab_top_newpage);
410 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext + $heightforinfotot);
411 $pageposbefore = $pdf->getPage();
413 $showpricebeforepagebreak = 1;
417 $curX = $this->posxdesc - 1;
419 $pdf->startTransaction();
420 pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxtva - $curX, 3, $curX, $curY, $hideref, $hidedesc, 1);
421 $pageposafter = $pdf->getPage();
422 if ($pageposafter > $pageposbefore) {
423 $pdf->rollbackTransaction(
true);
424 $pageposafter = $pageposbefore;
426 $pdf->setPageOrientation(
'', 1, $heightforfooter);
427 pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxtva - $curX, 4, $curX, $curY, $hideref, $hidedesc, 1);
428 $posyafter = $pdf->GetY();
429 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
430 if ($i == ($nblines - 1)) {
431 $pdf->AddPage(
'',
'',
true);
432 if (!empty($tplidx)) {
433 $pdf->useTemplate($tplidx);
436 $this->
_pagehead($pdf, $object, 0, $outputlangs);
438 $pdf->setPage($pageposafter + 1);
443 if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
444 $showpricebeforepagebreak = 1;
446 $showpricebeforepagebreak = 0;
451 $pdf->commitTransaction();
453 $posYAfterDescription = $pdf->GetY();
455 $nexY = $pdf->GetY();
456 $pageposafter = $pdf->getPage();
457 $pdf->setPage($pageposbefore);
458 $pdf->setTopMargin($this->marge_haute);
459 $pdf->setPageOrientation(
'', 1, 0);
462 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
463 $pdf->setPage($pageposafter);
464 $curY = $tab_top_newpage;
467 $pdf->SetFont(
'',
'', $default_font_size - 1);
470 if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) {
472 $pdf->SetXY($this->posxtva, $curY);
473 $pdf->MultiCell($this->posxup - $this->posxtva - 1, 3, $vat_rate, 0,
'R');
478 $pdf->SetXY($this->posxup, $curY);
479 $pdf->MultiCell($this->posxqty - $this->posxup - 0.8, 3, $up_excl_tax, 0,
'R', 0);
483 $pdf->SetXY($this->posxqty, $curY);
484 $pdf->MultiCell($this->posxunit - $this->posxqty - 0.8, 4, $qty, 0,
'R');
487 if (!empty($conf->global->PRODUCT_USE_UNITS)) {
488 $unit =
pdf_getlineunit($object, $i, $outputlangs, $hidedetails, $hookmanager);
489 $pdf->SetXY($this->posxunit, $curY);
490 $pdf->MultiCell($this->posxdiscount - $this->posxunit - 0.8, 4, $unit, 0,
'L');
494 if ($object->lines[$i]->remise_percent) {
495 $pdf->SetXY($this->posxdiscount - 2, $curY);
497 $pdf->MultiCell($this->postotalht - $this->posxdiscount - 1, 3, $remise_percent, 0,
'R');
502 $pdf->SetXY($this->postotalht, $curY);
503 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->postotalht, 3, $total_excl_tax, 0,
'R', 0);
506 if (
isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) {
507 $tvaligne = $object->lines[$i]->multicurrency_total_tva;
509 $tvaligne = $object->lines[$i]->total_tva;
512 $localtax1ligne = $object->lines[$i]->total_localtax1;
513 $localtax2ligne = $object->lines[$i]->total_localtax2;
515 if (!empty($object->remise_percent)) {
516 $tvaligne -= ($tvaligne * $object->remise_percent) / 100;
519 $vatrate = (string) $object->lines[$i]->tva_tx;
520 $localtax1rate = (
string) $object->lines[$i]->localtax1_tx;
521 $localtax2rate = (string) $object->lines[$i]->localtax2_tx;
523 if (($object->lines[$i]->info_bits & 0x01) == 0x01) {
526 if (empty($this->tva[$vatrate])) {
527 $this->tva[$vatrate] = 0;
529 if (empty($this->localtax1[$localtax1rate])) {
530 $this->localtax1[$localtax1rate] = 0;
532 if (empty($this->localtax2[$localtax2rate])) {
533 $this->localtax2[$localtax2rate] = 0;
535 $this->tva[$vatrate] += $tvaligne;
536 $this->localtax1[$localtax1rate] += $localtax1ligne;
537 $this->localtax2[$localtax2rate] += $localtax2ligne;
539 if ($posYAfterImage > $posYAfterDescription) {
540 $nexY = $posYAfterImage;
544 if (!empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblines - 1)) {
545 $pdf->setPage($pageposafter);
546 $pdf->SetLineStyle(array(
'dash'=>
'1,1',
'color'=>array(80, 80, 80)));
548 $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
549 $pdf->SetLineStyle(array(
'dash'=>0));
555 while ($pagenb < $pageposafter) {
556 $pdf->setPage($pagenb);
558 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
560 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
562 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
564 $pdf->setPage($pagenb);
565 $pdf->setPageOrientation(
'', 1, 0);
567 $this->
_pagehead($pdf, $object, 0, $outputlangs);
570 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
572 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
574 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
576 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
579 if (!empty($tplidx)) {
580 $pdf->useTemplate($tplidx);
584 $this->
_pagehead($pdf, $object, 0, $outputlangs);
591 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0, $object->multicurrency_code);
592 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
594 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code);
595 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
599 $posy = $this->
_tableau_tot($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs);
601 $amount_credit_notes_included = 0;
602 $amount_deposits_included = 0;
605 if (($deja_regle || $amount_credit_notes_included || $amount_deposits_included) && empty($conf->global->SUPPLIER_INVOICE_NO_PAYMENT_DETAILS)) {
610 $this->
_pagefoot($pdf, $object, $outputlangs);
611 if (method_exists($pdf,
'AliasNbPages')) {
612 $pdf->AliasNbPages();
617 $pdf->Output($file,
'F');
620 $hookmanager->initHooks(array(
'pdfgeneration'));
621 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
623 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
625 $this->error = $hookmanager->error;
626 $this->errors = $hookmanager->errors;
629 if (!empty($conf->global->MAIN_UMASK)) {
630 @chmod($file, octdec($conf->global->MAIN_UMASK));
633 $this->result = array(
'fullpath'=>$file);
637 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
641 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"SUPPLIER_OUTPUTDIR");
658 protected function _tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs)
661 global $conf, $mysoc;
664 if ($object->type == 2 && !empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) {
672 $pdf->SetFont(
'',
'', $default_font_size - 1);
677 if ($this->page_largeur < 210) {
680 $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
686 $pdf->SetFillColor(255, 255, 255);
687 $pdf->SetXY($col1x, $tab2_top + 0);
688 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalHT"), 0,
'L', 1);
690 $total_ht = ((
isModEnabled(
"multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ht : $object->total_ht);
691 $pdf->SetXY($col2x, $tab2_top + 0);
692 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * ($total_ht + (!empty($object->remise) ? $object->remise : 0)), 0, $outputlangs), 0,
'R', 1);
695 $pdf->SetFillColor(248, 248, 248);
697 $total_ttc = (
isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ttc : $object->total_ttc;
699 $this->atleastoneratenotnull = 0;
700 foreach ($this->tva as $tvakey => $tvaval) {
702 $this->atleastoneratenotnull++;
705 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
709 if (preg_match(
'/\*/', $tvakey)) {
710 $tvakey = str_replace(
'*',
'', $tvakey);
711 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
714 $totalvat = $outputlangs->transcountrynoentities(
"TotalVAT", $mysoc->country_code).
' ';
715 $totalvat .=
vatrate($tvakey, 1).$tvacompl;
716 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
718 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
719 $pdf->MultiCell($largcol2, $tab2_hl,
price($tvaval, 0, $outputlangs), 0,
'R', 1);
722 if (!$this->atleastoneratenotnull) {
724 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
725 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transcountrynoentities(
"TotalVAT", $mysoc->country_code), 0,
'L', 1);
726 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
727 $pdf->MultiCell($largcol2, $tab2_hl,
price($object->total_tva, 0, $outputlangs), 0,
'R', 1);
730 if (!empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION ==
'localtax1on' && $object->total_localtax1 > 0) {
732 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
733 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transcountrynoentities(
"TotalLT1", $mysoc->country_code), 0,
'L', 1);
734 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
735 $pdf->MultiCell($largcol2, $tab2_hl,
price($object->total_localtax1, 0, $outputlangs), 0,
'R', 1);
739 if (!empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION ==
'localtax2on' && $object->total_localtax2 > 0) {
741 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
742 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transcountrynoentities(
"TotalLT2", $mysoc->country_code), 0,
'L', 1);
743 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
744 $pdf->MultiCell($largcol2, $tab2_hl,
price($object->total_localtax2, 0, $outputlangs), 0,
'R', 1);
750 foreach ($this->localtax1 as $tvakey => $tvaval) {
755 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
758 if (preg_match(
'/\*/', $tvakey)) {
759 $tvakey = str_replace(
'*',
'', $tvakey);
760 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
762 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1", $mysoc->country_code).
' ';
763 $totalvat .=
vatrate(abs($tvakey), 1).$tvacompl;
764 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
766 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
767 $pdf->MultiCell($largcol2, $tab2_hl,
price($tvaval, 0, $outputlangs), 0,
'R', 1);
775 foreach ($this->localtax2 as $tvakey => $tvaval) {
780 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
783 if (preg_match(
'/\*/', $tvakey)) {
784 $tvakey = str_replace(
'*',
'', $tvakey);
785 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
787 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT2", $mysoc->country_code).
' ';
788 $totalvat .=
vatrate(abs($tvakey), 1).$tvacompl;
789 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
791 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
792 $pdf->MultiCell($largcol2, $tab2_hl,
price($tvaval, 0, $outputlangs), 0,
'R', 1);
800 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
801 $pdf->SetTextColor(0, 0, 60);
802 $pdf->SetFillColor(224, 224, 224);
803 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalTTC"), $useborder,
'L', 1);
805 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
806 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * $total_ttc, 0, $outputlangs), $useborder,
'R', 1);
808 $pdf->SetTextColor(0, 0, 0);
809 $creditnoteamount = $object->getSumCreditNotesUsed((
isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
810 $depositsamount = $object->getSumDepositsUsed((
isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
812 $resteapayer =
price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount,
'MT');
813 if (!empty($object->paye)) {
817 if (($deja_regle > 0 || $creditnoteamount > 0 || $depositsamount > 0) && empty($conf->global->INVOICE_NO_PAYMENT_DETAILS)) {
820 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
821 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"Paid"), 0,
'L', 0);
822 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
823 $pdf->MultiCell($largcol2, $tab2_hl,
price($deja_regle + $depositsamount, 0, $outputlangs), 0,
'R', 0);
826 if ($creditnoteamount) {
827 $labeltouse = ($outputlangs->transnoentities(
"CreditNotesOrExcessReceived") !=
"CreditNotesOrExcessReceived") ? $outputlangs->transnoentities(
"CreditNotesOrExcessReceived") : $outputlangs->transnoentities(
"CreditNotes");
829 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
830 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $labeltouse, 0,
'L', 0);
831 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
832 $pdf->MultiCell($largcol2, $tab2_hl,
price($creditnoteamount, 0, $outputlangs), 0,
'R', 0);
836 if ($object->close_code == FactureFournisseur::CLOSECODE_DISCOUNTVAT) {
838 $pdf->SetFillColor(255, 255, 255);
840 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
841 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"EscompteOfferedShort"), $useborder,
'L', 1);
842 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
843 $pdf->MultiCell($largcol2, $tab2_hl,
price($object->total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 0, $outputlangs), $useborder,
'R', 1);
849 $pdf->SetTextColor(0, 0, 60);
850 $pdf->SetFillColor(224, 224, 224);
851 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
852 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"RemainderToPay"), $useborder,
'L', 1);
854 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
855 $pdf->MultiCell($largcol2, $tab2_hl,
price($resteapayer, 0, $outputlangs), $useborder,
'R', 1);
856 $pdf->SetFont(
'',
'', $default_font_size - 1);
857 $pdf->SetTextColor(0, 0, 0);
861 return ($tab2_top + ($tab2_hl * $index));
878 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency =
'')
888 $currency = !empty($currency) ? $currency : $conf->currency;
892 $pdf->SetTextColor(0, 0, 0);
893 $pdf->SetFont(
'',
'', $default_font_size - 2);
895 if (empty($hidetop)) {
896 $titre = $outputlangs->transnoentities(
"AmountInCurrency", $outputlangs->transnoentitiesnoconv(
"Currency".$currency));
897 $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
898 $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
901 if (!empty($conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)) {
902 $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_droite - $this->marge_gauche, 5,
'F',
null, explode(
',', $conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR));
906 $pdf->SetDrawColor(128, 128, 128);
907 $pdf->SetFont(
'',
'', $default_font_size - 1);
910 $this->
printRect($pdf, $this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $tab_height, $hidetop, $hidebottom);
912 if (empty($hidetop)) {
913 $pdf->line($this->marge_gauche, $tab_top + 5, $this->page_largeur - $this->marge_droite, $tab_top + 5);
915 $pdf->SetXY($this->posxdesc - 1, $tab_top + 1);
916 $pdf->MultiCell(108, 2, $outputlangs->transnoentities(
"Designation"),
'',
'L');
919 if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) && empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) {
920 $pdf->line($this->posxtva - 1, $tab_top, $this->posxtva - 1, $tab_top + $tab_height);
921 if (empty($hidetop)) {
922 $pdf->SetXY($this->posxtva - 3, $tab_top + 1);
923 $pdf->MultiCell($this->posxup - $this->posxtva + 3, 2, $outputlangs->transnoentities(
"VAT"),
'',
'C');
927 $pdf->line($this->posxup - 1, $tab_top, $this->posxup - 1, $tab_top + $tab_height);
928 if (empty($hidetop)) {
929 $pdf->SetXY($this->posxup - 1, $tab_top + 1);
930 $pdf->MultiCell($this->posxqty - $this->posxup - 1, 2, $outputlangs->transnoentities(
"PriceUHT"),
'',
'C');
933 $pdf->line($this->posxqty - 1, $tab_top, $this->posxqty - 1, $tab_top + $tab_height);
934 if (empty($hidetop)) {
935 $pdf->SetXY($this->posxqty - 1, $tab_top + 1);
936 $pdf->MultiCell($this->posxunit - $this->posxqty - 1, 2, $outputlangs->transnoentities(
"Qty"),
'',
'C');
939 if (!empty($conf->global->PRODUCT_USE_UNITS)) {
940 $pdf->line($this->posxunit - 1, $tab_top, $this->posxunit - 1, $tab_top + $tab_height);
941 if (empty($hidetop)) {
942 $pdf->SetXY($this->posxunit - 1, $tab_top + 1);
944 $this->posxdiscount - $this->posxunit - 1,
946 $outputlangs->transnoentities(
"Unit"),
953 if ($this->atleastonediscount) {
954 $pdf->line($this->posxdiscount - 1, $tab_top, $this->posxdiscount - 1, $tab_top + $tab_height);
955 if (empty($hidetop)) {
956 $pdf->SetXY($this->posxdiscount - 1, $tab_top + 1);
957 $pdf->MultiCell($this->postotalht - $this->posxdiscount + 1, 2, $outputlangs->transnoentities(
"ReductionShort"),
'',
'C');
961 $pdf->line($this->postotalht, $tab_top, $this->postotalht, $tab_top + $tab_height);
962 if (empty($hidetop)) {
963 $pdf->SetXY($this->postotalht - 1, $tab_top + 1);
964 $pdf->MultiCell(30, 2, $outputlangs->transnoentities(
"TotalHTShort"),
'',
'C');
986 if ($object->type == 2 && !empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) {
991 $tab3_top = $posy + 8;
994 if ($this->page_largeur < 210) {
1000 $pdf->SetFont(
'',
'', $default_font_size - 3);
1001 $pdf->SetXY($tab3_posx, $tab3_top - 4);
1002 $pdf->MultiCell(60, 3, $outputlangs->transnoentities(
"PaymentsAlreadyDone"), 0,
'L', 0);
1004 $pdf->line($tab3_posx, $tab3_top, $tab3_posx + $tab3_width, $tab3_top);
1006 $pdf->SetFont(
'',
'', $default_font_size - 4);
1007 $pdf->SetXY($tab3_posx, $tab3_top);
1008 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Payment"), 0,
'L', 0);
1009 $pdf->SetXY($tab3_posx + 21, $tab3_top);
1010 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Amount"), 0,
'L', 0);
1011 $pdf->SetXY($tab3_posx + 40, $tab3_top);
1012 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Type"), 0,
'L', 0);
1013 $pdf->SetXY($tab3_posx + 58, $tab3_top);
1014 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Num"), 0,
'L', 0);
1016 $pdf->line($tab3_posx, $tab3_top - 1 + $tab3_height, $tab3_posx + $tab3_width, $tab3_top - 1 + $tab3_height);
1020 $pdf->SetFont(
'',
'', $default_font_size - 4);
1026 $sql =
"SELECT p.datep as date, p.fk_paiement as type, p.num_paiement as num, pf.amount as amount, pf.multicurrency_amount,";
1028 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiementfourn_facturefourn as pf, ".MAIN_DB_PREFIX.
"paiementfourn as p";
1029 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as cp ON p.fk_paiement = cp.id";
1030 $sql .=
" WHERE pf.fk_paiementfourn = p.rowid and pf.fk_facturefourn = ".((int) $object->id);
1031 $sql .=
" ORDER BY p.datep";
1034 $num = $this->
db->num_rows(
$resql);
1038 $row = $this->
db->fetch_object(
$resql);
1040 $pdf->SetXY($tab3_posx, $tab3_top + $y);
1041 $pdf->MultiCell(20, 3,
dol_print_date($this->
db->jdate($row->date),
'day',
false, $outputlangs,
true), 0,
'L', 0);
1042 $pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
1043 $pdf->MultiCell(20, 3,
price($sign * ((
isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) ? $row->multicurrency_amount : $row->amount)), 0,
'L', 0);
1044 $pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
1045 $oper = $outputlangs->transnoentitiesnoconv(
"PaymentTypeShort".$row->code);
1047 $pdf->MultiCell(20, 3, $oper, 0,
'L', 0);
1048 $pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
1049 $pdf->MultiCell(30, 3, $row->num, 0,
'L', 0);
1051 $pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
1056 $this->error = $this->
db->lasterror();
1071 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
1073 global $langs, $conf, $mysoc;
1076 $outputlangs->loadLangs(array(
"main",
"orders",
"companies",
"bills"));
1083 $pdf->SetTextColor(0, 0, 60);
1084 $pdf->SetFont(
'',
'B', $default_font_size + 3);
1086 $posy = $this->marge_haute;
1087 $posx = $this->page_largeur - $this->marge_droite - 100;
1089 $pdf->SetXY($this->marge_gauche, $posy);
1111 $text = $this->emetteur->name;
1112 $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0,
'L');
1115 $pdf->SetFont(
'',
'B', $default_font_size + 3);
1116 $pdf->SetXY($posx, $posy);
1117 $pdf->SetTextColor(0, 0, 60);
1118 $title = $outputlangs->transnoentities(
"PdfInvoiceTitle");
1119 if ($object->type == 1) {
1120 $title = $outputlangs->transnoentities(
"InvoiceReplacement");
1122 if ($object->type == 2) {
1123 $title = $outputlangs->transnoentities(
"InvoiceAvoir");
1125 if ($object->type == 3) {
1126 $title = $outputlangs->transnoentities(
"InvoiceDeposit");
1128 $pdf->MultiCell(100, 3, $title.
" ".$outputlangs->convToOutputCharset($object->ref),
'',
'R');
1131 if ($object->ref_supplier) {
1133 $pdf->SetFont(
'',
'B', $default_font_size);
1134 $pdf->SetXY($posx, $posy);
1135 $pdf->SetTextColor(0, 0, 60);
1136 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"RefSupplier").
" : ".$object->ref_supplier,
'',
'R');
1140 $pdf->SetFont(
'',
'', $default_font_size - 1);
1142 if (!empty($conf->global->PDF_SHOW_PROJECT_TITLE)) {
1143 $object->fetch_projet();
1144 if (!empty($object->project->ref)) {
1146 $pdf->SetXY($posx, $posy);
1147 $pdf->SetTextColor(0, 0, 60);
1148 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Project").
" : ".(empty($object->project->title) ?
'' : $object->project->title),
'',
'R');
1152 if (!empty($conf->global->PDF_SHOW_PROJECT)) {
1153 $object->fetch_projet();
1154 if (!empty($object->project->ref)) {
1155 $outputlangs->load(
"projects");
1157 $pdf->SetXY($posx, $posy);
1158 $langs->load(
"projects");
1159 $pdf->SetTextColor(0, 0, 60);
1160 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"Project").
" : ".(empty($object->project->ref) ?
'' : $object->project->ref),
'',
'R');
1164 if ($object->date) {
1166 $pdf->SetXY($posx, $posy);
1167 $pdf->SetTextColor(0, 0, 60);
1168 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"Date").
" : ".
dol_print_date($object->date,
"day",
false, $outputlangs,
true),
'',
'R');
1171 $pdf->SetXY($posx, $posy);
1172 $pdf->SetTextColor(255, 0, 0);
1173 $pdf->MultiCell(100, 4, strtolower($outputlangs->transnoentities(
"OrderToProcess")),
'',
'R');
1176 if ($object->thirdparty->code_fournisseur) {
1178 $pdf->SetXY($posx, $posy);
1179 $pdf->SetTextColor(0, 0, 60);
1180 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"SupplierCode").
" : ".$outputlangs->transnoentities($object->thirdparty->code_fournisseur),
'',
'R');
1184 $pdf->SetTextColor(0, 0, 60);
1188 $current_y = $pdf->getY();
1189 $posy =
pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3,
'R', $default_font_size);
1190 if ($current_y < $pdf->getY()) {
1191 $top_shift = $pdf->getY() - $current_y;
1196 $carac_emetteur =
'';
1198 $arrayidcontact = $object->getIdContact(
'internal',
'SALESREPFOLL');
1199 if (count($arrayidcontact) > 0) {
1200 $object->fetch_user($arrayidcontact[0]);
1201 $carac_emetteur .= ($carac_emetteur ?
"\n" :
'').$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs)).
"\n";
1204 $carac_emetteur .=
pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty,
'', 0,
'source', $object);
1207 $posy = 42 + $top_shift;
1208 $posx = $this->marge_gauche;
1209 if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
1210 $posx = $this->page_largeur - $this->marge_droite - 80;
1215 $pdf->SetTextColor(0, 0, 0);
1216 $pdf->SetFont(
'',
'', $default_font_size - 2);
1217 $pdf->SetXY($posx, $posy - 5);
1218 $pdf->MultiCell(80, 5, $outputlangs->transnoentities(
"BillFrom"), 0,
'L');
1219 $pdf->SetXY($posx, $posy);
1220 $pdf->SetFillColor(230, 230, 230);
1221 $pdf->MultiCell(82, $hautcadre,
"", 0,
'R', 1);
1222 $pdf->SetTextColor(0, 0, 60);
1225 $pdf->SetXY($posx + 2, $posy + 3);
1226 $pdf->SetFont(
'',
'B', $default_font_size);
1227 $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0,
'L');
1228 $posy = $pdf->getY();
1231 $pdf->SetXY($posx + 2, $posy);
1232 $pdf->SetFont(
'',
'', $default_font_size - 1);
1233 $pdf->MultiCell(80, 4, $carac_emetteur, 0,
'L');
1238 $usecontact =
false;
1239 $arrayidcontact = $object->getIdContact(
'internal',
'BILLING');
1240 if (count($arrayidcontact) > 0) {
1242 $result = $object->fetch_contact($arrayidcontact[0]);
1246 if ($usecontact && ($object->contact->socid != $object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) || !empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)))) {
1247 $thirdparty = $object->contact;
1249 $thirdparty = $mysoc;
1254 $carac_client =
pdf_build_address($outputlangs, $this->emetteur, $mysoc, ((!empty($object->contact)) ? $object->contact :
null), $usecontact,
'target', $object);
1258 if ($this->page_largeur < 210) {
1261 $posy = 42 + $top_shift;
1262 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
1263 if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
1264 $posx = $this->marge_gauche;
1268 $pdf->SetTextColor(0, 0, 0);
1269 $pdf->SetFont(
'',
'', $default_font_size - 2);
1270 $pdf->SetXY($posx + 2, $posy - 5);
1271 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"BillTo"), 0,
'L');
1272 $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
1275 $pdf->SetXY($posx + 2, $posy + 3);
1276 $pdf->SetFont(
'',
'B', $default_font_size);
1277 $pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0,
'L');
1279 $posy = $pdf->getY();
1282 $pdf->SetFont(
'',
'', $default_font_size - 1);
1283 $pdf->SetXY($posx + 2, $posy);
1284 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0,
'L');
1300 protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
1302 $showdetails =
getDolGlobalInt(
'MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
1303 return pdf_pagefoot($pdf, $outputlangs,
'SUPPLIER_INVOICE_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext);