28 require_once DOL_DOCUMENT_ROOT.
'/core/modules/supplier_payment/modules_supplier_payment.php';
29 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
30 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/paiementfourn.class.php';
31 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
32 require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
33 require_once DOL_DOCUMENT_ROOT.
'/core/lib/pdf.lib.php';
34 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functionsnumtoword.lib.php';
60 public $update_main_doc_field;
71 public $version =
'dolibarr';
74 public $posxreffacturefourn;
75 public $posxreffacture;
89 global $langs, $mysoc;
92 $langs->loadLangs(array(
"main",
"bills"));
95 $this->
name =
"standard";
96 $this->
description = $langs->trans(
'DocumentModelStandardPDF');
97 $this->update_main_doc_field = 0;
102 $this->page_largeur = $formatarray[
'width'];
103 $this->page_hauteur = $formatarray[
'height'];
104 $this->format = array($this->page_largeur, $this->page_hauteur);
110 $this->option_logo = 1;
111 $this->option_multilang = 1;
114 $this->posxdate = $this->marge_gauche + 1;
115 $this->posxreffacturefourn = 30;
116 $this->posxreffacture = 65;
117 $this->posxtype = 100;
118 $this->posxtotalht = 80;
120 $this->posxtotalttc = 180;
122 if ($this->page_largeur < 210) {
123 $this->posxreffacturefourn -= 20;
124 $this->posxreffacture -= 20;
125 $this->posxtype -= 20;
126 $this->posxtotalht -= 20;
127 $this->posxtva -= 20;
128 $this->posxtotalttc -= 20;
131 $this->tva = array();
132 $this->tva_array = array();
133 $this->localtax1 = array();
134 $this->localtax2 = array();
135 $this->atleastoneratenotnull = 0;
136 $this->atleastonediscount = 0;
139 $this->emetteur = $mysoc;
140 if (!$this->emetteur->country_code) {
141 $this->emetteur->country_code = substr($langs->defaultlang, -2);
158 public function write_file(
$object, $outputlangs =
null, $srctemplatepath =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
161 global $user, $langs, $conf, $mysoc, $hookmanager;
163 if (!is_object($outputlangs)) {
164 $outputlangs = $langs;
168 $outputlangs->charset_output =
'ISO-8859-1';
172 $outputlangs->loadLangs(array(
"main",
"suppliers",
"companies",
"bills",
"dict",
"products"));
176 if ($conf->fournisseur->payment->dir_output) {
181 $sql =
'SELECT f.rowid, f.ref, f.datef, f.ref_supplier, f.total_ht, f.total_tva, f.total_ttc, pf.amount, f.rowid as facid, f.paye';
182 $sql .=
', f.fk_statut, s.nom as name, s.rowid as socid';
183 $sql .=
' FROM '.MAIN_DB_PREFIX.
'paiementfourn_facturefourn as pf,'.MAIN_DB_PREFIX.
'facture_fourn as f,'.MAIN_DB_PREFIX.
'societe as s';
184 $sql .=
' WHERE pf.fk_facturefourn = f.rowid AND f.fk_soc = s.rowid';
185 $sql .=
' AND pf.fk_paiementfourn = '.((int)
$object->id);
186 $resql = $this->db->query(
$sql);
188 if ($this->db->num_rows($resql) > 0) {
189 while ($objp = $this->db->fetch_object($resql)) {
190 $objp->type = $outputlangs->trans(
'SupplierInvoice');
200 $dir = $conf->fournisseur->payment->dir_output;
201 $file = $dir.
"/SPECIMEN.pdf";
205 $dir = $conf->fournisseur->payment->dir_output.
'/'.$objectref;
206 $file = $dir.
"/".$objectref.
".pdf";
212 if (!file_exists($dir)) {
214 $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
219 if (file_exists($dir)) {
221 if (!is_object($hookmanager)) {
222 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
225 $hookmanager->initHooks(array(
'pdfgeneration'));
226 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
228 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters,
$object, $action);
234 $heightforinfotot = 50;
235 $heightforfreetext = (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->MAIN_PDF_FREETEXT_HEIGHT : 5);
236 $heightforfooter = $this->marge_basse + 8;
238 $heightforfooter += 6;
240 $pdf->SetAutoPageBreak(1, 0);
242 if (class_exists(
'TCPDF')) {
243 $pdf->setPrintHeader(
false);
244 $pdf->setPrintFooter(
false);
249 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.
'/' .
getDolGlobalString(
'MAIN_ADD_PDF_BACKGROUND'));
250 $tplidx = $pdf->importPage(1);
255 $pdf->SetDrawColor(128, 128, 128);
257 $pdf->SetTitle($outputlangs->convToOutputCharset(
$object->ref));
258 $pdf->SetSubject($outputlangs->transnoentities(
"Invoice"));
259 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
260 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
261 $pdf->SetKeyWords($outputlangs->convToOutputCharset(
$object->ref).
" ".$outputlangs->transnoentities(
"Order").
" ".$outputlangs->convToOutputCharset(
$object->thirdparty->name));
263 $pdf->SetCompression(
false);
267 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
272 if (!empty($tplidx)) {
273 $pdf->useTemplate($tplidx);
277 $pdf->SetFont(
'',
'', $default_font_size - 1);
278 $pdf->MultiCell(0, 3,
'');
279 $pdf->SetTextColor(0, 0, 0);
282 $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 : 10);
284 $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
287 $height_incoterms = 0;
291 $iniY = $tab_top + 7;
292 $curY = $tab_top + 7;
293 $nexY = $tab_top + 7;
296 for ($i = 0; $i < $nblines; $i++) {
298 $pdf->SetFont(
'',
'', $default_font_size - 1);
299 $pdf->SetTextColor(0, 0, 0);
301 $pdf->setTopMargin($tab_top_newpage);
302 $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext + $heightforinfotot);
303 $pageposbefore = $pdf->getPage();
306 $curX = $this->posxdate - 1;
307 $showpricebeforepagebreak = 1;
309 $pdf->startTransaction();
311 $pdf->writeHTMLCell($this->posxtva - $curX, 4, $curX, $curY,
$object->lines[$i]->datef, 0, 1,
false,
true,
'J',
true);
312 $pageposafter = $pdf->getPage();
313 if ($pageposafter > $pageposbefore) {
314 $pdf->rollbackTransaction(
true);
315 $pageposafter = $pageposbefore;
317 $pdf->setPageOrientation(
'', 1, $heightforfooter);
319 $pdf->writeHTMLCell($this->posxtva - $curX, 4, $curX, $curY,
$object->lines[$i]->datef, 0, 1,
false,
true,
'J',
true);
320 $posyafter = $pdf->GetY();
321 if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {
322 if ($i == ($nblines - 1)) {
323 $pdf->AddPage(
'',
'',
true);
324 if (!empty($tplidx)) {
325 $pdf->useTemplate($tplidx);
330 $pdf->setPage($pageposafter + 1);
336 $showpricebeforepagebreak = 1;
338 $showpricebeforepagebreak = 0;
342 $pdf->commitTransaction();
345 $nexY = $pdf->GetY();
346 $pageposafter = $pdf->getPage();
347 $pdf->setPage($pageposbefore);
348 $pdf->setTopMargin($this->marge_haute);
349 $pdf->setPageOrientation(
'', 1, 0);
352 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
353 $pdf->setPage($pageposafter);
354 $curY = $tab_top_newpage;
357 $pdf->SetFont(
'',
'', $default_font_size - 1);
360 $pdf->SetXY($this->posxreffacturefourn, $curY);
361 $pdf->MultiCell($this->posxreffacturefourn - 0.8, 3,
$object->lines[$i]->ref_supplier, 0,
'L', 0);
364 $pdf->SetXY($this->posxreffacture, $curY);
365 $pdf->MultiCell($this->posxreffacture - 0.8, 3,
$object->lines[$i]->ref, 0,
'L', 0);
368 $pdf->SetXY($this->posxtype, $curY);
369 $pdf->MultiCell($this->posxtype - 0.8, 3,
$object->lines[$i]->type, 0,
'L', 0);
372 $pdf->SetXY($this->posxtotalht, $curY);
373 $pdf->MultiCell($this->posxtotalht - 0.8, 3,
price(
$object->lines[$i]->total_ht), 0,
'R', 0);
376 $pdf->SetXY($this->posxtva, $curY);
377 $pdf->MultiCell($this->posxtva - 0.8, 3,
price(
$object->lines[$i]->total_tva), 0,
'R', 0);
380 $pdf->SetXY($this->posxtotalttc, $curY);
381 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxtotalttc, 3,
price(
$object->lines[$i]->total_ttc), 0,
'R', 0);
386 $pdf->setPage($pageposafter);
387 $pdf->SetLineStyle(array(
'dash' =>
'1,1',
'color' => array(80, 80, 80)));
389 $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
390 $pdf->SetLineStyle(array(
'dash' => 0));
396 while ($pagenb < $pageposafter) {
397 $pdf->setPage($pagenb);
399 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
401 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
405 $pdf->setPage($pagenb);
406 $pdf->setPageOrientation(
'', 1, 0);
410 if (!empty($tplidx)) {
411 $pdf->useTemplate($tplidx);
414 if (isset(
$object->lines[$i + 1]->pagebreak) &&
$object->lines[$i + 1]->pagebreak) {
416 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
418 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
423 if (!empty($tplidx)) {
424 $pdf->useTemplate($tplidx);
435 $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
436 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
438 $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
439 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
450 if (method_exists($pdf,
'AliasNbPages')) {
451 $pdf->AliasNbPages();
456 $pdf->Output($file,
'F');
459 $hookmanager->initHooks(array(
'pdfgeneration'));
460 $parameters = array(
'file' => $file,
'object' =>
$object,
'outputlangs' => $outputlangs);
462 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
464 $this->error = $hookmanager->error;
465 $this->errors = $hookmanager->errors;
470 $this->result = array(
'fullpath' => $file);
474 $this->error = $langs->trans(
"ErrorCanNotCreateDir", $dir);
478 $this->error = $langs->trans(
"ErrorConstantNotDefined",
"SUPPLIER_OUTPUTDIR");
497 global $conf, $mysoc;
501 $pdf->SetFont(
'',
'', $default_font_size - 1);
502 $pdf->SetFillColor(255, 255, 255);
505 $pdf->SetXY($this->marge_gauche, $posy);
506 $pdf->MultiCell(30, 4,
'N° '.$outputlangs->transnoentities(
"Payment"), 0,
'L', 1);
509 $pdf->SetXY($this->marge_gauche + 30, $posy);
510 $pdf->MultiCell(50, 4,
$object->ref, 0,
'L', 1);
513 $pdf->SetXY($this->page_largeur - $this->marge_droite - 50, $posy);
514 $pdf->MultiCell(50, 4,
price(
$object->amount), 0,
'R', 1);
518 $currency = $conf->currency;
520 $pdf->SetXY($this->marge_gauche + 50, $posy);
521 $pdf->SetFont(
'',
'', $default_font_size - 3);
522 $pdf->MultiCell(90, 8, $translateinletter, 0,
'L', 1);
523 $pdf->SetFont(
'',
'', $default_font_size - 1);
527 $pdf->SetXY($this->marge_gauche + 50, $posy);
528 $pdf->MultiCell(150, 4,
$object->thirdparty->name, 0,
'L', 1);
531 $pdf->SetXY($this->page_largeur - $this->marge_droite - $LENGTHAMOUNT, $posy);
532 $pdf->MultiCell($LENGTHAMOUNT, 4, str_pad(
price(
$object->amount).
' '.$currency, 18,
'*', STR_PAD_LEFT), 0,
'R', 1);
536 $pdf->SetXY($this->page_largeur - $this->marge_droite - 30, $posy);
537 $pdf->MultiCell(150, 4, $mysoc->town, 0,
'L', 1);
541 $pdf->SetXY($this->page_largeur - $this->marge_droite - 30, $posy);
542 $pdf->MultiCell(150, 4, date(
"d").
' '.$outputlangs->transnoentitiesnoconv(date(
"F")).
' '.date(
"Y"), 0,
'L', 1);
560 protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency =
'')
562 global $conf, $mysoc;
570 $currency = !empty($currency) ? $currency : $conf->currency;
574 $pdf->SetTextColor(0, 0, 0);
575 $pdf->SetFont(
'',
'', $default_font_size - 2);
581 $titre = $outputlangs->transnoentities(
"AmountInCurrency", $outputlangs->transnoentitiesnoconv(
"Currency".$currency));
582 $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top);
583 $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
586 $pdf->SetDrawColor(128, 128, 128);
587 $pdf->SetFont(
'',
'', $default_font_size - 1);
605 global $langs, $conf, $mysoc;
608 $outputlangs->loadLangs(array(
"main",
"orders",
"companies",
"bills"));
615 $pdf->SetTextColor(0, 0, 60);
616 $pdf->SetFont(
'',
'B', $default_font_size + 3);
618 $posy = $this->marge_haute;
619 $posx = $this->page_largeur - $this->marge_droite - 100;
621 $pdf->SetXY($this->marge_gauche, $posy);
624 $logo = $conf->mycompany->dir_output.
'/logos/'.$mysoc->logo;
626 if (is_readable($logo)) {
628 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
630 $pdf->SetTextColor(200, 0, 0);
631 $pdf->SetFont(
'',
'B', $default_font_size - 2);
632 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0,
'L');
633 $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"ErrorGoToModuleSetup"), 0,
'L');
636 $text = $this->emetteur->name;
637 $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0,
'L');
717 $posx = $this->marge_gauche;
719 $posx = $this->page_largeur - $this->marge_droite - 80;
724 $pdf->SetTextColor(0, 0, 0);
725 $pdf->SetFont(
'',
'', $default_font_size - 2);
726 $pdf->SetXY($posx, $posy - 5);
727 $pdf->MultiCell(80, 5, $outputlangs->transnoentities(
"PayedBy"), 0,
'L');
728 $pdf->SetXY($posx, $posy);
729 $pdf->SetFillColor(230, 230, 230);
730 $pdf->MultiCell(82, $hautcadre,
"", 0,
'R', 1);
731 $pdf->SetTextColor(0, 0, 60);
734 $pdf->SetXY($posx + 2, $posy + 3);
735 $pdf->SetFont(
'',
'B', $default_font_size);
736 $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0,
'L');
737 $posy = $pdf->getY();
740 $pdf->SetXY($posx + 2, $posy);
741 $pdf->SetFont(
'',
'', $default_font_size - 1);
742 $pdf->MultiCell(80, 4, $carac_emetteur, 0,
'L');
745 $thirdparty =
$object->thirdparty;
755 if ($this->page_largeur < 210) {
759 $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
761 $posx = $this->marge_gauche;
765 $pdf->SetTextColor(0, 0, 0);
766 $pdf->SetFont(
'',
'', $default_font_size - 2);
767 $pdf->SetXY($posx + 2, $posy - 5);
768 $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"PayedTo"), 0,
'L');
769 $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
772 $pdf->SetXY($posx + 2, $posy + 3);
773 $pdf->SetFont(
'',
'B', $default_font_size);
774 $pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0,
'L');
776 $posy = $pdf->getY();
779 $pdf->SetFont(
'',
'', $default_font_size - 1);
780 $pdf->SetXY($posx + 2, $posy);
781 $pdf->MultiCell($widthrecbox, 4, $carac_client, 0,
'L');
785 $sql =
"SELECT iban_prefix as iban";
786 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_rib as rib";
787 $sql .=
" WHERE fk_soc = ".($object->thirdparty->id);
788 $sql .=
" AND rib.default_rib = 1";
789 $sql .=
" AND rib.type = 'ban'";
791 $resql = $this->db->query(
$sql);
793 $obj = $this->db->fetch_object($resql);
800 $pdf->SetFont(
'',
'', $default_font_size - 1);
801 $pdf->SetXY($posx + 2, $posy + 15);
802 $pdf->MultiCell($widthrecbox, 4, $langs->trans(
"IBAN").
': '.$iban, 0,
'L');
821 $showdetails =
getDolGlobalInt(
'MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', 0);
822 return pdf_pagefoot($pdf, $outputlangs,
'SUPPLIER_INVOICE_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur,
$object, $showdetails, $hidefreetext);
if($user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Parent class for supplier invoices models.
Class to generate expense report based on standard model.
__construct($db)
Constructor.
_tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0, $currency='')
Show table for lines.
_tableau_cheque(&$pdf, $object, $posy, $outputlangs)
Show total to pay.
write_file($object, $outputlangs=null, $srctemplatepath='', $hidedetails=0, $hidedesc=0, $hideref=0)
Function to build pdf onto disk.
_pagehead(&$pdf, $object, $showaddress, $outputlangs)
Show top header of page.
_pagefoot(&$pdf, $object, $outputlangs, $hidefreetext=0)
Show footer of page.
if(isModEnabled('invoice') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&!getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD') && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') && $user->hasRight('tax', 'charges', 'lire')) if(isModEnabled('invoice') &&isModEnabled('order') && $user->hasRight("commande", "lire") &&!getDolGlobalString('WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER')) $sql
Social contributions to pay.
print *****$script_file(".$version.") pid cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dolChmod($filepath, $newmask='')
Change mod of a file.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
dol_convertToWord($num, $langs, $currency='', $centimes=false)
Function to return a number into a text.
pdf_getPDFFontSize($outputlangs)
Return font size to use for PDF generation.
pdf_getFormat(Translate $outputlangs=null, $mode='setup')
Return array with format properties of default PDF format.
pdf_getHeightForLogo($logo, $url=false)
Return height to use for Logo onto PDF.
pdf_pagefoot(&$pdf, $outputlangs, $paramfreetext, $fromcompany, $marge_basse, $marge_gauche, $page_hauteur, $object, $showdetails=0, $hidefreetext=0, $page_largeur=0, $watermark='')
Show footer of page for PDF generation.
pdf_getPDFFont($outputlangs)
Return font name to use for PDF generation.
pdf_build_address($outputlangs, $sourcecompany, $targetcompany='', $targetcontact='', $usecontact=0, $mode='source', $object=null)
Return a string with full address formatted for output on PDF documents.
pdf_getInstance($format='', $metric='mm', $pagetype='P')
Return a PDF instance object.
pdfBuildThirdpartyName($thirdparty, Translate $outputlangs, $includealias=0)
Returns the name of the thirdparty.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
$conf db name
Only used if Module[ID]Name translation string is not found.