--- /tmp/dsg/dolibarr/htdocs/core/modules/cheque/doc/github_pdf_blochet.class.php +++ /tmp/dsg/dolibarr/htdocs/core/modules/cheque/doc/client_pdf_blochet.class.php @@ -68,17 +68,17 @@ $this->marge_haute = isset($conf->global->MAIN_PDF_MARGIN_TOP) ? $conf->global->MAIN_PDF_MARGIN_TOP : 10; $this->marge_basse = isset($conf->global->MAIN_PDF_MARGIN_BOTTOM) ? $conf->global->MAIN_PDF_MARGIN_BOTTOM : 10; - // Retrieves transmitter - $this->emetteur = $mysoc; - if (!$this->emetteur->country_code) $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default if not defined - - // Define column position - $this->line_height = 5; + // Retrieves transmitter + $this->emetteur = $mysoc; + if (!$this->emetteur->country_code) $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default if not defined + + // Define column position + $this->line_height = 5; $this->line_per_page = 40; $this->tab_height = 200; //$this->line_height * $this->line_per_page; } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Fonction to generate document on disk * @@ -86,22 +86,22 @@ * @param string $_dir Directory * @param string $number Number * @param Translate $outputlangs Lang output object - * @return int 1=ok, 0=ko + * @return int 1=ok, 0=ko */ public function write_file($object, $_dir, $number, $outputlangs) { - // phpcs:enable + // phpcs:enable global $user, $conf, $langs, $hookmanager; - 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 - $sav_charset_output = $outputlangs->charset_output; - if (!empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output = 'ISO-8859-1'; - - // Load traductions files required by page + 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 + $sav_charset_output = $outputlangs->charset_output; + if (!empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output = 'ISO-8859-1'; + + // Load traductions files required by page $outputlangs->loadLangs(array("main", "companies", "bills", "products", "compta")); - $dir = $_dir."/".get_exdir($number, 0, 1, 0, $object, 'checkdeposits'); + $dir = $_dir."/".get_exdir($number, 0, 1, 0, $object, 'cheque').$number; if (!is_dir($dir)) { @@ -128,19 +128,19 @@ $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks // Create PDF instance - $pdf = pdf_getInstance($this->format); - $heightforinfotot = 50; // Height reserved to output the info and total part - $heightforfreetext = (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->MAIN_PDF_FREETEXT_HEIGHT : 5); // Height reserved to output the free text on last page - $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin) - if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS)) $heightforfooter += 6; - $pdf->SetAutoPageBreak(1, 0); - - if (class_exists('TCPDF')) - { - $pdf->setPrintHeader(false); - $pdf->setPrintFooter(false); - } - $pdf->SetFont(pdf_getPDFFont($outputlangs)); + $pdf = pdf_getInstance($this->format); + $heightforinfotot = 50; // Height reserved to output the info and total part + $heightforfreetext = (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->MAIN_PDF_FREETEXT_HEIGHT : 5); // Height reserved to output the free text on last page + $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin) + if ($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS > 0) $heightforfooter += 6; + $pdf->SetAutoPageBreak(1, 0); + + if (class_exists('TCPDF')) + { + $pdf->setPrintHeader(false); + $pdf->setPrintFooter(false); + } + $pdf->SetFont(pdf_getPDFFont($outputlangs)); $pdf->Open(); $pagenb = 0; @@ -170,7 +170,7 @@ } $pdf->AddPage(); - $pagenb++; + $pagenb++; $this->Header($pdf, $pagenb, $pages, $outputlangs); $this->Body($pdf, $pagenb, $pages, $outputlangs); @@ -195,8 +195,8 @@ $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks if ($reshook < 0) { - $this->error = $hookmanager->error; - $this->errors = $hookmanager->errors; + $this->error = $hookmanager->error; + $this->errors = $hookmanager->errors; } if (!empty($conf->global->MAIN_UMASK)) @@ -204,16 +204,16 @@ $this->result = array('fullpath'=>$file); - $outputlangs->charset_output = $sav_charset_output; - return 1; // No error + $outputlangs->charset_output = $sav_charset_output; + return 1; // No error } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Generate Header * - * @param TCPDF $pdf Pdf object + * @param PDF $pdf Pdf object * @param int $page Current page number * @param int $pages Total number of pages * @param Translate $outputlangs Object language for output @@ -221,7 +221,7 @@ */ public function Header(&$pdf, $page, $pages, $outputlangs) { - // phpcs:enable + // phpcs:enable global $langs; $default_font_size = pdf_getPDFFontSize($outputlangs); @@ -230,47 +230,47 @@ $title = $outputlangs->transnoentities("CheckReceipt"); $pdf->SetFont('', 'B', $default_font_size); - $pdf->SetXY(10, 8); - $pdf->MultiCell(0, 2, $title, 0, 'L'); - - $pdf->SetFont('', '', $default_font_size); - $pdf->SetXY(10, 15); + $pdf->SetXY(10, 8); + $pdf->MultiCell(0, 2, $title, 0, 'L'); + + $pdf->SetFont('', '', $default_font_size); + $pdf->SetXY(10, 15); $pdf->MultiCell(22, 2, $outputlangs->transnoentities("Ref"), 0, 'L'); - $pdf->SetXY(32, 15); - $pdf->SetFont('', '', $default_font_size); - $pdf->MultiCell(60, 2, $outputlangs->convToOutputCharset($this->ref.($this->ref_ext ? " - ".$this->ref_ext : '')), 0, 'L'); - - $pdf->SetFont('', '', $default_font_size); - $pdf->SetXY(10, 20); - $pdf->MultiCell(22, 2, $outputlangs->transnoentities("Date"), 0, 'L'); - $pdf->SetXY(32, 20); - $pdf->SetFont('', '', $default_font_size); - $pdf->MultiCell(60, 2, dol_print_date($this->date, "day", false, $outputlangs)); - - $pdf->SetFont('', '', $default_font_size); - $pdf->SetXY(10, 26); - $pdf->MultiCell(22, 2, $outputlangs->transnoentities("Owner"), 0, 'L'); - $pdf->SetFont('', '', $default_font_size); - $pdf->SetXY(32, 26); - $pdf->MultiCell(80, 2, $outputlangs->convToOutputCharset($this->account->proprio), 0, 'L'); - - $pdf->SetFont('', '', $default_font_size); - $pdf->SetXY(10, 32); - $pdf->MultiCell(0, 2, $outputlangs->transnoentities("Account"), 0, 'L'); - pdf_bank($pdf, $outputlangs, 32, 32, $this->account, 1); - - $pdf->SetFont('', '', $default_font_size); - $pdf->SetXY(114, 15); + $pdf->SetXY(32, 15); + $pdf->SetFont('', '', $default_font_size); + $pdf->MultiCell(60, 2, $outputlangs->convToOutputCharset($this->ref.($this->ref_ext ? " - ".$this->ref_ext : '')), 0, 'L'); + + $pdf->SetFont('', '', $default_font_size); + $pdf->SetXY(10, 20); + $pdf->MultiCell(22, 2, $outputlangs->transnoentities("Date"), 0, 'L'); + $pdf->SetXY(32, 20); + $pdf->SetFont('', '', $default_font_size); + $pdf->MultiCell(60, 2, dol_print_date($this->date, "day", false, $outputlangs)); + + $pdf->SetFont('', '', $default_font_size); + $pdf->SetXY(10, 26); + $pdf->MultiCell(22, 2, $outputlangs->transnoentities("Owner"), 0, 'L'); + $pdf->SetFont('', '', $default_font_size); + $pdf->SetXY(32, 26); + $pdf->MultiCell(80, 2, $outputlangs->convToOutputCharset($this->account->proprio), 0, 'L'); + + $pdf->SetFont('', '', $default_font_size); + $pdf->SetXY(10, 32); + $pdf->MultiCell(0, 2, $outputlangs->transnoentities("Account"), 0, 'L'); + pdf_bank($pdf, $outputlangs, 32, 32, $this->account, 1); + + $pdf->SetFont('', '', $default_font_size); + $pdf->SetXY(114, 15); $pdf->MultiCell(40, 2, $outputlangs->transnoentities("Signature"), 0, 'L'); - $pdf->Rect(9, 14, 192, 35); - $pdf->line(9, 19, 112, 19); - $pdf->line(9, 25, 112, 25); - //$pdf->line(9, 31, 201, 31); - $pdf->line(9, 31, 112, 31); - - $pdf->line(30, 14, 30, 49); - $pdf->line(112, 14, 112, 49); + $pdf->Rect(9, 14, 192, 35); + $pdf->line(9, 19, 112, 19); + $pdf->line(9, 25, 112, 25); + //$pdf->line(9, 31, 201, 31); + $pdf->line(9, 31, 112, 31); + + $pdf->line(30, 14, 30, 49); + $pdf->line(112, 14, 112, 49); // Number of cheques $posy = 51; @@ -284,11 +284,11 @@ $pdf->MultiCell(40, 2, $outputlangs->transnoentities("NumberOfCheques"), 0, 'L'); $pdf->SetFont('', 'B', $default_font_size); - $pdf->SetXY(57, $posy + 1); - $pdf->MultiCell(40, 2, $this->nbcheque, 0, 'L'); - - $pdf->SetFont('', '', $default_font_size); - $pdf->SetXY(148, $posy + 1); + $pdf->SetXY(57, $posy + 1); + $pdf->MultiCell(40, 2, $this->nbcheque, 0, 'L'); + + $pdf->SetFont('', '', $default_font_size); + $pdf->SetXY(148, $posy + 1); $pdf->MultiCell(40, 2, $langs->trans("Total")); $pdf->SetFont('', 'B', $default_font_size); @@ -302,11 +302,11 @@ $pdf->line(40, $this->tab_top, 40, $this->tab_top + $this->tab_height + 10); $pdf->SetXY(41, $this->tab_top + 2); - $pdf->MultiCell(40, 2, $outputlangs->transnoentities("Bank"), 0, 'L'); + $pdf->MultiCell(40, 2, $outputlangs->transnoentities("Bank"), 0, 'L'); $pdf->line(100, $this->tab_top, 100, $this->tab_top + $this->tab_height + 10); - $pdf->SetXY(101, $this->tab_top + 2); - $pdf->MultiCell(40, 2, $outputlangs->transnoentities("CheckTransmitter"), 0, 'L'); + $pdf->SetXY(101, $this->tab_top + 2); + $pdf->MultiCell(40, 2, $outputlangs->transnoentities("CheckTransmitter"), 0, 'L'); $pdf->line(180, $this->tab_top, 180, $this->tab_top + $this->tab_height + 10); $pdf->SetXY(180, $this->tab_top + 2); @@ -317,11 +317,11 @@ } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Output array * - * @param TCPDF $pdf PDF object + * @param PDF $pdf PDF object * @param int $pagenb Page nb * @param int $pages Pages * @param Translate $outputlangs Object lang @@ -329,7 +329,7 @@ */ public function Body(&$pdf, $pagenb, $pages, $outputlangs) { - // phpcs:enable + // phpcs:enable // x=10 - Num // x=30 - Banque // x=100 - Emetteur @@ -342,30 +342,30 @@ $num = count($this->lines); for ($j = 0; $j < $num; $j++) { - // Dynamic max line heigh calculation - $dynamic_line_height = array(); - $dynamic_line_height[] = $pdf->getStringHeight(60, $outputlangs->convToOutputCharset($this->lines[$j]->bank_chq)); - $dynamic_line_height[] = $pdf->getStringHeight(80, $outputlangs->convToOutputCharset($this->lines[$j]->emetteur_chq)); - $max_line_height = max($dynamic_line_height); - // Calculate number of line used function of estimated line size - if ($max_line_height > $this->line_height) $nb_lines = floor($max_line_height / $this->line_height) + 1; - else $nb_lines = 1; - - // Add page break if we do not have space to add current line + // Dynamic max line heigh calculation + $dynamic_line_height = array(); + $dynamic_line_height[] = $pdf->getStringHeight(60, $outputlangs->convToOutputCharset($this->lines[$j]->bank_chq)); + $dynamic_line_height[] = $pdf->getStringHeight(80, $outputlangs->convToOutputCharset($this->lines[$j]->emetteur_chq)); + $max_line_height = max($dynamic_line_height); + // Calculate number of line used function of estimated line size + if ($max_line_height > $this->line_height) $nb_lines = floor($max_line_height / $this->line_height) + 1; + else $nb_lines = 1; + + // Add page break if we do not have space to add current line if ($lineinpage >= ($this->line_per_page - 1)) { - $lineinpage = 0; $yp = 0; - - // New page - $pdf->AddPage(); - $pagenb++; - $this->Header($pdf, $pagenb, $pages, $outputlangs); - $pdf->SetFont('', '', $default_font_size - 1); - $pdf->MultiCell(0, 3, ''); // Set interline to 3 - $pdf->SetTextColor(0, 0, 0); + $lineinpage = 0; $yp = 0; + + // New page + $pdf->AddPage(); + $pagenb++; + $this->Header($pdf, $pagenb, $pages, $outputlangs); + $pdf->SetFont('', '', $default_font_size - 1); + $pdf->MultiCell(0, 3, ''); // Set interline to 3 + $pdf->SetTextColor(0, 0, 0); } - $lineinpage += $nb_lines; + $lineinpage += $nb_lines; $pdf->SetXY(1, $this->tab_top + 10 + $yp); $pdf->MultiCell(8, $this->line_height, $j + 1, 0, 'R', 0); @@ -382,15 +382,15 @@ $pdf->SetXY(180, $this->tab_top + 10 + $yp); $pdf->MultiCell(20, $this->line_height, price($this->lines[$j]->amount_chq), 0, 'R', 0); - $yp = $yp + ($this->line_height * $nb_lines); + $yp = $yp + ($this->line_height * $nb_lines); } } // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore /** * Show footer of page. Need this->emetteur object - * - * @param TCPDF $pdf PDF + * + * @param PDF $pdf PDF * @param Object $object Object to show * @param Translate $outputlangs Object lang for output * @param int $hidefreetext 1=Hide free text @@ -399,17 +399,16 @@ protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0) { global $conf; - - $showdetails = empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS) ? 0 : $conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS; + $default_font_size = pdf_getPDFFontSize($outputlangs); + + $showdetails = $conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS; // Line of free text - $substitutionarray = pdf_getSubstitutionArray($outputlangs, null, $object); - complete_substitutions_array($substitutionarray, $outputlangs, $object); $newfreetext = ''; $paramfreetext = 'BANK_CHEQUERECEIPT_FREE_TEXT'; if (!empty($conf->global->$paramfreetext)) { - $newfreetext = make_substitutions($conf->global->$paramfreetext, $substitutionarray); + $newfreetext = make_substitutions($conf->global->$paramfreetext, $substitutionarray); } return pdf_pagefoot($pdf, $outputlangs, $newfreetext, $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext);