177 public function write_file(
$object, $outputlangs, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
180 global $user, $langs, $conf, $mysoc, $db, $hookmanager, $nblines;
182 if (!is_object($outputlangs)) {
183 $outputlangs = $langs;
187 $outputlangs->charset_output =
'ISO-8859-1';
191 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"bills",
"products",
"orders",
"deliveries"));
198 global $outputlangsbis;
199 $outputlangsbis =
null;
201 $outputlangsbis =
new Translate(
'', $conf);
203 $outputlangsbis->loadLangs(array(
"main",
"dict",
"companies",
"bills",
"products",
"orders",
"deliveries"));
206 $nblines = count(
$object->lines);
208 if ($conf->commande->multidir_output[$conf->entity]) {
215 $dir = $conf->commande->multidir_output[$conf->entity];
216 $file = $dir.
"/SPECIMEN.pdf";
226 $dir = $conf->commande->multidir_output[
$object->entity].
"/".$objectref;
227 $file = $dir.
"/".$objectref.$suffix.
".pdf";
230 if (!file_exists($dir)) {
232 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
237 if (file_exists($dir)) {
239 if (!is_object($hookmanager)) {
240 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
243 $hookmanager->initHooks(array(
'pdfgeneration'));
244 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
246 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters,
$object, $action);
249 $nblines = count(
$object->lines);
254 $pdf->SetAutoPageBreak(1, 0);
256 $heightforinfotot = 40;
258 $heightforfooter = $this->marge_basse + 8;
260 $heightforfooter += 6;
263 if (class_exists(
'TCPDF')) {
264 $pdf->setPrintHeader(
false);
265 $pdf->setPrintFooter(
false);
270 $logodir = $conf->mycompany->dir_output;
271 if (!empty($conf->mycompany->multidir_output[
$object->entity])) {
272 $logodir = $conf->mycompany->multidir_output[
$object->entity];
274 $pagecount = $pdf->setSourceFile($logodir.
'/' .
getDolGlobalString(
'MAIN_ADD_PDF_BACKGROUND'));
275 $tplidx = $pdf->importPage(1);
280 $pdf->SetDrawColor(128, 128, 128);
282 $pdf->SetTitle($outputlangs->convToOutputCharset(
$object->ref));
283 $pdf->SetSubject($outputlangs->transnoentities(
"PdfOrderTitle"));
284 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
285 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
286 $pdf->SetKeyWords($outputlangs->convToOutputCharset(
$object->ref).
" ".$outputlangs->transnoentities(
"PdfOrderTitle").
" ".$outputlangs->convToOutputCharset(
$object->thirdparty->name));
288 $pdf->SetCompression(
false);
292 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
295 for ($i = 0; $i < $nblines; $i++) {
296 if (
$object->lines[$i]->remise_percent) {
297 $this->atleastonediscount++;
300 if (empty($this->atleastonediscount)) {
301 $delta = ($this->postotalht - $this->posxdiscount);
302 $this->posxpicture += $delta;
303 $this->posxtva += $delta;
304 $this->posxup += $delta;
305 $this->posxqty += $delta;
306 $this->posxunit += $delta;
307 $this->posxdiscount += $delta;
313 if (!empty($tplidx)) {
314 $pdf->useTemplate($tplidx);
317 $top_shift = $this->
_pagehead($pdf,
$object, 1, $outputlangs, (is_object($outputlangsbis) ? $outputlangsbis :
null));
318 $pdf->SetFont(
'',
'', $default_font_size - 1);
319 $pdf->MultiCell(0, 3,
'');
320 $pdf->SetTextColor(0, 0, 0);
323 $tab_top = 90 + $top_shift;
324 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
327 $height_incoterms = 0;
328 if (isModEnabled(
'incoterm')) {
329 $desc_incoterms =
$object->getIncotermsForPDF();
330 if ($desc_incoterms) {
333 $pdf->SetFont(
'',
'', $default_font_size - 1);
334 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1,
dol_htmlentitiesbr($desc_incoterms), 0, 1);
335 $nexY = $pdf->GetY();
336 $height_incoterms = $nexY - $tab_top;
339 $pdf->SetDrawColor(192, 192, 192);
340 $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_incoterms + 1);
342 $tab_top = $nexY + 6;
347 $notetoshow = empty(
$object->note_public) ?
'' :
$object->note_public;
350 if (is_object(
$object->thirdparty)) {
351 $salereparray =
$object->thirdparty->getSalesRepresentatives($user);
352 $salerepobj =
new User($this->db);
353 $salerepobj->fetch($salereparray[0][
'id']);
354 if (!empty($salerepobj->signature)) {
355 $notetoshow =
dol_concatdesc($notetoshow, $salerepobj->signature);
360 $extranote = $this->getExtrafieldsInHtml(
$object, $outputlangs);
361 if (!empty($extranote)) {
373 $pdf->SetFont(
'',
'', $default_font_size - 1);
374 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1,
dol_htmlentitiesbr($notetoshow), 0, 1);
375 $nexY = $pdf->GetY();
376 $height_note = $nexY - $tab_top;
379 $pdf->SetDrawColor(192, 192, 192);
380 $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1);
382 $tab_top = $nexY + 6;
385 $iniY = $tab_top + 7;
386 $curY = $tab_top + 7;
387 $nexY = $tab_top + 7;
390 for ($i = 0; $i < $nblines; $i++) {
392 $pdf->SetFont(
'',
'', $default_font_size - 1);
393 $pdf->SetTextColor(0, 0, 0);
395 $pdf->setTopMargin($tab_top_newpage);
396 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext + $heightforinfotot);
397 $pageposbefore = $pdf->getPage();
400 $curX = $this->posxdesc - 1;
402 $showpricebeforepagebreak = 1;
404 $pdf->startTransaction();
406 $pageposafter = $pdf->getPage();
407 if ($pageposafter > $pageposbefore) {
408 $pdf->rollbackTransaction(
true);
409 $pageposafter = $pageposbefore;
411 $pdf->setPageOrientation(
'', 1, $heightforfooter);
413 $pageposafter = $pdf->getPage();
414 $posyafter = $pdf->GetY();
415 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
416 if ($i == ($nblines - 1)) {
417 $pdf->AddPage(
'',
'',
true);
418 if (!empty($tplidx)) {
419 $pdf->useTemplate($tplidx);
424 $pdf->setPage($pageposafter + 1);
430 $showpricebeforepagebreak = 1;
432 $showpricebeforepagebreak = 0;
436 $pdf->commitTransaction();
438 $posYAfterDescription = $pdf->GetY();
440 $nexY = $pdf->GetY();
441 $pageposafter = $pdf->getPage();
443 $pdf->setPage($pageposbefore);
444 $pdf->setTopMargin($this->marge_haute);
445 $pdf->setPageOrientation(
'', 1, 0);
448 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
449 $pdf->setPage($pageposafter);
450 $curY = $tab_top_newpage;
453 $pdf->SetFont(
'',
'', $default_font_size - 1);
458 $pdf->SetXY($this->posxtva - 5, $curY);
459 $pdf->MultiCell($this->posxup - $this->posxtva + 4, 3, $vat_rate, 0,
'R');
464 $pdf->SetXY($this->posxup, $curY);
465 $pdf->MultiCell($this->posxqty - $this->posxup - 0.8, 3, $up_excl_tax, 0,
'R', 0);
469 $pdf->SetXY($this->posxqty, $curY);
470 $pdf->MultiCell($this->posxunit - $this->posxqty - 0.8, 4, $qty, 0,
'R');
475 $pdf->SetXY($this->posxunit, $curY);
476 $pdf->MultiCell($this->posxdiscount - $this->posxunit - 0.8, 4, $unit, 0,
'L');
480 $pdf->SetXY($this->posxdiscount, $curY);
481 if (
$object->lines[$i]->remise_percent) {
482 $pdf->SetXY($this->posxdiscount - 2, $curY);
484 $pdf->MultiCell($this->postotalht - $this->posxdiscount + 2, 3, $remise_percent, 0,
'R');
489 $pdf->SetXY($this->postotalht, $curY);
490 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->postotalht, 3, $total_excl_tax, 0,
'R', 0);
493 if (isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) {
494 $tvaligne =
$object->lines[$i]->multicurrency_total_tva;
496 $tvaligne =
$object->lines[$i]->total_tva;
499 $localtax1ligne =
$object->lines[$i]->total_localtax1;
500 $localtax2ligne =
$object->lines[$i]->total_localtax2;
501 $localtax1_rate =
$object->lines[$i]->localtax1_tx;
502 $localtax2_rate =
$object->lines[$i]->localtax2_tx;
503 $localtax1_type =
$object->lines[$i]->localtax1_type;
504 $localtax2_type =
$object->lines[$i]->localtax2_type;
517 $vatrate = (string)
$object->lines[$i]->tva_tx;
520 if ((!isset($localtax1_type) || $localtax1_type ==
'' || !isset($localtax2_type) || $localtax2_type ==
'')
521 && (!empty($localtax1_rate) || !empty($localtax2_rate))) {
523 $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] :
'';
524 $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] :
'';
528 if ($localtax1_type && $localtax1ligne != 0) {
529 if (empty($this->localtax1[$localtax1_type][$localtax1_rate])) {
530 $this->localtax1[$localtax1_type][$localtax1_rate] = $localtax1ligne;
532 $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
535 if ($localtax2_type && $localtax2ligne != 0) {
536 if (empty($this->localtax2[$localtax2_type][$localtax2_rate])) {
537 $this->localtax2[$localtax2_type][$localtax2_rate] = $localtax2ligne;
539 $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
543 if ((
$object->lines[$i]->info_bits & 0x01) == 0x01) {
548 if (!isset($this->tva[$vatrate])) {
549 $this->tva[$vatrate] = 0;
551 $this->tva[$vatrate] += $tvaligne;
552 $vatcode =
$object->lines[$i]->vat_src_code;
553 if (empty($this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'])) {
554 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] = 0;
556 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')] = array(
'vatrate' => $vatrate,
'vatcode' => $vatcode,
'amount' => $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] + $tvaligne);
560 $pdf->setPage($pageposafter);
561 $pdf->SetLineStyle(array(
'dash' =>
'1,1',
'color' => array(80, 80, 80)));
563 $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
564 $pdf->SetLineStyle(array(
'dash' => 0));
570 while ($pagenb < $pageposafter) {
571 $pdf->setPage($pagenb);
573 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1,
$object->multicurrency_code);
575 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1,
$object->multicurrency_code);
579 $pdf->setPage($pagenb);
580 $pdf->setPageOrientation(
'', 1, 0);
584 if (!empty($tplidx)) {
585 $pdf->useTemplate($tplidx);
588 if (isset(
$object->lines[$i + 1]->pagebreak) &&
$object->lines[$i + 1]->pagebreak) {
590 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1,
$object->multicurrency_code);
592 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1,
$object->multicurrency_code);
597 if (!empty($tplidx)) {
598 $pdf->useTemplate($tplidx);
609 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0,
$object->multicurrency_code);
611 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0,
$object->multicurrency_code);
613 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
631 if (method_exists($pdf,
'AliasNbPages')) {
632 $pdf->AliasNbPages();
637 $pdf->Output($file,
'F');
640 $hookmanager->initHooks(array(
'pdfgeneration'));
641 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
643 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
645 $this->error = $hookmanager->error;
646 $this->errors = $hookmanager->errors;
651 $this->result = array(
'fullpath' => $file);
655 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
659 $this->error = $langs->transnoentities(
"ErrorConstantNotDefined",
"COMMANDE_OUTPUTDIR");
695 global $conf, $mysoc;
698 $pdf->SetFont(
'',
'', $default_font_size - 1);
700 $diffsizetitle = (!
getDolGlobalString(
'PDF_DIFFSIZE_TITLE') ? 3 : $conf->global->PDF_DIFFSIZE_TITLE);
703 if ($this->emetteur->country_code ==
'FR' && empty($mysoc->tva_assuj)) {
704 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
705 $pdf->SetXY($this->marge_gauche, $posy);
706 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"VATIsNotUsedForInvoice"), 0,
'L', 0);
708 $posy = $pdf->GetY() + 4;
713 $diffsizetitle = (!
getDolGlobalString(
'PDF_DIFFSIZE_TITLE') ? 3 : $conf->global->PDF_DIFFSIZE_TITLE);
717 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
718 $pdf->SetXY($this->marge_gauche, $posy);
719 $titre = $outputlangs->transnoentities(
"PaymentConditions").
':';
720 $pdf->MultiCell(43, 4, $titre, 0,
'L');
722 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
723 $pdf->SetXY($posxval, $posy);
724 $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);
725 $lib_condition_paiement = str_replace(
'\n',
"\n", $lib_condition_paiement);
726 if (
$object->deposit_percent > 0) {
727 $lib_condition_paiement = str_replace(
'__DEPOSIT_PERCENT__', (
string)
$object->deposit_percent, $lib_condition_paiement);
729 $pdf->MultiCell(67, 4, $lib_condition_paiement, 0,
'L');
731 $posy = $pdf->GetY() + 3;
762 if (!empty(
$object->delivery_date)) {
763 $outputlangs->load(
"sendings");
764 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
765 $pdf->SetXY($this->marge_gauche, $posy);
766 $titre = $outputlangs->transnoentities(
"DateDeliveryPlanned").
':';
767 $pdf->MultiCell(80, 4, $titre, 0,
'L');
768 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
769 $pdf->SetXY($posxval, $posy);
771 $pdf->MultiCell(80, 4, $dlp, 0,
'L');
773 $posy = $pdf->GetY() + 1;
776 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
777 $pdf->SetXY($this->marge_gauche, $posy);
778 $titre = $outputlangs->transnoentities(
"AvailabilityPeriod").
':';
779 $pdf->MultiCell(80, 4, $titre, 0,
'L');
780 $pdf->SetTextColor(0, 0, 0);
781 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
782 $pdf->SetXY($posxval, $posy);
783 $lib_availability = $outputlangs->transnoentities(
"AvailabilityType".
$object->availability_code) !=
'AvailabilityType'.$object->availability_code ? $outputlangs->transnoentities(
"AvailabilityType".
$object->availability_code) : $outputlangs->convToOutputCharset(isset(
$object->availability) ?
$object->availability :
'');
784 $lib_availability = str_replace(
'\n',
"\n", $lib_availability);
785 $pdf->MultiCell(80, 4, $lib_availability, 0,
'L');
787 $posy = $pdf->GetY() + 1;
791 if (
$object->mode_reglement_code
792 &&
$object->mode_reglement_code !=
'CHQ'
793 &&
$object->mode_reglement_code !=
'VIR') {
794 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
795 $pdf->SetXY($this->marge_gauche, $posy);
796 $titre = $outputlangs->transnoentities(
"PaymentMode").
':';
797 $pdf->MultiCell(80, 5, $titre, 0,
'L');
799 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
800 $pdf->SetXY($posxval, $posy);
801 $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);
802 $pdf->MultiCell(80, 5, $lib_mode_reg, 0,
'L');
804 $posy = $pdf->GetY() + 2;
808 if (empty(
$object->mode_reglement_code) ||
$object->mode_reglement_code ==
'CHQ') {
812 $account =
new Account($this->db);
815 $pdf->SetXY($this->marge_gauche, $posy);
816 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
817 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
'PaymentByChequeOrderedTo', $account->owner_name), 0,
'L', 0);
818 $posy = $pdf->GetY() + 1;
821 $pdf->SetXY($this->marge_gauche, $posy);
822 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
823 $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($account->owner_address), 0,
'L', 0);
824 $posy = $pdf->GetY() + 2;
827 if ($conf->global->FACTURE_CHQ_NUMBER == -1) {
828 $pdf->SetXY($this->marge_gauche, $posy);
829 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
830 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
'PaymentByChequeOrderedTo', $this->emetteur->name), 0,
'L', 0);
831 $posy = $pdf->GetY() + 1;
834 $pdf->SetXY($this->marge_gauche, $posy);
835 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
836 $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0,
'L', 0);
837 $posy = $pdf->GetY() + 2;
844 if (empty(
$object->mode_reglement_code) ||
$object->mode_reglement_code ==
'VIR') {
846 $bankid = (
$object->fk_account <= 0 ? $conf->global->FACTURE_RIB_NUMBER :
$object->fk_account);
850 $account =
new Account($this->db);
851 $account->fetch($bankid);
853 $curx = $this->marge_gauche;
856 $posy =
pdf_bank($pdf, $outputlangs, $curx, $cury, $account, 0, $default_font_size);
881 global $conf, $mysoc, $hookmanager;
886 $outputlangsbis =
new Translate(
'', $conf);
888 $outputlangsbis->loadLangs(array(
"main",
"dict",
"companies",
"bills",
"products",
"propal"));
889 $default_font_size--;
894 $pdf->SetFont(
'',
'', $default_font_size - 1);
899 if ($this->page_largeur < 210) {
902 $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
908 $pdf->SetFillColor(255, 255, 255);
909 $pdf->SetXY($col1x, $tab2_top);
910 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalHT").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"TotalHT") :
''), 0,
'L', 1);
912 $total_ht = ((isModEnabled(
"multicurrency") && isset(
$object->multicurrency_tx) &&
$object->multicurrency_tx != 1) ?
$object->multicurrency_total_ht :
$object->total_ht);
913 $pdf->SetXY($col2x, $tab2_top);
914 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_ht + (!empty(
$object->remise) ?
$object->remise : 0), 0, $outputlangs), 0,
'R', 1);
917 $pdf->SetFillColor(248, 248, 248);
919 $total_ttc = (isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ?
$object->multicurrency_total_ttc :
$object->total_ttc;
921 $this->atleastoneratenotnull = 0;
923 $tvaisnull = ((!empty($this->tva) && count($this->tva) == 1 && isset($this->tva[
'0.000']) && is_float($this->tva[
'0.000'])) ?
true :
false);
928 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
929 if (in_array((
string) $localtax_type, array(
'1',
'3',
'5'))) {
932 foreach ($localtax_rate as $tvakey => $tvaval) {
937 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
940 if (preg_match(
'/\*/', (
string) $tvakey)) {
941 $tvakey = str_replace(
'*',
'', (
string) $tvakey);
942 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
944 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT1", $mysoc->country_code) :
'');
948 $totalvat .= $tvacompl;
950 $totalvat .=
vatrate(abs($tvakey), 1).$tvacompl;
953 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
955 $total_localtax = ((isModEnabled(
"multicurrency") && isset(
$object->multicurrency_tx) &&
$object->multicurrency_tx != 1) ?
price2num($tvaval *
$object->multicurrency_tx,
'MT') : $tvaval);
957 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
958 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R', 1);
964 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
965 if (in_array((
string) $localtax_type, array(
'1',
'3',
'5'))) {
968 foreach ($localtax_rate as $tvakey => $tvaval) {
973 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
976 if (preg_match(
'/\*/', (
string) $tvakey)) {
977 $tvakey = str_replace(
'*',
'', (
string) $tvakey);
978 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
980 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT2", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT2", $mysoc->country_code) :
'');
984 $totalvat .= $tvacompl;
986 $totalvat .=
vatrate(abs($tvakey), 1).$tvacompl;
989 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
991 $total_localtax = ((isModEnabled(
"multicurrency") && isset(
$object->multicurrency_tx) &&
$object->multicurrency_tx != 1) ?
price2num($tvaval *
$object->multicurrency_tx,
'MT') : $tvaval);
993 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
994 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R', 1);
1000 foreach ($this->tva_array as $tvakey => $tvaval) {
1002 $this->atleastoneratenotnull++;
1005 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1008 if (preg_match(
'/\*/', $tvakey)) {
1009 $tvakey = str_replace(
'*',
'', $tvakey);
1010 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1012 $totalvat = $outputlangs->transcountrynoentities(
"TotalVAT", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalVAT", $mysoc->country_code) :
'');
1015 $totalvat .=
vatrate($tvaval[
'vatrate'], 1).$tvacompl;
1017 $totalvat .= $tvaval[
'vatcode'].$tvacompl;
1019 $totalvat .= $tvacompl;
1021 $totalvat .=
vatrate($tvaval[
'vatrate'], 1).($tvaval[
'vatcode'] ?
' ('.$tvaval[
'vatcode'].
')' :
'').$tvacompl;
1023 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1025 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1026 $pdf->MultiCell($largcol2, $tab2_hl,
price(
price2num($tvaval[
'amount'],
'MT'), 0, $outputlangs), 0,
'R', 1);
1033 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1034 if (in_array((
string) $localtax_type, array(
'2',
'4',
'6'))) {
1038 foreach ($localtax_rate as $tvakey => $tvaval) {
1043 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1046 if (preg_match(
'/\*/', (
string) $tvakey)) {
1047 $tvakey = str_replace(
'*',
'', (
string) $tvakey);
1048 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1050 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT1", $mysoc->country_code) :
'');
1054 $totalvat .= $tvacompl;
1056 $totalvat .=
vatrate(abs($tvakey), 1).$tvacompl;
1059 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1061 $total_localtax = ((isModEnabled(
"multicurrency") && isset(
$object->multicurrency_tx) &&
$object->multicurrency_tx != 1) ?
price2num($tvaval *
$object->multicurrency_tx,
'MT') : $tvaval);
1063 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1064 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R', 1);
1072 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
1073 if (in_array((
string) $localtax_type, array(
'2',
'4',
'6'))) {
1077 foreach ($localtax_rate as $tvakey => $tvaval) {
1083 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1086 if (preg_match(
'/\*/', (
string) $tvakey)) {
1087 $tvakey = str_replace(
'*',
'', (
string) $tvakey);
1088 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1090 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT2", $mysoc->country_code).(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalLT2", $mysoc->country_code) :
'');
1094 $totalvat .= $tvacompl;
1096 $totalvat .=
vatrate(abs($tvakey), 1).$tvacompl;
1099 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1101 $total_localtax = ((isModEnabled(
"multicurrency") && isset(
$object->multicurrency_tx) &&
$object->multicurrency_tx != 1) ?
price2num($tvaval *
$object->multicurrency_tx,
'MT') : $tvaval);
1103 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1104 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_localtax, 0, $outputlangs), 0,
'R', 1);
1112 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1113 $pdf->SetTextColor(0, 0, 60);
1114 $pdf->SetFillColor(224, 224, 224);
1115 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalTTC").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transcountrynoentities(
"TotalTTC", $mysoc->country_code) :
''), $useborder,
'L', 1);
1117 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1118 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_ttc, 0, $outputlangs), $useborder,
'R', 1);
1122 $pdf->SetTextColor(0, 0, 0);
1124 $creditnoteamount = 0;
1125 $depositsamount = 0;
1129 $resteapayer =
price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount,
'MT');
1134 if ($deja_regle > 0) {
1138 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1139 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"AlreadyPaid").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"AlreadyPaid") :
''), 0,
'L', 0);
1140 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1141 $pdf->MultiCell($largcol2, $tab2_hl,
price($deja_regle, 0, $outputlangs), 0,
'R', 0);
1144 $pdf->SetTextColor(0, 0, 60);
1145 $pdf->SetFillColor(224, 224, 224);
1146 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1147 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"RemainderToPay").(is_object($outputlangsbis) ?
' / '.$outputlangsbis->transnoentities(
"AlreadyPaid") :
''), $useborder,
'L', 1);
1149 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1150 $pdf->MultiCell($largcol2, $tab2_hl,
price($resteapayer, 0, $outputlangs), $useborder,
'R', 1);
1152 $pdf->SetFont(
'',
'', $default_font_size - 1);
1153 $pdf->SetTextColor(0, 0, 0);
1157 return ($tab2_top + ($tab2_hl * $index));
1175 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency =
'', $outputlangsbis =
null)
1185 $currency = !empty($currency) ? $currency : $conf->currency;
1189 $pdf->SetTextColor(0, 0, 0);
1190 $pdf->SetFont(
'',
'', $default_font_size - 2);
1192 if (empty($hidetop)) {
1193 $titre = $outputlangs->transnoentities(
"AmountInCurrency", $outputlangs->transnoentitiesnoconv(
"Currency".$currency));
1194 if (
getDolGlobalString(
'PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
1195 $titre .=
' - '.$outputlangsbis->transnoentities(
"AmountInCurrency", $outputlangsbis->transnoentitiesnoconv(
"Currency".$currency));
1198 $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
1199 $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
1203 $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')));
1207 $pdf->SetDrawColor(128, 128, 128);
1208 $pdf->SetFont(
'',
'', $default_font_size - 1);
1211 $this->
printRect($pdf, $this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $tab_height, $hidetop, $hidebottom);
1213 if (empty($hidetop)) {
1214 $pdf->line($this->marge_gauche, $tab_top + 5, $this->page_largeur - $this->marge_droite, $tab_top + 5);
1216 $pdf->SetXY($this->posxdesc - 1, $tab_top + 1);
1217 $pdf->MultiCell(108, 2, $outputlangs->transnoentities(
"Designation"),
'',
'L');
1221 $pdf->line($this->posxtva - 1, $tab_top, $this->posxtva - 1, $tab_top + $tab_height);
1222 if (empty($hidetop)) {
1223 $pdf->SetXY($this->posxtva - 3, $tab_top + 1);
1224 $pdf->MultiCell($this->posxup - $this->posxtva + 3, 2, $outputlangs->transnoentities(
"VAT"),
'',
'C');
1228 $pdf->line($this->posxup - 1, $tab_top, $this->posxup - 1, $tab_top + $tab_height);
1229 if (empty($hidetop)) {
1230 $pdf->SetXY($this->posxup - 1, $tab_top + 1);
1231 $pdf->MultiCell($this->posxqty - $this->posxup - 1, 2, $outputlangs->transnoentities(
"PriceUHT"),
'',
'C');
1234 $pdf->line($this->posxqty - 1, $tab_top, $this->posxqty - 1, $tab_top + $tab_height);
1235 if (empty($hidetop)) {
1236 $pdf->SetXY($this->posxqty - 1, $tab_top + 1);
1237 $pdf->MultiCell($this->posxunit - $this->posxqty - 1, 2, $outputlangs->transnoentities(
"Qty"),
'',
'C');
1241 $pdf->line($this->posxunit - 1, $tab_top, $this->posxunit - 1, $tab_top + $tab_height);
1242 if (empty($hidetop)) {
1243 $pdf->SetXY($this->posxunit - 1, $tab_top + 1);
1244 $pdf->MultiCell($this->posxdiscount - $this->posxunit - 1, 2, $outputlangs->transnoentities(
"Unit"),
'',
'C');
1248 $pdf->line($this->posxdiscount - 1, $tab_top, $this->posxdiscount - 1, $tab_top + $tab_height);
1249 if (empty($hidetop)) {
1250 if ($this->atleastonediscount) {
1251 $pdf->SetXY($this->posxdiscount - 1, $tab_top + 1);
1252 $pdf->MultiCell($this->postotalht - $this->posxdiscount + 1, 2, $outputlangs->transnoentities(
"ReductionShort"),
'',
'C');
1256 if ($this->atleastonediscount) {
1257 $pdf->line($this->postotalht, $tab_top, $this->postotalht, $tab_top + $tab_height);
1259 if (empty($hidetop)) {
1260 $pdf->SetXY($this->postotalht - 1, $tab_top + 1);
1261 $pdf->MultiCell(30, 2, $outputlangs->transnoentities(
"TotalHTShort"),
'',
'C');
1278 protected function _pagehead(&$pdf,
$object, $showaddress, $outputlangs, $outputlangsbis =
null, $titlekey =
"PdfOrderTitle")
1281 global $conf, $langs, $hookmanager;
1283 $ltrdirection =
'L';
1284 if ($outputlangs->trans(
"DIRECTION") ==
'rtl') {
1285 $ltrdirection =
'R';
1289 $outputlangs->loadLangs(array(
"main",
"bills",
"propal",
"orders",
"companies"));
1295 $pdf->SetTextColor(0, 0, 60);
1296 $pdf->SetFont(
'',
'B', $default_font_size + 3);
1300 $posy = $this->marge_haute;
1301 $posx = $this->page_largeur - $this->marge_droite - $w;
1303 $pdf->SetXY($this->marge_gauche, $posy);
1307 if ($this->emetteur->logo) {
1308 $logodir = $conf->mycompany->dir_output;
1309 if (!empty($conf->mycompany->multidir_output[
$object->entity])) {
1310 $logodir = $conf->mycompany->multidir_output[
$object->entity];
1313 $logo = $logodir.
'/logos/thumbs/'.$this->emetteur->logo_small;
1315 $logo = $logodir.
'/logos/'.$this->emetteur->logo;
1317 if (is_readable($logo)) {
1319 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
1321 $pdf->SetTextColor(200, 0, 0);
1322 $pdf->SetFont(
'',
'B', $default_font_size - 2);
1323 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
1324 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorGoToGlobalSetup"), 0,
'L');
1327 $text = $this->emetteur->name;
1328 $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, $ltrdirection);
1332 $pdf->SetFont(
'',
'B', $default_font_size + 3);
1333 $pdf->SetXY($posx, $posy);
1334 $pdf->SetTextColor(0, 0, 60);
1335 $title = $outputlangs->transnoentities($titlekey);
1336 $title .=
' '.$outputlangs->convToOutputCharset(
$object->ref);
1337 if (
$object->statut == $object::STATUS_DRAFT) {
1338 $pdf->SetTextColor(128, 0, 0);
1339 $title .=
' - '.$outputlangs->transnoentities(
"NotValidated");
1341 $pdf->MultiCell($w, 3, $title,
'',
'R');
1343 $pdf->SetFont(
'',
'B', $default_font_size);
1353 $pdf->SetFont(
'',
'', $default_font_size - 1);
1357 $pdf->SetXY($posx, $posy);
1358 $pdf->SetTextColor(0, 0, 60);
1359 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefCustomer").
" : ".$outputlangs->convToOutputCharset(
$object->ref_client),
'',
'R');
1364 if (!empty(
$object->project->ref)) {
1366 $pdf->SetXY($posx, $posy);
1367 $pdf->SetTextColor(0, 0, 60);
1368 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Project").
" : ".(empty(
$object->project->title) ?
'' :
$object->project->title),
'',
'R');
1374 if (!empty(
$object->project->ref)) {
1375 $outputlangs->load(
"projects");
1377 $pdf->SetXY($posx, $posy);
1378 $pdf->SetTextColor(0, 0, 60);
1379 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefProject").
" : ".(empty(
$object->project->ref) ?
'' :
$object->project->ref),
'',
'R');
1384 $pdf->SetXY($posx, $posy);
1385 $pdf->SetTextColor(0, 0, 60);
1386 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"OrderDate").
" : ".
dol_print_date(
$object->date,
"day",
false, $outputlangs,
true),
'',
'R');
1390 $pdf->SetXY($posx, $posy);
1391 $pdf->SetTextColor(0, 0, 60);
1392 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CustomerCode").
" : ".$outputlangs->transnoentities(
$object->thirdparty->code_client),
'',
'R');
1397 $arrayidcontact =
$object->getIdContact(
'internal',
'SALESREPFOLL');
1398 if (count($arrayidcontact) > 0) {
1399 $usertmp =
new User($this->db);
1400 $usertmp->fetch($arrayidcontact[0]);
1402 $pdf->SetXY($posx, $posy);
1403 $pdf->SetTextColor(0, 0, 60);
1404 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"SalesRepresentative").
" : ".$usertmp->getFullName($langs),
'',
'R');
1412 $current_y = $pdf->getY();
1414 if ($current_y < $pdf->getY()) {
1415 $top_shift = $pdf->getY() - $current_y;
1420 $carac_emetteur =
'';
1422 $arrayidcontact =
$object->getIdContact(
'internal',
'SALESREPFOLL');
1423 if (count($arrayidcontact) > 0) {
1424 $object->fetch_user($arrayidcontact[0]);
1425 $labelbeforecontactname = ($outputlangs->transnoentities(
"FromContactName") !=
'FromContactName' ? $outputlangs->transnoentities(
"FromContactName") : $outputlangs->transnoentities(
"Name"));
1426 $carac_emetteur .= ($carac_emetteur ?
"\n" :
'').$labelbeforecontactname.
" ".$outputlangs->convToOutputCharset(
$object->user->getFullName($outputlangs));
1428 $carac_emetteur .= (
getDolGlobalInt(
'PDF_SHOW_PHONE_AFTER_USER_CONTACT') && !empty(
$object->user->office_phone)) ?
$object->user->office_phone :
'';
1432 $carac_emetteur .=
"\n";
1438 $posy = 42 + $top_shift;
1439 $posx = $this->marge_gauche;
1441 $posx = $this->page_largeur - $this->marge_droite - 80;
1447 $pdf->SetTextColor(0, 0, 0);
1448 $pdf->SetFont(
'',
'', $default_font_size - 2);
1449 $pdf->SetXY($posx, $posy - 5);
1450 $pdf->MultiCell(80, 5, $outputlangs->transnoentities(
"BillFrom"), 0, $ltrdirection);
1451 $pdf->SetXY($posx, $posy);
1452 $pdf->SetFillColor(230, 230, 230);
1453 $pdf->MultiCell(82, $hautcadre,
"", 0,
'R', 1);
1454 $pdf->SetTextColor(0, 0, 60);
1459 $pdf->SetXY($posx + 2, $posy + 3);
1460 $pdf->SetFont(
'',
'B', $default_font_size);
1461 $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, $ltrdirection);
1462 $posy = $pdf->getY();
1466 $pdf->SetXY($posx + 2, $posy);
1467 $pdf->SetFont(
'',
'', $default_font_size - 1);
1468 $pdf->MultiCell(80, 4, $carac_emetteur, 0,
'L');
1472 $usecontact =
false;
1473 $arrayidcontact =
$object->getIdContact(
'external',
'CUSTOMER');
1474 if (count($arrayidcontact) > 0) {
1476 $result =
$object->fetch_contact($arrayidcontact[0]);
1480 if ($usecontact && (
$object->contact->socid !=
$object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) ||
getDolGlobalString(
'MAIN_USE_COMPANY_NAME_OF_CONTACT')))) {
1481 $thirdparty =
$object->contact;
1483 $thirdparty =
$object->thirdparty;
1493 if ($this->page_largeur < 210) {
1497 $posy += $top_shift;
1498 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
1500 $posx = $this->marge_gauche;
1505 $pdf->SetTextColor(0, 0, 0);
1506 $pdf->SetFont(
'',
'', $default_font_size - 2);
1507 $pdf->SetXY($posx + 2, $posy - 5);
1508 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"BillTo"), 0, $ltrdirection);
1509 $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
1513 $pdf->SetXY($posx + 2, $posy + 3);
1514 $pdf->SetFont(
'',
'B', $default_font_size);
1516 $pdf->MultiCell($widthrecbox, 2, $carac_client_name, 0, $ltrdirection);
1518 $posy = $pdf->getY();
1521 $pdf->SetFont(
'',
'', $default_font_size - 1);
1522 $pdf->SetXY($posx + 2, $posy);
1524 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, $ltrdirection);
1527 $pdf->SetTextColor(0, 0, 0);