31 require_once DOL_DOCUMENT_ROOT.
'/core/modules/supplier_order/modules_commandefournisseur.php';
32 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.class.php';
33 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
34 require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
35 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
36 require_once DOL_DOCUMENT_ROOT.
'/core/lib/pdf.lib.php';
62 public $update_main_doc_field;
73 public $phpmin = array(7, 0);
79 public $version =
'dolibarr';
104 public $marge_droite;
130 global $conf, $langs, $mysoc;
133 $langs->loadLangs(array(
"main",
"bills"));
136 $this->
name =
"muscadet";
137 $this->
description = $langs->trans(
'SuppliersCommandModelMuscadet');
138 $this->update_main_doc_field = 1;
143 $this->page_largeur = $formatarray[
'width'];
144 $this->page_hauteur = $formatarray[
'height'];
145 $this->format = array($this->page_largeur, $this->page_hauteur);
151 $this->option_logo = 1;
152 $this->option_tva = 1;
153 $this->option_modereg = 1;
154 $this->option_condreg = 1;
155 $this->option_multilang = 1;
156 $this->option_escompte = 0;
157 $this->option_credit_note = 0;
158 $this->option_freetext = 1;
159 $this->option_draft_watermark = 1;
162 $this->emetteur = $mysoc;
163 if (empty($this->emetteur->country_code)) {
164 $this->emetteur->country_code = substr($langs->defaultlang, -2);
168 $this->posxdesc = $this->marge_gauche + 1;
169 $this->posxdiscount = 162;
170 $this->postotalht = 174;
175 $this->posxqty = 132;
176 $this->posxunit = 147;
178 $this->posxtva = 110;
180 $this->posxqty = 145;
181 $this->posxunit = 162;
184 if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) {
185 $this->posxup = $this->posxtva;
187 $this->posxpicture = $this->posxtva - (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH) ? 20 : $conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH);
188 if ($this->page_largeur < 210) {
189 $this->posxpicture -= 20;
190 $this->posxtva -= 20;
192 $this->posxqty -= 20;
193 $this->posxunit -= 20;
194 $this->posxdiscount -= 20;
195 $this->postotalht -= 20;
198 $this->tva = array();
199 $this->tva_array = array();
200 $this->localtax1 = array();
201 $this->localtax2 = array();
202 $this->atleastoneratenotnull = 0;
203 $this->atleastonediscount = 0;
219 public function write_file($object, $outputlangs =
'', $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
222 global $user, $langs, $conf, $hookmanager, $mysoc, $nblines;
224 if (!is_object($outputlangs)) {
225 $outputlangs = $langs;
228 if (!empty($conf->global->MAIN_USE_FPDF)) {
229 $outputlangs->charset_output =
'ISO-8859-1';
233 $outputlangs->loadLangs(array(
"main",
"orders",
"companies",
"bills",
"dict",
"products"));
235 $nblines = count($object->lines);
238 $realpatharray = array();
239 if (!empty($conf->global->MAIN_GENERATE_SUPPLIER_ORDER_WITH_PICTURE)) {
240 for ($i = 0; $i < $nblines; $i++) {
241 if (empty($object->lines[$i]->fk_product)) {
246 $objphoto->fetch($object->lines[$i]->fk_product);
249 $pdir =
get_exdir($objphoto->id, 2, 0, 0, $objphoto,
'product').$object->lines[$i]->fk_product.
"/photos/";
250 $dir = $conf->product->dir_output.
'/'.$pdir;
252 $pdir =
get_exdir($objphoto->id, 0, 0, 0, $objphoto,
'product');
253 $dir = $conf->product->dir_output.
'/'.$pdir;
256 foreach ($objphoto->liste_photos($dir, 1) as $key => $obj) {
258 if ($obj[
'photo_vignette']) {
259 $filename = $obj[
'photo_vignette'];
261 $filename = $obj[
'photo'];
264 $filename = $obj[
'photo'];
266 $realpath = $dir.$filename;
271 $realpatharray[$i] = $realpath;
275 if (count($realpatharray) == 0) {
276 $this->posxpicture = $this->posxtva;
279 if ($conf->fournisseur->commande->dir_output) {
280 $object->fetch_thirdparty();
283 $amount_credit_notes_included = 0;
284 $amount_deposits_included = 0;
289 if ($object->specimen) {
290 $dir = $conf->fournisseur->commande->dir_output;
291 $file = $dir.
"/SPECIMEN.pdf";
295 $dir = $conf->fournisseur->commande->dir_output.
'/'.$objectref;
296 $file = $dir.
"/".$objectref.
".pdf";
297 if (!empty($conf->global->SUPPLIER_REF_IN_NAME)) {
298 $file = $dir.
"/".$objectref.($objectrefsupplier ?
"_".$objectrefsupplier :
"").
".pdf";
302 if (!file_exists($dir)) {
304 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
309 if (file_exists($dir)) {
311 if (!is_object($hookmanager)) {
312 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
315 $hookmanager->initHooks(array(
'pdfgeneration'));
316 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
318 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters, $object, $action);
320 $nblines = count($object->lines);
324 $heightforinfotot = 50;
325 $heightforfreetext = (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->MAIN_PDF_FREETEXT_HEIGHT : 5);
326 $heightforfooter = $this->marge_basse + 8;
327 if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS)) {
328 $heightforfooter += 6;
330 $pdf->SetAutoPageBreak(1, 0);
332 if (class_exists(
'TCPDF')) {
333 $pdf->setPrintHeader(
false);
334 $pdf->setPrintFooter(
false);
338 if (!empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) {
339 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.
'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
340 $tplidx = $pdf->importPage(1);
345 $pdf->SetDrawColor(128, 128, 128);
347 $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
348 $pdf->SetSubject($outputlangs->transnoentities(
"PurchaseOrder"));
349 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
350 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
352 $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref).
" ".$outputlangs->transnoentities(
"PurchaseOrder").
" ".$outputlangs->convToOutputCharset($object->thirdparty->name));
354 $pdf->SetCompression(
false);
357 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
360 for ($i = 0; $i < $nblines; $i++) {
361 if ($object->lines[$i]->remise_percent) {
362 $this->atleastonediscount++;
365 if (empty($this->atleastonediscount)) {
366 $delta = ($this->postotalht - $this->posxdiscount);
367 $this->posxpicture += $delta;
368 $this->posxtva += $delta;
369 $this->posxup += $delta;
370 $this->posxqty += $delta;
371 $this->posxunit += $delta;
372 $this->posxdiscount += $delta;
378 if (!empty($tplidx)) {
379 $pdf->useTemplate($tplidx);
382 $top_shift = $this->
_pagehead($pdf, $object, 1, $outputlangs);
383 $pdf->SetFont(
'',
'', $default_font_size - 1);
384 $pdf->MultiCell(0, 3,
'');
385 $pdf->SetTextColor(0, 0, 0);
387 $tab_top = 90 + $top_shift;
388 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
392 $desc_incoterms = $object->getIncotermsForPDF();
393 if ($desc_incoterms) {
396 $pdf->SetFont(
'',
'', $default_font_size - 1);
397 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1,
dol_htmlentitiesbr($desc_incoterms), 0, 1);
398 $nexY = $pdf->GetY();
399 $height_incoterms = $nexY - $tab_top;
402 $pdf->SetDrawColor(192, 192, 192);
403 $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_incoterms + 1);
405 $tab_top = $nexY + 6;
410 if (!empty($object->note_public)) {
413 $pdf->SetFont(
'',
'', $default_font_size - 1);
414 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1,
dol_htmlentitiesbr($object->note_public), 0, 1);
415 $nexY = $pdf->GetY();
416 $height_note = $nexY - $tab_top;
419 $pdf->SetDrawColor(192, 192, 192);
420 $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1);
422 $tab_top = $nexY + 6;
425 $iniY = $tab_top + 7;
426 $curY = $tab_top + 7;
427 $nexY = $tab_top + 7;
430 for ($i = 0; $i < $nblines; $i++) {
432 $pdf->SetFont(
'',
'', $default_font_size - 1);
433 $pdf->SetTextColor(0, 0, 0);
436 $imglinesize = array();
437 if (!empty($realpatharray[$i])) {
441 $pdf->setTopMargin($tab_top_newpage);
442 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext + $heightforinfotot);
443 $pageposbefore = $pdf->getPage();
445 $showpricebeforepagebreak = 1;
447 $posYAfterDescription = 0;
450 if (!empty($imglinesize[
'width']) && !empty($imglinesize[
'height']) && ($curY + $imglinesize[
'height']) > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
451 $pdf->AddPage(
'',
'',
true);
452 if (!empty($tplidx)) {
453 $pdf->useTemplate($tplidx);
456 $this->
_pagehead($pdf, $object, 0, $outputlangs);
458 $pdf->setPage($pageposbefore + 1);
460 $curY = $tab_top_newpage;
463 if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
464 $showpricebeforepagebreak = 1;
466 $showpricebeforepagebreak = 0;
470 if (!empty($imglinesize[
'width']) && !empty($imglinesize[
'height'])) {
471 $curX = $this->posxpicture - 1;
472 $pdf->Image($realpatharray[$i], $curX + (($this->posxtva - $this->posxpicture - $imglinesize[
'width']) / 2), $curY, $imglinesize[
'width'], $imglinesize[
'height'],
'',
'',
'', 2, 300);
474 $posYAfterImage = $curY + $imglinesize[
'height'];
477 $curX = $this->posxdesc - 1;
478 $showpricebeforepagebreak = 1;
480 $pdf->startTransaction();
481 if ($posYAfterImage > 0) {
482 $descWidth = $this->posxpicture - $curX;
484 $descWidth = $this->posxtva - $curX;
486 pdf_writelinedesc($pdf, $object, $i, $outputlangs, $descWidth, 3, $curX, $curY, $hideref, $hidedesc, 1);
488 $pageposafter = $pdf->getPage();
489 if ($pageposafter > $pageposbefore) {
490 $pdf->rollbackTransaction(
true);
491 $pageposafter = $pageposbefore;
493 $pdf->setPageOrientation(
'', 1, $heightforfooter);
494 pdf_writelinedesc($pdf, $object, $i, $outputlangs, $descWidth, 3, $curX, $curY, $hideref, $hidedesc, 1);
495 $posyafter = $pdf->GetY();
496 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
497 if ($i == ($nblines - 1)) {
498 $pdf->AddPage(
'',
'',
true);
499 if (!empty($tplidx)) {
500 $pdf->useTemplate($tplidx);
503 $this->
_pagehead($pdf, $object, 0, $outputlangs);
505 $pdf->setPage($pageposafter + 1);
510 if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
511 $showpricebeforepagebreak = 1;
513 $showpricebeforepagebreak = 0;
518 $pdf->commitTransaction();
521 $nexY = $pdf->GetY();
522 $pageposafter = $pdf->getPage();
523 $pdf->setPage($pageposbefore);
524 $pdf->setTopMargin($this->marge_haute);
525 $pdf->setPageOrientation(
'', 1, 0);
528 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
529 $pdf->setPage($pageposafter);
530 $curY = $tab_top_newpage;
533 $pdf->SetFont(
'',
'', $default_font_size - 1);
536 if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) && empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) {
538 $pdf->SetXY($this->posxtva, $curY);
539 $pdf->MultiCell($this->posxup - $this->posxtva - 1, 3, $vat_rate, 0,
'R');
543 if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_PURCHASE_ORDER_WITHOUT_UNIT_PRICE)) {
545 $pdf->SetXY($this->posxup, $curY);
546 $pdf->MultiCell($this->posxqty - $this->posxup - 0.8, 3, $up_excl_tax, 0,
'R', 0);
551 $pdf->SetXY($this->posxqty, $curY);
552 $pdf->MultiCell($this->posxunit - $this->posxqty - 0.8, 4, $qty, 0,
'R');
556 $unit =
pdf_getlineunit($object, $i, $outputlangs, $hidedetails, $hookmanager);
557 $pdf->SetXY($this->posxunit, $curY);
558 $pdf->MultiCell($this->posxdiscount - $this->posxunit - 0.8, 4, $unit, 0,
'L');
562 $pdf->SetXY($this->posxdiscount, $curY);
563 if ($object->lines[$i]->remise_percent) {
565 $pdf->MultiCell($this->postotalht - $this->posxdiscount - 1, 3, $remise_percent, 0,
'R');
569 if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_PURCHASE_ORDER_WITHOUT_TOTAL_COLUMN)) {
571 $pdf->SetXY($this->postotalht, $curY);
572 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->postotalht, 3, $total_excl_tax, 0,
'R', 0);
576 if (
isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) {
577 $tvaligne = $object->lines[$i]->multicurrency_total_tva;
579 $tvaligne = $object->lines[$i]->total_tva;
582 $localtax1ligne = $object->lines[$i]->total_localtax1;
583 $localtax2ligne = $object->lines[$i]->total_localtax2;
584 $localtax1_rate = $object->lines[$i]->localtax1_tx;
585 $localtax2_rate = $object->lines[$i]->localtax2_tx;
586 $localtax1_type = $object->lines[$i]->localtax1_type;
587 $localtax2_type = $object->lines[$i]->localtax2_type;
589 if (!empty($object->remise_percent)) {
590 $tvaligne -= ($tvaligne * $object->remise_percent) / 100;
592 if (!empty($object->remise_percent)) {
593 $localtax1ligne -= ($localtax1ligne * $object->remise_percent) / 100;
595 if (!empty($object->remise_percent)) {
596 $localtax2ligne -= ($localtax2ligne * $object->remise_percent) / 100;
599 $vatrate = (string) $object->lines[$i]->tva_tx;
602 if ((!isset($localtax1_type) || $localtax1_type ==
'' || !isset($localtax2_type) || $localtax2_type ==
'')
603 && (!empty($localtax1_rate) || !empty($localtax2_rate))) {
605 $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] :
'';
606 $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] :
'';
610 if ($localtax1_type && $localtax1ligne != 0) {
611 $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
613 if ($localtax2_type && $localtax2ligne != 0) {
614 $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
617 if (($object->lines[$i]->info_bits & 0x01) == 0x01) {
622 if (!isset($this->tva[$vatrate])) {
623 $this->tva[$vatrate] = 0;
625 $this->tva[$vatrate] += $tvaligne;
626 $vatcode = $object->lines[$i]->vat_src_code;
627 if (empty($this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'])) {
628 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] = 0;
630 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')] = array(
'vatrate'=>$vatrate,
'vatcode'=>$vatcode,
'amount'=> $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] + $tvaligne);
632 if ($posYAfterImage > $posYAfterDescription) {
633 $nexY = $posYAfterImage;
637 if (!empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblines - 1)) {
638 $pdf->setPage($pageposafter);
639 $pdf->SetLineStyle(array(
'dash'=>
'1,1',
'color'=>array(80, 80, 80)));
641 $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
642 $pdf->SetLineStyle(array(
'dash'=>0));
648 while ($pagenb < $pageposafter) {
649 $pdf->setPage($pagenb);
651 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
653 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
655 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
657 $pdf->setPage($pagenb);
658 $pdf->setPageOrientation(
'', 1, 0);
660 $this->
_pagehead($pdf, $object, 0, $outputlangs);
662 if (!empty($tplidx)) {
663 $pdf->useTemplate($tplidx);
666 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
668 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
670 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
672 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
675 if (!empty($tplidx)) {
676 $pdf->useTemplate($tplidx);
680 $this->
_pagehead($pdf, $object, 0, $outputlangs);
687 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0, $object->multicurrency_code);
688 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
690 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code);
691 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
695 $posy = $this->
_tableau_info($pdf, $object, $bottomlasttab, $outputlangs);
698 $posy = $this->
_tableau_tot($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs);
701 if ($deja_regle || $amount_credit_notes_included || $amount_deposits_included) {
706 $this->
_pagefoot($pdf, $object, $outputlangs);
707 if (method_exists($pdf,
'AliasNbPages')) {
708 $pdf->AliasNbPages();
713 $pdf->Output($file,
'F');
716 $hookmanager->initHooks(array(
'pdfgeneration'));
717 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
719 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
721 $this->error = $hookmanager->error;
722 $this->errors = $hookmanager->errors;
727 $this->result = array(
'fullpath'=>$file);
731 $this->error = $langs->trans(
"ErrorCanNotCreateDir", $dir);
735 $this->error = $langs->trans(
"ErrorConstantNotDefined",
"SUPPLIER_OUTPUTDIR");
770 global $conf, $mysoc;
774 if ($this->emetteur->country_code ==
'FR' && empty($mysoc->tva_assuj)) {
775 $pdf->SetFont(
'',
'B', $default_font_size - 2);
776 $pdf->SetXY($this->marge_gauche, $posy);
777 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"VATIsNotUsedForInvoice"), 0,
'L', 0);
779 $posy = $pdf->GetY() + 4;
785 if (!empty($object->cond_reglement_code) || $object->cond_reglement_id) {
786 $pdf->SetFont(
'',
'B', $default_font_size - 2);
787 $pdf->SetXY($this->marge_gauche, $posy);
788 $titre = $outputlangs->transnoentities(
"PaymentConditions").
':';
789 $pdf->MultiCell(80, 4, $titre, 0,
'L');
791 $pdf->SetFont(
'',
'', $default_font_size - 2);
792 $pdf->SetXY($posxval, $posy);
793 $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);
794 $lib_condition_paiement = str_replace(
'\n',
"\n", $lib_condition_paiement);
795 $pdf->MultiCell(80, 4, $lib_condition_paiement, 0,
'L');
797 $posy = $pdf->GetY() + 3;
801 if (!empty($object->mode_reglement_code)) {
802 $pdf->SetFont(
'',
'B', $default_font_size - 2);
803 $pdf->SetXY($this->marge_gauche, $posy);
804 $titre = $outputlangs->transnoentities(
"PaymentMode").
':';
805 $pdf->MultiCell(80, 5, $titre, 0,
'L');
807 $pdf->SetFont(
'',
'', $default_font_size - 2);
808 $pdf->SetXY($posxval, $posy);
809 $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);
810 $pdf->MultiCell(80, 5, $lib_mode_reg, 0,
'L');
812 $posy = $pdf->GetY() + 2;
830 protected function _tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs)
833 global $conf, $mysoc;
839 $pdf->SetFont(
'',
'', $default_font_size - 1);
844 if ($this->page_largeur < 210) {
847 $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
853 $pdf->SetFillColor(255, 255, 255);
854 $pdf->SetXY($col1x, $tab2_top);
855 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalHT"), 0,
'L', 1);
857 $total_ht = ((
isModEnabled(
"multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ht : $object->total_ht);
858 $pdf->SetXY($col2x, $tab2_top);
859 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_ht + (!empty($object->remise) ? $object->remise : 0)), 0,
'R', 1);
862 $pdf->SetFillColor(248, 248, 248);
864 $this->atleastoneratenotnull = 0;
865 foreach ($this->tva as $tvakey => $tvaval) {
867 $this->atleastoneratenotnull++;
870 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
874 if (preg_match(
'/\*/', $tvakey)) {
875 $tvakey = str_replace(
'*',
'', $tvakey);
876 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
879 $totalvat = $outputlangs->transcountrynoentities(
"TotalVAT", $mysoc->country_code).
' ';
880 $totalvat .=
vatrate($tvakey, 1).$tvacompl;
881 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
883 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
884 $pdf->MultiCell($largcol2, $tab2_hl,
price($tvaval), 0,
'R', 1);
887 if (!$this->atleastoneratenotnull) {
889 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
890 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transcountrynoentities(
"TotalVAT", $mysoc->country_code), 0,
'L', 1);
892 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
893 $pdf->MultiCell($largcol2, $tab2_hl,
price($object->total_tva), 0,
'R', 1);
896 if (!empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION ==
'localtax1on' && $object->total_localtax1 > 0) {
898 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
899 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transcountrynoentities(
"TotalLT1", $mysoc->country_code), 0,
'L', 1);
900 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
901 $pdf->MultiCell($largcol2, $tab2_hl,
price($object->total_localtax1), $useborder,
'R', 1);
905 if (!empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION ==
'localtax2on' && $object->total_localtax2 > 0) {
907 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
908 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transcountrynoentities(
"TotalLT2", $mysoc->country_code), 0,
'L', 1);
909 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
910 $pdf->MultiCell($largcol2, $tab2_hl,
price($object->total_localtax2), $useborder,
'R', 1);
916 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
917 if (in_array((
string) $localtax_type, array(
'2',
'4',
'6'))) {
921 foreach ($localtax_rate as $tvakey => $tvaval) {
926 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
929 if (preg_match(
'/\*/', $tvakey)) {
930 $tvakey = str_replace(
'*',
'', $tvakey);
931 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
933 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1", $mysoc->country_code).
' ';
934 $totalvat .=
vatrate(abs($tvakey), 1).$tvacompl;
935 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
937 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
938 $pdf->MultiCell($largcol2, $tab2_hl,
price($tvaval, 0, $outputlangs), 0,
'R', 1);
946 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
947 if (in_array((
string) $localtax_type, array(
'2',
'4',
'6'))) {
951 foreach ($localtax_rate as $tvakey => $tvaval) {
956 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
959 if (preg_match(
'/\*/', $tvakey)) {
960 $tvakey = str_replace(
'*',
'', $tvakey);
961 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
963 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT2", $mysoc->country_code).
' ';
964 $totalvat .=
vatrate(abs($tvakey), 1).$tvacompl;
965 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
967 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
968 $pdf->MultiCell($largcol2, $tab2_hl,
price($tvaval), 0,
'R', 1);
976 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
977 $pdf->SetTextColor(0, 0, 60);
978 $pdf->SetFillColor(224, 224, 224);
979 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalTTC"), $useborder,
'L', 1);
981 $total_ttc = (
isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ttc : $object->total_ttc;
982 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
983 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_ttc), $useborder,
'R', 1);
984 $pdf->SetFont(
'',
'', $default_font_size - 1);
985 $pdf->SetTextColor(0, 0, 0);
987 $creditnoteamount = 0;
992 $resteapayer =
price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount,
'MT');
993 if (!empty($object->paye)) {
997 if ($deja_regle > 0) {
1001 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1002 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"AlreadyPaid"), 0,
'L', 0);
1003 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1004 $pdf->MultiCell($largcol2, $tab2_hl,
price($deja_regle), 0,
'R', 0);
1007 $pdf->SetTextColor(0, 0, 60);
1008 $pdf->SetFillColor(224, 224, 224);
1009 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1010 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"RemainderToPay"), $useborder,
'L', 1);
1012 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1013 $pdf->MultiCell($largcol2, $tab2_hl,
price($resteapayer), $useborder,
'R', 1);
1015 $pdf->SetFont(
'',
'', $default_font_size - 1);
1016 $pdf->SetTextColor(0, 0, 0);
1020 return ($tab2_top + ($tab2_hl * $index));
1037 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency =
'')
1047 $currency = !empty($currency) ? $currency : $conf->currency;
1051 $pdf->SetTextColor(0, 0, 0);
1052 $pdf->SetFont(
'',
'', $default_font_size - 2);
1054 if (empty($hidetop)) {
1055 $titre = $outputlangs->transnoentities(
"AmountInCurrency", $outputlangs->transnoentitiesnoconv(
"Currency".$currency));
1056 $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
1057 $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
1060 if (!empty($conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)) {
1061 $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_droite - $this->marge_gauche, 5,
'F',
null, explode(
',', $conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR));
1065 $pdf->SetDrawColor(128, 128, 128);
1066 $pdf->SetFont(
'',
'', $default_font_size - 1);
1069 $this->
printRect($pdf, $this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $tab_height, $hidetop, $hidebottom);
1071 if (empty($hidetop)) {
1072 $pdf->line($this->marge_gauche, $tab_top + 5, $this->page_largeur - $this->marge_droite, $tab_top + 5);
1074 $pdf->SetXY($this->posxdesc - 1, $tab_top + 1);
1075 $pdf->MultiCell(108, 2, $outputlangs->transnoentities(
"Designation"),
'',
'L');
1078 if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) {
1079 $pdf->line($this->posxtva, $tab_top, $this->posxtva, $tab_top + $tab_height);
1080 if (empty($hidetop)) {
1081 $pdf->SetXY($this->posxtva - 3, $tab_top + 1);
1082 $pdf->MultiCell($this->posxup - $this->posxtva + 3, 2, $outputlangs->transnoentities(
"VAT"),
'',
'C');
1086 $pdf->line($this->posxup, $tab_top, $this->posxup, $tab_top + $tab_height);
1087 if (empty($hidetop)) {
1088 $pdf->SetXY($this->posxup - 1, $tab_top + 1);
1089 $pdf->MultiCell($this->posxqty - $this->posxup - 1, 2, $outputlangs->transnoentities(
"PriceUHT"),
'',
'C');
1092 $pdf->line($this->posxqty - 1, $tab_top, $this->posxqty - 1, $tab_top + $tab_height);
1093 if (empty($hidetop)) {
1094 $pdf->SetXY($this->posxqty - 1, $tab_top + 1);
1095 $pdf->MultiCell($this->posxunit - $this->posxqty - 1, 2, $outputlangs->transnoentities(
"Qty"),
'',
'C');
1099 $pdf->line($this->posxunit - 1, $tab_top, $this->posxunit - 1, $tab_top + $tab_height);
1100 if (empty($hidetop)) {
1101 $pdf->SetXY($this->posxunit - 1, $tab_top + 1);
1102 $pdf->MultiCell($this->posxdiscount - $this->posxunit - 1, 2, $outputlangs->transnoentities(
"Unit"),
'',
'C');
1106 $pdf->line($this->posxdiscount - 1, $tab_top, $this->posxdiscount - 1, $tab_top + $tab_height);
1107 if (empty($hidetop)) {
1108 if ($this->atleastonediscount) {
1109 $pdf->SetXY($this->posxdiscount - 1, $tab_top + 1);
1110 $pdf->MultiCell($this->postotalht - $this->posxdiscount + 1, 2, $outputlangs->transnoentities(
"ReductionShort"),
'',
'C');
1114 if ($this->atleastonediscount) {
1115 $pdf->line($this->postotalht, $tab_top, $this->postotalht, $tab_top + $tab_height);
1117 if (empty($hidetop)) {
1118 $pdf->SetXY($this->postotalht - 1, $tab_top + 1);
1119 $pdf->MultiCell(30, 2, $outputlangs->transnoentities(
"TotalHTShort"),
'',
'C');
1133 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
1135 global $langs, $conf, $mysoc;
1137 $ltrdirection =
'L';
1138 if ($outputlangs->trans(
"DIRECTION") ==
'rtl') {
1139 $ltrdirection =
'R';
1143 $outputlangs->loadLangs(array(
"main",
"orders",
"companies",
"bills",
"sendings"));
1157 $pdf->SetTextColor(0, 0, 60);
1158 $pdf->SetFont(
'',
'B', $default_font_size + 3);
1160 $posx = $this->page_largeur - $this->marge_droite - 100;
1161 $posy = $this->marge_haute;
1163 $pdf->SetXY($this->marge_gauche, $posy);
1167 if ($this->emetteur->logo) {
1168 $logodir = $conf->mycompany->dir_output;
1169 if (!empty($conf->mycompany->multidir_output[$object->entity])) {
1170 $logodir = $conf->mycompany->multidir_output[$object->entity];
1173 $logo = $logodir.
'/logos/thumbs/'.$this->emetteur->logo_small;
1175 $logo = $logodir.
'/logos/'.$this->emetteur->logo;
1177 if (is_readable($logo)) {
1179 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
1181 $pdf->SetTextColor(200, 0, 0);
1182 $pdf->SetFont(
'',
'B', $default_font_size - 2);
1183 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
1184 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"ErrorGoToGlobalSetup"), 0,
'L');
1187 $text = $this->emetteur->name;
1188 $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0, $ltrdirection);
1192 $pdf->SetFont(
'',
'B', $default_font_size + 3);
1193 $pdf->SetXY($posx, $posy);
1194 $pdf->SetTextColor(0, 0, 60);
1195 $title = $outputlangs->transnoentities(
"SupplierOrder").
" ".$outputlangs->convToOutputCharset($object->ref);
1196 $pdf->MultiCell(100, 3, $title,
'',
'R');
1199 if ($object->ref_supplier) {
1201 $pdf->SetFont(
'',
'B', $default_font_size);
1202 $pdf->SetXY($posx, $posy);
1203 $pdf->SetTextColor(0, 0, 60);
1204 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"RefSupplier").
" : ".$outputlangs->convToOutputCharset($object->ref_supplier),
'',
'R');
1208 $pdf->SetFont(
'',
'', $default_font_size - 1);
1210 if (!empty($conf->global->PDF_SHOW_PROJECT_TITLE)) {
1211 $object->fetch_projet();
1212 if (!empty($object->project->ref)) {
1214 $pdf->SetXY($posx, $posy);
1215 $pdf->SetTextColor(0, 0, 60);
1216 $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Project").
" : ".(empty($object->project->title) ?
'' : $object->project->title),
'',
'R');
1220 if (!empty($conf->global->PDF_SHOW_PROJECT)) {
1221 $object->fetch_projet();
1222 if (!empty($object->project->ref)) {
1223 $outputlangs->load(
"projects");
1225 $pdf->SetXY($posx, $posy);
1226 $langs->load(
"projects");
1227 $pdf->SetTextColor(0, 0, 60);
1228 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"Project").
" : ".(empty($object->project->ref) ?
'' : $object->project->ref),
'',
'R');
1232 if (!empty($object->date_commande)) {
1234 $pdf->SetXY($posx, $posy);
1235 $pdf->SetTextColor(0, 0, 60);
1236 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"OrderDate").
" : ".
dol_print_date($object->date_commande,
"day",
false, $outputlangs,
true),
'',
'R');
1239 $pdf->SetXY($posx, $posy);
1240 $pdf->SetTextColor(255, 0, 0);
1241 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"OrderToProcess"),
'',
'R');
1244 $pdf->SetTextColor(0, 0, 60);
1245 $usehourmin =
'day';
1246 if (!empty($conf->global->SUPPLIER_ORDER_USE_HOUR_FOR_DELIVERY_DATE)) {
1247 $usehourmin =
'dayhour';
1249 if (!empty($object->delivery_date)) {
1251 $pdf->SetXY($posx - 90, $posy);
1252 $pdf->MultiCell(190, 3, $outputlangs->transnoentities(
"DateDeliveryPlanned").
" : ".
dol_print_date($object->delivery_date, $usehourmin,
false, $outputlangs,
true),
'',
'R');
1255 if ($object->thirdparty->code_fournisseur) {
1257 $pdf->SetXY($posx, $posy);
1258 $pdf->SetTextColor(0, 0, 60);
1259 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"SupplierCode").
" : ".$outputlangs->transnoentities($object->thirdparty->code_fournisseur),
'',
'R');
1263 if (!empty($conf->global->DOC_SHOW_FIRST_SALES_REP)) {
1264 $arrayidcontact = $object->getIdContact(
'internal',
'SALESREPFOLL');
1265 if (count($arrayidcontact) > 0) {
1266 $usertmp =
new User($this->
db);
1267 $usertmp->fetch($arrayidcontact[0]);
1269 $pdf->SetXY($posx, $posy);
1270 $pdf->SetTextColor(0, 0, 60);
1271 $pdf->MultiCell(100, 3, $langs->trans(
"BuyerName").
" : ".$usertmp->getFullName($langs),
'',
'R');
1276 $pdf->SetTextColor(0, 0, 60);
1280 $current_y = $pdf->getY();
1281 $posy =
pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3,
'R', $default_font_size);
1282 if ($current_y < $pdf->getY()) {
1283 $top_shift = $pdf->getY() - $current_y;
1288 $carac_emetteur =
'';
1290 $arrayidcontact = $object->getIdContact(
'internal',
'SALESREPFOLL');
1291 if (count($arrayidcontact) > 0) {
1292 $object->fetch_user($arrayidcontact[0]);
1293 $carac_emetteur .= ($carac_emetteur ?
"\n" :
'').$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs)).
"\n";
1296 $carac_emetteur .=
pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty,
'', 0,
'source', $object);
1299 $posy = 42 + $top_shift;
1300 $posx = $this->marge_gauche;
1301 if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
1302 $posx = $this->page_largeur - $this->marge_droite - 80;
1307 $pdf->SetTextColor(0, 0, 0);
1308 $pdf->SetFont(
'',
'', $default_font_size - 2);
1309 $pdf->SetXY($posx, $posy - 5);
1310 $pdf->MultiCell(80, 5, $outputlangs->transnoentities(
"BillFrom"), 0, $ltrdirection);
1311 $pdf->SetXY($posx, $posy);
1312 $pdf->SetFillColor(230, 230, 230);
1313 $pdf->MultiCell(82, $hautcadre,
"", 0,
'R', 1);
1314 $pdf->SetTextColor(0, 0, 60);
1317 $pdf->SetXY($posx + 2, $posy + 3);
1318 $pdf->SetFont(
'',
'B', $default_font_size);
1319 $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, $ltrdirection);
1320 $posy = $pdf->getY();
1323 $pdf->SetXY($posx + 2, $posy);
1324 $pdf->SetFont(
'',
'', $default_font_size - 1);
1325 $pdf->MultiCell(80, 4, $carac_emetteur, 0, $ltrdirection);
1329 $usecontact =
false;
1330 $arrayidcontact = $object->getIdContact(
'external',
'CUSTOMER');
1331 if (count($arrayidcontact) > 0) {
1333 $result = $object->fetch_contact($arrayidcontact[0]);
1337 if ($usecontact && ($object->contact->socid != $object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) || !empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)))) {
1338 $thirdparty = $object->contact;
1340 $thirdparty = $object->thirdparty;
1345 $carac_client =
pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ($usecontact ? $object->contact :
''), $usecontact,
'target', $object);
1349 if ($this->page_largeur < 210) {
1352 $posy = 42 + $top_shift;
1353 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
1354 if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
1355 $posx = $this->marge_gauche;
1359 $pdf->SetTextColor(0, 0, 0);
1360 $pdf->SetFont(
'',
'', $default_font_size - 2);
1361 $pdf->SetXY($posx + 2, $posy - 5);
1362 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"BillTo"), 0, $ltrdirection);
1363 $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
1366 $pdf->SetXY($posx + 2, $posy + 3);
1367 $pdf->SetFont(
'',
'B', $default_font_size);
1368 $pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0, $ltrdirection);
1370 $posy = $pdf->getY();
1373 $pdf->SetFont(
'',
'', $default_font_size - 1);
1374 $pdf->SetXY($posx + 2, $posy);
1375 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, $ltrdirection);
1391 protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
1393 $showdetails =
getDolGlobalInt(
'MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
1394 return pdf_pagefoot($pdf, $outputlangs,
'SUPPLIER_ORDER_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext);