--- /tmp/dsg/dolibarr/htdocs/core/modules/project/doc/github_doc_generic_project_odt.modules.php +++ /tmp/dsg/dolibarr/htdocs/core/modules/project/doc/client_doc_generic_project_odt.modules.php @@ -61,15 +61,15 @@ public $emetteur; /** - * @var array Minimum version of PHP required by module. - * e.g.: PHP ≥ 5.6 = array(5, 6) - */ - public $phpmin = array(5, 6); - - /** - * Dolibarr version of the loaded document - * @var string - */ + * @var array Minimum version of PHP required by module. + * e.g.: PHP ≥ 5.5 = array(5, 5) + */ + public $phpmin = array(5, 5); + + /** + * Dolibarr version of the loaded document + * @var string + */ public $version = 'dolibarr'; @@ -117,33 +117,33 @@ } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Define array with couple substitution key => substitution value * * @param Project $object Main object to use as data source * @param Translate $outputlangs Lang object to use for output - * @param string $array_key Name of the key for return array + * @param string $array_key Name of the key for return array * @return array Array of substitution */ public function get_substitutionarray_object($object, $outputlangs, $array_key = 'object') { - // phpcs:enable + // phpcs:enable global $conf; $resarray = array( - $array_key.'_id'=>$object->id, - $array_key.'_ref'=>$object->ref, - $array_key.'_title'=>$object->title, - $array_key.'_description'=>$object->description, - $array_key.'_date_creation'=>dol_print_date($object->date_c, 'day'), - $array_key.'_date_modification'=>dol_print_date($object->date_m, 'day'), - $array_key.'_date_start'=>dol_print_date($object->date_start, 'day'), - $array_key.'_date_end'=>dol_print_date($object->date_end, 'day'), - $array_key.'_note_private'=>$object->note_private, - $array_key.'_note_public'=>$object->note_public, - $array_key.'_public'=>$object->public, - $array_key.'_statut'=>$object->getLibStatut() + $array_key.'_id'=>$object->id, + $array_key.'_ref'=>$object->ref, + $array_key.'_title'=>$object->title, + $array_key.'_description'=>$object->description, + $array_key.'_date_creation'=>dol_print_date($object->date_c, 'day'), + $array_key.'_date_modification'=>dol_print_date($object->date_m, 'day'), + $array_key.'_date_start'=>dol_print_date($object->date_start, 'day'), + $array_key.'_date_end'=>dol_print_date($object->date_end, 'day'), + $array_key.'_note_private'=>$object->note_private, + $array_key.'_note_public'=>$object->note_public, + $array_key.'_public'=>$object->public, + $array_key.'_statut'=>$object->getLibStatut() ); require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; @@ -156,7 +156,7 @@ return $resarray; } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Define array with couple substitution key => substitution value * @@ -166,7 +166,7 @@ */ public function get_substitutionarray_tasks(Task $task, $outputlangs) { - // phpcs:enable + // phpcs:enable global $conf; $resarray = array( @@ -197,7 +197,7 @@ return $resarray; } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Define array with couple substitution key => substitution value * @@ -207,7 +207,7 @@ */ public function get_substitutionarray_project_contacts($contact, $outputlangs) { - // phpcs:enable + // phpcs:enable global $conf; $pc = 'projcontacts_'; // prefix to avoid typos @@ -255,7 +255,7 @@ return $ret; } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Define array with couple substitution key => substitution value * @@ -263,19 +263,19 @@ * @param Translate $outputlangs Lang object to use for output * @return array Return a substitution array */ - public function get_substitutionarray_project_file($file, $outputlangs) - { - // phpcs:enable - global $conf; - - return array( - 'projfile_name'=>$file['name'], - 'projfile_date'=>dol_print_date($file['date'], 'day'), - 'projfile_size'=>$file['size'] - ); - } - - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + public function get_substitutionarray_project_file($file, $outputlangs) + { + // phpcs:enable + global $conf; + + return array( + 'projfile_name'=>$file['name'], + 'projfile_date'=>dol_print_date($file['date'], 'day'), + 'projfile_size'=>$file['size'] + ); + } + + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Define array with couple substitution key => substitution value * @@ -283,23 +283,23 @@ * @param Translate $outputlangs Lang object to use for output * @return array Return a substitution array */ - public function get_substitutionarray_project_reference($refdetail, $outputlangs) - { - // phpcs:enable - global $conf; - - return array( - 'projref_type'=>$refdetail['type'], - 'projref_ref'=>$refdetail['ref'], - 'projref_date'=>dol_print_date($refdetail['date'], 'day'), - 'projref_socname'=>$refdetail['socname'], - 'projref_amountht'=>price($refdetail['amountht'], 0, $outputlangs), - 'projref_amountttc'=>price($refdetail['amountttc'], 0, $outputlangs), - 'projref_status'=>$refdetail['status'] - ); - } - - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + public function get_substitutionarray_project_reference($refdetail, $outputlangs) + { + // phpcs:enable + global $conf; + + return array( + 'projref_type'=>$refdetail['type'], + 'projref_ref'=>$refdetail['ref'], + 'projref_date'=>dol_print_date($refdetail['date'], 'day'), + 'projref_socname'=>$refdetail['socname'], + 'projref_amountht'=>price($refdetail['amountht'], 0, $outputlangs), + 'projref_amountttc'=>price($refdetail['amountttc'], 0, $outputlangs), + 'projref_status'=>$refdetail['status'] + ); + } + + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Define array with couple substitution key => substitution value * @@ -309,7 +309,7 @@ */ public function get_substitutionarray_tasksressource($taskressource, $outputlangs) { - // phpcs:enable + // phpcs:enable global $conf; //dol_syslog(get_class($this).'::get_substitutionarray_tasksressource taskressource='.var_export($taskressource,true),LOG_DEBUG); return array( @@ -323,7 +323,7 @@ ); } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Define array with couple substitution key => substitution value * @@ -333,7 +333,7 @@ */ public function get_substitutionarray_taskstime($tasktime, $outputlangs) { - // phpcs:enable + // phpcs:enable global $conf; return array( @@ -352,7 +352,7 @@ ); } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Define array with couple substitution key => substitution value * @@ -362,7 +362,7 @@ */ public function get_substitutionarray_task_file($file, $outputlangs) { - // phpcs:enable + // phpcs:enable global $conf; return array( @@ -384,7 +384,7 @@ global $conf, $langs; // Load translation files required by the page - $langs->loadLangs(array("companies", "errors")); + $langs->loadLangs(array("companies", "errors")); $form = new Form($this->db); @@ -408,7 +408,8 @@ unset($listofdir[$key]); continue; } if (!is_dir($tmpdir)) $texttitle .= img_warning($langs->trans("ErrorDirNotFound", $tmpdir), 0); - else { + else + { $tmpfiles = dol_dir_list($tmpdir, 'files', 0, '\.(ods|odt)'); if (count($tmpfiles)) $listoffiles = array_merge($listoffiles, $tmpfiles); } @@ -440,10 +441,10 @@ if ($nbofiles) { - $texte .= '
'; - // Show list of found files - foreach ($listoffiles as $file) { - $texte .= '- '.$file['name'].' '.img_picto('', 'listlight').'
'; + $texte .= ''; } @@ -461,7 +462,7 @@ return $texte; } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Function to build a document on disk using the generic odt module. * @@ -472,7 +473,7 @@ */ public function write_file($object, $outputlangs, $srctemplatepath) { - // phpcs:enable + // phpcs:enable global $user, $langs, $conf, $mysoc, $hookmanager; if (empty($srctemplatepath)) @@ -511,8 +512,6 @@ return -1; } } - - $object->fetch_thirdparty(); $dir = $conf->projet->dir_output; $objectref = dol_sanitizeFileName($object->ref); @@ -541,10 +540,12 @@ $newfileformat = substr($newfile, strrpos($newfile, '.') + 1); if (!empty($conf->global->MAIN_DOC_USE_TIMING)) { - $format = $conf->global->MAIN_DOC_USE_TIMING; - if ($format == '1') $format = '%Y%m%d%H%M%S'; + $format = $conf->global->MAIN_DOC_USE_TIMING; + if ($format == '1') $format = '%Y%m%d%H%M%S'; $filename = $newfiletmp.'-'.dol_print_date(dol_now(), $format).'.'.$newfileformat; - } else { + } + else + { $filename = $newfiletmp.'.'.$newfileformat; } $file = $dir.'/'.$filename; @@ -568,8 +569,8 @@ $contactobject = null; if (!empty($usecontact)) { - // if we have a PROJECTLEADER contact and we dont use it as recipient we store the contact object for later use - $contactobject = $object->contact; + // if we have a PROJECTLEADER contact and we dont use it as recipient we store the contact object for later use + $contactobject = $object->contact; } $socobject = $object->thirdparty; @@ -587,7 +588,7 @@ // Open and load template require_once ODTPHP_PATH.'odf.php'; try { - $odfHandler = new odf( + $odfHandler = new odf( $srctemplatepath, array( 'PATH_TO_TMP' => $conf->projet->dir_temp, @@ -634,18 +635,21 @@ { if (file_exists($value)) $odfHandler->setImage($key, $value); else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8'); - } else // Text + } + else // Text { $odfHandler->setVars($key, $value, true, 'UTF-8'); } - } catch (OdfException $e) + } + catch (OdfException $e) { - dol_syslog($e->getMessage(), LOG_INFO); + dol_syslog($e->getMessage(), LOG_INFO); } } // Replace tags of lines for tasks - try { + try + { $listlines = $odfHandler->setSegment('tasks'); $taskstatic = new Task($this->db); @@ -663,12 +667,15 @@ //complete_substitutions_array($tmparray, $outputlangs, $object, $task, "completesubstitutionarray_lines"); foreach ($tmparray as $key => $val) { - try { + try + { $listlines->setVars($key, $val, true, 'UTF-8'); - } catch (OdfException $e) + } + catch (OdfException $e) { dol_syslog($e->getMessage(), LOG_INFO); - } catch (SegmentException $e) + } + catch (SegmentException $e) { dol_syslog($e->getMessage(), LOG_INFO); } @@ -711,12 +718,15 @@ foreach ($tmparray as $key => $val) { - try { + try + { $listlinestaskres->setVars($key, $val, true, 'UTF-8'); - } catch (OdfException $e) + } + catch (OdfException $e) { dol_syslog($e->getMessage(), LOG_INFO); - } catch (SegmentException $e) + } + catch (SegmentException $e) { dol_syslog($e->getMessage(), LOG_INFO); } @@ -758,12 +768,15 @@ $tmparray = $this->get_substitutionarray_taskstime($row, $outputlangs); foreach ($tmparray as $key => $val) { - try { + try + { $listlinestasktime->setVars($key, $val, true, 'UTF-8'); - } catch (OdfException $e) + } + catch (OdfException $e) { dol_syslog($e->getMessage(), LOG_INFO); - } catch (SegmentException $e) + } + catch (SegmentException $e) { dol_syslog($e->getMessage(), LOG_INFO); } @@ -795,12 +808,15 @@ foreach ($tmparray as $key => $val) { - try { + try + { $listlinestasktime->setVars($key, $val, true, 'UTF-8'); - } catch (OdfException $e) + } + catch (OdfException $e) { dol_syslog($e->getMessage(), LOG_INFO); - } catch (SegmentException $e) + } + catch (SegmentException $e) { dol_syslog($e->getMessage(), LOG_INFO); } @@ -825,12 +841,15 @@ //dol_syslog(get_class($this).'::main $tmparray'.var_export($tmparray,true)); foreach ($tmparray as $key => $val) { - try { + try + { $listtasksfiles->setVars($key, $val, true, 'UTF-8'); - } catch (OdfException $e) + } + catch (OdfException $e) { dol_syslog($e->getMessage(), LOG_INFO); - } catch (SegmentException $e) + } + catch (SegmentException $e) { dol_syslog($e->getMessage(), LOG_INFO); } @@ -840,7 +859,8 @@ $listlines->merge(); } $odfHandler->mergeSegment($listlines); - } catch (OdfException $e) + } + catch (OdfException $e) { $ExceptionTrace = $e->getTrace(); // no segment defined on ODT is not an error @@ -853,7 +873,8 @@ } // Replace tags of project files - try { + try + { $listlines = $odfHandler->setSegment('projectfiles'); $upload_dir = $conf->projet->dir_output.'/'.dol_sanitizeFileName($object->ref); @@ -866,12 +887,15 @@ foreach ($tmparray as $key => $val) { - try { + try + { $listlines->setVars($key, $val, true, 'UTF-8'); - } catch (OdfException $e) + } + catch (OdfException $e) { dol_syslog($e->getMessage(), LOG_INFO); - } catch (SegmentException $e) + } + catch (SegmentException $e) { dol_syslog($e->getMessage(), LOG_INFO); } @@ -879,7 +903,8 @@ $listlines->merge(); } $odfHandler->mergeSegment($listlines); - } catch (OdfException $e) + } + catch (OdfException $e) { $this->error = $e->getMessage(); dol_syslog($this->error, LOG_WARNING); @@ -898,7 +923,8 @@ } if ((is_array($contact_arrray) && count($contact_arrray) > 0)) { - try { + try + { $listlines = $odfHandler->setSegment('projectcontacts'); foreach ($contact_arrray as $contact) @@ -920,20 +946,24 @@ $tmparray = $this->get_substitutionarray_project_contacts($contact, $outputlangs); foreach ($tmparray as $key => $val) { - try { + try + { $listlines->setVars($key, $val, true, 'UTF-8'); - } catch (OdfException $e) - { - dol_syslog($e->getMessage(), LOG_INFO); - } catch (SegmentException $e) + } + catch (OdfException $e) { dol_syslog($e->getMessage(), LOG_INFO); } + catch (SegmentException $e) + { + dol_syslog($e->getMessage(), LOG_INFO); + } } $listlines->merge(); } $odfHandler->mergeSegment($listlines); - } catch (OdfException $e) + } + catch (OdfException $e) { $this->error = $e->getMessage(); dol_syslog($this->error, LOG_WARNING); @@ -1054,7 +1084,8 @@ ); //Insert reference - try { + try + { $listlines = $odfHandler->setSegment('projectrefs'); foreach ($listofreferent as $keyref => $valueref) @@ -1116,12 +1147,15 @@ foreach ($tmparray as $key => $val) { - try { + try + { $listlines->setVars($key, $val, true, 'UTF-8'); - } catch (OdfException $e) + } + catch (OdfException $e) { dol_syslog($e->getMessage(), LOG_INFO); - } catch (SegmentException $e) + } + catch (SegmentException $e) { dol_syslog($e->getMessage(), LOG_INFO); } @@ -1145,7 +1179,7 @@ try { $odfHandler->setVars($key, $value, true, 'UTF-8'); } catch (OdfException $e) { - dol_syslog($e->getMessage(), LOG_INFO); + dol_syslog($e->getMessage(), LOG_INFO); } } @@ -1167,7 +1201,7 @@ $odfHandler->saveToDisk($file); } catch (Exception $e) { $this->error = $e->getMessage(); - dol_syslog($e->getMessage(), LOG_INFO); + dol_syslog($e->getMessage(), LOG_INFO); return -1; } } @@ -1182,7 +1216,9 @@ $this->result = array('fullpath'=>$file); return 1; // Success - } else { + } + else + { $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir); return -1; } --- /tmp/dsg/dolibarr/htdocs/core/modules/project/doc/github_pdf_baleine.modules.php +++ /tmp/dsg/dolibarr/htdocs/core/modules/project/doc/client_pdf_baleine.modules.php @@ -39,20 +39,75 @@ class pdf_baleine extends ModelePDFProjects { /** - * @var array Minimum version of PHP required by module. - * e.g.: PHP ≥ 5.6 = array(5, 6) - */ - public $phpmin = array(5, 6); - - /** - * Dolibarr version of the loaded document - * @var string - */ + * @var DoliDb Database handler + */ + public $db; + + /** + * @var string model name + */ + public $name; + + /** + * @var string model description (short text) + */ + public $description; + + /** + * @var string document type + */ + public $type; + + /** + * @var array Minimum version of PHP required by module. + * e.g.: PHP ≥ 5.5 = array(5, 5) + */ + public $phpmin = array(5, 5); + + /** + * Dolibarr version of the loaded document + * @var string + */ public $version = 'dolibarr'; /** + * @var int page_largeur + */ + public $page_largeur; + + /** + * @var int page_hauteur + */ + public $page_hauteur; + + /** + * @var array format + */ + public $format; + + /** + * @var int marge_gauche + */ + public $marge_gauche; + + /** + * @var int marge_droite + */ + public $marge_droite; + + /** + * @var int marge_haute + */ + public $marge_haute; + + /** + * @var int marge_basse + */ + public $marge_basse; + + /** * Issuer - * @var Societe Object that emits + * @var Company object that emits */ public $emetteur; @@ -94,10 +149,10 @@ // Define position of columns $this->posxref = $this->marge_gauche + 1; $this->posxlabel = $this->marge_gauche + 25; - $this->posxworkload = $this->marge_gauche + 117; - $this->posxprogress = $this->marge_gauche + 137; - $this->posxdatestart = $this->marge_gauche + 147; - $this->posxdateend = $this->marge_gauche + 169; + $this->posxworkload = $this->marge_gauche + 120; + $this->posxprogress = $this->marge_gauche + 140; + $this->posxdatestart = $this->marge_gauche + 152; + $this->posxdateend = $this->marge_gauche + 170; if ($this->page_largeur < 210) // To work with US executive format { $this->posxref -= 20; @@ -110,7 +165,7 @@ } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Function to build pdf project onto disk * @@ -120,7 +175,7 @@ */ public function write_file($object, $outputlangs) { - // phpcs:enable + // phpcs:enable global $conf, $hookmanager, $langs, $user; if (!is_object($outputlangs)) $outputlangs = $langs; @@ -167,22 +222,22 @@ $pdf->SetAutoPageBreak(1, 0); $heightforinfotot = 40; // 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; - - if (class_exists('TCPDF')) - { - $pdf->setPrintHeader(false); - $pdf->setPrintFooter(false); - } - $pdf->SetFont(pdf_getPDFFont($outputlangs)); - // Set path to the background PDF File - if (!empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) - { - $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND); - $tplidx = $pdf->importPage(1); - } + $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; + + if (class_exists('TCPDF')) + { + $pdf->setPrintHeader(false); + $pdf->setPrintFooter(false); + } + $pdf->SetFont(pdf_getPDFFont($outputlangs)); + // Set path to the background PDF File + if (!empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) + { + $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND); + $tplidx = $pdf->importPage(1); + } // Complete object by loading several other informations $task = new Task($this->db); @@ -245,7 +300,9 @@ $tab_height = $tab_height - $height_note; $tab_top = $nexY + 6; - } else { + } + else + { $height_note = 0; } @@ -301,13 +358,16 @@ if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs); $pdf->setPage($pageposafter + 1); } - } else { + } + else + { // We found a page break // Allows data in the first page if description is long enough to break in multiples pages if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) $showpricebeforepagebreak = 1; - else $showpricebeforepagebreak = 0; + else + $showpricebeforepagebreak = 0; $forcedesconsamepage = 1; if ($forcedesconsamepage) @@ -336,7 +396,8 @@ } } //var_dump($i.' '.$posybefore.' '.$posyafter.' '.($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot)).' '.$showpricebeforepagebreak); - } else // No pagebreak + } + else // No pagebreak { $pdf->commitTransaction(); } @@ -365,8 +426,7 @@ // Progress $pdf->SetXY($this->posxprogress, $curY); $pdf->MultiCell($this->posxdatestart - $this->posxprogress, 3, $progress, 0, 'R'); - - // Date start and end + // Date $pdf->SetXY($this->posxdatestart, $curY); $pdf->MultiCell($this->posxdateend - $this->posxdatestart, 3, $datestart, 0, 'C'); $pdf->SetXY($this->posxdateend, $curY); @@ -391,7 +451,9 @@ if ($pagenb == 1) { $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1); - } else { + } + else + { $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1); } $this->_pagefoot($pdf, $object, $outputlangs, 1); @@ -405,7 +467,9 @@ if ($pagenb == 1) { $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1); - } else { + } + else + { $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1); } $this->_pagefoot($pdf, $object, $outputlangs, 1); @@ -420,7 +484,8 @@ // Show square if ($pagenb == 1) $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0); - else $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0); + else + $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0); $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1; // Footer of the page @@ -438,8 +503,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)) @@ -448,11 +513,15 @@ $this->result = array('fullpath'=>$file); return 1; // No error - } else { + } + else + { $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir); return 0; } - } else { + } + else + { $this->error = $langs->transnoentities("ErrorConstantNotDefined", "PROJECT_OUTPUTDIR"); return 0; } @@ -462,7 +531,7 @@ /** * Show table for lines * - * @param TCPDF $pdf Object PDF + * @param PDF $pdf Object PDF * @param string $tab_top Top position of table * @param string $tab_height Height of table (rectangle) * @param int $nexY Y @@ -484,7 +553,7 @@ // Draw rect of all tab (title + lines). Rect takes a length in 3rd parameter $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $tab_height); - // Line takes a position y in 3rd parameter + // line takes a position y in 3rd parameter $pdf->line($this->marge_gauche, $tab_top + $heightoftitleline, $this->page_largeur - $this->marge_droite, $tab_top + $heightoftitleline); $pdf->SetTextColor(0, 0, 0); @@ -502,20 +571,18 @@ $pdf->SetXY($this->posxprogress, $tab_top + 1); $pdf->MultiCell($this->posxdatestart - $this->posxprogress, 3, '%', 0, 'R'); - // Date start $pdf->SetXY($this->posxdatestart, $tab_top + 1); - $pdf->MultiCell($this->posxdateend - $this->posxdatestart, 3, $outputlangs->trans("Start"), 0, 'C'); - - // Date end + $pdf->MultiCell($this->posxdateend - $this->posxdatestart, 3, '', 0, 'C'); + $pdf->SetXY($this->posxdateend, $tab_top + 1); - $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxdateend, 3, $outputlangs->trans("End"), 0, 'C'); + $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxdatestart, 3, '', 0, 'C'); } // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore /** * Show top header of page. * - * @param TCPDF $pdf Object PDF + * @param PDF $pdf Object PDF * @param Project $object Object to show * @param int $showaddress 0=no, 1=yes * @param Translate $outputlangs Object lang for output @@ -532,7 +599,7 @@ $pdf->SetTextColor(0, 0, 60); $pdf->SetFont('', 'B', $default_font_size + 3); - $posx = $this->page_largeur - $this->marge_droite - 100; + $posx = $this->page_largeur - $this->marge_droite - 100; $posy = $this->marge_haute; $pdf->SetXY($this->marge_gauche, $posy); @@ -543,15 +610,18 @@ { if (is_readable($logo)) { - $height = pdf_getHeightForLogo($logo); - $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto) - } else { + $height = pdf_getHeightForLogo($logo); + $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto) + } + else + { $pdf->SetTextColor(200, 0, 0); $pdf->SetFont('', 'B', $default_font_size - 2); $pdf->MultiCell(100, 3, $langs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L'); $pdf->MultiCell(100, 3, $langs->transnoentities("ErrorGoToModuleSetup"), 0, 'L'); } - } else $pdf->MultiCell(100, 4, $outputlangs->transnoentities($this->emetteur->name), 0, 'L'); + } + else $pdf->MultiCell(100, 4, $outputlangs->transnoentities($this->emetteur->name), 0, 'L'); $pdf->SetFont('', 'B', $default_font_size + 3); $pdf->SetXY($posx, $posy); @@ -605,8 +675,8 @@ // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore /** * Show footer of page. Need this->emetteur object - * - * @param TCPDF $pdf PDF + * + * @param PDF $pdf PDF * @param Project $object Object to show * @param Translate $outputlangs Object lang for output * @param int $hidefreetext 1=Hide free text @@ -615,7 +685,7 @@ 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; + $showdetails = $conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS; return pdf_pagefoot($pdf, $outputlangs, 'PROJECT_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext); } } --- /tmp/dsg/dolibarr/htdocs/core/modules/project/doc/github_pdf_beluga.modules.php +++ /tmp/dsg/dolibarr/htdocs/core/modules/project/doc/client_pdf_beluga.modules.php @@ -54,11 +54,11 @@ class pdf_beluga extends ModelePDFProjects { - /** - * Page orientation - * @var string 'P' or 'Portait' (default), 'L' or 'Landscape' - */ - private $orientation = ''; + /** + * Page orientation + * @var string 'P' or 'Portait' (default), 'L' or 'Landscape' + */ + private $orientation = ''; /** * Issuer @@ -85,14 +85,14 @@ // Page size for A4 format $this->type = 'pdf'; $formatarray = pdf_getFormat(); - $this->orientation = 'L'; - if ($this->orientation == 'L' || $this->orientation == 'Landscape') { - $this->page_largeur = $formatarray['height']; - $this->page_hauteur = $formatarray['width']; - } else { - $this->page_largeur = $formatarray['width']; - $this->page_hauteur = $formatarray['height']; - } + $this->orientation = 'L'; + if ($this->orientation == 'L' || $this->orientation == 'Landscape') { + $this->page_largeur = $formatarray['height']; + $this->page_hauteur = $formatarray['width']; + } else { + $this->page_largeur = $formatarray['width']; + $this->page_hauteur = $formatarray['height']; + } $this->format = array($this->page_largeur, $this->page_hauteur); $this->marge_gauche = isset($conf->global->MAIN_PDF_MARGIN_LEFT) ? $conf->global->MAIN_PDF_MARGIN_LEFT : 10; $this->marge_droite = isset($conf->global->MAIN_PDF_MARGIN_RIGHT) ? $conf->global->MAIN_PDF_MARGIN_RIGHT : 10; @@ -107,22 +107,22 @@ $this->emetteur = $mysoc; if (!$this->emetteur->country_code) $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default if not defined - // Define position of columns - if ($this->orientation == 'L' || $this->orientation == 'Landscape') { - $this->posxref = $this->marge_gauche + 1; - $this->posxdate = $this->marge_gauche + 105; - $this->posxsociety = $this->marge_gauche + 126; - $this->posxamountht = $this->marge_gauche + 190; - $this->posxamountttc = $this->marge_gauche + 215; - $this->posxstatut = $this->marge_gauche + 245; - } else { - $this->posxref = $this->marge_gauche + 1; - $this->posxdate = $this->marge_gauche + 25; - $this->posxsociety = $this->marge_gauche + 46; - $this->posxamountht = $this->marge_gauche + 110; - $this->posxamountttc = $this->marge_gauche + 135; - $this->posxstatut = $this->marge_gauche + 165; - } + // Define position of columns + if ($this->orientation == 'L' || $this->orientation == 'Landscape') { + $this->posxref = $this->marge_gauche + 1; + $this->posxdate = $this->marge_gauche + 105; + $this->posxsociety = $this->marge_gauche + 125; + $this->posxamountht = $this->marge_gauche + 190; + $this->posxamountttc = $this->marge_gauche + 215; + $this->posxstatut = $this->marge_gauche + 245; + } else { + $this->posxref = $this->marge_gauche + 1; + $this->posxdate = $this->marge_gauche + 25; + $this->posxsociety = $this->marge_gauche + 45; + $this->posxamountht = $this->marge_gauche + 110; + $this->posxamountttc = $this->marge_gauche + 135; + $this->posxstatut = $this->marge_gauche + 165; + } if ($this->page_largeur < 210) // To work with US executive format { $this->posxref -= 20; @@ -135,7 +135,7 @@ } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Fonction generant le projet sur le disque * @@ -145,10 +145,10 @@ */ public function write_file($object, $outputlangs) { - // phpcs:enable + // phpcs:enable global $conf, $hookmanager, $langs, $user; - $formproject = new FormProjets($this->db); + $formproject = new FormProjets($this->db); 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 @@ -194,22 +194,22 @@ $pdf->SetAutoPageBreak(1, 0); $heightforinfotot = 40; // 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; - - if (class_exists('TCPDF')) - { - $pdf->setPrintHeader(false); - $pdf->setPrintFooter(false); - } - $pdf->SetFont(pdf_getPDFFont($outputlangs)); - // Set path to the background PDF File - if (!empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) - { - $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND); - $tplidx = $pdf->importPage(1); - } + $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; + + if (class_exists('TCPDF')) + { + $pdf->setPrintHeader(false); + $pdf->setPrintFooter(false); + } + $pdf->SetFont(pdf_getPDFFont($outputlangs)); + // Set path to the background PDF File + if (!empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) + { + $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND); + $tplidx = $pdf->importPage(1); + } // Complete object by loading several other informations $task = new Task($this->db); @@ -273,7 +273,9 @@ $tab_height = $tab_height - $height_note; $tab_top = $nexY + 6; - } else { + } + else + { $height_note = 0; } @@ -282,363 +284,371 @@ $curY = $tab_top + $heightoftitleline + 1; $nexY = $tab_top + $heightoftitleline + 1; - $listofreferent = array( - 'propal'=>array( - 'name'=>"Proposals", - 'title'=>"ListProposalsAssociatedProject", - 'class'=>'Propal', - 'table'=>'propal', - 'datefieldname'=>'datep', - 'test'=>$conf->propal->enabled && $user->rights->propale->lire, - 'lang'=>'propal'), - 'order'=>array( - 'name'=>"CustomersOrders", - 'title'=>"ListOrdersAssociatedProject", - 'class'=>'Commande', - 'table'=>'commande', - 'datefieldname'=>'date_commande', - 'test'=>$conf->commande->enabled && $user->rights->commande->lire, - 'lang'=>'orders'), - 'invoice'=>array( - 'name'=>"CustomersInvoices", - 'title'=>"ListInvoicesAssociatedProject", - 'class'=>'Facture', - 'margin'=>'add', - 'table'=>'facture', - 'datefieldname'=>'datef', - 'test'=>$conf->facture->enabled && $user->rights->facture->lire, - 'lang'=>'bills'), - 'invoice_predefined'=>array( - 'name'=>"PredefinedInvoices", - 'title'=>"ListPredefinedInvoicesAssociatedProject", - 'class'=>'FactureRec', - 'table'=>'facture_rec', - 'datefieldname'=>'datec', - 'test'=>$conf->facture->enabled && $user->rights->facture->lire, - 'lang'=>'bills'), - 'order_supplier'=>array( - 'name'=>"SuppliersOrders", - 'title'=>"ListSupplierOrdersAssociatedProject", - 'class'=>'CommandeFournisseur', - 'table'=>'commande_fournisseur', - 'datefieldname'=>'date_commande', - 'test'=>$conf->fournisseur->enabled && $user->rights->fournisseur->commande->lire, - 'lang'=>'orders'), - 'invoice_supplier'=>array( - 'name'=>"BillsSuppliers", - 'title'=>"ListSupplierInvoicesAssociatedProject", - 'class'=>'FactureFournisseur', - 'margin'=>'minus', - 'table'=>'facture_fourn', - 'datefieldname'=>'datef', - 'test'=>$conf->fournisseur->enabled && $user->rights->fournisseur->facture->lire, - 'lang'=>'bills'), - 'contract'=>array( - 'name'=>"Contracts", - 'title'=>"ListContractAssociatedProject", - 'class'=>'Contrat', - 'table'=>'contrat', - 'datefieldname'=>'date_contrat', - 'test'=>$conf->contrat->enabled && $user->rights->contrat->lire, - 'lang'=>'contract'), - 'intervention'=>array( - 'name'=>"Interventions", - 'title'=>"ListFichinterAssociatedProject", - 'class'=>'Fichinter', - 'table'=>'fichinter', - 'datefieldname'=>'date_valid', - 'disableamount'=>1, - 'test'=>$conf->ficheinter->enabled && $user->rights->ficheinter->lire, - 'lang'=>'interventions'), - 'trip'=>array( - 'name'=>"TripsAndExpenses", - 'title'=>"ListExpenseReportsAssociatedProject", - 'class'=>'Deplacement', - 'table'=>'deplacement', - 'datefieldname'=>'dated', - 'margin'=>'minus', - 'disableamount'=>1, - 'test'=>$conf->deplacement->enabled && $user->rights->deplacement->lire, - 'lang'=>'trip'), - 'expensereport'=>array( - 'name'=>"ExpensesReports", - 'title'=>"ListExpenseReportsAssociatedProject", - 'class'=>'ExpenseReport', - 'table'=>'expensereport', - 'datefieldname'=>'dated', - 'margin'=>'minus', - 'disableamount'=>1, - 'test'=>$conf->expensereport->enabled && $user->rights->expensereport->lire, - 'lang'=>'trip'), - 'agenda'=>array( - 'name'=>"Agenda", - 'title'=>"ListActionsAssociatedProject", - 'class'=>'ActionComm', - 'table'=>'actioncomm', - 'datefieldname'=>'datep', - 'disableamount'=>1, - 'test'=>$conf->agenda->enabled && $user->rights->agenda->allactions->read, - 'lang'=>'agenda') - ); - - $hookmanager->initHooks(array('completeListOfReferent')); - $hookmanager->executeHooks('completeListOfReferent', ['listofreferent'=>$listofreferent], $object, $action); - if (!empty($hookmanager->resArray)) { - $listofreferent = array_merge($listofreferent, $hookmanager->resArray); - } - - foreach ($listofreferent as $key => $value) - { - $title = $value['title']; - $classname = $value['class']; - $tablename = $value['table']; - $datefieldname = $value['datefieldname']; - $qualified = $value['test']; - $langstoload = $value['lang']; - $projectField = isset($value['project_field']) ? $value['project_field'] : 'fk_projet'; - $langs->load($langstoload); - - if (!$qualified) continue; - - //var_dump("$key, $tablename, $datefieldname, $dates, $datee"); - $elementarray = $object->get_element_list($key, $tablename, $datefieldname, $dates, $datee, $projectField); - - $num = count($elementarray); - if ($num >= 0) - { - $nexY = $pdf->GetY() + 5; - - $curY = $nexY; - $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage - $pdf->SetTextColor(0, 0, 0); - - $pdf->SetXY($this->posxref, $curY); - $pdf->MultiCell($this->posxstatut - $this->posxref, 3, $outputlangs->transnoentities($title), 0, 'L'); - - $selectList = $formproject->select_element($tablename, $project->thirdparty->id, '', -2, $projectField); - $nexY = $pdf->GetY() + 1; - $curY = $nexY; - $pdf->SetXY($this->posxref, $curY); - $pdf->MultiCell($this->posxdate - $this->posxref, 3, $outputlangs->transnoentities("Ref"), 1, 'L'); - $pdf->SetXY($this->posxdate, $curY); - $pdf->MultiCell($this->posxsociety - $this->posxdate, 3, $outputlangs->transnoentities("Date"), 1, 'C'); - $pdf->SetXY($this->posxsociety, $curY); - $titlethirdparty = $outputlangs->transnoentities("ThirdParty"); - if ($classname == 'ExpenseReport') $titlethirdparty = $langs->trans("User"); - $pdf->MultiCell($this->posxamountht - $this->posxsociety, 3, $titlethirdparty, 1, 'L'); - if (empty($value['disableamount'])) { - $pdf->SetXY($this->posxamountht, $curY); - $pdf->MultiCell($this->posxamountttc - $this->posxamountht, 3, $outputlangs->transnoentities("AmountHTShort"), 1, 'R'); - $pdf->SetXY($this->posxamountttc, $curY); - $pdf->MultiCell($this->posxstatut - $this->posxamountttc, 3, $outputlangs->transnoentities("AmountTTCShort"), 1, 'R'); - } else { - $pdf->SetXY($this->posxamountht, $curY); - $pdf->MultiCell($this->posxstatut - $this->posxamountht, 3, "", 1, 'R'); - } - $pdf->SetXY($this->posxstatut, $curY); - $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxstatut, 3, $outputlangs->transnoentities("Status"), 1, 'R'); - - if (is_array($elementarray) && count($elementarray) > 0) - { - $nexY = $pdf->GetY(); - - $total_ht = 0; - $total_ttc = 0; - $num = count($elementarray); - - // Loop on each lines - for ($i = 0; $i < $num; $i++) - { - $curY = $nexY; - $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage - $pdf->SetTextColor(0, 0, 0); - - $pdf->setTopMargin($tab_top_newpage); - $pdf->setPageOrientation($this->orientation, 1, $heightforfooter + $heightforfreetext + $heightforinfotot); // The only function to edit the bottom margin of current page to set it. - $pageposbefore = $pdf->getPage(); - - // Description of line - $idofelement = $elementarray[$i]; - if ($classname == 'ExpenseReport') - { - // We get id of expense report - $expensereportline = new ExpenseReportLine($this->db); - $expensereportline->fetch($idofelement); - $idofelement = $expensereportline->fk_expensereport; - } - - $element = new $classname($this->db); - $element->fetch($idofelement); - $element->fetch_thirdparty(); - // print $classname; - - $qualifiedfortotal = true; - if ($key == 'invoice') { - if ($element->close_code == 'replaced') - $qualifiedfortotal = false; // Replacement invoice - } - - $showpricebeforepagebreak = 1; - - $pdf->startTransaction(); - // Label - $pdf->SetXY($this->posxref, $curY); - $pdf->MultiCell($this->posxdate - $this->posxref, 3, $element->ref, 1, 'L'); - $pageposafter = $pdf->getPage(); - if ($pageposafter > $pageposbefore) // There is a pagebreak - { - $pdf->rollbackTransaction(true); - $pageposafter = $pageposbefore; - //print $pageposafter.'-'.$pageposbefore;exit; - $pdf->setPageOrientation($this->orientation, 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it. - // Label - $pdf->SetXY($this->posxref, $curY); - $posybefore = $pdf->GetY(); - $pdf->MultiCell($this->posxdate - $this->posxref, 3, $element->ref, 1, 'L'); - $pageposafter = $pdf->getPage(); - $posyafter = $pdf->GetY(); - if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) // There is no space left for total+free text - { - if ($i == ($num - 1)) // No more lines, and no space left to show total, so we create a new page - { - $pdf->AddPage($this->orientation, '', true); - if (!empty($tplidx)) $pdf->useTemplate($tplidx); - if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs); - $pdf->setPage($pageposafter + 1); - } - } else { - // We found a page break + $listofreferent = array( + 'propal'=>array( + 'name'=>"Proposals", + 'title'=>"ListProposalsAssociatedProject", + 'class'=>'Propal', + 'table'=>'propal', + 'datefieldname'=>'datep', + 'test'=>$conf->propal->enabled && $user->rights->propale->lire, + 'lang'=>'propal'), + 'order'=>array( + 'name'=>"CustomersOrders", + 'title'=>"ListOrdersAssociatedProject", + 'class'=>'Commande', + 'table'=>'commande', + 'datefieldname'=>'date_commande', + 'test'=>$conf->commande->enabled && $user->rights->commande->lire, + 'lang'=>'orders'), + 'invoice'=>array( + 'name'=>"CustomersInvoices", + 'title'=>"ListInvoicesAssociatedProject", + 'class'=>'Facture', + 'margin'=>'add', + 'table'=>'facture', + 'datefieldname'=>'datef', + 'test'=>$conf->facture->enabled && $user->rights->facture->lire, + 'lang'=>'bills'), + 'invoice_predefined'=>array( + 'name'=>"PredefinedInvoices", + 'title'=>"ListPredefinedInvoicesAssociatedProject", + 'class'=>'FactureRec', + 'table'=>'facture_rec', + 'datefieldname'=>'datec', + 'test'=>$conf->facture->enabled && $user->rights->facture->lire, + 'lang'=>'bills'), + 'order_supplier'=>array( + 'name'=>"SuppliersOrders", + 'title'=>"ListSupplierOrdersAssociatedProject", + 'class'=>'CommandeFournisseur', + 'table'=>'commande_fournisseur', + 'datefieldname'=>'date_commande', + 'test'=>$conf->fournisseur->enabled && $user->rights->fournisseur->commande->lire, + 'lang'=>'orders'), + 'invoice_supplier'=>array( + 'name'=>"BillsSuppliers", + 'title'=>"ListSupplierInvoicesAssociatedProject", + 'class'=>'FactureFournisseur', + 'margin'=>'minus', + 'table'=>'facture_fourn', + 'datefieldname'=>'datef', + 'test'=>$conf->fournisseur->enabled && $user->rights->fournisseur->facture->lire, + 'lang'=>'bills'), + 'contract'=>array( + 'name'=>"Contracts", + 'title'=>"ListContractAssociatedProject", + 'class'=>'Contrat', + 'table'=>'contrat', + 'datefieldname'=>'date_contrat', + 'test'=>$conf->contrat->enabled && $user->rights->contrat->lire, + 'lang'=>'contract'), + 'intervention'=>array( + 'name'=>"Interventions", + 'title'=>"ListFichinterAssociatedProject", + 'class'=>'Fichinter', + 'table'=>'fichinter', + 'datefieldname'=>'date_valid', + 'disableamount'=>1, + 'test'=>$conf->ficheinter->enabled && $user->rights->ficheinter->lire, + 'lang'=>'interventions'), + 'trip'=>array( + 'name'=>"TripsAndExpenses", + 'title'=>"ListExpenseReportsAssociatedProject", + 'class'=>'Deplacement', + 'table'=>'deplacement', + 'datefieldname'=>'dated', + 'margin'=>'minus', + 'disableamount'=>1, + 'test'=>$conf->deplacement->enabled && $user->rights->deplacement->lire, + 'lang'=>'trip'), + 'expensereport'=>array( + 'name'=>"ExpensesReports", + 'title'=>"ListExpenseReportsAssociatedProject", + 'class'=>'ExpenseReport', + 'table'=>'expensereport', + 'datefieldname'=>'dated', + 'margin'=>'minus', + 'disableamount'=>1, + 'test'=>$conf->expensereport->enabled && $user->rights->expensereport->lire, + 'lang'=>'trip'), + 'agenda'=>array( + 'name'=>"Agenda", + 'title'=>"ListActionsAssociatedProject", + 'class'=>'ActionComm', + 'table'=>'actioncomm', + 'datefieldname'=>'datep', + 'disableamount'=>1, + 'test'=>$conf->agenda->enabled && $user->rights->agenda->allactions->read, + 'lang'=>'agenda') + ); + + $hookmanager->initHooks(array('completeListOfReferent')); + $hookmanager->executeHooks('completeListOfReferent', ['listofreferent'=>$listofreferent], $object, $action); + if (!empty($hookmanager->resArray)) { + $listofreferent = array_merge($listofreferent, $hookmanager->resArray); + } + + foreach ($listofreferent as $key => $value) + { + $title = $value['title']; + $classname = $value['class']; + $tablename = $value['table']; + $datefieldname = $value['datefieldname']; + $qualified = $value['test']; + $langstoload = $value['lang']; + $projectField = isset($value['project_field']) ? $value['project_field'] : 'fk_projet'; + $langs->load($langstoload); + + if (!$qualified) continue; + + //var_dump("$key, $tablename, $datefieldname, $dates, $datee"); + $elementarray = $object->get_element_list($key, $tablename, $datefieldname, $dates, $datee, $projectField); + + $num = count($elementarray); + if ($num >= 0) + { + $nexY = $pdf->GetY() + 5; + + $curY = $nexY; + $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage + $pdf->SetTextColor(0, 0, 0); + + $pdf->SetXY($this->posxref, $curY); + $pdf->MultiCell($this->posxstatut - $this->posxref, 3, $outputlangs->transnoentities($title), 0, 'L'); + + $selectList = $formproject->select_element($tablename, $project->thirdparty->id, '', -2, $projectField); + $nexY = $pdf->GetY() + 1; + $curY = $nexY; + $pdf->SetXY($this->posxref, $curY); + $pdf->MultiCell($this->posxdate - $this->posxref, 3, $outputlangs->transnoentities("Ref"), 1, 'L'); + $pdf->SetXY($this->posxdate, $curY); + $pdf->MultiCell($this->posxsociety - $this->posxdate, 3, $outputlangs->transnoentities("Date"), 1, 'C'); + $pdf->SetXY($this->posxsociety, $curY); + $titlethirdparty = $outputlangs->transnoentities("ThirdParty"); + if ($classname == 'ExpenseReport') $titlethirdparty = $langs->trans("User"); + $pdf->MultiCell($this->posxamountht - $this->posxsociety, 3, $titlethirdparty, 1, 'L'); + if (empty($value['disableamount'])) { + $pdf->SetXY($this->posxamountht, $curY); + $pdf->MultiCell($this->posxamountttc - $this->posxamountht, 3, $outputlangs->transnoentities("AmountHTShort"), 1, 'R'); + $pdf->SetXY($this->posxamountttc, $curY); + $pdf->MultiCell($this->posxstatut - $this->posxamountttc, 3, $outputlangs->transnoentities("AmountTTCShort"), 1, 'R'); + } else { + $pdf->SetXY($this->posxamountht, $curY); + $pdf->MultiCell($this->posxstatut - $this->posxamountht, 3, "", 1, 'R'); + } + $pdf->SetXY($this->posxstatut, $curY); + $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxstatut, 3, $outputlangs->transnoentities("Status"), 1, 'R'); + + if (is_array($elementarray) && count($elementarray) > 0) + { + $nexY = $pdf->GetY(); + + $total_ht = 0; + $total_ttc = 0; + $num = count($elementarray); + + // Loop on each lines + for ($i = 0; $i < $num; $i++) + { + $curY = $nexY; + $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage + $pdf->SetTextColor(0, 0, 0); + + $pdf->setTopMargin($tab_top_newpage); + $pdf->setPageOrientation($this->orientation, 1, $heightforfooter + $heightforfreetext + $heightforinfotot); // The only function to edit the bottom margin of current page to set it. + $pageposbefore = $pdf->getPage(); + + // Description of line + $idofelement = $elementarray[$i]; + if ($classname == 'ExpenseReport') + { + // We get id of expense report + $expensereportline = new ExpenseReportLine($this->db); + $expensereportline->fetch($idofelement); + $idofelement = $expensereportline->fk_expensereport; + } + + $element = new $classname($this->db); + $element->fetch($idofelement); + $element->fetch_thirdparty(); + // print $classname; + + $qualifiedfortotal = true; + if ($key == 'invoice') { + if ($element->close_code == 'replaced') + $qualifiedfortotal = false; // Replacement invoice + } + + $showpricebeforepagebreak = 1; + + $pdf->startTransaction(); + // Label + $pdf->SetXY($this->posxref, $curY); + $pdf->MultiCell($this->posxdate - $this->posxref, 3, $element->ref, 1, 'L'); + $pageposafter = $pdf->getPage(); + if ($pageposafter > $pageposbefore) // There is a pagebreak + { + $pdf->rollbackTransaction(true); + $pageposafter = $pageposbefore; + //print $pageposafter.'-'.$pageposbefore;exit; + $pdf->setPageOrientation($this->orientation, 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it. + // Label + $pdf->SetXY($this->posxref, $curY); + $posybefore = $pdf->GetY(); + $pdf->MultiCell($this->posxdate - $this->posxref, 3, $element->ref, 1, 'L'); + $pageposafter = $pdf->getPage(); + $posyafter = $pdf->GetY(); + if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) // There is no space left for total+free text + { + if ($i == ($num - 1)) // No more lines, and no space left to show total, so we create a new page + { + $pdf->AddPage($this->orientation, '', true); + if (!empty($tplidx)) $pdf->useTemplate($tplidx); + if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs); + $pdf->setPage($pageposafter + 1); + } + } + else + { + // We found a page break // Allows data in the first page if description is long enough to break in multiples pages if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) $showpricebeforepagebreak = 1; - else $showpricebeforepagebreak = 0; - - $forcedesconsamepage = 1; - if ($forcedesconsamepage) - { - $pdf->rollbackTransaction(true); - $pageposafter = $pageposbefore; - $pdf->setPageOrientation($this->orientation, 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it. - - $pdf->AddPage($this->orientation, '', true); - if (!empty($tplidx)) $pdf->useTemplate($tplidx); - if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs); - $pdf->setPage($pageposafter + 1); - $pdf->SetFont('', '', $default_font_size - 1); // On repositionne la police par defaut - $pdf->MultiCell(0, 3, ''); // Set interline to 3 - $pdf->SetTextColor(0, 0, 0); - - $pdf->setPageOrientation($this->orientation, 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it. - $curY = $tab_top_newpage + $heightoftitleline + 1; - - // Label - $pdf->SetXY($this->posxref, $curY); - $posybefore = $pdf->GetY(); - $pdf->MultiCell($this->posxdate - $this->posxref, 3, $element->ref, 1, 'L'); - $pageposafter = $pdf->getPage(); - $posyafter = $pdf->GetY(); - } - } - //var_dump($i.' '.$posybefore.' '.$posyafter.' '.($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot)).' '.$showpricebeforepagebreak); - } else // No pagebreak - { - $pdf->commitTransaction(); - } - $posYAfterDescription = $pdf->GetY(); - - $nexY = $pdf->GetY(); - $pageposafter = $pdf->getPage(); - $pdf->setPage($pageposbefore); - $pdf->setTopMargin($this->marge_haute); - $pdf->setPageOrientation($this->orientation, 1, 0); // The only function to edit the bottom margin of current page to set it. - - // We suppose that a too long description is moved completely on next page - if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) { - //var_dump($pageposbefore.'-'.$pageposafter.'-'.$showpricebeforepagebreak); - $pdf->setPage($pageposafter); $curY = $tab_top_newpage + $heightoftitleline + 1; - } - - $pdf->SetFont('', '', $default_font_size - 1); // On repositionne la police par defaut - - // Date - if ($tablename == 'commande_fournisseur' || $tablename == 'supplier_order') - $date = $element->date_commande; - else { - $date = $element->date; - if (empty($date)) - $date = $element->datep; - if (empty($date)) - $date = $element->date_contrat; - if (empty($date)) - $date = $element->datev; // Fiche inter - } - - $pdf->SetXY($this->posxdate, $curY); - $pdf->MultiCell($this->posxsociety - $this->posxdate, 3, dol_print_date($date, 'day'), 1, 'C'); - - $pdf->SetXY($this->posxsociety, $curY); - if ($classname == 'ExpenseReport') - { - $fuser = new User($this->db); - $fuser->fetch($element->fk_user_author); - $pdf->MultiCell($this->posxamountht - $this->posxsociety, 3, $fuser->getFullName($outputlangs), 1, 'L'); - } else { - $pdf->MultiCell($this->posxamountht - $this->posxsociety, 3, (is_object($element->thirdparty) ? $element->thirdparty->name : ''), 1, 'L'); - } - - // Amount without tax - if (empty($value['disableamount'])) { - $pdf->SetXY($this->posxamountht, $curY); - $pdf->MultiCell($this->posxamountttc - $this->posxamountht, 3, (isset($element->total_ht) ? price($element->total_ht) : ''), 1, 'R'); - $pdf->SetXY($this->posxamountttc, $curY); - $pdf->MultiCell($this->posxstatut - $this->posxamountttc, 3, (isset($element->total_ttc) ? price($element->total_ttc) : ''), 1, 'R'); - } else { - $pdf->SetXY($this->posxamountht, $curY); - if ($key == 'agenda') - { - $textforamount = dol_trunc($element->label, 26); - $pdf->MultiCell($this->posxstatut - $this->posxamountht, 3, $textforamount, 1, 'L'); - } else { - $pdf->MultiCell($this->posxstatut - $this->posxamountht, 3, "", 1, 'R'); - } - } - - // Status - if ($element instanceof CommonInvoice) { - // This applies for Facture and FactureFournisseur - $outputstatut = $element->getLibStatut(1, $element->getSommePaiement()); - } else { - $outputstatut = $element->getLibStatut(1); - } - $pdf->SetXY($this->posxstatut, $curY); - $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxstatut, 3, $outputstatut, 1, 'R', false, 1, '', '', true, 0, true); - - if ($qualifiedfortotal) { - $total_ht = $total_ht + $element->total_ht; - $total_ttc = $total_ttc + $element->total_ttc; - } - $nexY = $pdf->GetY(); - $curY = $nexY; - } - - if (empty($value['disableamount'])) { - $curY = $nexY; - $pdf->SetXY($this->posxref, $curY); - $pdf->MultiCell($this->posxamountttc - $this->posxref, 3, "TOTAL", 1, 'L'); - $pdf->SetXY($this->posxamountht, $curY); - $pdf->MultiCell($this->posxamountttc - $this->posxamountht, 3, (isset($element->total_ht) ? price($total_ht) : ''), 1, 'R'); - $pdf->SetXY($this->posxamountttc, $curY); - $pdf->MultiCell($this->posxstatut - $this->posxamountttc, 3, (isset($element->total_ttc) ? price($total_ttc) : ''), 1, 'R'); - $pdf->SetXY($this->posxstatut, $curY); - $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxstatut, 3, $outputlangs->transnoentities("Nb")." ".$num, 1, 'L'); - } - $nexY = $pdf->GetY() + 5; - $curY = $nexY; - } - } - - $nexY += 2; // Add space between lines + else + $showpricebeforepagebreak = 0; + + $forcedesconsamepage = 1; + if ($forcedesconsamepage) + { + $pdf->rollbackTransaction(true); + $pageposafter = $pageposbefore; + $pdf->setPageOrientation($this->orientation, 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it. + + $pdf->AddPage($this->orientation, '', true); + if (!empty($tplidx)) $pdf->useTemplate($tplidx); + if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs); + $pdf->setPage($pageposafter + 1); + $pdf->SetFont('', '', $default_font_size - 1); // On repositionne la police par defaut + $pdf->MultiCell(0, 3, ''); // Set interline to 3 + $pdf->SetTextColor(0, 0, 0); + + $pdf->setPageOrientation($this->orientation, 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it. + $curY = $tab_top_newpage + $heightoftitleline + 1; + + // Label + $pdf->SetXY($this->posxref, $curY); + $posybefore = $pdf->GetY(); + $pdf->MultiCell($this->posxdate - $this->posxref, 3, $element->ref, 1, 'L'); + $pageposafter = $pdf->getPage(); + $posyafter = $pdf->GetY(); + } + } + //var_dump($i.' '.$posybefore.' '.$posyafter.' '.($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot)).' '.$showpricebeforepagebreak); + } + else // No pagebreak + { + $pdf->commitTransaction(); + } + $posYAfterDescription = $pdf->GetY(); + + $nexY = $pdf->GetY(); + $pageposafter = $pdf->getPage(); + $pdf->setPage($pageposbefore); + $pdf->setTopMargin($this->marge_haute); + $pdf->setPageOrientation($this->orientation, 1, 0); // The only function to edit the bottom margin of current page to set it. + + // We suppose that a too long description is moved completely on next page + if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) { + //var_dump($pageposbefore.'-'.$pageposafter.'-'.$showpricebeforepagebreak); + $pdf->setPage($pageposafter); $curY = $tab_top_newpage + $heightoftitleline + 1; + } + + $pdf->SetFont('', '', $default_font_size - 1); // On repositionne la police par defaut + + // Date + if ($tablename == 'commande_fournisseur' || $tablename == 'supplier_order') + $date = $element->date_commande; + else { + $date = $element->date; + if (empty($date)) + $date = $element->datep; + if (empty($date)) + $date = $element->date_contrat; + if (empty($date)) + $date = $element->datev; // Fiche inter + } + + $pdf->SetXY($this->posxdate, $curY); + $pdf->MultiCell($this->posxsociety - $this->posxdate, 3, dol_print_date($date, 'day'), 1, 'C'); + + $pdf->SetXY($this->posxsociety, $curY); + if ($classname == 'ExpenseReport') + { + $fuser = new User($this->db); + $fuser->fetch($element->fk_user_author); + $pdf->MultiCell($this->posxamountht - $this->posxsociety, 3, $fuser->getFullName($outputlangs), 1, 'L'); + } + else + { + $pdf->MultiCell($this->posxamountht - $this->posxsociety, 3, (is_object($element->thirdparty) ? $element->thirdparty->name : ''), 1, 'L'); + } + + // Amount without tax + if (empty($value['disableamount'])) { + $pdf->SetXY($this->posxamountht, $curY); + $pdf->MultiCell($this->posxamountttc - $this->posxamountht, 3, (isset($element->total_ht) ? price($element->total_ht) : ''), 1, 'R'); + $pdf->SetXY($this->posxamountttc, $curY); + $pdf->MultiCell($this->posxstatut - $this->posxamountttc, 3, (isset($element->total_ttc) ? price($element->total_ttc) : ''), 1, 'R'); + } else { + $pdf->SetXY($this->posxamountht, $curY); + if ($key == 'agenda') + { + $textforamount = dol_trunc($element->label, 26); + $pdf->MultiCell($this->posxstatut - $this->posxamountht, 3, $textforamount, 1, 'L'); + } + else + { + $pdf->MultiCell($this->posxstatut - $this->posxamountht, 3, "", 1, 'R'); + } + } + + // Status + if ($element instanceof CommonInvoice) { + // This applies for Facture and FactureFournisseur + $outputstatut = $element->getLibStatut(1, $element->getSommePaiement()); + } else { + $outputstatut = $element->getLibStatut(1); + } + $pdf->SetXY($this->posxstatut, $curY); + $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxstatut, 3, $outputstatut, 1, 'R', false, 1, '', '', true, 0, true); + + if ($qualifiedfortotal) { + $total_ht = $total_ht + $element->total_ht; + $total_ttc = $total_ttc + $element->total_ttc; + } + $nexY = $pdf->GetY(); + $curY = $nexY; + } + + if (empty($value['disableamount'])) { + $curY = $nexY; + $pdf->SetXY($this->posxref, $curY); + $pdf->MultiCell($this->posxamountttc - $this->posxref, 3, "TOTAL", 1, 'L'); + $pdf->SetXY($this->posxamountht, $curY); + $pdf->MultiCell($this->posxamountttc - $this->posxamountht, 3, (isset($element->total_ht) ? price($total_ht) : ''), 1, 'R'); + $pdf->SetXY($this->posxamountttc, $curY); + $pdf->MultiCell($this->posxstatut - $this->posxamountttc, 3, (isset($element->total_ttc) ? price($total_ttc) : ''), 1, 'R'); + $pdf->SetXY($this->posxstatut, $curY); + $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxstatut, 3, $outputlangs->transnoentities("Nb")." ".$num, 1, 'L'); + } + $nexY = $pdf->GetY() + 5; + $curY = $nexY; + } + } + + $nexY += 2; // Add space between lines // Detect if some page were added automatically and output _tableau for past pages while ($pagenb < $pageposafter) @@ -667,8 +677,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)) @@ -677,11 +687,15 @@ $this->result = array('fullpath'=>$file); return 1; // No error - } else { + } + else + { $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir); return 0; } - } else { + } + else + { $this->error = $langs->transnoentities("ErrorConstantNotDefined", "PROJECT_OUTPUTDIR"); return 0; } @@ -691,7 +705,7 @@ /** * Show table for lines * - * @param TCPDF $pdf Object PDF + * @param PDF $pdf Object PDF * @param string $tab_top Top position of table * @param string $tab_height Height of table (rectangle) * @param int $nexY Y @@ -742,7 +756,7 @@ /** * Show top header of page. * - * @param TCPDF $pdf Object PDF + * @param PDF $pdf Object PDF * @param Project $object Object to show * @param int $showaddress 0=no, 1=yes * @param Translate $outputlangs Object lang for output @@ -759,7 +773,7 @@ $pdf->SetTextColor(0, 0, 60); $pdf->SetFont('', 'B', $default_font_size + 3); - $posx = $this->page_largeur - $this->marge_droite - 100; + $posx = $this->page_largeur - $this->marge_droite - 100; $posy = $this->marge_haute; $pdf->SetXY($this->marge_gauche, $posy); @@ -770,15 +784,18 @@ { if (is_readable($logo)) { - $height = pdf_getHeightForLogo($logo); - $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto) - } else { + $height = pdf_getHeightForLogo($logo); + $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto) + } + else + { $pdf->SetTextColor(200, 0, 0); $pdf->SetFont('', 'B', $default_font_size - 2); $pdf->MultiCell(100, 3, $langs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L'); $pdf->MultiCell(100, 3, $langs->transnoentities("ErrorGoToModuleSetup"), 0, 'L'); } - } else $pdf->MultiCell(100, 4, $outputlangs->transnoentities($this->emetteur->name), 0, 'L'); + } + else $pdf->MultiCell(100, 4, $outputlangs->transnoentities($this->emetteur->name), 0, 'L'); $pdf->SetFont('', 'B', $default_font_size + 3); $pdf->SetXY($posx, $posy); @@ -808,8 +825,8 @@ // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore /** * Show footer of page. Need this->emetteur object - * - * @param TCPDF $pdf PDF + * + * @param PDF $pdf PDF * @param Project $object Object to show * @param Translate $outputlangs Object lang for output * @param int $hidefreetext 1=Hide free text @@ -818,7 +835,7 @@ 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; + $showdetails = $conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS; return pdf_pagefoot($pdf, $outputlangs, 'PROJECT_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext); } } --- /tmp/dsg/dolibarr/htdocs/core/modules/project/doc/github_pdf_timespent.modules.php +++ /tmp/dsg/dolibarr/htdocs/core/modules/project/doc/client_pdf_timespent.modules.php @@ -38,20 +38,8 @@ class pdf_timespent extends ModelePDFProjects { /** - * @var array Minimum version of PHP required by module. - * e.g.: PHP ≥ 5.6 = array(5, 6) - */ - public $phpmin = array(5, 6); - - /** - * Dolibarr version of the loaded document - * @var string - */ - public $version = 'dolibarr'; - - /** * Issuer - * @var Societe Object that emits + * @var Societe */ public $emetteur; @@ -93,26 +81,25 @@ // Define position of columns $this->posxref = $this->marge_gauche + 1; $this->posxlabel = $this->marge_gauche + 25; - $this->posxworkload = $this->marge_gauche + 100; $this->posxtimespent = $this->marge_gauche + 120; //$this->posxprogress=$this->marge_gauche+140; - $this->posxuser = $this->marge_gauche + 147; - //$this->posxdateend = $this->marge_gauche + 169; + $this->posxdatestart = $this->marge_gauche + 152; + $this->posxdateend = $this->marge_gauche + 170; if ($this->page_largeur < 210) // To work with US executive format { $this->posxref -= 20; $this->posxlabel -= 20; $this->posxtimespent -= 20; //$this->posxprogress-=20; - $this->posxuser -= 20; - //$this->posxdateend -= 20; + $this->posxdatestart -= 20; + $this->posxdateend -= 20; } } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** - * Function to build pdf project onto disk + * Fonction generant le projet sur le disque * * @param Project $object Object project a generer * @param Translate $outputlangs Lang output object @@ -120,7 +107,7 @@ */ public function write_file($object, $outputlangs) { - // phpcs:enable + // phpcs:enable global $conf, $hookmanager, $langs, $user; if (!is_object($outputlangs)) $outputlangs = $langs; @@ -167,31 +154,30 @@ $pdf->SetAutoPageBreak(1, 0); $heightforinfotot = 40; // 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; - - if (class_exists('TCPDF')) - { - $pdf->setPrintHeader(false); - $pdf->setPrintFooter(false); - } - $pdf->SetFont(pdf_getPDFFont($outputlangs)); - // Set path to the background PDF File - if (!empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) - { - $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND); - $tplidx = $pdf->importPage(1); - } + $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 (class_exists('TCPDF')) + { + $pdf->setPrintHeader(false); + $pdf->setPrintFooter(false); + } + $pdf->SetFont(pdf_getPDFFont($outputlangs)); + // Set path to the background PDF File + if (!empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) + { + $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND); + $tplidx = $pdf->importPage(1); + } // Complete object by loading several other informations $task = new Task($this->db); $tasksarray = $task->getTasksArray(0, 0, $object->id); - if (!$object->id > 0) // Special case when used with object = specimen, we may return all lines - { - $tasksarray = array_slice($tasksarray, 0, min(5, count($tasksarray))); - } + if (!$object->id > 0) // Special case when used with object = specimen, we may return all lines + { + $tasksarray = array_slice($tasksarray, 0, min(5, count($tasksarray))); + } $object->lines = $tasksarray; $nblines = count($object->lines); @@ -241,11 +227,13 @@ // Rect takes a length in 3rd parameter $pdf->SetDrawColor(192, 192, 192); - $pdf->Rect($this->marge_gauche, $tab_top - 2, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 2); + $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1); $tab_height = $tab_height - $height_note; $tab_top = $nexY + 6; - } else { + } + else + { $height_note = 0; } @@ -253,10 +241,6 @@ $iniY = $tab_top + $heightoftitleline + 1; $curY = $tab_top + $heightoftitleline + 1; $nexY = $tab_top + $heightoftitleline + 1; - - $tmpuser = new User($this->db); - - // TODO We should loop on record of times spent grouped by user instead of lines of tasks // Loop on each lines for ($i = 0; $i < $nblines; $i++) @@ -305,13 +289,16 @@ if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs); $pdf->setPage($pageposafter + 1); } - } else { + } + else + { // We found a page break // Allows data in the first page if description is long enough to break in multiples pages if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) $showpricebeforepagebreak = 1; - else $showpricebeforepagebreak = 0; + else + $showpricebeforepagebreak = 0; $forcedesconsamepage = 1; if ($forcedesconsamepage) @@ -340,7 +327,8 @@ } } //var_dump($i.' '.$posybefore.' '.$posyafter.' '.($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot)).' '.$showpricebeforepagebreak); - } else // No pagebreak + } + else // No pagebreak { $pdf->commitTransaction(); } @@ -358,24 +346,22 @@ $pdf->setPage($pageposafter); $curY = $tab_top_newpage + $heightoftitleline + 1; } - $pdf->SetFont('', '', $default_font_size - 1); // We reposition the default font + $pdf->SetFont('', '', $default_font_size - 1); // On repositionne la police par defaut // Ref of task $pdf->SetXY($this->posxref, $curY); $pdf->MultiCell($this->posxlabel - $this->posxref, 3, $outputlangs->convToOutputCharset($ref), 0, 'L'); // timespent $pdf->SetXY($this->posxtimespent, $curY); - $pdf->MultiCell($this->posxuser - $this->posxtimespent, 3, $duration ? $duration : '', 0, 'R'); + $pdf->MultiCell($this->posxdatestart - $this->posxtimespent, 3, $duration ? $duration : '', 0, 'R'); // Progress //$pdf->SetXY($this->posxprogress, $curY); - //$pdf->MultiCell($this->posxuser-$this->posxprogress, 3, $progress, 0, 'R'); - - // User spending time - /*var_dump($object->lines[$i]);exit; - $tmpuser->fetch($object->lines[$i]->fk_user); - $pdf->SetXY($this->posxuser, $curY); - $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxuser, 3, $tmpuser->getFullName($outputlangs, 0, -1, 20), 0, 'C'); - */ + //$pdf->MultiCell($this->posxdatestart-$this->posxprogress, 3, $progress, 0, 'R'); + // Date + $pdf->SetXY($this->posxdatestart, $curY); + $pdf->MultiCell($this->posxdateend - $this->posxdatestart, 3, $datestart, 0, 'C'); + $pdf->SetXY($this->posxdateend, $curY); + $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxdateend, 3, $dateend, 0, 'C'); // Add line if (!empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblines - 1)) @@ -396,7 +382,9 @@ if ($pagenb == 1) { $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1); - } else { + } + else + { $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1); } $this->_pagefoot($pdf, $object, $outputlangs, 1); @@ -410,7 +398,9 @@ if ($pagenb == 1) { $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1); - } else { + } + else + { $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1); } $this->_pagefoot($pdf, $object, $outputlangs, 1); @@ -425,10 +415,11 @@ // Show square if ($pagenb == 1) $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0); - else $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0); + else + $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0); $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1; - // Footer of the page + // Pied de page $this->_pagefoot($pdf, $object, $outputlangs); if (method_exists($pdf, 'AliasNbPages')) $pdf->AliasNbPages(); @@ -443,8 +434,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)) @@ -453,11 +444,15 @@ $this->result = array('fullpath'=>$file); return 1; // No error - } else { + } + else + { $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir); return 0; } - } else { + } + else + { $this->error = $langs->transnoentities("ErrorConstantNotDefined", "PROJECT_OUTPUTDIR"); return 0; } @@ -467,7 +462,7 @@ /** * Show table for lines * - * @param TCPDF $pdf Object PDF + * @param PDF $pdf Object PDF * @param string $tab_top Top position of table * @param string $tab_height Height of table (rectangle) * @param int $nexY Y @@ -482,14 +477,14 @@ $heightoftitleline = 10; - $default_font_size = pdf_getPDFFontSize($outputlangs); + $default_font_size = pdf_getPDFFontSize($outputlangs); $pdf->SetDrawColor(128, 128, 128); // Draw rect of all tab (title + lines). Rect takes a length in 3rd parameter $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $tab_height); - // Line takes a position y in 3rd parameter + // line prend une position y en 3eme param $pdf->line($this->marge_gauche, $tab_top + $heightoftitleline, $this->page_largeur - $this->marge_droite, $tab_top + $heightoftitleline); $pdf->SetTextColor(0, 0, 0); @@ -502,20 +497,23 @@ $pdf->MultiCell($this->posxtimespent - $this->posxlabel, 3, $outputlangs->transnoentities("Description"), 0, 'L'); $pdf->SetXY($this->posxtimespent, $tab_top + 1); - $pdf->MultiCell($this->posxuser - $this->posxtimespent, 3, $outputlangs->transnoentities("TimeSpent"), 0, 'R'); + $pdf->MultiCell($this->posxdatestart - $this->posxtimespent, 3, $outputlangs->transnoentities("TimeSpent"), 0, 'R'); //$pdf->SetXY($this->posxprogress, $tab_top+1); - //$pdf->MultiCell($this->posxuser - $this->posxprogress, 3, '%', 0, 'R'); - - $pdf->SetXY($this->posxuser, $tab_top + 1); - $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxuser, 3, '', 0, 'C'); + //$pdf->MultiCell($this->posxdatestart-$this->posxprogress, 3, '%', 0, 'R'); + + $pdf->SetXY($this->posxdatestart, $tab_top + 1); + $pdf->MultiCell($this->posxdateend - $this->posxdatestart, 3, $outputlangs->transnoentities("Date"), 0, 'C'); + + $pdf->SetXY($this->posxdateend, $tab_top + 1); + $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxdatestart, 3, '', 0, 'C'); } // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore /** * Show top header of page. * - * @param TCPDF $pdf Object PDF + * @param PDF $pdf Object PDF * @param Project $object Object to show * @param int $showaddress 0=no, 1=yes * @param Translate $outputlangs Object lang for output @@ -532,7 +530,7 @@ $pdf->SetTextColor(0, 0, 60); $pdf->SetFont('', 'B', $default_font_size + 3); - $posx = $this->page_largeur - $this->marge_droite - 100; + $posx = $this->page_largeur - $this->marge_droite - 100; $posy = $this->marge_haute; $pdf->SetXY($this->marge_gauche, $posy); @@ -543,15 +541,18 @@ { if (is_readable($logo)) { - $height = pdf_getHeightForLogo($logo); - $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto) - } else { + $height = pdf_getHeightForLogo($logo); + $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto) + } + else + { $pdf->SetTextColor(200, 0, 0); $pdf->SetFont('', 'B', $default_font_size - 2); $pdf->MultiCell(100, 3, $langs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L'); $pdf->MultiCell(100, 3, $langs->transnoentities("ErrorGoToModuleSetup"), 0, 'L'); } - } else $pdf->MultiCell(100, 4, $outputlangs->transnoentities($this->emetteur->name), 0, 'L'); + } + else $pdf->MultiCell(100, 4, $outputlangs->transnoentities($this->emetteur->name), 0, 'L'); $pdf->SetFont('', 'B', $default_font_size + 3); $pdf->SetXY($posx, $posy); @@ -603,19 +604,19 @@ } // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore - /** - * Show footer of page. Need this->emetteur object - * - * @param TCPDF $pdf PDF - * @param Project $object Object to show - * @param Translate $outputlangs Object lang for output - * @param int $hidefreetext 1=Hide free text - * @return integer - */ + /** + * Show footer of page. Need this->emetteur object + * + * @param PDF $pdf PDF + * @param Project $object Object to show + * @param Translate $outputlangs Object lang for output + * @param int $hidefreetext 1=Hide free text + * @return integer + */ 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; - return pdf_pagefoot($pdf, $outputlangs, 'PROJECT_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext); - } + { + global $conf; + $showdetails = $conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS; + return pdf_pagefoot($pdf, $outputlangs, 'PROJECT_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext); + } }