diff --git a/htdocs/admin/expensereport.php b/htdocs/admin/expensereport.php new file mode 100644 index 00000000000..d8b3d727bb5 --- /dev/null +++ b/htdocs/admin/expensereport.php @@ -0,0 +1,499 @@ + + * Copyright (C) 2004-2015 Laurent Destailleur + * Copyright (C) 2004 Sebastien Di Cintio + * Copyright (C) 2004 Benoit Mortier + * Copyright (C) 2005-2014 Regis Houssin + * Copyright (C) 2008 Raphael Bertrand (Resultic) + * Copyright (C) 2011-2013 Juanjo Menent + * Copyright (C) 2011-2013 Philippe Grand + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * \file htdocs/admin/expensereport.php + * \ingroup expensereport + * \brief Setup page of module ExpenseReport + */ + +require '../main.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/expensereport.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php'; + +$langs->load("admin"); +$langs->load("errors"); +$langs->load("trips"); +$langs->load('other'); + +if (! $user->admin) accessforbidden(); + +$action = GETPOST('action','alpha'); +$value = GETPOST('value','alpha'); +$label = GETPOST('label','alpha'); +$scandir = GETPOST('scandir','alpha'); +$type='expensereport'; + + +/* + * Actions + */ +if ($action == 'updateMask') +{ + $maskconst=GETPOST('maskconst','alpha'); + $maskvalue=GETPOST('maskvalue','alpha'); + if ($maskconst) $res = dolibarr_set_const($db,$maskconst,$maskvalue,'chaine',0,'',$conf->entity); + + if (! $res > 0) $error++; + + if (! $error) + { + setEventMessage($langs->trans("SetupSaved")); + } + else + { + setEventMessage($langs->trans("Error"),'errors'); + } +} + +else if ($action == 'specimen') // For fiche inter +{ + $modele= GETPOST('module','alpha'); + + $inter = new ExpenseReport($db); + $inter->initAsSpecimen(); + + // Search template files + $file=''; $classname=''; $filefound=0; + $dirmodels=array_merge(array('/'),(array) $conf->modules_parts['models']); + foreach($dirmodels as $reldir) + { + $file=dol_buildpath($reldir."core/modules/expensereport/doc/pdf_".$modele.".modules.php",0); + if (file_exists($file)) + { + $filefound=1; + $classname = "pdf_".$modele; + break; + } + } + + if ($filefound) + { + require_once $file; + + $module = new $classname($db); + + if ($module->write_file($inter,$langs) > 0) + { + header("Location: ".DOL_URL_ROOT."/document.php?modulepart=expensereport&file=SPECIMEN.pdf"); + return; + } + else + { + setEventMessage($obj->error,'errors'); + dol_syslog($obj->error, LOG_ERR); + } + } + else + { + setEventMessage($langs->trans("ErrorModuleNotFound"),'errors'); + dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR); + } +} + +// Define constants for submodules that contains parameters (forms with param1, param2, ... and value1, value2, ...) +if ($action == 'setModuleOptions') +{ + $post_size=count($_POST); + + $db->begin(); + + for($i=0;$i < $post_size;$i++) + { + if (array_key_exists('param'.$i,$_POST)) + { + $param=GETPOST("param".$i,'alpha'); + $value=GETPOST("value".$i,'alpha'); + if ($param) $res = dolibarr_set_const($db,$param,$value,'chaine',0,'',$conf->entity); + if (! $res > 0) $error++; + } + } + if (! $error) + { + $db->commit(); + setEventMessage($langs->trans("SetupSaved")); + } + else + { + $db->rollback(); + setEventMessage($langs->trans("Error"),'errors'); + } +} + +// Activate a model +else if ($action == 'set') +{ + $ret = addDocumentModel($value, $type, $label, $scandir); +} + +else if ($action == 'del') +{ + $ret = delDocumentModel($value, $type); + if ($ret > 0) + { + if ($conf->global->EXPENSEREPORT_ADDON_PDF == "$value") dolibarr_del_const($db, 'EXPENSEREPORT_ADDON_PDF',$conf->entity); + } +} + +// Set default model +else if ($action == 'setdoc') +{ + if (dolibarr_set_const($db, "EXPENSEREPORT_ADDON_PDF",$value,'chaine',0,'',$conf->entity)) + { + // La constante qui a ete lue en avant du nouveau set + // on passe donc par une variable pour avoir un affichage coherent + $conf->global->EXPENSEREPORT_ADDON_PDF = $value; + } + + // On active le modele + $ret = delDocumentModel($value, $type); + if ($ret > 0) + { + $ret = addDocumentModel($value, $type, $label, $scandir); + } +} + +else if ($action == 'setmod') +{ + // TODO Verifier si module numerotation choisi peut etre active + // par appel methode canBeActivated + + dolibarr_set_const($db, "EXPENSEREPORT_ADDON",$value,'chaine',0,'',$conf->entity); +} + +else if ($action == 'set_EXPENSEREPORT_FREE_TEXT') +{ + $freetext= GETPOST('EXPENSEREPORT_FREE_TEXT','alpha'); + $res = dolibarr_set_const($db, "EXPENSEREPORT_FREE_TEXT",$freetext,'chaine',0,'',$conf->entity); + + if (! $res > 0) $error++; + + if (! $error) + { + setEventMessage($langs->trans("SetupSaved")); + } + else + { + setEventMessage($langs->trans("Error"),'errors'); + } +} + +else if ($action == 'set_EXPENSEREPORT_DRAFT_WATERMARK') +{ + $draft= GETPOST('EXPENSEREPORT_DRAFT_WATERMARK','alpha'); + + $res = dolibarr_set_const($db, "EXPENSEREPORT_DRAFT_WATERMARK",trim($draft),'chaine',0,'',$conf->entity); + + if (! $res > 0) $error++; + + if (! $error) + { + setEventMessage($langs->trans("SetupSaved")); + } + else + { + setEventMessage($langs->trans("Error"),'errors'); + } +} + + + +/* + * View + */ + +$dirmodels=array_merge(array('/'),(array) $conf->modules_parts['models']); + +llxHeader(); + +$form=new Form($db); + +$linkback=''.$langs->trans("BackToModuleList").''; +print_fiche_titre($langs->trans("ExpenseReportsSetup"),$linkback,'setup'); + + +$head=expensereport_admin_prepare_head(); + +dol_fiche_head($head, 'expensereport', $langs->trans("ExpenseReports"), 0, 'trip'); + +// Interventions numbering model +/* +print_titre($langs->trans("FicheinterNumberingModules")); + +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +print "\n"; + +clearstatcache(); + +foreach ($dirmodels as $reldir) +{ + $dir = dol_buildpath($reldir."core/modules/fichinter/"); + + if (is_dir($dir)) + { + $handle = opendir($dir); + if (is_resource($handle)) + { + $var=true; + + while (($file = readdir($handle))!==false) + { + if (preg_match('/^(mod_.*)\.php$/i',$file,$reg)) + { + $file = $reg[1]; + $classname = substr($file,4); + + require_once $dir.$file.'.php'; + + $module = new $file; + + if ($module->isEnabled()) + { + // Show modules according to features level + if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue; + if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue; + + $var=!$var; + print ''; + + // Show example of numbering model + print ''."\n"; + + print ''; + + $ficheinter=new Fichinter($db); + $ficheinter->initAsSpecimen(); + + // Info + $htmltooltip=''; + $htmltooltip.=''.$langs->trans("Version").': '.$module->getVersion().'
'; + $nextval=$module->getNextValue($mysoc,$ficheinter); + if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval + $htmltooltip.=''.$langs->trans("NextValue").': '; + if ($nextval) { + if (preg_match('/^Error/',$nextval) || $nextval=='NotConfigured') + $nextval = $langs->trans($nextval); + $htmltooltip.=$nextval.'
'; + } else { + $htmltooltip.=$langs->trans($module->error).'
'; + } + } + print ''; + + print ''; + } + } + } + closedir($handle); + } + } +} + +print '
'.$langs->trans("Name").''.$langs->trans("Description").''.$langs->trans("Example").''.$langs->trans("Status").''.$langs->trans("ShortInfo").'
'.$module->nom."\n"; + print $module->info(); + print ''; + $tmp=$module->getExample(); + if (preg_match('/^Error/',$tmp)) print '
'.$langs->trans($tmp).'
'; + elseif ($tmp=='NotConfigured') print $langs->trans($tmp); + else print $tmp; + print '
'; + if ($conf->global->FICHEINTER_ADDON == $classname) + { + print img_picto($langs->trans("Activated"),'switch_on'); + } + else + { + print ''.img_picto($langs->trans("Disabled"),'switch_off').''; + } + print ''; + print $form->textwithpicto('',$htmltooltip,1,0); + print '

