206 public function write_file($object, $outputlangs, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
209 global $user, $langs, $conf, $mysoc, $db, $hookmanager, $nblines;
211 if (!is_object($outputlangs)) {
212 $outputlangs = $langs;
215 if (!empty($conf->global->MAIN_USE_FPDF)) {
216 $outputlangs->charset_output =
'ISO-8859-1';
220 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"bills",
"products",
"supplier_proposal"));
223 if ($object->statut == $object::STATUS_DRAFT && (!empty($conf->global->SUPPLIER_PROPOSAL_DRAFT_WATERMARK))) {
224 $this->watermark = $conf->global->SUPPLIER_PROPOSAL_DRAFT_WATERMARK;
227 $nblines = count($object->lines);
230 $realpatharray = array();
231 if (!empty($conf->global->MAIN_GENERATE_SUPPLIER_PROPOSAL_WITH_PICTURE)) {
232 for ($i = 0; $i < $nblines; $i++) {
233 if (empty($object->lines[$i]->fk_product)) {
237 $objphoto =
new Product($this->db);
238 $objphoto->fetch($object->lines[$i]->fk_product);
241 $pdir =
get_exdir($object->lines[$i]->fk_product, 2, 0, 0, $objphoto,
'product').$object->lines[$i]->fk_product.
"/photos/";
242 $dir = $conf->product->dir_output.
'/'.$pdir;
244 $pdir =
get_exdir(0, 0, 0, 0, $objphoto,
'product');
245 $dir = $conf->product->dir_output.
'/'.$pdir;
249 foreach ($objphoto->liste_photos($dir, 1) as $key => $obj) {
251 if ($obj[
'photo_vignette']) {
252 $filename = $obj[
'photo_vignette'];
254 $filename = $obj[
'photo'];
257 $filename = $obj[
'photo'];
259 $realpath = $dir.$filename;
264 $realpatharray[$i] = $realpath;
268 if (count($realpatharray) == 0) {
269 $this->posxpicture = $this->posxup;
272 if ($conf->supplier_proposal->dir_output) {
273 $object->fetch_thirdparty();
278 if ($object->specimen) {
279 $dir = $conf->supplier_proposal->dir_output;
280 $file = $dir.
"/SPECIMEN.pdf";
283 $dir = $conf->supplier_proposal->dir_output.
"/".$objectref;
284 $file = $dir.
"/".$objectref.
".pdf";
287 if (!file_exists($dir)) {
289 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
294 if (file_exists($dir)) {
296 if (!is_object($hookmanager)) {
297 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
300 $hookmanager->initHooks(array(
'pdfgeneration'));
301 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
303 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters, $object, $action);
308 $heightforinfotot = 50;
309 $heightforfreetext = (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->MAIN_PDF_FREETEXT_HEIGHT : 5);
310 $heightforfooter = $this->marge_basse + 8;
311 if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS)) {
312 $heightforfooter += 6;
314 $pdf->SetAutoPageBreak(1, 0);
316 if (class_exists(
'TCPDF')) {
317 $pdf->setPrintHeader(
false);
318 $pdf->setPrintFooter(
false);
322 if (!empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) {
323 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.
'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
324 $tplidx = $pdf->importPage(1);
329 $pdf->SetDrawColor(128, 128, 128);
331 $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
332 $pdf->SetSubject($outputlangs->transnoentities(
"CommercialAsk"));
333 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
334 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
335 $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref).
" ".$outputlangs->transnoentities(
"CommercialAsk").
" ".$outputlangs->convToOutputCharset($object->thirdparty->name));
337 $pdf->SetCompression(
false);
340 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
343 for ($i = 0; $i < $nblines; $i++) {
344 if ($object->lines[$i]->remise_percent) {
345 $this->atleastonediscount++;
348 if (empty($this->atleastonediscount)) {
349 $delta = ($this->postotalht - $this->posxdiscount);
350 $this->posxpicture += $delta;
351 $this->posxup += $delta;
352 $this->posxqty += $delta;
353 $this->posxunit += $delta;
354 $this->posxdiscount += $delta;
360 if (!empty($tplidx)) {
361 $pdf->useTemplate($tplidx);
364 $top_shift = $this->
_pagehead($pdf, $object, 1, $outputlangs);
365 $pdf->SetFont(
'',
'', $default_font_size - 1);
366 $pdf->MultiCell(0, 3,
'');
367 $pdf->SetTextColor(0, 0, 0);
369 $tab_top = 90 + $top_shift;
370 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
373 $notetoshow = empty($object->note_public) ?
'' : $object->note_public;
374 if (!empty($conf->global->MAIN_ADD_SALE_REP_SIGNATURE_IN_NOTE)) {
376 if (is_object($object->thirdparty)) {
377 $salereparray = $object->thirdparty->getSalesRepresentatives($user);
378 $salerepobj =
new User($this->db);
379 $salerepobj->fetch($salereparray[0][
'id']);
380 if (!empty($salerepobj->signature)) {
381 $notetoshow =
dol_concatdesc($notetoshow, $salerepobj->signature);
387 $extranote = $this->getExtrafieldsInHtml($object, $outputlangs);
388 if (!empty($extranote)) {
400 $pdf->SetFont(
'',
'', $default_font_size - 1);
401 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1,
dol_htmlentitiesbr($notetoshow), 0, 1);
402 $nexY = $pdf->GetY();
403 $height_note = $nexY - $tab_top;
406 $pdf->SetDrawColor(192, 192, 192);
407 $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1);
409 $tab_top = $nexY + 6;
412 $iniY = $tab_top + 7;
413 $curY = $tab_top + 7;
414 $nexY = $tab_top + 7;
417 for ($i = 0; $i < $nblines; $i++) {
419 $pdf->SetFont(
'',
'', $default_font_size - 1);
420 $pdf->SetTextColor(0, 0, 0);
423 $imglinesize = array();
424 if (!empty($realpatharray[$i])) {
428 $pdf->setTopMargin($tab_top_newpage);
429 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext + $heightforinfotot);
430 $pageposbefore = $pdf->getPage();
432 $showpricebeforepagebreak = 1;
434 $posYAfterDescription = 0;
437 if (!empty($imglinesize[
'width']) && !empty($imglinesize[
'height']) && ($curY + $imglinesize[
'height']) > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
438 $pdf->AddPage(
'',
'',
true);
439 if (!empty($tplidx)) {
440 $pdf->useTemplate($tplidx);
443 $this->
_pagehead($pdf, $object, 0, $outputlangs);
445 $pdf->setPage($pageposbefore + 1);
447 $curY = $tab_top_newpage;
450 if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
451 $showpricebeforepagebreak = 1;
453 $showpricebeforepagebreak = 0;
457 if (!empty($imglinesize[
'width']) && !empty($imglinesize[
'height'])) {
458 $curX = $this->posxpicture - 1;
459 $pdf->Image($realpatharray[$i], $curX + (($this->posxup - $this->posxpicture - $imglinesize[
'width']) / 2), $curY, $imglinesize[
'width'], $imglinesize[
'height'],
'',
'',
'', 2, 300);
461 $posYAfterImage = $curY + $imglinesize[
'height'];
465 $curX = $this->posxdesc - 1;
467 $pdf->startTransaction();
468 if ($posYAfterImage > 0) {
469 $descWidth = $this->posxpicture - $curX;
471 $descWidth = $this->posxup - $curX;
473 pdf_writelinedesc($pdf, $object, $i, $outputlangs, $descWidth, 3, $curX, $curY, $hideref, $hidedesc, 1);
475 $pageposafter = $pdf->getPage();
476 if ($pageposafter > $pageposbefore) {
477 $pdf->rollbackTransaction(
true);
478 $pageposafter = $pageposbefore;
480 $pdf->setPageOrientation(
'', 1, $heightforfooter);
481 pdf_writelinedesc($pdf, $object, $i, $outputlangs, $descWidth, 3, $curX, $curY, $hideref, $hidedesc, 1);
483 $pageposafter = $pdf->getPage();
484 $posyafter = $pdf->GetY();
486 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
487 if ($i == ($nblines - 1)) {
488 $pdf->AddPage(
'',
'',
true);
489 if (!empty($tplidx)) {
490 $pdf->useTemplate($tplidx);
493 $this->
_pagehead($pdf, $object, 0, $outputlangs);
495 $pdf->setPage($pageposafter + 1);
500 if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
501 $showpricebeforepagebreak = 1;
503 $showpricebeforepagebreak = 0;
508 $pdf->commitTransaction();
510 $posYAfterDescription = $pdf->GetY();
512 $nexY = $pdf->GetY();
513 $pageposafter = $pdf->getPage();
515 $pdf->setPage($pageposbefore);
516 $pdf->setTopMargin($this->marge_haute);
517 $pdf->setPageOrientation(
'', 1, 0);
520 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
521 $pdf->setPage($pageposafter);
522 $curY = $tab_top_newpage;
525 $pdf->SetFont(
'',
'', $default_font_size - 1);
529 $pdf->SetXY($this->posxqty, $curY);
530 $pdf->MultiCell($this->posxunit - $this->posxqty - 0.8, 4, $qty, 0,
'R');
534 $unit =
pdf_getlineunit($object, $i, $outputlangs, $hidedetails, $hookmanager);
535 $pdf->SetXY($this->posxunit, $curY);
536 $pdf->MultiCell($this->posxdiscount - $this->posxunit - 0.8, 4, $unit, 0,
'L');
556 if (isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) {
557 $tvaligne = $object->lines[$i]->multicurrency_total_tva;
559 $tvaligne = $object->lines[$i]->total_tva;
562 $localtax1ligne = $object->lines[$i]->total_localtax1;
563 $localtax2ligne = $object->lines[$i]->total_localtax2;
564 $localtax1_rate = $object->lines[$i]->localtax1_tx;
565 $localtax2_rate = $object->lines[$i]->localtax2_tx;
566 $localtax1_type = $object->lines[$i]->localtax1_type;
567 $localtax2_type = $object->lines[$i]->localtax2_type;
580 $vatrate = (string) $object->lines[$i]->tva_tx;
583 if ((!isset($localtax1_type) || $localtax1_type ==
'' || !isset($localtax2_type) || $localtax2_type ==
'')
584 && (!empty($localtax1_rate) || !empty($localtax2_rate))) {
586 $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] :
'';
587 $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] :
'';
591 if ($localtax1_type && $localtax1ligne != 0) {
592 if (empty($this->localtax1[$localtax1_type][$localtax1_rate])) {
593 $this->localtax1[$localtax1_type][$localtax1_rate] = $localtax1ligne;
595 $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
598 if ($localtax2_type && $localtax2ligne != 0) {
599 if (empty($this->localtax2[$localtax2_type][$localtax2_rate])) {
600 $this->localtax2[$localtax2_type][$localtax2_rate] = $localtax2ligne;
602 $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
606 if (($object->lines[$i]->info_bits & 0x01) == 0x01) {
611 if (!isset($this->tva[$vatrate])) {
612 $this->tva[$vatrate] = 0;
614 $this->tva[$vatrate] += $tvaligne;
615 $vatcode = $object->lines[$i]->vat_src_code;
616 if (empty($this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'])) {
617 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] = 0;
619 $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')] = array(
'vatrate'=>$vatrate,
'vatcode'=>$vatcode,
'amount'=> $this->tva_array[$vatrate.($vatcode ?
' ('.$vatcode.
')' :
'')][
'amount'] + $tvaligne);
621 if ($posYAfterImage > $posYAfterDescription) {
622 $nexY = $posYAfterImage;
626 if (!empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblines - 1)) {
627 $pdf->setPage($pageposafter);
628 $pdf->SetLineStyle(array(
'dash'=>
'1,1',
'color'=>array(80, 80, 80)));
630 $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
631 $pdf->SetLineStyle(array(
'dash'=>0));
637 while ($pagenb < $pageposafter) {
638 $pdf->setPage($pagenb);
640 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
642 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
644 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
646 $pdf->setPage($pagenb);
647 $pdf->setPageOrientation(
'', 1, 0);
649 $this->
_pagehead($pdf, $object, 0, $outputlangs);
651 if (!empty($tplidx)) {
652 $pdf->useTemplate($tplidx);
655 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
657 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
659 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
661 $this->
_pagefoot($pdf, $object, $outputlangs, 1);
664 if (!empty($tplidx)) {
665 $pdf->useTemplate($tplidx);
669 $this->
_pagehead($pdf, $object, 0, $outputlangs);
676 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
677 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
679 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
680 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
684 $posy = $this->
_tableau_info($pdf, $object, $bottomlasttab, $outputlangs);
698 $this->
_pagefoot($pdf, $object, $outputlangs);
699 if (method_exists($pdf,
'AliasNbPages')) {
700 $pdf->AliasNbPages();
705 $pdf->Output($file,
'F');
708 $hookmanager->initHooks(array(
'pdfgeneration'));
709 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
711 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
713 $this->error = $hookmanager->error;
714 $this->errors = $hookmanager->errors;
719 $this->result = array(
'fullpath'=>$file);
723 $this->error = $langs->trans(
"ErrorCanNotCreateDir", $dir);
727 $this->error = $langs->trans(
"ErrorConstantNotDefined",
"SUPPLIER_PROPOSAL_OUTPUTDIR");
766 $diffsizetitle = (empty($conf->global->PDF_DIFFSIZE_TITLE) ? 3 : $conf->global->PDF_DIFFSIZE_TITLE);
768 $pdf->SetFont(
'',
'', $default_font_size - 1);
773 if (!empty($object->delivery_date)) {
774 $outputlangs->load(
"sendings");
775 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
776 $pdf->SetXY($this->marge_gauche, $posy);
777 $titre = $outputlangs->transnoentities(
"DateDeliveryPlanned").
':';
778 $pdf->MultiCell(80, 4, $titre, 0,
'L');
779 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
780 $pdf->SetXY($posxval, $posy);
781 $dlp =
dol_print_date($object->delivery_date,
"daytext",
false, $outputlangs,
true);
782 $pdf->MultiCell(80, 4, $dlp, 0,
'L');
784 $posy = $pdf->GetY() + 1;
786 $outputlangs->load(
"sendings");
787 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
788 $pdf->SetXY($this->marge_gauche, $posy);
789 $titre = $outputlangs->transnoentities(
"DateDeliveryPlanned").
':';
790 $pdf->MultiCell(80, 4, $titre, 0,
'L');
791 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
792 $pdf->SetXY($posxval, $posy);
794 $pdf->MultiCell(80, 4,
'', 0,
'L');
796 $posy = $pdf->GetY() + 1;
816 if (empty($conf->global->SUPPLIER_PROPOSAL_PDF_HIDE_PAYMENTTERMCOND) && ($object->cond_reglement_code || $object->cond_reglement)) {
817 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
818 $pdf->SetXY($this->marge_gauche, $posy);
819 $titre = $outputlangs->transnoentities(
"PaymentConditions").
':';
820 $pdf->MultiCell(80, 4, $titre, 0,
'L');
822 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
823 $pdf->SetXY($posxval, $posy);
824 $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);
825 $lib_condition_paiement = str_replace(
'\n',
"\n", $lib_condition_paiement);
826 $pdf->MultiCell(80, 4, $lib_condition_paiement, 0,
'L');
828 $posy = $pdf->GetY() + 3;
831 if (!empty($conf->global->SUPPLIER_PROPOSAL_PDF_SHOW_PAYMENTTERMMODE)) {
833 if ($object->mode_reglement_code
834 && $object->mode_reglement_code !=
'CHQ'
835 && $object->mode_reglement_code !=
'VIR') {
836 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
837 $pdf->SetXY($this->marge_gauche, $posy - 2);
838 $titre = $outputlangs->transnoentities(
"PaymentMode").
':';
839 $pdf->MultiCell(80, 5, $titre, 0,
'L');
840 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
841 $pdf->SetXY($posxval, $posy - 2);
842 $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);
843 $pdf->MultiCell(80, 5, $lib_mode_reg, 0,
'L');
845 $posy = $pdf->GetY() + 2;
849 if (empty($object->mode_reglement_code) || $object->mode_reglement_code ==
'CHQ') {
852 if ($conf->global->FACTURE_CHQ_NUMBER > 0) {
853 $account =
new Account($this->db);
856 $pdf->SetXY($this->marge_gauche, $posy);
857 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
858 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
'PaymentByChequeOrderedTo', $account->proprio), 0,
'L', 0);
859 $posy = $pdf->GetY() + 1;
861 if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS)) {
862 $pdf->SetXY($this->marge_gauche, $posy);
863 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
864 $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($account->owner_address), 0,
'L', 0);
865 $posy = $pdf->GetY() + 2;
869 $pdf->SetXY($this->marge_gauche, $posy);
870 $pdf->SetFont(
'',
'B', $default_font_size - $diffsizetitle);
871 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
'PaymentByChequeOrderedTo', $this->emetteur->name), 0,
'L', 0);
872 $posy = $pdf->GetY() + 1;
874 if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS)) {
875 $pdf->SetXY($this->marge_gauche, $posy);
876 $pdf->SetFont(
'',
'', $default_font_size - $diffsizetitle);
877 $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0,
'L', 0);
878 $posy = $pdf->GetY() + 2;
885 if (empty($object->mode_reglement_code) || $object->mode_reglement_code ==
'VIR') {
886 if (!empty($object->fk_bank) ||
getDolGlobalInt(
'FACTURE_RIB_NUMBER')) {
887 $bankid = (empty($object->fk_bank) ? $conf->global->FACTURE_RIB_NUMBER : $object->fk_bank);
888 $account =
new Account($this->db);
889 $account->fetch($bankid);
891 $curx = $this->marge_gauche;
894 $posy =
pdf_bank($pdf, $outputlangs, $curx, $cury, $account, 0, $default_font_size);
916 protected function _tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs)
919 global $conf, $mysoc;
924 $pdf->SetFont(
'',
'', $default_font_size - 1);
929 if ($this->page_largeur < 210) {
932 $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
938 $pdf->SetFillColor(255, 255, 255);
939 $pdf->SetXY($col1x, $tab2_top);
940 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalHT"), 0,
'L', 1);
942 $total_ht = ((isModEnabled(
"multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ht : $object->total_ht);
943 $pdf->SetXY($col2x, $tab2_top);
944 $pdf->MultiCell($largcol2, $tab2_hl,
price($total_ht + (!empty($object->remise) ? $object->remise : 0), 0, $outputlangs), 0,
'R', 1);
947 $pdf->SetFillColor(248, 248, 248);
949 $this->atleastoneratenotnull = 0;
950 if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) {
951 $tvaisnull = ((!empty($this->tva) && count($this->tva) == 1 && isset($this->tva[
'0.000']) && is_float($this->tva[
'0.000'])) ?
true :
false);
952 if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL) && $tvaisnull) {
958 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
959 if (in_array((
string) $localtax_type, array(
'1',
'3',
'5'))) {
963 foreach ($localtax_rate as $tvakey => $tvaval) {
968 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
971 if (preg_match(
'/\*/', $tvakey)) {
972 $tvakey = str_replace(
'*',
'', $tvakey);
973 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
975 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1", $mysoc->country_code).
' ';
976 $totalvat .=
vatrate(abs($tvakey), 1).$tvacompl;
977 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
979 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
980 $pdf->MultiCell($largcol2, $tab2_hl,
price($tvaval, 0, $outputlangs), 0,
'R', 1);
988 foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
989 if (in_array((
string) $localtax_type, array(
'1',
'3',
'5'))) {
993 foreach ($localtax_rate as $tvakey => $tvaval) {
1000 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1003 if (preg_match(
'/\*/', $tvakey)) {
1004 $tvakey = str_replace(
'*',
'', $tvakey);
1005 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1007 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT2", $mysoc->country_code).
' ';
1008 $totalvat .=
vatrate(abs($tvakey), 1).$tvacompl;
1009 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1011 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1012 $pdf->MultiCell($largcol2, $tab2_hl,
price($tvaval, 0, $outputlangs), 0,
'R', 1);
1018 foreach ($this->tva as $tvakey => $tvaval) {
1020 $this->atleastoneratenotnull++;
1023 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1026 if (preg_match(
'/\*/', $tvakey)) {
1027 $tvakey = str_replace(
'*',
'', $tvakey);
1028 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1030 $totalvat = $outputlangs->transcountrynoentities(
"TotalVAT", $mysoc->country_code).
' ';
1031 $totalvat .=
vatrate($tvakey, 1).$tvacompl;
1032 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1034 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1035 $pdf->MultiCell($largcol2, $tab2_hl,
price($tvaval, 0, $outputlangs), 0,
'R', 1);
1042 foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
1043 if (in_array((
string) $localtax_type, array(
'2',
'4',
'6'))) {
1047 foreach ($localtax_rate as $tvakey => $tvaval) {
1052 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1055 if (preg_match(
'/\*/', $tvakey)) {
1056 $tvakey = str_replace(
'*',
'', $tvakey);
1057 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1059 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT1", $mysoc->country_code).
' ';
1061 $totalvat .=
vatrate(abs($tvakey), 1).$tvacompl;
1062 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1063 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1064 $pdf->MultiCell($largcol2, $tab2_hl,
price($tvaval, 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(
'/\*/', $tvakey)) {
1087 $tvakey = str_replace(
'*',
'', $tvakey);
1088 $tvacompl =
" (".$outputlangs->transnoentities(
"NonPercuRecuperable").
")";
1090 $totalvat = $outputlangs->transcountrynoentities(
"TotalLT2", $mysoc->country_code).
' ';
1092 $totalvat .=
vatrate(abs($tvakey), 1).$tvacompl;
1093 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0,
'L', 1);
1095 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1096 $pdf->MultiCell($largcol2, $tab2_hl,
price($tvaval, 0, $outputlangs), 0,
'R', 1);
1104 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1105 $pdf->SetTextColor(0, 0, 60);
1106 $pdf->SetFillColor(224, 224, 224);
1107 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"TotalTTC"), $useborder,
'L', 1);
1109 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1110 $pdf->MultiCell($largcol2, $tab2_hl,
price($object->total_ttc, 0, $outputlangs), $useborder,
'R', 1);
1114 $pdf->SetTextColor(0, 0, 0);
1116 $resteapayer = $object->total_ttc - $deja_regle;
1117 if (!empty($object->paye)) {
1121 if ($deja_regle > 0) {
1124 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1125 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"AlreadyPaid"), 0,
'L', 0);
1127 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1128 $pdf->MultiCell($largcol2, $tab2_hl,
price($deja_regle, 0, $outputlangs), 0,
'R', 0);
1131 $pdf->SetTextColor(0, 0, 60);
1132 $pdf->SetFillColor(224, 224, 224);
1133 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
1134 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(
"RemainderToPay"), $useborder,
'L', 1);
1136 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
1137 $pdf->MultiCell($largcol2, $tab2_hl,
price($resteapayer, 0, $outputlangs), $useborder,
'R', 1);
1139 $pdf->SetFont(
'',
'', $default_font_size - 1);
1140 $pdf->SetTextColor(0, 0, 0);
1144 return ($tab2_top + ($tab2_hl * $index));
1161 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency =
'')
1171 $currency = !empty($currency) ? $currency : $conf->currency;
1175 $pdf->SetTextColor(0, 0, 0);
1176 $pdf->SetFont(
'',
'', $default_font_size - 2);
1178 if (empty($hidetop)) {
1179 $titre = $outputlangs->transnoentities(
"AmountInCurrency", $outputlangs->transnoentitiesnoconv(
"Currency".$currency));
1180 $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
1181 $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
1184 if (!empty($conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)) {
1185 $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));
1189 $pdf->SetDrawColor(128, 128, 128);
1190 $pdf->SetFont(
'',
'', $default_font_size - 1);
1193 $this->
printRect($pdf, $this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $tab_height, $hidetop, $hidebottom);
1195 if (empty($hidetop)) {
1196 $pdf->line($this->marge_gauche, $tab_top + 5, $this->page_largeur - $this->marge_droite, $tab_top + 5);
1198 $pdf->SetXY($this->posxdesc - 1, $tab_top + 1);
1199 $pdf->MultiCell(108, 2, $outputlangs->transnoentities(
"Designation"),
'',
'L');
1202 $pdf->line($this->posxup + 1, $tab_top, $this->posxup + 1, $tab_top + $tab_height);
1203 if (empty($hidetop)) {
1204 $pdf->SetXY($this->posxup - 1, $tab_top + 1);
1205 $pdf->MultiCell($this->posxqty - $this->posxup - 1, 2, $outputlangs->transnoentities(
"PriceUHT"),
'',
'C');
1208 $pdf->line($this->posxqty - 1, $tab_top, $this->posxqty - 1, $tab_top + $tab_height);
1209 if (empty($hidetop)) {
1210 $pdf->SetXY($this->posxqty - 1, $tab_top + 1);
1211 $pdf->MultiCell($this->posxunit - $this->posxqty - 1, 2, $outputlangs->transnoentities(
"Qty"),
'',
'C');
1215 $pdf->line($this->posxunit - 1, $tab_top, $this->posxunit - 1, $tab_top + $tab_height);
1216 if (empty($hidetop)) {
1217 $pdf->SetXY($this->posxunit - 1, $tab_top + 1);
1218 $pdf->MultiCell($this->posxdiscount - $this->posxunit - 1, 2, $outputlangs->transnoentities(
"Unit"),
'',
'C');
1222 $pdf->line($this->posxdiscount - 1, $tab_top, $this->posxdiscount - 1, $tab_top + $tab_height);
1223 if (empty($hidetop)) {
1224 if ($this->atleastonediscount) {
1225 $pdf->SetXY($this->posxdiscount - 1, $tab_top + 1);
1226 $pdf->MultiCell($this->postotalht - $this->posxdiscount + 1, 2, $outputlangs->transnoentities(
"ReductionShort"),
'',
'C');
1229 if ($this->atleastonediscount) {
1230 $pdf->line($this->postotalht, $tab_top, $this->postotalht, $tab_top + $tab_height);
1232 if (empty($hidetop)) {
1233 $pdf->SetXY($this->postotalht - 1, $tab_top + 1);
1234 $pdf->MultiCell(30, 2, $outputlangs->transnoentities(
"TotalHTShort"),
'',
'C');
1248 protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
1250 global $conf, $langs;
1253 $outputlangs->loadLangs(array(
"main",
"bills",
"supplier_proposal",
"companies"));
1259 $pdf->SetTextColor(0, 0, 60);
1260 $pdf->SetFont(
'',
'B', $default_font_size + 3);
1262 $posy = $this->marge_haute;
1263 $posx = $this->page_largeur - $this->marge_droite - 100;
1265 $pdf->SetXY($this->marge_gauche, $posy);
1269 if ($this->emetteur->logo) {
1270 $logodir = $conf->mycompany->dir_output;
1271 if (!empty($conf->mycompany->multidir_output[$object->entity])) {
1272 $logodir = $conf->mycompany->multidir_output[$object->entity];
1275 $logo = $logodir.
'/logos/thumbs/'.$this->emetteur->logo_small;
1277 $logo = $logodir.
'/logos/'.$this->emetteur->logo;
1279 if (is_readable($logo)) {
1281 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
1283 $pdf->SetTextColor(200, 0, 0);
1284 $pdf->SetFont(
'',
'B', $default_font_size - 2);
1285 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
1286 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"ErrorGoToGlobalSetup"), 0,
'L');
1289 $text = $this->emetteur->name;
1290 $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0);
1294 $pdf->SetFont(
'',
'B', $default_font_size + 3);
1295 $pdf->SetXY($posx, $posy);
1296 $pdf->SetTextColor(0, 0, 60);
1297 $title = $outputlangs->transnoentities(
"CommercialAsk");
1298 $pdf->MultiCell(100, 4, $title,
'',
'R');
1300 $pdf->SetFont(
'',
'B', $default_font_size);
1303 $pdf->SetXY($posx, $posy);
1304 $pdf->SetTextColor(0, 0, 60);
1305 $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"Ref").
" : ".$outputlangs->convToOutputCharset($object->ref),
'',
'R');
1308 $pdf->SetFont(
'',
'', $default_font_size - 2);
1310 if ($object->ref_fourn) {
1312 $pdf->SetXY($posx, $posy);
1313 $pdf->SetTextColor(0, 0, 60);
1314 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"RefSupplier").
" : ".
dol_trunc($outputlangs->convToOutputCharset($object->ref_fourn), 65),
'',
'R');
1317 if ($object->thirdparty->code_fournisseur) {
1319 $pdf->SetXY($posx, $posy);
1320 $pdf->SetTextColor(0, 0, 60);
1321 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"SupplierCode").
" : ".$outputlangs->transnoentities($object->thirdparty->code_fournisseur),
'',
'R');
1325 if (!empty($conf->global->DOC_SHOW_FIRST_SALES_REP)) {
1326 $arrayidcontact = $object->getIdContact(
'internal',
'SALESREPFOLL');
1327 if (count($arrayidcontact) > 0) {
1328 $usertmp =
new User($this->db);
1329 $usertmp->fetch($arrayidcontact[0]);
1331 $pdf->SetXY($posx, $posy);
1332 $pdf->SetTextColor(0, 0, 60);
1333 $pdf->MultiCell(100, 3, $langs->trans(
"BuyerName").
" : ".$usertmp->getFullName($langs),
'',
'R');
1341 $current_y = $pdf->getY();
1342 $posy =
pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3,
'R', $default_font_size);
1343 if ($current_y < $pdf->getY()) {
1344 $top_shift = $pdf->getY() - $current_y;
1349 $carac_emetteur =
'';
1351 $arrayidcontact = $object->getIdContact(
'internal',
'SALESREPFOLL');
1352 if (count($arrayidcontact) > 0) {
1353 $object->fetch_user($arrayidcontact[0]);
1354 $labelbeforecontactname = ($outputlangs->transnoentities(
"FromContactName") !=
'FromContactName' ? $outputlangs->transnoentities(
"FromContactName") : $outputlangs->transnoentities(
"Name"));
1355 $carac_emetteur .= ($carac_emetteur ?
"\n" :
'').$labelbeforecontactname.
": ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs));
1357 $carac_emetteur .= (
getDolGlobalInt(
'PDF_SHOW_PHONE_AFTER_USER_CONTACT') && !empty($object->user->office_phone)) ? $object->user->office_phone :
'';
1359 $carac_emetteur .= (
getDolGlobalInt(
'PDF_SHOW_EMAIL_AFTER_USER_CONTACT') && !empty($object->user->email)) ? $object->user->email :
'';
1361 $carac_emetteur .=
"\n";
1364 $carac_emetteur .=
pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty,
'', 0,
'source', $object);
1367 $posy = 42 + $top_shift;
1368 $posx = $this->marge_gauche;
1369 if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
1370 $posx = $this->page_largeur - $this->marge_droite - 80;
1375 $pdf->SetTextColor(0, 0, 0);
1376 $pdf->SetFont(
'',
'', $default_font_size - 2);
1377 $pdf->SetXY($posx, $posy - 5);
1378 $pdf->MultiCell(80, 5, $outputlangs->transnoentities(
"BillFrom"), 0,
'L');
1379 $pdf->SetXY($posx, $posy);
1380 $pdf->SetFillColor(230, 230, 230);
1381 $pdf->MultiCell(82, $hautcadre,
"", 0,
'R', 1);
1382 $pdf->SetTextColor(0, 0, 60);
1385 $pdf->SetXY($posx + 2, $posy + 3);
1386 $pdf->SetFont(
'',
'B', $default_font_size);
1387 $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0,
'L');
1388 $posy = $pdf->getY();
1391 $pdf->SetXY($posx + 2, $posy);
1392 $pdf->SetFont(
'',
'', $default_font_size - 1);
1393 $pdf->MultiCell(80, 4, $carac_emetteur, 0,
'L');
1397 $usecontact =
false;
1398 $arrayidcontact = $object->getIdContact(
'external',
'CUSTOMER');
1399 if (count($arrayidcontact) > 0) {
1401 $result = $object->fetch_contact($arrayidcontact[0]);
1405 if (!empty($usecontact)) {
1406 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)))) {
1407 $socname = $object->contact;
1409 $socname = $object->thirdparty;
1412 $socname = $object->thirdparty;
1417 $carac_client =
pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ($usecontact ? $object->contact :
''), $usecontact,
'target', $object);
1421 if ($this->page_largeur < 210) {
1424 $posy = 42 + $top_shift;
1425 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
1426 if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
1427 $posx = $this->marge_gauche;
1431 $pdf->SetTextColor(0, 0, 0);
1432 $pdf->SetFont(
'',
'', $default_font_size - 2);
1433 $pdf->SetXY($posx + 2, $posy - 5);
1434 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"BillTo"), 0,
'L');
1435 $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
1438 $pdf->SetXY($posx + 2, $posy + 3);
1439 $pdf->SetFont(
'',
'B', $default_font_size);
1440 $pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0,
'L');
1443 $pdf->SetFont(
'',
'', $default_font_size - 1);
1444 $pdf->SetXY($posx + 2, $posy + 4 + (
dol_nboflines_bis($carac_client_name, 50) * 4));
1445 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0,
'L');
1448 $pdf->SetTextColor(0, 0, 0);