From 6961db00079bffa44d97ae180629f1c7a44f2489 Mon Sep 17 00:00:00 2001 From: De Coninck Laurent Date: Fri, 24 Feb 2017 11:01:52 +0100 Subject: [PATCH 1/6] use access right to validate expense report created for someone else --- htdocs/expensereport/card.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/expensereport/card.php b/htdocs/expensereport/card.php index dd1a86d1a74..e84cf38c15b 100644 --- a/htdocs/expensereport/card.php +++ b/htdocs/expensereport/card.php @@ -2092,7 +2092,7 @@ if ($action != 'create' && $action != 'edit') */ if ($user->rights->expensereport->creer && $object->fk_statut==0) { - if (in_array($object->fk_user_author, $user->getAllChildIds(1))) + if (in_array($object->fk_user_author, $user->getAllChildIds(1)) || !empty($user->rights->expensereport->writeall_advance)) { // Modify print '
id.'">'.$langs->trans('Modify').'
'; From 4fc046835690cb268752fb70733d998421855789 Mon Sep 17 00:00:00 2001 From: De Coninck Laurent Date: Fri, 24 Feb 2017 12:07:32 +0100 Subject: [PATCH 2/6] fix edition of expense report without vat --- htdocs/expensereport/card.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/htdocs/expensereport/card.php b/htdocs/expensereport/card.php index dd1a86d1a74..1765303f27a 100644 --- a/htdocs/expensereport/card.php +++ b/htdocs/expensereport/card.php @@ -950,7 +950,6 @@ if (empty($reshook)) // if VAT is not used in Dolibarr, set VAT rate to 0 because VAT rate is necessary. if (empty($vatrate)) $vatrate = "0.000"; - $object_ligne->vatrate = price2num($vatrate); $object_ligne->fk_projet = $fk_projet; @@ -1079,6 +1078,10 @@ if (empty($reshook)) $qty = GETPOST('qty'); $value_unit = GETPOST('value_unit'); $vatrate = GETPOST('vatrate'); + + // if VAT is not used in Dolibarr, set VAT rate to 0 because VAT rate is necessary. + if (empty($vatrate)) $vatrate = "0.000"; + $vatrate = price2num($vatrate); if (! GETPOST('fk_c_type_fees') > 0) { @@ -1086,7 +1089,7 @@ if (empty($reshook)) setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), null, 'errors'); $action=''; } - if (GETPOST('vatrate') < 0 || GETPOST('vatrate') == '') + if ((int)$vatrate < 0 || $vatrate == '') { $error++; setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Vat")), null, 'errors'); From 8be9679f84bb17843d1f2ed12abb2b4c99b5e437 Mon Sep 17 00:00:00 2001 From: De Coninck Laurent Date: Fri, 24 Feb 2017 12:31:14 +0100 Subject: [PATCH 3/6] add space --- htdocs/expensereport/card.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/expensereport/card.php b/htdocs/expensereport/card.php index 1765303f27a..6155aa31b68 100644 --- a/htdocs/expensereport/card.php +++ b/htdocs/expensereport/card.php @@ -1089,7 +1089,7 @@ if (empty($reshook)) setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), null, 'errors'); $action=''; } - if ((int)$vatrate < 0 || $vatrate == '') + if ((int) $vatrate < 0 || $vatrate == '') { $error++; setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Vat")), null, 'errors'); From 7e80505104ded651f1753be41985279e85a68141 Mon Sep 17 00:00:00 2001 From: De Coninck Laurent Date: Fri, 24 Feb 2017 13:49:34 +0100 Subject: [PATCH 4/6] prepend the author firstname and lastname for ER ref Instead of using the validator of the ER use the author firstname and last name. This is not always the case as soon ass someone can create ER for someone else --- htdocs/expensereport/class/expensereport.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/expensereport/class/expensereport.class.php b/htdocs/expensereport/class/expensereport.class.php index 4a6c9df691e..e50623a99b0 100644 --- a/htdocs/expensereport/class/expensereport.class.php +++ b/htdocs/expensereport/class/expensereport.class.php @@ -958,7 +958,7 @@ class ExpenseReport extends CommonObject { $prefix="ER"; if (! empty($conf->global->EXPENSE_REPORT_PREFIX)) $prefix=$conf->global->EXPENSE_REPORT_PREFIX; - $this->ref = strtoupper($fuser->login).$expld_car.$prefix.$this->ref.$expld_car.dol_print_date($this->date_debut,'%y%m%d'); + $this->ref = str_replace(' ','_', $this->user_author_infos).$expld_car.$prefix.$this->ref.$expld_car.dol_print_date($this->date_debut,'%y%m%d'); } require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; // We rename directory in order to avoid losing the attachments From 5733826a68a7a49fe7c2a483a512e34c7cc57423 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 24 Feb 2017 15:51:10 +0100 Subject: [PATCH 5/6] Fix do not lose the user of expense report when we edit it. --- .../class/expensereport.class.php | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/htdocs/expensereport/class/expensereport.class.php b/htdocs/expensereport/class/expensereport.class.php index 4a6c9df691e..cc10657799c 100644 --- a/htdocs/expensereport/class/expensereport.class.php +++ b/htdocs/expensereport/class/expensereport.class.php @@ -60,7 +60,7 @@ class ExpenseReport extends CommonObject // Create var $date_create; - var $fk_user_author; // the user the expense report is for (not really the author) + var $fk_user_author; // Note fk_user_author is not the 'author' but the guy the expense report is for. // Update var $date_modif; @@ -126,7 +126,7 @@ class ExpenseReport extends CommonObject $now = dol_now(); - $fuserid = $this->fk_user_author; + $fuserid = $this->fk_user_author; // Note fk_user_author is not the 'author' but the guy the expense report is for. if (empty($fuserid)) $fuserid = $user->id; $this->db->begin(); @@ -254,7 +254,7 @@ class ExpenseReport extends CommonObject $this->statut=0; // Clear fields - $this->fk_user_author = $user->id; + $this->fk_user_author = $user->id; // Note fk_user_author is not the 'author' but the guy the expense report is for. $this->fk_user_valid = ''; $this->date_create = ''; $this->date_creation = ''; @@ -301,9 +301,10 @@ class ExpenseReport extends CommonObject * update * * @param User $user User making change + * @param User $newuser New user we want to have the expense report on. * @return int <0 if KO, >0 if OK */ - function update($user) + function update($user, $userofexpensereport=null) { global $langs; @@ -313,10 +314,13 @@ class ExpenseReport extends CommonObject $sql.= " , total_tva = ".$this->total_tva; $sql.= " , date_debut = '".$this->db->idate($this->date_debut)."'"; $sql.= " , date_fin = '".$this->db->idate($this->date_fin)."'"; - $sql.= " , fk_user_author = ".($user->id > 0 ? "'".$user->id."'":"null"); + if ($userofexpensereport && is_object($userofexpensereport)) + { + $sql.= " , fk_user_author = ".($userofexpensereport->id > 0 ? "'".$userofexpensereport->id."'":"null"); // Note fk_user_author is not the 'author' but the guy the expense report is for. + } $sql.= " , fk_user_validator = ".($this->fk_user_validator > 0 ? $this->fk_user_validator:"null"); $sql.= " , fk_user_valid = ".($this->fk_user_valid > 0 ? $this->fk_user_valid:"null"); - $sql.= " , fk_user_modif = ".($this->fk_user_modif > 0 ? $this->fk_user_modif:"null"); + $sql.= " , fk_user_modif = ".$user->id; $sql.= " , fk_statut = ".($this->fk_statut >= 0 ? $this->fk_statut:'0'); $sql.= " , fk_c_paiement = ".($this->fk_c_paiement > 0 ? $this->fk_c_paiement:"null"); $sql.= " , note_public = ".(!empty($this->note_public)?"'".$this->db->escape($this->note_public)."'":"''"); @@ -388,7 +392,7 @@ class ExpenseReport extends CommonObject $this->date_refuse = $this->db->jdate($obj->date_refuse); $this->date_cancel = $this->db->jdate($obj->date_cancel); - $this->fk_user_author = $obj->fk_user_author; + $this->fk_user_author = $obj->fk_user_author; // Note fk_user_author is not the 'author' but the guy the expense report is for. $this->fk_user_modif = $obj->fk_user_modif; $this->fk_user_validator = $obj->fk_user_validator; $this->fk_user_valid = $obj->fk_user_valid; From 92acbbd8a8e3e07c2e4b7d95be06814efe406520 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 27 Feb 2017 00:20:17 +0100 Subject: [PATCH 6/6] Fix parameters --- htdocs/core/class/utils.class.php | 3 ++- htdocs/core/modules/modCron.class.php | 2 +- htdocs/cron/class/cronjob.class.php | 2 +- htdocs/langs/en_US/cron.lang | 10 +++++----- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/htdocs/core/class/utils.class.php b/htdocs/core/class/utils.class.php index 6f01a4c1406..3f1afa003a3 100644 --- a/htdocs/core/class/utils.class.php +++ b/htdocs/core/class/utils.class.php @@ -146,9 +146,10 @@ class Utils * @param string $type 'mysql', 'postgresql', ... * @param int $usedefault 1=Use default backup profile (Set this to 1 when used as cron) * @param string $file 'auto' or filename to build + * @param int $keeplastnfiles Keep only last n files (not used yet) * @return int 0 if OK, < 0 if KO (this function is used also by cron so only 0 is OK) */ - function dumpDatabase($compression='none', $type='auto', $usedefault=1, $file='auto') + function dumpDatabase($compression='none', $type='auto', $usedefault=1, $file='auto', $keeplastnfiles=0) { global $db, $conf, $langs, $dolibarr_main_data_root; global $dolibarr_main_db_name, $dolibarr_main_db_host, $dolibarr_main_db_user, $dolibarr_main_db_port, $dolibarr_main_db_pass; diff --git a/htdocs/core/modules/modCron.class.php b/htdocs/core/modules/modCron.class.php index 73b27aae96b..bd5f193c568 100644 --- a/htdocs/core/modules/modCron.class.php +++ b/htdocs/core/modules/modCron.class.php @@ -102,7 +102,7 @@ class modCron extends DolibarrModules // Cronjobs $this->cronjobs = array( 0=>array('label'=>'PurgeDeleteTemporaryFilesShort', 'jobtype'=>'method', 'class'=>'core/class/utils.class.php', 'objectname'=>'Utils', 'method'=>'purgeFiles', 'parameters'=>'', 'comment'=>'PurgeDeleteTemporaryFiles', 'frequency'=>2, 'unitfrequency'=>3600 * 24 * 7, 'priority'=>10, 'status'=>1, 'test'=>true), - 1=>array('label'=>'MakeLocalDatabaseDumpShort', 'jobtype'=>'method', 'class'=>'core/class/utils.class.php', 'objectname'=>'Utils', 'method'=>'dumpDatabase', 'parameters'=>'none', 'comment'=>'MakeLocalDatabaseDump', 'frequency'=>1, 'unitfrequency'=>3600 * 24 * 7, 'priority'=>20, 'status'=>0, 'test'=>in_array($db->type, array('mysql','mysqli'))), + 1=>array('label'=>'MakeLocalDatabaseDumpShort', 'jobtype'=>'method', 'class'=>'core/class/utils.class.php', 'objectname'=>'Utils', 'method'=>'dumpDatabase', 'parameters'=>'none,auto,1,auto,10', 'comment'=>'MakeLocalDatabaseDump', 'frequency'=>1, 'unitfrequency'=>3600 * 24 * 7, 'priority'=>20, 'status'=>0, 'test'=>in_array($db->type, array('mysql','mysqli'))), // 1=>array('label'=>'My label', 'jobtype'=>'command', 'command'=>'', 'parameters'=>'', 'comment'=>'Comment', 'frequency'=>1, 'unitfrequency'=>3600*24) ); diff --git a/htdocs/cron/class/cronjob.class.php b/htdocs/cron/class/cronjob.class.php index e532f1e23e0..59a3d025386 100644 --- a/htdocs/cron/class/cronjob.class.php +++ b/htdocs/cron/class/cronjob.class.php @@ -959,7 +959,7 @@ class Cronjob extends CommonObject // Create Object for the call module $object = new $this->objectname($this->db); - $params_arr = explode(", ",$this->params); + $params_arr = array_map('trim', explode(",",$this->params)); if (!is_array($params_arr)) { $result = call_user_func(array($object, $this->methodename), $this->params); diff --git a/htdocs/langs/en_US/cron.lang b/htdocs/langs/en_US/cron.lang index 7ee76c03395..01b69b3b839 100644 --- a/htdocs/langs/en_US/cron.lang +++ b/htdocs/langs/en_US/cron.lang @@ -58,11 +58,11 @@ CronStatusInactiveBtn=Disable CronTaskInactive=This job is disabled CronId=Id CronClassFile=Classes (filename.class.php) -CronModuleHelp=Name of Dolibarr module directory (also work with external Dolibarr module).
For exemple to fetch method of Dolibarr Product object /htdocs/product/class/product.class.php, the value of module is product -CronClassFileHelp=The file name to load.
For exemple to fetch method of Dolibarr Product object /htdocs/product/class/product.class.php, the value of class file name is product.class.php -CronObjectHelp=The object name to load.
For exemple to fetch method of Dolibarr Product object /htdocs/product/class/product.class.php, the value of class file name is Product -CronMethodHelp=The object method to launch.
For exemple to fetch method of Dolibarr Product object /htdocs/product/class/product.class.php, the value of method is is fecth -CronArgsHelp=The method arguments.
For exemple to fetch method of Dolibarr Product object /htdocs/product/class/product.class.php, the value of paramters can be 0, ProductRef +CronModuleHelp=Name of Dolibarr module directory (also work with external Dolibarr module).
For exemple to call the fetch method of Dolibarr Product object /htdocs/product/class/product.class.php, the value of module is product +CronClassFileHelp=The file name to load.
For exemple to call the fetch method of Dolibarr Product object /htdocs/product/class/product.class.php, the value of class file name is product.class.php +CronObjectHelp=The object name to load.
For exemple to call the fetch method of Dolibarr Product object /htdocs/product/class/product.class.php, the value of class file name is Product +CronMethodHelp=The object method to launch.
For exemple to call the fetch method of Dolibarr Product object /htdocs/product/class/product.class.php, the value of method is is fecth +CronArgsHelp=The method arguments.
For exemple to call the fetch method of Dolibarr Product object /htdocs/product/class/product.class.php, the value of paramters can be 0, ProductRef CronCommandHelp=The system command line to execute. CronCreateJob=Create new Scheduled Job CronFrom=From