Skip to content

Commit

Permalink
Merge pull request #241 from delcroip/develop
Browse files Browse the repository at this point in the history
last merge before making a dolibarr 18 only version
  • Loading branch information
delcroip authored Jan 3, 2024
2 parents ce91452 + dc2302a commit 1a24211
Show file tree
Hide file tree
Showing 12 changed files with 73 additions and 92 deletions.
2 changes: 1 addition & 1 deletion build/makepack-timesheet.conf
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ htdocs/timesheet/sql/llx_project_task_timesheet.sql
htdocs/timesheet/sql/llx_project_task_timesheet.key.sql
htdocs/timesheet/sql/llx_project_task_time_approval.sql
htdocs/timesheet/sql/llx_project_task_time_approval.key.sql
htdocs/timesheet/sql/llx_projet_task_time.key.sql
htdocs/timesheet/sql/llx_element_time.key.sql
htdocs/timesheet/sql/index.php
#mains
htdocs/timesheet/AttendanceClock.php
Expand Down
4 changes: 4 additions & 0 deletions htdocs/timesheet/ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# dolibarr_project_timesheet changelog
5.0.0
- Support Dolibarr 18


4.6.7
- support chrono on PSQL
- better chrono error management
Expand Down
7 changes: 1 addition & 6 deletions htdocs/timesheet/Timesheet.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,7 @@
$ref = dol_sanitizeFileName($object->ref);
$upload_dir = $conf->timesheet->dir_output.'/users/'
.get_exdir($object->id, 2, 0, 0, $object, 'timesheet').$ref;
if (version_compare(DOL_VERSION, "4.0") >= 0) {
include_once DOL_DOCUMENT_ROOT . '/core/actions_linkedfiles.inc.php';
} else{
include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_pre_headers.tpl.php';
//require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
}
include_once DOL_DOCUMENT_ROOT . '/core/actions_linkedfiles.inc.php';
}
/***************************************************
* VIEW
Expand Down
6 changes: 1 addition & 5 deletions htdocs/timesheet/TimesheetFavouriteAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,11 +245,7 @@
case 'create':
default:
//document handling
if (version_compare(DOL_VERSION, "4.0") >= 0) {
include_once DOL_DOCUMENT_ROOT . '/core/actions_linkedfiles.inc.php';
} else{
include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_pre_headers.tpl.php';
}
include_once DOL_DOCUMENT_ROOT . '/core/actions_linkedfiles.inc.php';
if (isset($_GET['urlfile'])) $action = 'viewdoc';
break;
}
Expand Down
33 changes: 14 additions & 19 deletions htdocs/timesheet/TimesheetProjectInvoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,18 @@
//steps
switch($step) {
case 2:
$fields = ($mode == 'user')?'fk_user':(($mode == 'taskUser')?'fk_user, fk_task':'fk_task');
$sql = 'SELECT '.$fields.', SUM(tt.task_duration) as duration, ';
$fields = ($mode == 'user')?'fk_user':(($mode == 'taskUser')?'fk_user, fk_element':'fk_element');
$sql = 'SELECT '.$fields.', SUM(tt.element_duration) as duration, ';
if ($db->type!='pgsql') {
$sql .= " GROUP_CONCAT(tt.rowid SEPARATOR ', ') as task_time_list";
} else{
$sql .= " STRING_AGG(to_char(tt.rowid, '9999999999999999'), ', ') as task_time_list";
}
$sql .= ' From '.MAIN_DB_PREFIX.'projet_task_time as tt';
$sql .= ' JOIN '.MAIN_DB_PREFIX.'projet_task as t ON tt.fk_task = t.rowid';
$sql .= ' From '.MAIN_DB_PREFIX.'element_time as tt';
$sql .= ' JOIN '.MAIN_DB_PREFIX.'projet_task as t ON tt.fk_element = t.rowid';
if ($invoicabletaskOnly == 1)$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'projet_task_extrafields as tske ON tske.fk_object = t.rowid ';
$sql .= ' WHERE t.fk_projet='.$projectId;
$sql .= " AND DATE(tt.task_datehour) BETWEEN '".$db->idate($dateStart);
$sql .= " WHERE tt.elementtype = 'task' and t.fk_projet=".$projectId;
$sql .= " AND DATE(tt.element_datehour) BETWEEN '".$db->idate($dateStart);
$sql .= "' AND '".$db->idate($dateEnd)."'";
if ($invoicabletaskOnly == 1)$sql .= ' AND tske.invoiceable = \'1\'';
if ($ts2Invoice!='all') {
Expand Down Expand Up @@ -132,12 +132,12 @@
break;
case 'taskUser':
//step 2.3 get the list of taskUser (all or approved)
$resArray[] = array("USER" => $obj->fk_user, "TASK" =>$obj->fk_task, "DURATION"=>$duration, 'LIST'=>$obj->task_time_list);
$resArray[] = array("USER" => $obj->fk_user, "TASK" =>$obj->fk_element, "DURATION"=>$duration, 'LIST'=>$obj->task_time_list);
break;
default:
case 'task':
//step 2.1 get the list of task (all or approved)
$resArray[] = array("USER" => "any", "TASK" =>$obj->fk_task, "DURATION"=>$duration, 'LIST'=>$obj->task_time_list);
$resArray[] = array("USER" => "any", "TASK" =>$obj->fk_element, "DURATION"=>$duration, 'LIST'=>$obj->task_time_list);
break;
}
$i++;
Expand Down Expand Up @@ -464,7 +464,6 @@

// End of object creation, we show it
if (1) {
if (version_compare(DOL_VERSION, "4.9.9") >= 0) {
foreach ($task_time_array AS $idLine => $task_time_list) {
//dol_syslog("ProjectInvoice::setnvoice".$idLine.' '.$task_time_list, LOG_DEBUG);
Update_task_time_invoice($id, $idLine, $task_time_list);
Expand All @@ -473,7 +472,6 @@
//dol_syslog("ProjectInvoice::setnvoice".$idLine.' '.$task_time_list, LOG_DEBUG);
Update_task_time_invoice(-1, -1, $task_time_list);
}
}
ob_start();
header('Location: ' . $object->getNomUrl(0, '', 0, 1, ''));
ob_end_flush();
Expand Down Expand Up @@ -594,14 +592,11 @@
$Form .= ($ts2Invoice == "all"?"checked":"").'> '
.$langs->trans("All")."</th></tr>";
// not alreqdy invoice
if (version_compare(DOL_VERSION, "4.9.9") >= 0) {
$Form .= '<tr class = "oddeven"><th align = "left" width = "80%">'
.$langs->trans('TimesheetNotInvoiced');
$Form .= '</th><th align = "left">'
.'<input type = "checkbox" name = "tsNotInvoiced" value = "1" ></th></tr>';
} else{
$Form .= '<input type = "hidden" name = "tsNotInvoiced" value = "0">';
}
$Form .= '<tr class = "oddeven"><th align = "left" width = "80%">'
.$langs->trans('TimesheetNotInvoiced');
$Form .= '</th><th align = "left">'
.'<input type = "checkbox" name = "tsNotInvoiced" value = "1" ></th></tr>';

//$invoicabletaskOnly
$Form .= '<tr class = "oddeven"><th align = "left" width = "80%">'.$langs->trans('InvoicableOnly');
$Form .= '</th><th align = "left"><input type = "checkbox" name = "invoicabletaskOnly" value = "1" '
Expand Down Expand Up @@ -816,7 +811,7 @@ function Update_task_time_invoice($idInvoice, $idLine, $task_time_list)
{
global $db;
$res = false;
$sql = 'UPDATE '.MAIN_DB_PREFIX.'projet_task_time';
$sql = 'UPDATE '.MAIN_DB_PREFIX.'element_time';
$sql .= " SET invoice_id = '{$idInvoice}', invoice_line_id = '{$idLine}'";
$sql .= " WHERE rowid in ({$task_time_list})";
dol_syslog("ProjectInvoice::setnvoice", LOG_DEBUG);
Expand Down
6 changes: 1 addition & 5 deletions htdocs/timesheet/TimesheetUserTasksAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,11 +247,7 @@
$ref = dol_sanitizeFileName($object->ref);
$upload_dir = $conf->timesheet->dir_output.'/tasks/'
.get_exdir($object->id, 2, 0, 0, $object, 'timesheet').$ref;
if (version_compare(DOL_VERSION, "4.0") >= 0) {
include_once DOL_DOCUMENT_ROOT . '/core/actions_linkedfiles.inc.php';
} else{
include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_pre_headers.tpl.php';
}
include_once DOL_DOCUMENT_ROOT . '/core/actions_linkedfiles.inc.php';
}
//Removing the $token array so the order can't be submitted two times
if (isset($_SESSION['timesheet'][$token])) {
Expand Down
40 changes: 18 additions & 22 deletions htdocs/timesheet/class/TimesheetReport.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public function initBasic($projectid, $userid, $name, $startDate, $stopDate, $mo
.str_replace('/', '-', dol_print_date($stopDate, 'day'));
switch($mode){
case 'PDT': //project / task / Days //FIXME dayoff missing
$this->modeSQLOrder = 'ORDER BY ptt.fk_user,tsk.fk_projet, DATE(ptt.task_datehour), tsk.rowid ASC ';
$this->modeSQLOrder = 'ORDER BY ptt.fk_user,tsk.fk_projet, DATE(ptt.element_datehour), tsk.rowid ASC ';
//title
$this->lvl0Title = 'userName';
$this->lvl1Title = 'projectLabel';
Expand All @@ -137,7 +137,7 @@ public function initBasic($projectid, $userid, $name, $startDate, $stopDate, $mo
$this->lvl2Key = 'dateDisplay';
break;
case 'DPT'://day /project /task
$this->modeSQLOrder = 'ORDER BY ptt.fk_user,DATE(ptt.task_datehour), tsk.fk_projet, tsk.rowid ASC ';
$this->modeSQLOrder = 'ORDER BY ptt.fk_user,DATE(ptt.element_datehour), tsk.fk_projet, tsk.rowid ASC ';
//title
$this->lvl0Title = 'userName';
$this->lvl1Title = 'dateDisplay';
Expand All @@ -154,7 +154,7 @@ public function initBasic($projectid, $userid, $name, $startDate, $stopDate, $mo
$this->lvl2Key = 'projectId';
break;
case 'PTD'://day /project /task
$this->modeSQLOrder = 'ORDER BY ptt.fk_user,tsk.fk_projet, tsk.rowid, DATE(ptt.task_datehour) ASC ';
$this->modeSQLOrder = 'ORDER BY ptt.fk_user,tsk.fk_projet, tsk.rowid, DATE(ptt.element_datehour) ASC ';
//title
$this->lvl0Title = 'userName';
$this->lvl1Title = 'projectLabel';
Expand All @@ -171,7 +171,7 @@ public function initBasic($projectid, $userid, $name, $startDate, $stopDate, $mo
$this->lvl2Key = 'taskId';
break;
case 'UDT': //project / task / Days //FIXME dayoff missing
$this->modeSQLOrder = 'ORDER BY tsk.fk_projet,ptt.fk_user, DATE(ptt.task_datehour), tsk.rowid ASC ';
$this->modeSQLOrder = 'ORDER BY tsk.fk_projet,ptt.fk_user, DATE(ptt.element_datehour), tsk.rowid ASC ';
//title
$this->lvl0Title = 'projectLabel';
$this->lvl1Title = 'userName';
Expand All @@ -188,7 +188,7 @@ public function initBasic($projectid, $userid, $name, $startDate, $stopDate, $mo
$this->lvl2Key = 'dateDisplay';
break;
case 'DUT'://day /project /task
$this->modeSQLOrder = 'ORDER BY tsk.fk_projet,DATE(ptt.task_datehour), ptt.fk_user, tsk.rowid ASC ';
$this->modeSQLOrder = 'ORDER BY tsk.fk_projet,DATE(ptt.element_datehour), ptt.fk_user, tsk.rowid ASC ';
//title
$this->lvl0Title = 'projectLabel';
$this->lvl1Title = 'dateDisplay';
Expand All @@ -205,7 +205,7 @@ public function initBasic($projectid, $userid, $name, $startDate, $stopDate, $mo
$this->lvl2Key = 'userId';
break;
case 'UTD'://day /project /task
$this->modeSQLOrder = ' ORDER BY tsk.fk_projet,ptt.fk_user, tsk.rowid, DATE(ptt.task_datehour) ASC ';
$this->modeSQLOrder = ' ORDER BY tsk.fk_projet,ptt.fk_user, tsk.rowid, DATE(ptt.element_datehour) ASC ';
$this->lvl0Title='projectLabel';
$this->lvl1Title = 'userName';
$this->lvl2Title = 'taskLabel';
Expand Down Expand Up @@ -235,25 +235,21 @@ public function getReportArray($forceGroup = false)
$first = true;

$sql = 'SELECT tsk.fk_projet as projectid, ptt.fk_user as userid, tsk.rowid as taskid, ';
if (version_compare(DOL_VERSION, "4.9.9") >= 0) {
$sql .= ' (ptt.invoice_id > 0 or ptt.invoice_line_id>0) AS invoiced,';
}else{
$sql .= ' 0 AS invoiced,';
}
$sql .= ' (ptt.invoice_id > 0 or ptt.invoice_line_id>0) AS invoiced,';
if ($forceGroup == 1){
if ($this->db->type!='pgsql') {
$sql .= " MAX(ptt.rowid) as id, GROUP_CONCAT(ptt.note SEPARATOR '. ') as note, MAX(tske.invoiceable) as invoicable, ";
} else {
$sql .= " MAX(ptt.rowid) as id, STRING_AGG(ptt.note, '. ') as note, MAX(tske.invoiceable) as invoicable, ";
}
$sql .= ' DATE(ptt.task_datehour) AS task_date, SUM(ptt.task_duration) as duration ';
$sql .= ' DATE(ptt.element_datehour) AS element_date, SUM(ptt.element_duration) as duration ';
}else{
$sql .= " ptt.rowid as id, ptt.note as note, tske.invoiceable as invoicable, ";
$sql .= ' DATE(ptt.task_datehour) AS task_date, ptt.task_duration as duration ';
$sql .= ' DATE(ptt.element_datehour) AS element_date, ptt.element_duration as duration ';
}
$sql .= ' FROM '.MAIN_DB_PREFIX.'projet_task_time as ptt ';
$sql .= ' JOIN '.MAIN_DB_PREFIX.'projet_task as tsk ON tsk.rowid = fk_task ';
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'projet_task_extrafields as tske ON tske.fk_object = fk_task ';
$sql .= ' FROM '.MAIN_DB_PREFIX.'element_time as ptt ';
$sql .= ' JOIN '.MAIN_DB_PREFIX."projet_task as tsk ON tsk.rowid = fk_element and elementtype = 'task' ";
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'projet_task_extrafields as tske ON tske.fk_object = tsk.rowid ';
$sql .= ' WHERE ';
if (!empty($this->userid)) {
$sql .= ' ptt.fk_user IN (\''.implode("','", array_keys($this->user)).'\') ';
Expand All @@ -270,10 +266,10 @@ public function getReportArray($forceGroup = false)
$sql .= ($first?'':'AND ').'tske.invoiceable = \'1\'';
}

$sql .= ($first?'':'AND ').' DATE(task_datehour) >= \''.$this->db->idate($this->startDate).'\'';
$sql .= ' AND DATE(task_datehour) <= \''.$this->db->idate($this->stopDate).'\'';
$sql .= ' AND (ptt.task_duration > 0 or LENGTH(ptt.note)>0)';
if ($forceGroup == 1)$sql .= ' GROUP BY ptt.fk_user, tsk.fk_projet, tsk.rowid, DATE(ptt.task_datehour), (ptt.invoice_id > 0 or ptt.invoice_line_id>0)';
$sql .= ($first?'':'AND ').' DATE(element_datehour) >= \''.$this->db->idate($this->startDate).'\'';
$sql .= ' AND DATE(element_datehour) <= \''.$this->db->idate($this->stopDate).'\'';
$sql .= ' AND (ptt.element_duration > 0 or LENGTH(ptt.note)>0)';
if ($forceGroup == 1)$sql .= ' GROUP BY ptt.fk_user, tsk.fk_projet, tsk.rowid, DATE(ptt.element_datehour), (ptt.invoice_id > 0 or ptt.invoice_line_id>0)';
$sql .= $this->modeSQLOrder;
dol_syslog(__METHOD__, LOG_DEBUG);
$resql = $this->db->query($sql);
Expand Down Expand Up @@ -333,8 +329,8 @@ public function getReportArray($forceGroup = false)
'taskRef' => $objtsk->ref,
'taskLink' => $objtsk->getNomUrl(0, "withproject", "task", getConf('TIMESHEET_HIDE_REF')),
'tasktitle' => $objtsk->label,
'date' => $this->db->jdate($obj->task_date),
'dateDisplay' => dol_print_date($this->db->jdate($obj->task_date), 'day'),
'date' => $this->db->jdate($obj->element_date),
'dateDisplay' => dol_print_date($this->db->jdate($obj->element_date), 'day'),
'duration' => $obj->duration,
'durationHours' => formatTime($obj->duration, 0),
'durationDays' => formatTime($obj->duration, -3),
Expand Down
Loading

0 comments on commit 1a24211

Please sign in to comment.