Total Complexity | 55 |
Total Lines | 620 |
Duplicated Lines | 0 % |
Changes | 0 |
Complex classes like pdf_timespent 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_timespent, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
44 | class pdf_timespent extends ModelePDFProjects |
||
45 | { |
||
46 | /** |
||
47 | * @var DoliDB Database handler |
||
48 | */ |
||
49 | public $db; |
||
50 | |||
51 | /** |
||
52 | * @var string model name |
||
53 | */ |
||
54 | public $name; |
||
55 | |||
56 | /** |
||
57 | * @var string model description (short text) |
||
58 | */ |
||
59 | public $description; |
||
60 | |||
61 | /** |
||
62 | * @var int Save the name of generated file as the main doc when generating a doc with this template |
||
63 | */ |
||
64 | public $update_main_doc_field; |
||
65 | |||
66 | /** |
||
67 | * @var string document type |
||
68 | */ |
||
69 | public $type; |
||
70 | |||
71 | /** |
||
72 | * @var int |
||
73 | */ |
||
74 | public $posxuser; |
||
75 | |||
76 | /** |
||
77 | * Dolibarr version of the loaded document |
||
78 | * @var string |
||
79 | */ |
||
80 | public $version = 'dolibarr'; |
||
81 | |||
82 | |||
83 | /** |
||
84 | * Constructor |
||
85 | * |
||
86 | * @param DoliDB $db Database handler |
||
87 | */ |
||
88 | public function __construct($db) |
||
134 | //$this->posxdateend -= 20; |
||
135 | } |
||
136 | } |
||
137 | |||
138 | |||
139 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
||
140 | |||
141 | /** |
||
142 | * Function to build pdf project onto disk |
||
143 | * |
||
144 | * @param Project $object Object project a generer |
||
145 | * @param Translate $outputlangs Lang output object |
||
146 | * @return int 1 if OK, <=0 if KO |
||
147 | */ |
||
148 | public function write_file($object, $outputlangs) |
||
149 | { |
||
150 | // phpcs:enable |
||
151 | global $conf, $hookmanager, $langs, $user; |
||
152 | |||
153 | if (!is_object($outputlangs)) { |
||
154 | $outputlangs = $langs; |
||
155 | } |
||
156 | // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO |
||
157 | if (getDolGlobalString('MAIN_USE_FPDF')) { |
||
158 | $outputlangs->charset_output = 'ISO-8859-1'; |
||
159 | } |
||
160 | |||
161 | // Load traductions files required by page |
||
162 | $outputlangs->loadLangs(array("main", "dict", "companies", "projects")); |
||
163 | |||
164 | if ($conf->project->multidir_output[$object->entity]) { |
||
165 | //$nblines = count($object->lines); // This is set later with array of tasks |
||
166 | |||
167 | $objectref = dol_sanitizeFileName($object->ref); |
||
168 | $dir = $conf->project->multidir_output[$object->entity]; |
||
169 | if (!preg_match('/specimen/i', $objectref)) { |
||
170 | $dir .= "/" . $objectref; |
||
171 | } |
||
172 | $file = $dir . "/" . $objectref . ".pdf"; |
||
173 | |||
174 | if (!file_exists($dir)) { |
||
175 | if (dol_mkdir($dir) < 0) { |
||
176 | $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir); |
||
177 | return 0; |
||
178 | } |
||
179 | } |
||
180 | |||
181 | if (file_exists($dir)) { |
||
182 | // Add pdfgeneration hook |
||
183 | if (!is_object($hookmanager)) { |
||
184 | $hookmanager = new HookManager($this->db); |
||
185 | } |
||
186 | $hookmanager->initHooks(array('pdfgeneration')); |
||
187 | $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs); |
||
188 | global $action; |
||
189 | $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks |
||
190 | |||
191 | // Create pdf instance |
||
192 | $pdf = pdf_getInstance($this->format); |
||
193 | $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance |
||
194 | $pdf->SetAutoPageBreak(1, 0); |
||
195 | |||
196 | $heightforinfotot = 40; // Height reserved to output the info and total part |
||
197 | $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 |
||
198 | $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin) |
||
199 | if (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS')) { |
||
200 | $heightforfooter += 6; |
||
201 | } |
||
202 | |||
203 | if (class_exists('TCPDF')) { |
||
204 | $pdf->setPrintHeader(false); |
||
205 | $pdf->setPrintFooter(false); |
||
206 | } |
||
207 | $pdf->SetFont(pdf_getPDFFont($outputlangs)); |
||
208 | // Set path to the background PDF File |
||
209 | if (getDolGlobalString('MAIN_ADD_PDF_BACKGROUND')) { |
||
210 | $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output . '/' . getDolGlobalString('MAIN_ADD_PDF_BACKGROUND')); |
||
211 | $tplidx = $pdf->importPage(1); |
||
212 | } |
||
213 | |||
214 | // Complete object by loading several other information |
||
215 | $task = new Task($this->db); |
||
216 | $tasksarray = $task->getTasksArray(0, 0, $object->id); |
||
217 | |||
218 | if (!$object->id > 0) { // Special case when used with object = specimen, we may return all lines |
||
219 | $tasksarray = array_slice($tasksarray, 0, min(5, count($tasksarray))); |
||
220 | } |
||
221 | |||
222 | $object->lines = $tasksarray; |
||
223 | $nblines = count($object->lines); |
||
224 | |||
225 | $pdf->Open(); |
||
226 | $pagenb = 0; |
||
227 | $pdf->SetDrawColor(128, 128, 128); |
||
228 | |||
229 | $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref)); |
||
230 | $pdf->SetSubject($outputlangs->transnoentities("Project")); |
||
231 | $pdf->SetCreator("Dolibarr " . DOL_VERSION); |
||
232 | $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs))); |
||
233 | $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref) . " " . $outputlangs->transnoentities("Project")); |
||
234 | if (getDolGlobalString('MAIN_DISABLE_PDF_COMPRESSION')) { |
||
235 | $pdf->SetCompression(false); |
||
236 | } |
||
237 | |||
238 | // @phan-suppress-next-line PhanPluginSuspiciousParamOrder |
||
239 | $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right |
||
240 | |||
241 | // New page |
||
242 | $pdf->AddPage(); |
||
243 | if (!empty($tplidx)) { |
||
244 | $pdf->useTemplate($tplidx); |
||
245 | } |
||
246 | $pagenb++; |
||
247 | $this->_pagehead($pdf, $object, 1, $outputlangs); |
||
248 | $pdf->SetFont('', '', $default_font_size - 1); |
||
249 | $pdf->MultiCell(0, 3, ''); // Set interline to 3 |
||
250 | $pdf->SetTextColor(0, 0, 0); |
||
251 | |||
252 | $tab_top = 50; |
||
253 | $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 : 10); |
||
254 | |||
255 | $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext; |
||
256 | |||
257 | // Show public note |
||
258 | $notetoshow = empty($object->note_public) ? '' : $object->note_public; |
||
259 | if ($notetoshow) { |
||
260 | $substitutionarray = pdf_getSubstitutionArray($outputlangs, null, $object); |
||
261 | complete_substitutions_array($substitutionarray, $outputlangs, $object); |
||
262 | $notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs); |
||
263 | $notetoshow = convertBackOfficeMediasLinksToPublicLinks($notetoshow); |
||
264 | |||
265 | $tab_top -= 2; |
||
266 | |||
267 | $pdf->SetFont('', '', $default_font_size - 1); |
||
268 | $pdf->writeHTMLCell(190, 3, $this->posxref - 1, $tab_top - 2, dol_htmlentitiesbr($notetoshow), 0, 1); |
||
269 | $nexY = $pdf->GetY(); |
||
270 | $height_note = $nexY - $tab_top; |
||
271 | |||
272 | // Rect takes a length in 3rd parameter |
||
273 | $pdf->SetDrawColor(192, 192, 192); |
||
274 | $pdf->Rect($this->marge_gauche, $tab_top - 2, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 2); |
||
275 | |||
276 | $tab_height = $tab_height - $height_note; |
||
277 | $tab_top = $nexY + 6; |
||
278 | } else { |
||
279 | $height_note = 0; |
||
280 | } |
||
281 | |||
282 | $heightoftitleline = 10; |
||
283 | $iniY = $tab_top + $heightoftitleline + 1; |
||
284 | $curY = $tab_top + $heightoftitleline + 1; |
||
285 | $nexY = $tab_top + $heightoftitleline + 1; |
||
286 | |||
287 | $tmpuser = new User($this->db); |
||
288 | |||
289 | // TODO We should loop on record of times spent grouped by user instead of lines of tasks |
||
290 | |||
291 | // Loop on each lines |
||
292 | for ($i = 0; $i < $nblines; $i++) { |
||
293 | $curY = $nexY; |
||
294 | $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage |
||
295 | $pdf->SetTextColor(0, 0, 0); |
||
296 | |||
297 | $pdf->setTopMargin($tab_top_newpage); |
||
298 | $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext + $heightforinfotot); // The only function to edit the bottom margin of current page to set it. |
||
299 | $pageposbefore = $pdf->getPage(); |
||
300 | |||
301 | // Description of line |
||
302 | $ref = $object->lines[$i]->ref; |
||
303 | $libelleline = $object->lines[$i]->label; |
||
304 | //$progress=($object->lines[$i]->progress?$object->lines[$i]->progress.'%':''); |
||
305 | $datestart = dol_print_date($object->lines[$i]->date_start, 'day'); |
||
306 | $dateend = dol_print_date($object->lines[$i]->date_end, 'day'); |
||
307 | $duration = convertSecondToTime((int)$object->lines[$i]->duration, 'allhourmin'); |
||
308 | |||
309 | $showpricebeforepagebreak = 1; |
||
310 | |||
311 | $pdf->startTransaction(); |
||
312 | // Label |
||
313 | $pdf->SetXY($this->posxlabel, $curY); |
||
314 | $pdf->MultiCell($this->posxtimespent - $this->posxlabel, 3, $outputlangs->convToOutputCharset($libelleline), 0, 'L'); |
||
315 | $pageposafter = $pdf->getPage(); |
||
316 | if ($pageposafter > $pageposbefore) { // There is a pagebreak |
||
317 | $pdf->rollbackTransaction(true); |
||
318 | $pageposafter = $pageposbefore; |
||
319 | //print $pageposafter.'-'.$pageposbefore;exit; |
||
320 | $pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it. |
||
321 | // Label |
||
322 | $pdf->SetXY($this->posxlabel, $curY); |
||
323 | $posybefore = $pdf->GetY(); |
||
324 | $pdf->MultiCell($this->posxtimespent - $this->posxlabel, 3, $outputlangs->convToOutputCharset($libelleline), 0, 'L'); |
||
325 | $pageposafter = $pdf->getPage(); |
||
326 | $posyafter = $pdf->GetY(); |
||
327 | if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) { // There is no space left for total+free text |
||
328 | if ($i == ($nblines - 1)) { // No more lines, and no space left to show total, so we create a new page |
||
329 | $pdf->AddPage('', '', true); |
||
330 | if (!empty($tplidx)) { |
||
331 | $pdf->useTemplate($tplidx); |
||
332 | } |
||
333 | if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) { |
||
334 | $this->_pagehead($pdf, $object, 0, $outputlangs); |
||
335 | } |
||
336 | $pdf->setPage($pageposafter + 1); |
||
337 | } |
||
338 | } else { |
||
339 | // We found a page break |
||
340 | |||
341 | // Allows data in the first page if description is long enough to break in multiples pages |
||
342 | if (getDolGlobalString('MAIN_PDF_DATA_ON_FIRST_PAGE')) { |
||
343 | $showpricebeforepagebreak = 1; |
||
344 | } else { |
||
345 | $showpricebeforepagebreak = 0; |
||
346 | } |
||
347 | |||
348 | $forcedesconsamepage = 1; |
||
349 | if ($forcedesconsamepage) { |
||
350 | $pdf->rollbackTransaction(true); |
||
351 | $pageposafter = $pageposbefore; |
||
352 | $pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it. |
||
353 | |||
354 | $pdf->AddPage('', '', true); |
||
355 | if (!empty($tplidx)) { |
||
356 | $pdf->useTemplate($tplidx); |
||
357 | } |
||
358 | if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) { |
||
359 | $this->_pagehead($pdf, $object, 0, $outputlangs); |
||
360 | } |
||
361 | $pdf->setPage($pageposafter + 1); |
||
362 | $pdf->SetFont('', '', $default_font_size - 1); // On repositionne la police par default |
||
363 | $pdf->MultiCell(0, 3, ''); // Set interline to 3 |
||
364 | $pdf->SetTextColor(0, 0, 0); |
||
365 | |||
366 | $pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it. |
||
367 | $curY = $tab_top_newpage + $heightoftitleline + 1; |
||
368 | |||
369 | // Label |
||
370 | $pdf->SetXY($this->posxlabel, $curY); |
||
371 | $posybefore = $pdf->GetY(); |
||
372 | $pdf->MultiCell($this->posxtimespent - $this->posxlabel, 3, $outputlangs->convToOutputCharset($libelleline), 0, 'L'); |
||
373 | $pageposafter = $pdf->getPage(); |
||
374 | $posyafter = $pdf->GetY(); |
||
375 | } |
||
376 | } |
||
377 | //var_dump($i.' '.$posybefore.' '.$posyafter.' '.($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot)).' '.$showpricebeforepagebreak); |
||
378 | } else { // No pagebreak |
||
379 | $pdf->commitTransaction(); |
||
380 | } |
||
381 | $posYAfterDescription = $pdf->GetY(); |
||
382 | |||
383 | $nexY = $pdf->GetY(); |
||
384 | $pageposafter = $pdf->getPage(); |
||
385 | $pdf->setPage($pageposbefore); |
||
386 | $pdf->setTopMargin($this->marge_haute); |
||
387 | $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it. |
||
388 | |||
389 | // We suppose that a too long description is moved completely on next page |
||
390 | if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) { |
||
391 | //var_dump($pageposbefore.'-'.$pageposafter.'-'.$showpricebeforepagebreak); |
||
392 | $pdf->setPage($pageposafter); |
||
393 | $curY = $tab_top_newpage + $heightoftitleline + 1; |
||
394 | } |
||
395 | |||
396 | $pdf->SetFont('', '', $default_font_size - 1); // We reposition the default font |
||
397 | |||
398 | // Ref of task |
||
399 | $pdf->SetXY($this->posxref, $curY); |
||
400 | $pdf->MultiCell($this->posxlabel - $this->posxref, 3, $outputlangs->convToOutputCharset($ref), 0, 'L'); |
||
401 | // timespent |
||
402 | $pdf->SetXY($this->posxtimespent, $curY); |
||
403 | $pdf->MultiCell($this->posxuser - $this->posxtimespent, 3, $duration ? $duration : '', 0, 'R'); |
||
404 | // Progress |
||
405 | //$pdf->SetXY($this->posxprogress, $curY); |
||
406 | //$pdf->MultiCell($this->posxuser-$this->posxprogress, 3, $progress, 0, 'R'); |
||
407 | |||
408 | // User spending time |
||
409 | /*var_dump($object->lines[$i]);exit; |
||
410 | $tmpuser->fetch($object->lines[$i]->fk_user); |
||
411 | $pdf->SetXY($this->posxuser, $curY); |
||
412 | $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxuser, 3, $tmpuser->getFullName($outputlangs, 0, -1, 20), 0, 'C'); |
||
413 | */ |
||
414 | |||
415 | // Add line |
||
416 | if (getDolGlobalString('MAIN_PDF_DASH_BETWEEN_LINES') && $i < ($nblines - 1)) { |
||
417 | $pdf->setPage($pageposafter); |
||
418 | $pdf->SetLineStyle(array('dash' => '1,1', 'color' => array(80, 80, 80))); |
||
419 | //$pdf->SetDrawColor(190,190,200); |
||
420 | $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1); |
||
421 | $pdf->SetLineStyle(array('dash' => 0)); |
||
422 | } |
||
423 | |||
424 | $nexY += 2; // Add space between lines |
||
425 | |||
426 | // Detect if some page were added automatically and output _tableau for past pages |
||
427 | while ($pagenb < $pageposafter) { |
||
428 | $pdf->setPage($pagenb); |
||
429 | if ($pagenb == 1) { |
||
430 | $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1); |
||
431 | } else { |
||
432 | $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1); |
||
433 | } |
||
434 | $this->_pagefoot($pdf, $object, $outputlangs, 1); |
||
435 | $pagenb++; |
||
436 | $pdf->setPage($pagenb); |
||
437 | $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it. |
||
438 | if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) { |
||
439 | $this->_pagehead($pdf, $object, 0, $outputlangs); |
||
440 | } |
||
441 | if (!empty($tplidx)) { |
||
442 | $pdf->useTemplate($tplidx); |
||
443 | } |
||
444 | } |
||
445 | if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) { |
||
446 | if ($pagenb == 1) { |
||
447 | $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1); |
||
448 | } else { |
||
449 | $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1); |
||
450 | } |
||
451 | $this->_pagefoot($pdf, $object, $outputlangs, 1); |
||
452 | // New page |
||
453 | $pdf->AddPage(); |
||
454 | if (!empty($tplidx)) { |
||
455 | $pdf->useTemplate($tplidx); |
||
456 | } |
||
457 | $pagenb++; |
||
458 | if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) { |
||
459 | $this->_pagehead($pdf, $object, 0, $outputlangs); |
||
460 | } |
||
461 | } |
||
462 | } |
||
463 | |||
464 | // Show square |
||
465 | if ($pagenb == 1) { |
||
466 | $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0); |
||
467 | } else { |
||
468 | $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0); |
||
469 | } |
||
470 | $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1; |
||
471 | |||
472 | // Footer of the page |
||
473 | $this->_pagefoot($pdf, $object, $outputlangs); |
||
474 | if (method_exists($pdf, 'AliasNbPages')) { |
||
475 | $pdf->AliasNbPages(); |
||
476 | } |
||
477 | |||
478 | $pdf->Close(); |
||
479 | |||
480 | $pdf->Output($file, 'F'); |
||
481 | |||
482 | // Add pdfgeneration hook |
||
483 | $hookmanager->initHooks(array('pdfgeneration')); |
||
484 | $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs); |
||
485 | global $action; |
||
486 | $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
||
487 | if ($reshook < 0) { |
||
488 | $this->error = $hookmanager->error; |
||
489 | $this->errors = $hookmanager->errors; |
||
490 | } |
||
491 | |||
492 | dolChmod($file); |
||
493 | |||
494 | $this->result = array('fullpath' => $file); |
||
495 | |||
496 | return 1; // No error |
||
497 | } else { |
||
498 | $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir); |
||
499 | return 0; |
||
500 | } |
||
501 | } else { |
||
502 | $this->error = $langs->transnoentities("ErrorConstantNotDefined", "PROJECT_OUTPUTDIR"); |
||
503 | return 0; |
||
504 | } |
||
505 | } |
||
506 | |||
507 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore |
||
508 | |||
509 | /** |
||
510 | * Show table for lines |
||
511 | * |
||
512 | * @param TCPDF $pdf Object PDF |
||
513 | * @param float|int $tab_top Top position of table |
||
514 | * @param float|int $tab_height Height of table (rectangle) |
||
515 | * @param int $nexY Y |
||
516 | * @param Translate $outputlangs Langs object |
||
517 | * @param int $hidetop Hide top bar of array |
||
518 | * @param int $hidebottom Hide bottom bar of array |
||
519 | * @return void |
||
520 | */ |
||
521 | protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0) |
||
554 | } |
||
555 | |||
556 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore |
||
557 | |||
558 | /** |
||
559 | * Show top header of page. |
||
560 | * |
||
561 | * @param TCPDF $pdf Object PDF |
||
562 | * @param Project $object Object to show |
||
563 | * @param int $showaddress 0=no, 1=yes |
||
564 | * @param Translate $outputlangs Object lang for output |
||
565 | * @return float|int Return topshift value |
||
566 | */ |
||
567 | protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs) |
||
568 | { |
||
569 | global $langs, $conf, $mysoc; |
||
570 | |||
571 | $default_font_size = pdf_getPDFFontSize($outputlangs); |
||
572 | |||
573 | pdf_pagehead($pdf, $outputlangs, $this->page_hauteur); |
||
574 | |||
575 | $pdf->SetTextColor(0, 0, 60); |
||
576 | $pdf->SetFont('', 'B', $default_font_size + 3); |
||
577 | |||
578 | $posx = $this->page_largeur - $this->marge_droite - 100; |
||
579 | $posy = $this->marge_haute; |
||
580 | |||
581 | $pdf->SetXY($this->marge_gauche, $posy); |
||
582 | |||
583 | // Logo |
||
584 | $logo = $conf->mycompany->dir_output . '/logos/' . $mysoc->logo; |
||
585 | if ($mysoc->logo) { |
||
586 | if (is_readable($logo)) { |
||
587 | $height = pdf_getHeightForLogo($logo); |
||
588 | $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto) |
||
589 | } else { |
||
590 | $pdf->SetTextColor(200, 0, 0); |
||
591 | $pdf->SetFont('', 'B', $default_font_size - 2); |
||
592 | $pdf->MultiCell(100, 3, $langs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L'); |
||
593 | $pdf->MultiCell(100, 3, $langs->transnoentities("ErrorGoToModuleSetup"), 0, 'L'); |
||
594 | } |
||
595 | } else { |
||
596 | $pdf->MultiCell(100, 4, $outputlangs->transnoentities($this->emetteur->name), 0, 'L'); |
||
597 | } |
||
598 | |||
599 | $pdf->SetFont('', 'B', $default_font_size + 3); |
||
600 | $pdf->SetXY($posx, $posy); |
||
601 | $pdf->SetTextColor(0, 0, 60); |
||
602 | $pdf->MultiCell(100, 4, $outputlangs->transnoentities("Project") . " " . $outputlangs->convToOutputCharset($object->ref), '', 'R'); |
||
603 | $pdf->SetFont('', '', $default_font_size + 2); |
||
604 | |||
605 | $posy += 6; |
||
606 | $pdf->SetXY($posx, $posy); |
||
607 | $pdf->SetTextColor(0, 0, 60); |
||
608 | $pdf->MultiCell(100, 4, $outputlangs->transnoentities("DateStart") . " : " . dol_print_date($object->date_start, 'day', false, $outputlangs, true), '', 'R'); |
||
609 | |||
610 | $posy += 6; |
||
611 | $pdf->SetXY($posx, $posy); |
||
612 | $pdf->MultiCell(100, 4, $outputlangs->transnoentities("DateEnd") . " : " . dol_print_date($object->date_end, 'day', false, $outputlangs, true), '', 'R'); |
||
613 | |||
614 | if (is_object($object->thirdparty)) { |
||
615 | $posy += 6; |
||
616 | $pdf->SetXY($posx, $posy); |
||
617 | $pdf->MultiCell(100, 4, $outputlangs->transnoentities("ThirdParty") . " : " . $object->thirdparty->getFullName($outputlangs), '', 'R'); |
||
618 | } |
||
619 | |||
620 | $pdf->SetTextColor(0, 0, 60); |
||
621 | |||
622 | // Add list of linked objects |
||
623 | /* Removed: A project can have more than thousands linked objects (orders, invoices, proposals, etc.... |
||
624 | $object->fetchObjectLinked(); |
||
625 | |||
626 | foreach($object->linkedObjects as $objecttype => $objects) |
||
627 | { |
||
628 | //var_dump($objects);exit; |
||
629 | if ($objecttype == 'commande') |
||
630 | { |
||
631 | $outputlangs->load('orders'); |
||
632 | $num=count($objects); |
||
633 | for ($i=0;$i<$num;$i++) |
||
634 | { |
||
635 | $posy+=4; |
||
636 | $pdf->SetXY($posx,$posy); |
||
637 | $pdf->SetFont('','', $default_font_size - 1); |
||
638 | $text=$objects[$i]->ref; |
||
639 | if ($objects[$i]->ref_client) $text.=' ('.$objects[$i]->ref_client.')'; |
||
640 | $pdf->MultiCell(100, 4, $outputlangs->transnoentities("RefOrder")." : ".$outputlangs->transnoentities($text), '', 'R'); |
||
641 | } |
||
642 | } |
||
643 | } |
||
644 | */ |
||
645 | |||
646 | return 0; |
||
647 | } |
||
648 | |||
649 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore |
||
650 | |||
651 | /** |
||
652 | * Show footer of page. Need this->emetteur object |
||
653 | * |
||
654 | * @param TCPDF $pdf PDF |
||
655 | * @param Project $object Object to show |
||
656 | * @param Translate $outputlangs Object lang for output |
||
657 | * @param int $hidefreetext 1=Hide free text |
||
658 | * @return integer |
||
659 | */ |
||
660 | protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0) |
||
664 | } |
||
665 | } |
||
666 |