195 public function write_file(
$object, $outputlangs, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
198 global $user, $langs, $conf, $mysoc, $hookmanager, $nblines;
200 dol_syslog(
"write_file outputlangs->defaultlang=".(is_object($outputlangs) ? $outputlangs->defaultlang :
'null'));
202 if (!is_object($outputlangs)) {
203 $outputlangs = $langs;
207 $outputlangs->charset_output =
'ISO-8859-1';
211 $outputlangs->loadLangs(array(
"main",
"bills",
"products",
"dict",
"companies"));
218 global $outputlangsbis;
219 $outputlangsbis =
null;
221 $outputlangsbis =
new Translate(
'', $conf);
223 $outputlangsbis->loadLangs(array(
"main",
"bills",
"products",
"dict",
"companies"));
226 $nblines = count(
$object->lines);
229 $realpatharray = array();
231 for ($i = 0; $i < $nblines; $i++) {
232 if (empty(
$object->lines[$i]->fk_product)) {
236 $objphoto =
new Product($this->db);
237 $objphoto->fetch(
$object->lines[$i]->fk_product);
239 $pdir =
get_exdir(
$object->lines[$i]->fk_product, 2, 0, 0, $objphoto,
'product').$object->lines[$i]->fk_product.
"/photos/";
240 $dir = $conf->product->dir_output.
'/'.$pdir;
243 foreach ($objphoto->liste_photos($dir, 1) as $key => $obj) {
244 $filename = $obj[
'photo'];
246 $realpath = $dir.$filename;
251 $realpatharray[$i] = $realpath;
255 if (count($realpatharray) == 0) {
256 $this->posxpicture = $this->posxtva;
259 if ($conf->facture->dir_output) {
262 $deja_regle =
$object->getSommePaiement((isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? 1 : 0);
263 $amount_credit_notes_included =
$object->getSumCreditNotesUsed((isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? 1 : 0);
264 $amount_deposits_included =
$object->getSumDepositsUsed((isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? 1 : 0);
268 $dir = empty($conf->facture->multidir_output[
$object->entity]) ? $conf->facture->dir_output : $conf->facture->multidir_output[
$object->entity];
269 $file = $dir.
"/SPECIMEN.pdf";
272 $dir = (empty($conf->facture->multidir_output[
$object->entity]) ? $conf->facture->dir_output : $conf->facture->multidir_output[
$object->entity]).
"/".$objectref;
273 $file = $dir.
"/".$objectref.
".pdf";
275 if (!file_exists($dir)) {
277 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
282 if (file_exists($dir)) {
284 if (!is_object($hookmanager)) {
285 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
288 $hookmanager->initHooks(array(
'pdfgeneration'));
289 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
291 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters,
$object, $action);
294 $nblines = count(
$object->lines);
295 $nbpayments = count(
$object->getListOfPayments());
300 $pdf->SetAutoPageBreak(1, 0);
302 $heightforinfotot = 50 + (4 * $nbpayments);
303 if ($heightforinfotot > 220) {
304 $heightforinfotot = 220;
306 $heightforfreetext = (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->MAIN_PDF_FREETEXT_HEIGHT : 5);
307 $heightforfooter = $this->marge_basse + 8;
309 $heightforfooter += 6;
312 $heightforqrinvoice_firstpage = 0;
315 if ($heightforqrinvoice_firstpage > 0) {
317 $heightforinfotot = 30 + (4 * $nbpayments);
321 if (class_exists(
'TCPDF')) {
322 $pdf->setPrintHeader(
false);
323 $pdf->setPrintFooter(
false);
329 $logodir = $conf->mycompany->dir_output;
330 if (!empty($conf->mycompany->multidir_output[
$object->entity])) {
331 $logodir = $conf->mycompany->multidir_output[
$object->entity];
333 $pagecount = $pdf->setSourceFile($logodir.
'/' .
getDolGlobalString(
'MAIN_ADD_PDF_BACKGROUND'));
334 $tplidx = $pdf->importPage(1);
339 $pdf->SetDrawColor(128, 128, 128);
341 $pdf->SetTitle($outputlangs->convToOutputCharset(
$object->ref));
342 $pdf->SetSubject($outputlangs->transnoentities(
"PdfInvoiceTitle"));
343 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
344 $pdf->SetAuthor($mysoc->name.($user->id > 0 ?
' - '.$outputlangs->convToOutputCharset($user->getFullName($outputlangs)) :
''));
345 $pdf->SetKeyWords($outputlangs->convToOutputCharset(
$object->ref).
" ".$outputlangs->transnoentities(
"PdfInvoiceTitle").
" ".$outputlangs->convToOutputCharset(
$object->thirdparty->name));
347 $pdf->SetCompression(
false);
351 $cert = empty($user->conf->CERTIFICATE_CRT) ?
'' : $user->conf->CERTIFICATE_CRT;
352 $certprivate = empty($user->conf->CERTIFICATE_CRT_PRIVATE) ?
'' : $user->conf->CERTIFICATE_CRT_PRIVATE;
358 $certprivate = !
getDolGlobalString(
'CERTIFICATE_CRT_PRIVATE') ?
'' : $conf->global->CERTIFICATE_CRT_PRIVATE;
363 'Name' => $this->emetteur->name,
364 'Location' =>
getCountry($this->emetteur->country_code, 0),
365 'Reason' =>
'INVOICE',
366 'ContactInfo' => $this->emetteur->email
368 $pdf->setSignature($cert, $certprivate, $this->emetteur->name,
'', 2, $info);
372 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
376 $categoryOfOperation = 0;
379 for ($i = 0; $i < $nblines; $i++) {
380 if (
$object->lines[$i]->remise_percent) {
381 $this->atleastonediscount++;
385 if ($categoryOfOperation < 2) {
386 $lineProductType =
$object->lines[$i]->product_type;
392 if ($nbProduct > 0 && $nbService > 0) {
394 $categoryOfOperation = 2;
399 if ($categoryOfOperation <= 0) {
401 if ($nbProduct == 0 && $nbService > 0) {
402 $categoryOfOperation = 1;
405 $this->categoryOfOperation = $categoryOfOperation;
406 if (empty($this->atleastonediscount)) {
407 $delta = ($this->posxprogress - $this->posxdiscount);
408 $this->posxpicture += $delta;
409 $this->posxtva += $delta;
410 $this->posxup += $delta;
411 $this->posxqty += $delta;
412 $this->posxunit += $delta;
413 $this->posxdiscount += $delta;
420 $this->situationinvoice =
true;
421 $progress_width = 10;
422 $this->posxpicture -= $progress_width;
423 $this->posxtva -= $progress_width;
424 $this->posxup -= $progress_width;
425 $this->posxqty -= $progress_width;
426 $this->posxunit -= $progress_width;
427 $this->posxdiscount -= $progress_width;
428 $this->posxprogress -= $progress_width;
433 if (!empty($tplidx)) {
434 $pdf->useTemplate($tplidx);
440 $pdf->SetFont(
'',
'', $default_font_size - 1);
441 $pdf->MultiCell(0, 3,
'');
442 $pdf->SetTextColor(0, 0, 0);
447 $tab_top = 90 + $top_shift;
448 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
451 $extra_under_address_shift = 0;
454 $qrcodestring =
$object->buildZATCAQRString();
457 $qrcodestring =
$object->buildSwitzerlandQRString();
461 $qrcodestring =
$object->buildEPCQrCodeString();
466 $qrcodecolor = array(
'25',
'25',
'25');
471 'fgcolor' => $qrcodecolor,
476 $pdf->write2DBarcode($qrcodestring,
'QRCODE,M', $this->marge_gauche, $tab_top - 5, 25, 25, $styleQr,
'N');
480 $pdf->SetXY($this->marge_gauche + 30, $pdf->GetY() - 15);
481 $pdf->SetFont(
'',
'', $default_font_size - 4);
482 $pdf->MultiCell(40, 3, $langs->transnoentitiesnoconv(
"INVOICE_ADD_EPC_QR_CODEPay"), 0,
'L', 0);
486 $extra_under_address_shift += 25;
494 'outputlangs' => $outputlangs,
495 'hidedetails' => $hidedetails
497 $reshook = $hookmanager->executeHooks(
'printUnderHeaderPDFline', $parameters, $this);
498 if (!empty($hookmanager->resArray[
'extra_under_address_shift'])) {
499 $extra_under_address_shift += $hookmanager->resArray[
'extra_under_address_shift'];
502 $tab_top += $extra_under_address_shift;
503 $tab_top_newpage += 0;
506 $height_incoterms = 0;
507 if (isModEnabled(
'incoterm')) {
508 $desc_incoterms =
$object->getIncotermsForPDF();
509 if ($desc_incoterms) {
512 $pdf->SetFont(
'',
'', $default_font_size - 1);
513 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1,
dol_htmlentitiesbr($desc_incoterms), 0, 1);
514 $nexY = $pdf->GetY();
515 $height_incoterms = $nexY - $tab_top;
518 $pdf->SetDrawColor(192, 192, 192);
519 $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_incoterms + 1);
521 $tab_top = $nexY + 6;
526 $notetoshow = empty(
$object->note_public) ?
'' :
$object->note_public;
529 if (is_object(
$object->thirdparty)) {
530 $salereparray =
$object->thirdparty->getSalesRepresentatives($user);
531 $salerepobj =
new User($this->db);
532 $salerepobj->fetch($salereparray[0][
'id']);
533 if (!empty($salerepobj->signature)) {
534 $notetoshow =
dol_concatdesc($notetoshow, $salerepobj->signature);
539 $extranote = $this->getExtrafieldsInHtml(
$object, $outputlangs);
540 if (!empty($extranote)) {
552 $pdf->SetFont(
'',
'', $default_font_size - 1);
553 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1,
dol_htmlentitiesbr($notetoshow), 0, 1);
554 $nexY = $pdf->GetY();
555 $height_note = $nexY - $tab_top;
558 $pdf->SetDrawColor(192, 192, 192);
559 $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1);
561 $tab_top = $nexY + 6;
564 $iniY = $tab_top + 7;
565 $curY = $tab_top + 7;
566 $nexY = $tab_top + 7;
569 for ($i = 0; $i < $nblines; $i++) {
571 $pdf->SetFont(
'',
'', $default_font_size - 1);
572 $pdf->SetTextColor(0, 0, 0);
575 $imglinesize = array();
576 if (!empty($realpatharray[$i])) {
580 $pdf->setTopMargin($tab_top_newpage);
581 $page_bottom_margin = $heightforfooter + $heightforfreetext + $heightforinfotot + $this->
getHeightForQRInvoice($pdf->getPage(),
$object, $langs);
582 $pdf->setPageOrientation(
'', 1, $page_bottom_margin);
583 $pageposbefore = $pdf->getPage();
585 $showpricebeforepagebreak = 1;
587 $posYAfterDescription = 0;
590 if (isset($imglinesize[
'width']) && isset($imglinesize[
'height']) && ($curY + $imglinesize[
'height']) > ($this->page_hauteur - $page_bottom_margin)) {
591 $pdf->AddPage(
'',
'',
true);
592 if (!empty($tplidx)) {
593 $pdf->useTemplate($tplidx);
597 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
599 $pdf->setPage($pageposbefore + 1);
601 $curY = $tab_top_newpage;
605 $showpricebeforepagebreak = 1;
607 $showpricebeforepagebreak = 0;
611 if (isset($imglinesize[
'width']) && isset($imglinesize[
'height'])) {
612 $curX = $this->posxpicture - 1;
613 $pdf->Image($realpatharray[$i], $curX + (($this->posxtva - $this->posxpicture - $imglinesize[
'width']) / 2), $curY, $imglinesize[
'width'], $imglinesize[
'height'],
'',
'',
'', 2, 300);
615 $posYAfterImage = $curY + $imglinesize[
'height'];
619 $curX = $this->posxdesc - 1;
621 $pdf->startTransaction();
622 pdf_writelinedesc($pdf,
$object, $i, $outputlangs, $this->posxpicture - $curX - $progress_width, 3, $curX, $curY, $hideref, $hidedesc);
623 $pageposafter = $pdf->getPage();
624 if ($pageposafter > $pageposbefore) {
625 $pdf->rollbackTransaction(
true);
626 $pageposafter = $pageposbefore;
628 $pdf->setPageOrientation(
'', 1, $heightforfooter);
629 pdf_writelinedesc($pdf,
$object, $i, $outputlangs, $this->posxpicture - $curX - $progress_width, 3, $curX, $curY, $hideref, $hidedesc);
630 $pageposafter = $pdf->getPage();
631 $posyafter = $pdf->GetY();
633 if ($posyafter > ($this->page_hauteur - $page_bottom_margin)) {
634 if ($i == ($nblines - 1)) {
635 $pdf->AddPage(
'',
'',
true);
636 if (!empty($tplidx)) {
637 $pdf->useTemplate($tplidx);
641 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
643 $pdf->setPage($pageposafter + 1);
650 $showpricebeforepagebreak = 1;
652 $showpricebeforepagebreak = 0;
656 $pdf->commitTransaction();
658 $posYAfterDescription = $pdf->GetY();
660 $nexY = $pdf->GetY();
661 $pageposafter = $pdf->getPage();
662 $pdf->setPage($pageposbefore);
663 $pdf->setTopMargin($this->marge_haute);
664 $pdf->setPageOrientation(
'', 1, 0);
667 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
668 $pdf->setPage($pageposafter);
669 $curY = $tab_top_newpage;
672 $pdf->SetFont(
'',
'', $default_font_size - 1);
677 $pdf->SetXY($this->posxtva - 5, $curY);
678 $pdf->MultiCell($this->posxup - $this->posxtva + 4, 3, $vat_rate, 0,
'R');
683 $pdf->SetXY($this->posxup, $curY);
684 $pdf->MultiCell($this->posxqty - $this->posxup - 0.8, 3, $up_excl_tax, 0,
'R', 0);
688 $pdf->SetXY($this->posxqty, $curY);
689 $pdf->MultiCell($this->posxunit - $this->posxqty - 0.8, 4, $qty, 0,
'R');
694 $pdf->SetXY($this->posxunit, $curY);
695 $pdf->MultiCell($this->posxdiscount - $this->posxunit - 0.8, 4, $unit, 0,
'L');
699 if (
$object->lines[$i]->remise_percent) {
700 $pdf->SetXY($this->posxdiscount - 2, $curY);
702 $pdf->MultiCell($this->posxprogress - $this->posxdiscount + 2, 3, $remise_percent, 0,
'R');
706 if ($this->situationinvoice) {
708 $pdf->SetXY($this->posxprogress, $curY);
709 $pdf->MultiCell($this->postotalht - $this->posxprogress + 1, 3, $progress, 0,
'R');
714 $pdf->SetXY($this->postotalht, $curY);
715 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->postotalht, 3, $total_excl_tax, 0,
'R', 0);
723 $prev_progress =
$object->lines[$i]->get_prev_progress(
$object->id);
724 if ($prev_progress > 0 && !empty(
$object->lines[$i]->situation_percent)) {
725 if (isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) {
726 $tvaligne = $sign *
$object->lines[$i]->multicurrency_total_tva * (
$object->lines[$i]->situation_percent - $prev_progress) /
$object->lines[$i]->situation_percent;
728 $tvaligne = $sign *
$object->lines[$i]->total_tva * (
$object->lines[$i]->situation_percent - $prev_progress) /
$object->lines[$i]->situation_percent;
731 if (isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) {
732 $tvaligne = $sign *
$object->lines[$i]->multicurrency_total_tva;
734 $tvaligne = $sign *
$object->lines[$i]->total_tva;
738 $localtax1ligne =
$object->lines[$i]->total_localtax1;
739 $localtax2ligne =
$object->lines[$i]->total_localtax2;
740 $localtax1_rate =
$object->lines[$i]->localtax1_tx;
741 $localtax2_rate =
$object->lines[$i]->localtax2_tx;
742 $localtax1_type =
$object->lines[$i]->localtax1_type;
743 $localtax2_type =
$object->lines[$i]->localtax2_type;
756 $vatrate = (string)
$object->lines[$i]->tva_tx;
759 if ((!isset($localtax1_type) || $localtax1_type ==
'' || !isset($localtax2_type) || $localtax2_type ==
'')
760 && (!empty($localtax1_rate) || !empty($localtax2_rate))) {
762 $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] :
'';
763 $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] :
'';
767 if ($localtax1_type && $localtax1ligne != 0) {
768 if (empty($this->localtax1[$localtax1_type][$localtax1_rate])) {
769 $this->localtax1[$localtax1_type][$localtax1_rate] = $localtax1ligne;
771 $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
774 if ($localtax2_type && $localtax2ligne != 0) {
775 if (empty($this->localtax2[$localtax2_type][$localtax2_rate])) {
776 $this->localtax2[$localtax2_type][$localtax2_rate] = $localtax2ligne;
778 $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
782 if ((
$object->lines[$i]->info_bits & 0x01) == 0x01) {
787 if (!isset($this->tva[$vatrate])) {
788 $this->tva[$vatrate] = 0;
790 $this->tva[$vatrate] += $tvaligne;
791 $vatcode =
$object->lines[$i]->vat_src_code;
792 if (empty($this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'])) {
793 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] = 0;
795 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')] = array(
'vatrate' => $vatrate,
'vatcode' => $vatcode,
'amount' => $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] + $tvaligne);
797 if ($posYAfterImage > $posYAfterDescription) {
798 $nexY = $posYAfterImage;
803 $pdf->setPage($pageposafter);
804 $pdf->SetLineStyle(array(
'dash' =>
'1,1',
'color' => array(80, 80, 80)));
806 $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
807 $pdf->SetLineStyle(array(
'dash' => 0));
813 while ($pagenb < $pageposafter) {
814 $pdf->setPage($pagenb);
816 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter - $heightforqrinvoice_firstpage, 0, $outputlangs, 0, 1,
$object->multicurrency_code);
818 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1,
$object->multicurrency_code);
822 $pdf->setPage($pagenb);
823 $pdf->setPageOrientation(
'', 1, 0);
826 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
828 if (!empty($tplidx)) {
829 $pdf->useTemplate($tplidx);
832 if (isset(
$object->lines[$i + 1]->pagebreak) &&
$object->lines[$i + 1]->pagebreak) {
834 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter - $heightforqrinvoice_firstpage, 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);
841 if (!empty($tplidx)) {
842 $pdf->useTemplate($tplidx);
847 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
854 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter - $heightforqrinvoice_firstpage, 0, $outputlangs, 0, 0,
$object->multicurrency_code);
855 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter - $heightforqrinvoice_firstpage + 1;
857 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0,
$object->multicurrency_code);
858 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
860 dol_syslog(
"bottomlasttab=".$bottomlasttab.
" this->page_hauteur=".$this->page_hauteur.
" heightforinfotot=".$heightforinfotot.
" heightforfreetext=".$heightforfreetext.
" heightforfooter=".$heightforfooter);
866 $posy = $this->
_tableau_tot($pdf,
$object, $deja_regle, $bottomlasttab, $outputlangs, $outputlangsbis);
869 if (($deja_regle || $amount_credit_notes_included || $amount_deposits_included) && !
getDolGlobalString(
'INVOICE_NO_PAYMENT_DETAILS')) {
875 if (method_exists($pdf,
'AliasNbPages')) {
876 $pdf->AliasNbPages();
888 $pdf->Output($file,
'F');
891 $hookmanager->initHooks(array(
'pdfgeneration'));
892 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
894 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
896 $this->error = $hookmanager->error;
897 $this->errors = $hookmanager->errors;
902 $this->result = array(
'fullpath' => $file);
906 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
910 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"FAC_OUTPUTDIR");
937 $current_page = $pdf->getPage();
939 $tab3_top = $posy + 8;
942 if ($this->page_largeur < 210) {
952 $pdf->SetFont(
'',
'', $default_font_size - 4);
956 $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,";
957 $sql .=
" re.description, re.fk_facture_source,";
958 $sql .=
" f.type, f.datef";
959 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as re, ".MAIN_DB_PREFIX.
"facture as f";
960 $sql .=
" WHERE re.fk_facture_source = f.rowid AND re.fk_facture = ".((int)
$object->id);
961 $resql = $this->db->query($sql);
963 $num = $this->db->num_rows($resql);
965 $invoice =
new Facture($this->db);
968 if ($tab3_top + $y >= ($this->page_hauteur - $heightforfooter)) {
971 $pdf->AddPage(
'',
'',
true);
977 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
979 $pdf->setPage($current_page);
983 $obj = $this->db->fetch_object($resql);
985 if ($obj->type == 2) {
986 $text = $outputlangs->transnoentities(
"CreditNote");
987 } elseif ($obj->type == 3) {
988 $text = $outputlangs->transnoentities(
"Deposit");
989 } elseif ($obj->type == 0) {
990 $text = $outputlangs->transnoentities(
"ExcessReceived");
992 $text = $outputlangs->transnoentities(
"UnknownType");
995 $invoice->fetch($obj->fk_facture_source);
997 $pdf->SetXY($tab3_posx, $tab3_top + $y);
998 $pdf->MultiCell(20, 3,
dol_print_date($this->db->jdate($obj->datef),
'day',
false, $outputlangs,
true), 0,
'L', 0);
999 $pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
1000 $pdf->MultiCell(20, 3,
price((isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? $obj->multicurrency_amount_ttc : $obj->amount_ttc, 0, $outputlangs), 0,
'L', 0);
1001 $pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
1002 $pdf->MultiCell(20, 3, $text, 0,
'L', 0);
1003 $pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
1004 $pdf->MultiCell(20, 3, $invoice->ref, 0,
'L', 0);
1006 $pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
1011 $this->error = $this->db->lasterror();
1017 $sql =
"SELECT p.datep as date, p.fk_paiement, p.num_paiement as num, pf.amount as amount, pf.multicurrency_amount,";
1019 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiement_facture as pf, ".MAIN_DB_PREFIX.
"paiement as p";
1020 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as cp ON p.fk_paiement = cp.id";
1021 $sql .=
" WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = ".((int)
$object->id);
1023 $sql .=
" ORDER BY p.datep";
1025 $resql = $this->db->query($sql);
1027 $num = $this->db->num_rows($resql);
1032 if ($tab3_top + $y >= ($this->page_hauteur - $heightforfooter)) {
1035 $pdf->AddPage(
'',
'',
true);
1041 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
1043 $pdf->setPage($current_page);
1047 $row = $this->db->fetch_object($resql);
1049 $pdf->SetXY($tab3_posx, $tab3_top + $y);
1050 $pdf->MultiCell(20, 3,
dol_print_date($this->db->jdate($row->date),
'day',
false, $outputlangs,
true), 0,
'L', 0);
1051 $pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
1052 $pdf->MultiCell(20, 3,
price($sign * ((isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? $row->multicurrency_amount : $row->amount), 0, $outputlangs), 0,
'L', 0);
1053 $pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
1054 $oper = $outputlangs->transnoentitiesnoconv(
"PaymentTypeShort".$row->code);
1056 $pdf->MultiCell(20, 3, $oper, 0,
'L', 0);
1057 $maxY = max($pdf->GetY() - $tab3_top - 3, $maxY);
1058 $pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
1059 $pdf->MultiCell(30, 3, $row->num, 0,
'L', 0);
1060 $y = $maxY = max($pdf->GetY() - $tab3_top - 3, $maxY);
1061 $pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
1066 return $tab3_top + $y + 3;
1068 $this->error = $this->db->lasterror();
1130 global $conf, $mysoc, $hookmanager;
1134 $pdf->SetFont(
'',
'', $default_font_size - 1);
1137 if ($this->emetteur->country_code ==
'FR' && empty($mysoc->tva_assuj)) {
1138 $pdf->SetFont(
'',
'B', $default_font_size - 2);
1139 $pdf->SetXY($this->marge_gauche, $posy);
1140 if ($mysoc->forme_juridique_code == 92) {
1141 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"VATIsNotUsedForInvoiceAsso"), 0,
'L', 0);
1143 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"VATIsNotUsedForInvoice"), 0,
'L', 0);
1146 $posy = $pdf->GetY() + 4;
1151 if ($this->page_largeur < 210) {
1157 $pdf->SetFont(
'',
'B', $default_font_size - 2);
1158 $pdf->SetXY($this->marge_gauche, $posy);
1159 $titre = $outputlangs->transnoentities(
"PaymentConditions").
':';
1160 $pdf->MultiCell(43, 4, $titre, 0,
'L');
1162 $pdf->SetFont(
'',
'', $default_font_size - 2);
1163 $pdf->SetXY($posxval, $posy);
1164 $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);
1165 $lib_condition_paiement = str_replace(
'\n',
"\n", $lib_condition_paiement);
1166 $pdf->MultiCell(67, 4, $lib_condition_paiement, 0,
'L');
1168 $posy = $pdf->GetY() + 3;
1172 if (
getDolGlobalInt(
'INVOICE_CATEGORY_OF_OPERATION') == 2 && $this->categoryOfOperation >= 0) {
1173 $pdf->SetFont(
'',
'B', $default_font_size - 2);
1174 $pdf->SetXY($this->marge_gauche, $posy);
1175 $categoryOfOperationTitle = $outputlangs->transnoentities(
"MentionCategoryOfOperations").
' : ';
1176 $pdf->MultiCell($posxval - $this->marge_gauche, 4, $categoryOfOperationTitle, 0,
'L');
1178 $pdf->SetFont(
'',
'', $default_font_size - 2);
1179 $pdf->SetXY($posxval, $posy);
1180 $categoryOfOperationLabel = $outputlangs->transnoentities(
"MentionCategoryOfOperations" . $this->categoryOfOperation);
1181 $pdf->MultiCell($posxend - $posxval, 4, $categoryOfOperationLabel, 0,
'L');
1183 $posy = $pdf->GetY() + 3;
1188 if (empty(
$object->mode_reglement_code)
1191 $this->error = $outputlangs->transnoentities(
"ErrorNoPaiementModeConfigured");
1195 $outputlangs->load(
"errors");
1197 $pdf->SetXY($this->marge_gauche, $posy);
1198 $pdf->SetTextColor(200, 0, 0);
1199 $pdf->SetFont(
'',
'B', $default_font_size - 2);
1200 $this->error = $outputlangs->transnoentities(
"ErrorPaymentModeDefinedToWithoutSetup",
$object->mode_reglement_code);
1201 $pdf->MultiCell(80, 3, $this->error, 0,
'L', 0);
1202 $pdf->SetTextColor(0, 0, 0);
1204 $posy = $pdf->GetY() + 1;
1208 if (!empty(
$object->mode_reglement_code)
1209 &&
$object->mode_reglement_code !=
'CHQ'
1210 &&
$object->mode_reglement_code !=
'VIR') {
1211 $pdf->SetFont(
'',
'B', $default_font_size - 2);
1212 $pdf->SetXY($this->marge_gauche, $posy);
1213 $titre = $outputlangs->transnoentities(
"PaymentMode").
':';
1214 $pdf->MultiCell(80, 5, $titre, 0,
'L');
1216 $pdf->SetFont(
'',
'', $default_font_size - 2);
1217 $pdf->SetXY($posxval, $posy);
1218 $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);
1220 if (
$object->mode_reglement_code ==
"PRE") {
1221 require_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
1224 $bac->fetch(0,
'',
$object->thirdparty->id);
1225 $iban = $bac->iban.(($bac->iban && $bac->bic) ?
' / ' :
'').$bac->bic;
1226 $lib_mode_reg .=
' '.$outputlangs->trans(
"PaymentTypePREdetails",
dol_trunc($iban, 6,
'right',
'UTF-8', 1));
1228 $pdf->MultiCell(80, 5, $lib_mode_reg, 0,
'L');
1230 $posy = $pdf->GetY();
1236 if ($this->emetteur->country_code ==
'FR') {
1238 $pdf->SetXY($this->marge_gauche, $posy);
1239 $pdf->writeHTMLCell(80, 5,
'',
'', $outputlangs->transnoentities(
"MentionVATDebitOptionIsOn"), 0, 1);
1241 $posy = $pdf->GetY() + 1;
1246 if (empty(
$object->mode_reglement_code) ||
$object->mode_reglement_code ==
'CB' ||
$object->mode_reglement_code ==
'VAD') {
1247 $useonlinepayment = 0;
1251 include_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
1252 $validpaymentmethod = getValidOnlinePaymentMethods(
'');
1253 $useonlinepayment = count($validpaymentmethod);
1257 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
1260 $langs->loadLangs(array(
'payment',
'paybox',
'stripe'));
1261 $servicename = $langs->transnoentities(
'Online');
1262 $paiement_url = getOnlinePaymentUrl(
'',
'invoice',
$object->ref,
'',
'',
'');
1263 $linktopay = $langs->trans(
"ToOfferALinkForOnlinePayment", $servicename).
' <a href="'.$paiement_url.
'">'.$outputlangs->transnoentities(
"ClickHere").
'</a>';
1265 $pdf->SetXY($this->marge_gauche, $posy);
1268 $posy = $pdf->GetY() + 1;
1273 if (empty(
$object->mode_reglement_code) ||
$object->mode_reglement_code ==
'CHQ') {
1276 $diffsizetitle = (!
getDolGlobalString(
'PDF_DIFFSIZE_TITLE') ? 3 : $conf->global->PDF_DIFFSIZE_TITLE);
1279 $account =
new Account($this->db);
1282 $pdf->SetXY($this->marge_gauche, $posy);
1283 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1284 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
'PaymentByChequeOrderedTo', $account->owner_name), 0,
'L', 0);
1285 $posy = $pdf->GetY() + 1;
1288 $pdf->SetXY($this->marge_gauche, $posy);
1289 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1290 $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($account->owner_address), 0,
'L', 0);
1291 $posy = $pdf->GetY() + 2;
1294 if ($conf->global->FACTURE_CHQ_NUMBER == -1) {
1295 $pdf->SetXY($this->marge_gauche, $posy);
1296 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
1297 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
'PaymentByChequeOrderedTo', $this->emetteur->name), 0,
'L', 0);
1298 $posy = $pdf->GetY() + 1;
1301 $pdf->SetXY($this->marge_gauche, $posy);
1302 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
1303 $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0,
'L', 0);
1304 $posy = $pdf->GetY() + 2;
1311 if (empty(
$object->mode_reglement_code) ||
$object->mode_reglement_code ==
'VIR') {
1313 $bankid = (
$object->fk_account <= 0 ? $conf->global->FACTURE_RIB_NUMBER :
$object->fk_account);
1317 $account =
new Account($this->db);
1318 $account->fetch($bankid);
1320 $curx = $this->marge_gauche;
1323 $posy =
pdf_bank($pdf, $outputlangs, $curx, $cury, $account, 0, $default_font_size);
1350 global $conf, $mysoc, $hookmanager;
1359 $outputlangsbis =
null;
1361 $outputlangsbis =
new Translate(
'', $conf);
1363 $outputlangsbis->loadLangs(array(
"main",
"dict",
"companies",
"bills",
"products",
"propal"));
1364 $default_font_size--;
1369 $pdf->SetFont(
'',
'', $default_font_size - 1);
1374 if ($this->page_largeur < 210) {
1378 $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
1384 $pdf->SetFillColor(255, 255, 255);
1385 $pdf->SetXY($col1x, $tab2_top);
1386 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(!
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT') ?
"TotalHT" :
"Total").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(!
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT') ?
"TotalHT" :
"Total") :
''), 0,
'L', 1);
1388 $total_ht = ((isModEnabled(
"multicurrency") && isset(
$object->multicurrency_tx) &&
$object->multicurrency_tx != 1) ?
$object->multicurrency_total_ht :
$object->total_ht);
1389 $pdf->SetXY($col2x, $tab2_top);
1390 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * ($total_ht + (!empty(
$object->remise) ?
$object->remise : 0)), 0, $outputlangs), 0,
'R', 1);
1393 $pdf->SetFillColor(248, 248, 248);
1395 $total_ttc = (isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ?
$object->multicurrency_total_ttc :
$object->total_ttc;
1397 $this->atleastoneratenotnull = 0;
1399 $tvaisnull = ((!empty($this->tva) && count($this->tva) == 1 && isset($this->tva[
'0.000']) && is_float($this->tva[
'0.000'])) ?
true :
false);
1400 if (
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL') && $tvaisnull) {
1404 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1405 if (in_array((
string) $localtax_type, array(
'1',
'3',
'5'))) {
1409 foreach ($localtax_rate as $tvakey => $tvaval) {
1414 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1417 if (preg_match(
'/\*/', (
string) $tvakey)) {
1418 $tvakey = str_replace(
'*',
'', (
string) $tvakey);
1419 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1422 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT1", $mysoc->country_code) :
'');
1426 $totalvat .= $tvacompl;
1428 $totalvat .=
vatrate(abs($tvakey), 1).$tvacompl;
1431 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1433 $total_localtax = ((isModEnabled(
"multicurrency") && isset(
$object->multicurrency_tx) &&
$object->multicurrency_tx != 1) ?
price2num($tvaval *
$object->multicurrency_tx,
'MT') : $tvaval);
1435 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1436 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R', 1);
1442 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1443 if (in_array((
string) $localtax_type, array(
'1',
'3',
'5'))) {
1447 foreach ($localtax_rate as $tvakey => $tvaval) {
1452 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1455 if (preg_match(
'/\*/', (
string) $tvakey)) {
1456 $tvakey = str_replace(
'*',
'', (
string) $tvakey);
1457 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1459 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT2", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT2", $mysoc->country_code) :
'');
1463 $totalvat .= $tvacompl;
1465 $totalvat .=
vatrate(abs($tvakey), 1).$tvacompl;
1468 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1470 $total_localtax = ((isModEnabled(
"multicurrency") && isset(
$object->multicurrency_tx) &&
$object->multicurrency_tx != 1) ?
price2num($tvaval *
$object->multicurrency_tx,
'MT') : $tvaval);
1472 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1473 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R', 1);
1479 foreach ($this->tva_array as $tvakey => $tvaval) {
1481 $this->atleastoneratenotnull++;
1484 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1487 if (preg_match(
'/\*/', $tvakey)) {
1488 $tvakey = str_replace(
'*',
'', $tvakey);
1489 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1491 $totalvat = $outputlangs->transcountrynoentities(
"TotalVAT", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalVAT", $mysoc->country_code) :
'');
1494 $totalvat .=
vatrate($tvaval[
'vatrate'], 1).$tvacompl;
1496 $totalvat .= $tvaval[
'vatcode'].$tvacompl;
1498 $totalvat .= $tvacompl;
1500 $totalvat .=
vatrate($tvaval[
'vatrate'], 1).($tvaval[
'vatcode'] ?
' ('.$tvaval[
'vatcode'].
')' :
'').$tvacompl;
1502 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1504 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1505 $pdf->MultiCell($largcol2, $tab2_hl,
price(
price2num($tvaval[
'amount'],
'MT'), 0, $outputlangs), 0,
'R', 1);
1510 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1511 if (in_array((
string) $localtax_type, array(
'2',
'4',
'6'))) {
1515 foreach ($localtax_rate as $tvakey => $tvaval) {
1520 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1523 if (preg_match(
'/\*/', (
string) $tvakey)) {
1524 $tvakey = str_replace(
'*',
'', (
string) $tvakey);
1525 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1527 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1", $mysoc->country_code).
' ';
1530 $totalvat .= $tvacompl;
1532 $totalvat .=
vatrate(abs($tvakey), 1).$tvacompl;
1535 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1537 $total_localtax = ((isModEnabled(
"multicurrency") && isset(
$object->multicurrency_tx) &&
$object->multicurrency_tx != 1) ?
price2num($tvaval *
$object->multicurrency_tx,
'MT') : $tvaval);
1539 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1540 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R', 1);
1546 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1547 if (in_array((
string) $localtax_type, array(
'2',
'4',
'6'))) {
1551 foreach ($localtax_rate as $tvakey => $tvaval) {
1555 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1558 if (preg_match(
'/\*/', (
string) $tvakey)) {
1559 $tvakey = str_replace(
'*',
'', (
string) $tvakey);
1560 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1562 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT2", $mysoc->country_code).
' ';
1565 $totalvat .= $tvacompl;
1567 $totalvat .=
vatrate(abs($tvakey), 1).$tvacompl;
1570 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1572 $total_localtax = ((isModEnabled(
"multicurrency") && isset(
$object->multicurrency_tx) &&
$object->multicurrency_tx != 1) ?
price2num($tvaval *
$object->multicurrency_tx,
'MT') : $tvaval);
1574 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1575 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R', 1);
1582 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1583 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"RevenueStamp"), $useborder,
'L', 1);
1585 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1586 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign *
$object->revenuestamp), $useborder,
'R', 1);
1591 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1592 $pdf->SetTextColor(0, 0, 60);
1593 $pdf->SetFillColor(224, 224, 224);
1594 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalTTC"), $useborder,
'L', 1);
1596 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1597 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * $total_ttc, 0, $outputlangs), $useborder,
'R', 1);
1600 if (
$object->displayRetainedWarranty()) {
1601 $pdf->SetTextColor(40, 40, 40);
1602 $pdf->SetFillColor(255, 255, 255);
1604 $retainedWarranty =
$object->getRetainedWarrantyAmount();
1605 $billedWithRetainedWarranty =
$object->total_ttc - $retainedWarranty;
1609 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1610 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"ToPayOn",
dol_print_date(
$object->date_lim_reglement,
'day')), $useborder,
'L', 1);
1612 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1613 $pdf->MultiCell($largcol2, $tab2_hl,
price($billedWithRetainedWarranty), $useborder,
'R', 1);
1617 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1619 $retainedWarrantyToPayOn = $outputlangs->transnoentities(
"RetainedWarranty").
' ('.
$object->retained_warranty.
'%)';
1620 $retainedWarrantyToPayOn .= !empty(
$object->retained_warranty_date_limit) ?
' '.$outputlangs->transnoentities(
"toPayOn",
dol_print_date(
$object->retained_warranty_date_limit,
'day')) :
'';
1622 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $retainedWarrantyToPayOn, $useborder,
'L', 1);
1623 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1624 $pdf->MultiCell($largcol2, $tab2_hl,
price($retainedWarranty), $useborder,
'R', 1);
1629 $pdf->SetTextColor(0, 0, 0);
1630 $creditnoteamount =
$object->getSumCreditNotesUsed((isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? 1 : 0);
1631 $depositsamount =
$object->getSumDepositsUsed((isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? 1 : 0);
1633 $resteapayer =
price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount,
'MT');
1638 if (($deja_regle > 0 || $creditnoteamount > 0 || $depositsamount > 0) && !
getDolGlobalString(
'INVOICE_NO_PAYMENT_DETAILS')) {
1641 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1642 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"Paid"), 0,
'L', 0);
1643 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1644 $pdf->MultiCell($largcol2, $tab2_hl,
price($deja_regle + $depositsamount, 0, $outputlangs), 0,
'R', 0);
1647 if ($creditnoteamount) {
1648 $labeltouse = ($outputlangs->transnoentities(
"CreditNotesOrExcessReceived") !=
"CreditNotesOrExcessReceived") ? $outputlangs->transnoentities(
"CreditNotesOrExcessReceived") : $outputlangs->transnoentities(
"CreditNotes");
1650 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1651 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $labeltouse, 0,
'L', 0);
1652 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1653 $pdf->MultiCell($largcol2, $tab2_hl,
price($creditnoteamount, 0, $outputlangs), 0,
'R', 0);
1657 if (
$object->close_code == Facture::CLOSECODE_DISCOUNTVAT) {
1659 $pdf->SetFillColor(255, 255, 255);
1661 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1662 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"EscompteOfferedShort"), $useborder,
'L', 1);
1663 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1664 $pdf->MultiCell($largcol2, $tab2_hl,
price(
$object->total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 0, $outputlangs), $useborder,
'R', 1);
1670 $pdf->SetTextColor(0, 0, 60);
1671 $pdf->SetFillColor(224, 224, 224);
1672 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1673 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"RemainderToPay"), $useborder,
'L', 1);
1674 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1675 $pdf->MultiCell($largcol2, $tab2_hl,
price($resteapayer, 0, $outputlangs), $useborder,
'R', 1);
1677 $pdf->SetFont(
'',
'', $default_font_size - 1);
1678 $pdf->SetTextColor(0, 0, 0);
1686 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1687 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $conf->global->BILL_TEXT_TOTAL_FOOTER, 0,
'L', 0);
1690 return ($tab2_top + ($tab2_hl * $index));
1707 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency =
'')
1717 $currency = !empty($currency) ? $currency : $conf->currency;
1721 $pdf->SetTextColor(0, 0, 0);
1722 $pdf->SetFont(
'',
'', $default_font_size - 2);
1724 if (empty($hidetop)) {
1726 if (
getDolGlobalInt(
'INVOICE_CATEGORY_OF_OPERATION') == 1 && $this->categoryOfOperation >= 0) {
1727 $categoryOfOperations = $outputlangs->transnoentities(
"MentionCategoryOfOperations") .
' : ' . $outputlangs->transnoentities(
"MentionCategoryOfOperations" . $this->categoryOfOperation);
1728 $pdf->SetXY($this->marge_gauche, $tab_top - 4);
1729 $pdf->MultiCell(($pdf->GetStringWidth($categoryOfOperations)) + 4, 2, $categoryOfOperations);
1732 $titre = $outputlangs->transnoentities(
"AmountInCurrency", $outputlangs->transnoentitiesnoconv(
"Currency".$currency));
1733 $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
1734 $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
1738 $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_droite - $this->marge_gauche, 5,
'F',
null, explode(
',',
getDolGlobalString(
'MAIN_PDF_TITLE_BACKGROUND_COLOR')));
1742 $pdf->SetDrawColor(128, 128, 128);
1743 $pdf->SetFont(
'',
'', $default_font_size - 1);
1746 $this->
printRect($pdf, $this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $tab_height, $hidetop, $hidebottom);
1748 if (empty($hidetop)) {
1749 $pdf->line($this->marge_gauche, $tab_top + 5, $this->page_largeur - $this->marge_droite, $tab_top + 5);
1751 $pdf->SetXY($this->posxdesc - 1, $tab_top + 1);
1752 $pdf->MultiCell(108, 2, $outputlangs->transnoentities(
"Designation"),
'',
'L');
1756 $pdf->line($this->posxpicture - 1, $tab_top, $this->posxpicture - 1, $tab_top + $tab_height);
1757 if (empty($hidetop)) {
1764 $pdf->line($this->posxtva - 1, $tab_top, $this->posxtva - 1, $tab_top + $tab_height);
1765 if (empty($hidetop)) {
1766 $pdf->SetXY($this->posxtva - 3, $tab_top + 1);
1767 $pdf->MultiCell($this->posxup - $this->posxtva + 3, 2, $outputlangs->transnoentities(
"VAT"),
'',
'C');
1771 $pdf->line($this->posxup - 1, $tab_top, $this->posxup - 1, $tab_top + $tab_height);
1772 if (empty($hidetop)) {
1773 $pdf->SetXY($this->posxup - 1, $tab_top + 1);
1774 $pdf->MultiCell($this->posxqty - $this->posxup - 1, 2, $outputlangs->transnoentities(
"PriceUHT"),
'',
'C');
1777 $pdf->line($this->posxqty - 1, $tab_top, $this->posxqty - 1, $tab_top + $tab_height);
1778 if (empty($hidetop)) {
1779 $pdf->SetXY($this->posxqty - 1, $tab_top + 1);
1780 $pdf->MultiCell($this->posxunit - $this->posxqty - 1, 2, $outputlangs->transnoentities(
"Qty"),
'',
'C');
1784 $pdf->line($this->posxunit - 1, $tab_top, $this->posxunit - 1, $tab_top + $tab_height);
1785 if (empty($hidetop)) {
1786 $pdf->SetXY($this->posxunit - 1, $tab_top + 1);
1787 $pdf->MultiCell($this->posxdiscount - $this->posxunit - 1, 2, $outputlangs->transnoentities(
"Unit"),
'',
'C');
1791 if ($this->atleastonediscount) {
1792 $pdf->line($this->posxdiscount - 1, $tab_top, $this->posxdiscount - 1, $tab_top + $tab_height);
1793 if (empty($hidetop)) {
1794 $pdf->SetXY($this->posxdiscount - 1, $tab_top + 1);
1795 $pdf->MultiCell($this->posxprogress - $this->posxdiscount + 1, 2, $outputlangs->transnoentities(
"ReductionShort"),
'',
'C');
1799 if ($this->situationinvoice) {
1800 $pdf->line($this->posxprogress - 1, $tab_top, $this->posxprogress - 1, $tab_top + $tab_height);
1801 if (empty($hidetop)) {
1802 $pdf->SetXY($this->posxprogress, $tab_top + 1);
1803 $pdf->MultiCell($this->postotalht - $this->posxprogress, 2, $outputlangs->transnoentities(
"ProgressShort"),
'',
'C');
1807 $pdf->line($this->postotalht, $tab_top, $this->postotalht, $tab_top + $tab_height);
1808 if (empty($hidetop)) {
1809 $pdf->SetXY($this->postotalht - 1, $tab_top + 1);
1810 $pdf->MultiCell(30, 2, $outputlangs->transnoentities(
"TotalHTShort"),
'',
'C');
1825 protected function _pagehead(&$pdf,
$object, $showaddress, $outputlangs, $outputlangsbis =
null)
1828 global $conf, $langs;
1830 $ltrdirection =
'L';
1831 if ($outputlangs->trans(
"DIRECTION") ==
'rtl') {
1832 $ltrdirection =
'R';
1836 $outputlangs->loadLangs(array(
"main",
"bills",
"propal",
"companies"));
1842 $pdf->SetTextColor(0, 0, 60);
1843 $pdf->SetFont(
'',
'B', $default_font_size + 3);
1847 $posy = $this->marge_haute;
1848 $posx = $this->page_largeur - $this->marge_droite - $w;
1850 $pdf->SetXY($this->marge_gauche, $posy);
1854 if ($this->emetteur->logo) {
1855 $logodir = $conf->mycompany->dir_output;
1856 if (!empty($conf->mycompany->multidir_output[
$object->entity])) {
1857 $logodir = $conf->mycompany->multidir_output[
$object->entity];
1860 $logo = $logodir.
'/logos/thumbs/'.$this->emetteur->logo_small;
1862 $logo = $logodir.
'/logos/'.$this->emetteur->logo;
1864 if (is_readable($logo)) {
1866 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
1868 $pdf->SetTextColor(200, 0, 0);
1869 $pdf->SetFont(
'',
'B', $default_font_size - 2);
1870 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
1871 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorGoToGlobalSetup"), 0,
'L');
1874 $text = $this->emetteur->name;
1875 $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, $ltrdirection);
1879 $pdf->SetFont(
'',
'B', $default_font_size + 3);
1880 $pdf->SetXY($posx, $posy);
1881 $pdf->SetTextColor(0, 0, 60);
1882 $title = $outputlangs->transnoentities(
"PdfInvoiceTitle");
1884 $title = $outputlangs->transnoentities(
"InvoiceReplacement");
1887 $title = $outputlangs->transnoentities(
"InvoiceAvoir");
1890 $title = $outputlangs->transnoentities(
"InvoiceDeposit");
1893 $title = $outputlangs->transnoentities(
"InvoiceProForma");
1895 if ($this->situationinvoice) {
1896 $langs->loadLangs(array(
"other"));
1897 $title = $outputlangs->transnoentities(
"PDFInvoiceSituation") .
" " . $outputlangs->transnoentities(
"NumberingShort") .
$object->situation_counter .
" -";
1899 if (
getDolGlobalString(
'PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
1902 if ($this->situationinvoice) {
1903 $title .= $outputlangsbis->transnoentities(
"PDFInvoiceSituation");
1905 $title .= $outputlangsbis->transnoentities(
"PdfInvoiceTitle");
1906 } elseif (
$object->type == 1) {
1907 $title .= $outputlangsbis->transnoentities(
"InvoiceReplacement");
1908 } elseif (
$object->type == 2) {
1909 $title .= $outputlangsbis->transnoentities(
"InvoiceAvoir");
1910 } elseif (
$object->type == 3) {
1911 $title .= $outputlangsbis->transnoentities(
"InvoiceDeposit");
1912 } elseif (
$object->type == 4) {
1913 $title .= $outputlangsbis->transnoentities(
"InvoiceProForma");
1916 $title .=
' '.$outputlangs->convToOutputCharset(
$object->ref);
1917 if (
$object->statut == $object::STATUS_DRAFT) {
1918 $pdf->SetTextColor(128, 0, 0);
1919 $title .=
' - '.$outputlangs->transnoentities(
"NotValidated");
1922 $pdf->MultiCell($w, 3, $title,
'',
'R');
1924 $pdf->SetFont(
'',
'B', $default_font_size);
1938 $pdf->SetFont(
'',
'', $default_font_size - 2);
1942 $pdf->SetXY($posx, $posy);
1943 $pdf->SetTextColor(0, 0, 60);
1944 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefCustomer").
" : ".$outputlangs->convToOutputCharset(
$object->ref_customer),
'',
'R');
1949 if (!empty(
$object->project->ref)) {
1951 $pdf->SetXY($posx, $posy);
1952 $pdf->SetTextColor(0, 0, 60);
1953 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Project").
" : ".(empty(
$object->project->title) ?
'' :
$object->project->title),
'',
'R');
1959 if (!empty(
$object->project->ref)) {
1960 $outputlangs->load(
"projects");
1962 $pdf->SetXY($posx, $posy);
1963 $pdf->SetTextColor(0, 0, 60);
1964 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefProject").
" : ".(empty(
$object->project->ref) ?
'' :
$object->project->ref),
'',
'R');
1968 $objectidnext =
$object->getIdReplacingInvoice(
'validated');
1969 if (
$object->type == 0 && $objectidnext) {
1970 $objectreplacing =
new Facture($this->db);
1971 $objectreplacing->fetch($objectidnext);
1974 $pdf->SetXY($posx, $posy);
1975 $pdf->SetTextColor(0, 0, 60);
1976 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ReplacementByInvoice").
' : '.$outputlangs->convToOutputCharset($objectreplacing->ref),
'',
'R');
1979 $objectreplaced =
new Facture($this->db);
1980 $objectreplaced->fetch(
$object->fk_facture_source);
1983 $pdf->SetXY($posx, $posy);
1984 $pdf->SetTextColor(0, 0, 60);
1985 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ReplacementInvoice").
' : '.$outputlangs->convToOutputCharset($objectreplaced->ref),
'',
'R');
1988 $objectreplaced =
new Facture($this->db);
1989 $objectreplaced->fetch(
$object->fk_facture_source);
1992 $pdf->SetXY($posx, $posy);
1993 $pdf->SetTextColor(0, 0, 60);
1994 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CorrectionInvoice").
' : '.$outputlangs->convToOutputCharset($objectreplaced->ref),
'',
'R');
1998 $pdf->SetXY($posx, $posy);
1999 $pdf->SetTextColor(0, 0, 60);
2000 $title = $outputlangs->transnoentities(
"DateInvoice");
2001 if (
getDolGlobalString(
'PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2002 $title .=
' - '.$outputlangsbis->transnoentities(
"DateInvoice");
2004 $pdf->MultiCell($w, 3, $title.
" : ".
dol_print_date(
$object->date,
"day",
false, $outputlangs,
true),
'',
'R');
2008 $pdf->SetXY($posx, $posy);
2009 $pdf->SetTextColor(0, 0, 60);
2010 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"DatePointOfTax").
" : ".
dol_print_date(
$object->date_pointoftax,
"day",
false, $outputlangs),
'',
'R');
2015 $pdf->SetXY($posx, $posy);
2016 $pdf->SetTextColor(0, 0, 60);
2017 $title = $outputlangs->transnoentities(
"DateDue");
2018 if (
getDolGlobalString(
'PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
2019 $title .=
' - '.$outputlangsbis->transnoentities(
"DateDue");
2021 $pdf->MultiCell($w, 3, $title.
" : ".
dol_print_date(
$object->date_lim_reglement,
"day",
false, $outputlangs,
true),
'',
'R');
2026 $pdf->SetXY($posx, $posy);
2027 $pdf->SetTextColor(0, 0, 60);
2028 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CustomerCode").
" : ".$outputlangs->transnoentities(
$object->thirdparty->code_client),
'',
'R');
2033 $arrayidcontact =
$object->getIdContact(
'internal',
'SALESREPFOLL');
2034 if (count($arrayidcontact) > 0) {
2035 $usertmp =
new User($this->db);
2036 $usertmp->fetch($arrayidcontact[0]);
2038 $pdf->SetXY($posx, $posy);
2039 $pdf->SetTextColor(0, 0, 60);
2040 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"SalesRepresentative").
" : ".$usertmp->getFullName($langs),
'',
'R');
2048 $current_y = $pdf->getY();
2050 if ($current_y < $pdf->getY()) {
2051 $top_shift = $pdf->getY() - $current_y;
2056 $carac_emetteur =
'';
2058 $arrayidcontact =
$object->getIdContact(
'internal',
'BILLING');
2059 if (count($arrayidcontact) > 0) {
2060 $object->fetch_user($arrayidcontact[0]);
2061 $labelbeforecontactname = ($outputlangs->transnoentities(
"FromContactName") !=
'FromContactName' ? $outputlangs->transnoentities(
"FromContactName") : $outputlangs->transnoentities(
"Name"));
2062 $carac_emetteur .= ($carac_emetteur ?
"\n" :
'').$labelbeforecontactname.
" ".$outputlangs->convToOutputCharset(
$object->user->getFullName($outputlangs));
2063 $carac_emetteur .=
"\n";
2070 $posy += $top_shift;
2071 $posx = $this->marge_gauche;
2073 $posx = $this->page_largeur - $this->marge_droite - 80;
2082 $pdf->SetTextColor(0, 0, 0);
2083 $pdf->SetFont(
'',
'', $default_font_size - 2);
2084 $pdf->SetXY($posx, $posy - 5);
2085 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"BillFrom"), 0, $ltrdirection);
2086 $pdf->SetXY($posx, $posy);
2087 $pdf->SetFillColor(230, 230, 230);
2088 $pdf->MultiCell($widthrecbox, $hautcadre,
"", 0,
'R', 1);
2089 $pdf->SetTextColor(0, 0, 60);
2094 $pdf->SetXY($posx + 2, $posy + 3);
2095 $pdf->SetFont(
'',
'B', $default_font_size);
2096 $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, $ltrdirection);
2097 $posy = $pdf->getY();
2101 $pdf->SetXY($posx + 2, $posy);
2102 $pdf->SetFont(
'',
'', $default_font_size - 1);
2103 $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0, $ltrdirection);
2107 $usecontact =
false;
2108 $arrayidcontact =
$object->getIdContact(
'external',
'BILLING');
2109 if (count($arrayidcontact) > 0) {
2111 $result =
$object->fetch_contact($arrayidcontact[0]);
2115 if ($usecontact && (
$object->contact->socid !=
$object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) ||
getDolGlobalString(
'MAIN_USE_COMPANY_NAME_OF_CONTACT')))) {
2116 $thirdparty =
$object->contact;
2118 $thirdparty =
$object->thirdparty;
2128 if ($this->page_largeur < 210) {
2132 $posy += $top_shift;
2133 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
2135 $posx = $this->marge_gauche;
2140 $pdf->SetTextColor(0, 0, 0);
2141 $pdf->SetFont(
'',
'', $default_font_size - 2);
2142 $pdf->SetXY($posx + 2, $posy - 5);
2143 $pdf->MultiCell($widthrecbox - 2, 5, $outputlangs->transnoentities(
"BillTo"), 0, $ltrdirection);
2144 $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
2148 $pdf->SetXY($posx + 2, $posy + 3);
2149 $pdf->SetFont(
'',
'B', $default_font_size);
2151 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name, 0, $ltrdirection);
2153 $posy = $pdf->getY();
2156 $pdf->SetFont(
'',
'', $default_font_size - 1);
2157 $pdf->SetXY($posx + 2, $posy);
2159 $pdf->MultiCell($widthrecbox - 2, 4, $carac_client, 0, $ltrdirection);
2163 $idaddressshipping =
$object->getIdContact(
'external',
'SHIPPING');
2165 if (!empty($idaddressshipping)) {
2166 $contactshipping =
$object->fetch_Contact($idaddressshipping[0]);
2167 $companystatic =
new Societe($this->db);
2168 $companystatic->fetch(
$object->contact->fk_soc);
2175 if (!empty($carac_client_shipping)) {
2176 $posy += $hautcadre;
2181 $pdf->SetXY($posx + 2, $posy - 5);
2182 $pdf->SetFont(
'',
'', $default_font_size - 2);
2183 $pdf->MultiCell($widthrecbox,
'', $outputlangs->transnoentities(
'ShippingTo'), 0,
'L', 0);
2184 $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
2187 $pdf->SetXY($posx + 2, $posy + 3);
2188 $pdf->SetFont(
'',
'B', $default_font_size);
2189 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name_shipping,
'',
'L');
2191 $posy = $pdf->getY();
2194 $pdf->SetXY($posx + 2, $posy);
2195 $pdf->SetFont(
'',
'', $default_font_size - 1);
2196 $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_shipping,
'',
'L');
2198 $top_shift += $hautcadre + 10;
2203 $pdf->SetTextColor(0, 0, 0);