/** * Function to build pdf onto disk * @param object Id of object to generate * @param outputlangs Lang output object * @param srctemplatepath Full path of source filename for generator using a template file * @param hidedetails Do not show line details * @param hidedesc Do not show desc * @param hideref Do not show ref * @return int 1=OK, 0=KO */ function write_file($object,$outputlangs,$srctemplatepath='',$hidedetails=0,$hidedesc=0,$hideref=0) { global $user,$conf,$langs,$mysoc; if (! is_object($outputlangs)) $outputlangs=$langs; // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO if (!class_exists('TCPDF')) $outputlangs->charset_output='ISO-8859-1'; $outputlangs->load("main"); $outputlangs->load("dict"); $outputlangs->load("companies"); $outputlangs->load("bills"); $outputlangs->load("products"); $outputlangs->load("orders"); $default_font_size = pdf_getPDFFontSize($outputlangs); if ($conf->commande->dir_output) { // Definition of $dir and $file if ($object->specimen) { $dir = $conf->commande->dir_output; $file = $dir . "/SPECIMEN.pdf"; } else { $objectref = dol_sanitizeFileName($object->ref); $dir = $conf->commande->dir_output . "/" . $objectref; $file = $dir . "/" . $objectref . ".pdf"; } if (! file_exists($dir)) { if (create_exdir($dir) < 0) { $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir); return 0; } } if (file_exists($dir)) { $pdf=pdf_getInstance($this->format); if (class_exists('TCPDF')) { $pdf->setPrintHeader(false); $pdf->setPrintFooter(false); } $pdf->SetFont(pdf_getPDFFont($outputlangs)); $pdf->Open(); $pagenb=0; $pdf->SetDrawColor(128,128,128); $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref)); $pdf->SetSubject($outputlangs->transnoentities("Order")); $pdf->SetCreator("Dolibarr ".DOL_VERSION); $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs))); $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("Order")); if ($conf->global->MAIN_DISABLE_PDF_COMPRESSION) $pdf->SetCompression(false); $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right $pdf->SetAutoPageBreak(1,0); // New page $pdf->AddPage(); $pagenb++; $this->_pagehead($pdf, $object, 1, $outputlangs); $pdf->SetFont('','', $default_font_size - 1); $pdf->MultiCell(0, 3, ''); // Set interline to 3 $pdf->SetTextColor(0,0,0); $tab_top = 100; $tab_height = 140; $pdf->SetFillColor(220,220,220); $pdf->SetTextColor(0,0,0); $pdf->SetFont('','', $default_font_size - 1); $pdf->SetXY (10, $tab_top + 10 ); $iniY = $pdf->GetY(); $curY = $pdf->GetY(); $nexY = $pdf->GetY(); $nblignes = sizeof($object->lines); for ($i = 0 ; $i < $nblignes ; $i++) { $curY = $nexY; $pdf->SetFont('','', $default_font_size - 1); // Dans boucle pour gerer multi-page // Description de la ligne produit pdf_writelinedesc($pdf,$object,$i,$outputlangs,100,3,30,$curY,1,$hidedesc); //$pdf->writeHTMLCell(100, 3, 30, $curY, $outputlangs->convToOutputCharset($libelleproduitservice), 0, 1); $pdf->SetFont('','', $default_font_size - 1); // On repositionne la police par defaut $nexY = $pdf->GetY(); $ref = pdf_getlineref($object, $i, $outputlangs); $pdf->SetXY (10, $curY); $pdf->MultiCell(20, 3, $ref, 0, 'C'); $vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails); $pdf->SetXY (133, $curY); $pdf->MultiCell(12, 3, $vat_rate, 0, 'C'); $qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails); $pdf->SetXY (145, $curY); $pdf->MultiCell(10, 3, $qty, 0, 'C'); $up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails); $pdf->SetXY (156, $curY); $pdf->MultiCell(18, 3, $up_excl_tax, 0, 'R', 0); $total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails); $pdf->SetXY (174, $curY); $pdf->MultiCell(26, 3, $total_excl_tax, 0, 'R', 0); $nexY+=2; // Passe espace entre les lignes // cherche nombre de lignes a venir pour savoir si place suffisante if ($i < ($nblignes - 1) && empty($hidedesc)) // If it's not last line { //on recupere la description du produit suivant $follow_descproduitservice = $object->lines[$i+1]->desc; //on compte le nombre de ligne afin de verifier la place disponible (largeur de ligne 52 caracteres) $nblineFollowDesc = (dol_nboflines_bis($follow_descproduitservice,52,$outputlangs->charset_output)*4); } else // If it's last line { $nblineFollowDesc = 0; } if (($nexY+$nblineFollowDesc) > ($tab_top+$tab_height) && $i < ($nblignes - 1)) { $this->_tableau($pdf, $tab_top, $tab_height, $nexY, $outputlangs); // New page $pdf->AddPage(); $pagenb++; $this->_pagehead($pdf, $object, 0, $outputlangs); $pdf->SetFont('','', $default_font_size - 1); $pdf->MultiCell(0, 3, ''); // Set interline to 3 $pdf->SetTextColor(0,0,0); $nexY = $tab_top + 8; } } $this->_tableau($pdf, $tab_top, $tab_height, $nexY, $outputlangs); $bottomlasttab=$tab_top + $tab_height + 1; // Affiche zone infos $this->_tableau_info($pdf, $object, $bottomlasttab, $outputlangs); // Affiche zone totaux $tab2_top = 241; $tab2_lh = 4; $pdf->SetFont('','', $default_font_size); $pdf->SetXY (132, $tab2_top + 0); $pdf->MultiCell(42, $tab2_lh, $langs->transnoentities("TotalHT"), 0, 'R', 0); $pdf->SetXY (132, $tab2_top + $tab2_lh); $pdf->MultiCell(42, $tab2_lh, $langs->transnoentities("TotalVAT"), 0, 'R', 0); $pdf->SetXY (132, $tab2_top + ($tab2_lh*2)); $pdf->MultiCell(42, $tab2_lh, $langs->transnoentities("TotalTTC"), 1, 'R', 1); $pdf->SetXY (174, $tab2_top + 0); $pdf->MultiCell(26, $tab2_lh, price($object->total_ht), 0, 'R', 0); $pdf->SetXY (174, $tab2_top + $tab2_lh); $pdf->MultiCell(26, $tab2_lh, price($object->total_tva), 0, 'R', 0); $pdf->SetXY (174, $tab2_top + ($tab2_lh*2)); $pdf->MultiCell(26, $tab2_lh, price($object->total_ttc), 1, 'R', 1); // Pied de page $this->_pagefoot($pdf,$object,$outputlangs); $pdf->AliasNbPages(); $pdf->Close(); $pdf->Output($file,'F'); if (! empty($conf->global->MAIN_UMASK)) @chmod($file, octdec($conf->global->MAIN_UMASK)); return 1; } } else { $this->error=$langs->transnoentities("ErrorConstantNotDefined","COMMANDE_OUTPUTDIR"); return 0; } $this->error=$langs->transnoentities("ErrorUnknown"); return 0; // Erreur par defaut }
/** * Function to build pdf onto disk * * @param int $object Id of object to generate * @param object $outputlangs Lang output object * @param string $srctemplatepath Full path of source filename for generator using a template file * @param int $hidedetails Do not show line details * @param int $hidedesc Do not show desc * @param int $hideref Do not show ref * @param object $hookmanager Hookmanager object * @return int 1=OK, 0=KO */ function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0, $hookmanager = false) { global $user, $conf, $langs, $mysoc; $default_font_size = pdf_getPDFFontSize($outputlangs); if (!is_object($outputlangs)) { $outputlangs = $langs; } // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO if (!empty($conf->global->MAIN_USE_FPDF)) { $outputlangs->charset_output = 'ISO-8859-1'; } $outputlangs->load("main"); $outputlangs->load("dict"); $outputlangs->load("companies"); $outputlangs->load("bills"); $outputlangs->load("products"); $outputlangs->load("orders"); if ($conf->commande->dir_output) { // Definition of $dir and $file if ($object->specimen) { $dir = $conf->commande->dir_output; $file = $dir . "/SPECIMEN.pdf"; } else { $objectref = dol_sanitizeFileName($object->ref); $dir = $conf->commande->dir_output . "/" . $objectref; $file = $dir . "/" . $objectref . ".pdf"; } if (!file_exists($dir)) { if (dol_mkdir($dir) < 0) { $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir); return 0; } } if (file_exists($dir)) { $nblignes = count($object->lines); $pdf = pdf_getInstance($this->format); if (class_exists('TCPDF')) { $pdf->setPrintHeader(false); $pdf->setPrintFooter(false); } $pdf->SetFont(pdf_getPDFFont($outputlangs)); // Set path to the background PDF File if (empty($conf->global->MAIN_DISABLE_FPDI) && !empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) { $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output . '/' . $conf->global->MAIN_ADD_PDF_BACKGROUND); $tplidx = $pdf->importPage(1); } $pdf->Open(); $pagenb = 0; $pdf->SetDrawColor(128, 128, 128); $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref)); $pdf->SetSubject($outputlangs->transnoentities("Order")); $pdf->SetCreator("Dolibarr " . DOL_VERSION); $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs))); $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref) . " " . $outputlangs->transnoentities("Order")); if ($conf->global->MAIN_DISABLE_PDF_COMPRESSION) { $pdf->SetCompression(false); } $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right $pdf->SetAutoPageBreak(1, 0); // New page $pdf->AddPage(); if (!empty($tplidx)) { $pdf->useTemplate($tplidx); } $pagenb++; $this->_pagehead($pdf, $object, 1, $outputlangs, $hookmanager); $pdf->SetFont('', '', $default_font_size - 1); $pdf->MultiCell(0, 3, ''); // Set interline to 3 $pdf->SetTextColor(0, 0, 0); $tab_top = 100; $tab_height = 140; $pdf->SetFillColor(220, 220, 220); $pdf->SetTextColor(0, 0, 0); $pdf->SetFont('', '', $default_font_size - 1); $pdf->SetXY(10, $tab_top + 10); $iniY = $pdf->GetY(); $curY = $pdf->GetY(); $nexY = $pdf->GetY(); $nblignes = count($object->lines); for ($i = 0; $i < $nblignes; $i++) { $curY = $nexY; $pdf->SetFont('', '', $default_font_size - 1); // Dans boucle pour gerer multi-page // Description of product line pdf_writelinedesc($pdf, $object, $i, $outputlangs, 100, 3, 30, $curY, 1, $hidedesc, 0, $hookmanager); $pdf->SetFont('', '', $default_font_size - 1); // On repositionne la police par defaut $nexY = $pdf->GetY(); $ref = pdf_getlineref($object, $i, $outputlangs, $hidedetails, $hookmanager); $pdf->SetXY(10, $curY); $pdf->MultiCell(20, 3, $ref, 0, 'C'); $vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails, $hookmanager); $pdf->SetXY(133, $curY); $pdf->MultiCell(12, 3, $vat_rate, 0, 'C'); $qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails, $hookmanager); $pdf->SetXY(145, $curY); $pdf->MultiCell(10, 3, $qty, 0, 'C'); $up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails, $hookmanager); $pdf->SetXY(156, $curY); $pdf->MultiCell(18, 3, $up_excl_tax, 0, 'R', 0); $total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails, $hookmanager); $pdf->SetXY(174, $curY); $pdf->MultiCell(26, 3, $total_excl_tax, 0, 'R', 0); $nexY += 2; // Passe espace entre les lignes // cherche nombre de lignes a venir pour savoir si place suffisante if ($i < $nblignes - 1 && empty($hidedesc)) { //on recupere la description du produit suivant $follow_descproduitservice = $object->lines[$i + 1]->desc; //on compte le nombre de ligne afin de verifier la place disponible (largeur de ligne 52 caracteres) $nblineFollowDesc = dol_nboflines_bis($follow_descproduitservice, 52, $outputlangs->charset_output) * 4; } else { $nblineFollowDesc = 0; } if ($nexY + $nblineFollowDesc > $tab_top + $tab_height && $i < $nblignes - 1 || isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) { $this->_tableau($pdf, $tab_top, $tab_height, $nexY, $outputlangs); // New page $pdf->AddPage(); if (!empty($tplidx)) { $pdf->useTemplate($tplidx); } $pagenb++; $this->_pagehead($pdf, $object, 0, $outputlangs, $hookmanager); $pdf->SetFont('', '', $default_font_size - 1); $pdf->MultiCell(0, 3, ''); // Set interline to 3 $pdf->SetTextColor(0, 0, 0); $nexY = $tab_top + 8; } } $this->_tableau($pdf, $tab_top, $tab_height, $nexY, $outputlangs); $bottomlasttab = $tab_top + $tab_height + 1; // Affiche zone infos $this->_tableau_info($pdf, $object, $bottomlasttab, $outputlangs); // Affiche zone totaux $tab2_top = 241; $tab2_lh = 4; $pdf->SetFont('', '', $default_font_size); $pdf->SetXY(132, $tab2_top + 0); $pdf->MultiCell(42, $tab2_lh, $langs->transnoentities("TotalHT"), 0, 'R', 0); $pdf->SetXY(132, $tab2_top + $tab2_lh); $pdf->MultiCell(42, $tab2_lh, $langs->transnoentities("TotalVAT"), 0, 'R', 0); $pdf->SetXY(132, $tab2_top + $tab2_lh * 2); $pdf->MultiCell(42, $tab2_lh, $langs->transnoentities("TotalTTC"), 1, 'R', 1); $pdf->SetXY(174, $tab2_top + 0); $pdf->MultiCell(26, $tab2_lh, price($object->total_ht), 0, 'R', 0); $pdf->SetXY(174, $tab2_top + $tab2_lh); $pdf->MultiCell(26, $tab2_lh, price($object->total_tva), 0, 'R', 0); $pdf->SetXY(174, $tab2_top + $tab2_lh * 2); $pdf->MultiCell(26, $tab2_lh, price($object->total_ttc), 1, 'R', 1); // Pied de page $this->_pagefoot($pdf, $object, $outputlangs); $pdf->AliasNbPages(); $pdf->Close(); $pdf->Output($file, 'F'); // Actions on extra fields (by external module or standard code) if (!is_object($hookmanager)) { include_once DOL_DOCUMENT_ROOT . '/core/class/hookmanager.class.php'; $hookmanager = new HookManager($this->db); } $hookmanager->initHooks(array('pdfgeneration')); $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs); global $action; $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks if (!empty($conf->global->MAIN_UMASK)) { @chmod($file, octdec($conf->global->MAIN_UMASK)); } return 1; } } else { $this->error = $langs->transnoentities("ErrorConstantNotDefined", "COMMANDE_OUTPUTDIR"); return 0; } $this->error = $langs->transnoentities("ErrorUnknown"); return 0; // Erreur par defaut }