diff --git a/htdocs/core/actions_sendmails.inc.php b/htdocs/core/actions_sendmails.inc.php
index 80385d34735..cc898d02c85 100644
--- a/htdocs/core/actions_sendmails.inc.php
+++ b/htdocs/core/actions_sendmails.inc.php
@@ -210,19 +210,17 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO
else
{
$langs->load("other");
- $mesg='
';
if ($mailfile->error)
{
+ $mesg='';
$mesg.=$langs->trans('ErrorFailedToSendMail',$from,$sendto);
$mesg.='
'.$mailfile->error;
+ setEventMessage($mesg,'errors');
}
else
{
- $mesg.='No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS';
+ setEventMessage('No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS', 'warnings');
}
- $mesg.='
';
-
- setEventMessage($mesg,'warnings');
$action = 'presend';
}
}
diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php
index 6355a871e8e..537cf68986b 100644
--- a/htdocs/core/lib/functions.lib.php
+++ b/htdocs/core/lib/functions.lib.php
@@ -4189,15 +4189,15 @@ function get_date_range($date_start,$date_end,$format = '',$outputlangs='', $wit
if ($date_start && $date_end)
{
- $out.= ($withparenthesis?' (':'').$outputlangs->trans('DateFromTo',dol_print_date($date_start, $format, false, $outputlangs),dol_print_date($date_end, $format, false, $outputlangs)).($withparenthesis?')':'');
+ $out.= ($withparenthesis?' (':'').$outputlangs->transnoentitiesnoconv('DateFromTo',dol_print_date($date_start, $format, false, $outputlangs),dol_print_date($date_end, $format, false, $outputlangs)).($withparenthesis?')':'');
}
if ($date_start && ! $date_end)
{
- $out.= ($withparenthesis?' (':'').$outputlangs->trans('DateFrom',dol_print_date($date_start, $format, false, $outputlangs)).($withparenthesis?')':'');
+ $out.= ($withparenthesis?' (':'').$outputlangs->transnoentitiesnoconv('DateFrom',dol_print_date($date_start, $format, false, $outputlangs)).($withparenthesis?')':'');
}
if (! $date_start && $date_end)
{
- $out.= ($withparenthesis?' (':'').$outputlangs->trans('DateUntil',dol_print_date($date_end, $format, false, $outputlangs)).($withparenthesis?')':'');
+ $out.= ($withparenthesis?' (':'').$outputlangs->transnoentitiesnoconv('DateUntil',dol_print_date($date_end, $format, false, $outputlangs)).($withparenthesis?')':'');
}
return $out;
diff --git a/htdocs/core/modules/modExpenseReport.class.php b/htdocs/core/modules/modExpenseReport.class.php
index b5b45ea23f8..1bf00f86f31 100755
--- a/htdocs/core/modules/modExpenseReport.class.php
+++ b/htdocs/core/modules/modExpenseReport.class.php
@@ -162,7 +162,7 @@ class modExpenseReport extends DolibarrModules
$this->rights[6][1] = 'Approve expense reports';
$this->rights[6][2] = 'w';
$this->rights[6][3] = 0;
- $this->rights[6][4] = 'to_validate';
+ $this->rights[6][4] = 'approve';
$this->rights[7][0] = 776;
$this->rights[7][1] = 'Pay expense reports';
@@ -267,7 +267,7 @@ class modExpenseReport extends DolibarrModules
'langs'=>'trips', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
'position'=>100,
'enabled'=>'$conf->expensereport->enabled', // Define condition to show or hide menu entry. Use '$conf->mymodule->enabled' if entry must be visible if module is enabled.
- 'perms'=>'$user->rights->expensereport->lire', // Use 'perms'=>'$user->rights->mymodule->level1->level2' if you want your menu with a permission rules
+ 'perms'=>'$user->rights->expensereport->approve', // Use 'perms'=>'$user->rights->mymodule->level1->level2' if you want your menu with a permission rules
'target'=>'',
'user'=>2); // 0=Menu for internal users, 1=external users, 2=both
$r++;
diff --git a/htdocs/expensereport/card.php b/htdocs/expensereport/card.php
index cfe3c86058b..75ab8b7cb45 100755
--- a/htdocs/expensereport/card.php
+++ b/htdocs/expensereport/card.php
@@ -70,6 +70,11 @@ if (! empty($conf->multicompany->enabled) && ! empty($conf->entity) && $conf->en
$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
+
/*
@@ -166,67 +171,74 @@ if ($action == "confirm_save" && GETPOST("confirm") == "yes" && $id > 0 && $user
$object = new ExpenseReport($db);
$object->fetch($id);
$result = $object->setValidate($user);
- if ($result > 0)
+ if ($result > 0 && $object->fk_user_validator > 0)
{
- // Send mail
- if (! empty($conf->global->DEPLACEMENT_TO_CLEAN))
+ $langs->load("mails");
+
+ // TO
+ $destinataire = new User($db);
+ $destinataire->fetch($object->fk_user_validator);
+ $emailTo = $destinataire->email;
+
+ // FROM
+ $expediteur = new User($db);
+ $expediteur->fetch($object->fk_user_author);
+ $emailFrom = $expediteur->email;
+
+ // SUBJECT
+ $subject = $langs->trans("ExpenseReportWaitingForApproval");
+
+ // CONTENT
+ $link = $urlwithroot.'/expenserecord/card.php?id='.$object->id;
+ $message = $langs->trans("ExpenseReportWaitingForApprovalMessage", $expediteur->getFullName($langs), get_date_range($object->date_debut,$object->date_fin,'',$langs), $link);
+
+ // Rebuild pdf
+ /*
+ $object->setDocModel($user,"");
+ $resultPDF = expensereport_pdf_create($db,$id,'',"",$langs);
+
+ if($resultPDF):
+ // ATTACHMENT
+ $filename=array(); $filedir=array(); $mimetype=array();
+ array_push($filename,dol_sanitizeFileName($object->ref).".pdf");
+ array_push($filedir,$conf->expensereport->dir_output . "/" . dol_sanitizeFileName($object->ref) . "/" . dol_sanitizeFileName($object->ref).".pdf");
+ array_push($mimetype,"application/pdf");
+ */
+
+ // PREPARE SEND
+ $mailfile = new CMailFile($subject,$emailTo,$emailFrom,$message,$filedir,$mimetype,$filename);
+
+ if ($mailfile)
{
- // Send mail
-
- // TO
- $destinataire = new User($db);
- $destinataire->fetch($object->fk_user_validator);
- $emailTo = $destinataire->email;
-
- // FROM
- $expediteur = new User($db);
- $expediteur->fetch($object->fk_user_author);
- $emailFrom = $expediteur->email;
-
- // SUBJECT
- $subject = "' ERP - Note de frais à valider";
-
- // CONTENT
- $message = "Bonjour {$destinataire->firstname},\n\n";
- $message.= "Veuillez trouver en pièce jointe une nouvelle note de frais à valider.\n";
- $message.= "- Déclarant : {$expediteur->firstname} {$expediteur->lastname}\n";
- $message.= "- Période : du {$object->date_debut} au {$object->date_fin}\n";
- $message.= "- Lien : {$dolibarr_main_url_root}/expensereport/card.php?id={$object->id}\n\n";
- $message.= "Bien cordialement,\n' SI";
-
- // Génération du pdf avant attachement
- $object->setDocModel($user,"");
- $resultPDF = expensereport_pdf_create($db,$id,'',"",$langs);
-
- if($resultPDF):
- // ATTACHMENT
- $filename=array(); $filedir=array(); $mimetype=array();
- array_push($filename,dol_sanitizeFileName($object->ref).".pdf");
- array_push($filedir,$conf->expensereport->dir_output . "/" . dol_sanitizeFileName($object->ref) . "/" . dol_sanitizeFileName($object->ref).".pdf");
- array_push($mimetype,"application/pdf");
-
- // PREPARE SEND
- $mailfile = new CMailFile($subject,$emailTo,$emailFrom,$message,$filedir,$mimetype,$filename);
-
- if(!$mailfile->error):
-
// SEND
$result=$mailfile->sendfile();
- if ($result):
- Header("Location: ".$_SEVER["PHP_SELF"]."?id=".$id);
- exit;
- endif;
-
- else:
-
- $mesg="Impossible d'envoyer l'email.";
-
- endif;
- // END - Send mail
- else:
- dol_print_error($db,$resultPDF);
- exit;
- endif;
+ if ($result)
+ {
+ $mesg=$langs->trans('MailSuccessfulySent',$mailfile->getValidAddress($emailFrom,2),$mailfile->getValidAddress($emailTo,2));
+ setEventMessage($mesg);
+ header("Location: ".$_SEVER["PHP_SELF"]."?id=".$id);
+ exit;
+ }
+ else
+ {
+ $langs->load("other");
+ if ($mailfile->error)
+ {
+ $mesg='';
+ $mesg.=$langs->trans('ErrorFailedToSendMail',$from,$sendto);
+ $mesg.='
'.$mailfile->error;
+ setEventMessage($mesg,'errors');
+ }
+ else
+ {
+ setEventMessage('No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS', 'warnings');
+ }
+ }
+ }
+ else
+ {
+ setEventMessages($mailfile->error,$mailfile->errors,'errors');
+ $action='';
}
}
else
@@ -311,7 +323,7 @@ if ($action == "confirm_save_from_refuse" && GETPOST("confirm") == "yes" && $id
}
// Approve
-if ($action == "confirm_validate" && GETPOST("confirm") == "yes" && $id > 0 && $user->rights->expensereport->to_validate)
+if ($action == "confirm_approve" && GETPOST("confirm") == "yes" && $id > 0 && $user->rights->expensereport->approve)
{
$object = new ExpenseReport($db);
$object->fetch($id);
@@ -394,7 +406,7 @@ if ($action == "confirm_validate" && GETPOST("confirm") == "yes" && $id > 0 && $
}
}
-if ($action == "confirm_refuse" && GETPOST('confirm')=="yes" && $id > 0 && $user->rights->expensereport->to_validate)
+if ($action == "confirm_refuse" && GETPOST('confirm')=="yes" && $id > 0 && $user->rights->expensereport->approve)
{
$object = new ExpenseReport($db);
$object->fetch($id);
@@ -1120,7 +1132,7 @@ else
endif;
if ($action == 'validate'):
- $ret=$form->form_confirm($_SEVER["PHP_SELF"]."?id=".$id,$langs->trans("ValideTrip"),$langs->trans("ConfirmValideTrip"),"confirm_validate","","",1);
+ $ret=$form->form_confirm($_SEVER["PHP_SELF"]."?id=".$id,$langs->trans("ValideTrip"),$langs->trans("ConfirmValideTrip"),"confirm_approve","","",1);
if ($ret == 'html') print '
';
endif;
@@ -1633,7 +1645,7 @@ if ($action != 'create' && $action != 'edit')
}
/* Si l'état est "En attente d'approbation"
- * ET user à droit de "to_validate"
+ * ET user à droit de "approve"
* ET fk_user_validator == user courant
* Afficher : "Valider" / "Refuser" / "Supprimer"
*/
@@ -1646,7 +1658,7 @@ if ($action != 'create' && $action != 'edit')
}
}
- if ($user->rights->expensereport->to_validate && $object->fk_c_expensereport_statuts == 2)
+ if ($user->rights->expensereport->approve && $object->fk_c_expensereport_statuts == 2)
{
//if($object->fk_user_validator==$user->id)
//{
@@ -1692,11 +1704,11 @@ if ($action != 'create' && $action != 'edit')
}
/* Si l'état est "Payée"
- * ET user à droit "to_validate"
+ * ET user à droit "approve"
* ET user à droit "to_paid"
* Afficher : "Annuler"
*/
- if ($user->rights->expensereport->to_validate && $user->rights->expensereport->to_paid && $object->fk_c_expensereport_statuts==6)
+ if ($user->rights->expensereport->approve && $user->rights->expensereport->to_paid && $object->fk_c_expensereport_statuts==6)
{
// Annuler
print ''.$langs->trans('Cancel').'';
diff --git a/htdocs/expensereport/class/expensereport.class.php b/htdocs/expensereport/class/expensereport.class.php
index 40be7298a1c..2523ef34154 100755
--- a/htdocs/expensereport/class/expensereport.class.php
+++ b/htdocs/expensereport/class/expensereport.class.php
@@ -790,7 +790,7 @@ class ExpenseReport extends CommonObject
}
/**
- * set_to_validate
+ * set_save_from_refuse
*
* @param User $user User
* @return int <0 if KO, >0 if OK
@@ -971,38 +971,6 @@ class ExpenseReport extends CommonObject
}
}
- /**
- * set_to_validate
- *
- * @param User $user User
- * @return int <0 if KO, >0 if OK
- */
- function set_to_valide($user)
- {
- if ($this->fk_c_expensereport_statuts != 2)
- {
- $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
- $sql.= " SET fk_c_expensereport_statuts = 2, fk_user_validator = ".$this->fk_user_validator;
- $sql.= ' WHERE rowid = '.$this->id;
-
- dol_syslog(get_class($this)."::set_to_valide sql=".$sql, LOG_DEBUG);
-
- if ($this->db->query($sql))
- {
- return 1;
- }
- else
- {
- $this->error=$this->db->error();
- return -1;
- }
- }
- else
- {
- dol_syslog(get_class($this)."::set_to_valide expensereport already with to-valide status", LOG_WARNING);
- }
- }
-
/**
* set_cancel
*
@@ -1312,7 +1280,7 @@ class ExpenseReport extends CommonObject
$sql = "SELECT fk_user";
$sql.= " FROM ".MAIN_DB_PREFIX."user_rights as ur, ".MAIN_DB_PREFIX."rights_def as rd";
- $sql.= " WHERE ur.fk_id = rd.id and module = 'expensereport' AND perms = 'to_validate'"; // Permission 'Approve';
+ $sql.= " WHERE ur.fk_id = rd.id and module = 'expensereport' AND perms = 'approve'"; // Permission 'Approve';
dol_syslog(get_class($this)."::fetch_users_approver_expensereport sql=".$sql);
$result = $this->db->query($sql);
diff --git a/htdocs/expensereport/class/expensereportstats.class.php b/htdocs/expensereport/class/expensereportstats.class.php
index e12b4ed2a79..9536d59937d 100644
--- a/htdocs/expensereport/class/expensereportstats.class.php
+++ b/htdocs/expensereport/class/expensereportstats.class.php
@@ -49,7 +49,7 @@ class ExpenseReportStats extends Stats
*/
function __construct($db, $socid=0, $userid=0)
{
- global $conf;
+ global $conf, $user;
$this->db = $db;
$this->socid = $socid;
@@ -65,7 +65,16 @@ class ExpenseReportStats extends Stats
{
$this->where.=" AND fk_soc = ".$this->socid;
}
- if ($this->userid > 0) $this->where.=' AND fk_user_author = '.$this->userid;
+
+ // Only me and subordinates
+ if (empty($user->rights->expensereport->readall) && empty($user->rights->expensereport->lire_tous))
+ {
+ $childids = $user->getAllChildIds();
+ $childids[]=$user->id;
+ $this->where.=" AND fk_user_author IN (".(join(',',$childids)).")";
+ }
+
+ if ($this->userid > 0) $this->where.=' AND fk_user_author = '.$this->userid;
}
diff --git a/htdocs/expensereport/index.php b/htdocs/expensereport/index.php
index 2ea024fb3b0..89469609e2a 100644
--- a/htdocs/expensereport/index.php
+++ b/htdocs/expensereport/index.php
@@ -69,7 +69,13 @@ $totalnb=$totalsum=0;
$sql = "SELECT tf.code, tf.label, count(de.rowid) as nb, sum(de.total_ht) as km";
$sql.= " FROM ".MAIN_DB_PREFIX."expensereport as d, ".MAIN_DB_PREFIX."expensereport_det as de, ".MAIN_DB_PREFIX."c_type_fees as tf";
$sql.= " WHERE de.fk_expensereport = d.rowid AND de.fk_c_type_fees = tf.id";
-if (empty($user->rights->expensereport->readall) && empty($user->rights->expensereport->lire_tous)) $sql.=' AND d.fk_user_author IN ('.join(',',$childids).')';
+
+// RESTRICT RIGHTS
+if (empty($user->rights->expensereport->readall) && empty($user->rights->expensereport->lire_tous))
+{
+ $sql.= " AND d.fk_user_author IN (".join(',',$childids).")\n";
+}
+
$sql.= " GROUP BY tf.code, tf.label";
$result = $db->query($sql);
diff --git a/htdocs/expensereport/list.php b/htdocs/expensereport/list.php
index 348c564812e..d71a9410c9f 100755
--- a/htdocs/expensereport/list.php
+++ b/htdocs/expensereport/list.php
@@ -48,7 +48,7 @@ $html = new Form($db);
$formother = new FormOther($db);
$expensereporttmp=new ExpenseReport($db);
-llxHeader();
+llxHeader('', $langs->trans("ListOfExpenseReports"));
$max_year = 5;
$min_year = 5;
@@ -84,13 +84,14 @@ $sql.= " u.rowid as id_user, u.firstname, u.lastname";
$sql.= " FROM ".MAIN_DB_PREFIX."expensereport d\n";
$sql.= " INNER JOIN ".MAIN_DB_PREFIX."user u ON d.fk_user_author = u.rowid\n";
+
+
// WHERE
if(!empty($search_ref)){
$sql.= " WHERE d.ref LIKE '%".$db->escape($search_ref)."%'\n";
}else{
$sql.= " WHERE 1 = 1\n";
}
-
// DATE START
if ($month_start > 0) {
if ($year_start > 0) {
@@ -148,13 +149,15 @@ if ($month_start > 0) {
}
}
}
-
-if (!empty($search_user) && $search_user != -1) $sql.= " AND d.fk_user_author = '$search_user'\n";
+if (!empty($search_user) && $search_user > 0) $sql.= " AND d.fk_user_author = ".$search_user."\n";
if($search_state != '') $sql.= " AND d.fk_c_expensereport_statuts = '$search_state'\n";
// RESTRICT RIGHTS
-if (empty($user->rights->expensereport->readall) && empty($user->rights->expensereport->lire_tous)){
- $sql.= " AND d.fk_user_author = '{$user->id}'\n";
+if (empty($user->rights->expensereport->readall) && empty($user->rights->expensereport->lire_tous))
+{
+ $childids = $user->getAllChildIds();
+ $childids[]=$user->id;
+ $sql.= " AND d.fk_user_author IN (".join(',',$childids).")\n";
}
$sql.= $db->order($sortfield,$sortorder);
diff --git a/htdocs/expensereport/stats/index.php b/htdocs/expensereport/stats/index.php
index 07843985b00..402eb56e01b 100755
--- a/htdocs/expensereport/stats/index.php
+++ b/htdocs/expensereport/stats/index.php
@@ -222,7 +222,9 @@ print '';
*/
// User
print '| '.$langs->trans("User").' | ';
-print $form->select_dolusers($userid,'userid',1);
+$include='';
+if (empty($user->rights->expensereport->readall) && empty($user->rights->expensereport->lire_tous)) $include='hierarchy';
+print $form->select_dolusers($userid,'userid',1,'',0,$include);
print ' |
';
// Year
print '| '.$langs->trans("Year").' | ';
diff --git a/htdocs/langs/en_US/trips.lang b/htdocs/langs/en_US/trips.lang
index c31b902805e..e5f683eb8fe 100644
--- a/htdocs/langs/en_US/trips.lang
+++ b/htdocs/langs/en_US/trips.lang
@@ -20,7 +20,8 @@ ListToApprove=Waiting for approval
ExpensesArea=Expense reports area
SearchATripAndExpense=Search an expense report
ClassifyRefunded=Classify 'Refunded'
-
+ExpenseReportWaitingForApproval=A new expense report has been submitted for approval
+ExpenseReportWaitingForApprovalMessage=A new expense report has been submitted and is waiting for approval.\n- User: %s\n- Period: %s\nClick here to validate: %s
TripId=Id expense report
AnyOtherInThisListCanValidate=Person to inform for validation.
TripSociete=Information company
diff --git a/htdocs/user/class/user.class.php b/htdocs/user/class/user.class.php
index 16123c86b9c..babac9c33ba 100644
--- a/htdocs/user/class/user.class.php
+++ b/htdocs/user/class/user.class.php
@@ -2211,7 +2211,7 @@ class User extends CommonObject
/**
- * Return and array with all instanciated children users of current user
+ * Return and array with all instanciated first level children users of current user
*
* @return void
*/
@@ -2365,7 +2365,7 @@ class User extends CommonObject
}
/**
- * Return list of all childs users in herarchy.
+ * Return list of all child users id in herarchy (all sublevels).
*
* @return array Array of user id lower than user. This overwrite this->users.
*/
|