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 $logodir = $conf->mycompany->dir_output;
255 if (!empty($conf->mycompany->multidir_output[
$object->entity])) {
256 $logodir = $conf->mycompany->multidir_output[
$object->entity];
258 $pagecount = $pdf->setSourceFile($logodir .
'/' .
getDolGlobalString(
'MAIN_ADD_PDF_BACKGROUND'));
259 $tplidx = $pdf->importPage(1);
264 $pdf->SetDrawColor(128, 128, 128);
266 $pdf->SetTitle($outputlangs->convToOutputCharset(
$object->ref));
267 $pdf->SetSubject($outputlangs->transnoentities(
"PdfInvoiceTitle"));
268 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
269 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
270 $pdf->SetKeyWords($outputlangs->convToOutputCharset(
$object->ref).
" ".$outputlangs->transnoentities(
"PdfInvoiceTitle").
" ".$outputlangs->convToOutputCharset(
$object->thirdparty->name));
272 $pdf->SetCompression(
false);
276 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
279 for ($i = 0; $i < $nblines; $i++) {
280 if (
$object->lines[$i]->remise_percent) {
281 $this->atleastonediscount++;
284 if (empty($this->atleastonediscount)) {
285 $delta = ($this->postotalht - $this->posxdiscount);
286 $this->posxpicture += $delta;
287 $this->posxtva += $delta;
288 $this->posxup += $delta;
289 $this->posxqty += $delta;
290 $this->posxunit += $delta;
291 $this->posxdiscount += $delta;
297 if (!empty($tplidx)) {
298 $pdf->useTemplate($tplidx);
302 $pdf->SetFont(
'',
'', $default_font_size - 1);
303 $pdf->MultiCell(0, 3,
'');
304 $pdf->SetTextColor(0, 0, 0);
306 $tab_top = 90 + $top_shift;
307 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
310 if (isModEnabled(
'incoterm')) {
311 $desc_incoterms =
$object->getIncotermsForPDF();
312 if ($desc_incoterms) {
315 $pdf->SetFont(
'',
'', $default_font_size - 1);
316 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1,
dol_htmlentitiesbr($desc_incoterms), 0, 1);
317 $nexY = $pdf->GetY();
318 $height_incoterms = $nexY - $tab_top;
321 $pdf->SetDrawColor(192, 192, 192);
322 $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_incoterms + 1);
324 $tab_top = $nexY + 6;
329 $notetoshow = empty(
$object->note_public) ?
'' :
$object->note_public;
333 $extranote = $this->getExtrafieldsInHtml(
$object, $outputlangs);
334 if (!empty($extranote)) {
347 $pdf->SetFont(
'',
'', $default_font_size - 1);
348 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1,
dol_htmlentitiesbr($notetoshow), 0, 1);
349 $nexY = $pdf->GetY();
350 $height_note = $nexY - $tab_top;
353 $pdf->SetDrawColor(192, 192, 192);
354 $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1);
356 $tab_top = $nexY + 6;
359 $iniY = $tab_top + 7;
360 $curY = $tab_top + 7;
361 $nexY = $tab_top + 7;
364 for ($i = 0; $i < $nblines; $i++) {
366 $pdf->SetFont(
'',
'', $default_font_size - 1);
367 $pdf->SetTextColor(0, 0, 0);
375 $pdf->setTopMargin($tab_top_newpage);
376 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext + $heightforinfotot);
377 $pageposbefore = $pdf->getPage();
379 $showpricebeforepagebreak = 1;
383 $curX = $this->posxdesc - 1;
385 $pdf->startTransaction();
386 pdf_writelinedesc($pdf,
$object, $i, $outputlangs, $this->posxtva - $curX, 3, $curX, $curY, $hideref, $hidedesc, 1);
387 $pageposafter = $pdf->getPage();
388 if ($pageposafter > $pageposbefore) {
389 $pdf->rollbackTransaction(
true);
390 $pageposafter = $pageposbefore;
392 $pdf->setPageOrientation(
'', 1, $heightforfooter);
393 pdf_writelinedesc($pdf,
$object, $i, $outputlangs, $this->posxtva - $curX, 4, $curX, $curY, $hideref, $hidedesc, 1);
394 $posyafter = $pdf->GetY();
395 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
396 if ($i == ($nblines - 1)) {
397 $pdf->AddPage(
'',
'',
true);
398 if (!empty($tplidx)) {
399 $pdf->useTemplate($tplidx);
404 $pdf->setPage($pageposafter + 1);
410 $showpricebeforepagebreak = 1;
412 $showpricebeforepagebreak = 0;
416 $pdf->commitTransaction();
418 $posYAfterDescription = $pdf->GetY();
420 $nexY = $pdf->GetY();
421 $pageposafter = $pdf->getPage();
422 $pdf->setPage($pageposbefore);
423 $pdf->setTopMargin($this->marge_haute);
424 $pdf->setPageOrientation(
'', 1, 0);
427 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
428 $pdf->setPage($pageposafter);
429 $curY = $tab_top_newpage;
432 $pdf->SetFont(
'',
'', $default_font_size - 1);
437 $pdf->SetXY($this->posxtva, $curY);
438 $pdf->MultiCell($this->posxup - $this->posxtva - 1, 3, $vat_rate, 0,
'R');
443 $pdf->SetXY($this->posxup, $curY);
444 $pdf->MultiCell($this->posxqty - $this->posxup - 0.8, 3, $up_excl_tax, 0,
'R', 0);
448 $pdf->SetXY($this->posxqty, $curY);
449 $pdf->MultiCell($this->posxunit - $this->posxqty - 0.8, 4, $qty, 0,
'R');
454 $pdf->SetXY($this->posxunit, $curY);
455 $pdf->MultiCell($this->posxdiscount - $this->posxunit - 0.8, 4, $unit, 0,
'L');
459 if (
$object->lines[$i]->remise_percent) {
460 $pdf->SetXY($this->posxdiscount - 2, $curY);
462 $pdf->MultiCell($this->postotalht - $this->posxdiscount - 1, 3, $remise_percent, 0,
'R');
467 $pdf->SetXY($this->postotalht, $curY);
468 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->postotalht, 3, $total_excl_tax, 0,
'R', 0);
471 if (isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) {
472 $tvaligne =
$object->lines[$i]->multicurrency_total_tva;
474 $tvaligne =
$object->lines[$i]->total_tva;
477 $localtax1ligne =
$object->lines[$i]->total_localtax1;
478 $localtax2ligne =
$object->lines[$i]->total_localtax2;
485 $vatrate = (string)
$object->lines[$i]->tva_tx;
486 $localtax1rate = (string)
$object->lines[$i]->localtax1_tx;
487 $localtax2rate = (string)
$object->lines[$i]->localtax2_tx;
489 if ((
$object->lines[$i]->info_bits & 0x01) == 0x01) {
492 if (empty($this->tva[$vatrate])) {
493 $this->tva[$vatrate] = 0;
495 if (empty($this->localtax1[$localtax1rate])) {
496 $this->localtax1[$localtax1rate] = 0;
498 if (empty($this->localtax2[$localtax2rate])) {
499 $this->localtax2[$localtax2rate] = 0;
501 $this->tva[$vatrate] += $tvaligne;
502 $this->localtax1[$localtax1rate] += $localtax1ligne;
503 $this->localtax2[$localtax2rate] += $localtax2ligne;
505 if ($posYAfterImage > $posYAfterDescription) {
506 $nexY = $posYAfterImage;
511 $pdf->setPage($pageposafter);
512 $pdf->SetLineStyle(array(
'dash' =>
'1,1',
'color' => array(80, 80, 80)));
514 $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
515 $pdf->SetLineStyle(array(
'dash' => 0));
521 while ($pagenb < $pageposafter) {
522 $pdf->setPage($pagenb);
524 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1,
$object->multicurrency_code);
526 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1,
$object->multicurrency_code);
530 $pdf->setPage($pagenb);
531 $pdf->setPageOrientation(
'', 1, 0);
536 if (isset(
$object->lines[$i + 1]->pagebreak) &&
$object->lines[$i + 1]->pagebreak) {
538 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1,
$object->multicurrency_code);
540 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1,
$object->multicurrency_code);
545 if (!empty($tplidx)) {
546 $pdf->useTemplate($tplidx);
557 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0,
$object->multicurrency_code);
558 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
560 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0,
$object->multicurrency_code);
561 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
567 $amount_credit_notes_included = 0;
568 $amount_deposits_included = 0;
571 if (($deja_regle || $amount_credit_notes_included || $amount_deposits_included) && !
getDolGlobalString(
'SUPPLIER_INVOICE_NO_PAYMENT_DETAILS')) {
577 if (method_exists($pdf,
'AliasNbPages')) {
578 $pdf->AliasNbPages();
583 $pdf->Output($file,
'F');
586 $hookmanager->initHooks(array(
'pdfgeneration'));
587 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
589 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
591 $this->error = $hookmanager->error;
592 $this->errors = $hookmanager->errors;
597 $this->result = array(
'fullpath' => $file);
601 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
605 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"SUPPLIER_OUTPUTDIR");
625 global $conf, $mysoc, $hookmanager;
636 $pdf->SetFont(
'',
'', $default_font_size - 1);
641 if ($this->page_largeur < 210) {
644 $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
650 $pdf->SetFillColor(255, 255, 255);
651 $pdf->SetXY($col1x, $tab2_top);
652 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalHT"), 0,
'L', 1);
654 $total_ht = ((isModEnabled(
"multicurrency") && isset(
$object->multicurrency_tx) &&
$object->multicurrency_tx != 1) ?
$object->multicurrency_total_ht :
$object->total_ht);
655 $pdf->SetXY($col2x, $tab2_top);
656 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * ($total_ht + (!empty(
$object->remise) ?
$object->remise : 0)), 0, $outputlangs), 0,
'R', 1);
659 $pdf->SetFillColor(248, 248, 248);
661 $total_ttc = (isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ?
$object->multicurrency_total_ttc :
$object->total_ttc;
663 $this->atleastoneratenotnull = 0;
664 foreach ($this->tva as $tvakey => $tvaval) {
666 $this->atleastoneratenotnull++;
669 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
673 if (preg_match(
'/\*/', $tvakey)) {
674 $tvakey = str_replace(
'*',
'', $tvakey);
675 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
678 $totalvat = $outputlangs->transcountrynoentities(
"TotalVAT", $mysoc->country_code).
' ';
679 $totalvat .=
vatrate($tvakey, 1).$tvacompl;
680 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
682 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
683 $pdf->MultiCell($largcol2, $tab2_hl,
price($tvaval, 0, $outputlangs), 0,
'R', 1);
686 if (!$this->atleastoneratenotnull) {
688 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
689 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transcountrynoentities(
"TotalVAT", $mysoc->country_code), 0,
'L', 1);
690 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
691 $pdf->MultiCell($largcol2, $tab2_hl,
price(
$object->total_tva, 0, $outputlangs), 0,
'R', 1);
696 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
697 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transcountrynoentities(
"TotalLT1", $mysoc->country_code), 0,
'L', 1);
698 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
699 $pdf->MultiCell($largcol2, $tab2_hl,
price(
$object->total_localtax1, 0, $outputlangs), 0,
'R', 1);
705 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
706 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transcountrynoentities(
"TotalLT2", $mysoc->country_code), 0,
'L', 1);
707 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
708 $pdf->MultiCell($largcol2, $tab2_hl,
price(
$object->total_localtax2, 0, $outputlangs), 0,
'R', 1);
714 foreach ($this->localtax1 as $tvakey => $tvaval) {
719 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
722 if (preg_match(
'/\*/', (
string) $tvakey)) {
723 $tvakey = str_replace(
'*',
'', (
string) $tvakey);
724 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
726 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1", $mysoc->country_code).
' ';
727 $totalvat .=
vatrate(abs($tvakey), 1).$tvacompl;
728 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
730 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
731 $pdf->MultiCell($largcol2, $tab2_hl,
price($tvaval, 0, $outputlangs), 0,
'R', 1);
739 foreach ($this->localtax2 as $tvakey => $tvaval) {
744 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
747 if (preg_match(
'/\*/', (
string) $tvakey)) {
748 $tvakey = str_replace(
'*',
'', (
string) $tvakey);
749 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
751 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT2", $mysoc->country_code).
' ';
752 $totalvat .=
vatrate(abs($tvakey), 1).$tvacompl;
753 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
755 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
756 $pdf->MultiCell($largcol2, $tab2_hl,
price($tvaval, 0, $outputlangs), 0,
'R', 1);
764 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
765 $pdf->SetTextColor(0, 0, 60);
766 $pdf->SetFillColor(224, 224, 224);
767 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalTTC"), $useborder,
'L', 1);
769 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
770 $pdf->MultiCell($largcol2, $tab2_hl,
price($sign * $total_ttc, 0, $outputlangs), $useborder,
'R', 1);
772 $pdf->SetTextColor(0, 0, 0);
773 $creditnoteamount =
$object->getSumCreditNotesUsed((isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? 1 : 0);
774 $depositsamount =
$object->getSumDepositsUsed((isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? 1 : 0);
776 $resteapayer =
price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount,
'MT');
781 if (($deja_regle > 0 || $creditnoteamount > 0 || $depositsamount > 0) && !
getDolGlobalString(
'INVOICE_NO_PAYMENT_DETAILS')) {
784 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
785 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"Paid"), 0,
'L', 0);
786 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
787 $pdf->MultiCell($largcol2, $tab2_hl,
price($deja_regle + $depositsamount, 0, $outputlangs), 0,
'R', 0);
790 if ($creditnoteamount) {
791 $labeltouse = ($outputlangs->transnoentities(
"CreditNotesOrExcessReceived") !=
"CreditNotesOrExcessReceived") ? $outputlangs->transnoentities(
"CreditNotesOrExcessReceived") : $outputlangs->transnoentities(
"CreditNotes");
793 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
794 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $labeltouse, 0,
'L', 0);
795 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
796 $pdf->MultiCell($largcol2, $tab2_hl,
price($creditnoteamount, 0, $outputlangs), 0,
'R', 0);
800 if (
$object->close_code == FactureFournisseur::CLOSECODE_DISCOUNTVAT) {
802 $pdf->SetFillColor(255, 255, 255);
804 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
805 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"EscompteOfferedShort"), $useborder,
'L', 1);
806 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
807 $pdf->MultiCell($largcol2, $tab2_hl,
price(
$object->total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 0, $outputlangs), $useborder,
'R', 1);
813 $pdf->SetTextColor(0, 0, 60);
814 $pdf->SetFillColor(224, 224, 224);
815 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
816 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"RemainderToPay"), $useborder,
'L', 1);
818 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
819 $pdf->MultiCell($largcol2, $tab2_hl,
price($resteapayer, 0, $outputlangs), $useborder,
'R', 1);
820 $pdf->SetFont(
'',
'', $default_font_size - 1);
821 $pdf->SetTextColor(0, 0, 0);
824 $parameters = array(
'pdf' => &$pdf,
'object' => &
$object,
'outputlangs' => $outputlangs,
'index' => &$index,
'posy' => $posy);
826 $reshook = $hookmanager->executeHooks(
'afterPDFTotalTable', $parameters, $this);
828 $this->error = $hookmanager->error;
829 $this->errors = $hookmanager->errors;
833 return ($tab2_top + ($tab2_hl * $index));
850 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency =
'')
860 $currency = !empty($currency) ? $currency : $conf->currency;
864 $pdf->SetTextColor(0, 0, 0);
865 $pdf->SetFont(
'',
'', $default_font_size - 2);
867 if (empty($hidetop)) {
868 $titre = $outputlangs->transnoentities(
"AmountInCurrency", $outputlangs->transnoentitiesnoconv(
"Currency".$currency));
869 $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
870 $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
874 $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')));
878 $pdf->SetDrawColor(128, 128, 128);
879 $pdf->SetFont(
'',
'', $default_font_size - 1);
882 $this->
printRect($pdf, $this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $tab_height, $hidetop, $hidebottom);
884 if (empty($hidetop)) {
885 $pdf->line($this->marge_gauche, $tab_top + 5, $this->page_largeur - $this->marge_droite, $tab_top + 5);
887 $pdf->SetXY($this->posxdesc - 1, $tab_top + 1);
888 $pdf->MultiCell(108, 2, $outputlangs->transnoentities(
"Designation"),
'',
'L');
892 $pdf->line($this->posxtva - 1, $tab_top, $this->posxtva - 1, $tab_top + $tab_height);
893 if (empty($hidetop)) {
894 $pdf->SetXY($this->posxtva - 3, $tab_top + 1);
895 $pdf->MultiCell($this->posxup - $this->posxtva + 3, 2, $outputlangs->transnoentities(
"VAT"),
'',
'C');
899 $pdf->line($this->posxup - 1, $tab_top, $this->posxup - 1, $tab_top + $tab_height);
900 if (empty($hidetop)) {
901 $pdf->SetXY($this->posxup - 1, $tab_top + 1);
902 $pdf->MultiCell($this->posxqty - $this->posxup - 1, 2, $outputlangs->transnoentities(
"PriceUHT"),
'',
'C');
905 $pdf->line($this->posxqty - 1, $tab_top, $this->posxqty - 1, $tab_top + $tab_height);
906 if (empty($hidetop)) {
907 $pdf->SetXY($this->posxqty - 1, $tab_top + 1);
908 $pdf->MultiCell($this->posxunit - $this->posxqty - 1, 2, $outputlangs->transnoentities(
"Qty"),
'',
'C');
912 $pdf->line($this->posxunit - 1, $tab_top, $this->posxunit - 1, $tab_top + $tab_height);
913 if (empty($hidetop)) {
914 $pdf->SetXY($this->posxunit - 1, $tab_top + 1);
916 $this->posxdiscount - $this->posxunit - 1,
918 $outputlangs->transnoentities(
"Unit"),
925 if ($this->atleastonediscount) {
926 $pdf->line($this->posxdiscount - 1, $tab_top, $this->posxdiscount - 1, $tab_top + $tab_height);
927 if (empty($hidetop)) {
928 $pdf->SetXY($this->posxdiscount - 1, $tab_top + 1);
929 $pdf->MultiCell($this->postotalht - $this->posxdiscount + 1, 2, $outputlangs->transnoentities(
"ReductionShort"),
'',
'C');
933 $pdf->line($this->postotalht, $tab_top, $this->postotalht, $tab_top + $tab_height);
934 if (empty($hidetop)) {
935 $pdf->SetXY($this->postotalht - 1, $tab_top + 1);
936 $pdf->MultiCell(30, 2, $outputlangs->transnoentities(
"TotalHTShort"),
'',
'C');
963 $tab3_top = $posy + 8;
966 if ($this->page_largeur < 210) {
972 $pdf->SetFont(
'',
'', $default_font_size - 3);
973 $pdf->SetXY($tab3_posx, $tab3_top - 4);
974 $pdf->MultiCell(60, 3, $outputlangs->transnoentities(
"PaymentsAlreadyDone"), 0,
'L', 0);
976 $pdf->line($tab3_posx, $tab3_top, $tab3_posx + $tab3_width, $tab3_top);
978 $pdf->SetFont(
'',
'', $default_font_size - 4);
979 $pdf->SetXY($tab3_posx, $tab3_top);
980 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Payment"), 0,
'L', 0);
981 $pdf->SetXY($tab3_posx + 21, $tab3_top);
982 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Amount"), 0,
'L', 0);
983 $pdf->SetXY($tab3_posx + 40, $tab3_top);
984 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Type"), 0,
'L', 0);
985 $pdf->SetXY($tab3_posx + 58, $tab3_top);
986 $pdf->MultiCell(20, 3, $outputlangs->transnoentities(
"Num"), 0,
'L', 0);
988 $pdf->line($tab3_posx, $tab3_top - 1 + $tab3_height, $tab3_posx + $tab3_width, $tab3_top - 1 + $tab3_height);
992 $pdf->SetFont(
'',
'', $default_font_size - 4);
998 $sql =
"SELECT p.datep as date, p.fk_paiement as type, p.num_paiement as num_payment, pf.amount as amount, pf.multicurrency_amount,";
1000 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiementfourn_facturefourn as pf, ".MAIN_DB_PREFIX.
"paiementfourn as p";
1001 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as cp ON p.fk_paiement = cp.id";
1002 $sql .=
" WHERE pf.fk_paiementfourn = p.rowid and pf.fk_facturefourn = ".((int)
$object->id);
1003 $sql .=
" ORDER BY p.datep";
1004 $resql = $this->db->query($sql);
1006 $num = $this->db->num_rows($resql);
1010 $row = $this->db->fetch_object($resql);
1012 $pdf->SetXY($tab3_posx, $tab3_top + $y);
1013 $pdf->MultiCell(20, 3,
dol_print_date($this->db->jdate($row->date),
'day',
false, $outputlangs,
true), 0,
'L', 0);
1014 $pdf->SetXY($tab3_posx + 21, $tab3_top + $y);
1015 $pdf->MultiCell(20, 3,
price($sign * ((isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? $row->multicurrency_amount : $row->amount)), 0,
'L', 0);
1016 $pdf->SetXY($tab3_posx + 40, $tab3_top + $y);
1017 $oper = $outputlangs->transnoentitiesnoconv(
"PaymentTypeShort".$row->code);
1019 $pdf->MultiCell(20, 3, $oper, 0,
'L', 0);
1020 $pdf->SetXY($tab3_posx + 58, $tab3_top + $y);
1021 $pdf->MultiCell(30, 3, $row->num_payment, 0,
'L', 0);
1023 $pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3);
1028 $this->error = $this->db->lasterror();
1046 global $langs, $conf, $mysoc;
1049 $outputlangs->loadLangs(array(
"main",
"orders",
"companies",
"bills"));
1056 $pdf->SetTextColor(0, 0, 60);
1057 $pdf->SetFont(
'',
'B', $default_font_size + 3);
1061 $posy = $this->marge_haute;
1062 $posx = $this->page_largeur - $this->marge_droite - 100;
1064 $pdf->SetXY($this->marge_gauche, $posy);
1086 $text = $this->emetteur->name;
1087 $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0,
'L');
1090 $pdf->SetFont(
'',
'B', $default_font_size + 3);
1091 $pdf->SetXY($posx, $posy);
1092 $pdf->SetTextColor(0, 0, 60);
1093 $title = $outputlangs->transnoentities(
"PdfInvoiceTitle");
1095 $title = $outputlangs->transnoentities(
"InvoiceReplacement");
1098 $title = $outputlangs->transnoentities(
"InvoiceAvoir");
1101 $title = $outputlangs->transnoentities(
"InvoiceDeposit");
1103 $pdf->MultiCell($w, 3, $title.
" ".$outputlangs->convToOutputCharset(
$object->ref),
'',
'R');
1108 $pdf->SetFont(
'',
'B', $default_font_size);
1109 $pdf->SetXY($posx, $posy);
1110 $pdf->SetTextColor(0, 0, 60);
1111 $pdf->MultiCell($w, 4, $outputlangs->transnoentities(
"RefSupplier").
" : ".
$object->ref_supplier,
'',
'R');
1115 $pdf->SetFont(
'',
'', $default_font_size - 1);
1119 if (!empty(
$object->project->ref)) {
1121 $pdf->SetXY($posx, $posy);
1122 $pdf->SetTextColor(0, 0, 60);
1123 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Project").
" : ".(empty(
$object->project->title) ?
'' :
$object->project->title),
'',
'R');
1129 if (!empty(
$object->project->ref)) {
1130 $outputlangs->load(
"projects");
1132 $pdf->SetXY($posx, $posy);
1133 $langs->load(
"projects");
1134 $pdf->SetTextColor(0, 0, 60);
1135 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Project").
" : ".(empty(
$object->project->ref) ?
'' :
$object->project->ref),
'',
'R');
1141 $pdf->SetXY($posx, $posy);
1142 $pdf->SetTextColor(0, 0, 60);
1143 $pdf->MultiCell($w, 4, $outputlangs->transnoentities(
"Date").
" : ".
dol_print_date(
$object->date,
"day",
false, $outputlangs,
true),
'',
'R');
1146 $pdf->SetXY($posx, $posy);
1147 $pdf->SetTextColor(255, 0, 0);
1148 $pdf->MultiCell($w, 4, strtolower($outputlangs->transnoentities(
"OrderToProcess")),
'',
'R');
1151 if (
$object->thirdparty->code_fournisseur) {
1153 $pdf->SetXY($posx, $posy);
1154 $pdf->SetTextColor(0, 0, 60);
1155 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"SupplierCode").
" : ".$outputlangs->transnoentities(
$object->thirdparty->code_fournisseur),
'',
'R');
1159 $pdf->SetTextColor(0, 0, 60);
1163 $current_y = $pdf->getY();
1165 if ($current_y < $pdf->getY()) {
1166 $top_shift = $pdf->getY() - $current_y;
1171 $carac_emetteur =
'';
1173 $arrayidcontact =
$object->getIdContact(
'internal',
'SALESREPFOLL');
1174 if (count($arrayidcontact) > 0) {
1175 $object->fetch_user($arrayidcontact[0]);
1176 $labelbeforecontactname = ($outputlangs->transnoentities(
"FromContactName") !=
'FromContactName' ? $outputlangs->transnoentities(
"FromContactName") : $outputlangs->transnoentities(
"Name"));
1177 $carac_emetteur .= ($carac_emetteur ?
"\n" :
'').$labelbeforecontactname.
": ".$outputlangs->convToOutputCharset(
$object->user->getFullName($outputlangs));
1179 $carac_emetteur .= (
getDolGlobalInt(
'PDF_SHOW_PHONE_AFTER_USER_CONTACT') && !empty(
$object->user->office_phone)) ?
$object->user->office_phone :
'';
1183 $carac_emetteur .=
"\n";
1189 $posy = 42 + $top_shift;
1190 $posx = $this->marge_gauche;
1192 $posx = $this->page_largeur - $this->marge_droite - 80;
1197 $pdf->SetTextColor(0, 0, 0);
1198 $pdf->SetFont(
'',
'', $default_font_size - 2);
1199 $pdf->SetXY($posx, $posy - 5);
1200 $pdf->MultiCell(80, 5, $outputlangs->transnoentities(
"BillFrom"), 0,
'L');
1201 $pdf->SetXY($posx, $posy);
1202 $pdf->SetFillColor(230, 230, 230);
1203 $pdf->MultiCell(82, $hautcadre,
"", 0,
'R', 1);
1204 $pdf->SetTextColor(0, 0, 60);
1207 $pdf->SetXY($posx + 2, $posy + 3);
1208 $pdf->SetFont(
'',
'B', $default_font_size);
1209 $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0,
'L');
1210 $posy = $pdf->getY();
1213 $pdf->SetXY($posx + 2, $posy);
1214 $pdf->SetFont(
'',
'', $default_font_size - 1);
1215 $pdf->MultiCell(80, 4, $carac_emetteur, 0,
'L');
1220 $usecontact =
false;
1221 $arrayidcontact =
$object->getIdContact(
'internal',
'BILLING');
1222 if (count($arrayidcontact) > 0) {
1224 $result =
$object->fetch_contact($arrayidcontact[0]);
1228 if ($usecontact && (
$object->contact->socid !=
$object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) ||
getDolGlobalString(
'MAIN_USE_COMPANY_NAME_OF_CONTACT')))) {
1229 $thirdparty =
$object->contact;
1231 $thirdparty = $mysoc;
1240 if ($this->page_largeur < 210) {
1243 $posy = 42 + $top_shift;
1244 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
1246 $posx = $this->marge_gauche;
1250 $pdf->SetTextColor(0, 0, 0);
1251 $pdf->SetFont(
'',
'', $default_font_size - 2);
1252 $pdf->SetXY($posx + 2, $posy - 5);
1253 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"BillTo"), 0,
'L');
1254 $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
1257 $pdf->SetXY($posx + 2, $posy + 3);
1258 $pdf->SetFont(
'',
'B', $default_font_size);
1259 $pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0,
'L');
1261 $posy = $pdf->getY();
1264 $pdf->SetFont(
'',
'', $default_font_size - 1);
1265 $pdf->SetXY($posx + 2, $posy);
1266 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0,
'L');