160 public function write_file(
$object, $outputlangs =
null, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
163 global $user, $langs, $conf, $mysoc, $hookmanager, $nblines;
166 if (!is_object(
$object->thirdparty)) {
169 if (!is_object(
$object->thirdparty)) {
173 $this->emetteur =
$object->thirdparty;
174 if (!$this->emetteur->country_code) {
175 $this->emetteur->country_code = substr($langs->defaultlang, -2);
178 if (!is_object($outputlangs)) {
179 $outputlangs = $langs;
183 $outputlangs->charset_output =
'ISO-8859-1';
187 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"bills",
"products"));
189 $nblines = count(
$object->lines);
191 if ($conf->fournisseur->facture->dir_output) {
192 $deja_regle =
$object->getSommePaiement((isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? 1 : 0);
193 $amount_credit_notes_included =
$object->getSumCreditNotesUsed((isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? 1 : 0);
194 $amount_deposits_included =
$object->getSumDepositsUsed((isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? 1 : 0);
198 $dir = $conf->fournisseur->facture->dir_output;
199 $file = $dir.
"/SPECIMEN.pdf";
203 $dir = $conf->fournisseur->facture->dir_output.
'/'.
get_exdir(
$object->id, 2, 0, 0,
$object,
'invoice_supplier').$objectref;
204 $file = $dir.
"/".$objectref.
".pdf";
206 $file = $dir.
"/".$objectref.($objectrefsupplier ?
"_".$objectrefsupplier :
"").
".pdf";
210 if (!file_exists($dir)) {
212 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
217 if (file_exists($dir)) {
219 if (!is_object($hookmanager)) {
220 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
223 $hookmanager->initHooks(array(
'pdfgeneration'));
224 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
226 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters,
$object, $action);
229 $nblines = count(
$object->lines);
230 $nbpayments = count(
$object->getListOfPayments());
235 $pdf->SetAutoPageBreak(1, 0);
237 $heightforinfotot = 50 + (4 * $nbpayments);
238 if ($heightforinfotot > 220) {
239 $heightforinfotot = 220;
241 $heightforfreetext = (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->MAIN_PDF_FREETEXT_HEIGHT : 5);
242 $heightforfooter = $this->marge_basse + 8;
244 $heightforfooter += 6;
247 if (class_exists(
'TCPDF')) {
248 $pdf->setPrintHeader(
false);
249 $pdf->setPrintFooter(
false);
254 $pagecount = $pdf->setSourceFile($conf->mycompany->multidir_output[
$object->entity].
'/' .
getDolGlobalString(
'MAIN_ADD_PDF_BACKGROUND'));
255 $tplidx = $pdf->importPage(1);
260 $pdf->SetDrawColor(128, 128, 128);
262 $pdf->SetTitle($outputlangs->convToOutputCharset(
$object->ref));
263 $pdf->SetSubject($outputlangs->transnoentities(
"PdfInvoiceTitle"));
264 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
265 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
266 $pdf->SetKeyWords($outputlangs->convToOutputCharset(
$object->ref).
" ".$outputlangs->transnoentities(
"PdfInvoiceTitle").
" ".$outputlangs->convToOutputCharset(
$object->thirdparty->name));
268 $pdf->SetCompression(
false);
272 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
275 for ($i = 0; $i < $nblines; $i++) {
276 if (
$object->lines[$i]->remise_percent) {
277 $this->atleastonediscount++;
280 if (empty($this->atleastonediscount)) {
281 $delta = ($this->postotalht - $this->posxdiscount);
282 $this->posxpicture += $delta;
283 $this->posxtva += $delta;
284 $this->posxup += $delta;
285 $this->posxqty += $delta;
286 $this->posxunit += $delta;
287 $this->posxdiscount += $delta;
293 if (!empty($tplidx)) {
294 $pdf->useTemplate($tplidx);
298 $pdf->SetFont(
'',
'', $default_font_size - 1);
299 $pdf->MultiCell(0, 3,
'');
300 $pdf->SetTextColor(0, 0, 0);
302 $tab_top = 90 + $top_shift;
303 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
306 if (isModEnabled(
'incoterm')) {
307 $desc_incoterms =
$object->getIncotermsForPDF();
308 if ($desc_incoterms) {
311 $pdf->SetFont(
'',
'', $default_font_size - 1);
312 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1,
dol_htmlentitiesbr($desc_incoterms), 0, 1);
313 $nexY = $pdf->GetY();
314 $height_incoterms = $nexY - $tab_top;
317 $pdf->SetDrawColor(192, 192, 192);
318 $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_incoterms + 1);
320 $tab_top = $nexY + 6;
325 $notetoshow = empty(
$object->note_public) ?
'' :
$object->note_public;
329 $extranote = $this->getExtrafieldsInHtml(
$object, $outputlangs);
330 if (!empty($extranote)) {
343 $pdf->SetFont(
'',
'', $default_font_size - 1);
344 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1,
dol_htmlentitiesbr($notetoshow), 0, 1);
345 $nexY = $pdf->GetY();
346 $height_note = $nexY - $tab_top;
349 $pdf->SetDrawColor(192, 192, 192);
350 $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1);
352 $tab_top = $nexY + 6;
355 $iniY = $tab_top + 7;
356 $curY = $tab_top + 7;
357 $nexY = $tab_top + 7;
360 for ($i = 0; $i < $nblines; $i++) {
362 $pdf->SetFont(
'',
'', $default_font_size - 1);
363 $pdf->SetTextColor(0, 0, 0);
371 $pdf->setTopMargin($tab_top_newpage);
372 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext + $heightforinfotot);
373 $pageposbefore = $pdf->getPage();
375 $showpricebeforepagebreak = 1;
379 $curX = $this->posxdesc - 1;
381 $pdf->startTransaction();
382 pdf_writelinedesc($pdf,
$object, $i, $outputlangs, $this->posxtva - $curX, 3, $curX, $curY, $hideref, $hidedesc, 1);
383 $pageposafter = $pdf->getPage();
384 if ($pageposafter > $pageposbefore) {
385 $pdf->rollbackTransaction(
true);
386 $pageposafter = $pageposbefore;
388 $pdf->setPageOrientation(
'', 1, $heightforfooter);
389 pdf_writelinedesc($pdf,
$object, $i, $outputlangs, $this->posxtva - $curX, 4, $curX, $curY, $hideref, $hidedesc, 1);
390 $posyafter = $pdf->GetY();
391 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
392 if ($i == ($nblines - 1)) {
393 $pdf->AddPage(
'',
'',
true);
394 if (!empty($tplidx)) {
395 $pdf->useTemplate($tplidx);
400 $pdf->setPage($pageposafter + 1);
406 $showpricebeforepagebreak = 1;
408 $showpricebeforepagebreak = 0;
412 $pdf->commitTransaction();
414 $posYAfterDescription = $pdf->GetY();
416 $nexY = $pdf->GetY();
417 $pageposafter = $pdf->getPage();
418 $pdf->setPage($pageposbefore);
419 $pdf->setTopMargin($this->marge_haute);
420 $pdf->setPageOrientation(
'', 1, 0);
423 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
424 $pdf->setPage($pageposafter);
425 $curY = $tab_top_newpage;
428 $pdf->SetFont(
'',
'', $default_font_size - 1);
433 $pdf->SetXY($this->posxtva, $curY);
434 $pdf->MultiCell($this->posxup - $this->posxtva - 1, 3, $vat_rate, 0,
'R');
439 $pdf->SetXY($this->posxup, $curY);
440 $pdf->MultiCell($this->posxqty - $this->posxup - 0.8, 3, $up_excl_tax, 0,
'R', 0);
444 $pdf->SetXY($this->posxqty, $curY);
445 $pdf->MultiCell($this->posxunit - $this->posxqty - 0.8, 4, $qty, 0,
'R');
450 $pdf->SetXY($this->posxunit, $curY);
451 $pdf->MultiCell($this->posxdiscount - $this->posxunit - 0.8, 4, $unit, 0,
'L');
455 if (
$object->lines[$i]->remise_percent) {
456 $pdf->SetXY($this->posxdiscount - 2, $curY);
458 $pdf->MultiCell($this->postotalht - $this->posxdiscount - 1, 3, $remise_percent, 0,
'R');
463 $pdf->SetXY($this->postotalht, $curY);
464 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->postotalht, 3, $total_excl_tax, 0,
'R', 0);
467 if (isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) {
468 $tvaligne =
$object->lines[$i]->multicurrency_total_tva;
470 $tvaligne =
$object->lines[$i]->total_tva;
473 $localtax1ligne =
$object->lines[$i]->total_localtax1;
474 $localtax2ligne =
$object->lines[$i]->total_localtax2;
481 $vatrate = (string)
$object->lines[$i]->tva_tx;
482 $localtax1rate = (string)
$object->lines[$i]->localtax1_tx;
483 $localtax2rate = (string)
$object->lines[$i]->localtax2_tx;
485 if ((
$object->lines[$i]->info_bits & 0x01) == 0x01) {
488 if (empty($this->tva[$vatrate])) {
489 $this->tva[$vatrate] = 0;
491 if (empty($this->localtax1[$localtax1rate])) {
492 $this->localtax1[$localtax1rate] = 0;
494 if (empty($this->localtax2[$localtax2rate])) {
495 $this->localtax2[$localtax2rate] = 0;
497 $this->tva[$vatrate] += $tvaligne;
498 $this->localtax1[$localtax1rate] += $localtax1ligne;
499 $this->localtax2[$localtax2rate] += $localtax2ligne;
501 if ($posYAfterImage > $posYAfterDescription) {
502 $nexY = $posYAfterImage;
507 $pdf->setPage($pageposafter);
508 $pdf->SetLineStyle(array(
'dash' =>
'1,1',
'color' => array(80, 80, 80)));
510 $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
511 $pdf->SetLineStyle(array(
'dash' => 0));
517 while ($pagenb < $pageposafter) {
518 $pdf->setPage($pagenb);
520 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1,
$object->multicurrency_code);
522 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1,
$object->multicurrency_code);
526 $pdf->setPage($pagenb);
527 $pdf->setPageOrientation(
'', 1, 0);
532 if (isset(
$object->lines[$i + 1]->pagebreak) &&
$object->lines[$i + 1]->pagebreak) {
534 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1,
$object->multicurrency_code);
536 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1,
$object->multicurrency_code);
541 if (!empty($tplidx)) {
542 $pdf->useTemplate($tplidx);
553 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0,
$object->multicurrency_code);
554 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
556 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0,
$object->multicurrency_code);
557 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
563 $amount_credit_notes_included = 0;
564 $amount_deposits_included = 0;
567 if (($deja_regle || $amount_credit_notes_included || $amount_deposits_included) && !
getDolGlobalString(
'SUPPLIER_INVOICE_NO_PAYMENT_DETAILS')) {
573 if (method_exists($pdf,
'AliasNbPages')) {
574 $pdf->AliasNbPages();
579 $pdf->Output($file,
'F');
582 $hookmanager->initHooks(array(
'pdfgeneration'));
583 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
585 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
587 $this->error = $hookmanager->error;
588 $this->errors = $hookmanager->errors;
593 $this->result = array(
'fullpath' => $file);
597 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
601 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"SUPPLIER_OUTPUTDIR");
621 global $conf, $mysoc, $hookmanager;
632 $pdf->SetFont(
'',
'', $default_font_size - 1);
637 if ($this->page_largeur < 210) {
640 $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
646 $pdf->SetFillColor(255, 255, 255);
647 $pdf->SetXY($col1x, $tab2_top);
648 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalHT"), 0,
'L', 1);
650 $total_ht = ((isModEnabled(
"multicurrency") && isset(
$object->multicurrency_tx) &&
$object->multicurrency_tx != 1) ?
$object->multicurrency_total_ht :
$object->total_ht);
651 $pdf->SetXY($col2x, $tab2_top);
652 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * ($total_ht + (!empty(
$object->remise) ?
$object->remise : 0)), 0, $outputlangs), 0,
'R', 1);
655 $pdf->SetFillColor(248, 248, 248);
657 $total_ttc = (isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ?
$object->multicurrency_total_ttc :
$object->total_ttc;
659 $this->atleastoneratenotnull = 0;
660 foreach ($this->tva as $tvakey => $tvaval) {
662 $this->atleastoneratenotnull++;
665 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
669 if (preg_match(
'/\*/', $tvakey)) {
670 $tvakey = str_replace(
'*',
'', $tvakey);
671 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
674 $totalvat = $outputlangs->transcountrynoentities(
"TotalVAT", $mysoc->country_code).
' ';
675 $totalvat .=
vatrate($tvakey, 1).$tvacompl;
676 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
678 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
679 $pdf->MultiCell($largcol2, $tab2_hl,
price($tvaval, 0, $outputlangs), 0,
'R', 1);
682 if (!$this->atleastoneratenotnull) {
684 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
685 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transcountrynoentities(
"TotalVAT", $mysoc->country_code), 0,
'L', 1);
686 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
687 $pdf->MultiCell($largcol2, $tab2_hl,
price(
$object->total_tva, 0, $outputlangs), 0,
'R', 1);
692 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
693 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transcountrynoentities(
"TotalLT1", $mysoc->country_code), 0,
'L', 1);
694 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
695 $pdf->MultiCell($largcol2, $tab2_hl,
price(
$object->total_localtax1, 0, $outputlangs), 0,
'R', 1);
701 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
702 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transcountrynoentities(
"TotalLT2", $mysoc->country_code), 0,
'L', 1);
703 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
704 $pdf->MultiCell($largcol2, $tab2_hl,
price(
$object->total_localtax2, 0, $outputlangs), 0,
'R', 1);
710 foreach ($this->localtax1 as $tvakey => $tvaval) {
715 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
718 if (preg_match(
'/\*/', (
string) $tvakey)) {
719 $tvakey = str_replace(
'*',
'', (
string) $tvakey);
720 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
722 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1", $mysoc->country_code).
' ';
723 $totalvat .=
vatrate(abs($tvakey), 1).$tvacompl;
724 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
726 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
727 $pdf->MultiCell($largcol2, $tab2_hl,
price($tvaval, 0, $outputlangs), 0,
'R', 1);
735 foreach ($this->localtax2 as $tvakey => $tvaval) {
740 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
743 if (preg_match(
'/\*/', (
string) $tvakey)) {
744 $tvakey = str_replace(
'*',
'', (
string) $tvakey);
745 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
747 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT2", $mysoc->country_code).
' ';
748 $totalvat .=
vatrate(abs($tvakey), 1).$tvacompl;
749 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
751 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
752 $pdf->MultiCell($largcol2, $tab2_hl,
price($tvaval, 0, $outputlangs), 0,
'R', 1);
760 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
761 $pdf->SetTextColor(0, 0, 60);
762 $pdf->SetFillColor(224, 224, 224);
763 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalTTC"), $useborder,
'L', 1);
765 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
766 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * $total_ttc, 0, $outputlangs), $useborder,
'R', 1);
768 $pdf->SetTextColor(0, 0, 0);
769 $creditnoteamount =
$object->getSumCreditNotesUsed((isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? 1 : 0);
770 $depositsamount =
$object->getSumDepositsUsed((isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? 1 : 0);
772 $resteapayer =
price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount,
'MT');
777 if (($deja_regle > 0 || $creditnoteamount > 0 || $depositsamount > 0) && !
getDolGlobalString(
'INVOICE_NO_PAYMENT_DETAILS')) {
780 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
781 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"Paid"), 0,
'L', 0);
782 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
783 $pdf->MultiCell($largcol2, $tab2_hl,
price($deja_regle + $depositsamount, 0, $outputlangs), 0,
'R', 0);
786 if ($creditnoteamount) {
787 $labeltouse = ($outputlangs->transnoentities(
"CreditNotesOrExcessReceived") !=
"CreditNotesOrExcessReceived") ? $outputlangs->transnoentities(
"CreditNotesOrExcessReceived") : $outputlangs->transnoentities(
"CreditNotes");
789 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
790 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $labeltouse, 0,
'L', 0);
791 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
792 $pdf->MultiCell($largcol2, $tab2_hl,
price($creditnoteamount, 0, $outputlangs), 0,
'R', 0);
796 if (
$object->close_code == FactureFournisseur::CLOSECODE_DISCOUNTVAT) {
798 $pdf->SetFillColor(255, 255, 255);
800 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
801 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"EscompteOfferedShort"), $useborder,
'L', 1);
802 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
803 $pdf->MultiCell($largcol2, $tab2_hl,
price(
$object->total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 0, $outputlangs), $useborder,
'R', 1);
809 $pdf->SetTextColor(0, 0, 60);
810 $pdf->SetFillColor(224, 224, 224);
811 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
812 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"RemainderToPay"), $useborder,
'L', 1);
814 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
815 $pdf->MultiCell($largcol2, $tab2_hl,
price($resteapayer, 0, $outputlangs), $useborder,
'R', 1);
816 $pdf->SetFont(
'',
'', $default_font_size - 1);
817 $pdf->SetTextColor(0, 0, 0);
820 $parameters = array(
'pdf' => &$pdf,
'object' => &
$object,
'outputlangs' => $outputlangs,
'index' => &$index,
'posy' => $posy);
822 $reshook = $hookmanager->executeHooks(
'afterPDFTotalTable', $parameters, $this);
824 $this->error = $hookmanager->error;
825 $this->errors = $hookmanager->errors;
829 return ($tab2_top + ($tab2_hl * $index));
846 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency =
'')
856 $currency = !empty($currency) ? $currency : $conf->currency;
860 $pdf->SetTextColor(0, 0, 0);
861 $pdf->SetFont(
'',
'', $default_font_size - 2);
863 if (empty($hidetop)) {
864 $titre = $outputlangs->transnoentities(
"AmountInCurrency", $outputlangs->transnoentitiesnoconv(
"Currency".$currency));
865 $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
866 $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
870 $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')));
874 $pdf->SetDrawColor(128, 128, 128);
875 $pdf->SetFont(
'',
'', $default_font_size - 1);
878 $this->
printRect($pdf, $this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $tab_height, $hidetop, $hidebottom);
880 if (empty($hidetop)) {
881 $pdf->line($this->marge_gauche, $tab_top + 5, $this->page_largeur - $this->marge_droite, $tab_top + 5);
883 $pdf->SetXY($this->posxdesc - 1, $tab_top + 1);
884 $pdf->MultiCell(108, 2, $outputlangs->transnoentities(
"Designation"),
'',
'L');
888 $pdf->line($this->posxtva - 1, $tab_top, $this->posxtva - 1, $tab_top + $tab_height);
889 if (empty($hidetop)) {
890 $pdf->SetXY($this->posxtva - 3, $tab_top + 1);
891 $pdf->MultiCell($this->posxup - $this->posxtva + 3, 2, $outputlangs->transnoentities(
"VAT"),
'',
'C');
895 $pdf->line($this->posxup - 1, $tab_top, $this->posxup - 1, $tab_top + $tab_height);
896 if (empty($hidetop)) {
897 $pdf->SetXY($this->posxup - 1, $tab_top + 1);
898 $pdf->MultiCell($this->posxqty - $this->posxup - 1, 2, $outputlangs->transnoentities(
"PriceUHT"),
'',
'C');
901 $pdf->line($this->posxqty - 1, $tab_top, $this->posxqty - 1, $tab_top + $tab_height);
902 if (empty($hidetop)) {
903 $pdf->SetXY($this->posxqty - 1, $tab_top + 1);
904 $pdf->MultiCell($this->posxunit - $this->posxqty - 1, 2, $outputlangs->transnoentities(
"Qty"),
'',
'C');
908 $pdf->line($this->posxunit - 1, $tab_top, $this->posxunit - 1, $tab_top + $tab_height);
909 if (empty($hidetop)) {
910 $pdf->SetXY($this->posxunit - 1, $tab_top + 1);
912 $this->posxdiscount - $this->posxunit - 1,
914 $outputlangs->transnoentities(
"Unit"),
921 if ($this->atleastonediscount) {
922 $pdf->line($this->posxdiscount - 1, $tab_top, $this->posxdiscount - 1, $tab_top + $tab_height);
923 if (empty($hidetop)) {
924 $pdf->SetXY($this->posxdiscount - 1, $tab_top + 1);
925 $pdf->MultiCell($this->postotalht - $this->posxdiscount + 1, 2, $outputlangs->transnoentities(
"ReductionShort"),
'',
'C');
929 $pdf->line($this->postotalht, $tab_top, $this->postotalht, $tab_top + $tab_height);
930 if (empty($hidetop)) {
931 $pdf->SetXY($this->postotalht - 1, $tab_top + 1);
932 $pdf->MultiCell(30, 2, $outputlangs->transnoentities(
"TotalHTShort"),
'',
'C');
959 $tab3_top = $posy + 8;
962 if ($this->page_largeur < 210) {
968 $pdf->SetFont(
'',
'', $default_font_size - 3);
969 $pdf->SetXY($tab3_posx, $tab3_top - 4);
970 $pdf->MultiCell(60, 3, $outputlangs->transnoentities(
"PaymentsAlreadyDone"), 0,
'L', 0);
972 $pdf->line($tab3_posx, $tab3_top, $tab3_posx + $tab3_width, $tab3_top);
974 $pdf->SetFont(
'',
'', $default_font_size - 4);
975 $pdf->SetXY($tab3_posx, $tab3_top);
976 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Payment"), 0,
'L', 0);
977 $pdf->SetXY($tab3_posx + 21, $tab3_top);
978 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Amount"), 0,
'L', 0);
979 $pdf->SetXY($tab3_posx + 40, $tab3_top);
980 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Type"), 0,
'L', 0);
981 $pdf->SetXY($tab3_posx + 58, $tab3_top);
982 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Num"), 0,
'L', 0);
984 $pdf->line($tab3_posx, $tab3_top - 1 + $tab3_height, $tab3_posx + $tab3_width, $tab3_top - 1 + $tab3_height);
988 $pdf->SetFont(
'',
'', $default_font_size - 4);
994 $sql =
"SELECT p.datep as date, p.fk_paiement as type, p.num_paiement as num_payment, pf.amount as amount, pf.multicurrency_amount,";
996 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiementfourn_facturefourn as pf, ".MAIN_DB_PREFIX.
"paiementfourn as p";
997 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as cp ON p.fk_paiement = cp.id";
998 $sql .=
" WHERE pf.fk_paiementfourn = p.rowid and pf.fk_facturefourn = ".((int)
$object->id);
999 $sql .=
" ORDER BY p.datep";
1000 $resql = $this->db->query($sql);
1002 $num = $this->db->num_rows($resql);
1006 $row = $this->db->fetch_object($resql);
1008 $pdf->SetXY($tab3_posx, $tab3_top + $y);
1009 $pdf->MultiCell(20, 3,
dol_print_date($this->db->jdate($row->date),
'day',
false, $outputlangs,
true), 0,
'L', 0);
1010 $pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
1011 $pdf->MultiCell(20, 3,
price($sign * ((isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? $row->multicurrency_amount : $row->amount)), 0,
'L', 0);
1012 $pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
1013 $oper = $outputlangs->transnoentitiesnoconv(
"PaymentTypeShort".$row->code);
1015 $pdf->MultiCell(20, 3, $oper, 0,
'L', 0);
1016 $pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
1017 $pdf->MultiCell(30, 3, $row->num_payment, 0,
'L', 0);
1019 $pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
1024 $this->error = $this->db->lasterror();
1042 global $langs, $conf, $mysoc;
1045 $outputlangs->loadLangs(array(
"main",
"orders",
"companies",
"bills"));
1052 $pdf->SetTextColor(0, 0, 60);
1053 $pdf->SetFont(
'',
'B', $default_font_size + 3);
1057 $posy = $this->marge_haute;
1058 $posx = $this->page_largeur - $this->marge_droite - 100;
1060 $pdf->SetXY($this->marge_gauche, $posy);
1082 $text = $this->emetteur->name;
1083 $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0,
'L');
1086 $pdf->SetFont(
'',
'B', $default_font_size + 3);
1087 $pdf->SetXY($posx, $posy);
1088 $pdf->SetTextColor(0, 0, 60);
1089 $title = $outputlangs->transnoentities(
"PdfInvoiceTitle");
1091 $title = $outputlangs->transnoentities(
"InvoiceReplacement");
1094 $title = $outputlangs->transnoentities(
"InvoiceAvoir");
1097 $title = $outputlangs->transnoentities(
"InvoiceDeposit");
1099 $pdf->MultiCell($w, 3, $title.
" ".$outputlangs->convToOutputCharset(
$object->ref),
'',
'R');
1104 $pdf->SetFont(
'',
'B', $default_font_size);
1105 $pdf->SetXY($posx, $posy);
1106 $pdf->SetTextColor(0, 0, 60);
1107 $pdf->MultiCell($w, 4, $outputlangs->transnoentities(
"RefSupplier").
" : ".
$object->ref_supplier,
'',
'R');
1111 $pdf->SetFont(
'',
'', $default_font_size - 1);
1115 if (!empty(
$object->project->ref)) {
1117 $pdf->SetXY($posx, $posy);
1118 $pdf->SetTextColor(0, 0, 60);
1119 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Project").
" : ".(empty(
$object->project->title) ?
'' :
$object->project->title),
'',
'R');
1125 if (!empty(
$object->project->ref)) {
1126 $outputlangs->load(
"projects");
1128 $pdf->SetXY($posx, $posy);
1129 $langs->load(
"projects");
1130 $pdf->SetTextColor(0, 0, 60);
1131 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Project").
" : ".(empty(
$object->project->ref) ?
'' :
$object->project->ref),
'',
'R');
1137 $pdf->SetXY($posx, $posy);
1138 $pdf->SetTextColor(0, 0, 60);
1139 $pdf->MultiCell($w, 4, $outputlangs->transnoentities(
"Date").
" : ".
dol_print_date(
$object->date,
"day",
false, $outputlangs,
true),
'',
'R');
1142 $pdf->SetXY($posx, $posy);
1143 $pdf->SetTextColor(255, 0, 0);
1144 $pdf->MultiCell($w, 4, strtolower($outputlangs->transnoentities(
"OrderToProcess")),
'',
'R');
1147 if (
$object->thirdparty->code_fournisseur) {
1149 $pdf->SetXY($posx, $posy);
1150 $pdf->SetTextColor(0, 0, 60);
1151 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"SupplierCode").
" : ".$outputlangs->transnoentities(
$object->thirdparty->code_fournisseur),
'',
'R');
1155 $pdf->SetTextColor(0, 0, 60);
1159 $current_y = $pdf->getY();
1161 if ($current_y < $pdf->getY()) {
1162 $top_shift = $pdf->getY() - $current_y;
1167 $carac_emetteur =
'';
1169 $arrayidcontact =
$object->getIdContact(
'internal',
'SALESREPFOLL');
1170 if (count($arrayidcontact) > 0) {
1171 $object->fetch_user($arrayidcontact[0]);
1172 $labelbeforecontactname = ($outputlangs->transnoentities(
"FromContactName") !=
'FromContactName' ? $outputlangs->transnoentities(
"FromContactName") : $outputlangs->transnoentities(
"Name"));
1173 $carac_emetteur .= ($carac_emetteur ?
"\n" :
'').$labelbeforecontactname.
": ".$outputlangs->convToOutputCharset(
$object->user->getFullName($outputlangs));
1175 $carac_emetteur .= (
getDolGlobalInt(
'PDF_SHOW_PHONE_AFTER_USER_CONTACT') && !empty(
$object->user->office_phone)) ?
$object->user->office_phone :
'';
1179 $carac_emetteur .=
"\n";
1185 $posy = 42 + $top_shift;
1186 $posx = $this->marge_gauche;
1188 $posx = $this->page_largeur - $this->marge_droite - 80;
1193 $pdf->SetTextColor(0, 0, 0);
1194 $pdf->SetFont(
'',
'', $default_font_size - 2);
1195 $pdf->SetXY($posx, $posy - 5);
1196 $pdf->MultiCell(80, 5, $outputlangs->transnoentities(
"BillFrom"), 0,
'L');
1197 $pdf->SetXY($posx, $posy);
1198 $pdf->SetFillColor(230, 230, 230);
1199 $pdf->MultiCell(82, $hautcadre,
"", 0,
'R', 1);
1200 $pdf->SetTextColor(0, 0, 60);
1203 $pdf->SetXY($posx + 2, $posy + 3);
1204 $pdf->SetFont(
'',
'B', $default_font_size);
1205 $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0,
'L');
1206 $posy = $pdf->getY();
1209 $pdf->SetXY($posx + 2, $posy);
1210 $pdf->SetFont(
'',
'', $default_font_size - 1);
1211 $pdf->MultiCell(80, 4, $carac_emetteur, 0,
'L');
1216 $usecontact =
false;
1217 $arrayidcontact =
$object->getIdContact(
'internal',
'BILLING');
1218 if (count($arrayidcontact) > 0) {
1220 $result =
$object->fetch_contact($arrayidcontact[0]);
1224 if ($usecontact && (
$object->contact->socid !=
$object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) ||
getDolGlobalString(
'MAIN_USE_COMPANY_NAME_OF_CONTACT')))) {
1225 $thirdparty =
$object->contact;
1227 $thirdparty = $mysoc;
1236 if ($this->page_largeur < 210) {
1239 $posy = 42 + $top_shift;
1240 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
1242 $posx = $this->marge_gauche;
1246 $pdf->SetTextColor(0, 0, 0);
1247 $pdf->SetFont(
'',
'', $default_font_size - 2);
1248 $pdf->SetXY($posx + 2, $posy - 5);
1249 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"BillTo"), 0,
'L');
1250 $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
1253 $pdf->SetXY($posx + 2, $posy + 3);
1254 $pdf->SetFont(
'',
'B', $default_font_size);
1255 $pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0,
'L');
1257 $posy = $pdf->getY();
1260 $pdf->SetFont(
'',
'', $default_font_size - 1);
1261 $pdf->SetXY($posx + 2, $posy);
1262 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0,
'L');