35 require_once DOL_DOCUMENT_ROOT.
'/core/modules/facture/modules_facture.php';
36 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
37 require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
38 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
39 require_once DOL_DOCUMENT_ROOT.
'/core/lib/pdf.lib.php';
65 public $update_main_doc_field;
76 public $phpmin = array(7, 0);
82 public $version =
'dolibarr';
102 public $marge_gauche;
107 public $marge_droite;
128 public $situationinvoice;
133 public $posxprogress;
138 public $categoryOfOperation = -1;
148 global $conf, $langs, $mysoc;
151 $langs->loadLangs(array(
"main",
"bills"));
154 $this->
name =
"crabe";
155 $this->
description = $langs->trans(
'PDFCrabeDescription');
156 $this->update_main_doc_field = 1;
161 $this->page_largeur = $formatarray[
'width'];
162 $this->page_hauteur = $formatarray[
'height'];
163 $this->format = array($this->page_largeur, $this->page_hauteur);
169 $this->option_logo = 1;
170 $this->option_tva = 1;
171 $this->option_modereg = 1;
172 $this->option_condreg = 1;
173 $this->option_multilang = 1;
174 $this->option_escompte = 1;
175 $this->option_credit_note = 1;
176 $this->option_freetext = 1;
177 $this->option_draft_watermark = 1;
178 $this->watermark =
'';
181 $this->emetteur = $mysoc;
182 if (empty($this->emetteur->country_code)) {
183 $this->emetteur->country_code = substr($langs->defaultlang, -2);
187 $this->posxdesc = $this->marge_gauche + 1;
188 if (!empty($conf->global->PRODUCT_USE_UNITS)) {
189 $this->posxtva = 101;
191 $this->posxqty = 135;
192 $this->posxunit = 151;
194 $this->posxtva = 106;
196 $this->posxqty = 145;
197 $this->posxunit = 162;
199 $this->posxprogress = 151;
200 $this->posxdiscount = 162;
201 $this->posxprogress = 174;
202 $this->postotalht = 174;
203 if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) || !empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) {
204 $this->posxtva = $this->posxup;
206 $this->posxpicture = $this->posxtva - (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH) ? 20 : $conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH);
207 if ($this->page_largeur < 210) {
208 $this->posxpicture -= 20;
209 $this->posxtva -= 20;
211 $this->posxqty -= 20;
212 $this->posxunit -= 20;
213 $this->posxdiscount -= 20;
214 $this->posxprogress -= 20;
215 $this->postotalht -= 20;
218 $this->tva = array();
219 $this->tva_array = array();
220 $this->localtax1 = array();
221 $this->localtax2 = array();
222 $this->atleastoneratenotnull = 0;
223 $this->atleastonediscount = 0;
224 $this->situationinvoice =
false;
240 public function write_file($object, $outputlangs, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
243 global $user, $langs, $conf, $mysoc, $hookmanager, $nblines;
245 dol_syslog(
"write_file outputlangs->defaultlang=".(is_object($outputlangs) ? $outputlangs->defaultlang :
'null'));
247 if (!is_object($outputlangs)) {
248 $outputlangs = $langs;
251 if (!empty($conf->global->MAIN_USE_FPDF)) {
252 $outputlangs->charset_output =
'ISO-8859-1';
256 $outputlangs->loadLangs(array(
"main",
"bills",
"products",
"dict",
"companies"));
259 if ($object->statut == $object::STATUS_DRAFT && (!empty($conf->global->FACTURE_DRAFT_WATERMARK))) {
260 $this->watermark = $conf->global->FACTURE_DRAFT_WATERMARK;
263 global $outputlangsbis;
264 $outputlangsbis =
null;
265 if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && $outputlangs->defaultlang != $conf->global->PDF_USE_ALSO_LANGUAGE_CODE) {
266 $outputlangsbis =
new Translate(
'', $conf);
267 $outputlangsbis->setDefaultLang($conf->global->PDF_USE_ALSO_LANGUAGE_CODE);
268 $outputlangsbis->loadLangs(array(
"main",
"bills",
"products",
"dict",
"companies"));
271 $nblines = count($object->lines);
274 $realpatharray = array();
275 if (!empty($conf->global->MAIN_GENERATE_INVOICES_WITH_PICTURE)) {
276 for ($i = 0; $i < $nblines; $i++) {
277 if (empty($object->lines[$i]->fk_product)) {
282 $objphoto->fetch($object->lines[$i]->fk_product);
284 $pdir =
get_exdir($object->lines[$i]->fk_product, 2, 0, 0, $objphoto,
'product').$object->lines[$i]->fk_product.
"/photos/";
285 $dir = $conf->product->dir_output.
'/'.$pdir;
288 foreach ($objphoto->liste_photos($dir, 1) as $key => $obj) {
289 $filename = $obj[
'photo'];
291 $realpath = $dir.$filename;
296 $realpatharray[$i] = $realpath;
300 if (count($realpatharray) == 0) {
301 $this->posxpicture = $this->posxtva;
304 if ($conf->facture->dir_output) {
305 $object->fetch_thirdparty();
307 $deja_regle = $object->getSommePaiement((
isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
308 $amount_credit_notes_included = $object->getSumCreditNotesUsed((
isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
309 $amount_deposits_included = $object->getSumDepositsUsed((
isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
312 if ($object->specimen) {
313 $dir = empty($conf->facture->multidir_output[$object->entity]) ? $conf->facture->dir_output : $conf->facture->multidir_output[$object->entity];
314 $file = $dir.
"/SPECIMEN.pdf";
317 $dir = (empty($conf->facture->multidir_output[$object->entity]) ? $conf->facture->dir_output : $conf->facture->multidir_output[$object->entity]).
"/".$objectref;
318 $file = $dir.
"/".$objectref.
".pdf";
320 if (!file_exists($dir)) {
322 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
327 if (file_exists($dir)) {
329 if (!is_object($hookmanager)) {
330 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
333 $hookmanager->initHooks(array(
'pdfgeneration'));
334 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
336 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters, $object, $action);
339 $nblines = count($object->lines);
340 $nbpayments = count($object->getListOfPayments());
345 $pdf->SetAutoPageBreak(1, 0);
347 $heightforinfotot = 50 + (4 * $nbpayments);
348 if ($heightforinfotot > 220) {
349 $heightforinfotot = 220;
351 $heightforfreetext = (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->MAIN_PDF_FREETEXT_HEIGHT : 5);
352 $heightforfooter = $this->marge_basse + 8;
353 if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS)) {
354 $heightforfooter += 6;
357 if (class_exists(
'TCPDF')) {
358 $pdf->setPrintHeader(
false);
359 $pdf->setPrintFooter(
false);
364 if (!empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) {
365 $logodir = $conf->mycompany->dir_output;
366 if (!empty($conf->mycompany->multidir_output[$object->entity])) {
367 $logodir = $conf->mycompany->multidir_output[$object->entity];
369 $pagecount = $pdf->setSourceFile($logodir.
'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
370 $tplidx = $pdf->importPage(1);
375 $pdf->SetDrawColor(128, 128, 128);
377 $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
378 $pdf->SetSubject($outputlangs->transnoentities(
"PdfInvoiceTitle"));
379 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
380 $pdf->SetAuthor($mysoc->name.($user->id > 0 ?
' - '.$outputlangs->convToOutputCharset($user->getFullName($outputlangs)) :
''));
381 $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref).
" ".$outputlangs->transnoentities(
"PdfInvoiceTitle").
" ".$outputlangs->convToOutputCharset($object->thirdparty->name));
383 $pdf->SetCompression(
false);
387 $cert = empty($user->conf->CERTIFICATE_CRT) ?
'' : $user->conf->CERTIFICATE_CRT;
388 $certprivate = empty($user->conf->CERTIFICATE_CRT_PRIVATE) ?
'' : $user->conf->CERTIFICATE_CRT_PRIVATE;
391 $cert = empty($conf->global->CERTIFICATE_CRT) ?
'' : $conf->global->CERTIFICATE_CRT;
394 $certprivate = empty($conf->global->CERTIFICATE_CRT_PRIVATE) ?
'' : $conf->global->CERTIFICATE_CRT_PRIVATE;
399 'Name' => $this->emetteur->name,
400 'Location' =>
getCountry($this->emetteur->country_code, 0),
401 'Reason' =>
'INVOICE',
402 'ContactInfo' => $this->emetteur->email
404 $pdf->setSignature($cert, $certprivate, $this->emetteur->name,
'', 2, $info);
407 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
411 $categoryOfOperation = 0;
414 for ($i = 0; $i < $nblines; $i++) {
415 if ($object->lines[$i]->remise_percent) {
416 $this->atleastonediscount++;
420 if ($categoryOfOperation < 2) {
421 $lineProductType = $object->lines[$i]->product_type;
427 if ($nbProduct > 0 && $nbService > 0) {
429 $categoryOfOperation = 2;
434 if ($categoryOfOperation <= 0) {
436 if ($nbProduct == 0 && $nbService > 0) {
437 $categoryOfOperation = 1;
440 $this->categoryOfOperation = $categoryOfOperation;
441 if (empty($this->atleastonediscount)) {
442 $delta = ($this->posxprogress - $this->posxdiscount);
443 $this->posxpicture += $delta;
444 $this->posxtva += $delta;
445 $this->posxup += $delta;
446 $this->posxqty += $delta;
447 $this->posxunit += $delta;
448 $this->posxdiscount += $delta;
454 if ($object->situation_cycle_ref && empty($conf->global->MAIN_PDF_HIDE_SITUATION)) {
455 $this->situationinvoice =
true;
456 $progress_width = 10;
457 $this->posxpicture -= $progress_width;
458 $this->posxtva -= $progress_width;
459 $this->posxup -= $progress_width;
460 $this->posxqty -= $progress_width;
461 $this->posxunit -= $progress_width;
462 $this->posxdiscount -= $progress_width;
463 $this->posxprogress -= $progress_width;
468 if (!empty($tplidx)) {
469 $pdf->useTemplate($tplidx);
474 $top_shift = $this->
_pagehead($pdf, $object, 1, $outputlangs);
475 $pdf->SetFont(
'',
'', $default_font_size - 1);
476 $pdf->MultiCell(0, 3,
'');
477 $pdf->SetTextColor(0, 0, 0);
482 $tab_top = 90 + $top_shift;
483 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
486 $extra_under_address_shift = 0;
488 if (!empty($conf->global->INVOICE_ADD_ZATCA_QR_CODE)) {
489 $qrcodestring = $object->buildZATCAQRString();
490 } elseif (!empty($conf->global->INVOICE_ADD_SWISS_QR_CODE)) {
491 $qrcodestring = $object->buildSwitzerlandQRString();
494 $qrcodecolor = array(
'25',
'25',
'25');
499 'fgcolor' => $qrcodecolor,
504 $pdf->write2DBarcode($qrcodestring,
'QRCODE,M', $this->marge_gauche, $tab_top - 5, 25, 25, $styleQr,
'N');
505 $extra_under_address_shift += 25;
513 'outputlangs' => $outputlangs,
514 'hidedetails' => $hidedetails
516 $reshook = $hookmanager->executeHooks(
'printUnderHeaderPDFline', $parameters, $this);
517 if (!empty($hookmanager->resArray[
'extra_under_address_shift'])) {
518 $extra_under_address_shift += $hookmanager->resArray[
'extra_under_header_shift'];
521 $tab_top += $extra_under_address_shift;
522 $tab_top_newpage += 0;
525 $height_incoterms = 0;
527 $desc_incoterms = $object->getIncotermsForPDF();
528 if ($desc_incoterms) {
531 $pdf->SetFont(
'',
'', $default_font_size - 1);
532 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1,
dol_htmlentitiesbr($desc_incoterms), 0, 1);
533 $nexY = $pdf->GetY();
534 $height_incoterms = $nexY - $tab_top;
537 $pdf->SetDrawColor(192, 192, 192);
538 $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_incoterms + 1);
540 $tab_top = $nexY + 6;
545 $notetoshow = empty($object->note_public) ?
'' : $object->note_public;
546 if (!empty($conf->global->MAIN_ADD_SALE_REP_SIGNATURE_IN_NOTE)) {
548 if (is_object($object->thirdparty)) {
549 $salereparray = $object->thirdparty->getSalesRepresentatives($user);
550 $salerepobj =
new User($this->
db);
551 $salerepobj->fetch($salereparray[0][
'id']);
552 if (!empty($salerepobj->signature)) {
553 $notetoshow =
dol_concatdesc($notetoshow, $salerepobj->signature);
558 $extranote = $this->getExtrafieldsInHtml($object, $outputlangs);
559 if (!empty($extranote)) {
571 $pdf->SetFont(
'',
'', $default_font_size - 1);
572 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1,
dol_htmlentitiesbr($notetoshow), 0, 1);
573 $nexY = $pdf->GetY();
574 $height_note = $nexY - $tab_top;
577 $pdf->SetDrawColor(192, 192, 192);
578 $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1);
580 $tab_top = $nexY + 6;
583 $iniY = $tab_top + 7;
584 $curY = $tab_top + 7;
585 $nexY = $tab_top + 7;
588 for ($i = 0; $i < $nblines; $i++) {
590 $pdf->SetFont(
'',
'', $default_font_size - 1);
591 $pdf->SetTextColor(0, 0, 0);
594 $imglinesize = array();
595 if (!empty($realpatharray[$i])) {
599 $pdf->setTopMargin($tab_top_newpage);
600 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext + $heightforinfotot);
601 $pageposbefore = $pdf->getPage();
603 $showpricebeforepagebreak = 1;
605 $posYAfterDescription = 0;
608 if (isset($imglinesize[
'width']) && isset($imglinesize[
'height']) && ($curY + $imglinesize[
'height']) > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
609 $pdf->AddPage(
'',
'',
true);
610 if (!empty($tplidx)) {
611 $pdf->useTemplate($tplidx);
614 $top_shift = $this->
_pagehead($pdf, $object, 0, $outputlangs);
615 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
617 $pdf->setPage($pageposbefore + 1);
619 $curY = $tab_top_newpage;
622 if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
623 $showpricebeforepagebreak = 1;
625 $showpricebeforepagebreak = 0;
629 if (isset($imglinesize[
'width']) && isset($imglinesize[
'height'])) {
630 $curX = $this->posxpicture - 1;
631 $pdf->Image($realpatharray[$i], $curX + (($this->posxtva - $this->posxpicture - $imglinesize[
'width']) / 2), $curY, $imglinesize[
'width'], $imglinesize[
'height'],
'',
'',
'', 2, 300);
633 $posYAfterImage = $curY + $imglinesize[
'height'];
637 $curX = $this->posxdesc - 1;
639 $pdf->startTransaction();
640 pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxpicture - $curX - $progress_width, 3, $curX, $curY, $hideref, $hidedesc);
641 $pageposafter = $pdf->getPage();
642 if ($pageposafter > $pageposbefore) {
643 $pdf->rollbackTransaction(
true);
644 $pageposafter = $pageposbefore;
646 $pdf->setPageOrientation(
'', 1, $heightforfooter);
647 pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxpicture - $curX - $progress_width, 3, $curX, $curY, $hideref, $hidedesc);
648 $pageposafter = $pdf->getPage();
649 $posyafter = $pdf->GetY();
651 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
652 if ($i == ($nblines - 1)) {
653 $pdf->AddPage(
'',
'',
true);
654 if (!empty($tplidx)) {
655 $pdf->useTemplate($tplidx);
658 $top_shift = $this->
_pagehead($pdf, $object, 0, $outputlangs);
659 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
661 $pdf->setPage($pageposafter + 1);
667 if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
668 $showpricebeforepagebreak = 1;
670 $showpricebeforepagebreak = 0;
675 $pdf->commitTransaction();
677 $posYAfterDescription = $pdf->GetY();
679 $nexY = $pdf->GetY();
680 $pageposafter = $pdf->getPage();
681 $pdf->setPage($pageposbefore);
682 $pdf->setTopMargin($this->marge_haute);
683 $pdf->setPageOrientation(
'', 1, 0);
686 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
687 $pdf->setPage($pageposafter);
688 $curY = $tab_top_newpage;
691 $pdf->SetFont(
'',
'', $default_font_size - 1);
694 if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) && empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) {
696 $pdf->SetXY($this->posxtva - 5, $curY);
697 $pdf->MultiCell($this->posxup - $this->posxtva + 4, 3, $vat_rate, 0,
'R');
702 $pdf->SetXY($this->posxup, $curY);
703 $pdf->MultiCell($this->posxqty - $this->posxup - 0.8, 3, $up_excl_tax, 0,
'R', 0);
707 $pdf->SetXY($this->posxqty, $curY);
708 $pdf->MultiCell($this->posxunit - $this->posxqty - 0.8, 4, $qty, 0,
'R');
711 if (!empty($conf->global->PRODUCT_USE_UNITS)) {
712 $unit =
pdf_getlineunit($object, $i, $outputlangs, $hidedetails, $hookmanager);
713 $pdf->SetXY($this->posxunit, $curY);
714 $pdf->MultiCell($this->posxdiscount - $this->posxunit - 0.8, 4, $unit, 0,
'L');
718 if ($object->lines[$i]->remise_percent) {
719 $pdf->SetXY($this->posxdiscount - 2, $curY);
721 $pdf->MultiCell($this->posxprogress - $this->posxdiscount + 2, 3, $remise_percent, 0,
'R');
725 if ($this->situationinvoice) {
727 $pdf->SetXY($this->posxprogress, $curY);
728 $pdf->MultiCell($this->postotalht - $this->posxprogress + 1, 3, $progress, 0,
'R');
733 $pdf->SetXY($this->postotalht, $curY);
734 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->postotalht, 3, $total_excl_tax, 0,
'R', 0);
738 if (isset($object->type) && $object->type == 2 && !empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) {
742 $prev_progress = $object->lines[$i]->get_prev_progress($object->id);
743 if ($prev_progress > 0 && !empty($object->lines[$i]->situation_percent)) {
744 if (
isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) {
745 $tvaligne = $sign * $object->lines[$i]->multicurrency_total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent;
747 $tvaligne = $sign * $object->lines[$i]->total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent;
750 if (
isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) {
751 $tvaligne = $sign * $object->lines[$i]->multicurrency_total_tva;
753 $tvaligne = $sign * $object->lines[$i]->total_tva;
757 $localtax1ligne = $object->lines[$i]->total_localtax1;
758 $localtax2ligne = $object->lines[$i]->total_localtax2;
759 $localtax1_rate = $object->lines[$i]->localtax1_tx;
760 $localtax2_rate = $object->lines[$i]->localtax2_tx;
761 $localtax1_type = $object->lines[$i]->localtax1_type;
762 $localtax2_type = $object->lines[$i]->localtax2_type;
764 if ($object->remise_percent) {
765 $tvaligne -= ($tvaligne * $object->remise_percent) / 100;
767 if ($object->remise_percent) {
768 $localtax1ligne -= ($localtax1ligne * $object->remise_percent) / 100;
770 if ($object->remise_percent) {
771 $localtax2ligne -= ($localtax2ligne * $object->remise_percent) / 100;
774 $vatrate = (string) $object->lines[$i]->tva_tx;
777 if ((!isset($localtax1_type) || $localtax1_type ==
'' || !isset($localtax2_type) || $localtax2_type ==
'')
778 && (!empty($localtax1_rate) || !empty($localtax2_rate))) {
780 $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] :
'';
781 $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] :
'';
785 if ($localtax1_type && $localtax1ligne != 0) {
786 if (empty($this->localtax1[$localtax1_type][$localtax1_rate])) {
787 $this->localtax1[$localtax1_type][$localtax1_rate] = $localtax1ligne;
789 $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
792 if ($localtax2_type && $localtax2ligne != 0) {
793 if (empty($this->localtax2[$localtax2_type][$localtax2_rate])) {
794 $this->localtax2[$localtax2_type][$localtax2_rate] = $localtax2ligne;
796 $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
800 if (($object->lines[$i]->info_bits & 0x01) == 0x01) {
805 if (!isset($this->tva[$vatrate])) {
806 $this->tva[$vatrate] = 0;
808 $this->tva[$vatrate] += $tvaligne;
809 $vatcode = $object->lines[$i]->vat_src_code;
810 if (empty($this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'])) {
811 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] = 0;
813 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')] = array(
'vatrate'=>$vatrate,
'vatcode'=>$vatcode,
'amount'=> $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] + $tvaligne);
815 if ($posYAfterImage > $posYAfterDescription) {
816 $nexY = $posYAfterImage;
820 if (!empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblines - 1)) {
821 $pdf->setPage($pageposafter);
822 $pdf->SetLineStyle(array(
'dash'=>
'1,1',
'color'=>array(80, 80, 80)));
824 $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
825 $pdf->SetLineStyle(array(
'dash'=>0));
831 while ($pagenb < $pageposafter) {
832 $pdf->setPage($pagenb);
834 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
836 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
838 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
840 $pdf->setPage($pagenb);
841 $pdf->setPageOrientation(
'', 1, 0);
843 $top_shift = $this->
_pagehead($pdf, $object, 0, $outputlangs);
844 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
846 if (!empty($tplidx)) {
847 $pdf->useTemplate($tplidx);
850 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
852 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
854 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
856 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
859 if (!empty($tplidx)) {
860 $pdf->useTemplate($tplidx);
864 $top_shift = $this->
_pagehead($pdf, $object, 0, $outputlangs);
865 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
872 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0, $object->multicurrency_code);
873 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
875 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code);
876 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
878 dol_syslog(
"bottomlasttab=".$bottomlasttab.
" this->page_hauteur=".$this->page_hauteur.
" heightforinfotot=".$heightforinfotot.
" heightforfreetext=".$heightforfreetext.
" heightforfooter=".$heightforfooter);
881 $posy = $this->
_tableau_info($pdf, $object, $bottomlasttab, $outputlangs, $outputlangsbis);
884 $posy = $this->
_tableau_tot($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs, $outputlangsbis);
887 if (($deja_regle || $amount_credit_notes_included || $amount_deposits_included) && empty($conf->global->INVOICE_NO_PAYMENT_DETAILS)) {
892 $this->
_pagefoot($pdf, $object, $outputlangs);
893 if (method_exists($pdf,
'AliasNbPages')) {
894 $pdf->AliasNbPages();
899 $pdf->Output($file,
'F');
902 $hookmanager->initHooks(array(
'pdfgeneration'));
903 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
905 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
907 $this->error = $hookmanager->error;
908 $this->errors = $hookmanager->errors;
911 if (!empty($conf->global->MAIN_UMASK)) {
912 @chmod($file, octdec($conf->global->MAIN_UMASK));
915 $this->result = array(
'fullpath'=>$file);
919 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
923 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"FAC_OUTPUTDIR");
947 if ($object->type == 2 && !empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) {
951 $current_page = $pdf->getPage();
953 $tab3_top = $posy + 8;
956 if ($this->page_largeur < 210) {
962 $this->
_tableau_versements_header($pdf, $object, $outputlangs, $default_font_size, $tab3_posx, $tab3_top, $tab3_width, $tab3_height);
966 $pdf->SetFont(
'',
'', $default_font_size - 4);
970 $sql =
"SELECT re.rowid, re.amount_ht, re.multicurrency_amount_ht, re.amount_tva, re.multicurrency_amount_tva, re.amount_ttc, re.multicurrency_amount_ttc,";
971 $sql .=
" re.description, re.fk_facture_source,";
972 $sql .=
" f.type, f.datef";
973 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re, ".MAIN_DB_PREFIX.
"facture as f";
974 $sql .=
" WHERE re.fk_facture_source = f.rowid AND re.fk_facture = ".((int) $object->id);
982 if ($tab3_top + $y >= ($this->page_hauteur - $heightforfooter)) {
985 $pdf->AddPage(
'',
'',
true);
986 if (!empty($tplidx)) {
987 $pdf->useTemplate($tplidx);
990 $top_shift = $this->
_pagehead($pdf, $object, 0, $outputlangs);
991 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
993 $pdf->setPage($current_page);
994 $this->
_tableau_versements_header($pdf, $object, $outputlangs, $default_font_size, $tab3_posx, $tab3_top + $y - 3, $tab3_width, $tab3_height);
997 $obj = $this->
db->fetch_object(
$resql);
999 if ($obj->type == 2) {
1000 $text = $outputlangs->transnoentities(
"CreditNote");
1001 } elseif ($obj->type == 3) {
1002 $text = $outputlangs->transnoentities(
"Deposit");
1003 } elseif ($obj->type == 0) {
1004 $text = $outputlangs->transnoentities(
"ExcessReceived");
1006 $text = $outputlangs->transnoentities(
"UnknownType");
1009 $invoice->fetch($obj->fk_facture_source);
1011 $pdf->SetXY($tab3_posx, $tab3_top + $y);
1012 $pdf->MultiCell(20, 3,
dol_print_date($this->
db->jdate($obj->datef),
'day',
false, $outputlangs,
true), 0,
'L', 0);
1013 $pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
1014 $pdf->MultiCell(20, 3,
price((
isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) ? $obj->multicurrency_amount_ttc : $obj->amount_ttc, 0, $outputlangs), 0,
'L', 0);
1015 $pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
1016 $pdf->MultiCell(20, 3, $text, 0,
'L', 0);
1017 $pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
1018 $pdf->MultiCell(20, 3, $invoice->ref, 0,
'L', 0);
1020 $pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
1025 $this->error = $this->
db->lasterror();
1031 $sql =
"SELECT p.datep as date, p.fk_paiement, p.num_paiement as num, pf.amount as amount, pf.multicurrency_amount,";
1033 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiement_facture as pf, ".MAIN_DB_PREFIX.
"paiement as p";
1034 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as cp ON p.fk_paiement = cp.id";
1035 $sql .=
" WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = ".((int) $object->id);
1037 $sql .=
" ORDER BY p.datep";
1041 $num = $this->
db->num_rows(
$resql);
1045 if ($tab3_top + $y >= ($this->page_hauteur - $heightforfooter)) {
1048 $pdf->AddPage(
'',
'',
true);
1049 if (!empty($tplidx)) {
1050 $pdf->useTemplate($tplidx);
1053 $top_shift = $this->
_pagehead($pdf, $object, 0, $outputlangs);
1054 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
1056 $pdf->setPage($current_page);
1057 $this->
_tableau_versements_header($pdf, $object, $outputlangs, $default_font_size, $tab3_posx, $tab3_top + $y - 3, $tab3_width, $tab3_height);
1060 $row = $this->
db->fetch_object(
$resql);
1062 $pdf->SetXY($tab3_posx, $tab3_top + $y);
1063 $pdf->MultiCell(20, 3,
dol_print_date($this->
db->jdate($row->date),
'day',
false, $outputlangs,
true), 0,
'L', 0);
1064 $pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
1065 $pdf->MultiCell(20, 3,
price($sign * ((
isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) ? $row->multicurrency_amount : $row->amount), 0, $outputlangs), 0,
'L', 0);
1066 $pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
1067 $oper = $outputlangs->transnoentitiesnoconv(
"PaymentTypeShort".$row->code);
1069 $pdf->MultiCell(20, 3, $oper, 0,
'L', 0);
1070 $pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
1071 $pdf->MultiCell(30, 3, $row->num, 0,
'L', 0);
1073 $pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
1078 return $tab3_top + $y + 3;
1080 $this->error = $this->
db->lasterror();
1103 $title = $outputlangs->transnoentities(
"PaymentsAlreadyDone");
1104 if ($object->type == 2) {
1105 $title = $outputlangs->transnoentities(
"PaymentsBackAlreadyDone");
1108 $pdf->SetFont(
'',
'', $default_font_size - 3);
1109 $pdf->SetXY($tab3_posx, $tab3_top - 4);
1110 $pdf->MultiCell(60, 3, $title, 0,
'L', 0);
1112 $pdf->line($tab3_posx, $tab3_top, $tab3_posx + $tab3_width, $tab3_top);
1114 $pdf->SetFont(
'',
'', $default_font_size - 4);
1115 $pdf->SetXY($tab3_posx, $tab3_top);
1116 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Payment"), 0,
'L', 0);
1117 $pdf->SetXY($tab3_posx + 21, $tab3_top);
1118 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Amount"), 0,
'L', 0);
1119 $pdf->SetXY($tab3_posx + 40, $tab3_top);
1120 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Type"), 0,
'L', 0);
1121 $pdf->SetXY($tab3_posx + 58, $tab3_top);
1122 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Num"), 0,
'L', 0);
1124 $pdf->line($tab3_posx, $tab3_top - 1 + $tab3_height, $tab3_posx + $tab3_width, $tab3_top - 1 + $tab3_height);
1139 protected function _tableau_info(&$pdf, $object, $posy, $outputlangs, $outputlangsbis)
1142 global $conf, $mysoc;
1146 $pdf->SetFont(
'',
'', $default_font_size - 1);
1149 if ($this->emetteur->country_code ==
'FR' && empty($mysoc->tva_assuj)) {
1150 $pdf->SetFont(
'',
'B', $default_font_size - 2);
1151 $pdf->SetXY($this->marge_gauche, $posy);
1152 if ($mysoc->forme_juridique_code == 92) {
1153 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"VATIsNotUsedForInvoiceAsso"), 0,
'L', 0);
1155 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"VATIsNotUsedForInvoice"), 0,
'L', 0);
1158 $posy = $pdf->GetY() + 4;
1163 if ($this->page_largeur < 210) {
1168 if ($object->type != 2 && ($object->cond_reglement_code || $object->cond_reglement)) {
1169 $pdf->SetFont(
'',
'B', $default_font_size - 2);
1170 $pdf->SetXY($this->marge_gauche, $posy);
1171 $titre = $outputlangs->transnoentities(
"PaymentConditions").
':';
1172 $pdf->MultiCell(43, 4, $titre, 0,
'L');
1174 $pdf->SetFont(
'',
'', $default_font_size - 2);
1175 $pdf->SetXY($posxval, $posy);
1176 $lib_condition_paiement = $outputlangs->transnoentities(
"PaymentCondition".$object->cond_reglement_code) != (
'PaymentCondition'.$object->cond_reglement_code) ? $outputlangs->transnoentities(
"PaymentCondition".$object->cond_reglement_code) : $outputlangs->convToOutputCharset($object->cond_reglement_doc ? $object->cond_reglement_doc : $object->cond_reglement_label);
1177 $lib_condition_paiement = str_replace(
'\n',
"\n", $lib_condition_paiement);
1178 $pdf->MultiCell(67, 4, $lib_condition_paiement, 0,
'L');
1180 $posy = $pdf->GetY() + 3;
1184 if (
getDolGlobalInt(
'INVOICE_CATEGORY_OF_OPERATION') == 2 && $this->categoryOfOperation >= 0) {
1185 $pdf->SetFont(
'',
'B', $default_font_size - 2);
1186 $pdf->SetXY($this->marge_gauche, $posy);
1187 $categoryOfOperationTitle = $outputlangs->transnoentities(
"MentionCategoryOfOperations").
' : ';
1188 $pdf->MultiCell($posxval - $this->marge_gauche, 4, $categoryOfOperationTitle, 0,
'L');
1190 $pdf->SetFont(
'',
'', $default_font_size - 2);
1191 $pdf->SetXY($posxval, $posy);
1192 $categoryOfOperationLabel = $outputlangs->transnoentities(
"MentionCategoryOfOperations" . $this->categoryOfOperation);
1193 $pdf->MultiCell($posxend - $posxval, 4, $categoryOfOperationLabel, 0,
'L');
1195 $posy = $pdf->GetY() + 3;
1198 if ($object->type != 2) {
1200 if (empty($object->mode_reglement_code)
1201 && empty($conf->global->FACTURE_CHQ_NUMBER)
1203 $this->error = $outputlangs->transnoentities(
"ErrorNoPaiementModeConfigured");
1204 } elseif (($object->mode_reglement_code ==
'CHQ' && empty($conf->global->FACTURE_CHQ_NUMBER) && empty($object->fk_account) && empty($object->fk_bank))
1205 || ($object->mode_reglement_code ==
'VIR' && !
getDolGlobalInt(
'FACTURE_RIB_NUMBER') && empty($object->fk_account) && empty($object->fk_bank))) {
1207 $outputlangs->load(
"errors");
1209 $pdf->SetXY($this->marge_gauche, $posy);
1210 $pdf->SetTextColor(200, 0, 0);
1211 $pdf->SetFont(
'',
'B', $default_font_size - 2);
1212 $this->error = $outputlangs->transnoentities(
"ErrorPaymentModeDefinedToWithoutSetup", $object->mode_reglement_code);
1213 $pdf->MultiCell(80, 3, $this->error, 0,
'L', 0);
1214 $pdf->SetTextColor(0, 0, 0);
1216 $posy = $pdf->GetY() + 1;
1220 if (!empty($object->mode_reglement_code)
1221 && $object->mode_reglement_code !=
'CHQ'
1222 && $object->mode_reglement_code !=
'VIR') {
1223 $pdf->SetFont(
'',
'B', $default_font_size - 2);
1224 $pdf->SetXY($this->marge_gauche, $posy);
1225 $titre = $outputlangs->transnoentities(
"PaymentMode").
':';
1226 $pdf->MultiCell(80, 5, $titre, 0,
'L');
1228 $pdf->SetFont(
'',
'', $default_font_size - 2);
1229 $pdf->SetXY($posxval, $posy);
1230 $lib_mode_reg = $outputlangs->transnoentities(
"PaymentType".$object->mode_reglement_code) != (
'PaymentType'.$object->mode_reglement_code) ? $outputlangs->transnoentities(
"PaymentType".$object->mode_reglement_code) : $outputlangs->convToOutputCharset($object->mode_reglement);
1232 if ($object->mode_reglement_code ==
"PRE") {
1233 require_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
1235 $bac->fetch(0, $object->thirdparty->id);
1236 $iban= $bac->iban.(($bac->iban && $bac->bic) ?
' / ' :
'').$bac->bic;
1237 $lib_mode_reg .= $outputlangs->trans(
"PaymentTypePREdetails",
dol_trunc($iban, 6,
'right',
'UTF-8', 1));
1239 $pdf->MultiCell(80, 5, $lib_mode_reg, 0,
'L');
1241 $posy = $pdf->GetY();
1247 if ($this->emetteur->country_code ==
'FR') {
1248 if (isset($conf->global->TAX_MODE) && $conf->global->TAX_MODE == 1) {
1249 $pdf->SetXY($this->marge_gauche, $posy);
1250 $pdf->writeHTMLCell(80, 5,
'',
'', $outputlangs->transnoentities(
"MentionVATDebitOptionIsOn"), 0, 1);
1252 $posy = $pdf->GetY() + 1;
1257 if (empty($object->mode_reglement_code) || $object->mode_reglement_code ==
'CB' || $object->mode_reglement_code ==
'VAD') {
1258 $useonlinepayment = 0;
1259 if (!empty($conf->global->PDF_SHOW_LINK_TO_ONLINE_PAYMENT)) {
1261 $useonlinepayment++;
1264 $useonlinepayment++;
1267 $useonlinepayment++;
1272 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
1275 $langs->loadLangs(array(
'payment',
'paybox',
'stripe'));
1276 $servicename = $langs->transnoentities(
'Online');
1277 $paiement_url = getOnlinePaymentUrl(
'',
'invoice', $object->ref,
'',
'',
'');
1278 $linktopay = $langs->trans(
"ToOfferALinkForOnlinePayment", $servicename).
' <a href="'.$paiement_url.
'">'.$outputlangs->transnoentities(
"ClickHere").
'</a>';
1280 $pdf->SetXY($this->marge_gauche, $posy);
1283 $posy = $pdf->GetY() + 1;
1288 if (empty($object->mode_reglement_code) || $object->mode_reglement_code ==
'CHQ') {
1290 if (!empty($conf->global->FACTURE_CHQ_NUMBER)) {
1291 $diffsizetitle = (empty($conf->global->PDF_DIFFSIZE_TITLE) ? 3 : $conf->global->PDF_DIFFSIZE_TITLE);
1293 if ($conf->global->FACTURE_CHQ_NUMBER > 0) {
1295 $account->fetch($conf->global->FACTURE_CHQ_NUMBER);
1297 $pdf->SetXY($this->marge_gauche, $posy);
1298 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1299 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
'PaymentByChequeOrderedTo', $account->proprio), 0,
'L', 0);
1300 $posy = $pdf->GetY() + 1;
1302 if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS)) {
1303 $pdf->SetXY($this->marge_gauche, $posy);
1304 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1305 $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($account->owner_address), 0,
'L', 0);
1306 $posy = $pdf->GetY() + 2;
1309 if ($conf->global->FACTURE_CHQ_NUMBER == -1) {
1310 $pdf->SetXY($this->marge_gauche, $posy);
1311 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1312 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
'PaymentByChequeOrderedTo', $this->emetteur->name), 0,
'L', 0);
1313 $posy = $pdf->GetY() + 1;
1315 if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS)) {
1316 $pdf->SetXY($this->marge_gauche, $posy);
1317 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1318 $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0,
'L', 0);
1319 $posy = $pdf->GetY() + 2;
1326 if (empty($object->mode_reglement_code) || $object->mode_reglement_code ==
'VIR') {
1327 if ($object->fk_account > 0 || $object->fk_bank > 0 ||
getDolGlobalInt(
'FACTURE_RIB_NUMBER')) {
1328 $bankid = ($object->fk_account <= 0 ? $conf->global->FACTURE_RIB_NUMBER : $object->fk_account);
1329 if ($object->fk_bank > 0) {
1330 $bankid = $object->fk_bank;
1333 $account->fetch($bankid);
1335 $curx = $this->marge_gauche;
1338 $posy =
pdf_bank($pdf, $outputlangs, $curx, $cury, $account, 0, $default_font_size);
1362 protected function _tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs, $outputlangsbis)
1365 global $conf, $mysoc, $hookmanager;
1368 if ($object->type == 2 && !empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) {
1374 $outputlangsbis =
null;
1375 if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && $outputlangs->defaultlang != $conf->global->PDF_USE_ALSO_LANGUAGE_CODE) {
1376 $outputlangsbis =
new Translate(
'', $conf);
1377 $outputlangsbis->setDefaultLang($conf->global->PDF_USE_ALSO_LANGUAGE_CODE);
1378 $outputlangsbis->loadLangs(array(
"main",
"dict",
"companies",
"bills",
"products",
"propal"));
1379 $default_font_size--;
1384 $pdf->SetFont(
'',
'', $default_font_size - 1);
1389 if ($this->page_largeur < 210) {
1393 $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
1399 $pdf->SetFillColor(255, 255, 255);
1400 $pdf->SetXY($col1x, $tab2_top + 0);
1401 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) ?
"TotalHT" :
"Total").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) ?
"TotalHT" :
"Total") :
''), 0,
'L', 1);
1403 $total_ht = ((
isModEnabled(
"multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ht : $object->total_ht);
1404 $pdf->SetXY($col2x, $tab2_top + 0);
1405 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * ($total_ht + (!empty($object->remise) ? $object->remise : 0)), 0, $outputlangs), 0,
'R', 1);
1408 $pdf->SetFillColor(248, 248, 248);
1410 $total_ttc = (
isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ttc : $object->total_ttc;
1412 $this->atleastoneratenotnull = 0;
1413 if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) {
1414 $tvaisnull = ((!empty($this->tva) && count($this->tva) == 1 && isset($this->tva[
'0.000']) && is_float($this->tva[
'0.000'])) ?
true :
false);
1415 if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL) && $tvaisnull) {
1423 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1424 if (in_array((
string) $localtax_type, array(
'1',
'3',
'5'))) {
1428 foreach ($localtax_rate as $tvakey => $tvaval) {
1433 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1436 if (preg_match(
'/\*/', $tvakey)) {
1437 $tvakey = str_replace(
'*',
'', $tvakey);
1438 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1441 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT1", $mysoc->country_code) :
'');
1443 $totalvat .=
vatrate(abs($tvakey), 1).$tvacompl;
1444 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1446 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1447 $pdf->MultiCell($largcol2, $tab2_hl,
price($tvaval, 0, $outputlangs), 0,
'R', 1);
1455 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1456 if (in_array((
string) $localtax_type, array(
'1',
'3',
'5'))) {
1460 foreach ($localtax_rate as $tvakey => $tvaval) {
1465 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1468 if (preg_match(
'/\*/', $tvakey)) {
1469 $tvakey = str_replace(
'*',
'', $tvakey);
1470 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1472 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT2", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT2", $mysoc->country_code) :
'');
1474 $totalvat .=
vatrate(abs($tvakey), 1).$tvacompl;
1475 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1477 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1478 $pdf->MultiCell($largcol2, $tab2_hl,
price($tvaval, 0, $outputlangs), 0,
'R', 1);
1486 foreach ($this->tva_array as $tvakey => $tvaval) {
1488 $this->atleastoneratenotnull++;
1491 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1494 if (preg_match(
'/\*/', $tvakey)) {
1495 $tvakey = str_replace(
'*',
'', $tvakey);
1496 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1498 $totalvat = $outputlangs->transcountrynoentities(
"TotalVAT", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalVAT", $mysoc->country_code) :
'');
1501 $totalvat .=
vatrate($tvaval[
'vatrate'], 1).$tvacompl;
1503 $totalvat .= $tvaval[
'vatcode'].$tvacompl;
1505 $totalvat .=
vatrate($tvaval[
'vatrate'], 1).($tvaval[
'vatcode'] ?
' ('.$tvaval[
'vatcode'].
')' :
'').$tvacompl;
1507 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1509 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1510 $pdf->MultiCell($largcol2, $tab2_hl,
price(
price2num($tvaval[
'amount'],
'MT'), 0, $outputlangs), 0,
'R', 1);
1517 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1518 if (in_array((
string) $localtax_type, array(
'2',
'4',
'6'))) {
1522 foreach ($localtax_rate as $tvakey => $tvaval) {
1527 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1530 if (preg_match(
'/\*/', $tvakey)) {
1531 $tvakey = str_replace(
'*',
'', $tvakey);
1532 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1534 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1", $mysoc->country_code).
' ';
1535 $totalvat .=
vatrate(abs($tvakey), 1).$tvacompl;
1537 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1538 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1539 $pdf->MultiCell($largcol2, $tab2_hl,
price($tvaval, 0, $outputlangs), 0,
'R', 1);
1547 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1548 if (in_array((
string) $localtax_type, array(
'2',
'4',
'6'))) {
1552 foreach ($localtax_rate as $tvakey => $tvaval) {
1556 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1559 if (preg_match(
'/\*/', $tvakey)) {
1560 $tvakey = str_replace(
'*',
'', $tvakey);
1561 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1563 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT2", $mysoc->country_code).
' ';
1565 $totalvat .=
vatrate(abs($tvakey), 1).$tvacompl;
1566 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1568 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1569 $pdf->MultiCell($largcol2, $tab2_hl,
price($tvaval, 0, $outputlangs), 0,
'R', 1);
1575 if (
price2num($object->revenuestamp) != 0) {
1577 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1578 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"RevenueStamp"), $useborder,
'L', 1);
1580 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1581 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * $object->revenuestamp), $useborder,
'R', 1);
1586 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1587 $pdf->SetTextColor(0, 0, 60);
1588 $pdf->SetFillColor(224, 224, 224);
1589 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalTTC"), $useborder,
'L', 1);
1591 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1592 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * $total_ttc, 0, $outputlangs), $useborder,
'R', 1);
1595 if ($object->displayRetainedWarranty()) {
1596 $pdf->SetTextColor(40, 40, 40);
1597 $pdf->SetFillColor(255, 255, 255);
1599 $retainedWarranty = $object->getRetainedWarrantyAmount();
1600 $billedWithRetainedWarranty = $object->total_ttc - $retainedWarranty;
1604 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1605 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"ToPayOn",
dol_print_date($object->date_lim_reglement,
'day')), $useborder,
'L', 1);
1607 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1608 $pdf->MultiCell($largcol2, $tab2_hl,
price($billedWithRetainedWarranty), $useborder,
'R', 1);
1612 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1614 $retainedWarrantyToPayOn = $outputlangs->transnoentities(
"RetainedWarranty").
' ('.$object->retained_warranty.
'%)';
1615 $retainedWarrantyToPayOn .= !empty($object->retained_warranty_date_limit) ?
' '.$outputlangs->transnoentities(
"toPayOn",
dol_print_date($object->retained_warranty_date_limit,
'day')) :
'';
1617 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $retainedWarrantyToPayOn, $useborder,
'L', 1);
1618 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1619 $pdf->MultiCell($largcol2, $tab2_hl,
price($retainedWarranty), $useborder,
'R', 1);
1624 $pdf->SetTextColor(0, 0, 0);
1625 $creditnoteamount = $object->getSumCreditNotesUsed((
isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
1626 $depositsamount = $object->getSumDepositsUsed((
isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
1628 $resteapayer =
price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount,
'MT');
1629 if (!empty($object->paye)) {
1633 if (($deja_regle > 0 || $creditnoteamount > 0 || $depositsamount > 0) && empty($conf->global->INVOICE_NO_PAYMENT_DETAILS)) {
1636 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1637 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"Paid"), 0,
'L', 0);
1638 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1639 $pdf->MultiCell($largcol2, $tab2_hl,
price($deja_regle + $depositsamount, 0, $outputlangs), 0,
'R', 0);
1642 if ($creditnoteamount) {
1643 $labeltouse = ($outputlangs->transnoentities(
"CreditNotesOrExcessReceived") !=
"CreditNotesOrExcessReceived") ? $outputlangs->transnoentities(
"CreditNotesOrExcessReceived") : $outputlangs->transnoentities(
"CreditNotes");
1645 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1646 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $labeltouse, 0,
'L', 0);
1647 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1648 $pdf->MultiCell($largcol2, $tab2_hl,
price($creditnoteamount, 0, $outputlangs), 0,
'R', 0);
1652 if ($object->close_code == Facture::CLOSECODE_DISCOUNTVAT) {
1654 $pdf->SetFillColor(255, 255, 255);
1656 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1657 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"EscompteOfferedShort"), $useborder,
'L', 1);
1658 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1659 $pdf->MultiCell($largcol2, $tab2_hl,
price($object->total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 0, $outputlangs), $useborder,
'R', 1);
1665 $pdf->SetTextColor(0, 0, 60);
1666 $pdf->SetFillColor(224, 224, 224);
1667 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1668 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"RemainderToPay"), $useborder,
'L', 1);
1669 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1670 $pdf->MultiCell($largcol2, $tab2_hl,
price($resteapayer, 0, $outputlangs), $useborder,
'R', 1);
1672 $pdf->SetFont(
'',
'', $default_font_size - 1);
1673 $pdf->SetTextColor(0, 0, 0);
1677 return ($tab2_top + ($tab2_hl * $index));
1694 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency =
'')
1704 $currency = !empty($currency) ? $currency : $conf->currency;
1708 $pdf->SetTextColor(0, 0, 0);
1709 $pdf->SetFont(
'',
'', $default_font_size - 2);
1711 if (empty($hidetop)) {
1713 if (
getDolGlobalInt(
'INVOICE_CATEGORY_OF_OPERATION') == 1 && $this->categoryOfOperation >= 0) {
1714 $categoryOfOperations = $outputlangs->transnoentities(
"MentionCategoryOfOperations") .
' : ' . $outputlangs->transnoentities(
"MentionCategoryOfOperations" . $this->categoryOfOperation);
1715 $pdf->SetXY($this->marge_gauche, $tab_top - 4);
1716 $pdf->MultiCell(($pdf->GetStringWidth($categoryOfOperations)) + 4, 2, $categoryOfOperations);
1719 $titre = $outputlangs->transnoentities(
"AmountInCurrency", $outputlangs->transnoentitiesnoconv(
"Currency".$currency));
1720 $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
1721 $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
1724 if (!empty($conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)) {
1725 $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));
1729 $pdf->SetDrawColor(128, 128, 128);
1730 $pdf->SetFont(
'',
'', $default_font_size - 1);
1733 $this->
printRect($pdf, $this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $tab_height, $hidetop, $hidebottom);
1735 if (empty($hidetop)) {
1736 $pdf->line($this->marge_gauche, $tab_top + 5, $this->page_largeur - $this->marge_droite, $tab_top + 5);
1738 $pdf->SetXY($this->posxdesc - 1, $tab_top + 1);
1739 $pdf->MultiCell(108, 2, $outputlangs->transnoentities(
"Designation"),
'',
'L');
1742 if (!empty($conf->global->MAIN_GENERATE_INVOICES_WITH_PICTURE)) {
1743 $pdf->line($this->posxpicture - 1, $tab_top, $this->posxpicture - 1, $tab_top + $tab_height);
1744 if (empty($hidetop)) {
1750 if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) && empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) {
1751 $pdf->line($this->posxtva - 1, $tab_top, $this->posxtva - 1, $tab_top + $tab_height);
1752 if (empty($hidetop)) {
1753 $pdf->SetXY($this->posxtva - 3, $tab_top + 1);
1754 $pdf->MultiCell($this->posxup - $this->posxtva + 3, 2, $outputlangs->transnoentities(
"VAT"),
'',
'C');
1758 $pdf->line($this->posxup - 1, $tab_top, $this->posxup - 1, $tab_top + $tab_height);
1759 if (empty($hidetop)) {
1760 $pdf->SetXY($this->posxup - 1, $tab_top + 1);
1761 $pdf->MultiCell($this->posxqty - $this->posxup - 1, 2, $outputlangs->transnoentities(
"PriceUHT"),
'',
'C');
1764 $pdf->line($this->posxqty - 1, $tab_top, $this->posxqty - 1, $tab_top + $tab_height);
1765 if (empty($hidetop)) {
1766 $pdf->SetXY($this->posxqty - 1, $tab_top + 1);
1767 $pdf->MultiCell($this->posxunit - $this->posxqty - 1, 2, $outputlangs->transnoentities(
"Qty"),
'',
'C');
1770 if (!empty($conf->global->PRODUCT_USE_UNITS)) {
1771 $pdf->line($this->posxunit - 1, $tab_top, $this->posxunit - 1, $tab_top + $tab_height);
1772 if (empty($hidetop)) {
1773 $pdf->SetXY($this->posxunit - 1, $tab_top + 1);
1774 $pdf->MultiCell($this->posxdiscount - $this->posxunit - 1, 2, $outputlangs->transnoentities(
"Unit"),
'',
'C');
1778 if ($this->atleastonediscount) {
1779 $pdf->line($this->posxdiscount - 1, $tab_top, $this->posxdiscount - 1, $tab_top + $tab_height);
1780 if (empty($hidetop)) {
1781 $pdf->SetXY($this->posxdiscount - 1, $tab_top + 1);
1782 $pdf->MultiCell($this->posxprogress - $this->posxdiscount + 1, 2, $outputlangs->transnoentities(
"ReductionShort"),
'',
'C');
1786 if ($this->situationinvoice) {
1787 $pdf->line($this->posxprogress - 1, $tab_top, $this->posxprogress - 1, $tab_top + $tab_height);
1788 if (empty($hidetop)) {
1789 $pdf->SetXY($this->posxprogress, $tab_top + 1);
1790 $pdf->MultiCell($this->postotalht - $this->posxprogress, 2, $outputlangs->transnoentities(
"ProgressShort"),
'',
'C');
1794 $pdf->line($this->postotalht, $tab_top, $this->postotalht, $tab_top + $tab_height);
1795 if (empty($hidetop)) {
1796 $pdf->SetXY($this->postotalht - 1, $tab_top + 1);
1797 $pdf->MultiCell(30, 2, $outputlangs->transnoentities(
"TotalHTShort"),
'',
'C');
1812 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $outputlangsbis =
null)
1814 global $conf, $langs;
1816 $ltrdirection =
'L';
1817 if ($outputlangs->trans(
"DIRECTION") ==
'rtl') $ltrdirection =
'R';
1820 $outputlangs->loadLangs(array(
"main",
"bills",
"propal",
"companies"));
1826 $pdf->SetTextColor(0, 0, 60);
1827 $pdf->SetFont(
'',
'B', $default_font_size + 3);
1831 $posy = $this->marge_haute;
1832 $posx = $this->page_largeur - $this->marge_droite - $w;
1834 $pdf->SetXY($this->marge_gauche, $posy);
1837 if (empty($conf->global->PDF_DISABLE_MYCOMPANY_LOGO)) {
1838 if ($this->emetteur->logo) {
1839 $logodir = $conf->mycompany->dir_output;
1840 if (!empty($conf->mycompany->multidir_output[$object->entity])) {
1841 $logodir = $conf->mycompany->multidir_output[$object->entity];
1843 if (empty($conf->global->MAIN_PDF_USE_LARGE_LOGO)) {
1844 $logo = $logodir.
'/logos/thumbs/'.$this->emetteur->logo_small;
1846 $logo = $logodir.
'/logos/'.$this->emetteur->logo;
1848 if (is_readable($logo)) {
1850 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
1852 $pdf->SetTextColor(200, 0, 0);
1853 $pdf->SetFont(
'',
'B', $default_font_size - 2);
1854 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
1855 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorGoToGlobalSetup"), 0,
'L');
1858 $text = $this->emetteur->name;
1859 $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, $ltrdirection);
1863 $pdf->SetFont(
'',
'B', $default_font_size + 3);
1864 $pdf->SetXY($posx, $posy);
1865 $pdf->SetTextColor(0, 0, 60);
1866 $title = $outputlangs->transnoentities(
"PdfInvoiceTitle");
1867 if ($object->type == 1) {
1868 $title = $outputlangs->transnoentities(
"InvoiceReplacement");
1870 if ($object->type == 2) {
1871 $title = $outputlangs->transnoentities(
"InvoiceAvoir");
1873 if ($object->type == 3) {
1874 $title = $outputlangs->transnoentities(
"InvoiceDeposit");
1876 if ($object->type == 4) {
1877 $title = $outputlangs->transnoentities(
"InvoiceProForma");
1879 if ($this->situationinvoice) {
1880 $title = $outputlangs->transnoentities(
"PDFInvoiceSituation");
1882 if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) {
1884 if ($object->type == 0) {
1885 if ($this->situationinvoice) {
1886 $title .= $outputlangsbis->transnoentities(
"PDFInvoiceSituation");
1888 $title .= $outputlangsbis->transnoentities(
"PdfInvoiceTitle");
1889 } elseif ($object->type == 1) {
1890 $title .= $outputlangsbis->transnoentities(
"InvoiceReplacement");
1891 } elseif ($object->type == 2) {
1892 $title .= $outputlangsbis->transnoentities(
"InvoiceAvoir");
1893 } elseif ($object->type == 3) {
1894 $title .= $outputlangsbis->transnoentities(
"InvoiceDeposit");
1895 } elseif ($object->type == 4) {
1896 $title .= $outputlangsbis->transnoentities(
"InvoiceProForma");
1899 $title .=
' '.$outputlangs->convToOutputCharset($object->ref);
1900 if ($object->statut == $object::STATUS_DRAFT) {
1901 $pdf->SetTextColor(128, 0, 0);
1902 $title .=
' - '.$outputlangs->transnoentities(
"NotValidated");
1905 $pdf->MultiCell($w, 3, $title,
'',
'R');
1907 $pdf->SetFont(
'',
'B', $default_font_size);
1921 $pdf->SetFont(
'',
'', $default_font_size - 2);
1923 if ($object->ref_client) {
1925 $pdf->SetXY($posx, $posy);
1926 $pdf->SetTextColor(0, 0, 60);
1927 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefCustomer").
" : ".$outputlangs->convToOutputCharset($object->ref_client),
'',
'R');
1930 if (!empty($conf->global->PDF_SHOW_PROJECT_TITLE)) {
1931 $object->fetch_projet();
1932 if (!empty($object->project->ref)) {
1934 $pdf->SetXY($posx, $posy);
1935 $pdf->SetTextColor(0, 0, 60);
1936 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Project").
" : ".(empty($object->project->title) ?
'' : $object->project->title),
'',
'R');
1940 if (!empty($conf->global->PDF_SHOW_PROJECT)) {
1941 $object->fetch_projet();
1942 if (!empty($object->project->ref)) {
1943 $outputlangs->load(
"projects");
1945 $pdf->SetXY($posx, $posy);
1946 $pdf->SetTextColor(0, 0, 60);
1947 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefProject").
" : ".(empty($object->project->ref) ?
'' : $object->project->ref),
'',
'R');
1951 $objectidnext = $object->getIdReplacingInvoice(
'validated');
1952 if ($object->type == 0 && $objectidnext) {
1953 $objectreplacing =
new Facture($this->
db);
1954 $objectreplacing->fetch($objectidnext);
1957 $pdf->SetXY($posx, $posy);
1958 $pdf->SetTextColor(0, 0, 60);
1959 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ReplacementByInvoice").
' : '.$outputlangs->convToOutputCharset($objectreplacing->ref),
'',
'R');
1961 if ($object->type == 1) {
1962 $objectreplaced =
new Facture($this->
db);
1963 $objectreplaced->fetch($object->fk_facture_source);
1966 $pdf->SetXY($posx, $posy);
1967 $pdf->SetTextColor(0, 0, 60);
1968 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ReplacementInvoice").
' : '.$outputlangs->convToOutputCharset($objectreplaced->ref),
'',
'R');
1970 if ($object->type == 2 && !empty($object->fk_facture_source)) {
1971 $objectreplaced =
new Facture($this->
db);
1972 $objectreplaced->fetch($object->fk_facture_source);
1975 $pdf->SetXY($posx, $posy);
1976 $pdf->SetTextColor(0, 0, 60);
1977 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CorrectionInvoice").
' : '.$outputlangs->convToOutputCharset($objectreplaced->ref),
'',
'R');
1981 $pdf->SetXY($posx, $posy);
1982 $pdf->SetTextColor(0, 0, 60);
1983 $title = $outputlangs->transnoentities(
"DateInvoice");
1984 if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) {
1985 $title .=
' - '.$outputlangsbis->transnoentities(
"DateInvoice");
1987 $pdf->MultiCell($w, 3, $title.
" : ".
dol_print_date($object->date,
"day",
false, $outputlangs,
true),
'',
'R');
1989 if (!empty($conf->global->INVOICE_POINTOFTAX_DATE)) {
1991 $pdf->SetXY($posx, $posy);
1992 $pdf->SetTextColor(0, 0, 60);
1993 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"DatePointOfTax").
" : ".
dol_print_date($object->date_pointoftax,
"day",
false, $outputlangs),
'',
'R');
1996 if ($object->type != 2) {
1998 $pdf->SetXY($posx, $posy);
1999 $pdf->SetTextColor(0, 0, 60);
2000 $title = $outputlangs->transnoentities(
"DateDue");
2001 if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) {
2002 $title .=
' - '.$outputlangsbis->transnoentities(
"DateDue");
2004 $pdf->MultiCell($w, 3, $title.
" : ".
dol_print_date($object->date_lim_reglement,
"day",
false, $outputlangs,
true),
'',
'R');
2007 if (empty($conf->global->MAIN_PDF_HIDE_CUSTOMER_CODE) && $object->thirdparty->code_client) {
2009 $pdf->SetXY($posx, $posy);
2010 $pdf->SetTextColor(0, 0, 60);
2011 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CustomerCode").
" : ".$outputlangs->transnoentities($object->thirdparty->code_client),
'',
'R');
2015 if (!empty($conf->global->DOC_SHOW_FIRST_SALES_REP)) {
2016 $arrayidcontact = $object->getIdContact(
'internal',
'SALESREPFOLL');
2017 if (count($arrayidcontact) > 0) {
2018 $usertmp =
new User($this->
db);
2019 $usertmp->fetch($arrayidcontact[0]);
2021 $pdf->SetXY($posx, $posy);
2022 $pdf->SetTextColor(0, 0, 60);
2023 $pdf->MultiCell($w, 3, $langs->transnoentities(
"SalesRepresentative").
" : ".$usertmp->getFullName($langs),
'',
'R');
2031 $current_y = $pdf->getY();
2032 $posy =
pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, $w, 3,
'R', $default_font_size);
2033 if ($current_y < $pdf->getY()) {
2034 $top_shift = $pdf->getY() - $current_y;
2039 $carac_emetteur =
pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty,
'', 0,
'source', $object);
2042 $posy = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
2043 $posy += $top_shift;
2044 $posx = $this->marge_gauche;
2045 if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
2046 $posx = $this->page_largeur - $this->marge_droite - 80;
2049 $hautcadre = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 38 : 40;
2050 $widthrecbox = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 82;
2054 if (empty($conf->global->MAIN_PDF_NO_SENDER_FRAME)) {
2055 $pdf->SetTextColor(0, 0, 0);
2056 $pdf->SetFont(
'',
'', $default_font_size - 2);
2057 $pdf->SetXY($posx, $posy - 5);
2058 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"BillFrom"), 0, $ltrdirection);
2059 $pdf->SetXY($posx, $posy);
2060 $pdf->SetFillColor(230, 230, 230);
2061 $pdf->MultiCell($widthrecbox, $hautcadre,
"", 0,
'R', 1);
2062 $pdf->SetTextColor(0, 0, 60);
2066 if (empty($conf->global->MAIN_PDF_HIDE_SENDER_NAME)) {
2067 $pdf->SetXY($posx + 2, $posy + 3);
2068 $pdf->SetFont(
'',
'B', $default_font_size);
2069 $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, $ltrdirection);
2070 $posy = $pdf->getY();
2074 $pdf->SetXY($posx + 2, $posy);
2075 $pdf->SetFont(
'',
'', $default_font_size - 1);
2076 $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0, $ltrdirection);
2080 $usecontact =
false;
2081 $arrayidcontact = $object->getIdContact(
'external',
'BILLING');
2082 if (count($arrayidcontact) > 0) {
2084 $result = $object->fetch_contact($arrayidcontact[0]);
2088 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)))) {
2089 $thirdparty = $object->contact;
2091 $thirdparty = $object->thirdparty;
2097 $carac_client =
pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ($usecontact ? $object->contact :
''), $usecontact, $mode, $object);
2100 $widthrecbox = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 100;
2101 if ($this->page_largeur < 210) {
2104 $posy = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
2105 $posy += $top_shift;
2106 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
2107 if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
2108 $posx = $this->marge_gauche;
2112 if (empty($conf->global->MAIN_PDF_NO_RECIPENT_FRAME)) {
2113 $pdf->SetTextColor(0, 0, 0);
2114 $pdf->SetFont(
'',
'', $default_font_size - 2);
2115 $pdf->SetXY($posx + 2, $posy - 5);
2116 $pdf->MultiCell($widthrecbox - 2, 5, $outputlangs->transnoentities(
"BillTo"), 0, $ltrdirection);
2117 $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
2121 $pdf->SetXY($posx + 2, $posy + 3);
2122 $pdf->SetFont(
'',
'B', $default_font_size);
2123 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name, 0, $ltrdirection);
2125 $posy = $pdf->getY();
2128 $pdf->SetFont(
'',
'', $default_font_size - 1);
2129 $pdf->SetXY($posx + 2, $posy);
2130 $pdf->MultiCell($widthrecbox - 2, 4, $carac_client, 0, $ltrdirection);
2134 $idaddressshipping = $object->getIdContact(
'external',
'SHIPPING');
2136 if (!empty($idaddressshipping)) {
2137 $contactshipping = $object->fetch_Contact($idaddressshipping[0]);
2138 $companystatic =
new Societe($this->
db);
2139 $companystatic->fetch($object->contact->fk_soc);
2141 $carac_client_shipping =
pdf_build_address($outputlangs, $this->emetteur, $companystatic, $object->contact, $usecontact,
'target', $object);
2144 $carac_client_shipping=
pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty,
'', 0,
'target', $object);;
2146 if (!empty($carac_client_shipping)) {
2147 $posy += $hautcadre;
2150 $pdf->SetXY($posx + 2, $posy - 5);
2151 $pdf->SetFont(
'',
'', $default_font_size - 2);
2152 $pdf->MultiCell($widthrecbox,
'', $outputlangs->transnoentities(
'ShippingTo'), 0,
'L', 0);
2153 $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
2156 $pdf->SetXY($posx + 2, $posy + 3);
2157 $pdf->SetFont(
'',
'B', $default_font_size);
2158 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name_shipping,
'',
'L');
2160 $posy = $pdf->getY();
2163 $pdf->SetXY($posx+2, $posy);
2164 $pdf->SetFont(
'',
'', $default_font_size - 1);
2165 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_shipping,
'',
'L');
2166 $top_shift += $hautcadre;
2171 $pdf->SetTextColor(0, 0, 0);
2185 protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
2187 $showdetails =
getDolGlobalInt(
'MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
2188 return pdf_pagefoot($pdf, $outputlangs,
'INVOICE_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext, $this->page_largeur, $this->watermark);
Class to manage bank accounts.
printRect($pdf, $x, $y, $l, $h, $hidetop=0, $hidebottom=0)
Rect pdf.
Class to manage bank accounts description of third parties.
Class to manage invoices.
const STATUS_DRAFT
Draft status.
Parent class of invoice document generators.
Class to manage products or services.
const TYPE_PRODUCT
Regular product.
const TYPE_SERVICE
Service.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage translations.
Class to manage Dolibarr users.
Class to generate the customer invoice PDF with template Crabe.
__construct($db)
Constructor.
_pagehead(&$pdf, $object, $showaddress, $outputlangs, $outputlangsbis=null)
Show top header of page.
_tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0, $currency='')
Show table for lines.
_tableau_versements(&$pdf, $object, $posy, $outputlangs, $heightforfooter=0)
Show payments table.
_pagefoot(&$pdf, $object, $outputlangs, $hidefreetext=0)
Show footer of page.
_tableau_info(&$pdf, $object, $posy, $outputlangs, $outputlangsbis)
Show miscellaneous information (payment mode, payment term, ...)
write_file($object, $outputlangs, $srctemplatepath='', $hidedetails=0, $hidedesc=0, $hideref=0)
Function to build pdf onto disk.
_tableau_versements_header($pdf, $object, $outputlangs, $default_font_size, $tab3_posx, $tab3_top, $tab3_width, $tab3_height)
Function _tableau_versements_header.
_tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs, $outputlangsbis)
Show total to pay.
getCountry($searchkey, $withcode='', $dbtouse=0, $outputlangs='', $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
print *****$script_file(".$version.") pid cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
if(!function_exists('dolEscapeXML')) convertBackOfficeMediasLinksToPublicLinks($notetoshow)
Convert links to local wrapper to medias files into a string into a public external URL readable on i...
vatrate($rate, $addpercent=false, $info_bits=0, $usestarfornpr=0, $html=0)
Return a string with VAT rate label formated for view output Used into pdf and HTML pages.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
getLocalTaxesFromRate($vatrate, $local, $buyer, $seller, $firstparamisid=0)
Get type and rate of localtaxes for a particular vat rate/country of a thirdparty.
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
complete_substitutions_array(&$substitutionarray, $outputlangs, $object=null, $parameters=null, $callfunc="completesubstitutionarray")
Complete the $substitutionarray with more entries coming from external module that had set the "subst...
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
dol_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom='UTF-8', $removelasteolbr=1)
This function is called to encode a string into a HTML string but differs from htmlentities because a...
isModEnabled($module)
Is Dolibarr module enabled.
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
if(!defined( 'CSRFCHECK_WITH_TOKEN'))
pdf_getSizeForImage($realpath)
Return dimensions to use for images onto PDF checking that width and height are not higher than maxim...
pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails=0)
Return line total excluding tax.
pdf_getPDFFontSize($outputlangs)
Return font size to use for PDF generation.
pdf_getFormat(Translate $outputlangs=null, $mode='setup')
Return array with format properties of default PDF format.
pdf_writelinedesc(&$pdf, $object, $i, $outputlangs, $w, $h, $posx, $posy, $hideref=0, $hidedesc=0, $issupplierline=0)
Output line description into PDF.
pdf_getHeightForLogo($logo, $url=false)
Return height to use for Logo onto PDF.
pdf_pagefoot(&$pdf, $outputlangs, $paramfreetext, $fromcompany, $marge_basse, $marge_gauche, $page_hauteur, $object, $showdetails=0, $hidefreetext=0, $page_largeur=0, $watermark='')
Show footer of page for PDF generation.
pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails=0)
Return line unit price excluding tax.
pdf_getlineprogress($object, $i, $outputlangs, $hidedetails=0, $hookmanager=null)
Return line percent.
pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails=0)
Return line vat rate.
pdf_getlineunit($object, $i, $outputlangs, $hidedetails=0, $hookmanager=false)
Return line unit.
pdf_getSubstitutionArray($outputlangs, $exclude=null, $object=null, $onlykey=0)
Return array of possible substitutions for PDF content (without external module substitutions).
pdf_pagehead(&$pdf, $outputlangs, $page_height)
Show header of page for PDF generation.
pdf_writeLinkedObjects(&$pdf, $object, $outputlangs, $posx, $posy, $w, $h, $align, $default_font_size)
Show linked objects for PDF generation.
pdf_bank(&$pdf, $outputlangs, $curx, $cury, $account, $onlynumber=0, $default_font_size=10)
Show bank informations for PDF generation.
pdf_getPDFFont($outputlangs)
Return font name to use for PDF generation.
pdf_build_address($outputlangs, $sourcecompany, $targetcompany='', $targetcontact='', $usecontact=0, $mode='source', $object=null)
Return a string with full address formated for output on documents.
pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails=0)
Return line remise percent.
pdf_getlineqty($object, $i, $outputlangs, $hidedetails=0)
Return line quantity.
pdf_getInstance($format='', $metric='mm', $pagetype='P')
Return a PDF instance object.
pdfBuildThirdpartyName($thirdparty, Translate $outputlangs, $includealias=0)
Returns the name of the thirdparty.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
$conf db name
Only used if Module[ID]Name translation string is not found.
$conf db
API class for accounts.