'; +*/ + +/* + * Documents models for Interventions + */ + +print_titre($langs->trans("TemplatePDFExpenseReports")); + +// Defini tableau def des modeles +$type='expensereport'; +$def = array(); +$sql = "SELECT nom"; +$sql.= " FROM ".MAIN_DB_PREFIX."document_model"; +$sql.= " WHERE type = '".$type."'"; +$sql.= " AND entity = ".$conf->entity; +$resql=$db->query($sql); +if ($resql) +{ + $i = 0; + $num_rows=$db->num_rows($resql); + while ($i < $num_rows) + { + $array = $db->fetch_array($resql); + array_push($def, $array[0]); + $i++; + } +} +else +{ + dol_print_error($db); +} + + +print ''; +print ''; +print ''; +print ''; +print '\n"; +print '\n"; +print ''; +print ''; +print "\n"; + +clearstatcache(); + +$var=true; +foreach ($dirmodels as $reldir) +{ + $dir = dol_buildpath($reldir."core/modules/expensereport/doc"); + + if (is_dir($dir)) + { + $handle=opendir($dir); + if (is_resource($handle)) + { + while (($file = readdir($handle))!==false) + { + $filelist[]=$file; + } + closedir($handle); + arsort($filelist); + + foreach($filelist as $file) + { + if (preg_match('/\.modules\.php$/i',$file) && preg_match('/^(pdf_|doc_)/',$file)) + { + + if (file_exists($dir.'/'.$file)) + { + $var=!$var; + + $name = substr($file, 4, dol_strlen($file) -16); + $classname = substr($file, 0, dol_strlen($file) -12); + + require_once $dir.'/'.$file; + $module = new $classname($db); + + $modulequalified=1; + if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) $modulequalified=0; + if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) $modulequalified=0; + + if ($modulequalified) + { + print ''; + + // Active + if (in_array($name, $def)) + { + print ""; + } + else + { + print ""; + } + + // Default + print "'; + + // Info + $htmltooltip = ''.$langs->trans("Name").': '.$module->name; + $htmltooltip.='
'.$langs->trans("Type").': '.($module->type?$module->type:$langs->trans("Unknown")); + $htmltooltip.='
'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur; + $htmltooltip.='

'.$langs->trans("FeaturesSupported").':'; + $htmltooltip.='
'.$langs->trans("Logo").': '.yn($module->option_logo,1,1); + $htmltooltip.='
'.$langs->trans("PaymentMode").': '.yn($module->option_modereg,1,1); + $htmltooltip.='
'.$langs->trans("PaymentConditions").': '.yn($module->option_condreg,1,1); + $htmltooltip.='
'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang,1,1); + $htmltooltip.='
'.$langs->trans("WatermarkOnDraftOrders").': '.yn($module->option_draft_watermark,1,1); + print ''; + + // Preview + print ''; + + print ''; + } + } + } + } + } + } +} + +print '
'.$langs->trans("Name").''.$langs->trans("Description").''.$langs->trans("Status")."'.$langs->trans("Default")."'.$langs->trans("ShortInfo").''.$langs->trans("Preview").'
'; + print (empty($module->name)?$name:$module->name); + print "\n"; + if (method_exists($module,'info')) print $module->info($langs); + else print $module->description; + print '\n"; + print 'scandir.'&label='.urlencode($module->name).'">'; + print img_picto($langs->trans("Enabled"),'switch_on'); + print ''; + print "\n"; + print 'scandir.'&label='.urlencode($module->name).'">'.img_picto($langs->trans("Disabled"),'switch_off').''; + print ""; + if ($conf->global->EXPENSEREPORT_ADDON_PDF == "$name") + { + print img_picto($langs->trans("Default"),'on'); + } + else + { + print 'scandir.'&label='.urlencode($module->name).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"),'off').''; + } + print ''; + print $form->textwithpicto('',$htmltooltip,-1,0); + print ''; + if ($module->type == 'pdf') + { + print ''.img_object($langs->trans("Preview"),'intervention').''; + } + else + { + print img_object($langs->trans("PreviewNotAvailable"),'generic'); + } + print '
'; + +dol_fiche_end(); + + +llxFooter(); + +$db->close(); diff --git a/htdocs/core/class/html.formfile.class.php b/htdocs/core/class/html.formfile.class.php index 241c44cf5f8..8a47e8a0eb1 100644 --- a/htdocs/core/class/html.formfile.class.php +++ b/htdocs/core/class/html.formfile.class.php @@ -440,11 +440,11 @@ class FormFile } else if ($modulepart != 'agenda') { - // For normalized standard modules - $file=dol_buildpath('/core/modules/'.$modulepart.'/modules_'.$modulepart.'.php',0); + // For normalized standard modules + $file=dol_buildpath('/core/modules/'.$modulepart.'/modules_'.$modulepart.'.php',0); if (file_exists($file)) { - $res=include_once $file; + $res=include_once $file; } // For normalized external modules else @@ -458,7 +458,7 @@ class FormFile $modellist=call_user_func($class.'::liste_modeles',$this->db); } else - { + { dol_print_error($this->db,'Bad value for modulepart'); return -1; } diff --git a/htdocs/core/lib/expensereport.lib.php b/htdocs/core/lib/expensereport.lib.php index f46e6416ec6..0bd2c0f721b 100644 --- a/htdocs/core/lib/expensereport.lib.php +++ b/htdocs/core/lib/expensereport.lib.php @@ -59,3 +59,46 @@ function expensereport_prepare_head($object) return $head; } + + + +/** + * Return array head with list of tabs to view object informations. + * + * @return array head array with tabs + */ +function expensereport_admin_prepare_head() +{ + global $langs, $conf, $user; + + $h = 0; + $head = array(); + + $h = 0; + + $head[$h][0] = DOL_URL_ROOT."/admin/expensereport.php"; + $head[$h][1] = $langs->trans("ExpenseReports"); + $head[$h][2] = 'expensereport'; + $h++; + + // Show more tabs from modules + // Entries must be declared in modules descriptor with line + // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab + // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab + complete_head_from_modules($conf,$langs,null,$head,$h,'expensereport_admin'); + + /*$head[$h][0] = DOL_URL_ROOT.'/fichinter/admin/fichinter_extrafields.php'; + $head[$h][1] = $langs->trans("ExtraFields"); + $head[$h][2] = 'attributes'; + $h++; + + $head[$h][0] = DOL_URL_ROOT.'/fichinter/admin/fichinterdet_extrafields.php'; + $head[$h][1] = $langs->trans("ExtraFieldsLines"); + $head[$h][2] = 'attributesdet'; + $h++; + */ + + complete_head_from_modules($conf,$langs,null,$head,$h,'expensereport_admin','remove'); + + return $head; +} diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 537cf68986b..ebbe6d0d79c 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -95,13 +95,13 @@ function getDoliDBInstance($type, $host, $user, $pass, $name, $port) } /** - * Get entity to use + * Get list of entity id to use * * @param string $element Current element - * @param int $shared 1=Return shared entities + * @param int $shared 0=Return id of entity, 1=Return id entity + shared entities * @return mixed Entity id(s) to use */ -function getEntity($element=false, $shared=false) +function getEntity($element=false, $shared=0) { global $conf, $mc; @@ -112,12 +112,9 @@ function getEntity($element=false, $shared=false) else { $out=''; - $addzero = array('user', 'usergroup'); if (in_array($element, $addzero)) $out.= '0,'; - $out.= $conf->entity; - return $out; } } diff --git a/htdocs/core/modules/commande/modules_commande.php b/htdocs/core/modules/commande/modules_commande.php index 18a586d3b63..2caf1f905e6 100644 --- a/htdocs/core/modules/commande/modules_commande.php +++ b/htdocs/core/modules/commande/modules_commande.php @@ -160,7 +160,7 @@ abstract class ModeleNumRefCommandes * @param int $hidedesc Hide description * @param int $hideref Hide ref * @return int 0 if KO, 1 if OK - * @deprecated Use the new function generateDocument of Commande class + * @deprecated Use the new function generateDocument of Commande class */ function commande_pdf_create(DoliDB $db, Commande $object, $modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0) { diff --git a/htdocs/core/modules/expensereport/doc/pdf_standard.modules.php b/htdocs/core/modules/expensereport/doc/pdf_standard.modules.php index 2ce272af9ef..bdb19778c87 100755 --- a/htdocs/core/modules/expensereport/doc/pdf_standard.modules.php +++ b/htdocs/core/modules/expensereport/doc/pdf_standard.modules.php @@ -3,7 +3,7 @@ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or + * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, @@ -19,10 +19,10 @@ /** * \file htdocs/core/modules/expensereport/doc/pdf_standard.modules.php * \ingroup expensereport - * \brief File of class to generate invoices from standard model + * \brief File of class to generate expense report from standard model */ -dol_include_once("/expensereport/core/modules/expensereport/modules_expensereport.php"); +require_once DOL_DOCUMENT_ROOT.'/core/modules/expensereport/modules_expensereport.php'; require_once(DOL_DOCUMENT_ROOT."/product/class/product.class.php"); require_once(DOL_DOCUMENT_ROOT."/core/lib/functions2.lib.php"); require_once(DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php'); @@ -34,9 +34,25 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; /** * Classe permettant de generer les factures au modele Crabe */ -class pdf_ extends ModeleExpenseReport +class pdf_standard extends ModeleExpenseReport { - var $emetteur; // Objet societe qui emet + var $db; + var $name; + var $description; + var $type; + + var $phpmin = array(4,3,0); // Minimum version of PHP required by module + var $version = 'dolibarr'; + + var $page_largeur; + var $page_hauteur; + var $format; + var $marge_gauche; + var $marge_droite; + var $marge_haute; + var $marge_basse; + + var $emetteur; // Objet societe qui emet /** @@ -51,11 +67,11 @@ class pdf_ extends ModeleExpenseReport $langs->load("main"); $langs->load("trips"); $langs->load("project"); - $langs->load("expensereport@expensereport"); + $langs->load("trips"); $this->db = $db; $this->name = ""; - $this->description = $langs->trans('PDFDescription'); + $this->description = $langs->trans('PDFStandardExpenseReports'); // Dimension page pour format A4 $this->type = 'pdf'; @@ -85,17 +101,16 @@ class pdf_ extends ModeleExpenseReport $this->emetteur=$mysoc; if (empty($this->emetteur->country_code)) $this->emetteur->country_code=substr($langs->defaultlang,-2); // By default, if was not defined - // Defini position des colonnes - // Defini position des colonnes + // Define position of columns $this->posxpiece=$this->marge_gauche+1; $this->posxdesc=20; $this->posxdate=85; $this->posxtype=105; $this->posxprojet=125; $this->posxtva=145; - $this->posxup=158; - $this->posxqty=170; - $this->postotalttc=176; + $this->posxup=162; + $this->posxqty=176; + $this->postotalttc=186; if ($this->page_largeur < 210) // To work with US executive format { $this->posxdate-=20; @@ -124,6 +139,7 @@ class pdf_ extends ModeleExpenseReport * @param int $hidedetails Do not show line details * @param int $hidedesc Do not show desc * @param int $hideref Do not show ref + * @return int 1=OK, 0=KO */ function write_file($object,$outputlangs,$srctemplatepath='',$hidedetails=0,$hidedesc=0,$hideref=0) { @@ -133,40 +149,27 @@ class pdf_ extends ModeleExpenseReport // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1'; - - // Hack to use expensereport dir - $rootfordata = DOL_DATA_ROOT; - $rootforuser = DOL_DATA_ROOT; - // If multicompany module is enabled, we redefine the root of data - //if (! empty($this->multicompany->enabled) && ! empty($this->entity) && $this->entity > 1) - //{ - // $rootfordata.='/'.$this->entity; - //} - $conf->expensereport->dir_output = $rootfordata.'/expensereport'; - $conf->expensereport_->dir_output = $rootfordata.'/expensereport'; - - $outputlangs->load("main"); $outputlangs->load("dict"); $outputlangs->load("trips"); $outputlangs->load("project"); - $outputlangs->load("expensereport@expensereport"); - $default_font_size = pdf_getPDFFontSize($outputlangs); + $nblignes = count($object->lines); - if ($conf->expensereport_->dir_output) + if ($conf->expensereport->dir_output) { - // Definition de l'objet $object (pour compatibilite ascendante) - if (! is_object($object)) + // Definition of $dir and $file + if ($object->specimen) { - $id = $object; - $object = new ExpenseReport($db); - $ret=$object->fetch($id,$user); + $dir = $conf->expensereport->dir_output; + $file = $dir . "/SPECIMEN.pdf"; + } + else + { + $objectref = dol_sanitizeFileName($object->ref); + $dir = $conf->expensereport->dir_output . "/" . $objectref; + $file = $dir . "/" . $objectref . ".pdf"; } - - $objectref = dol_sanitizeFileName($object->ref_number); - $dir = $conf->expensereport_->dir_output . "/" . $objectref; - $file = $dir . "/" . $objectref . ".pdf"; if (! file_exists($dir)) { @@ -181,10 +184,24 @@ class pdf_ extends ModeleExpenseReport if (file_exists($dir)) { - $nblignes = count($object->lines); + // Add pdfgeneration hook + if (! is_object($hookmanager)) + { + include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; + $hookmanager=new HookManager($this->db); + } + $hookmanager->initHooks(array('pdfgeneration')); + $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs); + global $action; + $reshook=$hookmanager->executeHooks('beforePDFCreation',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks // Create pdf instance $pdf=pdf_getInstance($this->format); + $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance + $heightforinfotot = 50; // Height reserved to output the info and total part + $heightforfreetext= (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT)?$conf->global->MAIN_PDF_FREETEXT_HEIGHT:5); // Height reserved to output the free text on last page + $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin) + $pdf->SetAutoPageBreak(1,0); if (class_exists('TCPDF')) { @@ -205,13 +222,12 @@ class pdf_ extends ModeleExpenseReport $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref_number)); $pdf->SetSubject($outputlangs->transnoentities("Trips")); - $pdf->SetCreator(""); + $pdf->SetCreator("Dolibarr ".DOL_VERSION); $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs))); - $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref_number)." ".$outputlangs->transnoentities("Trips")); + $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("Trips")); if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false); $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right - $pdf->SetAutoPageBreak(1,0); // Positionne $this->atleastonediscount si on a au moins une remise for ($i = 0 ; $i < $nblignes ; $i++) @@ -232,17 +248,29 @@ class pdf_ extends ModeleExpenseReport $pdf->SetTextColor(0,0,0); $tab_top = 95; - $tab_top_newpage = 95; + $tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)?95:10); $tab_height = 110; $tab_height_newpage = 110; // Affiche notes - if (! empty($object->note)) + $notetoshow=empty($object->note_public)?'':$object->note_public; + if (! empty($conf->global->MAIN_ADD_SALE_REP_SIGNATURE_IN_NOTE)) { - $tab_top = 93; + // Get first sale rep + if (is_object($object->thirdparty)) + { + $salereparray=$object->thirdparty->getSalesRepresentatives($user); + $salerepobj=new User($this->db); + $salerepobj->fetch($salereparray[0]['id']); + if (! empty($salerepobj->signature)) $notetoshow=dol_concatdesc($notetoshow, $salerepobj->signature); + } + } + if ($notetoshow) + { + $tab_top = 95; $pdf->SetFont('','', $default_font_size - 1); - $pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top, dol_htmlentitiesbr($object->note), 0, 1); + $pdf->writeHTMLCell(190, 3, $this->posxpiece-1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1); $nexY = $pdf->GetY(); $height_note=$nexY-$tab_top; @@ -265,11 +293,20 @@ class pdf_ extends ModeleExpenseReport // Loop on each lines for ($i = 0 ; $i < $nblignes ; $i++) { + $piece_comptable = $i +1; + $curY = $nexY; $pdf->SetFont('','', $default_font_size - 1); // Into loop to work with multipage $pdf->SetTextColor(0,0,0); - $piece_comptable = $i +1; + $pdf->setTopMargin($tab_top_newpage); + $pdf->setPageOrientation('', 1, $heightforfooter+$heightforfreetext+$heightforinfotot); // The only function to edit the bottom margin of current page to set it. + $pageposbefore=$pdf->getPage(); + + // Description of product line + $curX = $this->posxdesc-1; + + $showpricebeforepagebreak=1; // Piece comptable $pdf->SetFont('','', $default_font_size - 1); @@ -277,46 +314,50 @@ class pdf_ extends ModeleExpenseReport // Comments $pdf->SetFont('','', $default_font_size - 1); - $pdf->SetXY ($this->posxcomment, $curY); - $pdf->writeHTMLCell($this->posxdate-$this->posxdesc-1, 3, $this->posxdesc-1, $curY, $object->lignes[$i]->comments, 0, 1); + $pdf->SetXY($this->posxcomment, $curY); + $pdf->writeHTMLCell($this->posxdate-$this->posxdesc-1, 3, $this->posxdesc-1, $curY, $object->lines[$i]->comments, 0, 1); //nexY $nexY = $pdf->GetY(); + $pageposafter=$pdf->getPage(); + $pdf->setPage($pageposbefore); + $pdf->setTopMargin($this->marge_haute); + $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it. // Date $pdf->SetFont('','', $default_font_size - 1); - $pdf->SetXY ($this->posxdate, $curY); - $pdf->MultiCell($this->posxtype-$this->posxdate-1, 3,dol_print_date($object->lignes[$i]->date,"day",false,$outpulangs), 0, 'C'); + $pdf->SetXY($this->posxdate, $curY); + $pdf->MultiCell($this->posxtype-$this->posxdate-1, 3,dol_print_date($object->lines[$i]->date,"day",false,$outpulangs), 0, 'C'); // Type $pdf->SetFont('','', $default_font_size - 1); - $pdf->SetXY ($this->posxtype, $curY); - $pdf->MultiCell($this->posxprojet-$this->posxtype-1, 3,$outputlangs->transnoentities($object->lignes[$i]->type_fees_code), 0, 'C'); + $pdf->SetXY($this->posxtype, $curY); + $pdf->MultiCell($this->posxprojet-$this->posxtype-1, 3,$outputlangs->transnoentities($object->lines[$i]->type_fees_code), 0, 'C'); // Projet $pdf->SetFont('','', $default_font_size - 1); - $pdf->SetXY ($this->posxprojet, $curY); - $pdf->MultiCell($this->posxtva-$this->posxprojet-1, 3,$object->lignes[$i]->projet_ref, 0, 'C'); + $pdf->SetXY($this->posxprojet, $curY); + $pdf->MultiCell($this->posxtva-$this->posxprojet-1, 3,$object->lines[$i]->projet_ref, 0, 'C'); - // TVA + // VAT Rate $pdf->SetFont('','', $default_font_size - 1); - $pdf->SetXY ($this->posxtva, $curY); - $pdf->MultiCell($this->posxup-$this->posxtva-1, 3,vatrate($object->lignes[$i]->tva_taux,true), 0, 'R'); + $pdf->SetXY($this->posxtva, $curY); + $pdf->MultiCell($this->posxup-$this->posxtva-1, 3,vatrate($object->lines[$i]->tva_taux,true), 0, 'R'); // UP $pdf->SetFont('','', $default_font_size - 1); - $pdf->SetXY ($this->posxup, $curY); - $pdf->MultiCell($this->posxqty-$this->posxup-1, 3,price($object->lignes[$i]->value_unit), 0, 'R'); + $pdf->SetXY($this->posxup, $curY); + $pdf->MultiCell($this->posxqty-$this->posxup-1, 3,price($object->lines[$i]->value_unit), 0, 'R'); - // QTY + // Quantity $pdf->SetFont('','', $default_font_size - 1); - $pdf->SetXY ($this->posxqty, $curY); - $pdf->MultiCell($this->postotalttc-$this->posxqty, 3,$object->lignes[$i]->qty, 0, 'C'); + $pdf->SetXY($this->posxqty, $curY); + $pdf->MultiCell($this->postotalttc-$this->posxqty, 3,$object->lines[$i]->qty, 0, 'C'); // TotalTTC $pdf->SetFont('','', $default_font_size - 1); - $pdf->SetXY ($this->postotalttc-2, $curY); - $pdf->MultiCell(26, 3,price($object->lignes[$i]->total_ttc), 0, 'R'); + $pdf->SetXY($this->postotalttc-2, $curY); + $pdf->MultiCell($this->page_largeur-$this->marge_droite-$this->postotalttc, 3, price($object->lines[$i]->total_ttc), 0, 'R'); $nexY+=5; @@ -338,38 +379,42 @@ class pdf_ extends ModeleExpenseReport $nblineFollowDesc = 0; } - // Test if a new page is required - if ($pagenb == 1) - { - $tab_top_in_current_page=$tab_top; - $tab_height_in_current_page=$tab_height; - } - else - { - $tab_top_in_current_page=$tab_top_newpage; - $tab_height_in_current_page=$tab_height_newpage; - } - if (($nexY+$nblineFollowDesc) > ($tab_top_in_current_page+$tab_height_in_current_page) && $i < ($nblignes - 1)) - { - if ($pagenb == 1): - $this->_tableau($pdf, $tab_top, $tab_height, $nexY, $outputlangs); - $nexY=$tab_top + $tab_height + 1; - else: - $this->_tableau($pdf, $tab_top_newpage, $tab_height_newpage, $nexY, $outputlangs); - $nexY=$tab_top_newpage + $tab_height_newpage + 1; - endif; - - $this->_pagefoot($pdf,$object,$outputlangs); + $nexY+=2; // Passe espace entre les lignes + // Detect if some page were added automatically and output _tableau for past pages + while ($pagenb < $pageposafter) + { + $pdf->setPage($pagenb); + if ($pagenb == 1) + { + $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1); + } + else + { + $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1); + } + $this->_pagefoot($pdf,$object,$outputlangs,1); + $pagenb++; + $pdf->setPage($pagenb); + $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it. + if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs); + } + if (isset($object->lines[$i+1]->pagebreak) && $object->lines[$i+1]->pagebreak) + { + if ($pagenb == 1) + { + $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1); + } + else + { + $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1); + } + $this->_pagefoot($pdf,$object,$outputlangs,1); // New page $pdf->AddPage(); + if (! empty($tplidx)) $pdf->useTemplate($tplidx); $pagenb++; - $this->_pagehead($pdf, $object, 0, $outputlangs); - $pdf->SetFont('','', $default_font_size - 1); - $pdf->MultiCell(0, 3, ''); // Set interline to 3 - $pdf->SetTextColor(0,0,0); - - $nexY = $tab_top_newpage + 7; + if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs); } } @@ -377,30 +422,30 @@ class pdf_ extends ModeleExpenseReport // Show square if ($pagenb == 1) { - $this->_tableau($pdf, $tab_top, $tab_height, $nexY, $outputlangs); - $bottomlasttab=$tab_top + $tab_height + 1; + $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0); + $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1; } else { - $this->_tableau($pdf, $tab_top_newpage, $tab_height_newpage, $nexY, $outputlangs); - $bottomlasttab=$tab_top_newpage + $tab_height_newpage + 1; + $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; } - // Affiche zone totaux + // Show total area box $posy=$bottomlasttab+5;//$nexY+95; - $pdf->SetXY(120, $posy); - $pdf->MultiCell(50, 5, $outputlangs->transnoentities("TotalHT"), 1, 'L'); - $pdf->SetXY (170, $posy); - $pdf->MultiCell(30, 5, price($object->total_ht), 1, 'R'); + $pdf->SetXY(100, $posy); + $pdf->MultiCell(60, 5, $outputlangs->transnoentities("TotalHT"), 1, 'L'); + $pdf->SetXY(160, $posy); + $pdf->MultiCell($this->page_largeur - $this->marge_gauche - 160, 5, price($object->total_ht), 1, 'R'); $pdf->SetFillColor(248,248,248); $posy+=5; - $pdf->SetXY (120, $posy); + $pdf->SetXY(100, $posy); $pdf->SetFont('','B', 10); $pdf->SetTextColor(0,0,60); - $pdf->MultiCell(50, 5, $outputlangs->transnoentities("TotalTTC"), 1,'L'); - $pdf->SetXY (170, $posy); - $pdf->MultiCell(30, 5, price($object->total_ttc),1, 'R'); + $pdf->MultiCell(60, 5, $outputlangs->transnoentities("TotalTTC"), 1,'L'); + $pdf->SetXY(160, $posy); + $pdf->MultiCell($this->page_largeur - $this->marge_gauche - 160, 5, price($object->total_ttc),1, 'R'); // Pied de page $this->_pagefoot($pdf,$object,$outputlangs); @@ -411,11 +456,6 @@ class pdf_ extends ModeleExpenseReport $pdf->Output($file,'F'); // Add pdfgeneration hook - if (! is_object($hookmanager)) - { - include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; - $hookmanager=new HookManager($this->db); - } $hookmanager->initHooks(array('pdfgeneration')); $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs); global $action; @@ -434,7 +474,7 @@ class pdf_ extends ModeleExpenseReport } else { - $this->error=$langs->trans("ErrorConstantNotDefined","DEPLACEMENT_OUTPUTDIR"); + $this->error=$langs->trans("ErrorConstantNotDefined","EXPENSEREPORT_OUTPUTDIR"); return 0; } $this->error=$langs->trans("ErrorUnknown"); @@ -468,9 +508,9 @@ class pdf_ extends ModeleExpenseReport */ // Filligrane brouillon - if($object->fk_c_expensereport_statuts==1) + if ($object->fk_c_expensereport_statuts==1 && ! empty($conf->global->EXPENSEREPORT_FREE_TEXT)) { - pdf_watermark($pdf,$outputlangs,$this->page_hauteur,$this->page_largeur,'mm',"' - PREVIEW ONLY"); + pdf_watermark($pdf,$outputlangs,$this->page_hauteur,$this->page_largeur,'mm',$conf->global->EXPENSEREPORT_FREE_TEXT); } $pdf->SetTextColor(0,0,60); @@ -504,48 +544,37 @@ class pdf_ extends ModeleExpenseReport $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0, 'L'); } - $pdf->SetFont('','B', $default_font_size + 6); + $pdf->SetFont('','B', $default_font_size + 4); $pdf->SetXY($posx,$posy); - $pdf->SetTextColor(255,255,255); - $pdf->SetFillColor(193,219,62); - $ref_text = explode($conf->global->NDF_EXPLODE_CHAR,$object->ref_number); - $ref_text = substr($ref_text[1],3,$conf->global->NDF_NUM_CAR_REF); - $pdf->MultiCell(110,6,"Note de frais ".$ref_text, 0, 'L', 1); + $pdf->SetTextColor(0,0,60); + $pdf->MultiCell($this->page_largeur-$this->marge_droite-$posx,6,$langs->trans("ExpenseReport"), 0, 'L'); $pdf->SetFont('','', $default_font_size -1); // Réf complète $posy+=8; - $pdf->SetXY(100,$posy); + $pdf->SetXY($posx,$posy); $pdf->SetTextColor(0,0,60); - $pdf->MultiCell(100, 3, $outputlangs->transnoentities("Ref")." : " . $object->ref_number, '', 'L'); + $pdf->MultiCell($this->page_largeur-$this->marge_droite-$posx, 3, $outputlangs->transnoentities("Ref")." : " . $object->ref, '', 'L'); // Date début période $posy+=5; - $pdf->SetXY(100,$posy); + $pdf->SetXY($posx,$posy); $pdf->SetTextColor(0,0,60); - $pdf->MultiCell(100, 3, $outputlangs->transnoentities("DateStart")." : " . ($object->date_debut>0?$object->date_debut:dol_print_date($object->date_debut,"day",false,$outpulangs)), '', 'L'); + $pdf->MultiCell($this->page_largeur-$this->marge_droite-$posx, 3, $outputlangs->transnoentities("DateStart")." : " . ($object->date_debut>0?dol_print_date($object->date_debut,"day",false,$outpulangs):''), '', 'L'); // Date fin période $posy+=5; - $pdf->SetXY(100,$posy); + $pdf->SetXY($posx,$posy); $pdf->SetTextColor(0,0,60); - $pdf->MultiCell(100, 3, $outputlangs->transnoentities("DateEnd")." : " . ($object->date_fin>0?dol_print_date($object->date_fin,"day",false,$outpulangs):''), '', 'L'); + $pdf->MultiCell($this->page_largeur-$this->marge_droite-$posx, 3, $outputlangs->transnoentities("DateEnd")." : " . ($object->date_fin>0?dol_print_date($object->date_fin,"day",false,$outpulangs):''), '', 'L'); // Statut NDF - $posy+=7; - $pdf->SetXY(100,$posy); - $pdf->SetFont('','B',20); + $posy+=6; + $pdf->SetXY($posx,$posy); + $pdf->SetFont('','B',18); $pdf->SetTextColor(111,81,124); - if(preg_match("#Pay#",$object->libelle_statut) && !preg_match("#A P#",$object->libelle_statut)): - $pdf->MultiCell(100, 3,$outputlangs->convToOutputCharset("Payée"), '', 'L'); - elseif(preg_match("#Annul#",$object->libelle_statut)): - $pdf->MultiCell(100, 3,$outputlangs->convToOutputCharset("Annulée"), '', 'L'); - elseif(preg_match("#Refus#",$object->libelle_statut)): - $pdf->MultiCell(100, 3,$outputlangs->convToOutputCharset("Refusée"), '', 'L'); - else: - $pdf->MultiCell(100, 3,$object->libelle_statut, '', 'L'); - endif; + $pdf->MultiCell($this->page_largeur-$this->marge_droite-$posx, 3, $object->getLibStatut(0), '', 'R'); // Sender properties $carac_emetteur = ''; @@ -596,64 +625,80 @@ class pdf_ extends ModeleExpenseReport $pdf->SetFont('','B',8); $pdf->SetXY($posx,$posy-5); $pdf->MultiCell(80,5, $outputlangs->transnoentities("TripNDF")." :", 0, 'L'); - $pdf->rect($posx, $posy, 100, $hautcadre); + $pdf->rect($posx, $posy, $this->page_largeur - $this->marge_gauche - $posx, $hautcadre); // Informations for trip (dates and users workflow) - $userfee=new User($this->db); - $userfee->fetch($object->fk_user_author); $posy+=3; - $pdf->SetXY($posx+2,$posy); - $pdf->SetFont('','',10); - $pdf->MultiCell(96,4,$outputlangs->transnoentities("AUTHOR")." : ".$outputlangs->convToOutputCharset($userfee->firstname)." ".$outputlangs->convToOutputCharset($userfee->lastname),0,'L'); - $posy+=5; - $pdf->SetXY($posx+2,$posy); - $pdf->MultiCell(96,4,$outputlangs->transnoentities("DATE_SAVE")." : ".dol_print_date($object->date_create,"day",false,$outpulangs),0,'L'); + if ($object->fk_user_author > 0) + { + $userfee=new User($this->db); + $userfee->fetch($object->fk_user_author); $posy+=3; + $pdf->SetXY($posx+2,$posy); + $pdf->SetFont('','',10); + $pdf->MultiCell(96,4,$outputlangs->transnoentities("AUTHOR")." : ".dolGetFirstLastname($userfee->firstname,$userfee->lastname),0,'L'); + $posy+=5; + $pdf->SetXY($posx+2,$posy); + $pdf->MultiCell(96,4,$outputlangs->transnoentities("DateCreation")." : ".dol_print_date($object->date_create,"day",false,$outpulangs),0,'L'); + } - if($object->fk_c_expensereport_statuts<3): - $userfee=new User($this->db); - $userfee->fetch($object->fk_user_validator); $posy+=6; - $pdf->SetXY($posx+2,$posy); - $pdf->MultiCell(96,4,$outputlangs->transnoentities("VALIDATOR")." : ".$outputlangs->convToOutputCharset($userfee->firstname)." ".$outputlangs->convToOutputCharset($userfee->lastname),0,'L'); - elseif($object->fk_c_expensereport_statuts==99): - $userfee=new User($this->db); - $userfee->fetch($object->fk_user_refuse); $posy+=6; - $pdf->SetXY($posx+2,$posy); - $pdf->MultiCell(96,4,$outputlangs->transnoentities("REFUSEUR")." : ".$outputlangs->convToOutputCharset($userfee->firstname)." ".$outputlangs->convToOutputCharset($userfee->lastname),0,'L'); - $posy+=5; - $pdf->SetXY($posx+2,$posy); - $pdf->MultiCell(96,4,$outputlangs->transnoentities("MOTIF_REFUS")." : ".$outputlangs->convToOutputCharset($object->detail_refuse),0,'L'); - $posy+=5; - $pdf->SetXY($posx+2,$posy); - $pdf->MultiCell(96,4,$outputlangs->transnoentities("DATE_REFUS")." : ".dol_print_date($object->date_refuse,"day",false,$outpulangs),0,'L'); - elseif($object->fk_c_expensereport_statuts==4): - $userfee=new User($this->db); - $userfee->fetch($object->fk_user_cancel); $posy+=6; - $pdf->SetXY($posx+2,$posy); - $pdf->MultiCell(96,4,$outputlangs->transnoentities("CANCEL_USER")." : ".$outputlangs->convToOutputCharset($userfee->firstname)." ".$outputlangs->convToOutputCharset($userfee->lastname),0,'L'); - $posy+=5; - $pdf->SetXY($posx+2,$posy); - $pdf->MultiCell(96,4,$outputlangs->transnoentities("MOTIF_CANCEL")." : ".$outputlangs->convToOutputCharset($object->detail_cancel),0,'L'); - $posy+=5; - $pdf->SetXY($posx+2,$posy); - $pdf->MultiCell(96,4,$outputlangs->transnoentities("DATE_CANCEL")." : ".dol_print_date($object->date_cancel,"day",false,$outpulangs),0,'L'); - else: - $userfee=new User($this->db); - $userfee->fetch($object->fk_user_validator); $posy+=6; - $pdf->SetXY($posx+2,$posy); - $pdf->MultiCell(96,4,$outputlangs->transnoentities("VALIDOR")." : ".$outputlangs->convToOutputCharset($userfee->firstname)." ".$outputlangs->convToOutputCharset($userfee->lastname),0,'L'); - $posy+=5; - $pdf->SetXY($posx+2,$posy); - $pdf->MultiCell(96,4,$outputlangs->transnoentities("DATE_VALIDE")." : ".dol_print_date($object->date_valide,"day",false,$outpulangs),0,'L'); - endif; + if ($object->fk_c_expensereport_statuts==99) + { + if ($object->fk_user_refuse > 0) + { + $userfee=new User($this->db); + $userfee->fetch($object->fk_user_refuse); $posy+=6; + $pdf->SetXY($posx+2,$posy); + $pdf->MultiCell(96,4,$outputlangs->transnoentities("REFUSEUR")." : ".dolGetFirstLastname($userfee->firstname,$userfee->lastname),0,'L'); + $posy+=5; + $pdf->SetXY($posx+2,$posy); + $pdf->MultiCell(96,4,$outputlangs->transnoentities("MOTIF_REFUS")." : ".$outputlangs->convToOutputCharset($object->detail_refuse),0,'L'); + $posy+=5; + $pdf->SetXY($posx+2,$posy); + $pdf->MultiCell(96,4,$outputlangs->transnoentities("DATE_REFUS")." : ".dol_print_date($object->date_refuse,"day",false,$outpulangs),0,'L'); + } + } + else if($object->fk_c_expensereport_statuts==4) + { + if ($object->fk_user_cancel > 0) + { + $userfee=new User($this->db); + $userfee->fetch($object->fk_user_cancel); $posy+=6; + $pdf->SetXY($posx+2,$posy); + $pdf->MultiCell(96,4,$outputlangs->transnoentities("CANCEL_USER")." : ".dolGetFirstLastname($userfee->firstname,$userfee->lastname),0,'L'); + $posy+=5; + $pdf->SetXY($posx+2,$posy); + $pdf->MultiCell(96,4,$outputlangs->transnoentities("MOTIF_CANCEL")." : ".$outputlangs->convToOutputCharset($object->detail_cancel),0,'L'); + $posy+=5; + $pdf->SetXY($posx+2,$posy); + $pdf->MultiCell(96,4,$outputlangs->transnoentities("DATE_CANCEL")." : ".dol_print_date($object->date_cancel,"day",false,$outpulangs),0,'L'); + } + } + else + { + if ($object->fk_user_approve > 0) + { + $userfee=new User($this->db); + $userfee->fetch($object->fk_user_approve); $posy+=6; + $pdf->SetXY($posx+2,$posy); + $pdf->MultiCell(96,4,$outputlangs->transnoentities("VALIDOR")." : ".dolGetFirstLastname($userfee->firstname,$userfee->lastname),0,'L'); + $posy+=5; + $pdf->SetXY($posx+2,$posy); + $pdf->MultiCell(96,4,$outputlangs->transnoentities("DateApprove")." : ".dol_print_date($object->date_approve,"day",false,$outpulangs),0,'L'); + } + } - if($object->fk_c_expensereport_statuts==6): - $userfee=new User($this->db); - $userfee->fetch($object->fk_user_paid); $posy+=6; - $pdf->SetXY($posx+2,$posy); - $pdf->MultiCell(96,4,$outputlangs->transnoentities("AUTHORPAIEMENT")." : ".$outputlangs->convToOutputCharset($userfee->firstname)." ".$outputlangs->convToOutputCharset($userfee->lastname),0,'L'); - $posy+=5; - $pdf->SetXY($posx+2,$posy); - $pdf->MultiCell(96,4,$outputlangs->transnoentities("DATE_PAIEMENT")." : ".dol_print_date($object->date_paiement,"day",false,$outpulangs),0,'L'); - endif; + if($object->fk_c_expensereport_statuts==6) + { + if ($object->fk_user_paid > 0) + { + $userfee=new User($this->db); + $userfee->fetch($object->fk_user_paid); $posy+=6; + $pdf->SetXY($posx+2,$posy); + $pdf->MultiCell(96,4,$outputlangs->transnoentities("AUTHORPAIEMENT")." : ".dolGetFirstLastname($userfee->firstname,$userfee->lastname),0,'L'); + $posy+=5; + $pdf->SetXY($posx+2,$posy); + $pdf->MultiCell(96,4,$outputlangs->transnoentities("DATE_PAIEMENT")." : ".dol_print_date($object->date_paiement,"day",false,$outpulangs),0,'L'); + } + } } @@ -690,48 +735,48 @@ class pdf_ extends ModeleExpenseReport $pdf->SetFont('','',8); //Piece comptable - $pdf->SetXY ($this->posxpiece-1, $tab_top+1); - $pdf->MultiCell($this->posxpiece-$this->posxpiece-1,1,$outputlangs->transnoentities("Piece"),'','L'); + $pdf->SetXY($this->posxpiece-1, $tab_top+1); + $pdf->MultiCell($this->posxdesc-$this->posxpiece-1,1,'','','R'); //Comments $pdf->line($this->posxdesc-1, $tab_top, $this->posxdesc-1, $tab_top + $tab_height); - $pdf->SetXY ($this->posxdesc-1, $tab_top+1); + $pdf->SetXY($this->posxdesc-1, $tab_top+1); $pdf->MultiCell($this->posxdate-$this->posxdesc-1,1,$outputlangs->transnoentities("Description"),'','L'); //Date $pdf->line($this->posxdate-1, $tab_top, $this->posxdate-1, $tab_top + $tab_height); - $pdf->SetXY ($this->posxdate-1, $tab_top+1); + $pdf->SetXY($this->posxdate-1, $tab_top+1); $pdf->MultiCell($this->posxtype-$this->posxdate-1,2, $outputlangs->transnoentities("Date"),'','C'); //Type $pdf->line($this->posxtype-1, $tab_top, $this->posxtype-1, $tab_top + $tab_height); - $pdf->SetXY ($this->posxtype-1, $tab_top+1); + $pdf->SetXY($this->posxtype-1, $tab_top+1); $pdf->MultiCell($this->posxprojet-$this->posxtype-1,2, $outputlangs->transnoentities("Type"),'','C'); // Projet $pdf->line($this->posxprojet-1, $tab_top, $this->posxprojet-1, $tab_top + $tab_height); - $pdf->SetXY ($this->posxprojet-1, $tab_top+1); + $pdf->SetXY($this->posxprojet-1, $tab_top+1); $pdf->MultiCell($this->posxtva-$this->posxprojet-1,2, $outputlangs->transnoentities("Project"),'','C'); //TVA $pdf->line($this->posxtva-1, $tab_top, $this->posxtva-1, $tab_top + $tab_height); - $pdf->SetXY ($this->posxtva-1, $tab_top+1); + $pdf->SetXY($this->posxtva-1, $tab_top+1); $pdf->MultiCell($this->posxup-$this->posxtva-1,2, $outputlangs->transnoentities("VAT"),'','C'); //PU $pdf->line($this->posxup-1, $tab_top, $this->posxup-1, $tab_top + $tab_height); - $pdf->SetXY ($this->posxup-1, $tab_top+1); - $pdf->MultiCell($this->posxqty-$this->posxup-1,2, $outputlangs->transnoentities("PU"),'','C'); + $pdf->SetXY($this->posxup-1, $tab_top+1); + $pdf->MultiCell($this->posxqty-$this->posxup-1,2, $outputlangs->transnoentities("UP"),'','C'); //QTY $pdf->line($this->posxqty-1, $tab_top, $this->posxqty-1, $tab_top + $tab_height); - $pdf->SetXY ($this->posxqty-1, $tab_top+1); - $pdf->MultiCell($this->postotalttc-$this->posxqty,2, $outputlangs->transnoentities("Q"),'','R'); + $pdf->SetXY($this->posxqty-1, $tab_top+1); + $pdf->MultiCell($this->postotalttc-$this->posxqty,2, $outputlangs->transnoentities("Qty"),'','R'); //TOTALTTC $pdf->line($this->postotalttc, $tab_top, $this->postotalttc, $tab_top + $tab_height); - $pdf->SetXY ($this->postotalttc-4, $tab_top+1); - $pdf->MultiCell(28,2, $outputlangs->transnoentities("TotalTTC"),'','R'); + $pdf->SetXY($this->postotalttc-1, $tab_top+1); + $pdf->MultiCell($this->page_largeur-$this->marge_droite-$this->postotalttc, 2, $outputlangs->transnoentities("TotalTTC"),'','R'); $pdf->SetTextColor(0,0,0); } @@ -747,7 +792,8 @@ class pdf_ extends ModeleExpenseReport */ function _pagefoot(&$pdf,$object,$outputlangs,$hidefreetext=0) { - return pdf_pagefoot($pdf,$outputlangs,'DEPLACEMENT_FREE_TEXT',$this->emetteur,$this->marge_basse,$this->marge_gauche,$this->page_hauteur,$object,0,$hidefreetext); + $showdetails=0; + return pdf_pagefoot($pdf,$outputlangs,'EXPENSEREPORT_FREE_TEXT',$this->emetteur,$this->marge_basse,$this->marge_gauche,$this->page_hauteur,$object,$showdetails,$hidefreetext); } } diff --git a/htdocs/core/modules/expensereport/modules_expensereport.php b/htdocs/core/modules/expensereport/modules_expensereport.php index 86fa894dbaf..641f1de9c98 100755 --- a/htdocs/core/modules/expensereport/modules_expensereport.php +++ b/htdocs/core/modules/expensereport/modules_expensereport.php @@ -49,62 +49,20 @@ class ModeleExpenseReport extends CommonDocGenerator } -function expensereport_pdf_create($db, $id, $message, $modele, $outputlangs) +/** + * expensereport_pdf_create + * + * @param DoliDB $db Database handler + * @param Object $object Object order + * @param string $modele Force le modele a utiliser ('' to not force) + * @param Translate $outputlangs objet lang a utiliser pour traduction + * @param int $hidedetails Hide details of lines + * @param int $hidedesc Hide description + * @param int $hideref Hide ref + * @return int 0 if KO, 1 if OK + * @return number + */ +function expensereport_pdf_create(DoliDB $db, ExpenseReport $object, $message, $modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0) { - global $conf,$langs; - $langs->load("trips"); - - // Increase limit for PDF build - $err=error_reporting(); - error_reporting(0); - @set_time_limit(120); - error_reporting($err); - - $dir = dol_buildpath('/expensereport/core/modules/expensereport/'); - - // Positionne modele sur le nom du modele a utiliser - if (! strlen($modele)) - { - if ($conf->global->DEPLACEMENT_ADDON_PDF) - { - $modele = $conf->global->DEPLACEMENT_ADDON_PDF; - } - else - { - print $langs->trans("Error")." ".$langs->trans("Error_DEPLACEMENT_ADDON_PDF_NotDefined"); - return 0; - } - } - - // Charge le modele - $file = "pdf_".$modele.".modules.php"; - if (file_exists($dir.$file)) - { - $classname = "pdf_".$modele; - require_once($dir.$file); - - $obj = new $classname($db); - $obj->message = $message; - - // We save charset_output to restore it because write_file can change it if needed for - // output format that does not support UTF8. - $sav_charset_output=$outputlangs->charset_output; - if ($obj->write_file($id, $outputlangs) > 0) - { - $outputlangs->charset_output=$sav_charset_output; - return 1; - } - else - { - $outputlangs->charset_output=$sav_charset_output; - dol_print_error($db,"expensereport_pdf_create Error: ".$obj->error); - return -1; - } - - } - else - { - dol_print_error('',$langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$dir.$file)); - return -1; - } + return $object->generateDocument($modele, $outputlangs, $hidedetails, $hidedesc, $hideref); } diff --git a/htdocs/core/modules/modAgenda.class.php b/htdocs/core/modules/modAgenda.class.php index c633734b227..165b547dff4 100644 --- a/htdocs/core/modules/modAgenda.class.php +++ b/htdocs/core/modules/modAgenda.class.php @@ -393,7 +393,7 @@ class modAgenda extends DolibarrModules $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'socpeople as sp on ac.fk_contact = sp.rowid'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe as s on ac.fk_soc = s.rowid'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as co on s.fk_pays = co.rowid'; - $this->export_sql_end[$r] .=' Where ac.entity = '.$conf->entity; + $this->export_sql_end[$r] .=' WHERE ac.entity IN ('.getEntity('agenda',1).')'; $this->export_sql_end[$r] .=' ORDER BY ac.datep'; } diff --git a/htdocs/core/modules/modBanque.class.php b/htdocs/core/modules/modBanque.class.php index 0d383603a06..246aac2b6d7 100644 --- a/htdocs/core/modules/modBanque.class.php +++ b/htdocs/core/modules/modBanque.class.php @@ -157,7 +157,7 @@ class modBanque extends DolibarrModules $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX."bank_url as bu ON (bu.fk_bank = b.rowid AND bu.type = 'company')"; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe as s ON bu.url_id = s.rowid'; $this->export_sql_end[$r] .=' WHERE ba.rowid = b.fk_account'; - $this->export_sql_end[$r] .=' AND ba.entity = '.$conf->entity; + $this->export_sql_end[$r] .=' AND ba.entity IN ('.getEntity('bank',1).')'; $this->export_sql_order[$r] =' ORDER BY b.datev, b.num_releve'; $r++; @@ -184,7 +184,7 @@ class modBanque extends DolibarrModules $this->export_sql_end[$r] .=' WHERE ba.rowid = b.fk_account AND bch.rowid = b.fk_bordereau and bch.fk_bank_account=ba.rowid'; $this->export_sql_end[$r] .=" AND b.fk_type = 'CHQ'"; $this->export_sql_end[$r] .=' AND p.fk_paiement = 7'; - $this->export_sql_end[$r] .=' AND ba.entity = '.$conf->entity; + $this->export_sql_end[$r] .=' AND ba.entity IN ('.getEntity('bank',1).')'; $this->export_sql_order[$r] =' ORDER BY b.datev, b.num_releve'; } diff --git a/htdocs/core/modules/modCategorie.class.php b/htdocs/core/modules/modCategorie.class.php index 327608c8814..a75e73e6c3d 100644 --- a/htdocs/core/modules/modCategorie.class.php +++ b/htdocs/core/modules/modCategorie.class.php @@ -122,7 +122,7 @@ class modCategorie extends DolibarrModules $this->export_sql_start[$r]='SELECT DISTINCT '; $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'categorie as u, '.MAIN_DB_PREFIX.'categorie_fournisseur as cf, '.MAIN_DB_PREFIX.'societe as s LEFT JOIN '.MAIN_DB_PREFIX.'c_typent as t ON s.fk_typent = t.id LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON s.fk_pays = c.rowid LEFT JOIN '.MAIN_DB_PREFIX.'c_effectif as ce ON s.fk_effectif = ce.id LEFT JOIN '.MAIN_DB_PREFIX.'c_forme_juridique as cfj ON s.fk_forme_juridique = cfj.code'; $this->export_sql_end[$r] .=' WHERE u.rowid = cf.fk_categorie AND cf.fk_societe = s.rowid'; - $this->export_sql_end[$r] .=' AND u.entity = '.$conf->entity; + $this->export_sql_end[$r] .=' AND u.entity IN ('.getEntity('category',1).')'; $this->export_sql_end[$r] .=' AND u.type = 1'; // Supplier categories $r++; @@ -137,7 +137,7 @@ class modCategorie extends DolibarrModules $this->export_sql_start[$r]='SELECT DISTINCT '; $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'categorie as u, '.MAIN_DB_PREFIX.'categorie_societe as cf, '.MAIN_DB_PREFIX.'societe as s LEFT JOIN '.MAIN_DB_PREFIX.'c_typent as t ON s.fk_typent = t.id LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON s.fk_pays = c.rowid LEFT JOIN '.MAIN_DB_PREFIX.'c_effectif as ce ON s.fk_effectif = ce.id LEFT JOIN '.MAIN_DB_PREFIX.'c_forme_juridique as cfj ON s.fk_forme_juridique = cfj.code'; $this->export_sql_end[$r] .=' WHERE u.rowid = cf.fk_categorie AND cf.fk_societe = s.rowid'; - $this->export_sql_end[$r] .=' AND u.entity = '.$conf->entity; + $this->export_sql_end[$r] .=' AND u.entity IN ('.getEntity('category',1).')'; $this->export_sql_end[$r] .=' AND u.type = 2'; // Customer/Prospect categories $r++; @@ -152,7 +152,7 @@ class modCategorie extends DolibarrModules $this->export_sql_start[$r]='SELECT DISTINCT '; $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'categorie as u, '.MAIN_DB_PREFIX.'categorie_product as cp, '.MAIN_DB_PREFIX.'product as p'; $this->export_sql_end[$r] .=' WHERE u.rowid = cp.fk_categorie AND cp.fk_product = p.rowid'; - $this->export_sql_end[$r] .=' AND u.entity = '.$conf->entity; + $this->export_sql_end[$r] .=' AND u.entity IN ('.getEntity('category',1).')'; $this->export_sql_end[$r] .=' AND u.type = 0'; // Supplier categories $r++; @@ -167,8 +167,8 @@ class modCategorie extends DolibarrModules $this->export_sql_start[$r]='SELECT DISTINCT '; $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'categorie as u, '.MAIN_DB_PREFIX.'categorie_member as cp, '.MAIN_DB_PREFIX.'adherent as p'; $this->export_sql_end[$r] .=' WHERE u.rowid = cp.fk_categorie AND cp.fk_member = p.rowid'; - $this->export_sql_end[$r] .=' AND u.entity = '.$conf->entity; - $this->export_sql_end[$r] .=' AND u.type = 3'; // Supplier categories + $this->export_sql_end[$r] .=' AND u.entity IN ('.getEntity('category',1).')'; + $this->export_sql_end[$r] .=' AND u.type = 3'; // Member categories $r++; $this->export_code[$r]='category_'.$r; @@ -232,7 +232,7 @@ class modCategorie extends DolibarrModules $this->export_sql_start[$r] = 'SELECT DISTINCT '; $this->export_sql_end[$r] = ' FROM ' . MAIN_DB_PREFIX . 'categorie as u, '.MAIN_DB_PREFIX . 'categorie_contact as cp, '.MAIN_DB_PREFIX . 'socpeople as p'; $this->export_sql_end[$r] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'c_country as country ON p.fk_pays = country.rowid'; - $this->export_sql_end[$r] .= ' WHERE u.rowid = cp.fk_categorie AND cp.fk_socpeople = p.rowid AND u.entity = ' . $conf->entity; + $this->export_sql_end[$r] .= ' WHERE u.rowid = cp.fk_categorie AND cp.fk_socpeople = p.rowid AND u.entity IN ('.getEntity('category',1).')'; $this->export_sql_end[$r] .= ' AND u.type = 4'; // contact categories // Imports diff --git a/htdocs/core/modules/modCommande.class.php b/htdocs/core/modules/modCommande.class.php index d8cc5647817..c7fb5cfa587 100644 --- a/htdocs/core/modules/modCommande.class.php +++ b/htdocs/core/modules/modCommande.class.php @@ -192,7 +192,7 @@ class modCommande extends DolibarrModules $this->export_sql_end[$r] .=' , '.MAIN_DB_PREFIX.'commandedet as cd'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product as p on cd.fk_product = p.rowid'; $this->export_sql_end[$r] .=' WHERE c.fk_soc = s.rowid AND c.rowid = cd.fk_commande'; - $this->export_sql_end[$r] .=' AND c.entity = '.$conf->entity; + $this->export_sql_end[$r] .=' AND c.entity IN ('.getEntity('commande',1).')'; } diff --git a/htdocs/core/modules/modContrat.class.php b/htdocs/core/modules/modContrat.class.php index 4906d9e3954..dc97964fa45 100644 --- a/htdocs/core/modules/modContrat.class.php +++ b/htdocs/core/modules/modContrat.class.php @@ -42,7 +42,7 @@ class modContrat extends DolibarrModules function __construct($db) { global $conf; - + $this->db = $db; $this->numero = 54; @@ -160,9 +160,9 @@ class modContrat extends DolibarrModules $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c on s.fk_pays = c.rowid,'; $this->export_sql_end[$r] .=' '.MAIN_DB_PREFIX.'contrat as co,'; $this->export_sql_end[$r] .=' '.MAIN_DB_PREFIX.'contratdet as cod'; - $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product as p on (cod.fk_product = p.rowid)'; + $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product as p on (cod.fk_product = p.rowid)'; $this->export_sql_end[$r] .=' WHERE co.fk_soc = s.rowid and co.rowid = cod.fk_contrat'; - $this->export_sql_end[$r] .=' AND co.entity = '.$conf->entity; + $this->export_sql_end[$r] .=' AND co.entity IN ('.getEntity('contract',1).')'; } diff --git a/htdocs/core/modules/modDeplacement.class.php b/htdocs/core/modules/modDeplacement.class.php index f08a346577a..47642e5195d 100644 --- a/htdocs/core/modules/modDeplacement.class.php +++ b/htdocs/core/modules/modDeplacement.class.php @@ -124,7 +124,7 @@ class modDeplacement extends DolibarrModules $this->export_sql_end[$r] .=', '.MAIN_DB_PREFIX.'deplacement as d'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe as s ON d.fk_soc = s.rowid'; $this->export_sql_end[$r] .=' WHERE d.fk_user = u.rowid'; - $this->export_sql_end[$r] .=' AND d.entity = '.$conf->entity; + $this->export_sql_end[$r] .=' AND d.entity IN ('.getEntity('deplacement',1).')'; } diff --git a/htdocs/core/modules/modExpedition.class.php b/htdocs/core/modules/modExpedition.class.php index e2c85c60352..2f4b7a88be8 100644 --- a/htdocs/core/modules/modExpedition.class.php +++ b/htdocs/core/modules/modExpedition.class.php @@ -229,7 +229,7 @@ class modExpedition extends DolibarrModules $this->export_sql_end[$r] .=' '.MAIN_DB_PREFIX.'expeditiondet as ed, '.MAIN_DB_PREFIX.'commandedet as cd'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product as p on cd.fk_product = p.rowid'; $this->export_sql_end[$r] .=' WHERE c.fk_soc = s.rowid AND c.rowid = ed.fk_expedition AND ed.fk_origin_line = cd.rowid'; - $this->export_sql_end[$r] .=' AND c.entity = '.$conf->entity; + $this->export_sql_end[$r] .=' AND c.entity IN ('.getEntity('shipment',1).')'; } diff --git a/htdocs/core/modules/modExpenseReport.class.php b/htdocs/core/modules/modExpenseReport.class.php index 1bf00f86f31..c82de294008 100755 --- a/htdocs/core/modules/modExpenseReport.class.php +++ b/htdocs/core/modules/modExpenseReport.class.php @@ -4,7 +4,7 @@ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or + * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, @@ -14,7 +14,6 @@ * * You should have received a copy of the GNU General Public License * along with this program. If not, see . - * or see http://www.gnu.org/ */ /** @@ -50,8 +49,6 @@ class modExpenseReport extends DolibarrModules // Id for module (must be unique). // Use here a free id (See in Home -> System information -> Dolibarr for list of used modules id). $this->numero = 770; - // Key text used to identify module (for permissions, menus, etc...) - $this->rights_class = 'deplacement'; // Family can be 'crm','financial','hr','projects','products','ecm','technic','other' // It is used to group modules in module setup page @@ -83,21 +80,29 @@ class modExpenseReport extends DolibarrModules //$this->style_sheet = '/mymodule/mymodule.css.php'; // Config pages. Put here list of php page names stored in admmin directory used to setup module. - $this->config_page_url = array(); + $this->config_page_url = array('expensereport.php'); // Dependencies $this->depends = array(); // List of modules id that must be enabled if this module is enabled // $this->conflictwith = array("modDeplacement"); $this->requiredby = array(); // List of modules id to disable if this one is disabled $this->phpmin = array(4,3); // Minimum version of PHP required by module - $this->need_dolibarr_version = array(3,0); // Minimum version of Dolibarr required by module - $this->langfiles = array("companies","trips","deplacement@deplacement"); + $this->need_dolibarr_version = array(3,7); // Minimum version of Dolibarr required by module + $this->langfiles = array("companies","trips"); // Constants // Example: $this->const=array(0=>array('MYMODULE_MYNEWCONST1','chaine','myvalue','This is a constant to add',0), // 1=>array('MYMODULE_MYNEWCONST2','chaine','myvalue','This is another constant to add',0) ); // 2=>array('MAIN_MODULE_MYMODULE_NEEDSMARTY','chaine',1,'Constant to say module need smarty',0) $this->const = array(); // List of particular constants to add when module is enabled (key, 'chaine', value, desc, visible, 0 or 'allentities') + $r=0; + + $this->const[$r][0] = "EXPENSEREPORT_ADDON_PDF"; + $this->const[$r][1] = "chaine"; + $this->const[$r][2] = "standard"; + $this->const[$r][3] = 'Name of manager to build PDF expense reports documents'; + $this->const[$r][4] = 0; + $r++; // Array to add new pages in new tabs $this->tabs = array(); @@ -195,19 +200,21 @@ class modExpenseReport extends DolibarrModules $r=0; $r++; - $this->export_code[$r]='trips_'.$r; + $this->export_code[$r]='expensereport_'.$r; $this->export_label[$r]='ListTripsAndExpenses'; + $this->export_icon[$r]='trip'; $this->export_permission[$r]=array(array("expensereport","export")); - $this->export_fields_array[$r]=array('d.rowid'=>"TripId",'d.type'=>"Type",'d.km'=>"FeesKilometersOrAmout",'d.note'=>'NotePrivate','d.note_public'=>'NotePublic','s.nom'=>'ThirdParty','u.lastname'=>'Lastname','u.firstname'=>'Firstname','d.dated'=>"Date"); - $this->export_entities_array[$r]=array('d.rowid'=>"Trip",'d.type'=>"Trip",'d.km'=>"Trip",'d.note'=>'Trip','d.note_public'=>'Trip','s.nom'=>'company','u.lastname'=>'user','u.firstname'=>'user','d.dated'=>"Date"); - $this->export_alias_array[$r]=array('d.rowid'=>"idtrip",'d.type'=>"type",'d.km'=>"km",'d.note'=>'note','d.note_public'=>'note_public','s.nom'=>'companyname','u.lastname'=>'name','u.firstname'=>'firstname','d.dated'=>'date'); + $this->export_fields_array[$r]=array('d.rowid'=>"TripId",'d.ref'=>'Ref','d.date_debut'=>'DateStart','d.date_fin'=>'DateEnd','d.date_create'=>'DateCreation','d.date_approve'=>'DateApprove','d.total_ht'=>"TotalHT",'d.total_tva'=>'TotalVAT','d.total_ttc'=>'TotalTTC','d.note_private'=>'NotePrivate','d.note_public'=>'NotePublic','u.lastname'=>'Lastname','u.firstname'=>'Firstname','u.login'=>"Login",'ed.rowid'=>'LineId','tf.code'=>'Type','ed.date'=>'Date','ed.fk_c_tva'=>'VATRate','ed.total_ht'=>'TotalHT','ed.total_tva'=>'TotalVAT','ed.total_ttc'=>'TotalTTC','ed.comments'=>'Comment','p.rowid'=>'ProjectId','p.ref'=>'Ref'); + $this->export_entities_array[$r]=array('u.lastname'=>'user','u.firstname'=>'user','u.login'=>'user','ed.rowid'=>'expensereport_line','ed.date'=>'expensereport_line','ed.fk_c_tva'=>'expensereport_line','ed.total_ht'=>'expensereport_line','ed.total_tva'=>'expensereport_line','ed.total_ttc'=>'expensereport_line','ed.comments'=>'expensereport_line','tf.code'=>'expensereport_line','p.project_ref'=>'expensereport_line','p.rowid'=>'project','p.ref'=>'project'); + $this->export_alias_array[$r]=array('d.rowid'=>"idtrip",'d.type'=>"type",'d.note_private'=>'note_private','d.note_public'=>'note_public','u.lastname'=>'name','u.firstname'=>'firstname','u.login'=>'login'); + $this->export_dependencies_array[$r]=array('expensereport_line'=>'ed.rowid','type_fees'=>'tf.rowid'); // To add unique key if we ask a field of a child to avoid the DISTINCT to discard them $this->export_sql_start[$r]='SELECT DISTINCT '; - $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'user as u'; - $this->export_sql_end[$r] .=', '.MAIN_DB_PREFIX.'expensereport as d'; - $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe as s ON d.fk_soc = s.rowid'; - $this->export_sql_end[$r] .=' WHERE d.fk_user = u.rowid'; - $this->export_sql_end[$r] .=' AND d.entity = '.$conf->entity; + $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'expensereport as d, '.MAIN_DB_PREFIX.'user as u,'; + $this->export_sql_end[$r] .=' '.MAIN_DB_PREFIX.'expensereport_det as ed LEFT JOIN '.MAIN_DB_PREFIX.'c_type_fees as tf ON ed.fk_c_type_fees = tf.id'; + $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'projet as p ON ed.fk_projet = p.rowid'; + $this->export_sql_end[$r] .=' WHERE ed.fk_expensereport = d.rowid AND d.fk_user_author = u.rowid'; + $this->export_sql_end[$r] .=' AND d.entity IN ('.getEntity('expensereport',1).')'; diff --git a/htdocs/core/modules/modFacture.class.php b/htdocs/core/modules/modFacture.class.php index 38a06576c9e..86762fbb87c 100644 --- a/htdocs/core/modules/modFacture.class.php +++ b/htdocs/core/modules/modFacture.class.php @@ -228,7 +228,7 @@ class modFacture extends DolibarrModules $this->export_sql_end[$r] .=' , '.MAIN_DB_PREFIX.'facturedet as fd'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product as p on (fd.fk_product = p.rowid)'; $this->export_sql_end[$r] .=' WHERE f.fk_soc = s.rowid AND f.rowid = fd.fk_facture'; - $this->export_sql_end[$r] .=' AND f.entity = '.$conf->entity; + $this->export_sql_end[$r] .=' AND f.entity IN ('.getEntity('facture',1).')'; $r++; $this->export_code[$r]=$this->rights_class.'_'.$r; @@ -284,7 +284,7 @@ class modFacture extends DolibarrModules $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'paiement_facture as pf ON pf.fk_facture = f.rowid'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'paiement as p ON pf.fk_paiement = p.rowid'; $this->export_sql_end[$r] .=' WHERE f.fk_soc = s.rowid'; - $this->export_sql_end[$r] .=' AND f.entity = '.$conf->entity; + $this->export_sql_end[$r] .=' AND f.entity IN ('.getEntity('facture',1).')'; $r++; } diff --git a/htdocs/core/modules/modFicheinter.class.php b/htdocs/core/modules/modFicheinter.class.php index 45d8a0fa7bc..7c54679bd9c 100644 --- a/htdocs/core/modules/modFicheinter.class.php +++ b/htdocs/core/modules/modFicheinter.class.php @@ -147,7 +147,7 @@ class modFicheinter extends DolibarrModules $this->export_sql_start[$r]='SELECT DISTINCT '; $this->export_sql_end[$r] =' FROM ('.MAIN_DB_PREFIX.'fichinter as f, '.MAIN_DB_PREFIX.'fichinterdet as fd, '.MAIN_DB_PREFIX.'societe as s)'; $this->export_sql_end[$r] .=' WHERE f.fk_soc = s.rowid AND f.rowid = fd.fk_fichinter'; - $this->export_sql_end[$r] .=' AND f.entity = '.$conf->entity; + $this->export_sql_end[$r] .=' AND f.entity IN ('.getEntity('intervention',1).')'; $r++; } diff --git a/htdocs/core/modules/modFournisseur.class.php b/htdocs/core/modules/modFournisseur.class.php index 656ef87c191..1f8b3af3ed6 100644 --- a/htdocs/core/modules/modFournisseur.class.php +++ b/htdocs/core/modules/modFournisseur.class.php @@ -297,7 +297,7 @@ class modFournisseur extends DolibarrModules $this->export_sql_end[$r] .=' , '.MAIN_DB_PREFIX.'facture_fourn_det as fd'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product as p on (fd.fk_product = p.rowid)'; $this->export_sql_end[$r] .=' WHERE f.fk_soc = s.rowid AND f.rowid = fd.fk_facture_fourn'; - $this->export_sql_end[$r] .=' AND f.entity = '.$conf->entity; + $this->export_sql_end[$r] .=' AND f.entity IN ('.getEntity('supplier_invoice',1).')'; $r++; $this->export_code[$r]=$this->rights_class.'_'.$r; @@ -351,7 +351,7 @@ class modFournisseur extends DolibarrModules $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf ON pf.fk_facturefourn = f.rowid'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn as p ON pf.fk_paiementfourn = p.rowid'; $this->export_sql_end[$r] .=' WHERE f.fk_soc = s.rowid'; - $this->export_sql_end[$r] .=' AND f.entity = '.$conf->entity; + $this->export_sql_end[$r] .=' AND f.entity IN ('.getEntity('supplier_invoice',1).')'; $r++; $this->export_code[$r]=$this->rights_class.'_'.$r; @@ -369,7 +369,7 @@ class modFournisseur extends DolibarrModules $this->export_sql_end[$r] .=' '.MAIN_DB_PREFIX.'commande_fournisseur as f, '.MAIN_DB_PREFIX.'commande_fournisseurdet as fd'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product as p on (fd.fk_product = p.rowid)'; $this->export_sql_end[$r] .=' WHERE f.fk_soc = s.rowid AND f.rowid = fd.fk_commande'; - $this->export_sql_end[$r] .=' AND f.entity = '.$conf->entity; + $this->export_sql_end[$r] .=' AND f.entity IN ('.getEntity('supplier_order',1).')'; } diff --git a/htdocs/core/modules/modProjet.class.php b/htdocs/core/modules/modProjet.class.php index 4a534c937cc..548306fc022 100644 --- a/htdocs/core/modules/modProjet.class.php +++ b/htdocs/core/modules/modProjet.class.php @@ -94,21 +94,21 @@ class modProjet extends DolibarrModules $this->const[$r][3] = ""; $this->const[$r][4] = 0; $r++; - + $this->const[$r][0] = "PROJECT_TASK_ADDON_PDF"; $this->const[$r][1] = "chaine"; $this->const[$r][2] = ""; $this->const[$r][3] = 'Name of PDF/ODT tasks manager class'; $this->const[$r][4] = 0; $r++; - + $this->const[$r][0] = "PROJECT_TASK_ADDON"; $this->const[$r][1] = "chaine"; $this->const[$r][2] = "mod_task_simple"; $this->const[$r][3] = 'Name of Numbering Rule task manager class'; $this->const[$r][4] = 0; $r++; - + $this->const[$r][0] = "PROJECT_TASK_ADDON_PDF_ODT_PATH"; $this->const[$r][1] = "chaine"; $this->const[$r][2] = "DOL_DATA_ROOT/doctemplates/tasks"; @@ -155,7 +155,7 @@ class modProjet extends DolibarrModules $this->rights[$r][2] = 'd'; // type de la permission (deprecie a ce jour) $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut $this->rights[$r][4] = 'export'; - + $r++; $this->rights[$r][0] = 141; // id de la permission $this->rights[$r][1] = "Lire tous les projets et tâches (y compris prives qui ne me sont pas affectes)"; // libelle de la permission @@ -189,7 +189,7 @@ class modProjet extends DolibarrModules $this->export_label[$r]='ProjectsAndTasksLines'; // Translation key (used only if key ExportDataset_xxx_z not found) $this->export_permission[$r]=array(array("projet","export")); $this->export_dependencies_array[$r]=array('task_time'=>'ppt.rowid'); - + $this->export_TypeFields_array[$r]=array('s.rowid'=>"List:societe:nom",'s.nom'=>'Text','s.address'=>'Text','s.zip'=>'Text','s.town'=>'Text','s.fk_pays'=>'List:c_country:label', 's.phone'=>'Text','s.siren'=>'Text','s.siret'=>'Text','s.ape'=>'Text','s.idprof4'=>'Text','s.code_compta'=>'Text','s.code_compta_fournisseur'=>'Text', 'p.rowid'=>"List:projet:ref",'p.ref'=>"Text",'p.datec'=>"Date",'p.dateo'=>"Date",'p.datee'=>"Date",'p.fk_statut'=>'Status','p.description'=>"Text", @@ -199,11 +199,11 @@ class modProjet extends DolibarrModules $this->export_entities_array[$r]=array('s.rowid'=>"company",'s.nom'=>'company','s.address'=>'company','s.zip'=>'company','s.town'=>'company','s.fk_pays'=>'company', 's.phone'=>'company','s.siren'=>'company','s.siret'=>'company','s.ape'=>'company','s.idprof4'=>'company','s.code_compta'=>'company','s.code_compta_fournisseur'=>'company', 'p.rowid'=>"project",'p.ref'=>"project",'p.datec'=>"project",'p.dateo'=>"project",'p.datee'=>"project",'p.duree'=>"project",'p.fk_statut'=>"project",'p.description'=>"project"); - + $this->export_fields_array[$r]=array('s.rowid'=>"IdCompany",'s.nom'=>'CompanyName','s.address'=>'Address','s.zip'=>'Zip','s.town'=>'Town','s.fk_pays'=>'Country', 's.phone'=>'Phone','s.siren'=>'ProfId1','s.siret'=>'ProfId2','s.ape'=>'ProfId3','s.idprof4'=>'ProfId4','s.code_compta'=>'CustomerAccountancyCode','s.code_compta_fournisseur'=>'SupplierAccountancyCode', 'p.rowid'=>"ProjectId",'p.ref'=>"RefProject",'p.datec'=>"DateCreation",'p.dateo'=>"DateStart",'p.datee'=>"DateEnd",'p.fk_statut'=>'Status','p.description'=>"Description"); - + // Add fields for project $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r], array()); // Add extra fields @@ -239,7 +239,7 @@ class modProjet extends DolibarrModules $this->export_entities_array[$r][$fieldname]='project'; } } - // End add extra fields + // End add extra fields // Add fields for tasks $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r], array('pt.rowid'=>'RefTask','pt.dateo'=>"TaskDateStart",'pt.datee'=>"TaskDateEnd",'pt.duration_effective'=>"DurationEffective",'pt.planned_workload'=>"PlannedWorkload",'pt.progress'=>"Progress",'pt.description'=>"TaskDescription")); @@ -277,10 +277,10 @@ class modProjet extends DolibarrModules $this->export_entities_array[$r][$fieldname]='projecttask'; } } - // End add extra fields + // End add extra fields $this->export_fields_array[$r]=array_merge($this->export_fields_array[$r], array('ptt.task_date'=>'TaskTimeDate','ptt.task_duration'=>"TimesSpent",'ptt.fk_user'=>"TaskTimeUser",'ptt.note'=>"TaskTimeNote")); $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r], array('ptt.task_date'=>'task_time','ptt.task_duration'=>"task_time",'ptt.fk_user'=>"task_time",'ptt.note'=>"task_time")); - + $this->export_sql_start[$r]='SELECT DISTINCT '; $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'projet as p'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'projet_extrafields as extra ON p.rowid = extra.fk_object'; @@ -289,7 +289,7 @@ class modProjet extends DolibarrModules $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX."projet_task_time as ptt ON pt.rowid = ptt.fk_task,"; $this->export_sql_end[$r] .=' '.MAIN_DB_PREFIX.'societe as s'; $this->export_sql_end[$r] .=' WHERE p.fk_soc = s.rowid'; - $this->export_sql_end[$r] .=' AND p.entity = '.$conf->entity; + $this->export_sql_end[$r] .=' AND p.entity IN ('.getEntity('project',1).')'; } @@ -344,12 +344,12 @@ class modProjet extends DolibarrModules return 0; } } - + $sql = array( "DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = '".$this->const[0][2]."' AND entity = ".$conf->entity, "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('".$this->const[0][2]."','invoice',".$conf->entity.")" ); - + $sql = array( "DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = '".$this->const[0][2]."' AND entity = ".$conf->entity, "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('".$this->const[0][2]."','project',".$conf->entity.")", diff --git a/htdocs/core/modules/modPropale.class.php b/htdocs/core/modules/modPropale.class.php index de1566578fe..e205c696a97 100644 --- a/htdocs/core/modules/modPropale.class.php +++ b/htdocs/core/modules/modPropale.class.php @@ -186,7 +186,7 @@ class modPropale extends DolibarrModules $this->export_sql_end[$r] .=', '.MAIN_DB_PREFIX.'propaldet as cd'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product as p on (cd.fk_product = p.rowid)'; $this->export_sql_end[$r] .=' WHERE c.fk_soc = s.rowid AND c.rowid = cd.fk_propal'; - $this->export_sql_end[$r] .=' AND c.entity = '.$conf->entity; + $this->export_sql_end[$r] .=' AND c.entity IN ('.getEntity('propal',1).')'; } diff --git a/htdocs/core/modules/modSalaries.class.php b/htdocs/core/modules/modSalaries.class.php index 35f5a145bee..2144c95b1b3 100644 --- a/htdocs/core/modules/modSalaries.class.php +++ b/htdocs/core/modules/modSalaries.class.php @@ -132,21 +132,7 @@ class modSalaries extends DolibarrModules // Exports //-------- $r=0; -/* - $r++; - $this->export_code[$r]=$this->rights_class.'_'.$r; - $this->export_label[$r]='Payment of salaries'; - $this->export_permission[$r]=array(array("tax","charges","export")); - $this->export_fields_array[$r]=array('cc.libelle'=>"Type",'c.rowid'=>"IdSocialContribution",'c.libelle'=>"Label",'c.date_ech'=>'DateDue','c.periode'=>'Period','c.amount'=>"AmountExpected","c.paye"=>"Status",'p.rowid'=>'PaymentId','p.datep'=>'DatePayment','p.amount'=>'AmountPayment','p.num_paiement'=>'Numero'); - $this->export_TypeFields_array[$r]=array('cc.libelle'=>"List:c_chargesociales:libelle:id",'c.libelle'=>"Text",'c.date_ech'=>'Date','c.periode'=>'Period','c.amount'=>"Number","c.paye"=>"Boolean",'p.datep'=>'Date','p.amount'=>'Number','p.num_paiement'=>'Number'); - $this->export_entities_array[$r]=array('cc.libelle'=>"tax_type",'c.rowid'=>"tax",'c.libelle'=>'tax','c.date_ech'=>'tax','c.periode'=>'tax','c.amount'=>"tax","c.paye"=>"tax",'p.rowid'=>'payment','p.datep'=>'payment','p.amount'=>'payment','p.num_paiement'=>'payment'); - $this->export_sql_start[$r]='SELECT DISTINCT '; - $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'c_chargesociales as cc, '.MAIN_DB_PREFIX.'chargesociales as c'; - $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'paiementcharge as p ON p.fk_charge = c.rowid'; - $this->export_sql_end[$r] .=' WHERE c.fk_type = cc.id'; - $this->export_sql_end[$r] .=' AND c.entity = '.$conf->entity; - */ } diff --git a/htdocs/core/modules/modStock.class.php b/htdocs/core/modules/modStock.class.php index 43c7cec6fb3..8f6840a21b0 100644 --- a/htdocs/core/modules/modStock.class.php +++ b/htdocs/core/modules/modStock.class.php @@ -131,7 +131,7 @@ class modStock extends DolibarrModules $this->export_sql_start[$r]='SELECT DISTINCT '; $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'product as p, '.MAIN_DB_PREFIX.'product_stock as ps, '.MAIN_DB_PREFIX.'entrepot as e'; $this->export_sql_end[$r] .=' WHERE p.rowid = ps.fk_product AND ps.fk_entrepot = e.rowid'; - $this->export_sql_end[$r] .=' AND e.entity = '.$conf->entity; + $this->export_sql_end[$r] .=' AND e.entity IN ('.getEntity('stock',1).')'; // Imports diff --git a/htdocs/core/modules/modTax.class.php b/htdocs/core/modules/modTax.class.php index f4942d567c9..6f47d66f5a9 100644 --- a/htdocs/core/modules/modTax.class.php +++ b/htdocs/core/modules/modTax.class.php @@ -133,7 +133,7 @@ class modTax extends DolibarrModules $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'c_chargesociales as cc, '.MAIN_DB_PREFIX.'chargesociales as c'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'paiementcharge as p ON p.fk_charge = c.rowid'; $this->export_sql_end[$r] .=' WHERE c.fk_type = cc.id'; - $this->export_sql_end[$r] .=' AND c.entity = '.$conf->entity; + $this->export_sql_end[$r] .=' AND c.entity IN ('.getEntity('tax',1).')'; } diff --git a/htdocs/core/modules/modUser.class.php b/htdocs/core/modules/modUser.class.php index 55e96f02262..c683c2b34cc 100644 --- a/htdocs/core/modules/modUser.class.php +++ b/htdocs/core/modules/modUser.class.php @@ -220,7 +220,7 @@ class modUser extends DolibarrModules } $this->export_sql_start[$r]='SELECT DISTINCT '; $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'user as u'; - $this->export_sql_end[$r] .=' WHERE u.entity IN (0,'.$conf->entity.')'; + $this->export_sql_end[$r] .=' WHERE u.entity IN ('.getEntity('user',1).')'; } diff --git a/htdocs/expensereport/card.php b/htdocs/expensereport/card.php index 75ab8b7cb45..8cbb25fcc53 100755 --- a/htdocs/expensereport/card.php +++ b/htdocs/expensereport/card.php @@ -33,8 +33,8 @@ require_once(DOL_DOCUMENT_ROOT."/projet/class/project.class.php"); require_once(DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'); require_once(DOL_DOCUMENT_ROOT."/core/lib/expensereport.lib.php"); require_once(DOL_DOCUMENT_ROOT."/core/lib/price.lib.php"); -dol_include_once('/expensereport/core/modules/expensereport/modules_expensereport.php'); -dol_include_once("/expensereport/class/expensereport.class.php"); +require_once(DOL_DOCUMENT_ROOT."/core/modules/expensereport/modules_expensereport.php"); +require_once(DOL_DOCUMENT_ROOT."/expensereport/class/expensereport.class.php"); $langs->load("trips"); @@ -68,13 +68,17 @@ if (! empty($conf->multicompany->enabled) && ! empty($conf->entity) && $conf->en $rootfordata.='/'.$conf->entity; } $conf->expensereport->dir_output = $rootfordata.'/expensereport'; -$conf->expensereport->dir_output = $rootfordata.'/expensereport'; // Define $urlwithroot $urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root)); $urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current +// PDF +$hidedetails = (GETPOST('hidedetails', 'int') ? GETPOST('hidedetails', 'int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0)); +$hidedesc = (GETPOST('hidedesc', 'int') ? GETPOST('hidedesc', 'int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0)); +$hideref = (GETPOST('hideref', 'int') ? GETPOST('hideref', 'int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0)); + /* @@ -83,7 +87,7 @@ $urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain if ($cancel) $action=''; -if ($action == 'confirm_delete' && $_GET["confirm"] == "yes" && $id > 0 && $user->rights->expensereport->supprimer) +if ($action == 'confirm_delete' && GETPOST("confirm") == "yes" && $id > 0 && $user->rights->expensereport->supprimer) { $object = new ExpenseReport($db); $result=$object->delete($id); @@ -171,6 +175,27 @@ if ($action == "confirm_save" && GETPOST("confirm") == "yes" && $id > 0 && $user $object = new ExpenseReport($db); $object->fetch($id); $result = $object->setValidate($user); + + if ($result > 0) + { + // Define output language + if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) + { + $outputlangs = $langs; + $newlang = ''; + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) $newlang = GETPOST('lang_id','alpha'); + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang; + if (! empty($newlang)) { + $outputlangs = new Translate("", $conf); + $outputlangs->setDefaultLang($newlang); + } + $model=$object->modelpdf; + $ret = $object->fetch($id); // Reload to get new records + + $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); + } + } + if ($result > 0 && $object->fk_user_validator > 0) { $langs->load("mails"); @@ -252,6 +277,27 @@ if ($action == "confirm_save_from_refuse" && GETPOST("confirm") == "yes" && $id $object = new ExpenseReport($db); $object->fetch($id); $result = $object->set_save_from_refuse($user); + + if ($result > 0) + { + // Define output language + if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) + { + $outputlangs = $langs; + $newlang = ''; + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) $newlang = GETPOST('lang_id','alpha'); + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang; + if (! empty($newlang)) { + $outputlangs = new Translate("", $conf); + $outputlangs->setDefaultLang($newlang); + } + $model=$object->modelpdf; + $ret = $object->fetch($id); // Reload to get new records + + $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); + } + } + if ($result > 0) { // Send mail @@ -283,7 +329,7 @@ if ($action == "confirm_save_from_refuse" && GETPOST("confirm") == "yes" && $id // Génération du pdf avant attachement $object->setDocModel($user,""); - $resultPDF = expensereport_pdf_create($db,$id,'',"",$langs); + $resultPDF = expensereport_pdf_create($db,$object,'',"",$langs); if($resultPDF): // ATTACHMENT @@ -329,6 +375,27 @@ if ($action == "confirm_approve" && GETPOST("confirm") == "yes" && $id > 0 && $u $object->fetch($id); $result = $object->setApproved($user); + + if ($result > 0) + { + // Define output language + if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) + { + $outputlangs = $langs; + $newlang = ''; + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) $newlang = GETPOST('lang_id','alpha'); + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang; + if (! empty($newlang)) { + $outputlangs = new Translate("", $conf); + $outputlangs->setDefaultLang($newlang); + } + $model=$object->modelpdf; + $ret = $object->fetch($id); // Reload to get new records + + $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); + } + } + if ($result > 0) { if (! empty($conf->global->DEPLACEMENT_TO_CLEAN)) @@ -360,7 +427,7 @@ if ($action == "confirm_approve" && GETPOST("confirm") == "yes" && $id > 0 && $u // Génération du pdf avant attachement $object->setDocModel($user,""); - $resultPDF = expensereport_pdf_create($db,$id,'',"",$langs); + $resultPDF = expensereport_pdf_create($db,$object,'',"",$langs); if($resultPDF): // ATTACHMENT @@ -412,6 +479,27 @@ if ($action == "confirm_refuse" && GETPOST('confirm')=="yes" && $id > 0 && $user $object->fetch($id); $result = $object->setDeny($user,GETPOST('detail_refuse')); + + if ($result > 0) + { + // Define output language + if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) + { + $outputlangs = $langs; + $newlang = ''; + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) $newlang = GETPOST('lang_id','alpha'); + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang; + if (! empty($newlang)) { + $outputlangs = new Translate("", $conf); + $outputlangs->setDefaultLang($newlang); + } + $model=$object->modelpdf; + $ret = $object->fetch($id); // Reload to get new records + + $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); + } + } + if ($result > 0) { if (! empty($conf->global->DEPLACEMENT_TO_CLEAN)) @@ -477,6 +565,26 @@ if ($action == "confirm_cancel" && GETPOST('confirm')=="yes" && GETPOST('detail_ { $result = $object->set_cancel($user,GETPOST('detail_cancel')); + if ($result > 0) + { + // Define output language + if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) + { + $outputlangs = $langs; + $newlang = ''; + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) $newlang = GETPOST('lang_id','alpha'); + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang; + if (! empty($newlang)) { + $outputlangs = new Translate("", $conf); + $outputlangs->setDefaultLang($newlang); + } + $model=$object->modelpdf; + $ret = $object->fetch($id); // Reload to get new records + + $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); + } + } + if ($result > 0) { if (! empty($conf->global->DEPLACEMENT_TO_CLEAN)) @@ -541,6 +649,27 @@ if ($action == "confirm_paid" && GETPOST('confirm')=="yes" && $id > 0 && $user-> $object->fetch($id); $result = $object->setPaid($user); + + if ($result > 0) + { + // Define output language + if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) + { + $outputlangs = $langs; + $newlang = ''; + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) $newlang = GETPOST('lang_id','alpha'); + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang; + if (! empty($newlang)) { + $outputlangs = new Translate("", $conf); + $outputlangs->setDefaultLang($newlang); + } + $model=$object->modelpdf; + $ret = $object->fetch($id); // Reload to get new records + + $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); + } + } + if ($result > 0) { if (! empty($conf->global->DEPLACEMENT_TO_CLEAN)) @@ -569,7 +698,7 @@ if ($action == "confirm_paid" && GETPOST('confirm')=="yes" && $id > 0 && $user-> // Génération du pdf avant attachement $object->setDocModel($user,""); - $resultPDF = expensereport_pdf_create($db,$id,'',"",$langs); + $resultPDF = expensereport_pdf_create($db,$object,'',"",$langs); // PREPARE SEND $mailfile = new CMailFile($subject,$emailTo,$emailFrom,$message); @@ -638,6 +767,27 @@ if ($action == "confirm_brouillonner" && GETPOST('confirm')=="yes" && $id > 0 && if ($user->id == $object->fk_user_author || $user->id == $object->fk_user_valid) { $result = $object->setStatut(0); + + if ($result > 0) + { + // Define output language + if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) + { + $outputlangs = $langs; + $newlang = ''; + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) $newlang = GETPOST('lang_id','alpha'); + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang; + if (! empty($newlang)) { + $outputlangs = new Translate("", $conf); + $outputlangs->setDefaultLang($newlang); + } + $model=$object->modelpdf; + $ret = $object->fetch($id); // Reload to get new records + + $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); + } + } + if ($result > 0) { header("Location: ".$_SEVER["PHP_SELF"]."?id=".$id); @@ -746,7 +896,7 @@ if ($action == "addline") $action=''; } -if ($action == 'confirm_delete_line' && $_POST["confirm"] == "yes") +if ($action == 'confirm_delete_line' && GETPOST("confirm") == "yes") { $object = new ExpenseReport($db); $object->fetch($id); @@ -759,6 +909,26 @@ if ($action == 'confirm_delete_line' && $_POST["confirm"] == "yes") $result=$object->deleteline($_GET["rowid"]); if ($result >= 0) { + if ($result > 0) + { + // Define output language + if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) + { + $outputlangs = $langs; + $newlang = ''; + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) $newlang = GETPOST('lang_id','alpha'); + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang; + if (! empty($newlang)) { + $outputlangs = new Translate("", $conf); + $outputlangs->setDefaultLang($newlang); + } + $model=$object->modelpdf; + $ret = $object->fetch($id); // Reload to get new records + + $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); + } + } + $object->update_totaux_del($object_ligne->total_ht,$object_ligne->total_tva); header("Location: ".$_SERVER["PHP_SELF"]."?id=".$_GET['id']); exit; @@ -801,6 +971,26 @@ if ($action == "updateligne" ) $result = $object->updateline($rowid, $type_fees_id, $projet_id, $c_tva, $comments, $qty, $value_unit, $date, $object_id); if ($result >= 0) { + if ($result > 0) + { + // Define output language + if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) + { + $outputlangs = $langs; + $newlang = ''; + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) $newlang = GETPOST('lang_id','alpha'); + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang; + if (! empty($newlang)) { + $outputlangs = new Translate("", $conf); + $outputlangs->setDefaultLang($newlang); + } + $model=$object->modelpdf; + $ret = $object->fetch($id); // Reload to get new records + + $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); + } + } + $object->recalculer($object_id); header("Location: ".$_SERVER["PHP_SELF"]."?id=".$object_id); exit; @@ -812,20 +1002,6 @@ if ($action == "updateligne" ) } } -if ($action == "recalc" && $id > 0) -{ - $object = new ExpenseReport($db); - $object->fetch($id); - if($object->recalculer($id) > 0) - { - header("Location: ".$_SERVER["PHP_SELF"]."?id=".$_GET['id']); - exit; - } - else - { - setEventMessages($object->error, $object->errors, 'errors'); - } -} /* * Generer ou regenerer le document PDF @@ -846,7 +1022,7 @@ if ($action == 'builddoc') // En get ou en post $outputlangs = new Translate("",$conf); $outputlangs->setDefaultLang($_REQUEST['lang_id']); } - $result=expensereport_pdf_create($db, $depl->id, '', $depl->modelpdf, $outputlangs); + $result=expensereport_pdf_create($db, $depl, '', $depl->modelpdf, $outputlangs); if ($result <= 0) { dol_print_error($db,$result); diff --git a/htdocs/expensereport/class/expensereport.class.php b/htdocs/expensereport/class/expensereport.class.php index 2523ef34154..0ebde8ac92c 100755 --- a/htdocs/expensereport/class/expensereport.class.php +++ b/htdocs/expensereport/class/expensereport.class.php @@ -24,7 +24,8 @@ class ExpenseReport extends CommonObject var $date_fin; var $fk_user_validator; - var $fk_c_expensereport_statuts; // -- 1=brouillon, 2=validé (attente approb), 4=annulé, 5=approuvé, 6=payed, 99=refusé + var $status; + var $fk_c_expensereport_statuts; // -- 1=draft, 2=validated (attente approb), 4=canceled, 5=approved, 6=payed, 99=denied var $fk_c_paiement; var $user_author_infos; @@ -467,6 +468,67 @@ class ExpenseReport extends CommonObject } + + /** + * Initialise an instance with random values. + * Used to build previews or test instances. + * id must be 0 if object instance is a specimen. + * + * @return void + */ + function initAsSpecimen() + { + global $user,$langs,$conf; + + $now=dol_now(); + + // Initialise parametres + $this->id=0; + $this->ref = 'SPECIMEN'; + $this->specimen=1; + $this->date_create = $now; + $this->date_debut = $now; + $this->date_fin = $now; + $this->date_approve = $now; + + $this->status = 5; + $this->fk_c_expensereport_statuts = 5; + + $this->fk_user_author = $user->id; + $this->fk_user_valid = $user->id; + $this->fk_user_approve = $user->id; + $this->fk_user_validator = $user->id; + + $this->note_private='Private note'; + $this->note_public='SPECIMEN'; + $nbp = 5; + $xnbp = 0; + while ($xnbp < $nbp) + { + $line=new ExpenseReportLine($this->db); + $line->comments=$langs->trans("Comment")." ".$xnbp; + $line->date=($now-3600*(1+$xnbp)); + $line->total_ht=100; + $line->total_tva=20; + $line->total_ttc=120; + $line->qty=1; + $line->fk_c_tva=20; + $line->tva_taux=20; + $line->value_unit=120; + $line->fk_expensereport=0; + $line->type_fees_code='TRA'; + + $line->projet_ref = 'ABC'; + + $this->lines[$xnbp]=$line; + $xnbp++; + + $this->total_ht+=$line->total_ht; + $this->total_tva+=$line->total_tva; + $this->total_ttc+=$line->total_ttc; + } + } + /** * fetch_line_by_project * @@ -1302,6 +1364,41 @@ class ExpenseReport extends CommonObject return -1; } } + + /** + * Create a document onto disk accordign to template module. + * + * @param string $modele Force le mnodele a utiliser ('' to not force) + * @param Translate $outputlangs objet lang a utiliser pour traduction + * @param int $hidedetails Hide details of lines + * @param int $hidedesc Hide description + * @param int $hideref Hide ref + * @return int 0 if KO, 1 if OK + */ + public function generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0) + { + global $conf,$langs; + + $langs->load("trips"); + + // Positionne le modele sur le nom du modele a utiliser + if (! dol_strlen($modele)) + { + if (! empty($conf->global->EXPENSEREPORT_ADDON_PDF)) + { + $modele = $conf->global->EXPENSEREPORT_ADDON_PDF; + } + else + { + $modele = 'standard'; + } + } + + $modelpath = "core/modules/expensereport/doc/"; + + return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref); + } + } diff --git a/htdocs/exports/export.php b/htdocs/exports/export.php index 45e78b2ecd3..ca997f0eb59 100644 --- a/htdocs/exports/export.php +++ b/htdocs/exports/export.php @@ -60,7 +60,9 @@ $entitytoicon = array( 'warehouse' => 'stock', 'category' => 'category', 'shipment' => 'sending', - 'shipment_line'=> 'sending' + 'shipment_line'=> 'sending', + 'expensereport'=> 'trip', + 'expensereport_line'=> 'trip' ); // Translation code @@ -95,7 +97,9 @@ $entitytolang = array( 'project' => 'Projects', 'projecttask' => 'Tasks', 'task_time' => 'TaskTimeSpent', - 'action' => 'Action' + 'action' => 'Action', + 'expensereport'=> 'ExpenseReport', + 'expensereport_line'=> 'ExpenseReportLine', ); $array_selected=isset($_SESSION["export_selected_fields"])?$_SESSION["export_selected_fields"]:array(); diff --git a/htdocs/install/mysql/migration/3.7.0-3.8.0.sql b/htdocs/install/mysql/migration/3.7.0-3.8.0.sql index 13c948bea56..4a71995133c 100755 --- a/htdocs/install/mysql/migration/3.7.0-3.8.0.sql +++ b/htdocs/install/mysql/migration/3.7.0-3.8.0.sql @@ -148,7 +148,7 @@ CREATE TABLE llx_expensereport ( fk_user_paid integer DEFAULT NULL, fk_c_expensereport_statuts integer NOT NULL, -- 1=brouillon, 2=validé (attente approb), 4=annulé, 5=approuvé, 6=payed, 99=refusé fk_c_paiement integer DEFAULT NULL, - note text, + note_public text, note_private text, detail_refuse varchar(255) DEFAULT NULL, detail_cancel varchar(255) DEFAULT NULL, diff --git a/htdocs/install/mysql/tables/llx_expensereport.sql b/htdocs/install/mysql/tables/llx_expensereport.sql index 7224ec38b61..e60be7251a5 100755 --- a/htdocs/install/mysql/tables/llx_expensereport.sql +++ b/htdocs/install/mysql/tables/llx_expensereport.sql @@ -46,7 +46,7 @@ CREATE TABLE llx_expensereport ( fk_user_paid integer DEFAULT NULL, fk_c_expensereport_statuts integer NOT NULL, -- 1=brouillon, 2=validé (attente approb), 4=annulé, 5=approuvé, 6=payed, 99=refusé fk_c_paiement integer DEFAULT NULL, - note text, + note_public text, note_private text, detail_refuse varchar(255) DEFAULT NULL, detail_cancel varchar(255) DEFAULT NULL, diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index 20d12072b5e..e16a0a30ccc 100755 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -1581,3 +1581,5 @@ SortOrder=Sort order Format=Format TypePaymentDesc=0:Customer payment type, 1:Supplier payment type, 2:Both customers and suppliers payment type IncludePath=Include path (defined into variable %s) +ExpenseReportsSetup=Setup of module Expense Reports +TemplatePDFExpenseReports=Document templates to generate expense report document diff --git a/htdocs/langs/en_US/trips.lang b/htdocs/langs/en_US/trips.lang index e5f683eb8fe..c84b8905562 100644 --- a/htdocs/langs/en_US/trips.lang +++ b/htdocs/langs/en_US/trips.lang @@ -27,10 +27,10 @@ AnyOtherInThisListCanValidate=Person to inform for validation. TripSociete=Information company TripSalarie=Informations user TripNDF=Informations expense report - DeleteLine=Delete a ligne of the expense report ConfirmDeleteLine=Are you sure you want to delete this line ? - +PDFStandardExpenseReports=Standard template to generate a PDF document for expense report +ExpenseReportLine=Expense report line TF_OTHER=Other TF_TRANSPORTATION=Transportation TF_LUNCH=Lunch @@ -67,10 +67,11 @@ MOTIF_REFUS=Reason MOTIF_CANCEL=Reason DATE_REFUS=Deny date -DATE_CANCEL=Cancelation date +DATE_SAVE=Validation date DATE_VALIDE=Validation date +DateApprove=Approving date +DATE_CANCEL=Cancelation date DATE_PAIEMENT=Payment date -DATE_SAVE=Recording date Deny=Deny TO_PAID=Pay