Total Complexity | 419 |
Total Lines | 2172 |
Duplicated Lines | 0 % |
Changes | 0 |
Complex classes like pdf_crabe often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use pdf_crabe, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
57 | class pdf_crabe extends ModelePDFFactures |
||
58 | { |
||
59 | /** |
||
60 | * @var DoliDB Database handler |
||
61 | */ |
||
62 | public $db; |
||
63 | |||
64 | /** |
||
65 | * @var string model name |
||
66 | */ |
||
67 | public $name; |
||
68 | |||
69 | /** |
||
70 | * @var string model description (short text) |
||
71 | */ |
||
72 | public $description; |
||
73 | |||
74 | /** |
||
75 | * @var int Save the name of generated file as the main doc when generating a doc with this template |
||
76 | */ |
||
77 | public $update_main_doc_field; |
||
78 | |||
79 | /** |
||
80 | * @var string document type |
||
81 | */ |
||
82 | public $type; |
||
83 | |||
84 | /** |
||
85 | * Dolibarr version of the loaded document |
||
86 | * @var string |
||
87 | */ |
||
88 | public $version = 'dolibarr'; |
||
89 | |||
90 | /** |
||
91 | * @var bool Situation invoice type |
||
92 | */ |
||
93 | public $situationinvoice; |
||
94 | |||
95 | /** |
||
96 | * @var float X position for the situation progress column |
||
97 | */ |
||
98 | public $posxprogress; |
||
99 | |||
100 | /** |
||
101 | * @var int Category of operation |
||
102 | */ |
||
103 | public $categoryOfOperation = -1; // unknown by default |
||
104 | |||
105 | |||
106 | /** |
||
107 | * Constructor |
||
108 | * |
||
109 | * @param DoliDB $db Database handler |
||
110 | */ |
||
111 | public function __construct($db) |
||
112 | { |
||
113 | global $conf, $langs, $mysoc; |
||
114 | |||
115 | // Translations |
||
116 | $langs->loadLangs(array("main", "bills")); |
||
117 | |||
118 | $this->db = $db; |
||
119 | $this->name = "crabe"; |
||
120 | $this->description = $langs->trans('PDFCrabeDescription'); |
||
121 | $this->update_main_doc_field = 1; // Save the name of generated file as the main doc when generating a doc with this template |
||
122 | |||
123 | // Dimension page |
||
124 | $this->type = 'pdf'; |
||
125 | $formatarray = pdf_getFormat(); |
||
126 | $this->page_largeur = $formatarray['width']; |
||
127 | $this->page_hauteur = $formatarray['height']; |
||
128 | $this->format = array($this->page_largeur, $this->page_hauteur); |
||
129 | $this->marge_gauche = getDolGlobalInt('MAIN_PDF_MARGIN_LEFT', 10); |
||
130 | $this->marge_droite = getDolGlobalInt('MAIN_PDF_MARGIN_RIGHT', 10); |
||
131 | $this->marge_haute = getDolGlobalInt('MAIN_PDF_MARGIN_TOP', 10); |
||
132 | $this->marge_basse = getDolGlobalInt('MAIN_PDF_MARGIN_BOTTOM', 10); |
||
133 | |||
134 | $this->option_logo = 1; // Display logo |
||
135 | $this->option_tva = 1; // Manage the vat option FACTURE_TVAOPTION |
||
136 | $this->option_modereg = 1; // Display payment mode |
||
137 | $this->option_condreg = 1; // Display payment terms |
||
138 | $this->option_multilang = 1; // Available in several languages |
||
139 | $this->option_escompte = 1; // Displays if there has been a discount |
||
140 | $this->option_credit_note = 1; // Support credit notes |
||
141 | $this->option_freetext = 1; // Support add of a personalised text |
||
142 | $this->option_draft_watermark = 1; // Support add of a watermark on drafts |
||
143 | $this->watermark = ''; |
||
144 | |||
145 | // Get source company |
||
146 | $this->emetteur = $mysoc; |
||
147 | if (empty($this->emetteur->country_code)) { |
||
148 | $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default, if was not defined |
||
149 | } |
||
150 | |||
151 | // Define position of columns |
||
152 | $this->posxdesc = $this->marge_gauche + 1; |
||
153 | if (getDolGlobalInt('PRODUCT_USE_UNITS')) { |
||
154 | $this->posxtva = 101; |
||
155 | $this->posxup = 118; |
||
156 | $this->posxqty = 135; |
||
157 | $this->posxunit = 151; |
||
158 | } else { |
||
159 | $this->posxtva = 106; |
||
160 | $this->posxup = 122; |
||
161 | $this->posxqty = 145; |
||
162 | $this->posxunit = 162; |
||
163 | } |
||
164 | $this->posxprogress = 151; // Only displayed for situation invoices |
||
165 | $this->posxdiscount = 162; |
||
166 | $this->posxprogress = 174; |
||
167 | $this->postotalht = 174; |
||
168 | if (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT') || getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN')) { |
||
169 | $this->posxtva = $this->posxup; |
||
170 | } |
||
171 | $this->posxpicture = $this->posxtva - getDolGlobalInt('MAIN_DOCUMENTS_WITH_PICTURE_WIDTH', 20); // width of images |
||
172 | if ($this->page_largeur < 210) { // To work with US executive format |
||
173 | $this->posxpicture -= 20; |
||
174 | $this->posxtva -= 20; |
||
175 | $this->posxup -= 20; |
||
176 | $this->posxqty -= 20; |
||
177 | $this->posxunit -= 20; |
||
178 | $this->posxdiscount -= 20; |
||
179 | $this->posxprogress -= 20; |
||
180 | $this->postotalht -= 20; |
||
181 | } |
||
182 | |||
183 | $this->tva = array(); |
||
184 | $this->tva_array = array(); |
||
185 | $this->localtax1 = array(); |
||
186 | $this->localtax2 = array(); |
||
187 | $this->atleastoneratenotnull = 0; |
||
188 | $this->atleastonediscount = 0; |
||
189 | $this->situationinvoice = false; |
||
190 | } |
||
191 | |||
192 | |||
193 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
||
194 | |||
195 | /** |
||
196 | * Function to build pdf onto disk |
||
197 | * |
||
198 | * @param Facture $object Object to generate |
||
199 | * @param Translate $outputlangs Lang output object |
||
200 | * @param string $srctemplatepath Full path of source filename for generator using a template file |
||
201 | * @param int $hidedetails Do not show line details |
||
202 | * @param int $hidedesc Do not show desc |
||
203 | * @param int $hideref Do not show ref |
||
204 | * @return int 1=OK, 0=KO |
||
205 | */ |
||
206 | public function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0) |
||
207 | { |
||
208 | // phpcs:enable |
||
209 | global $user, $langs, $conf, $mysoc, $hookmanager, $nblines; |
||
210 | |||
211 | dol_syslog("write_file outputlangs->defaultlang=" . (is_object($outputlangs) ? $outputlangs->defaultlang : 'null')); |
||
212 | |||
213 | if (!is_object($outputlangs)) { |
||
214 | $outputlangs = $langs; |
||
215 | } |
||
216 | // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO |
||
217 | if (getDolGlobalString('MAIN_USE_FPDF')) { |
||
218 | $outputlangs->charset_output = 'ISO-8859-1'; |
||
219 | } |
||
220 | |||
221 | // Load translation files required by the page |
||
222 | $outputlangs->loadLangs(array("main", "bills", "products", "dict", "companies")); |
||
223 | |||
224 | // Show Draft Watermark |
||
225 | if ($object->statut == $object::STATUS_DRAFT && (getDolGlobalString('FACTURE_DRAFT_WATERMARK'))) { |
||
226 | $this->watermark = getDolGlobalString('FACTURE_DRAFT_WATERMARK'); |
||
227 | } |
||
228 | |||
229 | global $outputlangsbis; |
||
230 | $outputlangsbis = null; |
||
231 | if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE') && $outputlangs->defaultlang != getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE')) { |
||
232 | $outputlangsbis = new Translate('', $conf); |
||
233 | $outputlangsbis->setDefaultLang(getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE')); |
||
234 | $outputlangsbis->loadLangs(array("main", "bills", "products", "dict", "companies")); |
||
235 | } |
||
236 | |||
237 | $nblines = count($object->lines); |
||
238 | |||
239 | // Loop on each lines to detect if there is at least one image to show |
||
240 | $realpatharray = array(); |
||
241 | if (getDolGlobalString('MAIN_GENERATE_INVOICES_WITH_PICTURE')) { |
||
242 | for ($i = 0; $i < $nblines; $i++) { |
||
243 | if (empty($object->lines[$i]->fk_product)) { |
||
244 | continue; |
||
245 | } |
||
246 | |||
247 | $objphoto = new Product($this->db); |
||
248 | $objphoto->fetch($object->lines[$i]->fk_product); |
||
249 | |||
250 | $pdir = get_exdir($object->lines[$i]->fk_product, 2, 0, 0, $objphoto, 'product') . $object->lines[$i]->fk_product . "/photos/"; |
||
251 | $dir = $conf->product->dir_output . '/' . $pdir; |
||
252 | |||
253 | $realpath = ''; |
||
254 | foreach ($objphoto->liste_photos($dir, 1) as $key => $obj) { |
||
255 | $filename = $obj['photo']; |
||
256 | //if ($obj['photo_vignette']) $filename='thumbs/'.$obj['photo_vignette']; |
||
257 | $realpath = $dir . $filename; |
||
258 | break; |
||
259 | } |
||
260 | |||
261 | if ($realpath) { |
||
262 | $realpatharray[$i] = $realpath; |
||
263 | } |
||
264 | } |
||
265 | } |
||
266 | if (count($realpatharray) == 0) { |
||
267 | $this->posxpicture = $this->posxtva; |
||
268 | } |
||
269 | |||
270 | if ($conf->facture->dir_output) { |
||
271 | $object->fetch_thirdparty(); |
||
272 | |||
273 | $deja_regle = $object->getSommePaiement((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0); |
||
274 | $amount_credit_notes_included = $object->getSumCreditNotesUsed((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0); |
||
275 | $amount_deposits_included = $object->getSumDepositsUsed((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0); |
||
276 | |||
277 | // Definition of $dir and $file |
||
278 | if ($object->specimen) { |
||
279 | $dir = empty($conf->facture->multidir_output[$object->entity]) ? $conf->facture->dir_output : $conf->facture->multidir_output[$object->entity]; |
||
280 | $file = $dir . "/SPECIMEN.pdf"; |
||
281 | } else { |
||
282 | $objectref = dol_sanitizeFileName($object->ref); |
||
283 | $dir = (empty($conf->facture->multidir_output[$object->entity]) ? $conf->facture->dir_output : $conf->facture->multidir_output[$object->entity]) . "/" . $objectref; |
||
284 | $file = $dir . "/" . $objectref . ".pdf"; |
||
285 | } |
||
286 | if (!file_exists($dir)) { |
||
287 | if (dol_mkdir($dir) < 0) { |
||
288 | $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir); |
||
289 | return 0; |
||
290 | } |
||
291 | } |
||
292 | |||
293 | if (file_exists($dir)) { |
||
294 | // Add pdfgeneration hook |
||
295 | if (!is_object($hookmanager)) { |
||
296 | $hookmanager = new HookManager($this->db); |
||
297 | } |
||
298 | $hookmanager->initHooks(array('pdfgeneration')); |
||
299 | $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs); |
||
300 | global $action; |
||
301 | $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks |
||
302 | |||
303 | // Set nblines with the new facture lines content after hook |
||
304 | $nblines = count($object->lines); |
||
305 | $nbpayments = count($object->getListOfPayments()); |
||
306 | |||
307 | // Create pdf instance |
||
308 | $pdf = pdf_getInstance($this->format); |
||
309 | $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance |
||
310 | $pdf->SetAutoPageBreak(1, 0); |
||
311 | |||
312 | $heightforinfotot = 50 + (4 * $nbpayments); // Height reserved to output the info and total part and payment part |
||
313 | if ($heightforinfotot > 220) { |
||
314 | $heightforinfotot = 220; |
||
315 | } |
||
316 | $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 |
||
317 | $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin) |
||
318 | if (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS')) { |
||
319 | $heightforfooter += 6; |
||
320 | } |
||
321 | |||
322 | $heightforqrinvoice_firstpage = 0; |
||
323 | if (getDolGlobalString('INVOICE_ADD_SWISS_QR_CODE') == 'bottom') { |
||
324 | $heightforqrinvoice_firstpage = $this->getHeightForQRInvoice(1, $object, $langs); |
||
325 | if ($heightforqrinvoice_firstpage > 0) { |
||
326 | // Shrink infotot to a base 30 |
||
327 | $heightforinfotot = 30 + (4 * $nbpayments); // Height reserved to output the info and total part and payment part |
||
328 | } |
||
329 | } |
||
330 | |||
331 | if (class_exists('TCPDF')) { |
||
332 | $pdf->setPrintHeader(false); |
||
333 | $pdf->setPrintFooter(false); |
||
334 | } |
||
335 | $pdf->SetFont(pdf_getPDFFont($outputlangs)); |
||
336 | |||
337 | // Set path to the background PDF File |
||
338 | if (getDolGlobalString('MAIN_ADD_PDF_BACKGROUND')) { |
||
339 | $logodir = $conf->mycompany->dir_output; |
||
340 | if (!empty($conf->mycompany->multidir_output[$object->entity])) { |
||
341 | $logodir = $conf->mycompany->multidir_output[$object->entity]; |
||
342 | } |
||
343 | $pagecount = $pdf->setSourceFile($logodir . '/' . getDolGlobalString('MAIN_ADD_PDF_BACKGROUND')); |
||
344 | $tplidx = $pdf->importPage(1); |
||
345 | } |
||
346 | |||
347 | $pdf->Open(); |
||
348 | $pagenb = 0; |
||
349 | $pdf->SetDrawColor(128, 128, 128); |
||
350 | |||
351 | $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref)); |
||
352 | $pdf->SetSubject($outputlangs->transnoentities("PdfInvoiceTitle")); |
||
353 | $pdf->SetCreator("Dolibarr " . DOL_VERSION); |
||
354 | $pdf->SetAuthor($mysoc->name . ($user->id > 0 ? ' - ' . $outputlangs->convToOutputCharset($user->getFullName($outputlangs)) : '')); |
||
355 | $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref) . " " . $outputlangs->transnoentities("PdfInvoiceTitle") . " " . $outputlangs->convToOutputCharset($object->thirdparty->name)); |
||
356 | if (getDolGlobalString('MAIN_DISABLE_PDF_COMPRESSION')) { |
||
357 | $pdf->SetCompression(false); |
||
358 | } |
||
359 | |||
360 | // Set certificate |
||
361 | $cert = empty($user->conf->CERTIFICATE_CRT) ? '' : $user->conf->CERTIFICATE_CRT; |
||
362 | $certprivate = empty($user->conf->CERTIFICATE_CRT_PRIVATE) ? '' : $user->conf->CERTIFICATE_CRT_PRIVATE; |
||
363 | // If user has no certificate, we try to take the company one |
||
364 | if (!$cert) { |
||
365 | $cert = !getDolGlobalString('CERTIFICATE_CRT') ? '' : $conf->global->CERTIFICATE_CRT; |
||
366 | } |
||
367 | if (!$certprivate) { |
||
368 | $certprivate = !getDolGlobalString('CERTIFICATE_CRT_PRIVATE') ? '' : $conf->global->CERTIFICATE_CRT_PRIVATE; |
||
369 | } |
||
370 | // If a certificate is found |
||
371 | if ($cert) { |
||
372 | $info = array( |
||
373 | 'Name' => $this->emetteur->name, |
||
374 | 'Location' => getCountry($this->emetteur->country_code, 0), |
||
375 | 'Reason' => 'INVOICE', |
||
376 | 'ContactInfo' => $this->emetteur->email |
||
377 | ); |
||
378 | $pdf->setSignature($cert, $certprivate, $this->emetteur->name, '', 2, $info); |
||
379 | } |
||
380 | |||
381 | // @phan-suppress-next-line PhanPluginSuspiciousParamOrder |
||
382 | $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right |
||
383 | |||
384 | // Set $this->atleastonediscount if you have at least one discount |
||
385 | // and determine category of operation |
||
386 | $categoryOfOperation = 0; |
||
387 | $nbProduct = 0; |
||
388 | $nbService = 0; |
||
389 | for ($i = 0; $i < $nblines; $i++) { |
||
390 | if ($object->lines[$i]->remise_percent) { |
||
391 | $this->atleastonediscount++; |
||
392 | } |
||
393 | |||
394 | // determine category of operation |
||
395 | if ($categoryOfOperation < 2) { |
||
396 | $lineProductType = $object->lines[$i]->product_type; |
||
397 | if ($lineProductType == Product::TYPE_PRODUCT) { |
||
398 | $nbProduct++; |
||
399 | } elseif ($lineProductType == Product::TYPE_SERVICE) { |
||
400 | $nbService++; |
||
401 | } |
||
402 | if ($nbProduct > 0 && $nbService > 0) { |
||
403 | // mixed products and services |
||
404 | $categoryOfOperation = 2; |
||
405 | } |
||
406 | } |
||
407 | } |
||
408 | // determine category of operation |
||
409 | if ($categoryOfOperation <= 0) { |
||
410 | // only services |
||
411 | if ($nbProduct == 0 && $nbService > 0) { |
||
412 | $categoryOfOperation = 1; |
||
413 | } |
||
414 | } |
||
415 | $this->categoryOfOperation = $categoryOfOperation; |
||
416 | if (empty($this->atleastonediscount)) { // retrieve space not used by discount |
||
417 | $delta = ($this->posxprogress - $this->posxdiscount); |
||
418 | $this->posxpicture += $delta; |
||
419 | $this->posxtva += $delta; |
||
420 | $this->posxup += $delta; |
||
421 | $this->posxqty += $delta; |
||
422 | $this->posxunit += $delta; |
||
423 | $this->posxdiscount += $delta; |
||
424 | // post of fields after are not modified, stay at same position |
||
425 | } |
||
426 | |||
427 | $progress_width = 0; |
||
428 | // Situation invoice handling |
||
429 | if ($object->situation_cycle_ref && !getDolGlobalString('MAIN_PDF_HIDE_SITUATION')) { |
||
430 | $this->situationinvoice = true; |
||
431 | $progress_width = 10; |
||
432 | $this->posxpicture -= $progress_width; |
||
433 | $this->posxtva -= $progress_width; |
||
434 | $this->posxup -= $progress_width; |
||
435 | $this->posxqty -= $progress_width; |
||
436 | $this->posxunit -= $progress_width; |
||
437 | $this->posxdiscount -= $progress_width; |
||
438 | $this->posxprogress -= $progress_width; |
||
439 | } |
||
440 | |||
441 | // New page |
||
442 | $pdf->AddPage(); |
||
443 | if (!empty($tplidx)) { |
||
444 | $pdf->useTemplate($tplidx); |
||
445 | } |
||
446 | $pagenb++; |
||
447 | |||
448 | // Output header (logo, ref and address blocks). This is first call for first page. |
||
449 | $top_shift = $this->_pagehead($pdf, $object, 1, $outputlangs); |
||
450 | $pdf->SetFont('', '', $default_font_size - 1); |
||
451 | $pdf->MultiCell(0, 3, ''); // Set interline to 3 |
||
452 | $pdf->SetTextColor(0, 0, 0); |
||
453 | |||
454 | // $pdf->GetY() here can't be used. It is bottom of the second address box but first one may be higher |
||
455 | |||
456 | // $tab_top is y where we must continue content (90 = 42 + 48: 42 is height of logo and ref, 48 is address blocks) |
||
457 | $tab_top = 90 + $top_shift; // top_shift is an addition for linked objects or addons (0 in most cases) |
||
458 | $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10); |
||
459 | |||
460 | // You can add more thing under header here, if you increase $extra_under_address_shift too. |
||
461 | $extra_under_address_shift = 0; |
||
462 | $qrcodestring = ''; |
||
463 | if (getDolGlobalString('INVOICE_ADD_ZATCA_QR_CODE')) { |
||
464 | $qrcodestring = $object->buildZATCAQRString(); |
||
465 | } elseif (getDolGlobalString('INVOICE_ADD_SWISS_QR_CODE') == '1' && (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'VIR')) { |
||
466 | if ($object->fk_account > 0 || $object->fk_bank > 0 || getDolGlobalInt('FACTURE_RIB_NUMBER')) { |
||
467 | $qrcodestring = $object->buildSwitzerlandQRString(); |
||
468 | } |
||
469 | } elseif (getDolGlobalString('INVOICE_ADD_EPC_QR_CODE') == '1' && (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'VIR')) { |
||
470 | if ($object->fk_account > 0 || $object->fk_bank > 0 || getDolGlobalInt('FACTURE_RIB_NUMBER')) { |
||
471 | $qrcodestring = $object->buildEPCQrCodeString(); |
||
472 | } |
||
473 | } |
||
474 | |||
475 | if ($qrcodestring) { |
||
476 | $qrcodecolor = array('25', '25', '25'); |
||
477 | // set style for QR-code |
||
478 | $styleQr = array( |
||
479 | 'border' => false, |
||
480 | 'padding' => 0, |
||
481 | 'fgcolor' => $qrcodecolor, |
||
482 | 'bgcolor' => false, //array(255,255,255) |
||
483 | 'module_width' => 1, // width of a single module in points |
||
484 | 'module_height' => 1 // height of a single module in points |
||
485 | ); |
||
486 | $pdf->write2DBarcode($qrcodestring, 'QRCODE,M', $this->marge_gauche, $tab_top - 5, 25, 25, $styleQr, 'N'); |
||
487 | |||
488 | if (getDolGlobalString('INVOICE_ADD_EPC_QR_CODE') == '1' && (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'VIR')) { |
||
489 | if ($object->fk_account > 0 || $object->fk_bank > 0 || getDolGlobalInt('FACTURE_RIB_NUMBER')) { |
||
490 | $pdf->SetXY($this->marge_gauche + 30, $pdf->GetY() - 15); |
||
491 | $pdf->SetFont('', '', $default_font_size - 4); |
||
492 | $pdf->MultiCell(40, 3, $langs->transnoentitiesnoconv("INVOICE_ADD_EPC_QR_CODEPay"), 0, 'L', 0); |
||
493 | } |
||
494 | } |
||
495 | |||
496 | $extra_under_address_shift += 25; |
||
497 | } |
||
498 | |||
499 | // Call hook printUnderHeaderPDFline |
||
500 | $parameters = array( |
||
501 | 'object' => $object, |
||
502 | 'i' => $i, |
||
503 | 'pdf' => &$pdf, |
||
504 | 'outputlangs' => $outputlangs, |
||
505 | 'hidedetails' => $hidedetails |
||
506 | ); |
||
507 | $reshook = $hookmanager->executeHooks('printUnderHeaderPDFline', $parameters, $this); // Note that $object may have been modified by hook |
||
508 | if (!empty($hookmanager->resArray['extra_under_address_shift'])) { |
||
509 | $extra_under_address_shift += $hookmanager->resArray['extra_under_address_shift']; |
||
510 | } |
||
511 | |||
512 | $tab_top += $extra_under_address_shift; |
||
513 | $tab_top_newpage += 0; |
||
514 | |||
515 | // Incoterm |
||
516 | $height_incoterms = 0; |
||
517 | if (isModEnabled('incoterm')) { |
||
518 | $desc_incoterms = $object->getIncotermsForPDF(); |
||
519 | if ($desc_incoterms) { |
||
520 | $tab_top -= 2; |
||
521 | |||
522 | $pdf->SetFont('', '', $default_font_size - 1); |
||
523 | $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1, dol_htmlentitiesbr($desc_incoterms), 0, 1); |
||
524 | $nexY = $pdf->GetY(); |
||
525 | $height_incoterms = $nexY - $tab_top; |
||
526 | |||
527 | // Rect takes a length in 3rd parameter |
||
528 | $pdf->SetDrawColor(192, 192, 192); |
||
529 | $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_incoterms + 1); |
||
530 | |||
531 | $tab_top = $nexY + 6; |
||
532 | } |
||
533 | } |
||
534 | |||
535 | // Display notes |
||
536 | $notetoshow = empty($object->note_public) ? '' : $object->note_public; |
||
537 | if (getDolGlobalString('MAIN_ADD_SALE_REP_SIGNATURE_IN_NOTE')) { |
||
538 | // Get first sale rep |
||
539 | if (is_object($object->thirdparty)) { |
||
540 | $salereparray = $object->thirdparty->getSalesRepresentatives($user); |
||
541 | $salerepobj = new User($this->db); |
||
542 | $salerepobj->fetch($salereparray[0]['id']); |
||
543 | if (!empty($salerepobj->signature)) { |
||
544 | $notetoshow = dol_concatdesc($notetoshow, $salerepobj->signature); |
||
545 | } |
||
546 | } |
||
547 | } |
||
548 | // Extrafields in note |
||
549 | $extranote = $this->getExtrafieldsInHtml($object, $outputlangs); |
||
550 | if (!empty($extranote)) { |
||
551 | $notetoshow = dol_concatdesc($notetoshow, $extranote); |
||
552 | } |
||
553 | if ($notetoshow) { |
||
554 | $tab_top -= 2; |
||
555 | |||
556 | $substitutionarray = pdf_getSubstitutionArray($outputlangs, null, $object); |
||
557 | complete_substitutions_array($substitutionarray, $outputlangs, $object); |
||
558 | |||
559 | $notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs); |
||
560 | $notetoshow = convertBackOfficeMediasLinksToPublicLinks($notetoshow); |
||
561 | |||
562 | $pdf->SetFont('', '', $default_font_size - 1); |
||
563 | $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1, dol_htmlentitiesbr($notetoshow), 0, 1); |
||
564 | $nexY = $pdf->GetY(); |
||
565 | $height_note = $nexY - $tab_top; |
||
566 | |||
567 | // Rect takes a length in 3rd parameter |
||
568 | $pdf->SetDrawColor(192, 192, 192); |
||
569 | $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1); |
||
570 | |||
571 | $tab_top = $nexY + 6; |
||
572 | } |
||
573 | |||
574 | $iniY = $tab_top + 7; |
||
575 | $curY = $tab_top + 7; |
||
576 | $nexY = $tab_top + 7; |
||
577 | |||
578 | // Loop on each lines |
||
579 | for ($i = 0; $i < $nblines; $i++) { |
||
580 | $curY = $nexY; |
||
581 | $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage |
||
582 | $pdf->SetTextColor(0, 0, 0); |
||
583 | |||
584 | // Define size of image if we need it |
||
585 | $imglinesize = array(); |
||
586 | if (!empty($realpatharray[$i])) { |
||
587 | $imglinesize = pdf_getSizeForImage($realpatharray[$i]); |
||
588 | } |
||
589 | |||
590 | $pdf->setTopMargin($tab_top_newpage); |
||
591 | $page_bottom_margin = $heightforfooter + $heightforfreetext + $heightforinfotot + $this->getHeightForQRInvoice($pdf->getPage(), $object, $langs); |
||
592 | $pdf->setPageOrientation('', 1, $page_bottom_margin); |
||
593 | $pageposbefore = $pdf->getPage(); |
||
594 | |||
595 | $showpricebeforepagebreak = 1; |
||
596 | $posYAfterImage = 0; |
||
597 | $posYAfterDescription = 0; |
||
598 | |||
599 | // We start with Photo of product line |
||
600 | if (isset($imglinesize['width']) && isset($imglinesize['height']) && ($curY + $imglinesize['height']) > ($this->page_hauteur - $page_bottom_margin)) { // If photo too high, we moved completely on new page |
||
601 | $pdf->AddPage('', '', true); |
||
602 | if (!empty($tplidx)) { |
||
603 | $pdf->useTemplate($tplidx); |
||
604 | } |
||
605 | if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) { |
||
606 | $top_shift = $this->_pagehead($pdf, $object, 0, $outputlangs); |
||
607 | $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10); |
||
608 | } |
||
609 | $pdf->setPage($pageposbefore + 1); |
||
610 | |||
611 | $curY = $tab_top_newpage; |
||
612 | |||
613 | // Allows data in the first page if description is long enough to break in multiples pages |
||
614 | if (getDolGlobalString('MAIN_PDF_DATA_ON_FIRST_PAGE')) { |
||
615 | $showpricebeforepagebreak = 1; |
||
616 | } else { |
||
617 | $showpricebeforepagebreak = 0; |
||
618 | } |
||
619 | } |
||
620 | |||
621 | if (isset($imglinesize['width']) && isset($imglinesize['height'])) { |
||
622 | $curX = $this->posxpicture - 1; |
||
623 | $pdf->Image($realpatharray[$i], $curX + (($this->posxtva - $this->posxpicture - $imglinesize['width']) / 2), $curY, $imglinesize['width'], $imglinesize['height'], '', '', '', 2, 300); // Use 300 dpi |
||
624 | // $pdf->Image does not increase value return by getY, so we save it manually |
||
625 | $posYAfterImage = $curY + $imglinesize['height']; |
||
626 | } |
||
627 | |||
628 | // Description of product line |
||
629 | $curX = $this->posxdesc - 1; |
||
630 | |||
631 | $pdf->startTransaction(); |
||
632 | pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxpicture - $curX - $progress_width, 3, $curX, $curY, $hideref, $hidedesc); |
||
633 | $pageposafter = $pdf->getPage(); |
||
634 | if ($pageposafter > $pageposbefore) { // There is a pagebreak |
||
635 | $pdf->rollbackTransaction(true); |
||
636 | $pageposafter = $pageposbefore; |
||
637 | //print $pageposafter.'-'.$pageposbefore;exit; |
||
638 | $pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it. |
||
639 | pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxpicture - $curX - $progress_width, 3, $curX, $curY, $hideref, $hidedesc); |
||
640 | $pageposafter = $pdf->getPage(); |
||
641 | $posyafter = $pdf->GetY(); |
||
642 | //var_dump($posyafter); var_dump(($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))); exit; |
||
643 | if ($posyafter > ($this->page_hauteur - $page_bottom_margin)) { // There is no space left for total+free text |
||
644 | if ($i == ($nblines - 1)) { // No more lines, and no space left to show total, so we create a new page |
||
645 | $pdf->AddPage('', '', true); |
||
646 | if (!empty($tplidx)) { |
||
647 | $pdf->useTemplate($tplidx); |
||
648 | } |
||
649 | if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) { |
||
650 | $top_shift = $this->_pagehead($pdf, $object, 0, $outputlangs); |
||
651 | $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10); |
||
652 | } |
||
653 | $pdf->setPage($pageposafter + 1); |
||
654 | } |
||
655 | } else { |
||
656 | // We found a page break |
||
657 | |||
658 | // Allows data in the first page if description is long enough to break in multiples pages |
||
659 | if (getDolGlobalString('MAIN_PDF_DATA_ON_FIRST_PAGE')) { |
||
660 | $showpricebeforepagebreak = 1; |
||
661 | } else { |
||
662 | $showpricebeforepagebreak = 0; |
||
663 | } |
||
664 | } |
||
665 | } else { // No pagebreak |
||
666 | $pdf->commitTransaction(); |
||
667 | } |
||
668 | $posYAfterDescription = $pdf->GetY(); |
||
669 | |||
670 | $nexY = $pdf->GetY(); |
||
671 | $pageposafter = $pdf->getPage(); |
||
672 | $pdf->setPage($pageposbefore); |
||
673 | $pdf->setTopMargin($this->marge_haute); |
||
674 | $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it. |
||
675 | |||
676 | // We suppose that a too long description or photo were moved completely on next page |
||
677 | if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) { |
||
678 | $pdf->setPage($pageposafter); |
||
679 | $curY = $tab_top_newpage; |
||
680 | } |
||
681 | |||
682 | $pdf->SetFont('', '', $default_font_size - 1); // We reposition the default font |
||
683 | |||
684 | // VAT Rate |
||
685 | if (!getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT') && !getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN')) { |
||
686 | $vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails); |
||
687 | $pdf->SetXY($this->posxtva - 5, $curY); |
||
688 | $pdf->MultiCell($this->posxup - $this->posxtva + 4, 3, $vat_rate, 0, 'R'); |
||
689 | } |
||
690 | |||
691 | // Unit price before discount |
||
692 | $up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails); |
||
693 | $pdf->SetXY($this->posxup, $curY); |
||
694 | $pdf->MultiCell($this->posxqty - $this->posxup - 0.8, 3, $up_excl_tax, 0, 'R', 0); |
||
695 | |||
696 | // Quantity |
||
697 | $qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails); |
||
698 | $pdf->SetXY($this->posxqty, $curY); |
||
699 | $pdf->MultiCell($this->posxunit - $this->posxqty - 0.8, 4, $qty, 0, 'R'); // Enough for 6 chars |
||
700 | |||
701 | // Unit |
||
702 | if (getDolGlobalInt('PRODUCT_USE_UNITS')) { |
||
703 | $unit = pdf_getlineunit($object, $i, $outputlangs, $hidedetails); |
||
704 | $pdf->SetXY($this->posxunit, $curY); |
||
705 | $pdf->MultiCell($this->posxdiscount - $this->posxunit - 0.8, 4, $unit, 0, 'L'); |
||
706 | } |
||
707 | |||
708 | // Discount on line |
||
709 | if ($object->lines[$i]->remise_percent) { |
||
710 | $pdf->SetXY($this->posxdiscount - 2, $curY); |
||
711 | $remise_percent = pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails); |
||
712 | $pdf->MultiCell($this->posxprogress - $this->posxdiscount + 2, 3, $remise_percent, 0, 'R'); |
||
713 | } |
||
714 | |||
715 | // Situation progress |
||
716 | if ($this->situationinvoice) { |
||
717 | $progress = pdf_getlineprogress($object, $i, $outputlangs, $hidedetails); |
||
718 | $pdf->SetXY($this->posxprogress, $curY); |
||
719 | $pdf->MultiCell($this->postotalht - $this->posxprogress + 1, 3, $progress, 0, 'R'); |
||
720 | } |
||
721 | |||
722 | // Total HT line |
||
723 | $total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails); |
||
724 | $pdf->SetXY($this->postotalht, $curY); |
||
725 | $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->postotalht, 3, $total_excl_tax, 0, 'R', 0); |
||
726 | |||
727 | |||
728 | $sign = 1; |
||
729 | if (isset($object->type) && $object->type == 2 && getDolGlobalString('INVOICE_POSITIVE_CREDIT_NOTE')) { |
||
730 | $sign = -1; |
||
731 | } |
||
732 | // Collection of totals by value of VAT in $this->tva["taux"]=total_tva |
||
733 | $prev_progress = $object->lines[$i]->get_prev_progress($object->id); |
||
734 | if ($prev_progress > 0 && !empty($object->lines[$i]->situation_percent)) { // Compute progress from previous situation |
||
735 | if (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) { |
||
736 | $tvaligne = $sign * $object->lines[$i]->multicurrency_total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent; |
||
737 | } else { |
||
738 | $tvaligne = $sign * $object->lines[$i]->total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent; |
||
739 | } |
||
740 | } else { |
||
741 | if (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) { |
||
742 | $tvaligne = $sign * $object->lines[$i]->multicurrency_total_tva; |
||
743 | } else { |
||
744 | $tvaligne = $sign * $object->lines[$i]->total_tva; |
||
745 | } |
||
746 | } |
||
747 | |||
748 | $localtax1ligne = $object->lines[$i]->total_localtax1; |
||
749 | $localtax2ligne = $object->lines[$i]->total_localtax2; |
||
750 | $localtax1_rate = $object->lines[$i]->localtax1_tx; |
||
751 | $localtax2_rate = $object->lines[$i]->localtax2_tx; |
||
752 | $localtax1_type = $object->lines[$i]->localtax1_type; |
||
753 | $localtax2_type = $object->lines[$i]->localtax2_type; |
||
754 | |||
755 | // TODO remise_percent is an obsolete field for object parent |
||
756 | /*if ($object->remise_percent) { |
||
757 | $tvaligne -= ($tvaligne * $object->remise_percent) / 100; |
||
758 | } |
||
759 | if ($object->remise_percent) { |
||
760 | $localtax1ligne -= ($localtax1ligne * $object->remise_percent) / 100; |
||
761 | } |
||
762 | if ($object->remise_percent) { |
||
763 | $localtax2ligne -= ($localtax2ligne * $object->remise_percent) / 100; |
||
764 | }*/ |
||
765 | |||
766 | $vatrate = (string)$object->lines[$i]->tva_tx; |
||
767 | |||
768 | // Retrieve type from database for backward compatibility with old records |
||
769 | if ( |
||
770 | (!isset($localtax1_type) || $localtax1_type == '' || !isset($localtax2_type) || $localtax2_type == '') // if tax type not defined |
||
771 | && (!empty($localtax1_rate) || !empty($localtax2_rate)) |
||
772 | ) { // and there is local tax |
||
773 | $localtaxtmp_array = getLocalTaxesFromRate($vatrate, 0, $object->thirdparty, $mysoc); |
||
774 | $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] : ''; |
||
775 | $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] : ''; |
||
776 | } |
||
777 | |||
778 | // retrieve global local tax |
||
779 | if ($localtax1_type && $localtax1ligne != 0) { |
||
780 | if (empty($this->localtax1[$localtax1_type][$localtax1_rate])) { |
||
781 | $this->localtax1[$localtax1_type][$localtax1_rate] = $localtax1ligne; |
||
782 | } else { |
||
783 | $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne; |
||
784 | } |
||
785 | } |
||
786 | if ($localtax2_type && $localtax2ligne != 0) { |
||
787 | if (empty($this->localtax2[$localtax2_type][$localtax2_rate])) { |
||
788 | $this->localtax2[$localtax2_type][$localtax2_rate] = $localtax2ligne; |
||
789 | } else { |
||
790 | $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne; |
||
791 | } |
||
792 | } |
||
793 | |||
794 | if (($object->lines[$i]->info_bits & 0x01) == 0x01) { |
||
795 | $vatrate .= '*'; |
||
796 | } |
||
797 | |||
798 | // Fill $this->tva and $this->tva_array |
||
799 | if (!isset($this->tva[$vatrate])) { |
||
800 | $this->tva[$vatrate] = 0; |
||
801 | } |
||
802 | $this->tva[$vatrate] += $tvaligne; // ->tva is abandoned, we use now ->tva_array that is more complete |
||
803 | $vatcode = $object->lines[$i]->vat_src_code; |
||
804 | if (empty($this->tva_array[$vatrate . ($vatcode ? ' (' . $vatcode . ')' : '')]['amount'])) { |
||
805 | $this->tva_array[$vatrate . ($vatcode ? ' (' . $vatcode . ')' : '')]['amount'] = 0; |
||
806 | } |
||
807 | $this->tva_array[$vatrate . ($vatcode ? ' (' . $vatcode . ')' : '')] = array('vatrate' => $vatrate, 'vatcode' => $vatcode, 'amount' => $this->tva_array[$vatrate . ($vatcode ? ' (' . $vatcode . ')' : '')]['amount'] + $tvaligne); |
||
808 | |||
809 | if ($posYAfterImage > $posYAfterDescription) { |
||
810 | $nexY = $posYAfterImage; |
||
811 | } |
||
812 | |||
813 | // Add line |
||
814 | if (getDolGlobalString('MAIN_PDF_DASH_BETWEEN_LINES') && $i < ($nblines - 1)) { |
||
815 | $pdf->setPage($pageposafter); |
||
816 | $pdf->SetLineStyle(array('dash' => '1,1', 'color' => array(80, 80, 80))); |
||
817 | //$pdf->SetDrawColor(190,190,200); |
||
818 | $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1); |
||
819 | $pdf->SetLineStyle(array('dash' => 0)); |
||
820 | } |
||
821 | |||
822 | $nexY += 2; // Add space between lines |
||
823 | |||
824 | // Detect if some page were added automatically and output _tableau for past pages |
||
825 | while ($pagenb < $pageposafter) { |
||
826 | $pdf->setPage($pagenb); |
||
827 | if ($pagenb == 1) { |
||
828 | $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter - $heightforqrinvoice_firstpage, 0, $outputlangs, 0, 1, $object->multicurrency_code); |
||
829 | } else { |
||
830 | $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code); |
||
831 | } |
||
832 | $this->_pagefoot($pdf, $object, $outputlangs, 1, $this->getHeightForQRInvoice($pagenb, $object, $langs)); |
||
833 | $pagenb++; |
||
834 | $pdf->setPage($pagenb); |
||
835 | $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it. |
||
836 | if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) { |
||
837 | $top_shift = $this->_pagehead($pdf, $object, 0, $outputlangs); |
||
838 | $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10); |
||
839 | } |
||
840 | if (!empty($tplidx)) { |
||
841 | $pdf->useTemplate($tplidx); |
||
842 | } |
||
843 | } |
||
844 | if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) { |
||
845 | if ($pagenb == 1) { |
||
846 | $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter - $heightforqrinvoice_firstpage, 0, $outputlangs, 0, 1, $object->multicurrency_code); |
||
847 | } else { |
||
848 | $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code); |
||
849 | } |
||
850 | $this->_pagefoot($pdf, $object, $outputlangs, 1, $this->getHeightForQRInvoice($pagenb, $object, $langs)); |
||
851 | // New page |
||
852 | $pdf->AddPage(); |
||
853 | if (!empty($tplidx)) { |
||
854 | $pdf->useTemplate($tplidx); |
||
855 | } |
||
856 | $pagenb++; |
||
857 | if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) { |
||
858 | $top_shift = $this->_pagehead($pdf, $object, 0, $outputlangs); |
||
859 | $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10); |
||
860 | } |
||
861 | } |
||
862 | } |
||
863 | |||
864 | // Show square |
||
865 | if ($pagenb == 1) { |
||
866 | $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter - $heightforqrinvoice_firstpage, 0, $outputlangs, 0, 0, $object->multicurrency_code); |
||
867 | $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter - $heightforqrinvoice_firstpage + 1; |
||
868 | } else { |
||
869 | $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code); |
||
870 | $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1; |
||
871 | } |
||
872 | dol_syslog("bottomlasttab=" . $bottomlasttab . " this->page_hauteur=" . $this->page_hauteur . " heightforinfotot=" . $heightforinfotot . " heightforfreetext=" . $heightforfreetext . " heightforfooter=" . $heightforfooter); |
||
873 | |||
874 | // Display info area |
||
875 | $posy = $this->_tableau_info($pdf, $object, $bottomlasttab, $outputlangs, $outputlangsbis); |
||
876 | |||
877 | // Display total area |
||
878 | $posy = $this->_tableau_tot($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs, $outputlangsbis); |
||
879 | |||
880 | // Display Payments area |
||
881 | if (($deja_regle || $amount_credit_notes_included || $amount_deposits_included) && !getDolGlobalString('INVOICE_NO_PAYMENT_DETAILS')) { |
||
882 | $posy = $this->_tableau_versements($pdf, $object, $posy, $outputlangs, $heightforfooter); |
||
883 | } |
||
884 | |||
885 | // Pagefoot |
||
886 | $this->_pagefoot($pdf, $object, $outputlangs, 0, $this->getHeightForQRInvoice($pdf->getPage(), $object, $langs)); |
||
887 | if (method_exists($pdf, 'AliasNbPages')) { |
||
888 | $pdf->AliasNbPages(); |
||
889 | } |
||
890 | |||
891 | if (getDolGlobalString('INVOICE_ADD_SWISS_QR_CODE') == 'bottom') { |
||
892 | $result = $this->addBottomQRInvoice($pdf, $object, $outputlangs); |
||
893 | if (!$result) { |
||
894 | $pdf->Close(); |
||
895 | return 0; |
||
896 | } |
||
897 | } |
||
898 | $pdf->Close(); |
||
899 | |||
900 | $pdf->Output($file, 'F'); |
||
901 | |||
902 | // Add pdfgeneration hook |
||
903 | $hookmanager->initHooks(array('pdfgeneration')); |
||
904 | $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs); |
||
905 | global $action; |
||
906 | $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
||
907 | if ($reshook < 0) { |
||
908 | $this->error = $hookmanager->error; |
||
909 | $this->errors = $hookmanager->errors; |
||
910 | } |
||
911 | |||
912 | dolChmod($file); |
||
913 | |||
914 | $this->result = array('fullpath' => $file); |
||
915 | |||
916 | return 1; // No error |
||
917 | } else { |
||
918 | $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir); |
||
919 | return 0; |
||
920 | } |
||
921 | } else { |
||
922 | $this->error = $langs->transnoentities("ErrorConstantNotDefined", "FAC_OUTPUTDIR"); |
||
923 | return 0; |
||
924 | } |
||
925 | } |
||
926 | |||
927 | |||
928 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
||
929 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore |
||
930 | /** |
||
931 | * Show payments table |
||
932 | * |
||
933 | * @param TCPDF $pdf Object PDF |
||
934 | * @param Facture $object Object invoice |
||
935 | * @param int $posy Position y in PDF |
||
936 | * @param Translate $outputlangs Object langs for output |
||
937 | * @param int $heightforfooter Height for footer |
||
938 | * @return int Return integer <0 if KO, >0 if OK |
||
939 | */ |
||
940 | protected function _tableau_versements(&$pdf, $object, $posy, $outputlangs, $heightforfooter = 0) |
||
941 | { |
||
942 | // phpcs:enable |
||
943 | global $conf; |
||
944 | |||
945 | $sign = 1; |
||
946 | if ($object->type == 2 && getDolGlobalString('INVOICE_POSITIVE_CREDIT_NOTE')) { |
||
947 | $sign = -1; |
||
948 | } |
||
949 | |||
950 | $current_page = $pdf->getPage(); |
||
951 | $tab3_posx = 120; |
||
952 | $tab3_top = $posy + 8; |
||
953 | $tab3_width = 80; |
||
954 | $tab3_height = 4; |
||
955 | if ($this->page_largeur < 210) { // To work with US executive format |
||
956 | $tab3_posx -= 15; |
||
957 | } |
||
958 | |||
959 | $default_font_size = pdf_getPDFFontSize($outputlangs); |
||
960 | |||
961 | $this->_tableau_versements_header($pdf, $object, $outputlangs, $default_font_size, $tab3_posx, $tab3_top, $tab3_width, $tab3_height); |
||
962 | |||
963 | $y = 0; |
||
964 | |||
965 | $pdf->SetFont('', '', $default_font_size - 4); |
||
966 | |||
967 | |||
968 | // Loop on each discount available (deposits and credit notes and excess of payment included) |
||
969 | $sql = "SELECT re.rowid, re.amount_ht, re.multicurrency_amount_ht, re.amount_tva, re.multicurrency_amount_tva, re.amount_ttc, re.multicurrency_amount_ttc,"; |
||
970 | $sql .= " re.description, re.fk_facture_source,"; |
||
971 | $sql .= " f.type, f.datef"; |
||
972 | $sql .= " FROM " . MAIN_DB_PREFIX . "societe_remise_except as re, " . MAIN_DB_PREFIX . "facture as f"; |
||
973 | $sql .= " WHERE re.fk_facture_source = f.rowid AND re.fk_facture = " . ((int)$object->id); |
||
974 | $resql = $this->db->query($sql); |
||
975 | if ($resql) { |
||
976 | $num = $this->db->num_rows($resql); |
||
977 | $i = 0; |
||
978 | $invoice = new Facture($this->db); |
||
979 | while ($i < $num) { |
||
980 | $y += 3; |
||
981 | if ($tab3_top + $y >= ($this->page_hauteur - $heightforfooter)) { |
||
982 | $y = 0; |
||
983 | $current_page++; |
||
984 | $pdf->AddPage('', '', true); |
||
985 | /*if (!empty($tplidx)) { |
||
986 | $pdf->useTemplate($tplidx); |
||
987 | }*/ |
||
988 | if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) { |
||
989 | $top_shift = $this->_pagehead($pdf, $object, 0, $outputlangs); |
||
990 | $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10); |
||
991 | } |
||
992 | $pdf->setPage($current_page); |
||
993 | $this->_tableau_versements_header($pdf, $object, $outputlangs, $default_font_size, $tab3_posx, $tab3_top + $y - 3, $tab3_width, $tab3_height); |
||
994 | } |
||
995 | |||
996 | $obj = $this->db->fetch_object($resql); |
||
997 | |||
998 | if ($obj->type == 2) { |
||
999 | $text = $outputlangs->transnoentities("CreditNote"); |
||
1000 | } elseif ($obj->type == 3) { |
||
1001 | $text = $outputlangs->transnoentities("Deposit"); |
||
1002 | } elseif ($obj->type == 0) { |
||
1003 | $text = $outputlangs->transnoentities("ExcessReceived"); |
||
1004 | } else { |
||
1005 | $text = $outputlangs->transnoentities("UnknownType"); |
||
1006 | } |
||
1007 | |||
1008 | $invoice->fetch($obj->fk_facture_source); |
||
1009 | |||
1010 | $pdf->SetXY($tab3_posx, $tab3_top + $y); |
||
1011 | $pdf->MultiCell(20, 3, dol_print_date($this->db->jdate($obj->datef), 'day', false, $outputlangs, true), 0, 'L', 0); |
||
1012 | $pdf->SetXY($tab3_posx + 21, $tab3_top + $y); |
||
1013 | $pdf->MultiCell(20, 3, price((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? $obj->multicurrency_amount_ttc : $obj->amount_ttc, 0, $outputlangs), 0, 'L', 0); |
||
1014 | $pdf->SetXY($tab3_posx + 40, $tab3_top + $y); |
||
1015 | $pdf->MultiCell(20, 3, $text, 0, 'L', 0); |
||
1016 | $pdf->SetXY($tab3_posx + 58, $tab3_top + $y); |
||
1017 | $pdf->MultiCell(20, 3, $invoice->ref, 0, 'L', 0); |
||
1018 | |||
1019 | $pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3); |
||
1020 | |||
1021 | $i++; |
||
1022 | } |
||
1023 | } else { |
||
1024 | $this->error = $this->db->lasterror(); |
||
1025 | return -1; |
||
1026 | } |
||
1027 | |||
1028 | // Loop on each payment |
||
1029 | // TODO Call getListOfPaymentsgetListOfPayments instead of hard coded sql |
||
1030 | $sql = "SELECT p.datep as date, p.fk_paiement, p.num_paiement as num, pf.amount as amount, pf.multicurrency_amount,"; |
||
1031 | $sql .= " cp.code"; |
||
1032 | $sql .= " FROM " . MAIN_DB_PREFIX . "paiement_facture as pf, " . MAIN_DB_PREFIX . "paiement as p"; |
||
1033 | $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "c_paiement as cp ON p.fk_paiement = cp.id"; |
||
1034 | $sql .= " WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = " . ((int)$object->id); |
||
1035 | //$sql.= " WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = 1"; |
||
1036 | $sql .= " ORDER BY p.datep"; |
||
1037 | |||
1038 | $resql = $this->db->query($sql); |
||
1039 | if ($resql) { |
||
1040 | $num = $this->db->num_rows($resql); |
||
1041 | $i = 0; |
||
1042 | $y += 3; |
||
1043 | $maxY = $y; |
||
1044 | while ($i < $num) { |
||
1045 | if ($tab3_top + $y >= ($this->page_hauteur - $heightforfooter)) { |
||
1046 | $y = 0; |
||
1047 | $current_page++; |
||
1048 | $pdf->AddPage('', '', true); |
||
1049 | /*if (!empty($tplidx)) { |
||
1050 | $pdf->useTemplate($tplidx); |
||
1051 | }*/ |
||
1052 | if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) { |
||
1053 | $top_shift = $this->_pagehead($pdf, $object, 0, $outputlangs); |
||
1054 | $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10); |
||
1055 | } |
||
1056 | $pdf->setPage($current_page); |
||
1057 | $this->_tableau_versements_header($pdf, $object, $outputlangs, $default_font_size, $tab3_posx, $tab3_top + $y - 3, $tab3_width, $tab3_height); |
||
1058 | } |
||
1059 | |||
1060 | $row = $this->db->fetch_object($resql); |
||
1061 | |||
1062 | $pdf->SetXY($tab3_posx, $tab3_top + $y); |
||
1063 | $pdf->MultiCell(20, 3, dol_print_date($this->db->jdate($row->date), 'day', false, $outputlangs, true), 0, 'L', 0); |
||
1064 | $pdf->SetXY($tab3_posx + 21, $tab3_top + $y); |
||
1065 | $pdf->MultiCell(20, 3, price($sign * ((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? $row->multicurrency_amount : $row->amount), 0, $outputlangs), 0, 'L', 0); |
||
1066 | $pdf->SetXY($tab3_posx + 40, $tab3_top + $y); |
||
1067 | $oper = $outputlangs->transnoentitiesnoconv("PaymentTypeShort" . $row->code); |
||
1068 | |||
1069 | $pdf->MultiCell(20, 3, $oper, 0, 'L', 0); |
||
1070 | $maxY = max($pdf->GetY() - $tab3_top - 3, $maxY); |
||
1071 | $pdf->SetXY($tab3_posx + 58, $tab3_top + $y); |
||
1072 | $pdf->MultiCell(30, 3, $row->num, 0, 'L', 0); |
||
1073 | $y = $maxY = max($pdf->GetY() - $tab3_top - 3, $maxY); |
||
1074 | $pdf->line($tab3_posx, $tab3_top + $y + 3, $tab3_posx + $tab3_width, $tab3_top + $y + 3); |
||
1075 | $y += 3; |
||
1076 | $i++; |
||
1077 | } |
||
1078 | |||
1079 | return $tab3_top + $y + 3; |
||
1080 | } else { |
||
1081 | $this->error = $this->db->lasterror(); |
||
1082 | return -1; |
||
1083 | } |
||
1084 | } |
||
1085 | |||
1086 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
||
1087 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore |
||
1088 | /** |
||
1089 | * Function _tableau_versements_header |
||
1090 | * |
||
1091 | * @param TCPDF $pdf Object PDF |
||
1092 | * @param Facture $object Object invoice |
||
1093 | * @param Translate $outputlangs Object langs for output |
||
1094 | * @param int $default_font_size Font size |
||
1095 | * @param int $tab3_posx pos x |
||
1096 | * @param int $tab3_top pos y |
||
1097 | * @param int $tab3_width width |
||
1098 | * @param int $tab3_height height |
||
1099 | * @return void |
||
1100 | */ |
||
1101 | protected function _tableau_versements_header($pdf, $object, $outputlangs, $default_font_size, $tab3_posx, $tab3_top, $tab3_width, $tab3_height) |
||
1102 | { |
||
1103 | // phpcs:enable |
||
1104 | $title = $outputlangs->transnoentities("PaymentsAlreadyDone"); |
||
1105 | if ($object->type == 2) { |
||
1106 | $title = $outputlangs->transnoentities("PaymentsBackAlreadyDone"); |
||
1107 | } |
||
1108 | |||
1109 | $pdf->SetFont('', '', $default_font_size - 3); |
||
1110 | $pdf->SetXY($tab3_posx, $tab3_top - 4); |
||
1111 | $pdf->MultiCell(60, 3, $title, 0, 'L', 0); |
||
1112 | |||
1113 | $pdf->line($tab3_posx, $tab3_top, $tab3_posx + $tab3_width, $tab3_top); |
||
1114 | |||
1115 | $pdf->SetFont('', '', $default_font_size - 4); |
||
1116 | $pdf->SetXY($tab3_posx, $tab3_top); |
||
1117 | $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Payment"), 0, 'L', 0); |
||
1118 | $pdf->SetXY($tab3_posx + 21, $tab3_top); |
||
1119 | $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Amount"), 0, 'L', 0); |
||
1120 | $pdf->SetXY($tab3_posx + 40, $tab3_top); |
||
1121 | $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Type"), 0, 'L', 0); |
||
1122 | $pdf->SetXY($tab3_posx + 58, $tab3_top); |
||
1123 | $pdf->MultiCell(20, 3, $outputlangs->transnoentities("Num"), 0, 'L', 0); |
||
1124 | |||
1125 | $pdf->line($tab3_posx, $tab3_top - 1 + $tab3_height, $tab3_posx + $tab3_width, $tab3_top - 1 + $tab3_height); |
||
1126 | } |
||
1127 | |||
1128 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
||
1129 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore |
||
1130 | /** |
||
1131 | * Show miscellaneous information (payment mode, payment term, ...) |
||
1132 | * |
||
1133 | * @param TCPDF $pdf Object PDF |
||
1134 | * @param Facture $object Object to show |
||
1135 | * @param int $posy Y |
||
1136 | * @param Translate $outputlangs Langs object |
||
1137 | * @param Translate $outputlangsbis Object lang for output bis |
||
1138 | * @return int Pos y |
||
1139 | */ |
||
1140 | protected function _tableau_info(&$pdf, $object, $posy, $outputlangs, $outputlangsbis) |
||
1141 | { |
||
1142 | // phpcs:enable |
||
1143 | global $conf, $mysoc, $hookmanager; |
||
1144 | |||
1145 | $default_font_size = pdf_getPDFFontSize($outputlangs); |
||
1146 | |||
1147 | $pdf->SetFont('', '', $default_font_size - 1); |
||
1148 | |||
1149 | // If France, show VAT mention if not applicable |
||
1150 | if ($this->emetteur->country_code == 'FR' && empty($mysoc->tva_assuj)) { |
||
1151 | $pdf->SetFont('', 'B', $default_font_size - 2); |
||
1152 | $pdf->SetXY($this->marge_gauche, $posy); |
||
1153 | if ($mysoc->forme_juridique_code == 92) { |
||
1154 | $pdf->MultiCell(100, 3, $outputlangs->transnoentities("VATIsNotUsedForInvoiceAsso"), 0, 'L', 0); |
||
1155 | } else { |
||
1156 | $pdf->MultiCell(100, 3, $outputlangs->transnoentities("VATIsNotUsedForInvoice"), 0, 'L', 0); |
||
1157 | } |
||
1158 | |||
1159 | $posy = $pdf->GetY() + 4; |
||
1160 | } |
||
1161 | |||
1162 | $posxval = 52; |
||
1163 | $posxend = 110; // End of x for text on left side |
||
1164 | if ($this->page_largeur < 210) { // To work with US executive format |
||
1165 | $posxend -= 10; |
||
1166 | } |
||
1167 | |||
1168 | // Show payments conditions |
||
1169 | if ($object->type != 2 && ($object->cond_reglement_code || $object->cond_reglement)) { |
||
1170 | $pdf->SetFont('', 'B', $default_font_size - 2); |
||
1171 | $pdf->SetXY($this->marge_gauche, $posy); |
||
1172 | $titre = $outputlangs->transnoentities("PaymentConditions") . ':'; |
||
1173 | $pdf->MultiCell(43, 4, $titre, 0, 'L'); |
||
1174 | |||
1175 | $pdf->SetFont('', '', $default_font_size - 2); |
||
1176 | $pdf->SetXY($posxval, $posy); |
||
1177 | $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); |
||
1178 | $lib_condition_paiement = str_replace('\n', "\n", $lib_condition_paiement); |
||
1179 | $pdf->MultiCell(67, 4, $lib_condition_paiement, 0, 'L'); |
||
1180 | |||
1181 | $posy = $pdf->GetY() + 3; // We need spaces for 2 lines payment conditions |
||
1182 | } |
||
1183 | |||
1184 | // Show category of operations |
||
1185 | if (getDolGlobalInt('INVOICE_CATEGORY_OF_OPERATION') == 2 && $this->categoryOfOperation >= 0) { |
||
1186 | $pdf->SetFont('', 'B', $default_font_size - 2); |
||
1187 | $pdf->SetXY($this->marge_gauche, $posy); |
||
1188 | $categoryOfOperationTitle = $outputlangs->transnoentities("MentionCategoryOfOperations") . ' : '; |
||
1189 | $pdf->MultiCell($posxval - $this->marge_gauche, 4, $categoryOfOperationTitle, 0, 'L'); |
||
1190 | |||
1191 | $pdf->SetFont('', '', $default_font_size - 2); |
||
1192 | $pdf->SetXY($posxval, $posy); |
||
1193 | $categoryOfOperationLabel = $outputlangs->transnoentities("MentionCategoryOfOperations" . $this->categoryOfOperation); |
||
1194 | $pdf->MultiCell($posxend - $posxval, 4, $categoryOfOperationLabel, 0, 'L'); |
||
1195 | |||
1196 | $posy = $pdf->GetY() + 3; // for 2 lines |
||
1197 | } |
||
1198 | |||
1199 | if ($object->type != 2) { |
||
1200 | // Check a payment mode is defined |
||
1201 | if ( |
||
1202 | empty($object->mode_reglement_code) |
||
1203 | && !getDolGlobalInt('FACTURE_CHQ_NUMBER') |
||
1204 | && !getDolGlobalInt('FACTURE_RIB_NUMBER') |
||
1205 | ) { |
||
1206 | $this->error = $outputlangs->transnoentities("ErrorNoPaiementModeConfigured"); |
||
1207 | } elseif ( |
||
1208 | ($object->mode_reglement_code == 'CHQ' && !getDolGlobalInt('FACTURE_CHQ_NUMBER') && empty($object->fk_account) && empty($object->fk_bank)) |
||
1209 | || ($object->mode_reglement_code == 'VIR' && !getDolGlobalInt('FACTURE_RIB_NUMBER') && empty($object->fk_account) && empty($object->fk_bank)) |
||
1210 | ) { |
||
1211 | // Avoid having any valid PDF with setup that is not complete |
||
1212 | $outputlangs->load("errors"); |
||
1213 | |||
1214 | $pdf->SetXY($this->marge_gauche, $posy); |
||
1215 | $pdf->SetTextColor(200, 0, 0); |
||
1216 | $pdf->SetFont('', 'B', $default_font_size - 2); |
||
1217 | $this->error = $outputlangs->transnoentities("ErrorPaymentModeDefinedToWithoutSetup", $object->mode_reglement_code); |
||
1218 | $pdf->MultiCell(80, 3, $this->error, 0, 'L', 0); |
||
1219 | $pdf->SetTextColor(0, 0, 0); |
||
1220 | |||
1221 | $posy = $pdf->GetY() + 1; |
||
1222 | } |
||
1223 | |||
1224 | // Show payment mode |
||
1225 | if ( |
||
1226 | !empty($object->mode_reglement_code) |
||
1227 | && $object->mode_reglement_code != 'CHQ' |
||
1228 | && $object->mode_reglement_code != 'VIR' |
||
1229 | ) { |
||
1230 | $pdf->SetFont('', 'B', $default_font_size - 2); |
||
1231 | $pdf->SetXY($this->marge_gauche, $posy); |
||
1232 | $titre = $outputlangs->transnoentities("PaymentMode") . ':'; |
||
1233 | $pdf->MultiCell(80, 5, $titre, 0, 'L'); |
||
1234 | |||
1235 | $pdf->SetFont('', '', $default_font_size - 2); |
||
1236 | $pdf->SetXY($posxval, $posy); |
||
1237 | $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); |
||
1238 | //#21654: add account number used for the debit |
||
1239 | if ($object->mode_reglement_code == "PRE") { |
||
1240 | $bac = new CompanyBankAccount($this->db); |
||
1241 | // @phan-suppress-next-line PhanPluginSuspiciousParamPosition |
||
1242 | $bac->fetch(0, '', $object->thirdparty->id); |
||
1243 | $iban = $bac->iban . (($bac->iban && $bac->bic) ? ' / ' : '') . $bac->bic; |
||
1244 | $lib_mode_reg .= ' ' . $outputlangs->trans("PaymentTypePREdetails", dol_trunc($iban, 6, 'right', 'UTF-8', 1)); |
||
1245 | } |
||
1246 | $pdf->MultiCell(80, 5, $lib_mode_reg, 0, 'L'); |
||
1247 | |||
1248 | $posy = $pdf->GetY(); |
||
1249 | } |
||
1250 | |||
1251 | // Show if Option VAT debit option is on also if transmitter is french |
||
1252 | // Decret n°2099-1299 2022-10-07 |
||
1253 | // French mention : "Option pour le paiement de la taxe d'après les débits" |
||
1254 | if ($this->emetteur->country_code == 'FR') { |
||
1255 | if (getDolGlobalInt('TAX_MODE') == 1) { |
||
1256 | $pdf->SetXY($this->marge_gauche, $posy); |
||
1257 | $pdf->writeHTMLCell(80, 5, '', '', $outputlangs->transnoentities("MentionVATDebitOptionIsOn"), 0, 1); |
||
1258 | |||
1259 | $posy = $pdf->GetY() + 1; |
||
1260 | } |
||
1261 | } |
||
1262 | |||
1263 | // Show online payment link |
||
1264 | if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'CB' || $object->mode_reglement_code == 'VAD') { |
||
1265 | $useonlinepayment = 0; |
||
1266 | if (getDolGlobalString('PDF_SHOW_LINK_TO_ONLINE_PAYMENT')) { |
||
1267 | // Show online payment link |
||
1268 | // The list can be complete by the hook 'doValidatePayment' executed inside getValidOnlinePaymentMethods() |
||
1269 | include_once DOL_DOCUMENT_ROOT . '/core/lib/payments.lib.php'; |
||
1270 | $validpaymentmethod = getValidOnlinePaymentMethods(''); |
||
1271 | $useonlinepayment = count($validpaymentmethod); |
||
1272 | } |
||
1273 | |||
1274 | if ($object->statut != Facture::STATUS_DRAFT && $useonlinepayment) { |
||
1275 | require_once constant('DOL_DOCUMENT_ROOT') . '/core/lib/payments.lib.php'; |
||
1276 | global $langs; |
||
1277 | |||
1278 | $langs->loadLangs(array('payment', 'paybox', 'stripe')); |
||
1279 | $servicename = $langs->transnoentities('Online'); |
||
1280 | $paiement_url = getOnlinePaymentUrl('', 'invoice', $object->ref, '', '', ''); |
||
1281 | $linktopay = $langs->trans("ToOfferALinkForOnlinePayment", $servicename) . ' <a href="' . $paiement_url . '">' . $outputlangs->transnoentities("ClickHere") . '</a>'; |
||
1282 | |||
1283 | $pdf->SetXY($this->marge_gauche, $posy); |
||
1284 | $pdf->writeHTMLCell(80, 5, '', '', dol_htmlentitiesbr($linktopay), 0, 1); |
||
1285 | |||
1286 | $posy = $pdf->GetY() + 1; |
||
1287 | } |
||
1288 | } |
||
1289 | |||
1290 | // Show payment mode CHQ |
||
1291 | if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'CHQ') { |
||
1292 | // If payment mode unregulated or payment mode forced to CHQ |
||
1293 | if (getDolGlobalInt('FACTURE_CHQ_NUMBER')) { |
||
1294 | $diffsizetitle = (!getDolGlobalString('PDF_DIFFSIZE_TITLE') ? 3 : $conf->global->PDF_DIFFSIZE_TITLE); |
||
1295 | |||
1296 | if (getDolGlobalInt('FACTURE_CHQ_NUMBER') > 0) { |
||
1297 | $account = new Account($this->db); |
||
1298 | $account->fetch(getDolGlobalInt('FACTURE_CHQ_NUMBER')); |
||
1299 | |||
1300 | $pdf->SetXY($this->marge_gauche, $posy); |
||
1301 | $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle); |
||
1302 | $pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo', $account->owner_name), 0, 'L', 0); |
||
1303 | $posy = $pdf->GetY() + 1; |
||
1304 | |||
1305 | if (!getDolGlobalString('MAIN_PDF_HIDE_CHQ_ADDRESS')) { |
||
1306 | $pdf->SetXY($this->marge_gauche, $posy); |
||
1307 | $pdf->SetFont('', '', $default_font_size - $diffsizetitle); |
||
1308 | $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($account->owner_address), 0, 'L', 0); |
||
1309 | $posy = $pdf->GetY() + 2; |
||
1310 | } |
||
1311 | } |
||
1312 | if ($conf->global->FACTURE_CHQ_NUMBER == -1) { |
||
1313 | $pdf->SetXY($this->marge_gauche, $posy); |
||
1314 | $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle); |
||
1315 | $pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo', $this->emetteur->name), 0, 'L', 0); |
||
1316 | $posy = $pdf->GetY() + 1; |
||
1317 | |||
1318 | if (!getDolGlobalString('MAIN_PDF_HIDE_CHQ_ADDRESS')) { |
||
1319 | $pdf->SetXY($this->marge_gauche, $posy); |
||
1320 | $pdf->SetFont('', '', $default_font_size - $diffsizetitle); |
||
1321 | $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0, 'L', 0); |
||
1322 | $posy = $pdf->GetY() + 2; |
||
1323 | } |
||
1324 | } |
||
1325 | } |
||
1326 | } |
||
1327 | |||
1328 | // If payment mode not forced or forced to VIR, show payment with BAN |
||
1329 | if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'VIR') { |
||
1330 | if ($object->fk_account > 0 || $object->fk_bank > 0 || getDolGlobalInt('FACTURE_RIB_NUMBER')) { |
||
1331 | $bankid = ($object->fk_account <= 0 ? $conf->global->FACTURE_RIB_NUMBER : $object->fk_account); |
||
1332 | if ($object->fk_bank > 0) { |
||
1333 | $bankid = $object->fk_bank; // For backward compatibility when object->fk_account is forced with object->fk_bank |
||
1334 | } |
||
1335 | $account = new Account($this->db); |
||
1336 | $account->fetch($bankid); |
||
1337 | |||
1338 | $curx = $this->marge_gauche; |
||
1339 | $cury = $posy; |
||
1340 | |||
1341 | $posy = pdf_bank($pdf, $outputlangs, $curx, $cury, $account, 0, $default_font_size); |
||
1342 | |||
1343 | $posy += 2; |
||
1344 | } |
||
1345 | } |
||
1346 | } |
||
1347 | |||
1348 | return $posy; |
||
1349 | } |
||
1350 | |||
1351 | |||
1352 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
||
1353 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore |
||
1354 | /** |
||
1355 | * Show total to pay |
||
1356 | * |
||
1357 | * @param TCPDF $pdf Object PDF |
||
1358 | * @param Facture $object Object invoice |
||
1359 | * @param int $deja_regle Amount already paid (in the currency of invoice) |
||
1360 | * @param int $posy Position depart |
||
1361 | * @param Translate $outputlangs Object langs |
||
1362 | * @param Translate $outputlangsbis Object lang for output bis |
||
1363 | * @return int Position pour suite |
||
1364 | */ |
||
1365 | protected function _tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs, $outputlangsbis) |
||
1696 | } |
||
1697 | |||
1698 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore |
||
1699 | |||
1700 | /** |
||
1701 | * Show table for lines |
||
1702 | * |
||
1703 | * @param TCPDF $pdf Object PDF |
||
1704 | * @param float|int $tab_top Top position of table |
||
1705 | * @param float|int $tab_height Height of table (rectangle) |
||
1706 | * @param int $nexY Y (not used) |
||
1707 | * @param Translate $outputlangs Langs object |
||
1708 | * @param int $hidetop 1=Hide top bar of array and title, 0=Hide nothing, -1=Hide only title |
||
1709 | * @param int $hidebottom Hide bottom bar of array |
||
1710 | * @param string $currency Currency code |
||
1711 | * @return void |
||
1712 | */ |
||
1713 | protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency = '') |
||
1817 | } |
||
1818 | } |
||
1819 | |||
1820 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore |
||
1821 | |||
1822 | /** |
||
1823 | * Show top header of page. |
||
1824 | * |
||
1825 | * @param TCPDF $pdf Object PDF |
||
1826 | * @param Facture $object Object to show |
||
1827 | * @param int $showaddress 0=no, 1=yes |
||
1828 | * @param Translate $outputlangs Object lang for output |
||
1829 | * @param Translate $outputlangsbis Object lang for output bis |
||
1830 | * @return float|int Return topshift value |
||
1831 | */ |
||
1832 | protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $outputlangsbis = null) |
||
2210 | } |
||
2211 | |||
2212 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore |
||
2213 | |||
2214 | /** |
||
2215 | * Show footer of page. Need this->emetteur object |
||
2216 | * |
||
2217 | * @param TCPDF $pdf PDF |
||
2218 | * @param Facture $object Object to show |
||
2219 | * @param Translate $outputlangs Object lang for output |
||
2220 | * @param int $hidefreetext 1=Hide free text |
||
2221 | * @param int $heightforqrinvoice Height for QR invoices |
||
2222 | * @return int Return height of bottom margin including footer text |
||
2223 | */ |
||
2224 | protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0, $heightforqrinvoice = 0) |
||
2231 |