Skip to content

Commit

Permalink
Merge pull request #169 from delcroip/develop
Browse files Browse the repository at this point in the history
4.4.10
  • Loading branch information
delcroip authored Oct 17, 2021
2 parents 88e2b10 + bbd5f8e commit b365ff2
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 77 deletions.
5 changes: 5 additions & 0 deletions htdocs/timesheet/ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# dolibarr_project_timesheet changelog
4.4.10 (2021-10-16)
- fix sendapproval
- Fix: User rights for viewing PDF. #165
- FIx: SQL syntax error. #164

4.4.9 (2021-08-28)
- fix white button
- fix sunday not showed
Expand Down
196 changes: 120 additions & 76 deletions htdocs/timesheet/class/TimesheetUserTasks.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1232,85 +1232,127 @@ public function GetTimeSheetXML()
$xml .= "</timesheet>";
return $xml;
} */
/**
* function that will send email to
*
* @return bool success / failure
*/
public function sendApprovalReminders()
{
global $langs;
$ret = true;
$sql = 'SELECT';
$sql .= ' COUNT(t.rowid) as nb, ';
$sql .= ' u.email as w_email, utm.email as tm_email,';
$sql .= ' u.fk_user as approverid';
$sql .= ' FROM '.MAIN_DB_PREFIX.'project_task_time_approval as t';
$sql .= ' JOIN '.MAIN_DB_PREFIX.'user as u on t.fk_userid = u.rowid ';
$sql .= ' JOIN '.MAIN_DB_PREFIX.'user as utm on u.fk_user = utm.rowid ';
$sql .= ' WHERE (t.status='.SUBMITTED.' OR t.status='.UNDERAPPROVAL.' OR t.status='.CHALLENGED.') ';
$sql .= ' AND t.recipient='.TEAM.' GROUP BY u.fk_user';
dol_syslog(__METHOD__, LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql) {
$num = $this->db->num_rows($resql);
for($i = 0;$i<$num;$i++)
{
$obj = $this->db->fetch_object($resql);
if ($obj) {
$message = str_replace("__NB_TS__", $obj->nb, str_replace('\n', "\n", $langs->trans('YouHaveApprovalPendingMsg')));
//$message = "Bonjour, \n\nVous avez __NB_TS__ feuilles de temps à approuver, veuillez vous connecter à Dolibarr pour les approuver.\n\nCordialement.\n\nVotre administrateur Dolibarr.";
$sendto = $obj->tm_email;
$replyto = $obj->w_email;
$addr_cc = null; //$addr_cc = $obj->w_email; // uncomment if the user should be in cc
$subject = $langs->transnoentities("YouHaveApprovalPending");
if (!empty($sendto) && $sendto!="NULL") {
require_once DOL_DOCUMENT_ROOT .'/core/class/CMailFile.class.php';
$mailfile = new CMailFile(
$subject,
$sendto,
$replyto,
$message,
$filename_list = array(),
$mimetype_list = array(),
$mimefilename_list = array(),
$addr_cc, $addr_bcc = null,
$deliveryreceipt = 0,
$msgishtml = 1);
$ret = $ret && $mailfile->sendfile();
/**
* Function that will send email to
*
* @return bool success / failure
*/
public function sendApprovalReminders()
{
global $langs;
$ret = true;
$sql = 'SELECT';
$sql .= ' t.date_start, t.date_end, ';
$sql .= ' u.email as w_email, utm.email as tm_email,';
$sql .= ' u.fk_user as approverid';
$sql .= ' FROM '.MAIN_DB_PREFIX.'project_task_time_approval as t';
$sql .= ' JOIN '.MAIN_DB_PREFIX.'user as u on t.fk_userid = u.rowid ';
$sql .= ' JOIN '.MAIN_DB_PREFIX.'user as utm on u.fk_user = utm.rowid ';
$sql .= ' WHERE (t.status='.SUBMITTED.' OR t.status='.UNDERAPPROVAL.' OR t.status='.CHALLENGED.') ';
$sql .= ' AND t.recipient='.TEAM.' ORDER BY u.fk_user';
dol_syslog(__METHOD__, LOG_DEBUG);
$emails = array();
$resql = $this->db->query($sql);
if ($resql) {
$num = $this->db->num_rows($resql);
for ($i = 0;$i<$num;$i++) {
$obj = $this->db->fetch_object($resql);
$emails[$obj->tm_email][$obj->w_email][] = array(
"date_start" => $obj->date_start,
"date_end" => $obj->date_end
);
}
} else {
dol_print_error($db);
$list = array();
$ret = false;
}
if ($ret != false) {
foreach ($emails as $tm_email => $user_approuvals) {
foreach ($user_approuvals as $w_email => $dates) {
$message = str_replace(
"__NB_TS__", count($dates),
str_replace('\n', "\n", $langs->trans('YouHaveApprovalPendingMsg'))
);
foreach ($dates as $date) {
$message .= "\n * ".$date["date_start"]." - ".$date["date_end"];
}
$sendto = $tm_email;
$replyto = $w_email;
$addr_cc = null; //$addr_cc = $obj->w_email;
$subject = $langs->transnoentities("YouHaveApprovalPending");
if (!empty($sendto) && $sendto!="NULL") {
include_once DOL_DOCUMENT_ROOT .'/core/class/CMailFile.class.php';
$mailfile = new CMailFile(
$subject,
$sendto,
$replyto,
$message,
$filename_list = array(),
$mimetype_list = array(),
$mimefilename_list = array(),
$addr_cc, $addr_bcc = null,
$deliveryreceipt = 0,
$msgishtml = 1
);
$ret = $ret && $mailfile->sendfile();
}
}
}
}
} else {
$error++;
dol_print_error($db);
$list = array();
$ret = false;
return $ret;
}
return $ret;
}
/**
* function that will send email upon timesheet rejection
* @param Doliuser $user objet
* @return void
*/


/**
* Function that will send email upon timesheet not sent
* @return bool success / failure
*/
public function sendTimesheetReminders()
{
//check date: was yesterday a period end day ?
$yesteday = date("Y-m-d"); - 24 * 60 *60;
$date_end = getEndDate($yesteday);
if ($yesteday == $date_end) {
//get the list of user that have the ts right
$users = [];
//foreach user check if there is: no timesheet approaval or a tta in draft or rejected
// SELECT userid, "-1" as status FROM $user LEFT JOIN tta on userid=fk_user and $yesteray = date_end WHERE tta.id = NULL
// UNION
// SELECT userid, status FROM tta where status in (DRAFT, REJECTED) and $yesteray = date_end

//send email to user that need to submit a timesheet

}
return false;
}


/**
* Function that will send email upon timesheet rejection
* @param Doliuser $user objet
* @return void
*/
public function sendRejectedReminders($user)
{
global $langs, $db, $dolibarr_main_url_root, $dolibarr_main_url_root_alt;
$tsUser = new User($db);
$tsUser->fetch($this->userId);
$url = $dolibarr_main_url_root;
if (strpos($dolibarr_main_url_root_alt, $_SERVER['PHP_SELF'])>0) {
$url .= $dolibarr_main_url_root_alt;
}
$url .= '/timesheet/Timesheet.php?dateStart='.$this->date_start;
$message = $langs->trans('YouHaveTimesheetRejectedMsg', date(' d', $this->date_start), $url);
//$message = "Bonjour, \n\nVous avez __NB_TS__ feuilles de temps à approuver, veuillez vous connecter à Dolibarr pour les approuver.\n\nCordialement.\n\nVotre administrateur Dolibarr.";
$sendto = $tsUser->email;
$replyto = $user->email;
$subject = $langs->transnoentities("YouHaveTimesheetRejected");
if (!empty($sendto) && $sendto!="NULL") {
require_once DOL_DOCUMENT_ROOT .'/core/class/CMailFile.class.php';
$url = $dolibarr_main_url_root;
if (strpos($dolibarr_main_url_root_alt, $_SERVER['PHP_SELF'])>0) {
$url .= $dolibarr_main_url_root_alt;
}
$url .= '/timesheet/Timesheet.php?dateStart='.$this->date_start;
$message = $langs->trans(
'YouHaveTimesheetRejectedMsg',
date(' d', $this->date_start),
$url
);
$sendto = $tsUser->email;
$replyto = $user->email;
$subject = $langs->transnoentities("YouHaveTimesheetRejected");
if (!empty($sendto) && $sendto!="NULL") {
include_once DOL_DOCUMENT_ROOT .'/core/class/CMailFile.class.php';
$mailfile = new CMailFile(
$subject,
$sendto,
Expand All @@ -1322,15 +1364,17 @@ public function sendRejectedReminders($user)
$addr_cc, $addr_bcc = 0,
$deliveryreceipt = 0,
$msgishtml = 1
);
$mailfile->sendfile();
}
);
$mailfile->sendfile();
}
}


/***
/**
* Function to import the calandar item into the timesheets
* @param int $userid user to import calcandar
* @param date $datestart datestart to use for the import
* @param date $dateStart datestart to use for the import
* @param date $dateEnd dateEnd to use for the import
*/
function importCalandar($userid = '', $dateStart = '', $dateEnd = ''){
global $conf, $user;
Expand All @@ -1341,7 +1385,7 @@ function importCalandar($userid = '', $dateStart = '', $dateEnd = ''){
return -1;
}
}
if(!is_a($dateStart,'DateTime') && !is_a($dateStart,'Date' && !is_numeric($dateStart) )){
if(!is_a($dateStart,'DateTime') && !is_a($dateStart,'Date' && !is_numeric($dateStart))){
$dateStart = $this->date_start;
}
if(!is_a($dateEnd,'DateTime') && !is_a($dateEnd,'Date') && !is_numeric($dateEnd) ){
Expand Down
2 changes: 1 addition & 1 deletion htdocs/timesheet/core/modules/modtimesheet.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function __construct($db)
$this->editor_name = 'Patrick Delcroix';
$this->editor_url = 'https://github.com/delcroip';
// Possible values for version are: 'development', 'experimental', 'dolibarr' or version
$this->version = '4.4.9';
$this->version = '4.4.10';
// Key used in llx_cons table to save module status enabled/disabled(where timesheet is value of property name of module in uppercase)
$this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
// Where to store the module in setup page(0=common, 1=interface, 2=others, 3=very specific)
Expand Down

0 comments on commit b365ff2

Please sign in to comment.