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;
189 $this->posxtva = 101;
191 $this->posxqty = 135;
192 $this->posxunit = 151;
194 $this->posxtva = 110;
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[$conf->entity]) ? $conf->facture->dir_output : $conf->facture->multidir_output[$conf->entity];
314 $file = $dir.
"/SPECIMEN.pdf";
317 $dir = (empty($conf->facture->multidir_output[$conf->entity]) ? $conf->facture->dir_output : $conf->facture->multidir_output[$conf->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');
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;
913 $this->result = array(
'fullpath'=>$file);
917 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
921 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"FAC_OUTPUTDIR");
945 if ($object->type == 2 && !empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) {
949 $current_page = $pdf->getPage();
951 $tab3_top = $posy + 8;
954 if ($this->page_largeur < 210) {
960 $this->
_tableau_versements_header($pdf, $object, $outputlangs, $default_font_size, $tab3_posx, $tab3_top, $tab3_width, $tab3_height);
964 $pdf->SetFont(
'',
'', $default_font_size - 4);
968 $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,";
969 $sql .=
" re.description, re.fk_facture_source,";
970 $sql .=
" f.type, f.datef";
971 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re, ".MAIN_DB_PREFIX.
"facture as f";
972 $sql .=
" WHERE re.fk_facture_source = f.rowid AND re.fk_facture = ".((int) $object->id);
973 $resql = $this->
db->query(
$sql);
975 $num = $this->
db->num_rows($resql);
980 if ($tab3_top + $y >= ($this->page_hauteur - $heightforfooter)) {
983 $pdf->AddPage(
'',
'',
true);
984 if (!empty($tplidx)) {
985 $pdf->useTemplate($tplidx);
988 $top_shift = $this->
_pagehead($pdf, $object, 0, $outputlangs);
989 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
991 $pdf->setPage($current_page);
992 $this->
_tableau_versements_header($pdf, $object, $outputlangs, $default_font_size, $tab3_posx, $tab3_top + $y - 3, $tab3_width, $tab3_height);
995 $obj = $this->
db->fetch_object($resql);
997 if ($obj->type == 2) {
998 $text = $outputlangs->transnoentities(
"CreditNote");
999 } elseif ($obj->type == 3) {
1000 $text = $outputlangs->transnoentities(
"Deposit");
1001 } elseif ($obj->type == 0) {
1002 $text = $outputlangs->transnoentities(
"ExcessReceived");
1004 $text = $outputlangs->transnoentities(
"UnknownType");
1007 $invoice->fetch($obj->fk_facture_source);
1009 $pdf->SetXY($tab3_posx, $tab3_top + $y);
1010 $pdf->MultiCell(20, 3,
dol_print_date($this->
db->jdate($obj->datef),
'day',
false, $outputlangs,
true), 0,
'L', 0);
1011 $pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
1012 $pdf->MultiCell(20, 3,
price((
isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) ? $obj->multicurrency_amount_ttc : $obj->amount_ttc, 0, $outputlangs), 0,
'L', 0);
1013 $pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
1014 $pdf->MultiCell(20, 3, $text, 0,
'L', 0);
1015 $pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
1016 $pdf->MultiCell(20, 3, $invoice->ref, 0,
'L', 0);
1018 $pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
1023 $this->error = $this->
db->lasterror();
1029 $sql =
"SELECT p.datep as date, p.fk_paiement, p.num_paiement as num, pf.amount as amount, pf.multicurrency_amount,";
1031 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiement_facture as pf, ".MAIN_DB_PREFIX.
"paiement as p";
1032 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as cp ON p.fk_paiement = cp.id";
1033 $sql .=
" WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = ".((int) $object->id);
1035 $sql .=
" ORDER BY p.datep";
1037 $resql = $this->
db->query(
$sql);
1039 $num = $this->
db->num_rows($resql);
1043 if ($tab3_top + $y >= ($this->page_hauteur - $heightforfooter)) {
1046 $pdf->AddPage(
'',
'',
true);
1047 if (!empty($tplidx)) {
1048 $pdf->useTemplate($tplidx);
1051 $top_shift = $this->
_pagehead($pdf, $object, 0, $outputlangs);
1052 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
1054 $pdf->setPage($current_page);
1055 $this->
_tableau_versements_header($pdf, $object, $outputlangs, $default_font_size, $tab3_posx, $tab3_top + $y - 3, $tab3_width, $tab3_height);
1058 $row = $this->
db->fetch_object($resql);
1060 $pdf->SetXY($tab3_posx, $tab3_top + $y);
1061 $pdf->MultiCell(20, 3,
dol_print_date($this->
db->jdate($row->date),
'day',
false, $outputlangs,
true), 0,
'L', 0);
1062 $pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
1063 $pdf->MultiCell(20, 3,
price($sign * ((
isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) ? $row->multicurrency_amount : $row->amount), 0, $outputlangs), 0,
'L', 0);
1064 $pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
1065 $oper = $outputlangs->transnoentitiesnoconv(
"PaymentTypeShort".$row->code);
1067 $pdf->MultiCell(20, 3, $oper, 0,
'L', 0);
1068 $pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
1069 $pdf->MultiCell(30, 3, $row->num, 0,
'L', 0);
1071 $pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
1076 return $tab3_top + $y + 3;
1078 $this->error = $this->
db->lasterror();
1101 $title = $outputlangs->transnoentities(
"PaymentsAlreadyDone");
1102 if ($object->type == 2) {
1103 $title = $outputlangs->transnoentities(
"PaymentsBackAlreadyDone");
1106 $pdf->SetFont(
'',
'', $default_font_size - 3);
1107 $pdf->SetXY($tab3_posx, $tab3_top - 4);
1108 $pdf->MultiCell(60, 3, $title, 0,
'L', 0);
1110 $pdf->line($tab3_posx, $tab3_top, $tab3_posx + $tab3_width, $tab3_top);
1112 $pdf->SetFont(
'',
'', $default_font_size - 4);
1113 $pdf->SetXY($tab3_posx, $tab3_top);
1114 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Payment"), 0,
'L', 0);
1115 $pdf->SetXY($tab3_posx + 21, $tab3_top);
1116 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Amount"), 0,
'L', 0);
1117 $pdf->SetXY($tab3_posx + 40, $tab3_top);
1118 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Type"), 0,
'L', 0);
1119 $pdf->SetXY($tab3_posx + 58, $tab3_top);
1120 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Num"), 0,
'L', 0);
1122 $pdf->line($tab3_posx, $tab3_top - 1 + $tab3_height, $tab3_posx + $tab3_width, $tab3_top - 1 + $tab3_height);
1137 protected function _tableau_info(&$pdf, $object, $posy, $outputlangs, $outputlangsbis)
1140 global $conf, $mysoc;
1144 $pdf->SetFont(
'',
'', $default_font_size - 1);
1147 if ($this->emetteur->country_code ==
'FR' && empty($mysoc->tva_assuj)) {
1148 $pdf->SetFont(
'',
'B', $default_font_size - 2);
1149 $pdf->SetXY($this->marge_gauche, $posy);
1150 if ($mysoc->forme_juridique_code == 92) {
1151 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"VATIsNotUsedForInvoiceAsso"), 0,
'L', 0);
1153 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"VATIsNotUsedForInvoice"), 0,
'L', 0);
1156 $posy = $pdf->GetY() + 4;
1161 if ($this->page_largeur < 210) {
1166 if ($object->type != 2 && ($object->cond_reglement_code || $object->cond_reglement)) {
1167 $pdf->SetFont(
'',
'B', $default_font_size - 2);
1168 $pdf->SetXY($this->marge_gauche, $posy);
1169 $titre = $outputlangs->transnoentities(
"PaymentConditions").
':';
1170 $pdf->MultiCell(43, 4, $titre, 0,
'L');
1172 $pdf->SetFont(
'',
'', $default_font_size - 2);
1173 $pdf->SetXY($posxval, $posy);
1174 $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);
1175 $lib_condition_paiement = str_replace(
'\n',
"\n", $lib_condition_paiement);
1176 $pdf->MultiCell(67, 4, $lib_condition_paiement, 0,
'L');
1178 $posy = $pdf->GetY() + 3;
1182 if (
getDolGlobalInt(
'INVOICE_CATEGORY_OF_OPERATION') == 2 && $this->categoryOfOperation >= 0) {
1183 $pdf->SetFont(
'',
'B', $default_font_size - 2);
1184 $pdf->SetXY($this->marge_gauche, $posy);
1185 $categoryOfOperationTitle = $outputlangs->transnoentities(
"MentionCategoryOfOperations").
' : ';
1186 $pdf->MultiCell($posxval - $this->marge_gauche, 4, $categoryOfOperationTitle, 0,
'L');
1188 $pdf->SetFont(
'',
'', $default_font_size - 2);
1189 $pdf->SetXY($posxval, $posy);
1190 $categoryOfOperationLabel = $outputlangs->transnoentities(
"MentionCategoryOfOperations" . $this->categoryOfOperation);
1191 $pdf->MultiCell($posxend - $posxval, 4, $categoryOfOperationLabel, 0,
'L');
1193 $posy = $pdf->GetY() + 3;
1196 if ($object->type != 2) {
1198 if (empty($object->mode_reglement_code)
1199 && empty($conf->global->FACTURE_CHQ_NUMBER)
1201 $this->error = $outputlangs->transnoentities(
"ErrorNoPaiementModeConfigured");
1202 } elseif (($object->mode_reglement_code ==
'CHQ' && empty($conf->global->FACTURE_CHQ_NUMBER) && empty($object->fk_account) && empty($object->fk_bank))
1203 || ($object->mode_reglement_code ==
'VIR' && !
getDolGlobalInt(
'FACTURE_RIB_NUMBER') && empty($object->fk_account) && empty($object->fk_bank))) {
1205 $outputlangs->load(
"errors");
1207 $pdf->SetXY($this->marge_gauche, $posy);
1208 $pdf->SetTextColor(200, 0, 0);
1209 $pdf->SetFont(
'',
'B', $default_font_size - 2);
1210 $this->error = $outputlangs->transnoentities(
"ErrorPaymentModeDefinedToWithoutSetup", $object->mode_reglement_code);
1211 $pdf->MultiCell(80, 3, $this->error, 0,
'L', 0);
1212 $pdf->SetTextColor(0, 0, 0);
1214 $posy = $pdf->GetY() + 1;
1218 if (!empty($object->mode_reglement_code)
1219 && $object->mode_reglement_code !=
'CHQ'
1220 && $object->mode_reglement_code !=
'VIR') {
1221 $pdf->SetFont(
'',
'B', $default_font_size - 2);
1222 $pdf->SetXY($this->marge_gauche, $posy);
1223 $titre = $outputlangs->transnoentities(
"PaymentMode").
':';
1224 $pdf->MultiCell(80, 5, $titre, 0,
'L');
1226 $pdf->SetFont(
'',
'', $default_font_size - 2);
1227 $pdf->SetXY($posxval, $posy);
1228 $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);
1230 if ($object->mode_reglement_code ==
"PRE") {
1231 require_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
1233 $bac->fetch(0, $object->thirdparty->id);
1234 $iban= $bac->iban.(($bac->iban && $bac->bic) ?
' / ' :
'').$bac->bic;
1235 $lib_mode_reg .= $outputlangs->trans(
"PaymentTypePREdetails",
dol_trunc($iban, 6,
'right',
'UTF-8', 1));
1237 $pdf->MultiCell(80, 5, $lib_mode_reg, 0,
'L');
1239 $posy = $pdf->GetY();
1245 if ($this->emetteur->country_code ==
'FR') {
1246 if (isset($conf->global->TAX_MODE) && $conf->global->TAX_MODE == 1) {
1247 $pdf->SetXY($this->marge_gauche, $posy);
1248 $pdf->writeHTMLCell(80, 5,
'',
'', $outputlangs->transnoentities(
"MentionVATDebitOptionIsOn"), 0, 1);
1250 $posy = $pdf->GetY() + 1;
1255 if (empty($object->mode_reglement_code) || $object->mode_reglement_code ==
'CB' || $object->mode_reglement_code ==
'VAD') {
1256 $useonlinepayment = 0;
1257 if (!empty($conf->global->PDF_SHOW_LINK_TO_ONLINE_PAYMENT)) {
1259 $useonlinepayment++;
1262 $useonlinepayment++;
1265 $useonlinepayment++;
1270 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
1273 $langs->loadLangs(array(
'payment',
'paybox',
'stripe'));
1274 $servicename = $langs->transnoentities(
'Online');
1275 $paiement_url = getOnlinePaymentUrl(
'',
'invoice', $object->ref,
'',
'',
'');
1276 $linktopay = $langs->trans(
"ToOfferALinkForOnlinePayment", $servicename).
' <a href="'.$paiement_url.
'">'.$outputlangs->transnoentities(
"ClickHere").
'</a>';
1278 $pdf->SetXY($this->marge_gauche, $posy);
1281 $posy = $pdf->GetY() + 1;
1286 if (empty($object->mode_reglement_code) || $object->mode_reglement_code ==
'CHQ') {
1288 if (!empty($conf->global->FACTURE_CHQ_NUMBER)) {
1289 $diffsizetitle = (empty($conf->global->PDF_DIFFSIZE_TITLE) ? 3 : $conf->global->PDF_DIFFSIZE_TITLE);
1291 if ($conf->global->FACTURE_CHQ_NUMBER > 0) {
1293 $account->fetch($conf->global->FACTURE_CHQ_NUMBER);
1295 $pdf->SetXY($this->marge_gauche, $posy);
1296 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1297 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
'PaymentByChequeOrderedTo', $account->proprio), 0,
'L', 0);
1298 $posy = $pdf->GetY() + 1;
1300 if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS)) {
1301 $pdf->SetXY($this->marge_gauche, $posy);
1302 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1303 $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($account->owner_address), 0,
'L', 0);
1304 $posy = $pdf->GetY() + 2;
1307 if ($conf->global->FACTURE_CHQ_NUMBER == -1) {
1308 $pdf->SetXY($this->marge_gauche, $posy);
1309 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1310 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
'PaymentByChequeOrderedTo', $this->emetteur->name), 0,
'L', 0);
1311 $posy = $pdf->GetY() + 1;
1313 if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS)) {
1314 $pdf->SetXY($this->marge_gauche, $posy);
1315 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1316 $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0,
'L', 0);
1317 $posy = $pdf->GetY() + 2;
1324 if (empty($object->mode_reglement_code) || $object->mode_reglement_code ==
'VIR') {
1325 if ($object->fk_account > 0 || $object->fk_bank > 0 ||
getDolGlobalInt(
'FACTURE_RIB_NUMBER')) {
1326 $bankid = ($object->fk_account <= 0 ? $conf->global->FACTURE_RIB_NUMBER : $object->fk_account);
1327 if ($object->fk_bank > 0) {
1328 $bankid = $object->fk_bank;
1331 $account->fetch($bankid);
1333 $curx = $this->marge_gauche;
1336 $posy =
pdf_bank($pdf, $outputlangs, $curx, $cury, $account, 0, $default_font_size);
1360 protected function _tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs, $outputlangsbis)
1363 global $conf, $mysoc, $hookmanager;
1366 if ($object->type == 2 && !empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) {
1372 $outputlangsbis =
null;
1373 if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && $outputlangs->defaultlang != $conf->global->PDF_USE_ALSO_LANGUAGE_CODE) {
1374 $outputlangsbis =
new Translate(
'', $conf);
1375 $outputlangsbis->setDefaultLang($conf->global->PDF_USE_ALSO_LANGUAGE_CODE);
1376 $outputlangsbis->loadLangs(array(
"main",
"dict",
"companies",
"bills",
"products",
"propal"));
1377 $default_font_size--;
1382 $pdf->SetFont(
'',
'', $default_font_size - 1);
1387 if ($this->page_largeur < 210) {
1391 $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
1397 $pdf->SetFillColor(255, 255, 255);
1398 $pdf->SetXY($col1x, $tab2_top);
1399 $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);
1401 $total_ht = ((
isModEnabled(
"multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ht : $object->total_ht);
1402 $pdf->SetXY($col2x, $tab2_top);
1403 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * ($total_ht + (!empty($object->remise) ? $object->remise : 0)), 0, $outputlangs), 0,
'R', 1);
1406 $pdf->SetFillColor(248, 248, 248);
1408 $total_ttc = (
isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ttc : $object->total_ttc;
1410 $this->atleastoneratenotnull = 0;
1411 if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) {
1412 $tvaisnull = ((!empty($this->tva) && count($this->tva) == 1 && isset($this->tva[
'0.000']) && is_float($this->tva[
'0.000'])) ?
true :
false);
1413 if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL) && $tvaisnull) {
1421 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1422 if (in_array((
string) $localtax_type, array(
'1',
'3',
'5'))) {
1426 foreach ($localtax_rate as $tvakey => $tvaval) {
1431 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1434 if (preg_match(
'/\*/', $tvakey)) {
1435 $tvakey = str_replace(
'*',
'', $tvakey);
1436 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1439 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT1", $mysoc->country_code) :
'');
1441 $totalvat .=
vatrate(abs($tvakey), 1).$tvacompl;
1442 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1444 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1445 $pdf->MultiCell($largcol2, $tab2_hl,
price($tvaval, 0, $outputlangs), 0,
'R', 1);
1453 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1454 if (in_array((
string) $localtax_type, array(
'1',
'3',
'5'))) {
1458 foreach ($localtax_rate as $tvakey => $tvaval) {
1463 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1466 if (preg_match(
'/\*/', $tvakey)) {
1467 $tvakey = str_replace(
'*',
'', $tvakey);
1468 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1470 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT2", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT2", $mysoc->country_code) :
'');
1472 $totalvat .=
vatrate(abs($tvakey), 1).$tvacompl;
1473 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1475 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1476 $pdf->MultiCell($largcol2, $tab2_hl,
price($tvaval, 0, $outputlangs), 0,
'R', 1);
1484 foreach ($this->tva_array as $tvakey => $tvaval) {
1486 $this->atleastoneratenotnull++;
1489 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1492 if (preg_match(
'/\*/', $tvakey)) {
1493 $tvakey = str_replace(
'*',
'', $tvakey);
1494 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1496 $totalvat = $outputlangs->transcountrynoentities(
"TotalVAT", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalVAT", $mysoc->country_code) :
'');
1499 $totalvat .=
vatrate($tvaval[
'vatrate'], 1).$tvacompl;
1501 $totalvat .= $tvaval[
'vatcode'].$tvacompl;
1503 $totalvat .=
vatrate($tvaval[
'vatrate'], 1).($tvaval[
'vatcode'] ?
' ('.$tvaval[
'vatcode'].
')' :
'').$tvacompl;
1505 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1507 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1508 $pdf->MultiCell($largcol2, $tab2_hl,
price(
price2num($tvaval[
'amount'],
'MT'), 0, $outputlangs), 0,
'R', 1);
1515 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1516 if (in_array((
string) $localtax_type, array(
'2',
'4',
'6'))) {
1520 foreach ($localtax_rate as $tvakey => $tvaval) {
1525 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1528 if (preg_match(
'/\*/', $tvakey)) {
1529 $tvakey = str_replace(
'*',
'', $tvakey);
1530 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1532 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1", $mysoc->country_code).
' ';
1533 $totalvat .=
vatrate(abs($tvakey), 1).$tvacompl;
1535 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1536 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1537 $pdf->MultiCell($largcol2, $tab2_hl,
price($tvaval, 0, $outputlangs), 0,
'R', 1);
1545 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1546 if (in_array((
string) $localtax_type, array(
'2',
'4',
'6'))) {
1550 foreach ($localtax_rate as $tvakey => $tvaval) {
1554 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1557 if (preg_match(
'/\*/', $tvakey)) {
1558 $tvakey = str_replace(
'*',
'', $tvakey);
1559 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1561 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT2", $mysoc->country_code).
' ';
1563 $totalvat .=
vatrate(abs($tvakey), 1).$tvacompl;
1564 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1566 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1567 $pdf->MultiCell($largcol2, $tab2_hl,
price($tvaval, 0, $outputlangs), 0,
'R', 1);
1573 if (
price2num($object->revenuestamp) != 0) {
1575 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1576 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"RevenueStamp"), $useborder,
'L', 1);
1578 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1579 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * $object->revenuestamp), $useborder,
'R', 1);
1584 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1585 $pdf->SetTextColor(0, 0, 60);
1586 $pdf->SetFillColor(224, 224, 224);
1587 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalTTC"), $useborder,
'L', 1);
1589 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1590 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * $total_ttc, 0, $outputlangs), $useborder,
'R', 1);
1593 if ($object->displayRetainedWarranty()) {
1594 $pdf->SetTextColor(40, 40, 40);
1595 $pdf->SetFillColor(255, 255, 255);
1597 $retainedWarranty = $object->getRetainedWarrantyAmount();
1598 $billedWithRetainedWarranty = $object->total_ttc - $retainedWarranty;
1602 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1603 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"ToPayOn",
dol_print_date($object->date_lim_reglement,
'day')), $useborder,
'L', 1);
1605 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1606 $pdf->MultiCell($largcol2, $tab2_hl,
price($billedWithRetainedWarranty), $useborder,
'R', 1);
1610 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1612 $retainedWarrantyToPayOn = $outputlangs->transnoentities(
"RetainedWarranty").
' ('.$object->retained_warranty.
'%)';
1613 $retainedWarrantyToPayOn .= !empty($object->retained_warranty_date_limit) ?
' '.$outputlangs->transnoentities(
"toPayOn",
dol_print_date($object->retained_warranty_date_limit,
'day')) :
'';
1615 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $retainedWarrantyToPayOn, $useborder,
'L', 1);
1616 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1617 $pdf->MultiCell($largcol2, $tab2_hl,
price($retainedWarranty), $useborder,
'R', 1);
1622 $pdf->SetTextColor(0, 0, 0);
1623 $creditnoteamount = $object->getSumCreditNotesUsed((
isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
1624 $depositsamount = $object->getSumDepositsUsed((
isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
1626 $resteapayer =
price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount,
'MT');
1627 if (!empty($object->paye)) {
1631 if (($deja_regle > 0 || $creditnoteamount > 0 || $depositsamount > 0) && empty($conf->global->INVOICE_NO_PAYMENT_DETAILS)) {
1634 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1635 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"Paid"), 0,
'L', 0);
1636 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1637 $pdf->MultiCell($largcol2, $tab2_hl,
price($deja_regle + $depositsamount, 0, $outputlangs), 0,
'R', 0);
1640 if ($creditnoteamount) {
1641 $labeltouse = ($outputlangs->transnoentities(
"CreditNotesOrExcessReceived") !=
"CreditNotesOrExcessReceived") ? $outputlangs->transnoentities(
"CreditNotesOrExcessReceived") : $outputlangs->transnoentities(
"CreditNotes");
1643 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1644 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $labeltouse, 0,
'L', 0);
1645 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1646 $pdf->MultiCell($largcol2, $tab2_hl,
price($creditnoteamount, 0, $outputlangs), 0,
'R', 0);
1650 if ($object->close_code == Facture::CLOSECODE_DISCOUNTVAT) {
1652 $pdf->SetFillColor(255, 255, 255);
1654 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1655 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"EscompteOfferedShort"), $useborder,
'L', 1);
1656 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1657 $pdf->MultiCell($largcol2, $tab2_hl,
price($object->total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 0, $outputlangs), $useborder,
'R', 1);
1663 $pdf->SetTextColor(0, 0, 60);
1664 $pdf->SetFillColor(224, 224, 224);
1665 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1666 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"RemainderToPay"), $useborder,
'L', 1);
1667 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1668 $pdf->MultiCell($largcol2, $tab2_hl,
price($resteapayer, 0, $outputlangs), $useborder,
'R', 1);
1670 $pdf->SetFont(
'',
'', $default_font_size - 1);
1671 $pdf->SetTextColor(0, 0, 0);
1675 return ($tab2_top + ($tab2_hl * $index));
1692 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency =
'')
1702 $currency = !empty($currency) ? $currency : $conf->currency;
1706 $pdf->SetTextColor(0, 0, 0);
1707 $pdf->SetFont(
'',
'', $default_font_size - 2);
1709 if (empty($hidetop)) {
1711 if (
getDolGlobalInt(
'INVOICE_CATEGORY_OF_OPERATION') == 1 && $this->categoryOfOperation >= 0) {
1712 $categoryOfOperations = $outputlangs->transnoentities(
"MentionCategoryOfOperations") .
' : ' . $outputlangs->transnoentities(
"MentionCategoryOfOperations" . $this->categoryOfOperation);
1713 $pdf->SetXY($this->marge_gauche, $tab_top - 4);
1714 $pdf->MultiCell(($pdf->GetStringWidth($categoryOfOperations)) + 4, 2, $categoryOfOperations);
1717 $titre = $outputlangs->transnoentities(
"AmountInCurrency", $outputlangs->transnoentitiesnoconv(
"Currency".$currency));
1718 $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
1719 $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
1722 if (!empty($conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)) {
1723 $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));
1727 $pdf->SetDrawColor(128, 128, 128);
1728 $pdf->SetFont(
'',
'', $default_font_size - 1);
1731 $this->
printRect($pdf, $this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $tab_height, $hidetop, $hidebottom);
1733 if (empty($hidetop)) {
1734 $pdf->line($this->marge_gauche, $tab_top + 5, $this->page_largeur - $this->marge_droite, $tab_top + 5);
1736 $pdf->SetXY($this->posxdesc - 1, $tab_top + 1);
1737 $pdf->MultiCell(108, 2, $outputlangs->transnoentities(
"Designation"),
'',
'L');
1740 if (!empty($conf->global->MAIN_GENERATE_INVOICES_WITH_PICTURE)) {
1741 $pdf->line($this->posxpicture - 1, $tab_top, $this->posxpicture - 1, $tab_top + $tab_height);
1742 if (empty($hidetop)) {
1748 if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) && empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) {
1749 $pdf->line($this->posxtva - 1, $tab_top, $this->posxtva - 1, $tab_top + $tab_height);
1750 if (empty($hidetop)) {
1751 $pdf->SetXY($this->posxtva - 3, $tab_top + 1);
1752 $pdf->MultiCell($this->posxup - $this->posxtva + 3, 2, $outputlangs->transnoentities(
"VAT"),
'',
'C');
1756 $pdf->line($this->posxup - 1, $tab_top, $this->posxup - 1, $tab_top + $tab_height);
1757 if (empty($hidetop)) {
1758 $pdf->SetXY($this->posxup - 1, $tab_top + 1);
1759 $pdf->MultiCell($this->posxqty - $this->posxup - 1, 2, $outputlangs->transnoentities(
"PriceUHT"),
'',
'C');
1762 $pdf->line($this->posxqty - 1, $tab_top, $this->posxqty - 1, $tab_top + $tab_height);
1763 if (empty($hidetop)) {
1764 $pdf->SetXY($this->posxqty - 1, $tab_top + 1);
1765 $pdf->MultiCell($this->posxunit - $this->posxqty - 1, 2, $outputlangs->transnoentities(
"Qty"),
'',
'C');
1769 $pdf->line($this->posxunit - 1, $tab_top, $this->posxunit - 1, $tab_top + $tab_height);
1770 if (empty($hidetop)) {
1771 $pdf->SetXY($this->posxunit - 1, $tab_top + 1);
1772 $pdf->MultiCell($this->posxdiscount - $this->posxunit - 1, 2, $outputlangs->transnoentities(
"Unit"),
'',
'C');
1776 if ($this->atleastonediscount) {
1777 $pdf->line($this->posxdiscount - 1, $tab_top, $this->posxdiscount - 1, $tab_top + $tab_height);
1778 if (empty($hidetop)) {
1779 $pdf->SetXY($this->posxdiscount - 1, $tab_top + 1);
1780 $pdf->MultiCell($this->posxprogress - $this->posxdiscount + 1, 2, $outputlangs->transnoentities(
"ReductionShort"),
'',
'C');
1784 if ($this->situationinvoice) {
1785 $pdf->line($this->posxprogress - 1, $tab_top, $this->posxprogress - 1, $tab_top + $tab_height);
1786 if (empty($hidetop)) {
1787 $pdf->SetXY($this->posxprogress, $tab_top + 1);
1788 $pdf->MultiCell($this->postotalht - $this->posxprogress, 2, $outputlangs->transnoentities(
"ProgressShort"),
'',
'C');
1792 $pdf->line($this->postotalht, $tab_top, $this->postotalht, $tab_top + $tab_height);
1793 if (empty($hidetop)) {
1794 $pdf->SetXY($this->postotalht - 1, $tab_top + 1);
1795 $pdf->MultiCell(30, 2, $outputlangs->transnoentities(
"TotalHT"),
'',
'C');
1810 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $outputlangsbis =
null)
1812 global $conf, $langs;
1814 $ltrdirection =
'L';
1815 if ($outputlangs->trans(
"DIRECTION") ==
'rtl') $ltrdirection =
'R';
1818 $outputlangs->loadLangs(array(
"main",
"bills",
"propal",
"companies"));
1824 $pdf->SetTextColor(0, 0, 60);
1825 $pdf->SetFont(
'',
'B', $default_font_size + 3);
1829 $posy = $this->marge_haute;
1830 $posx = $this->page_largeur - $this->marge_droite - $w;
1832 $pdf->SetXY($this->marge_gauche, $posy);
1836 if ($this->emetteur->logo) {
1837 $logodir = $conf->mycompany->dir_output;
1838 if (!empty($conf->mycompany->multidir_output[$object->entity])) {
1839 $logodir = $conf->mycompany->multidir_output[$object->entity];
1842 $logo = $logodir.
'/logos/thumbs/'.$this->emetteur->logo_small;
1844 $logo = $logodir.
'/logos/'.$this->emetteur->logo;
1846 if (is_readable($logo)) {
1848 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
1850 $pdf->SetTextColor(200, 0, 0);
1851 $pdf->SetFont(
'',
'B', $default_font_size - 2);
1852 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
1853 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorGoToGlobalSetup"), 0,
'L');
1856 $text = $this->emetteur->name;
1857 $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, $ltrdirection);
1861 $pdf->SetFont(
'',
'B', $default_font_size + 3);
1862 $pdf->SetXY($posx, $posy);
1863 $pdf->SetTextColor(0, 0, 60);
1864 $title = $outputlangs->transnoentities(
"PdfInvoiceTitle");
1865 if ($object->type == 1) {
1866 $title = $outputlangs->transnoentities(
"InvoiceReplacement");
1868 if ($object->type == 2) {
1869 $title = $outputlangs->transnoentities(
"InvoiceAvoir");
1871 if ($object->type == 3) {
1872 $title = $outputlangs->transnoentities(
"InvoiceDeposit");
1874 if ($object->type == 4) {
1875 $title = $outputlangs->transnoentities(
"InvoiceProForma");
1877 if ($this->situationinvoice) {
1878 $title = $outputlangs->transnoentities(
"PDFInvoiceSituation");
1880 if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) {
1882 if ($object->type == 0) {
1883 if ($this->situationinvoice) {
1884 $title .= $outputlangsbis->transnoentities(
"PDFInvoiceSituation");
1886 $title .= $outputlangsbis->transnoentities(
"PdfInvoiceTitle");
1887 } elseif ($object->type == 1) {
1888 $title .= $outputlangsbis->transnoentities(
"InvoiceReplacement");
1889 } elseif ($object->type == 2) {
1890 $title .= $outputlangsbis->transnoentities(
"InvoiceAvoir");
1891 } elseif ($object->type == 3) {
1892 $title .= $outputlangsbis->transnoentities(
"InvoiceDeposit");
1893 } elseif ($object->type == 4) {
1894 $title .= $outputlangsbis->transnoentities(
"InvoiceProForma");
1897 $title .=
' '.$outputlangs->convToOutputCharset($object->ref);
1898 if ($object->statut == $object::STATUS_DRAFT) {
1899 $pdf->SetTextColor(128, 0, 0);
1900 $title .=
' - '.$outputlangs->transnoentities(
"NotValidated");
1903 $pdf->MultiCell($w, 3, $title,
'',
'R');
1905 $pdf->SetFont(
'',
'B', $default_font_size);
1919 $pdf->SetFont(
'',
'', $default_font_size - 2);
1921 if ($object->ref_client) {
1923 $pdf->SetXY($posx, $posy);
1924 $pdf->SetTextColor(0, 0, 60);
1925 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefCustomer").
" : ".$outputlangs->convToOutputCharset($object->ref_client),
'',
'R');
1928 if (!empty($conf->global->PDF_SHOW_PROJECT_TITLE)) {
1929 $object->fetch_projet();
1930 if (!empty($object->project->ref)) {
1932 $pdf->SetXY($posx, $posy);
1933 $pdf->SetTextColor(0, 0, 60);
1934 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Project").
" : ".(empty($object->project->title) ?
'' : $object->project->title),
'',
'R');
1938 if (!empty($conf->global->PDF_SHOW_PROJECT)) {
1939 $object->fetch_projet();
1940 if (!empty($object->project->ref)) {
1941 $outputlangs->load(
"projects");
1943 $pdf->SetXY($posx, $posy);
1944 $pdf->SetTextColor(0, 0, 60);
1945 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefProject").
" : ".(empty($object->project->ref) ?
'' : $object->project->ref),
'',
'R');
1949 $objectidnext = $object->getIdReplacingInvoice(
'validated');
1950 if ($object->type == 0 && $objectidnext) {
1951 $objectreplacing =
new Facture($this->
db);
1952 $objectreplacing->fetch($objectidnext);
1955 $pdf->SetXY($posx, $posy);
1956 $pdf->SetTextColor(0, 0, 60);
1957 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ReplacementByInvoice").
' : '.$outputlangs->convToOutputCharset($objectreplacing->ref),
'',
'R');
1959 if ($object->type == 1) {
1960 $objectreplaced =
new Facture($this->
db);
1961 $objectreplaced->fetch($object->fk_facture_source);
1964 $pdf->SetXY($posx, $posy);
1965 $pdf->SetTextColor(0, 0, 60);
1966 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ReplacementInvoice").
' : '.$outputlangs->convToOutputCharset($objectreplaced->ref),
'',
'R');
1968 if ($object->type == 2 && !empty($object->fk_facture_source)) {
1969 $objectreplaced =
new Facture($this->
db);
1970 $objectreplaced->fetch($object->fk_facture_source);
1973 $pdf->SetXY($posx, $posy);
1974 $pdf->SetTextColor(0, 0, 60);
1975 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CorrectionInvoice").
' : '.$outputlangs->convToOutputCharset($objectreplaced->ref),
'',
'R');
1979 $pdf->SetXY($posx, $posy);
1980 $pdf->SetTextColor(0, 0, 60);
1981 $title = $outputlangs->transnoentities(
"DateInvoice");
1982 if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) {
1983 $title .=
' - '.$outputlangsbis->transnoentities(
"DateInvoice");
1985 $pdf->MultiCell($w, 3, $title.
" : ".
dol_print_date($object->date,
"day",
false, $outputlangs,
true),
'',
'R');
1987 if (!empty($conf->global->INVOICE_POINTOFTAX_DATE)) {
1989 $pdf->SetXY($posx, $posy);
1990 $pdf->SetTextColor(0, 0, 60);
1991 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"DatePointOfTax").
" : ".
dol_print_date($object->date_pointoftax,
"day",
false, $outputlangs),
'',
'R');
1994 if ($object->type != 2) {
1996 $pdf->SetXY($posx, $posy);
1997 $pdf->SetTextColor(0, 0, 60);
1998 $title = $outputlangs->transnoentities(
"DateDue");
1999 if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) {
2000 $title .=
' - '.$outputlangsbis->transnoentities(
"DateDue");
2002 $pdf->MultiCell($w, 3, $title.
" : ".
dol_print_date($object->date_lim_reglement,
"day",
false, $outputlangs,
true),
'',
'R');
2005 if (empty($conf->global->MAIN_PDF_HIDE_CUSTOMER_CODE) && $object->thirdparty->code_client) {
2007 $pdf->SetXY($posx, $posy);
2008 $pdf->SetTextColor(0, 0, 60);
2009 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CustomerCode").
" : ".$outputlangs->transnoentities($object->thirdparty->code_client),
'',
'R');
2013 if (!empty($conf->global->DOC_SHOW_FIRST_SALES_REP)) {
2014 $arrayidcontact = $object->getIdContact(
'internal',
'SALESREPFOLL');
2015 if (count($arrayidcontact) > 0) {
2016 $usertmp =
new User($this->
db);
2017 $usertmp->fetch($arrayidcontact[0]);
2019 $pdf->SetXY($posx, $posy);
2020 $pdf->SetTextColor(0, 0, 60);
2021 $pdf->MultiCell($w, 3, $langs->transnoentities(
"SalesRepresentative").
" : ".$usertmp->getFullName($langs),
'',
'R');
2029 $current_y = $pdf->getY();
2030 $posy =
pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, $w, 3,
'R', $default_font_size);
2031 if ($current_y < $pdf->getY()) {
2032 $top_shift = $pdf->getY() - $current_y;
2037 $carac_emetteur =
pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty,
'', 0,
'source', $object);
2040 $posy = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
2041 $posy += $top_shift;
2042 $posx = $this->marge_gauche;
2043 if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
2044 $posx = $this->page_largeur - $this->marge_droite - 80;
2047 $hautcadre = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 38 : 40;
2048 $widthrecbox = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 82;
2052 if (empty($conf->global->MAIN_PDF_NO_SENDER_FRAME)) {
2053 $pdf->SetTextColor(0, 0, 0);
2054 $pdf->SetFont(
'',
'', $default_font_size - 2);
2055 $pdf->SetXY($posx, $posy - 5);
2056 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"BillFrom"), 0, $ltrdirection);
2057 $pdf->SetXY($posx, $posy);
2058 $pdf->SetFillColor(230, 230, 230);
2059 $pdf->MultiCell($widthrecbox, $hautcadre,
"", 0,
'R', 1);
2060 $pdf->SetTextColor(0, 0, 60);
2064 if (empty($conf->global->MAIN_PDF_HIDE_SENDER_NAME)) {
2065 $pdf->SetXY($posx + 2, $posy + 3);
2066 $pdf->SetFont(
'',
'B', $default_font_size);
2067 $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, $ltrdirection);
2068 $posy = $pdf->getY();
2072 $pdf->SetXY($posx + 2, $posy);
2073 $pdf->SetFont(
'',
'', $default_font_size - 1);
2074 $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0, $ltrdirection);
2078 $usecontact =
false;
2079 $arrayidcontact = $object->getIdContact(
'external',
'BILLING');
2080 if (count($arrayidcontact) > 0) {
2082 $result = $object->fetch_contact($arrayidcontact[0]);
2086 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)))) {
2087 $thirdparty = $object->contact;
2089 $thirdparty = $object->thirdparty;
2095 $carac_client =
pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ($usecontact ? $object->contact :
''), $usecontact, $mode, $object);
2098 $widthrecbox = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 100;
2099 if ($this->page_largeur < 210) {
2102 $posy = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
2103 $posy += $top_shift;
2104 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
2105 if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
2106 $posx = $this->marge_gauche;
2110 if (empty($conf->global->MAIN_PDF_NO_RECIPENT_FRAME)) {
2111 $pdf->SetTextColor(0, 0, 0);
2112 $pdf->SetFont(
'',
'', $default_font_size - 2);
2113 $pdf->SetXY($posx + 2, $posy - 5);
2114 $pdf->MultiCell($widthrecbox - 2, 5, $outputlangs->transnoentities(
"BillTo"), 0, $ltrdirection);
2115 $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
2119 $pdf->SetXY($posx + 2, $posy + 3);
2120 $pdf->SetFont(
'',
'B', $default_font_size);
2121 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name, 0, $ltrdirection);
2123 $posy = $pdf->getY();
2126 $pdf->SetFont(
'',
'', $default_font_size - 1);
2127 $pdf->SetXY($posx + 2, $posy);
2128 $pdf->MultiCell($widthrecbox - 2, 4, $carac_client, 0, $ltrdirection);
2132 $idaddressshipping = $object->getIdContact(
'external',
'SHIPPING');
2134 if (!empty($idaddressshipping)) {
2135 $contactshipping = $object->fetch_Contact($idaddressshipping[0]);
2136 $companystatic =
new Societe($this->
db);
2137 $companystatic->fetch($object->contact->fk_soc);
2139 $carac_client_shipping =
pdf_build_address($outputlangs, $this->emetteur, $companystatic, $object->contact, $usecontact,
'target', $object);
2142 $carac_client_shipping=
pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty,
'', 0,
'target', $object);
2144 if (!empty($carac_client_shipping) && (isset($object->contact->socid) && $object->contact->socid != $object->socid)) {
2145 $posy += $hautcadre;
2148 $pdf->SetXY($posx + 2, $posy - 5);
2149 $pdf->SetFont(
'',
'', $default_font_size - 2);
2150 $pdf->MultiCell($widthrecbox,
'', $outputlangs->transnoentities(
'ShippingTo'), 0,
'L', 0);
2151 $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
2154 $pdf->SetXY($posx + 2, $posy + 3);
2155 $pdf->SetFont(
'',
'B', $default_font_size);
2156 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name_shipping,
'',
'L');
2158 $posy = $pdf->getY();
2161 $pdf->SetXY($posx+2, $posy);
2162 $pdf->SetFont(
'',
'', $default_font_size - 1);
2163 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_shipping,
'',
'L');
2164 $top_shift += $hautcadre;
2169 $pdf->SetTextColor(0, 0, 0);
2183 protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
2185 $showdetails =
getDolGlobalInt(
'MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
2186 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);