161 public function write_file(
$object, $outputlangs =
null, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
164 global $user, $langs, $conf, $mysoc, $hookmanager, $nblines;
167 if (!is_object(
$object->thirdparty)) {
170 if (!is_object(
$object->thirdparty)) {
174 $this->emetteur =
$object->thirdparty;
175 if (!$this->emetteur->country_code) {
176 $this->emetteur->country_code = substr($langs->defaultlang, -2);
179 if (!is_object($outputlangs)) {
180 $outputlangs = $langs;
184 $outputlangs->charset_output =
'ISO-8859-1';
188 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"bills",
"products"));
190 $nblines = count(
$object->lines);
192 if ($conf->fournisseur->facture->dir_output) {
193 $deja_regle =
$object->getSommePaiement((isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? 1 : 0);
194 $amount_credit_notes_included =
$object->getSumCreditNotesUsed((isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? 1 : 0);
195 $amount_deposits_included =
$object->getSumDepositsUsed((isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? 1 : 0);
199 $dir = $conf->fournisseur->facture->dir_output;
200 $file = $dir.
"/SPECIMEN.pdf";
204 $dir = $conf->fournisseur->facture->dir_output.
'/'.
get_exdir(
$object->id, 2, 0, 0,
$object,
'invoice_supplier').$objectref;
205 $file = $dir.
"/".$objectref.
".pdf";
207 $file = $dir.
"/".$objectref.($objectrefsupplier ?
"_".$objectrefsupplier :
"").
".pdf";
211 if (!file_exists($dir)) {
213 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
218 if (file_exists($dir)) {
220 if (!is_object($hookmanager)) {
221 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
224 $hookmanager->initHooks(array(
'pdfgeneration'));
225 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
227 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters,
$object, $action);
230 $nblines = count(
$object->lines);
231 $nbpayments = count(
$object->getListOfPayments());
236 $pdf->SetAutoPageBreak(1, 0);
238 $heightforinfotot = 50 + (4 * $nbpayments);
239 if ($heightforinfotot > 220) {
240 $heightforinfotot = 220;
243 $heightforfooter = $this->marge_basse + 8;
245 $heightforfooter += 6;
248 if (class_exists(
'TCPDF')) {
249 $pdf->setPrintHeader(
false);
250 $pdf->setPrintFooter(
false);
255 $pagecount = $pdf->setSourceFile($conf->mycompany->multidir_output[
$object->entity].
'/' .
getDolGlobalString(
'MAIN_ADD_PDF_BACKGROUND'));
256 $tplidx = $pdf->importPage(1);
261 $pdf->SetDrawColor(128, 128, 128);
263 $pdf->SetTitle($outputlangs->convToOutputCharset(
$object->ref));
264 $pdf->SetSubject($outputlangs->transnoentities(
"PdfInvoiceTitle"));
265 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
266 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
267 $pdf->SetKeyWords($outputlangs->convToOutputCharset(
$object->ref).
" ".$outputlangs->transnoentities(
"PdfInvoiceTitle").
" ".$outputlangs->convToOutputCharset(
$object->thirdparty->name));
269 $pdf->SetCompression(
false);
273 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
276 for ($i = 0; $i < $nblines; $i++) {
277 if (
$object->lines[$i]->remise_percent) {
278 $this->atleastonediscount++;
281 if (empty($this->atleastonediscount)) {
282 $delta = ($this->postotalht - $this->posxdiscount);
283 $this->posxpicture += $delta;
284 $this->posxtva += $delta;
285 $this->posxup += $delta;
286 $this->posxqty += $delta;
287 $this->posxunit += $delta;
288 $this->posxdiscount += $delta;
294 if (!empty($tplidx)) {
295 $pdf->useTemplate($tplidx);
299 $pdf->SetFont(
'',
'', $default_font_size - 1);
300 $pdf->MultiCell(0, 3,
'');
301 $pdf->SetTextColor(0, 0, 0);
303 $tab_top = 90 + $top_shift;
304 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
307 if (isModEnabled(
'incoterm')) {
308 $desc_incoterms =
$object->getIncotermsForPDF();
309 if ($desc_incoterms) {
312 $pdf->SetFont(
'',
'', $default_font_size - 1);
313 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1,
dol_htmlentitiesbr($desc_incoterms), 0, 1);
314 $nexY = $pdf->GetY();
315 $height_incoterms = $nexY - $tab_top;
318 $pdf->SetDrawColor(192, 192, 192);
319 $pdf->RoundedRect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_incoterms + 3, $this->corner_radius,
'1234',
'D');
321 $tab_top = $nexY + 6;
326 $notetoshow = empty(
$object->note_public) ?
'' :
$object->note_public;
330 $extranote = $this->getExtrafieldsInHtml(
$object, $outputlangs);
331 if (!empty($extranote)) {
344 $pdf->SetFont(
'',
'', $default_font_size - 1);
345 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1,
dol_htmlentitiesbr($notetoshow), 0, 1);
346 $nexY = $pdf->GetY();
347 $height_note = $nexY - $tab_top;
350 $pdf->SetDrawColor(192, 192, 192);
351 $pdf->RoundedRect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 2, $this->corner_radius,
'1234',
'D');
353 $tab_top = $nexY + 6;
356 $iniY = $tab_top + 7;
357 $curY = $tab_top + 7;
358 $nexY = $tab_top + 7;
361 for ($i = 0; $i < $nblines; $i++) {
363 $pdf->SetFont(
'',
'', $default_font_size - 1);
364 $pdf->SetTextColor(0, 0, 0);
372 $pdf->setTopMargin($tab_top_newpage);
373 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext + $heightforinfotot);
374 $pageposbefore = $pdf->getPage();
376 $showpricebeforepagebreak = 1;
380 $curX = $this->posxdesc - 1;
382 $pdf->startTransaction();
383 pdf_writelinedesc($pdf,
$object, $i, $outputlangs, $this->posxtva - $curX, 3, $curX, $curY, $hideref, $hidedesc, 1);
384 $pageposafter = $pdf->getPage();
385 if ($pageposafter > $pageposbefore) {
386 $pdf->rollbackTransaction(
true);
387 $pageposafter = $pageposbefore;
389 $pdf->setPageOrientation(
'', 1, $heightforfooter);
390 pdf_writelinedesc($pdf,
$object, $i, $outputlangs, $this->posxtva - $curX, 4, $curX, $curY, $hideref, $hidedesc, 1);
391 $posyafter = $pdf->GetY();
392 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
393 if ($i == ($nblines - 1)) {
394 $pdf->AddPage(
'',
'',
true);
395 if (!empty($tplidx)) {
396 $pdf->useTemplate($tplidx);
401 $pdf->setPage($pageposafter + 1);
407 $showpricebeforepagebreak = 1;
409 $showpricebeforepagebreak = 0;
413 $pdf->commitTransaction();
415 $posYAfterDescription = $pdf->GetY();
417 $nexY = $pdf->GetY();
418 $pageposafter = $pdf->getPage();
419 $pdf->setPage($pageposbefore);
420 $pdf->setTopMargin($this->marge_haute);
421 $pdf->setPageOrientation(
'', 1, 0);
424 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
425 $pdf->setPage($pageposafter);
426 $curY = $tab_top_newpage;
429 $pdf->SetFont(
'',
'', $default_font_size - 1);
434 $pdf->SetXY($this->posxtva, $curY);
435 $pdf->MultiCell($this->posxup - $this->posxtva - 1, 3, $vat_rate, 0,
'R');
440 $pdf->SetXY($this->posxup, $curY);
441 $pdf->MultiCell($this->posxqty - $this->posxup - 0.8, 3, $up_excl_tax, 0,
'R', 0);
445 $pdf->SetXY($this->posxqty, $curY);
446 $pdf->MultiCell($this->posxunit - $this->posxqty - 0.8, 4, $qty, 0,
'R');
451 $pdf->SetXY($this->posxunit, $curY);
452 $pdf->MultiCell($this->posxdiscount - $this->posxunit - 0.8, 4, $unit, 0,
'L');
456 if (
$object->lines[$i]->remise_percent) {
457 $pdf->SetXY($this->posxdiscount - 2, $curY);
459 $pdf->MultiCell($this->postotalht - $this->posxdiscount - 1, 3, $remise_percent, 0,
'R');
464 $pdf->SetXY($this->postotalht, $curY);
465 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->postotalht, 3, $total_excl_tax, 0,
'R', 0);
468 if (isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) {
469 $tvaligne =
$object->lines[$i]->multicurrency_total_tva;
471 $tvaligne =
$object->lines[$i]->total_tva;
474 $localtax1ligne =
$object->lines[$i]->total_localtax1;
475 $localtax2ligne =
$object->lines[$i]->total_localtax2;
482 $vatrate = (string)
$object->lines[$i]->tva_tx;
483 $localtax1rate = (string)
$object->lines[$i]->localtax1_tx;
484 $localtax2rate = (string)
$object->lines[$i]->localtax2_tx;
486 if ((
$object->lines[$i]->info_bits & 0x01) == 0x01) {
489 if (empty($this->tva[$vatrate])) {
490 $this->tva[$vatrate] = 0;
492 if (empty($this->localtax1[$localtax1rate])) {
493 $this->localtax1[$localtax1rate] = 0;
495 if (empty($this->localtax2[$localtax2rate])) {
496 $this->localtax2[$localtax2rate] = 0;
498 $this->tva[$vatrate] += $tvaligne;
499 $this->localtax1[$localtax1rate] += $localtax1ligne;
500 $this->localtax2[$localtax2rate] += $localtax2ligne;
502 if ($posYAfterImage > $posYAfterDescription) {
503 $nexY = $posYAfterImage;
508 $pdf->setPage($pageposafter);
509 $pdf->SetLineStyle(array(
'dash' =>
'1,1',
'color' => array(80, 80, 80)));
511 $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
512 $pdf->SetLineStyle(array(
'dash' => 0));
518 while ($pagenb < $pageposafter) {
519 $pdf->setPage($pagenb);
521 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1,
$object->multicurrency_code);
523 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1,
$object->multicurrency_code);
527 $pdf->setPage($pagenb);
528 $pdf->setPageOrientation(
'', 1, 0);
533 if (isset(
$object->lines[$i + 1]->pagebreak) &&
$object->lines[$i + 1]->pagebreak) {
535 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1,
$object->multicurrency_code);
537 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1,
$object->multicurrency_code);
542 if (!empty($tplidx)) {
543 $pdf->useTemplate($tplidx);
554 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0,
$object->multicurrency_code);
555 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
557 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0,
$object->multicurrency_code);
558 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
564 $amount_credit_notes_included = 0;
565 $amount_deposits_included = 0;
568 if (($deja_regle || $amount_credit_notes_included || $amount_deposits_included) && !
getDolGlobalString(
'SUPPLIER_INVOICE_NO_PAYMENT_DETAILS')) {
574 if (method_exists($pdf,
'AliasNbPages')) {
575 $pdf->AliasNbPages();
580 $pdf->Output($file,
'F');
583 $hookmanager->initHooks(array(
'pdfgeneration'));
584 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
586 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
588 $this->error = $hookmanager->error;
589 $this->errors = $hookmanager->errors;
594 $this->result = array(
'fullpath' => $file);
598 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
602 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"SUPPLIER_OUTPUTDIR");
622 global $conf, $mysoc, $hookmanager;
633 $pdf->SetFont(
'',
'', $default_font_size - 1);
638 if ($this->page_largeur < 210) {
641 $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
647 $pdf->SetFillColor(255, 255, 255);
648 $pdf->SetXY($col1x, $tab2_top);
649 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalHT"), 0,
'L', 1);
651 $total_ht = ((isModEnabled(
"multicurrency") && isset(
$object->multicurrency_tx) &&
$object->multicurrency_tx != 1) ?
$object->multicurrency_total_ht :
$object->total_ht);
652 $pdf->SetXY($col2x, $tab2_top);
653 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * ($total_ht + (!empty(
$object->remise) ?
$object->remise : 0)), 0, $outputlangs), 0,
'R', 1);
656 $pdf->SetFillColor(248, 248, 248);
658 $total_ttc = (isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ?
$object->multicurrency_total_ttc :
$object->total_ttc;
660 $this->atleastoneratenotnull = 0;
661 foreach ($this->tva as $tvakey => $tvaval) {
663 $this->atleastoneratenotnull++;
666 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
670 if (preg_match(
'/\*/', $tvakey)) {
671 $tvakey = str_replace(
'*',
'', $tvakey);
672 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
675 $totalvat = $outputlangs->transcountrynoentities(
"TotalVAT", $mysoc->country_code).
' ';
676 $totalvat .=
vatrate($tvakey, 1).$tvacompl;
677 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
679 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
680 $pdf->MultiCell($largcol2, $tab2_hl,
price($tvaval, 0, $outputlangs), 0,
'R', 1);
683 if (!$this->atleastoneratenotnull) {
685 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
686 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transcountrynoentities(
"TotalVAT", $mysoc->country_code), 0,
'L', 1);
687 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
688 $pdf->MultiCell($largcol2, $tab2_hl,
price(
$object->total_tva, 0, $outputlangs), 0,
'R', 1);
693 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
694 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transcountrynoentities(
"TotalLT1", $mysoc->country_code), 0,
'L', 1);
695 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
696 $pdf->MultiCell($largcol2, $tab2_hl,
price(
$object->total_localtax1, 0, $outputlangs), 0,
'R', 1);
702 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
703 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transcountrynoentities(
"TotalLT2", $mysoc->country_code), 0,
'L', 1);
704 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
705 $pdf->MultiCell($largcol2, $tab2_hl,
price(
$object->total_localtax2, 0, $outputlangs), 0,
'R', 1);
711 foreach ($this->localtax1 as $tvakey => $tvaval) {
716 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
719 if (preg_match(
'/\*/', (
string) $tvakey)) {
720 $tvakey = str_replace(
'*',
'', (
string) $tvakey);
721 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
723 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1", $mysoc->country_code).
' ';
724 $totalvat .=
vatrate((
string) abs((
float) $tvakey), 1).$tvacompl;
725 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
727 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
728 $pdf->MultiCell($largcol2, $tab2_hl,
price((
string) $tvaval, 0, $outputlangs), 0,
'R', 1);
736 foreach ($this->localtax2 as $tvakey => $tvaval) {
741 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
744 if (preg_match(
'/\*/', (
string) $tvakey)) {
745 $tvakey = str_replace(
'*',
'', (
string) $tvakey);
746 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
748 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT2", $mysoc->country_code).
' ';
749 $totalvat .=
vatrate((
string) abs((
float) $tvakey), 1).$tvacompl;
750 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
752 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
753 $pdf->MultiCell($largcol2, $tab2_hl,
price((
string) $tvaval, 0, $outputlangs), 0,
'R', 1);
761 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
762 $pdf->SetTextColor(0, 0, 60);
763 $pdf->SetFillColor(224, 224, 224);
764 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalTTC"), $useborder,
'L', 1);
766 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
767 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * $total_ttc, 0, $outputlangs), $useborder,
'R', 1);
769 $pdf->SetTextColor(0, 0, 0);
770 $creditnoteamount =
$object->getSumCreditNotesUsed((isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? 1 : 0);
771 $depositsamount =
$object->getSumDepositsUsed((isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? 1 : 0);
773 $resteapayer =
price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount,
'MT');
778 if (($deja_regle > 0 || $creditnoteamount > 0 || $depositsamount > 0) && !
getDolGlobalString(
'INVOICE_NO_PAYMENT_DETAILS')) {
781 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
782 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"Paid"), 0,
'L', 0);
783 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
784 $pdf->MultiCell($largcol2, $tab2_hl,
price($deja_regle + $depositsamount, 0, $outputlangs), 0,
'R', 0);
787 if ($creditnoteamount) {
788 $labeltouse = ($outputlangs->transnoentities(
"CreditNotesOrExcessReceived") !=
"CreditNotesOrExcessReceived") ? $outputlangs->transnoentities(
"CreditNotesOrExcessReceived") : $outputlangs->transnoentities(
"CreditNotes");
790 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
791 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $labeltouse, 0,
'L', 0);
792 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
793 $pdf->MultiCell($largcol2, $tab2_hl,
price($creditnoteamount, 0, $outputlangs), 0,
'R', 0);
797 if (
$object->close_code == FactureFournisseur::CLOSECODE_DISCOUNTVAT) {
799 $pdf->SetFillColor(255, 255, 255);
801 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
802 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"EscompteOfferedShort"), $useborder,
'L', 1);
803 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
804 $pdf->MultiCell($largcol2, $tab2_hl,
price(
$object->total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 0, $outputlangs), $useborder,
'R', 1);
810 $pdf->SetTextColor(0, 0, 60);
811 $pdf->SetFillColor(224, 224, 224);
812 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
813 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"RemainderToPay"), $useborder,
'L', 1);
815 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
816 $pdf->MultiCell($largcol2, $tab2_hl,
price($resteapayer, 0, $outputlangs), $useborder,
'R', 1);
817 $pdf->SetFont(
'',
'', $default_font_size - 1);
818 $pdf->SetTextColor(0, 0, 0);
821 $parameters = array(
'pdf' => &$pdf,
'object' => &
$object,
'outputlangs' => $outputlangs,
'index' => &$index,
'posy' => $posy);
823 $reshook = $hookmanager->executeHooks(
'afterPDFTotalTable', $parameters, $this);
825 $this->error = $hookmanager->error;
826 $this->errors = $hookmanager->errors;
830 return ($tab2_top + ($tab2_hl * $index));
847 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency =
'')
857 $currency = !empty($currency) ? $currency : $conf->currency;
861 $pdf->SetTextColor(0, 0, 0);
862 $pdf->SetFont(
'',
'', $default_font_size - 2);
864 if (empty($hidetop)) {
865 $titre = $outputlangs->transnoentities(
"AmountInCurrency", $outputlangs->transnoentitiesnoconv(
"Currency".$currency));
866 $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
867 $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
871 $pdf->RoundedRect($this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_droite - $this->marge_gauche, 5, $this->corner_radius,
'1001',
'F',
null, explode(
',',
getDolGlobalString(
'MAIN_PDF_TITLE_BACKGROUND_COLOR')));
875 $pdf->SetDrawColor(128, 128, 128);
876 $pdf->SetFont(
'',
'', $default_font_size - 1);
879 $this->
printRoundedRect($pdf, $this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $tab_height, $this->corner_radius, $hidetop, $hidebottom,
'D');
881 if (empty($hidetop)) {
882 $pdf->line($this->marge_gauche, $tab_top + 5, $this->page_largeur - $this->marge_droite, $tab_top + 5);
884 $pdf->SetXY($this->posxdesc - 1, $tab_top + 1);
885 $pdf->MultiCell(108, 2, $outputlangs->transnoentities(
"Designation"),
'',
'L');
889 $pdf->line($this->posxtva - 1, $tab_top, $this->posxtva - 1, $tab_top + $tab_height);
890 if (empty($hidetop)) {
891 $pdf->SetXY($this->posxtva - 3, $tab_top + 1);
892 $pdf->MultiCell($this->posxup - $this->posxtva + 3, 2, $outputlangs->transnoentities(
"VAT"),
'',
'C');
896 $pdf->line($this->posxup - 1, $tab_top, $this->posxup - 1, $tab_top + $tab_height);
897 if (empty($hidetop)) {
898 $pdf->SetXY($this->posxup - 1, $tab_top + 1);
899 $pdf->MultiCell($this->posxqty - $this->posxup - 1, 2, $outputlangs->transnoentities(
"PriceUHT"),
'',
'C');
902 $pdf->line($this->posxqty - 1, $tab_top, $this->posxqty - 1, $tab_top + $tab_height);
903 if (empty($hidetop)) {
904 $pdf->SetXY($this->posxqty - 1, $tab_top + 1);
905 $pdf->MultiCell($this->posxunit - $this->posxqty - 1, 2, $outputlangs->transnoentities(
"Qty"),
'',
'C');
909 $pdf->line($this->posxunit - 1, $tab_top, $this->posxunit - 1, $tab_top + $tab_height);
910 if (empty($hidetop)) {
911 $pdf->SetXY($this->posxunit - 1, $tab_top + 1);
913 $this->posxdiscount - $this->posxunit - 1,
915 $outputlangs->transnoentities(
"Unit"),
922 if ($this->atleastonediscount) {
923 $pdf->line($this->posxdiscount - 1, $tab_top, $this->posxdiscount - 1, $tab_top + $tab_height);
924 if (empty($hidetop)) {
925 $pdf->SetXY($this->posxdiscount - 1, $tab_top + 1);
926 $pdf->MultiCell($this->postotalht - $this->posxdiscount + 1, 2, $outputlangs->transnoentities(
"ReductionShort"),
'',
'C');
930 $pdf->line($this->postotalht, $tab_top, $this->postotalht, $tab_top + $tab_height);
931 if (empty($hidetop)) {
932 $pdf->SetXY($this->postotalht - 1, $tab_top + 1);
933 $pdf->MultiCell(30, 2, $outputlangs->transnoentities(
"TotalHTShort"),
'',
'C');
960 $tab3_top = $posy + 8;
963 if ($this->page_largeur < 210) {
969 $pdf->SetFont(
'',
'', $default_font_size - 3);
970 $pdf->SetXY($tab3_posx, $tab3_top - 4);
971 $pdf->MultiCell(60, 3, $outputlangs->transnoentities(
"PaymentsAlreadyDone"), 0,
'L', 0);
973 $pdf->line($tab3_posx, $tab3_top, $tab3_posx + $tab3_width, $tab3_top);
975 $pdf->SetFont(
'',
'', $default_font_size - 4);
976 $pdf->SetXY($tab3_posx, $tab3_top);
977 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Payment"), 0,
'L', 0);
978 $pdf->SetXY($tab3_posx + 21, $tab3_top);
979 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Amount"), 0,
'L', 0);
980 $pdf->SetXY($tab3_posx + 40, $tab3_top);
981 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Type"), 0,
'L', 0);
982 $pdf->SetXY($tab3_posx + 58, $tab3_top);
983 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Num"), 0,
'L', 0);
985 $pdf->line($tab3_posx, $tab3_top - 1 + $tab3_height, $tab3_posx + $tab3_width, $tab3_top - 1 + $tab3_height);
989 $pdf->SetFont(
'',
'', $default_font_size - 4);
995 $sql =
"SELECT p.datep as date, p.fk_paiement as type, p.num_paiement as num_payment, pf.amount as amount, pf.multicurrency_amount,";
997 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiementfourn_facturefourn as pf, ".MAIN_DB_PREFIX.
"paiementfourn as p";
998 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as cp ON p.fk_paiement = cp.id";
999 $sql .=
" WHERE pf.fk_paiementfourn = p.rowid and pf.fk_facturefourn = ".((int)
$object->id);
1000 $sql .=
" ORDER BY p.datep";
1001 $resql = $this->db->query($sql);
1003 $num = $this->db->num_rows($resql);
1007 $row = $this->db->fetch_object($resql);
1009 $pdf->SetXY($tab3_posx, $tab3_top + $y);
1010 $pdf->MultiCell(20, 3,
dol_print_date($this->db->jdate($row->date),
'day',
false, $outputlangs,
true), 0,
'L', 0);
1011 $pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
1012 $pdf->MultiCell(20, 3,
price($sign * ((isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? $row->multicurrency_amount : $row->amount)), 0,
'L', 0);
1013 $pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
1014 $oper = $outputlangs->transnoentitiesnoconv(
"PaymentTypeShort".$row->code);
1016 $pdf->MultiCell(20, 3, $oper, 0,
'L', 0);
1017 $pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
1018 $pdf->MultiCell(30, 3, $row->num_payment, 0,
'L', 0);
1020 $pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
1025 $this->error = $this->db->lasterror();
1043 global $langs, $conf, $mysoc;
1046 $outputlangs->loadLangs(array(
"main",
"orders",
"companies",
"bills"));
1053 $pdf->SetTextColor(0, 0, 60);
1054 $pdf->SetFont(
'',
'B', $default_font_size + 3);
1058 $posy = $this->marge_haute;
1059 $posx = $this->page_largeur - $this->marge_droite - 100;
1061 $pdf->SetXY($this->marge_gauche, $posy);
1083 $text = $this->emetteur->name;
1084 $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0,
'L');
1087 $pdf->SetFont(
'',
'B', $default_font_size + 3);
1088 $pdf->SetXY($posx, $posy);
1089 $pdf->SetTextColor(0, 0, 60);
1090 $title = $outputlangs->transnoentities(
"PdfInvoiceTitle");
1092 $title = $outputlangs->transnoentities(
"InvoiceReplacement");
1095 $title = $outputlangs->transnoentities(
"InvoiceAvoir");
1098 $title = $outputlangs->transnoentities(
"InvoiceDeposit");
1100 $pdf->MultiCell($w, 3, $title.
" ".$outputlangs->convToOutputCharset(
$object->ref),
'',
'R');
1105 $pdf->SetFont(
'',
'B', $default_font_size);
1106 $pdf->SetXY($posx, $posy);
1107 $pdf->SetTextColor(0, 0, 60);
1108 $pdf->MultiCell($w, 4, $outputlangs->transnoentities(
"RefSupplier").
" : ".
$object->ref_supplier,
'',
'R');
1112 $pdf->SetFont(
'',
'', $default_font_size - 1);
1116 if (!empty(
$object->project->ref)) {
1118 $pdf->SetXY($posx, $posy);
1119 $pdf->SetTextColor(0, 0, 60);
1120 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Project").
" : ".(empty(
$object->project->title) ?
'' :
$object->project->title),
'',
'R');
1126 if (!empty(
$object->project->ref)) {
1127 $outputlangs->load(
"projects");
1129 $pdf->SetXY($posx, $posy);
1130 $langs->load(
"projects");
1131 $pdf->SetTextColor(0, 0, 60);
1132 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Project").
" : ".(empty(
$object->project->ref) ?
'' :
$object->project->ref),
'',
'R');
1138 $pdf->SetXY($posx, $posy);
1139 $pdf->SetTextColor(0, 0, 60);
1140 $pdf->MultiCell($w, 4, $outputlangs->transnoentities(
"Date").
" : ".
dol_print_date(
$object->date,
"day",
false, $outputlangs,
true),
'',
'R');
1143 $pdf->SetXY($posx, $posy);
1144 $pdf->SetTextColor(255, 0, 0);
1145 $pdf->MultiCell($w, 4, strtolower($outputlangs->transnoentities(
"OrderToProcess")),
'',
'R');
1148 if (
$object->thirdparty->code_fournisseur) {
1150 $pdf->SetXY($posx, $posy);
1151 $pdf->SetTextColor(0, 0, 60);
1152 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"SupplierCode").
" : ".$outputlangs->transnoentities(
$object->thirdparty->code_fournisseur),
'',
'R');
1156 $pdf->SetTextColor(0, 0, 60);
1160 $current_y = $pdf->getY();
1162 if ($current_y < $pdf->getY()) {
1163 $top_shift = $pdf->getY() - $current_y;
1168 $carac_emetteur =
'';
1170 $arrayidcontact =
$object->getIdContact(
'internal',
'SALESREPFOLL');
1171 if (count($arrayidcontact) > 0) {
1172 $object->fetch_user($arrayidcontact[0]);
1173 $labelbeforecontactname = ($outputlangs->transnoentities(
"FromContactName") !=
'FromContactName' ? $outputlangs->transnoentities(
"FromContactName") : $outputlangs->transnoentities(
"Name"));
1174 $carac_emetteur .= ($carac_emetteur ?
"\n" :
'').$labelbeforecontactname.
": ".$outputlangs->convToOutputCharset(
$object->user->getFullName($outputlangs));
1176 $carac_emetteur .= (
getDolGlobalInt(
'PDF_SHOW_PHONE_AFTER_USER_CONTACT') && !empty(
$object->user->office_phone)) ?
$object->user->office_phone :
'';
1180 $carac_emetteur .=
"\n";
1186 $posy = 42 + $top_shift;
1187 $posx = $this->marge_gauche;
1189 $posx = $this->page_largeur - $this->marge_droite - 80;
1194 $pdf->SetTextColor(0, 0, 0);
1195 $pdf->SetFont(
'',
'', $default_font_size - 2);
1196 $pdf->SetXY($posx, $posy - 5);
1197 $pdf->MultiCell(80, 5, $outputlangs->transnoentities(
"BillFrom"), 0,
'L');
1198 $pdf->SetXY($posx, $posy);
1199 $pdf->SetFillColor(230, 230, 230);
1200 $pdf->RoundedRect($posx, $posy, 82, $hautcadre, $this->corner_radius,
'1234',
'F');
1201 $pdf->SetTextColor(0, 0, 60);
1204 $pdf->SetXY($posx + 2, $posy + 3);
1205 $pdf->SetFont(
'',
'B', $default_font_size);
1206 $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0,
'L');
1207 $posy = $pdf->getY();
1210 $pdf->SetXY($posx + 2, $posy);
1211 $pdf->SetFont(
'',
'', $default_font_size - 1);
1212 $pdf->MultiCell(80, 4, $carac_emetteur, 0,
'L');
1217 $usecontact =
false;
1218 $arrayidcontact =
$object->getIdContact(
'internal',
'BILLING');
1219 if (count($arrayidcontact) > 0) {
1221 $result =
$object->fetch_contact($arrayidcontact[0]);
1225 if ($usecontact && (
$object->contact->socid !=
$object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) ||
getDolGlobalString(
'MAIN_USE_COMPANY_NAME_OF_CONTACT')))) {
1226 $thirdparty =
$object->contact;
1228 $thirdparty = $mysoc;
1237 if ($this->page_largeur < 210) {
1240 $posy = 42 + $top_shift;
1241 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
1243 $posx = $this->marge_gauche;
1247 $pdf->SetTextColor(0, 0, 0);
1248 $pdf->SetFont(
'',
'', $default_font_size - 2);
1249 $pdf->SetXY($posx + 2, $posy - 5);
1250 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"BillTo"), 0,
'L');
1251 $pdf->RoundedRect($posx, $posy, $widthrecbox, $hautcadre, $this->corner_radius,
'1234',
'D');
1254 $pdf->SetXY($posx + 2, $posy + 3);
1255 $pdf->SetFont(
'',
'B', $default_font_size);
1256 $pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0,
'L');
1258 $posy = $pdf->getY();
1261 $pdf->SetFont(
'',
'', $default_font_size - 1);
1262 $pdf->SetXY($posx + 2, $posy);
1263 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0,
'L');