2009-07-28 02:52:34 +02:00
< ? php
2012-04-18 11:16:15 +02:00
/* Copyright ( C ) 2005 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2021-12-20 17:50:59 +01:00
* Copyright ( C ) 2006 - 2021 Laurent Destailleur < eldy @ users . sourceforge . net >
2018-10-27 14:43:12 +02:00
* Copyright ( C ) 2010 - 2012 Regis Houssin < regis . houssin @ inodbox . com >
2013-10-30 21:44:04 +01:00
* Copyright ( C ) 2011 Juanjo Menent < jmenent @ 2 byte . es >
2018-04-20 10:38:16 +02:00
* Copyright ( C ) 2018 Ferran Marcet < fmarcet @ 2 byte . es >
2018-09-09 10:40:00 +02:00
* Copyright ( C ) 2018 Frédéric France < frederic . france @ netlogic . fr >
2021-06-29 15:26:04 +02:00
* Copyright ( C ) 2019 - 2021 Christophe Battarel < christophe @ altairis . fr >
2013-10-30 21:44:04 +01:00
*
* 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
2019-09-23 21:55:30 +02:00
* along with this program . If not , see < https :// www . gnu . org / licenses />.
2013-10-30 21:44:04 +01:00
*/
2009-07-28 02:52:34 +02:00
/**
2019-12-29 20:47:18 +01:00
* \file htdocs / projet / tasks / time . php
* \ingroup project
* \brief Page to add new time spent on a task
2013-10-30 21:44:04 +01:00
*/
2009-07-28 02:52:34 +02:00
2012-08-22 23:24:21 +02:00
require '../../main.inc.php' ;
2012-08-22 23:11:24 +02:00
require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/projet/class/task.class.php' ;
2019-05-04 11:18:14 +02:00
require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php' ;
2012-08-22 23:11:24 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/project.lib.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php' ;
2014-09-29 16:25:18 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formother.class.php' ;
2018-02-26 11:57:29 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formprojet.class.php' ;
2021-06-30 10:56:09 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formintervention.class.php' ;
2009-07-28 02:52:34 +02:00
2018-05-26 21:11:25 +02:00
// Load translation files required by the page
2021-03-11 19:09:42 +01:00
$langsLoad = array ( 'projects' , 'bills' , 'orders' );
if ( ! empty ( $conf -> eventorganization -> enabled )) {
$langsLoad [] = 'eventorganization' ;
}
$langs -> loadLangs ( $langsLoad );
2010-03-01 20:36:58 +01:00
2019-12-29 20:47:18 +01:00
$action = GETPOST ( 'action' , 'alpha' );
2019-11-13 19:35:02 +01:00
$massaction = GETPOST ( 'massaction' , 'alpha' ); // The bulk action (combo box choice into lists)
2019-12-29 20:47:18 +01:00
$confirm = GETPOST ( 'confirm' , 'alpha' );
$cancel = GETPOST ( 'cancel' , 'alpha' );
2020-01-30 01:48:28 +01:00
$toselect = GETPOST ( 'toselect' , 'array' ); // Array of ids of elements selected into a list
2020-09-25 10:27:30 +02:00
$contextpage = GETPOST ( 'contextpage' , 'aZ' ) ? GETPOST ( 'contextpage' , 'aZ' ) : 'timespentlist' ; // To manage different context of search
2019-11-13 19:35:02 +01:00
$backtopage = GETPOST ( 'backtopage' , 'alpha' ); // Go back to a dedicated page
2019-12-29 20:47:18 +01:00
$optioncss = GETPOST ( 'optioncss' , 'alpha' );
2023-04-26 10:25:08 +02:00
$mode = GETPOST ( 'mode' , 'alpha' );
2019-01-27 11:55:16 +01:00
2019-12-29 20:47:18 +01:00
$id = GETPOST ( 'id' , 'int' );
$projectid = GETPOST ( 'projectid' , 'int' );
$ref = GETPOST ( 'ref' , 'alpha' );
2019-11-13 19:35:02 +01:00
$withproject = GETPOST ( 'withproject' , 'int' );
$project_ref = GETPOST ( 'project_ref' , 'alpha' );
2020-04-15 14:54:54 +02:00
$tab = GETPOST ( 'tab' , 'aZ09' );
2019-11-13 19:35:02 +01:00
$search_day = GETPOST ( 'search_day' , 'int' );
$search_month = GETPOST ( 'search_month' , 'int' );
$search_year = GETPOST ( 'search_year' , 'int' );
$search_datehour = '' ;
$search_datewithhour = '' ;
$search_note = GETPOST ( 'search_note' , 'alpha' );
$search_duration = GETPOST ( 'search_duration' , 'int' );
$search_value = GETPOST ( 'search_value' , 'int' );
$search_task_ref = GETPOST ( 'search_task_ref' , 'alpha' );
$search_task_label = GETPOST ( 'search_task_label' , 'alpha' );
$search_user = GETPOST ( 'search_user' , 'int' );
$search_valuebilled = GETPOST ( 'search_valuebilled' , 'int' );
2016-08-30 20:17:34 +02:00
2019-11-13 19:35:02 +01:00
$limit = GETPOST ( 'limit' , 'int' ) ? GETPOST ( 'limit' , 'int' ) : $conf -> liste_limit ;
2022-01-13 11:09:37 +01:00
$sortfield = GETPOST ( 'sortfield' , 'aZ09comma' );
$sortorder = GETPOST ( 'sortorder' , 'aZ09comma' );
2020-03-13 13:07:11 +01:00
$page = GETPOSTISSET ( 'pageplusone' ) ? ( GETPOST ( 'pageplusone' ) - 1 ) : GETPOST ( " page " , 'int' );
2021-02-26 18:49:22 +01:00
if ( empty ( $page ) || $page == - 1 ) {
$page = 0 ;
} // If $page is not defined, or '' or -1
2016-08-30 20:17:34 +02:00
$offset = $limit * $page ;
$pageprev = $page - 1 ;
$pagenext = $page + 1 ;
2021-02-26 18:49:22 +01:00
if ( ! $sortfield ) {
$sortfield = 't.task_date,t.task_datehour,t.rowid' ;
}
if ( ! $sortorder ) {
$sortorder = 'DESC,DESC,DESC' ;
}
2016-08-30 20:17:34 +02:00
2022-01-21 16:22:59 +01:00
$childids = $user -> getAllChildIds ( 1 );
2017-06-10 12:56:28 +02:00
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
2018-03-31 18:48:27 +02:00
//$object = new TaskTime($db);
2019-11-13 19:35:02 +01:00
$hookmanager -> initHooks ( array ( 'projecttasktime' , 'globalcard' ));
2016-08-30 20:16:58 +02:00
2012-04-18 11:16:15 +02:00
$object = new Task ( $db );
2019-10-22 17:08:37 +02:00
$extrafields = new ExtraFields ( $db );
2022-07-26 11:04:52 +02:00
$projectstatic = new Project ( $db );
// fetch optionals attributes and labels
2019-10-22 17:08:37 +02:00
$extrafields -> fetch_name_optionals_label ( $projectstatic -> table_element );
$extrafields -> fetch_name_optionals_label ( $object -> table_element );
2012-04-18 11:16:15 +02:00
2021-12-20 17:50:59 +01:00
// Load task
2021-09-19 01:30:39 +02:00
if ( $id > 0 || $ref ) {
$object -> fetch ( $id , $ref );
}
2022-01-21 16:22:59 +01:00
// Security check
$socid = 0 ;
//if ($user->socid > 0) $socid = $user->socid; // For external user, no check is done on company because readability is managed by public status of project and assignement.
if ( ! $user -> rights -> projet -> lire ) {
accessforbidden ();
}
2021-12-20 17:50:59 +01:00
if ( $object -> fk_project > 0 ) {
restrictedArea ( $user , 'projet' , $object -> fk_project , 'projet&project' );
} else {
restrictedArea ( $user , 'projet' , null , 'projet&project' );
2022-01-21 16:22:59 +01:00
// We check user has permission to see all tasks of all users
2021-12-20 17:50:59 +01:00
if ( empty ( $projectid ) && ! $user -> hasRight ( 'projet' , 'all' , 'lire' )) {
$search_user = $user -> id ;
}
}
2021-09-19 01:30:39 +02:00
2010-05-30 14:21:32 +02:00
2009-07-28 02:52:34 +02:00
/*
* Actions
2014-10-03 03:42:11 +02:00
*/
2012-04-18 12:15:14 +02:00
2021-02-26 18:49:22 +01:00
if ( GETPOST ( 'cancel' , 'alpha' )) {
$action = '' ;
}
2021-06-29 15:26:04 +02:00
if ( ! GETPOST ( 'confirmmassaction' , 'alpha' ) && $massaction != 'presend' && $massaction != 'confirm_presend' && $massaction != 'confirm_generateinvoice' && $massaction != 'confirm_generateinter' ) {
2021-02-26 18:49:22 +01:00
$massaction = '' ;
}
2018-02-26 11:57:29 +01:00
2019-11-13 19:35:02 +01:00
$parameters = array ( 'socid' => $socid , 'projectid' => $projectid );
$reshook = $hookmanager -> executeHooks ( 'doActions' , $parameters , $object , $action ); // Note that $action and $object may have been modified by some hooks
2021-02-26 18:49:22 +01:00
if ( $reshook < 0 ) {
setEventMessages ( $hookmanager -> error , $hookmanager -> errors , 'errors' );
}
2016-08-30 20:17:34 +02:00
include DOL_DOCUMENT_ROOT . '/core/actions_changeselectedfields.inc.php' ;
// Purge search criteria
2021-02-26 18:49:22 +01:00
if ( GETPOST ( 'button_removefilter_x' , 'alpha' ) || GETPOST ( 'button_removefilter.x' , 'alpha' ) || GETPOST ( 'button_removefilter' , 'alpha' )) { // All tests are required to be compatible with all browsers
2019-11-13 19:35:02 +01:00
$search_day = '' ;
$search_month = '' ;
$search_year = '' ;
$search_date = '' ;
2019-12-29 20:47:18 +01:00
$search_datehour = '' ;
$search_datewithhour = '' ;
$search_note = '' ;
$search_duration = '' ;
$search_value = '' ;
$search_date_creation = '' ;
$search_date_update = '' ;
$search_task_ref = '' ;
$search_task_label = '' ;
2022-12-14 16:04:35 +01:00
$search_user = - 1 ;
2019-12-29 20:47:18 +01:00
$search_valuebilled = '' ;
2022-05-08 18:25:22 +02:00
$toselect = array ();
2019-12-29 20:47:18 +01:00
$search_array_options = array ();
$action = '' ;
2016-08-30 20:17:34 +02:00
}
2021-07-16 11:14:30 +02:00
if ( $action == 'addtimespent' && $user -> rights -> projet -> time ) {
2019-11-13 19:35:02 +01:00
$error = 0 ;
2010-02-28 02:33:12 +01:00
2019-01-27 11:55:16 +01:00
$timespent_durationhour = GETPOST ( 'timespent_durationhour' , 'int' );
$timespent_durationmin = GETPOST ( 'timespent_durationmin' , 'int' );
2021-02-26 18:49:22 +01:00
if ( empty ( $timespent_durationhour ) && empty ( $timespent_durationmin )) {
2019-01-27 11:55:16 +01:00
setEventMessages ( $langs -> trans ( 'ErrorFieldRequired' , $langs -> transnoentitiesnoconv ( " Duration " )), null , 'errors' );
2010-02-28 02:33:12 +01:00
$error ++ ;
}
2021-03-24 19:53:31 +01:00
if ( ! GETPOST ( " userid " , 'int' )) {
2014-08-07 12:05:42 +02:00
$langs -> load ( " errors " );
2015-12-17 14:14:44 +01:00
setEventMessages ( $langs -> trans ( 'ErrorUserNotAssignedToTask' ), null , 'errors' );
2010-05-30 22:25:08 +02:00
$error ++ ;
}
2010-02-28 02:33:12 +01:00
2021-02-26 18:49:22 +01:00
if ( ! $error ) {
if ( $id || $ref ) {
2018-02-26 11:57:29 +01:00
$object -> fetch ( $id , $ref );
2020-05-21 15:05:19 +02:00
} else {
2021-02-26 18:49:22 +01:00
if ( ! GETPOST ( 'taskid' , 'int' ) || GETPOST ( 'taskid' , 'int' ) < 0 ) {
2019-12-29 20:47:18 +01:00
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " Task " )), null , 'errors' );
$action = 'createtime' ;
$error ++ ;
2020-05-21 15:05:19 +02:00
} else {
2019-12-29 20:47:18 +01:00
$object -> fetch ( GETPOST ( 'taskid' , 'int' ));
}
2018-02-26 11:57:29 +01:00
}
2010-02-25 10:44:58 +01:00
2021-02-26 18:49:22 +01:00
if ( ! $error ) {
2019-12-29 20:47:18 +01:00
$object -> fetch_projet ();
2021-02-26 18:49:22 +01:00
if ( empty ( $object -> project -> statut )) {
2019-12-29 20:47:18 +01:00
setEventMessages ( $langs -> trans ( " ProjectMustBeValidatedFirst " ), null , 'errors' );
$action = 'createtime' ;
$error ++ ;
2020-05-21 15:05:19 +02:00
} else {
2021-03-29 21:47:31 +02:00
$object -> timespent_note = GETPOST ( " timespent_note " , 'alpha' );
2021-02-26 18:49:22 +01:00
if ( GETPOST ( 'progress' , 'int' ) > 0 ) {
$object -> progress = GETPOST ( 'progress' , 'int' ); // If progress is -1 (not defined), we do not change value
}
2021-03-25 01:07:29 +01:00
$object -> timespent_duration = GETPOSTINT ( " timespent_durationhour " ) * 60 * 60 ; // We store duration in seconds
$object -> timespent_duration += ( GETPOSTINT ( 'timespent_durationmin' ) ? GETPOSTINT ( 'timespent_durationmin' ) : 0 ) * 60 ; // We store duration in seconds
2021-02-26 18:49:22 +01:00
if ( GETPOST ( " timehour " ) != '' && GETPOST ( " timehour " ) >= 0 ) { // If hour was entered
2021-05-18 13:36:07 +02:00
$object -> timespent_date = dol_mktime ( GETPOST ( " timehour " , 'int' ), GETPOST ( " timemin " , 'int' ), 0 , GETPOST ( " timemonth " , 'int' ), GETPOST ( " timeday " , 'int' ), GETPOST ( " timeyear " , 'int' ));
2019-12-29 20:47:18 +01:00
$object -> timespent_withhour = 1 ;
2020-05-21 15:05:19 +02:00
} else {
2021-05-18 13:36:07 +02:00
$object -> timespent_date = dol_mktime ( 12 , 0 , 0 , GETPOST ( " timemonth " , 'int' ), GETPOST ( " timeday " , 'int' ), GETPOST ( " timeyear " , 'int' ));
2019-12-29 20:47:18 +01:00
}
2021-03-24 19:53:31 +01:00
$object -> timespent_fk_user = GETPOST ( " userid " , 'int' );
2019-12-29 20:47:18 +01:00
$result = $object -> addTimeSpent ( $user );
2021-02-26 18:49:22 +01:00
if ( $result >= 0 ) {
2019-12-29 20:47:18 +01:00
setEventMessages ( $langs -> trans ( " RecordSaved " ), null , 'mesgs' );
2020-05-21 15:05:19 +02:00
} else {
2019-12-29 20:47:18 +01:00
setEventMessages ( $langs -> trans ( $object -> error ), null , 'errors' );
$error ++ ;
}
}
2010-02-28 02:33:12 +01:00
}
2020-05-21 15:05:19 +02:00
} else {
2021-02-26 18:49:22 +01:00
if ( empty ( $id )) {
$action = 'createtime' ;
} else {
$action = 'createtime' ;
}
2010-02-25 10:44:58 +01:00
}
}
2021-02-26 18:49:22 +01:00
if (( $action == 'updateline' || $action == 'updatesplitline' ) && ! $cancel && $user -> rights -> projet -> lire ) {
2019-11-13 19:35:02 +01:00
$error = 0 ;
2010-03-01 17:42:02 +01:00
2021-02-26 18:49:22 +01:00
if ( ! GETPOST ( " new_durationhour " ) && ! GETPOST ( " new_durationmin " )) {
2019-01-27 11:55:16 +01:00
setEventMessages ( $langs -> trans ( 'ErrorFieldRequired' , $langs -> transnoentitiesnoconv ( " Duration " )), null , 'errors' );
2010-03-01 17:42:02 +01:00
$error ++ ;
}
2010-02-28 02:33:12 +01:00
2021-02-26 18:49:22 +01:00
if ( ! $error ) {
if ( GETPOST ( 'taskid' , 'int' ) != $id ) { // GETPOST('taskid') is id of new task
2022-06-09 12:05:23 +02:00
$id_temp = GETPOST ( 'taskid' , 'int' ); // should not overwrite $id
2022-06-09 12:09:49 +02:00
2019-11-22 15:18:09 +01:00
2019-11-22 15:14:55 +01:00
$object -> fetchTimeSpent ( GETPOST ( 'lineid' , 'int' ));
2022-01-21 16:22:59 +01:00
$result = 0 ;
if ( in_array ( $object -> timespent_fk_user , $childids ) || $user -> rights -> projet -> all -> creer ) {
$result = $object -> delTimeSpent ( $user );
}
2019-11-22 15:18:09 +01:00
2022-06-09 12:05:23 +02:00
$object -> fetch ( $id_temp , $ref );
2022-01-21 16:22:59 +01:00
2022-06-20 02:10:27 +02:00
$object -> timespent_note = GETPOST ( " timespent_note_line " , " alphanohtml " );
$object -> timespent_old_duration = GETPOST ( " old_duration " , " int " );
2021-03-25 01:07:29 +01:00
$object -> timespent_duration = GETPOSTINT ( " new_durationhour " ) * 60 * 60 ; // We store duration in seconds
$object -> timespent_duration += ( GETPOSTINT ( " new_durationmin " ) ? GETPOSTINT ( 'new_durationmin' ) : 0 ) * 60 ; // We store duration in seconds
2021-02-26 18:49:22 +01:00
if ( GETPOST ( " timelinehour " ) != '' && GETPOST ( " timelinehour " ) >= 0 ) { // If hour was entered
2019-11-22 15:14:55 +01:00
$object -> timespent_date = dol_mktime ( GETPOST ( " timelinehour " ), GETPOST ( " timelinemin " ), 0 , GETPOST ( " timelinemonth " ), GETPOST ( " timelineday " ), GETPOST ( " timelineyear " ));
$object -> timespent_withhour = 1 ;
2020-05-21 15:05:19 +02:00
} else {
2019-11-22 15:14:55 +01:00
$object -> timespent_date = dol_mktime ( 12 , 0 , 0 , GETPOST ( " timelinemonth " ), GETPOST ( " timelineday " ), GETPOST ( " timelineyear " ));
}
2021-03-24 19:53:31 +01:00
$object -> timespent_fk_user = GETPOST ( " userid_line " , 'int' );
2022-01-21 16:22:59 +01:00
$result = 0 ;
if ( in_array ( $object -> timespent_fk_user , $childids ) || $user -> rights -> projet -> all -> creer ) {
$result = $object -> addTimeSpent ( $user );
}
2021-02-26 18:49:22 +01:00
if ( $result >= 0 ) {
2019-11-22 15:14:55 +01:00
setEventMessages ( $langs -> trans ( " RecordSaved " ), null , 'mesgs' );
2020-05-21 15:05:19 +02:00
} else {
2019-11-22 15:14:55 +01:00
setEventMessages ( $langs -> trans ( $object -> error ), null , 'errors' );
$error ++ ;
}
2020-05-21 15:05:19 +02:00
} else {
2019-11-22 15:14:55 +01:00
$object -> fetch ( $id , $ref );
2021-03-24 19:53:31 +01:00
$object -> timespent_id = GETPOST ( " lineid " , 'int' );
2022-06-20 02:10:27 +02:00
$object -> timespent_note = GETPOST ( " timespent_note_line " , " alphanohtml " );
$object -> timespent_old_duration = GETPOST ( " old_duration " , " int " );
2021-03-25 01:07:29 +01:00
$object -> timespent_duration = GETPOSTINT ( " new_durationhour " ) * 60 * 60 ; // We store duration in seconds
$object -> timespent_duration += ( GETPOSTINT ( " new_durationmin " ) ? GETPOSTINT ( 'new_durationmin' ) : 0 ) * 60 ; // We store duration in seconds
2021-02-26 18:49:22 +01:00
if ( GETPOST ( " timelinehour " ) != '' && GETPOST ( " timelinehour " ) >= 0 ) { // If hour was entered
2021-07-12 23:01:34 +02:00
$object -> timespent_date = dol_mktime ( GETPOST ( " timelinehour " , 'int' ), GETPOST ( " timelinemin " , 'int' ), 0 , GETPOST ( " timelinemonth " , 'int' ), GETPOST ( " timelineday " , 'int' ), GETPOST ( " timelineyear " , 'int' ));
2019-11-22 15:14:55 +01:00
$object -> timespent_withhour = 1 ;
2020-05-21 15:05:19 +02:00
} else {
2021-07-12 23:01:34 +02:00
$object -> timespent_date = dol_mktime ( 12 , 0 , 0 , GETPOST ( " timelinemonth " , 'int' ), GETPOST ( " timelineday " , 'int' ), GETPOST ( " timelineyear " , 'int' ));
2019-11-22 15:14:55 +01:00
}
2021-03-24 19:53:31 +01:00
$object -> timespent_fk_user = GETPOST ( " userid_line " , 'int' );
2019-11-22 15:14:55 +01:00
2022-01-21 16:22:59 +01:00
$result = 0 ;
if ( in_array ( $object -> timespent_fk_user , $childids ) || $user -> rights -> projet -> all -> creer ) {
$result = $object -> updateTimeSpent ( $user );
if ( $result >= 0 ) {
setEventMessages ( $langs -> trans ( " RecordSaved " ), null , 'mesgs' );
} else {
setEventMessages ( $langs -> trans ( $object -> error ), null , 'errors' );
$error ++ ;
}
2019-11-22 15:14:55 +01:00
}
2010-03-01 17:42:02 +01:00
}
2020-05-21 15:05:19 +02:00
} else {
2019-11-13 19:35:02 +01:00
$action = '' ;
2010-03-01 17:42:02 +01:00
}
2010-02-24 11:30:26 +01:00
}
2009-07-28 02:52:34 +02:00
2023-04-26 10:25:08 +02:00
if ( $action == 'confirm_deleteline' && $confirm == " yes " && ( $user -> hasRight ( 'projet' , 'time' ) || $user -> hasRight ( 'projet' , 'all' , 'creer' ))) {
2022-01-21 16:22:59 +01:00
$object -> fetchTimeSpent ( GETPOST ( 'lineid' , 'int' )); // load properties like $object->timespent_id
2010-02-24 15:54:55 +01:00
2023-04-26 10:25:08 +02:00
if ( in_array ( $object -> timespent_fk_user , $childids ) || $user -> hasRight ( 'projet' , 'all' , 'creer' )) {
2022-01-21 16:22:59 +01:00
$result = $object -> delTimeSpent ( $user ); // delete line with $object->timespent_id
if ( $result < 0 ) {
$langs -> load ( " errors " );
setEventMessages ( $langs -> trans ( $object -> error ), null , 'errors' );
$error ++ ;
$action = '' ;
} else {
setEventMessages ( $langs -> trans ( " RecordDeleted " ), null , 'mesgs' );
}
2018-02-26 13:21:16 +01:00
}
2012-04-18 11:16:15 +02:00
}
2020-10-23 20:08:35 +02:00
// Retrieve First Task ID of Project if withprojet is on to allow project prev next to work
2021-02-26 18:49:22 +01:00
if ( ! empty ( $project_ref ) && ! empty ( $withproject )) {
if ( $projectstatic -> fetch ( 0 , $project_ref ) > 0 ) {
2019-11-13 19:35:02 +01:00
$tasksarray = $object -> getTasksArray ( 0 , 0 , $projectstatic -> id , $socid , 0 );
2021-02-26 18:49:22 +01:00
if ( count ( $tasksarray ) > 0 ) {
2019-11-13 19:35:02 +01:00
$id = $tasksarray [ 0 ] -> id ;
2020-05-21 15:05:19 +02:00
} else {
2019-11-13 19:35:02 +01:00
header ( " Location: " . DOL_URL_ROOT . '/projet/tasks.php?id=' . $projectstatic -> id . ( $withproject ? '&withproject=1' : '' ) . ( empty ( $mode ) ? '' : '&mode=' . $mode ));
2012-04-18 12:15:14 +02:00
exit ;
2012-04-18 11:16:15 +02:00
}
2010-02-24 15:54:55 +01:00
}
2010-02-24 11:30:26 +01:00
}
2009-07-28 02:52:34 +02:00
2016-02-28 00:00:08 +01:00
// To show all time lines for project
2019-11-13 19:35:02 +01:00
$projectidforalltimes = 0 ;
2021-02-26 18:49:22 +01:00
if ( GETPOST ( 'projectid' , 'int' ) > 0 ) {
2019-11-13 19:35:02 +01:00
$projectidforalltimes = GETPOST ( 'projectid' , 'int' );
2019-01-24 18:16:14 +01:00
2019-11-13 19:35:02 +01:00
$result = $projectstatic -> fetch ( $projectidforalltimes );
2021-02-26 18:49:22 +01:00
if ( ! empty ( $projectstatic -> socid )) {
$projectstatic -> fetch_thirdparty ();
}
2019-12-29 20:47:18 +01:00
$res = $projectstatic -> fetch_optionals ();
2021-02-26 18:49:22 +01:00
} elseif ( GETPOST ( 'project_ref' , 'alpha' )) {
2019-12-29 20:47:18 +01:00
$projectstatic -> fetch ( 0 , GETPOST ( 'project_ref' , 'alpha' ));
$projectidforalltimes = $projectstatic -> id ;
$withproject = 1 ;
2021-02-26 18:49:22 +01:00
} elseif ( $id > 0 ) {
2019-12-29 20:47:18 +01:00
$object -> fetch ( $id );
$result = $projectstatic -> fetch ( $object -> fk_project );
2019-03-29 15:54:46 +01:00
}
2021-12-20 17:50:59 +01:00
// If not task selected and no project selected
if ( $id <= 0 && $projectidforalltimes == 0 ) {
$allprojectforuser = $user -> id ;
}
2016-02-28 00:00:08 +01:00
2021-02-26 18:49:22 +01:00
if ( $action == 'confirm_generateinvoice' ) {
if ( ! empty ( $projectstatic -> socid )) {
$projectstatic -> fetch_thirdparty ();
}
2019-03-29 15:54:46 +01:00
2020-11-01 15:20:33 +01:00
if ( ! ( $projectstatic -> thirdparty -> id > 0 )) {
2019-03-29 15:54:46 +01:00
setEventMessages ( $langs -> trans ( " ThirdPartyRequiredToGenerateInvoice " ), null , 'errors' );
2020-05-21 15:05:19 +02:00
} else {
2019-03-29 15:54:46 +01:00
include_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php' ;
include_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php' ;
include_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php' ;
$tmpinvoice = new Facture ( $db );
2019-11-13 19:35:02 +01:00
$tmptimespent = new Task ( $db );
$tmpproduct = new Product ( $db );
2019-03-29 15:54:46 +01:00
$fuser = new User ( $db );
$db -> begin ();
$idprod = GETPOST ( 'productid' , 'int' );
2019-12-29 20:45:30 +01:00
$generateinvoicemode = GETPOST ( 'generateinvoicemode' , 'string' );
2020-10-31 14:32:18 +01:00
$invoiceToUse = GETPOST ( 'invoiceid' , 'int' );
2019-12-29 20:45:30 +01:00
2020-10-31 14:32:18 +01:00
$prodDurationHours = 1.0 ;
2021-02-26 18:49:22 +01:00
if ( $idprod > 0 ) {
2019-03-29 15:54:46 +01:00
$tmpproduct -> fetch ( $idprod );
2021-07-12 23:01:34 +02:00
if ( empty ( $tmpproduct -> duration_value )) {
$error ++ ;
$langs -> load ( " errors " );
setEventMessages ( $langs -> trans ( " ErrorDurationForServiceNotDefinedCantCalculateHourlyPrice " ), null , 'errors' );
}
2021-02-26 18:49:22 +01:00
if ( $tmpproduct -> duration_unit == 'i' ) {
2020-10-31 14:32:18 +01:00
$prodDurationHours = 1. / 60 ;
2021-02-26 18:49:22 +01:00
}
if ( $tmpproduct -> duration_unit == 'h' ) {
2020-10-31 14:32:18 +01:00
$prodDurationHours = 1. ;
2021-02-26 18:49:22 +01:00
}
if ( $tmpproduct -> duration_unit == 'd' ) {
2020-10-31 14:32:18 +01:00
$prodDurationHours = 24. ;
2021-02-26 18:49:22 +01:00
}
if ( $tmpproduct -> duration_unit == 'w' ) {
2020-10-31 14:32:18 +01:00
$prodDurationHours = 24. * 7 ;
2021-02-26 18:49:22 +01:00
}
if ( $tmpproduct -> duration_unit == 'm' ) {
2020-10-31 14:32:18 +01:00
$prodDurationHours = 24. * 30 ;
2021-02-26 18:49:22 +01:00
}
if ( $tmpproduct -> duration_unit == 'y' ) {
2020-10-31 14:32:18 +01:00
$prodDurationHours = 24. * 365 ;
2021-02-26 18:49:22 +01:00
}
2020-10-31 14:32:18 +01:00
$prodDurationHours *= $tmpproduct -> duration_value ;
2019-03-29 15:54:46 +01:00
$dataforprice = $tmpproduct -> getSellPrice ( $mysoc , $projectstatic -> thirdparty , 0 );
2020-11-01 15:20:33 +01:00
2019-11-13 19:35:02 +01:00
$pu_ht = empty ( $dataforprice [ 'pu_ht' ]) ? 0 : $dataforprice [ 'pu_ht' ];
2019-03-29 15:54:46 +01:00
$txtva = $dataforprice [ 'tva_tx' ];
$localtax1 = $dataforprice [ 'localtax1' ];
$localtax2 = $dataforprice [ 'localtax2' ];
2020-05-21 15:05:19 +02:00
} else {
2021-07-12 23:01:34 +02:00
$prodDurationHours = 1 ;
2019-12-29 20:47:18 +01:00
$pu_ht = 0 ;
$txtva = get_default_tva ( $mysoc , $projectstatic -> thirdparty );
$localtax1 = get_default_localtax ( $mysoc , $projectstatic -> thirdparty , 1 );
$localtax2 = get_default_localtax ( $mysoc , $projectstatic -> thirdparty , 2 );
2019-03-29 15:54:46 +01:00
}
2019-01-26 15:20:36 +01:00
2019-03-29 15:54:46 +01:00
$tmpinvoice -> socid = $projectstatic -> thirdparty -> id ;
$tmpinvoice -> date = dol_mktime ( GETPOST ( 'rehour' , 'int' ), GETPOST ( 'remin' , 'int' ), GETPOST ( 'resec' , 'int' ), GETPOST ( 'remonth' , 'int' ), GETPOST ( 'reday' , 'int' ), GETPOST ( 'reyear' , 'int' ));
$tmpinvoice -> fk_project = $projectstatic -> id ;
2019-01-26 15:20:36 +01:00
2020-10-31 14:32:18 +01:00
if ( $invoiceToUse ) {
$tmpinvoice -> fetch ( $invoiceToUse );
} else {
$result = $tmpinvoice -> create ( $user );
2021-02-26 18:49:22 +01:00
if ( $result <= 0 ) {
2020-10-31 14:32:18 +01:00
$error ++ ;
setEventMessages ( $tmpinvoice -> error , $tmpinvoice -> errors , 'errors' );
}
}
2019-01-24 19:45:17 +01:00
2021-02-26 18:49:22 +01:00
if ( ! $error ) {
2020-01-30 01:48:28 +01:00
if ( $generateinvoicemode == 'onelineperuser' ) {
2021-05-18 13:36:07 +02:00
$arrayoftasks = array ();
2021-02-26 18:49:22 +01:00
foreach ( $toselect as $key => $value ) {
2019-12-29 20:58:38 +01:00
// Get userid, timepent
$object -> fetchTimeSpent ( $value );
$arrayoftasks [ $object -> timespent_fk_user ][ 'timespent' ] += $object -> timespent_duration ;
$arrayoftasks [ $object -> timespent_fk_user ][ 'totalvaluetodivideby3600' ] += ( $object -> timespent_duration * $object -> timespent_thm );
2019-12-29 20:47:18 +01:00
}
2019-02-01 22:39:36 +01:00
2021-02-26 18:49:22 +01:00
foreach ( $arrayoftasks as $userid => $value ) {
2019-12-29 20:58:38 +01:00
$fuser -> fetch ( $userid );
2022-12-08 19:22:41 +01:00
$pu_ht = $fuser -> thm ;
2019-12-29 20:58:38 +01:00
$username = $fuser -> getFullName ( $langs );
2019-03-29 15:54:46 +01:00
2019-12-29 20:58:38 +01:00
// Define qty per hour
2020-01-02 15:18:26 +01:00
$qtyhour = $value [ 'timespent' ] / 3600 ;
2019-12-29 20:58:38 +01:00
$qtyhourtext = convertSecondToTime ( $value [ 'timespent' ], 'all' , $conf -> global -> MAIN_DURATION_OF_WORKDAY );
2019-03-29 15:54:46 +01:00
2022-12-10 20:15:00 +01:00
/*
2019-12-29 20:58:38 +01:00
// If no unit price known
2021-02-26 18:49:22 +01:00
if ( empty ( $pu_ht )) {
2019-12-29 20:58:38 +01:00
$pu_ht = price2num ( $value [ 'totalvaluetodivideby3600' ] / 3600 , 'MU' );
}
2022-12-10 20:15:00 +01:00
*/
//Unit price
$pu_ht = price2num (( $value [ 'totalvaluetodivideby3600' ] / $value [ 'timespent' ]), 'MU' );
2019-12-29 20:58:38 +01:00
// Add lines
2020-01-30 01:48:28 +01:00
$lineid = $tmpinvoice -> addline ( $langs -> trans ( " TimeSpentForInvoice " , $username ) . ' : ' . $qtyhourtext , $pu_ht , round ( $qtyhour / $prodDurationHours , 2 ), $txtva , $localtax1 , $localtax2 , ( $idprod > 0 ? $idprod : 0 ));
2019-12-29 20:58:38 +01:00
// Update lineid into line of timespent
2021-03-30 11:36:50 +02:00
$sql = 'UPDATE ' . MAIN_DB_PREFIX . 'projet_task_time SET invoice_line_id = ' . (( int ) $lineid ) . ', invoice_id = ' . (( int ) $tmpinvoice -> id );
2021-03-22 12:47:23 +01:00
$sql .= ' WHERE rowid IN (' . $db -> sanitize ( join ( ',' , $toselect )) . ') AND fk_user = ' . (( int ) $userid );
2019-12-29 20:58:38 +01:00
$result = $db -> query ( $sql );
2021-02-26 18:49:22 +01:00
if ( ! $result ) {
2019-12-29 20:58:38 +01:00
$error ++ ;
setEventMessages ( $db -> lasterror (), null , 'errors' );
break ;
}
2019-03-29 15:54:46 +01:00
}
2021-05-18 13:36:07 +02:00
} elseif ( $generateinvoicemode == 'onelineperperiod' ) { // One line for each time spent line
$arrayoftasks = array ();
2021-08-31 09:10:57 +02:00
$withdetail = GETPOST ( 'detail_time_duration' , 'alpha' );
2021-02-26 18:49:22 +01:00
foreach ( $toselect as $key => $value ) {
2019-12-29 20:58:38 +01:00
// Get userid, timepent
$object -> fetchTimeSpent ( $value );
2021-05-18 13:36:07 +02:00
// $object->id is the task id
$ftask = new Task ( $db );
$ftask -> fetch ( $object -> id );
$fuser -> fetch ( $object -> timespent_fk_user );
$username = $fuser -> getFullName ( $langs );
2019-12-29 20:58:38 +01:00
$arrayoftasks [ $object -> timespent_id ][ 'timespent' ] = $object -> timespent_duration ;
$arrayoftasks [ $object -> timespent_id ][ 'totalvaluetodivideby3600' ] = $object -> timespent_duration * $object -> timespent_thm ;
2021-05-18 13:36:07 +02:00
$arrayoftasks [ $object -> timespent_id ][ 'note' ] = $ftask -> ref . ' - ' . $ftask -> label . ' - ' . $username . ( $object -> timespent_note ? ' - ' . $object -> timespent_note : '' ); // TODO Add user name in note
2021-08-31 09:10:57 +02:00
if ( ! empty ( $withdetail )) {
2021-08-31 09:24:41 +02:00
if ( ! empty ( $conf -> fckeditor -> enabled ) && ! empty ( $conf -> global -> FCKEDITOR_ENABLE_DETAILS )) {
$arrayoftasks [ $object -> timespent_id ][ 'note' ] .= " <br/> " ;
} else {
$arrayoftasks [ $object -> timespent_id ][ 'note' ] .= " \n " ;
}
2021-08-27 17:27:05 +02:00
if ( ! empty ( $object -> timespent_withhour )) {
$arrayoftasks [ $object -> timespent_id ][ 'note' ] .= $langs -> trans ( " Date " ) . ': ' . dol_print_date ( $object -> timespent_datehour );
} else {
$arrayoftasks [ $object -> timespent_id ][ 'note' ] .= $langs -> trans ( " Date " ) . ': ' . dol_print_date ( $object -> timespent_date );
}
$arrayoftasks [ $object -> timespent_id ][ 'note' ] .= ' - ' . $langs -> trans ( " Duration " ) . ': ' . convertSecondToTime ( $object -> timespent_duration , 'all' , $conf -> global -> MAIN_DURATION_OF_WORKDAY );
}
2019-12-29 20:58:38 +01:00
$arrayoftasks [ $object -> timespent_id ][ 'user' ] = $object -> timespent_fk_user ;
2019-12-29 20:47:18 +01:00
}
2021-02-26 18:49:22 +01:00
foreach ( $arrayoftasks as $timespent_id => $value ) {
2019-12-29 20:58:38 +01:00
$userid = $value [ 'user' ];
//$pu_ht = $value['timespent'] * $fuser->thm;
2019-03-29 15:54:46 +01:00
2019-12-29 20:58:38 +01:00
// Define qty per hour
2020-01-02 15:18:26 +01:00
$qtyhour = $value [ 'timespent' ] / 3600 ;
2019-12-29 20:58:38 +01:00
// If no unit price known
2021-02-26 18:49:22 +01:00
if ( empty ( $pu_ht )) {
2019-12-29 20:58:38 +01:00
$pu_ht = price2num ( $value [ 'totalvaluetodivideby3600' ] / 3600 , 'MU' );
}
// Add lines
2020-01-30 01:48:28 +01:00
$lineid = $tmpinvoice -> addline ( $value [ 'note' ], $pu_ht , round ( $qtyhour / $prodDurationHours , 2 ), $txtva , $localtax1 , $localtax2 , ( $idprod > 0 ? $idprod : 0 ));
2021-05-18 13:36:07 +02:00
//var_dump($lineid);exit;
2019-12-29 20:58:38 +01:00
// Update lineid into line of timespent
2021-03-30 11:36:50 +02:00
$sql = 'UPDATE ' . MAIN_DB_PREFIX . 'projet_task_time SET invoice_line_id = ' . (( int ) $lineid ) . ', invoice_id = ' . (( int ) $tmpinvoice -> id );
2021-03-22 12:47:23 +01:00
$sql .= ' WHERE rowid IN (' . $db -> sanitize ( join ( ',' , $toselect )) . ') AND fk_user = ' . (( int ) $userid );
2019-12-29 20:58:38 +01:00
$result = $db -> query ( $sql );
2021-02-26 18:49:22 +01:00
if ( ! $result ) {
2019-12-29 20:58:38 +01:00
$error ++ ;
setEventMessages ( $db -> lasterror (), null , 'errors' );
break ;
}
2019-12-29 20:47:18 +01:00
}
2021-07-12 23:01:34 +02:00
} elseif ( $generateinvoicemode == 'onelinepertask' ) { // One line for each different task
2021-05-18 13:36:07 +02:00
$arrayoftasks = array ();
2021-02-26 18:49:22 +01:00
foreach ( $toselect as $key => $value ) {
2019-12-29 20:58:38 +01:00
// Get userid, timepent
2021-07-12 23:01:34 +02:00
$object -> fetchTimeSpent ( $value ); // Call method to get list of timespent for a timespent line id (We use the utiliy method found into Task object)
// $object->id is now the task id
2019-12-29 20:58:38 +01:00
$arrayoftasks [ $object -> id ][ 'timespent' ] += $object -> timespent_duration ;
2021-07-12 23:01:34 +02:00
$arrayoftasks [ $object -> id ][ 'totalvaluetodivideby3600' ] += ( $object -> timespent_duration * $object -> timespent_thm );
2019-12-29 20:47:18 +01:00
}
2019-03-29 15:54:46 +01:00
2021-02-26 18:49:22 +01:00
foreach ( $arrayoftasks as $task_id => $value ) {
2019-12-29 20:58:38 +01:00
$ftask = new Task ( $db );
$ftask -> fetch ( $task_id );
// Define qty per hour
2020-01-02 15:18:26 +01:00
$qtyhour = $value [ 'timespent' ] / 3600 ;
2019-12-29 20:58:38 +01:00
$qtyhourtext = convertSecondToTime ( $value [ 'timespent' ], 'all' , $conf -> global -> MAIN_DURATION_OF_WORKDAY );
2021-07-12 23:01:34 +02:00
if ( $idprod > 0 ) {
// If a product is defined, we msut use the $prodDurationHours and $pu_ht of product (already set previously).
$pu_ht_for_task = $pu_ht ;
// If we want to reuse the value of timespent (so use same price than cost price)
if ( ! empty ( $conf -> global -> PROJECT_TIME_SPENT_INTO_INVOICE_USE_VALUE )) {
$pu_ht_for_task = price2num ( $value [ 'totalvaluetodivideby3600' ] / $value [ 'timespent' ], 'MU' ) * $prodDurationHours ;
}
$pa_ht = price2num ( $value [ 'totalvaluetodivideby3600' ] / $value [ 'timespent' ], 'MU' ) * $prodDurationHours ;
} else {
// If not product used, we use the hour unit for duration and unit price.
$pu_ht_for_task = 0 ;
// If we want to reuse the value of timespent (so use same price than cost price)
if ( ! empty ( $conf -> global -> PROJECT_TIME_SPENT_INTO_INVOICE_USE_VALUE )) {
$pu_ht_for_task = price2num ( $value [ 'totalvaluetodivideby3600' ] / $value [ 'timespent' ], 'MU' );
}
$pa_ht = price2num ( $value [ 'totalvaluetodivideby3600' ] / $value [ 'timespent' ], 'MU' );
2019-12-29 20:58:38 +01:00
}
// Add lines
2021-07-12 23:01:34 +02:00
$date_start = '' ;
$date_end = '' ;
2019-12-29 20:58:38 +01:00
$lineName = $ftask -> ref . ' - ' . $ftask -> label ;
2021-07-12 23:01:34 +02:00
$lineid = $tmpinvoice -> addline ( $lineName , $pu_ht_for_task , price2num ( $qtyhour / $prodDurationHours , 'MS' ), $txtva , $localtax1 , $localtax2 , ( $idprod > 0 ? $idprod : 0 ), 0 , $date_start , $date_end , 0 , 0 , '' , 'HT' , 0 , 1 , - 1 , 0 , '' , 0 , 0 , null , $pa_ht );
if ( $lineid < 0 ) {
2019-12-29 20:58:38 +01:00
$error ++ ;
2021-07-12 23:01:34 +02:00
setEventMessages ( $tmpinvoice -> error , $tmpinvoice -> errors , 'errors' );
2019-12-29 20:58:38 +01:00
break ;
}
2021-07-12 23:01:34 +02:00
if ( ! $error ) {
// Update lineid into line of timespent
$sql = 'UPDATE ' . MAIN_DB_PREFIX . 'projet_task_time SET invoice_line_id = ' . (( int ) $lineid ) . ', invoice_id = ' . (( int ) $tmpinvoice -> id );
$sql .= ' WHERE rowid IN (' . $db -> sanitize ( join ( ',' , $toselect )) . ')' ;
$result = $db -> query ( $sql );
if ( ! $result ) {
$error ++ ;
setEventMessages ( $db -> lasterror (), null , 'errors' );
break ;
}
}
2019-03-29 15:54:46 +01:00
}
2019-02-01 22:39:36 +01:00
}
2019-03-29 15:54:46 +01:00
}
2019-01-24 19:45:17 +01:00
2021-02-26 18:49:22 +01:00
if ( ! $error ) {
2019-12-29 20:47:18 +01:00
$urltoinvoice = $tmpinvoice -> getNomUrl ( 0 );
2021-05-18 13:36:07 +02:00
$mesg = $langs -> trans ( " InvoiceGeneratedFromTimeSpent " , '{s1}' );
$mesg = str_replace ( '{s1}' , $urltoinvoice , $mesg );
setEventMessages ( $mesg , null , 'mesgs' );
2019-12-29 20:47:18 +01:00
//var_dump($tmpinvoice);
2019-02-01 22:39:36 +01:00
2019-12-29 20:47:18 +01:00
$db -> commit ();
2020-05-21 15:05:19 +02:00
} else {
2019-03-29 15:54:46 +01:00
$db -> rollback ();
}
}
2019-01-24 18:16:14 +01:00
}
2021-06-29 15:50:41 +02:00
if ( $action == 'confirm_generateinter' ) {
2021-06-29 15:26:04 +02:00
$langs -> load ( 'interventions' );
if ( ! empty ( $projectstatic -> socid )) $projectstatic -> fetch_thirdparty ();
if ( ! ( $projectstatic -> thirdparty -> id > 0 )) {
setEventMessages ( $langs -> trans ( " ThirdPartyRequiredToGenerateIntervention " ), null , 'errors' );
} else {
include_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php' ;
include_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php' ;
include_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/fichinter/class/fichinter.class.php' ;
$tmpinter = new Fichinter ( $db );
$tmptimespent = new Task ( $db );
$fuser = new User ( $db );
$db -> begin ();
2021-06-29 15:50:41 +02:00
$interToUse = GETPOST ( 'interid' , 'int' );
2021-06-29 15:26:04 +02:00
$tmpinter -> socid = $projectstatic -> thirdparty -> id ;
$tmpinter -> date = dol_mktime ( GETPOST ( 'rehour' , 'int' ), GETPOST ( 'remin' , 'int' ), GETPOST ( 'resec' , 'int' ), GETPOST ( 'remonth' , 'int' ), GETPOST ( 'reday' , 'int' ), GETPOST ( 'reyear' , 'int' ));
$tmpinter -> fk_project = $projectstatic -> id ;
$tmpinter -> description = $projectstatic -> title . ( ! empty ( $projectstatic -> description ) ? '-' . $projectstatic -> label : '' );
2021-06-29 15:50:41 +02:00
if ( $interToUse ) {
$tmpinter -> fetch ( $interToUse );
2021-06-29 15:52:50 +02:00
} else {
2021-06-29 15:50:41 +02:00
$result = $tmpinter -> create ( $user );
2021-06-29 15:52:50 +02:00
if ( $result <= 0 ) {
2021-06-29 15:50:41 +02:00
$error ++ ;
setEventMessages ( $tmpinter -> error , $tmpinter -> errors , 'errors' );
}
}
if ( ! $error ) {
2021-06-29 15:26:04 +02:00
$arrayoftasks = array ();
2021-06-29 15:50:41 +02:00
foreach ( $toselect as $key => $value ) {
2022-02-24 11:10:46 +01:00
// Get userid, timespent
2021-06-29 15:26:04 +02:00
$object -> fetchTimeSpent ( $value );
// $object->id is the task id
2022-02-24 11:10:46 +01:00
$arrayoftasks [ $object -> timespent_id ][ 'id' ] = $object -> id ;
2021-06-29 15:26:04 +02:00
$arrayoftasks [ $object -> timespent_id ][ 'timespent' ] = $object -> timespent_duration ;
$arrayoftasks [ $object -> timespent_id ][ 'totalvaluetodivideby3600' ] = $object -> timespent_duration * $object -> timespent_thm ;
$arrayoftasks [ $object -> timespent_id ][ 'note' ] = $object -> timespent_note ;
$arrayoftasks [ $object -> timespent_id ][ 'date' ] = date ( 'Y-m-d H:i:s' , $object -> timespent_datehour );
}
2021-06-29 15:50:41 +02:00
foreach ( $arrayoftasks as $timespent_id => $value ) {
2021-06-29 15:26:04 +02:00
$ftask = new Task ( $db );
2022-02-24 11:10:46 +01:00
$ftask -> fetch ( $value [ 'id' ]);
2021-06-29 15:26:04 +02:00
// Define qty per hour
$qtyhour = $value [ 'timespent' ] / 3600 ;
$qtyhourtext = convertSecondToTime ( $value [ 'timespent' ], 'all' , $conf -> global -> MAIN_DURATION_OF_WORKDAY );
// Add lines
$lineid = $tmpinter -> addline ( $user , $tmpinter -> id , $ftask -> label . ( ! empty ( $value [ 'note' ]) ? ' - ' . $value [ 'note' ] : '' ), $value [ 'date' ], $value [ 'timespent' ]);
}
}
2021-06-29 15:50:41 +02:00
if ( ! $error ) {
2021-06-29 15:26:04 +02:00
$urltointer = $tmpinter -> getNomUrl ( 0 );
$mesg = $langs -> trans ( " InterventionGeneratedFromTimeSpent " , '{s1}' );
$mesg = str_replace ( '{s1}' , $urltointer , $mesg );
setEventMessages ( $mesg , null , 'mesgs' );
//var_dump($tmpinvoice);
$db -> commit ();
2021-06-29 15:50:41 +02:00
} else {
2021-06-29 15:26:04 +02:00
$db -> rollback ();
}
}
}
2017-06-07 10:55:39 +02:00
2009-07-28 02:52:34 +02:00
/*
* View
2014-10-03 03:42:11 +02:00
*/
2009-07-28 02:52:34 +02:00
2019-11-13 19:35:02 +01:00
$arrayofselected = is_array ( $toselect ) ? $toselect : array ();
2019-01-18 18:11:10 +01:00
2019-01-27 11:55:16 +01:00
llxHeader ( " " , $langs -> trans ( " Task " ));
2009-07-28 02:52:34 +02:00
2011-11-08 10:18:45 +01:00
$form = new Form ( $db );
2014-09-29 16:25:18 +02:00
$formother = new FormOther ( $db );
2018-02-26 11:57:29 +01:00
$formproject = new FormProjets ( $db );
2012-08-07 14:54:56 +02:00
$userstatic = new User ( $db );
2009-07-28 02:52:34 +02:00
2021-12-20 17:50:59 +01:00
if (( $id > 0 || ! empty ( $ref )) || $projectidforalltimes > 0 || $allprojectforuser > 0 ) {
2009-07-28 02:52:34 +02:00
/*
* Fiche projet en mode visu
2019-12-29 20:47:18 +01:00
*/
2021-02-26 18:49:22 +01:00
if ( $projectidforalltimes > 0 ) {
2019-12-29 20:47:18 +01:00
$result = $projectstatic -> fetch ( $projectidforalltimes );
2021-02-26 18:49:22 +01:00
if ( ! empty ( $projectstatic -> socid )) {
$projectstatic -> fetch_thirdparty ();
}
2019-12-29 20:47:18 +01:00
$res = $projectstatic -> fetch_optionals ();
2021-02-26 18:49:22 +01:00
} elseif ( $object -> fetch ( $id , $ref ) >= 0 ) {
if ( ! empty ( $conf -> global -> PROJECT_ALLOW_COMMENT_ON_TASK ) && method_exists ( $object , 'fetchComments' ) && empty ( $object -> comments )) {
$object -> fetchComments ();
}
2019-11-13 19:35:02 +01:00
$result = $projectstatic -> fetch ( $object -> fk_project );
2021-02-26 18:49:22 +01:00
if ( ! empty ( $conf -> global -> PROJECT_ALLOW_COMMENT_ON_PROJECT ) && method_exists ( $projectstatic , 'fetchComments' ) && empty ( $projectstatic -> comments )) {
$projectstatic -> fetchComments ();
}
if ( ! empty ( $projectstatic -> socid )) {
$projectstatic -> fetch_thirdparty ();
}
2019-11-13 19:35:02 +01:00
$res = $projectstatic -> fetch_optionals ();
2017-06-07 10:55:39 +02:00
2015-09-24 16:32:48 +02:00
$object -> project = clone $projectstatic ;
2019-12-29 20:47:18 +01:00
}
2017-06-07 10:55:39 +02:00
2019-12-29 20:47:18 +01:00
$userRead = $projectstatic -> restrictedProjectArea ( $user , 'read' );
$linktocreatetime = '' ;
2014-05-10 16:43:47 +02:00
2021-02-26 18:49:22 +01:00
if ( $projectstatic -> id > 0 ) {
if ( $withproject ) {
2013-05-14 20:22:33 +02:00
// Tabs for project
2021-02-26 18:49:22 +01:00
if ( empty ( $id ) || $tab == 'timespent' ) {
$tab = 'timespent' ;
} else {
$tab = 'tasks' ;
}
2020-04-15 14:54:54 +02:00
2019-11-13 19:35:02 +01:00
$head = project_prepare_head ( $projectstatic );
2020-10-22 22:50:03 +02:00
print dol_get_fiche_head ( $head , $tab , $langs -> trans ( " Project " ), - 1 , ( $projectstatic -> public ? 'projectpub' : 'project' ));
2013-05-14 20:22:33 +02:00
2021-10-24 09:59:30 +02:00
$param = (( ! empty ( $mode ) && $mode == 'mine' ) ? '&mode=mine' : '' );
2021-12-20 18:12:08 +01:00
if ( $search_user ) {
$param .= '&search_user=' . (( int ) $search_user );
}
if ( $search_month ) {
$param .= '&search_month=' . (( int ) $search_month );
}
if ( $search_year ) {
$param .= '&search_year=' . (( int ) $search_year );
}
2013-05-14 20:22:33 +02:00
2016-10-18 12:16:12 +02:00
// Project card
2017-06-07 10:55:39 +02:00
2019-12-29 20:47:18 +01:00
$linkback = '<a href="' . DOL_URL_ROOT . '/projet/list.php?restore_lastsearch_values=1">' . $langs -> trans ( " BackToList " ) . '</a>' ;
2017-06-07 10:55:39 +02:00
2019-12-29 20:47:18 +01:00
$morehtmlref = '<div class="refidno">' ;
// Title
$morehtmlref .= $projectstatic -> title ;
// Thirdparty
2021-10-24 09:59:30 +02:00
if ( ! empty ( $projectstatic -> thirdparty -> id ) && $projectstatic -> thirdparty -> id > 0 ) {
2019-12-29 20:47:18 +01:00
$morehtmlref .= '<br>' . $langs -> trans ( 'ThirdParty' ) . ' : ' . $projectstatic -> thirdparty -> getNomUrl ( 1 , 'project' );
}
$morehtmlref .= '</div>' ;
2017-06-07 10:55:39 +02:00
2019-12-29 20:47:18 +01:00
// Define a complementary filter for search of next/prev ref.
2021-10-24 09:59:30 +02:00
if ( empty ( $user -> rights -> projet -> all -> lire )) {
2019-12-29 20:47:18 +01:00
$objectsListId = $projectstatic -> getProjectsAuthorizedForUser ( $user , 0 , 0 );
2021-03-22 12:47:23 +01:00
$projectstatic -> next_prev_filter = " rowid IN ( " . $db -> sanitize ( count ( $objectsListId ) ? join ( ',' , array_keys ( $objectsListId )) : '0' ) . " ) " ;
2019-12-29 20:47:18 +01:00
}
2017-06-07 10:55:39 +02:00
2021-12-20 18:12:08 +01:00
dol_banner_tab ( $projectstatic , 'project_ref' , $linkback , 1 , 'ref' , 'ref' , $morehtmlref , $param );
2017-06-07 10:55:39 +02:00
2019-12-29 20:47:18 +01:00
print '<div class="fichecenter">' ;
print '<div class="fichehalfleft">' ;
print '<div class="underbanner clearboth"></div>' ;
2017-06-07 10:55:39 +02:00
2019-12-29 20:47:18 +01:00
print '<table class="border tableforfield centpercent">' ;
2019-09-01 01:40:51 +02:00
2019-12-29 20:47:18 +01:00
// Usage
2022-07-26 11:04:52 +02:00
if ( ! empty ( $conf -> global -> PROJECT_USE_OPPORTUNITIES ) || empty ( $conf -> global -> PROJECT_HIDE_TASKS ) || isModEnabled ( 'eventorganization' )) {
2021-03-18 11:07:48 +01:00
print '<tr><td class="tdtop">' ;
print $langs -> trans ( " Usage " );
print '</td>' ;
print '<td>' ;
2021-03-20 12:42:46 +01:00
if ( ! empty ( $conf -> global -> PROJECT_USE_OPPORTUNITIES )) {
2021-03-18 11:07:48 +01:00
print '<input type="checkbox" disabled name="usage_opportunity"' . ( GETPOSTISSET ( 'usage_opportunity' ) ? ( GETPOST ( 'usage_opportunity' , 'alpha' ) != '' ? ' checked="checked"' : '' ) : ( $projectstatic -> usage_opportunity ? ' checked="checked"' : '' )) . '"> ' ;
$htmltext = $langs -> trans ( " ProjectFollowOpportunity " );
print $form -> textwithpicto ( $langs -> trans ( " ProjectFollowOpportunity " ), $htmltext );
print '<br>' ;
}
2021-03-20 12:42:46 +01:00
if ( empty ( $conf -> global -> PROJECT_HIDE_TASKS )) {
2021-03-18 11:07:48 +01:00
print '<input type="checkbox" disabled name="usage_task"' . ( GETPOSTISSET ( 'usage_task' ) ? ( GETPOST ( 'usage_task' , 'alpha' ) != '' ? ' checked="checked"' : '' ) : ( $projectstatic -> usage_task ? ' checked="checked"' : '' )) . '"> ' ;
$htmltext = $langs -> trans ( " ProjectFollowTasks " );
print $form -> textwithpicto ( $langs -> trans ( " ProjectFollowTasks " ), $htmltext );
print '<br>' ;
}
2021-03-20 12:42:46 +01:00
if ( empty ( $conf -> global -> PROJECT_HIDE_TASKS ) && ! empty ( $conf -> global -> PROJECT_BILL_TIME_SPENT )) {
2021-03-18 11:07:48 +01:00
print '<input type="checkbox" disabled name="usage_bill_time"' . ( GETPOSTISSET ( 'usage_bill_time' ) ? ( GETPOST ( 'usage_bill_time' , 'alpha' ) != '' ? ' checked="checked"' : '' ) : ( $projectstatic -> usage_bill_time ? ' checked="checked"' : '' )) . '"> ' ;
$htmltext = $langs -> trans ( " ProjectBillTimeDescription " );
print $form -> textwithpicto ( $langs -> trans ( " BillTime " ), $htmltext );
print '<br>' ;
}
2022-07-26 11:04:52 +02:00
if ( isModEnabled ( 'eventorganization' )) {
2021-10-22 00:19:10 +02:00
print '<input type="checkbox" disabled name="usage_organize_event"' . ( GETPOSTISSET ( 'usage_organize_event' ) ? ( GETPOST ( 'usage_organize_event' , 'alpha' ) != '' ? ' checked="checked"' : '' ) : ( $projectstatic -> usage_organize_event ? ' checked="checked"' : '' )) . '"> ' ;
2021-03-20 12:42:46 +01:00
$htmltext = $langs -> trans ( " EventOrganizationDescriptionLong " );
print $form -> textwithpicto ( $langs -> trans ( " ManageOrganizeEvent " ), $htmltext );
}
2021-03-18 11:07:48 +01:00
print '</td></tr>' ;
2021-03-11 19:09:42 +01:00
}
2018-10-26 19:00:24 +02:00
2019-12-29 20:47:18 +01:00
// Visibility
print '<tr><td class="titlefield">' . $langs -> trans ( " Visibility " ) . '</td><td>' ;
2021-02-26 18:49:22 +01:00
if ( $projectstatic -> public ) {
2022-05-16 18:00:59 +02:00
print img_picto ( $langs -> trans ( 'SharedProject' ), 'world' , 'class="paddingrightonly"' );
2021-02-26 18:49:22 +01:00
print $langs -> trans ( 'SharedProject' );
} else {
2022-05-16 18:00:59 +02:00
print img_picto ( $langs -> trans ( 'PrivateProject' ), 'private' , 'class="paddingrightonly"' );
2021-02-26 18:49:22 +01:00
print $langs -> trans ( 'PrivateProject' );
}
2019-12-29 20:47:18 +01:00
print '</td></tr>' ;
// Date start - end
print '<tr><td>' . $langs -> trans ( " DateStart " ) . ' - ' . $langs -> trans ( " DateEnd " ) . '</td><td>' ;
$start = dol_print_date ( $projectstatic -> date_start , 'day' );
print ( $start ? $start : '?' );
$end = dol_print_date ( $projectstatic -> date_end , 'day' );
print ' - ' ;
print ( $end ? $end : '?' );
2021-02-26 18:49:22 +01:00
if ( $projectstatic -> hasDelay ()) {
print img_warning ( " Late " );
}
2019-12-29 20:47:18 +01:00
print '</td></tr>' ;
// Budget
print '<tr><td>' . $langs -> trans ( " Budget " ) . '</td><td>' ;
2021-02-26 18:49:22 +01:00
if ( strcmp ( $projectstatic -> budget_amount , '' )) {
2022-01-01 18:15:22 +01:00
print '<span class="amount">' . price ( $projectstatic -> budget_amount , '' , $langs , 1 , 0 , 0 , $conf -> currency ) . '</span>' ;
2021-02-26 18:49:22 +01:00
}
2019-12-29 20:47:18 +01:00
print '</td></tr>' ;
// Other attributes
$cols = 2 ;
//include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
2017-06-07 10:55:39 +02:00
2019-12-29 20:47:18 +01:00
print '</table>' ;
2017-06-07 10:55:39 +02:00
2019-12-29 20:47:18 +01:00
print '</div>' ;
print '<div class="fichehalfright">' ;
print '<div class="underbanner clearboth"></div>' ;
2017-06-07 10:55:39 +02:00
2021-11-25 14:11:18 +01:00
print '<table class="border tableforfield centpercent">' ;
2019-12-29 20:47:18 +01:00
// Description
print '<td class="titlefield tdtop">' . $langs -> trans ( " Description " ) . '</td><td>' ;
print nl2br ( $projectstatic -> description );
print '</td></tr>' ;
// Categories
2022-06-09 22:41:59 +02:00
if ( isModEnabled ( 'categorie' )) {
2019-12-29 20:47:18 +01:00
print '<tr><td class="valignmiddle">' . $langs -> trans ( " Categories " ) . '</td><td>' ;
print $form -> showCategories ( $projectstatic -> id , 'project' , 1 );
print " </td></tr> " ;
}
print '</table>' ;
print '</div>' ;
print '</div>' ;
print '<div class="clearboth"></div>' ;
2013-05-14 20:22:33 +02:00
2020-10-27 18:19:31 +01:00
print dol_get_fiche_end ();
2017-06-07 10:55:39 +02:00
2018-02-26 11:57:29 +01:00
print '<br>' ;
2019-01-04 16:24:56 +01:00
}
2016-08-31 01:04:33 +02:00
2019-03-29 15:27:00 +01:00
// Link to create time
2019-12-29 20:47:18 +01:00
$linktocreatetimeBtnStatus = 0 ;
$linktocreatetimeUrl = '' ;
$linktocreatetimeHelpText = '' ;
2022-05-11 09:53:23 +02:00
if ( ! empty ( $user -> rights -> projet -> time )) {
2021-02-26 18:49:22 +01:00
if ( $projectstatic -> public || $userRead > 0 ) {
2019-12-29 20:47:18 +01:00
$linktocreatetimeBtnStatus = 1 ;
2022-05-11 09:53:23 +02:00
if ( ! empty ( $projectidforalltimes )) {
// We are on tab 'Time Spent' of project
2019-12-29 20:47:18 +01:00
$backtourl = $_SERVER [ 'PHP_SELF' ] . '?projectid=' . $projectstatic -> id . ( $withproject ? '&withproject=1' : '' );
2022-05-11 09:53:23 +02:00
$linktocreatetimeUrl = $_SERVER [ 'PHP_SELF' ] . '?' . ( $withproject ? 'withproject=1' : '' ) . '&projectid=' . $projectstatic -> id . '&action=createtime&token=' . newToken () . $param . '&backtopage=' . urlencode ( $backtourl );
} else {
// We are on tab 'Time Spent' of task
2019-12-29 20:47:18 +01:00
$backtourl = $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id . ( $withproject ? '&withproject=1' : '' );
2022-05-11 09:53:23 +02:00
$linktocreatetimeUrl = $_SERVER [ 'PHP_SELF' ] . '?' . ( $withproject ? 'withproject=1' : '' ) . ( $object -> id > 0 ? '&id=' . $object -> id : '&projectid=' . $projectstatic -> id ) . '&action=createtime&token=' . newToken () . $param . '&backtopage=' . urlencode ( $backtourl );
2019-12-29 20:47:18 +01:00
}
2020-05-21 15:05:19 +02:00
} else {
2019-12-29 20:47:18 +01:00
$linktocreatetimeBtnStatus = - 2 ;
$linktocreatetimeHelpText = $langs -> trans ( " NotOwnerOfProject " );
}
2022-05-11 10:02:59 +02:00
} else {
$linktocreatetimeBtnStatus = - 2 ;
$linktocreatetimeHelpText = $langs -> trans ( " NotEnoughPermissions " );
2019-03-29 15:27:00 +01:00
}
2019-04-16 21:49:26 +02:00
2022-01-21 16:22:59 +01:00
$paramsbutton = array ( 'morecss' => 'reposition' );
$linktocreatetime = dolGetButtonTitle ( $langs -> trans ( 'AddTimeSpent' ), $linktocreatetimeHelpText , 'fa fa-plus-circle' , $linktocreatetimeUrl , '' , $linktocreatetimeBtnStatus , $paramsbutton );
2019-12-29 20:47:18 +01:00
}
2019-03-29 15:27:00 +01:00
$massactionbutton = '' ;
2021-08-27 17:27:05 +02:00
$arrayofmassactions = array ();
2022-06-14 14:48:15 +02:00
if ( $projectstatic -> id > 0 ) {
// If we are on a given project.
if ( $projectstatic -> usage_bill_time ) {
$arrayofmassactions = array (
'generateinvoice' => $langs -> trans ( " GenerateBill " ),
//'builddoc'=>$langs->trans("PDFMerge"),
);
}
if ( ! empty ( $conf -> ficheinter -> enabled ) && $user -> rights -> ficheinter -> creer ) {
$langs -> load ( " interventions " );
$arrayofmassactions [ 'generateinter' ] = $langs -> trans ( " GenerateInter " );
}
2021-06-29 15:26:04 +02:00
}
//if ($user->rights->projet->creer) $arrayofmassactions['predelete']='<span class="fa fa-trash paddingrightonly"></span>'.$langs->trans("Delete");
if ( in_array ( $massaction , array ( 'presend' , 'predelete' , 'generateinvoice' , 'generateinter' ))) {
$arrayofmassactions = array ();
}
$massactionbutton = $form -> selectMassAction ( '' , $arrayofmassactions );
2017-06-07 10:55:39 +02:00
2019-03-29 15:27:00 +01:00
// Show section with information of task. If id of task is not defined and project id defined, then $projectidforalltimes is not empty.
2021-12-20 17:50:59 +01:00
if ( empty ( $projectidforalltimes ) && empty ( $allprojectforuser )) {
2019-11-13 19:35:02 +01:00
$head = task_prepare_head ( $object );
2020-10-22 22:50:03 +02:00
print dol_get_fiche_head ( $head , 'task_time' , $langs -> trans ( " Task " ), - 1 , 'projecttask' , 0 , '' , 'reposition' );
2009-07-28 02:52:34 +02:00
2021-02-26 18:49:22 +01:00
if ( $action == 'deleteline' ) {
2022-01-21 16:22:59 +01:00
print $form -> formconfirm ( $_SERVER [ " PHP_SELF " ] . " ? " . ( $object -> id > 0 ? " id= " . $object -> id : 'projectid=' . $projectstatic -> id ) . '&lineid=' . GETPOST ( " lineid " , 'int' ) . ( $withproject ? '&withproject=1' : '' ), $langs -> trans ( " DeleteATimeSpent " ), $langs -> trans ( " ConfirmDeleteATimeSpent " ), " confirm_deleteline " , '' , '' , 1 );
2010-02-24 11:30:26 +01:00
}
2009-07-28 02:52:34 +02:00
2019-11-13 19:35:02 +01:00
$param = ( $withproject ? '&withproject=1' : '' );
$linkback = $withproject ? '<a href="' . DOL_URL_ROOT . '/projet/tasks.php?id=' . $projectstatic -> id . '">' . $langs -> trans ( " BackToList " ) . '</a>' : '' ;
2012-02-15 23:08:20 +01:00
2021-02-26 18:49:22 +01:00
if ( ! GETPOST ( 'withproject' ) || empty ( $projectstatic -> id )) {
2019-01-27 11:55:16 +01:00
$projectsListId = $projectstatic -> getProjectsAuthorizedForUser ( $user , 0 , 1 );
2021-03-22 12:47:23 +01:00
$object -> next_prev_filter = " fk_projet IN ( " . $db -> sanitize ( $projectsListId ) . " ) " ;
2021-02-26 18:49:22 +01:00
} else {
$object -> next_prev_filter = " fk_projet = " . $projectstatic -> id ;
}
2017-06-07 10:55:39 +02:00
2019-11-13 19:35:02 +01:00
$morehtmlref = '' ;
2017-09-17 20:05:36 +02:00
2017-05-18 12:12:36 +02:00
// Project
2021-02-26 18:49:22 +01:00
if ( empty ( $withproject )) {
2019-12-29 20:47:18 +01:00
$morehtmlref .= '<div class="refidno">' ;
$morehtmlref .= $langs -> trans ( " Project " ) . ': ' ;
$morehtmlref .= $projectstatic -> getNomUrl ( 1 );
$morehtmlref .= '<br>' ;
// Third party
$morehtmlref .= $langs -> trans ( " ThirdParty " ) . ': ' ;
2022-07-26 11:04:52 +02:00
if ( ! empty ( $projectstatic -> thirdparty ) && is_object ( $projectstatic -> thirdparty )) {
2019-12-29 20:47:18 +01:00
$morehtmlref .= $projectstatic -> thirdparty -> getNomUrl ( 1 );
}
$morehtmlref .= '</div>' ;
2017-05-18 12:12:36 +02:00
}
2017-06-07 10:55:39 +02:00
2017-04-05 14:48:24 +02:00
dol_banner_tab ( $object , 'ref' , $linkback , 1 , 'ref' , 'ref' , $morehtmlref , $param );
2017-06-07 10:55:39 +02:00
2017-04-05 14:48:24 +02:00
print '<div class="fichecenter">' ;
2017-05-18 12:12:36 +02:00
print '<div class="fichehalfleft">' ;
2017-06-07 10:55:39 +02:00
2019-12-29 20:47:18 +01:00
print '<div class="underbanner clearboth"></div>' ;
2022-07-26 11:04:52 +02:00
print '<table class="border centpercent tableforfield">' ;
// Task parent
print '<tr><td>' . $langs -> trans ( " ChildOfTask " ) . '</td><td>' ;
if ( $object -> fk_task_parent > 0 ) {
$tasktmp = new Task ( $db );
$tasktmp -> fetch ( $object -> fk_task_parent );
print $tasktmp -> getNomUrl ( 1 );
}
print '</td></tr>' ;
2017-04-05 14:48:24 +02:00
// Date start - Date end
2022-07-26 11:04:52 +02:00
print '<tr><td class="titlefield">' . $langs -> trans ( " DateStart " ) . ' - ' . $langs -> trans ( " Deadline " ) . '</td><td>' ;
2019-01-27 11:55:16 +01:00
$start = dol_print_date ( $object -> date_start , 'dayhour' );
2019-11-13 19:35:02 +01:00
print ( $start ? $start : '?' );
2019-01-27 11:55:16 +01:00
$end = dol_print_date ( $object -> date_end , 'dayhour' );
2017-04-05 14:48:24 +02:00
print ' - ' ;
2019-11-13 19:35:02 +01:00
print ( $end ? $end : '?' );
2021-02-26 18:49:22 +01:00
if ( $object -> hasDelay ()) {
print img_warning ( " Late " );
}
2014-10-03 03:42:11 +02:00
print '</td></tr>' ;
// Planned workload
2017-05-18 12:12:36 +02:00
print '<tr><td>' . $langs -> trans ( " PlannedWorkload " ) . '</td><td>' ;
2021-02-26 18:49:22 +01:00
if ( $object -> planned_workload ) {
2019-01-27 11:55:16 +01:00
print convertSecondToTime ( $object -> planned_workload , 'allhourmin' );
2018-12-06 21:25:04 +01:00
}
2014-10-17 15:01:56 +02:00
print '</td></tr>' ;
2014-10-03 03:42:11 +02:00
2017-05-18 12:12:36 +02:00
print '</table>' ;
print '</div>' ;
2017-06-07 10:55:39 +02:00
2021-10-23 17:18:35 +02:00
print '<div class="fichehalfright">' ;
2017-06-07 10:55:39 +02:00
2017-05-18 12:12:36 +02:00
print '<div class="underbanner clearboth"></div>' ;
2019-03-29 15:27:00 +01:00
print '<table class="border tableforfield centpercent">' ;
2017-06-07 10:55:39 +02:00
2014-10-17 15:01:56 +02:00
// Progress declared
2017-09-17 20:05:36 +02:00
print '<tr><td class="titlefield">' . $langs -> trans ( " ProgressDeclared " ) . '</td><td>' ;
2018-12-06 21:25:04 +01:00
print $object -> progress != '' ? $object -> progress . ' %' : '' ;
2014-10-03 03:42:11 +02:00
print '</td></tr>' ;
2014-10-17 15:01:56 +02:00
// Progress calculated
2017-05-18 12:12:36 +02:00
print '<tr><td>' . $langs -> trans ( " ProgressCalculated " ) . '</td><td>' ;
2021-02-26 18:49:22 +01:00
if ( $object -> planned_workload ) {
2019-11-13 19:35:02 +01:00
$tmparray = $object -> getSummaryOfTimeSpent ();
2021-02-26 18:49:22 +01:00
if ( $tmparray [ 'total_duration' ] > 0 ) {
print round ( $tmparray [ 'total_duration' ] / $object -> planned_workload * 100 , 2 ) . ' %' ;
} else {
print '0 %' ;
}
} else {
print '<span class="opacitymedium">' . $langs -> trans ( " WorkloadNotDefined " ) . '</span>' ;
}
2019-01-15 20:59:56 +01:00
print '</td>' ;
print '</tr>' ;
2014-10-03 03:42:11 +02:00
2010-02-24 10:53:16 +01:00
print '</table>' ;
2017-05-18 12:12:36 +02:00
print '</div>' ;
2017-06-07 10:55:39 +02:00
2017-05-18 12:12:36 +02:00
print '</div>' ;
print '<div class="clearboth"></div>' ;
2017-06-07 10:55:39 +02:00
2020-10-27 18:19:31 +01:00
print dol_get_fiche_end ();
2016-02-28 00:00:08 +01:00
}
2017-06-07 10:55:39 +02:00
2019-03-29 15:27:00 +01:00
2021-12-20 17:50:59 +01:00
if ( $projectstatic -> id > 0 || $allprojectforuser > 0 ) {
2021-02-26 18:49:22 +01:00
if ( $action == 'deleteline' && ! empty ( $projectidforalltimes )) {
2022-01-21 16:22:59 +01:00
print $form -> formconfirm ( $_SERVER [ " PHP_SELF " ] . " ? " . ( $object -> id > 0 ? " id= " . $object -> id : 'projectid=' . $projectstatic -> id ) . '&lineid=' . GETPOST ( 'lineid' , 'int' ) . ( $withproject ? '&withproject=1' : '' ), $langs -> trans ( " DeleteATimeSpent " ), $langs -> trans ( " ConfirmDeleteATimeSpent " ), " confirm_deleteline " , '' , '' , 1 );
2016-08-30 20:16:58 +02:00
}
2017-06-07 10:55:39 +02:00
2022-03-29 10:16:06 +02:00
// Initialize technical object to manage hooks. Note that conf->hooks_modules contains array
$hookmanager -> initHooks ( array ( 'tasktimelist' ));
$formconfirm = '' ;
2021-02-26 18:49:22 +01:00
if ( $action == 'deleteline' && ! empty ( $projectidforalltimes )) {
2022-03-29 10:16:06 +02:00
$formconfirm = $form -> formconfirm ( $_SERVER [ " PHP_SELF " ] . " ? " . ( $object -> id > 0 ? " id= " . $object -> id : 'projectid=' . $projectstatic -> id ) . '&lineid=' . GETPOST ( 'lineid' , 'int' ) . ( $withproject ? '&withproject=1' : '' ), $langs -> trans ( " DeleteATimeSpent " ), $langs -> trans ( " ConfirmDeleteATimeSpent " ), " confirm_deleteline " , '' , '' , 1 );
2016-08-30 20:16:58 +02:00
}
2017-06-07 10:55:39 +02:00
2022-03-29 10:16:06 +02:00
// Call Hook formConfirm
$parameters = array ( 'formConfirm' => $formconfirm , 'lineid' => $lineid , " projectstatic " => $projectstatic , " withproject " => $withproject );
$reshook = $hookmanager -> executeHooks ( 'formConfirm' , $parameters , $object , $action ); // Note that $action and $object may have been modified by hook
if ( empty ( $reshook )) {
$formconfirm .= $hookmanager -> resPrint ;
} elseif ( $reshook > 0 ) {
$formconfirm = $hookmanager -> resPrint ;
}
// Print form confirm
print $formconfirm ;
2019-01-30 20:02:41 +01:00
2019-12-29 20:47:18 +01:00
// Definition of fields for list
$arrayfields = array ();
$arrayfields [ 't.task_date' ] = array ( 'label' => $langs -> trans ( " Date " ), 'checked' => 1 );
2021-02-26 18:49:22 +01:00
if (( empty ( $id ) && empty ( $ref )) || ! empty ( $projectidforalltimes )) { // Not a dedicated task
2019-12-29 20:47:18 +01:00
$arrayfields [ 't.task_ref' ] = array ( 'label' => $langs -> trans ( " RefTask " ), 'checked' => 1 );
$arrayfields [ 't.task_label' ] = array ( 'label' => $langs -> trans ( " LabelTask " ), 'checked' => 1 );
}
$arrayfields [ 'author' ] = array ( 'label' => $langs -> trans ( " By " ), 'checked' => 1 );
$arrayfields [ 't.note' ] = array ( 'label' => $langs -> trans ( " Note " ), 'checked' => 1 );
$arrayfields [ 't.task_duration' ] = array ( 'label' => $langs -> trans ( " Duration " ), 'checked' => 1 );
$arrayfields [ 'value' ] = array ( 'label' => $langs -> trans ( " Value " ), 'checked' => 1 , 'enabled' => ( empty ( $conf -> salaries -> enabled ) ? 0 : 1 ));
$arrayfields [ 'valuebilled' ] = array ( 'label' => $langs -> trans ( " Billed " ), 'checked' => 1 , 'enabled' => ((( ! empty ( $conf -> global -> PROJECT_HIDE_TASKS ) || empty ( $conf -> global -> PROJECT_BILL_TIME_SPENT )) ? 0 : 1 ) && $projectstatic -> usage_bill_time ));
// Extra fields
2020-12-23 19:14:47 +01:00
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_array_fields.tpl.php' ;
2019-12-29 20:47:18 +01:00
$arrayfields = dol_sort_array ( $arrayfields , 'position' );
$param = '' ;
2021-02-26 18:49:22 +01:00
if ( ! empty ( $contextpage ) && $contextpage != $_SERVER [ " PHP_SELF " ]) {
$param .= '&contextpage=' . urlencode ( $contextpage );
}
if ( $limit > 0 && $limit != $conf -> liste_limit ) {
$param .= '&limit=' . urlencode ( $limit );
}
if ( $search_month > 0 ) {
$param .= '&search_month=' . urlencode ( $search_month );
}
if ( $search_year > 0 ) {
$param .= '&search_year=' . urlencode ( $search_year );
}
if ( $search_user > 0 ) {
$param .= '&search_user=' . urlencode ( $search_user );
}
if ( $search_task_ref != '' ) {
$param .= '&search_task_ref=' . urlencode ( $search_task_ref );
}
if ( $search_task_label != '' ) {
$param .= '&search_task_label=' . urlencode ( $search_task_label );
}
if ( $search_note != '' ) {
$param .= '&search_note=' . urlencode ( $search_note );
}
if ( $search_duration != '' ) {
$param .= '&search_field2=' . urlencode ( $search_duration );
}
if ( $optioncss != '' ) {
$param .= '&optioncss=' . urlencode ( $optioncss );
}
2010-02-03 17:57:23 +01:00
/*
2019-12-29 20:47:18 +01:00
// Add $param from extra fields
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_search_param.tpl.php' ;
*/
2021-02-26 18:49:22 +01:00
if ( $id ) {
$param .= '&id=' . urlencode ( $id );
}
if ( $projectid ) {
$param .= '&projectid=' . urlencode ( $projectid );
}
if ( $withproject ) {
$param .= '&withproject=' . urlencode ( $withproject );
}
2022-03-29 10:16:06 +02:00
// Add $param from hooks
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'printFieldListSearchParam' , $parameters , $object ); // Note that $action and $object may have been modified by hook
$param .= $hookmanager -> resPrint ;
2019-12-29 20:47:18 +01:00
print '<form method="POST" action="' . $_SERVER [ " PHP_SELF " ] . '">' ;
2021-02-26 18:49:22 +01:00
if ( $optioncss != '' ) {
print '<input type="hidden" name="optioncss" value="' . $optioncss . '">' ;
}
2019-12-29 20:47:18 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">' ;
2021-02-26 18:49:22 +01:00
if ( $action == 'editline' ) {
print '<input type="hidden" name="action" value="updateline">' ;
} elseif ( $action == 'splitline' ) {
print '<input type="hidden" name="action" value="updatesplitline">' ;
2021-07-16 11:14:30 +02:00
} elseif ( $action == 'createtime' && $user -> rights -> projet -> time ) {
2021-02-26 18:49:22 +01:00
print '<input type="hidden" name="action" value="addtimespent">' ;
} elseif ( $massaction == 'generateinvoice' && $user -> rights -> facture -> lire ) {
print '<input type="hidden" name="action" value="confirm_generateinvoice">' ;
2021-06-29 15:26:04 +02:00
} elseif ( $massaction == 'generateinter' && $user -> rights -> ficheinter -> lire ) {
print '<input type="hidden" name="action" value="confirm_generateinter">' ;
2021-02-26 18:49:22 +01:00
} else {
print '<input type="hidden" name="action" value="list">' ;
}
2019-12-29 20:47:18 +01:00
print '<input type="hidden" name="sortfield" value="' . $sortfield . '">' ;
print '<input type="hidden" name="sortorder" value="' . $sortorder . '">' ;
print '<input type="hidden" name="id" value="' . $id . '">' ;
print '<input type="hidden" name="projectid" value="' . $projectidforalltimes . '">' ;
print '<input type="hidden" name="withproject" value="' . $withproject . '">' ;
2020-04-15 14:54:54 +02:00
print '<input type="hidden" name="tab" value="' . $tab . '">' ;
2021-10-03 18:20:01 +02:00
print '<input type="hidden" name="page_y" value="">' ;
2019-12-29 20:47:18 +01:00
2020-11-01 15:20:33 +01:00
// Form to convert time spent into invoice
2021-02-26 18:49:22 +01:00
if ( $massaction == 'generateinvoice' ) {
2020-11-01 15:20:33 +01:00
if ( $projectstatic -> thirdparty -> id > 0 ) {
2021-07-12 23:01:34 +02:00
print '<table class="noborder centerpercent">' ;
2019-12-29 20:47:18 +01:00
print '<tr>' ;
2020-11-01 15:20:33 +01:00
print '<td class="titlefield">' ;
print $langs -> trans ( 'DateInvoice' );
print '</td>' ;
2019-12-29 20:47:18 +01:00
print '<td>' ;
2020-11-01 15:20:33 +01:00
print $form -> selectDate ( '' , '' , '' , '' , '' , '' , 1 , 1 );
2019-12-29 20:47:18 +01:00
print '</td>' ;
2020-11-01 15:20:33 +01:00
print '</tr>' ;
2019-12-29 20:47:18 +01:00
print '<tr>' ;
print '<td>' ;
2020-11-01 15:20:33 +01:00
print $langs -> trans ( 'Mode' );
2019-12-29 20:47:18 +01:00
print '</td>' ;
print '<td>' ;
2020-11-01 15:20:33 +01:00
$tmparray = array (
'onelineperuser' => 'OneLinePerUser' ,
'onelinepertask' => 'OneLinePerTask' ,
2021-05-18 13:36:07 +02:00
'onelineperperiod' => 'OneLinePerTimeSpentLine' ,
2020-11-01 15:20:33 +01:00
);
print $form -> selectarray ( 'generateinvoicemode' , $tmparray , 'onelineperuser' , 0 , 0 , 0 , '' , 1 );
2021-08-31 09:10:57 +02:00
print " \n " . '<script type="text/javascript">' ;
print '
$ ( document ) . ready ( function () {
setDetailVisibility ();
$ ( " #generateinvoicemode " ) . change ( function () {
setDetailVisibility ();
});
function setDetailVisibility () {
generateinvoicemode = $ ( " #generateinvoicemode option:selected " ) . val ();
if ( generateinvoicemode == " onelineperperiod " ) {
$ ( " #detail_time_duration " ) . show ();
} else {
$ ( " #detail_time_duration " ) . hide ();
}
}
});
' ;
print '</script>' . " \n " ;
print '<span style="display:none" id="detail_time_duration"><input type="checkbox" value="detail" name="detail_time_duration"/>' . $langs -> trans ( 'AddDetailDateAndDuration' ) . '</span>' ;
2019-12-29 20:47:18 +01:00
print '</td>' ;
print '</tr>' ;
2021-02-26 18:49:22 +01:00
if ( $conf -> service -> enabled ) {
2020-11-01 15:20:33 +01:00
print '<tr>' ;
print '<td>' ;
print $langs -> trans ( 'ServiceToUseOnLines' );
print '</td>' ;
print '<td>' ;
$form -> select_produits ( '' , 'productid' , '1' , 0 , $projectstatic -> thirdparty -> price_level , 1 , 2 , '' , 0 , array (), $projectstatic -> thirdparty -> id , 'None' , 0 , 'maxwidth500' );
print '</td>' ;
print '</tr>' ;
}
print '<tr>' ;
print '<td class="titlefield">' ;
print $langs -> trans ( 'InvoiceToUse' );
print '</td>' ;
print '<td>' ;
2022-12-14 11:45:40 +01:00
$form -> selectInvoice ( $projectstatic -> thirdparty -> id , '' , 'invoiceid' , 24 , 0 , $langs -> trans ( 'NewInvoice' ), 1 , 0 , 0 , 'maxwidth500' , '' , 'all' );
2020-11-01 15:20:33 +01:00
print '</td>' ;
print '</tr>' ;
/* print '<tr>' ;
print '<td>' ;
print $langs -> trans ( 'ValidateInvoices' );
print '</td>' ;
print '<td>' ;
print $form -> selectyesno ( 'validate_invoices' , 0 , 1 );
print '</td>' ;
print '</tr>' ; */
print '</table>' ;
print '<br>' ;
print '<div class="center">' ;
print '<input type="submit" class="button" id="createbills" name="createbills" value="' . $langs -> trans ( 'GenerateBill' ) . '"> ' ;
2020-11-23 15:12:52 +01:00
print '<input type="submit" class="button button-cancel" id="cancel" name="cancel" value="' . $langs -> trans ( " Cancel " ) . '">' ;
2020-11-01 15:20:33 +01:00
print '</div>' ;
print '<br>' ;
} else {
print '<div class="warning">' . $langs -> trans ( " ThirdPartyRequiredToGenerateInvoice " ) . '</div>' ;
print '<div class="center">' ;
2020-11-23 15:12:52 +01:00
print '<input type="submit" class="button button-cancel" id="cancel" name="cancel" value="' . $langs -> trans ( " Cancel " ) . '">' ;
2020-11-01 15:20:33 +01:00
print '</div>' ;
$massaction = '' ;
}
2021-06-29 15:26:04 +02:00
} elseif ( $massaction == 'generateinter' ) {
2021-06-29 15:50:41 +02:00
// Form to convert time spent into invoice
2021-06-29 15:26:04 +02:00
print '<input type="hidden" name="massaction" value="confirm_createinter">' ;
if ( $projectstatic -> thirdparty -> id > 0 ) {
2022-06-20 02:10:27 +02:00
print '<br>' ;
2022-06-14 14:48:15 +02:00
print '<table class="noborder centpercent">' ;
2021-06-29 15:26:04 +02:00
print '<tr>' ;
print '<td class="titlefield">' ;
2022-06-20 02:10:27 +02:00
print img_picto ( '' , 'intervention' , 'class="pictofixedwidth"' ) . $langs -> trans ( 'InterToUse' );
2021-06-29 15:26:04 +02:00
print '</td>' ;
print '<td>' ;
2021-06-30 10:56:09 +02:00
$forminter = new FormIntervention ( $db );
print $forminter -> select_interventions ( $projectstatic -> thirdparty -> id , '' , 'interid' , 24 , $langs -> trans ( 'NewInter' ), true );
2021-06-29 15:26:04 +02:00
print '</td>' ;
print '</tr>' ;
print '</table>' ;
print '<div class="center">' ;
print '<input type="submit" class="button" id="createinter" name="createinter" value="' . $langs -> trans ( 'GenerateInter' ) . '"> ' ;
print '<input type="submit" class="button" id="cancel" name="cancel" value="' . $langs -> trans ( 'Cancel' ) . '">' ;
print '</div>' ;
print '<br>' ;
} else {
2021-06-29 15:38:24 +02:00
print '<div class="warning">' . $langs -> trans ( " ThirdPartyRequiredToGenerateIntervention " ) . '</div>' ;
2021-06-29 15:26:04 +02:00
print '<div class="center">' ;
print '<input type="submit" class="button" id="cancel" name="cancel" value="' . $langs -> trans ( 'Cancel' ) . '">' ;
print '</div>' ;
$massaction = '' ;
}
2019-12-29 20:47:18 +01:00
}
2019-01-30 20:02:41 +01:00
2022-03-29 10:16:06 +02:00
// Allow Pre-Mass-Action hook (eg for confirmation dialog)
$parameters = array (
'toselect' => $toselect ,
'uploaddir' => isset ( $uploaddir ) ? $uploaddir : null
);
$reshook = $hookmanager -> executeHooks ( 'doPreMassActions' , $parameters , $object , $action );
if ( $reshook < 0 ) {
setEventMessages ( $hookmanager -> error , $hookmanager -> errors , 'errors' );
} else {
print $hookmanager -> resPrint ;
}
2010-02-03 17:57:23 +01:00
/*
2019-12-29 20:47:18 +01:00
* List of time spent
2014-10-12 01:04:34 +02:00
*/
2015-10-06 16:09:24 +02:00
$tasks = array ();
2017-06-07 10:55:39 +02:00
2016-08-30 20:16:58 +02:00
$sql = " SELECT t.rowid, t.fk_task, t.task_date, t.task_datehour, t.task_date_withhour, t.task_duration, t.fk_user, t.note, t.thm, " ;
2021-12-20 17:50:59 +01:00
$sql .= " pt.ref, pt.label, pt.fk_projet, " ;
2018-12-06 21:16:02 +01:00
$sql .= " u.lastname, u.firstname, u.login, u.photo, u.statut as user_status, " ;
2022-03-29 10:16:06 +02:00
$sql .= " il.fk_facture as invoice_id, inv.fk_statut, " ;
// Add fields from hooks
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'printFieldListSelect' , $parameters , $object ); // Note that $action and $object may have been modified by hook
$sql .= preg_replace ( '/^,/' , '' , $hookmanager -> resPrint );
$sql = preg_replace ( '/,\s*$/' , '' , $sql );
2018-02-26 13:21:16 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " projet_task_time as t " ;
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " facturedet as il ON il.rowid = t.invoice_line_id " ;
2022-03-29 10:16:06 +02:00
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " facture as inv ON inv.rowid = il.fk_facture " ;
// Add table from hooks
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'printFieldListFrom' , $parameters , $object ); // Note that $action and $object may have been modified by hook
$sql .= $hookmanager -> resPrint ;
$sql .= " , " . MAIN_DB_PREFIX . " projet_task as pt, " . MAIN_DB_PREFIX . " user as u " ;
2016-08-30 20:16:58 +02:00
$sql .= " WHERE t.fk_user = u.rowid AND t.fk_task = pt.rowid " ;
2021-09-17 12:29:58 +02:00
2021-12-20 17:50:59 +01:00
if ( empty ( $projectidforalltimes ) && empty ( $allprojectforuser )) {
// Limit on one task
2021-06-09 15:36:47 +02:00
$sql .= " AND t.fk_task = " . (( int ) $object -> id );
2021-12-20 17:50:59 +01:00
} elseif ( ! empty ( $projectidforalltimes )) {
// Limit on one project
2021-03-22 11:30:18 +01:00
$sql .= " AND pt.fk_projet IN ( " . $db -> sanitize ( $projectidforalltimes ) . " ) " ;
2021-12-20 17:50:59 +01:00
} elseif ( ! empty ( $allprojectforuser )) {
// Limit on on user
if ( empty ( $search_user )) {
$search_user = $user -> id ;
}
2022-12-14 16:21:42 +01:00
if ( $search_user > 0 ) $sql .= " AND t.fk_user = " . (( int ) $search_user );
2021-02-26 18:49:22 +01:00
}
2021-12-20 17:50:59 +01:00
2021-02-26 18:49:22 +01:00
if ( $search_note ) {
$sql .= natural_search ( 't.note' , $search_note );
}
if ( $search_task_ref ) {
$sql .= natural_search ( 'pt.ref' , $search_task_ref );
}
if ( $search_task_label ) {
$sql .= natural_search ( 'pt.label' , $search_task_label );
}
if ( $search_user > 0 ) {
2021-09-17 12:29:58 +02:00
$sql .= natural_search ( 't.fk_user' , $search_user , 2 );
2021-02-26 18:49:22 +01:00
}
if ( $search_valuebilled == '1' ) {
$sql .= ' AND t.invoice_id > 0' ;
}
if ( $search_valuebilled == '0' ) {
$sql .= ' AND (t.invoice_id = 0 OR t.invoice_id IS NULL)' ;
}
2022-06-14 14:39:32 +02:00
2019-09-28 13:22:05 +02:00
$sql .= dolSqlDateFilter ( 't.task_datehour' , $search_day , $search_month , $search_year );
2022-06-14 14:39:32 +02:00
2022-03-29 10:16:06 +02:00
// Add where from hooks
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'printFieldListWhere' , $parameters ); // Note that $action and $object may have been modified by hook
$sql .= $hookmanager -> resPrint ;
2016-08-30 20:17:34 +02:00
$sql .= $db -> order ( $sortfield , $sortorder );
2017-06-07 10:55:39 +02:00
2019-01-18 20:06:33 +01:00
// Count total nb of records
$nbtotalofrecords = '' ;
2021-02-26 18:49:22 +01:00
if ( empty ( $conf -> global -> MAIN_DISABLE_FULL_SCANLIST )) {
2019-12-29 20:47:18 +01:00
$resql = $db -> query ( $sql );
2021-09-16 17:53:47 +02:00
if ( ! $resql ) {
dol_print_error ( $db );
exit ;
}
2019-12-29 20:47:18 +01:00
$nbtotalofrecords = $db -> num_rows ( $resql );
2021-02-26 18:49:22 +01:00
if (( $page * $limit ) > $nbtotalofrecords ) { // if total of record found is smaller than page * limit, goto and load page 0
2019-12-29 20:47:18 +01:00
$page = 0 ;
$offset = 0 ;
}
2019-01-18 20:06:33 +01:00
}
// if total of record found is smaller than limit, no need to do paging and to restart another select with limits set.
2021-02-26 18:49:22 +01:00
if ( is_numeric ( $nbtotalofrecords ) && $limit > $nbtotalofrecords ) {
2019-12-29 20:47:18 +01:00
$num = $nbtotalofrecords ;
2020-05-21 15:05:19 +02:00
} else {
2019-12-29 20:47:18 +01:00
$sql .= $db -> plimit ( $limit + 1 , $offset );
2019-01-18 20:06:33 +01:00
2019-12-29 20:47:18 +01:00
$resql = $db -> query ( $sql );
2021-02-26 18:49:22 +01:00
if ( ! $resql ) {
2019-12-29 20:47:18 +01:00
dol_print_error ( $db );
exit ;
}
2016-02-28 00:00:08 +01:00
2019-12-29 20:47:18 +01:00
$num = $db -> num_rows ( $resql );
2019-01-18 20:06:33 +01:00
}
2021-02-26 18:49:22 +01:00
if ( $num >= 0 ) {
if ( ! empty ( $projectidforalltimes )) {
2018-02-26 12:32:26 +01:00
print '<!-- List of time spent for project -->' . " \n " ;
2019-11-13 19:35:02 +01:00
$title = $langs -> trans ( " ListTaskTimeUserProject " );
2019-01-18 20:06:33 +01:00
2021-01-18 13:47:29 +01:00
print_barre_liste ( $title , $page , $_SERVER [ " PHP_SELF " ], $param , $sortfield , $sortorder , $massactionbutton , $num , $nbtotalofrecords , 'clock' , 0 , $linktocreatetime , '' , $limit , 0 , 0 , 1 );
2020-05-21 15:05:19 +02:00
} else {
2021-12-20 17:50:59 +01:00
print '<!-- List of time spent -->' . " \n " ;
2019-03-29 15:27:00 +01:00
2019-12-29 20:47:18 +01:00
$title = $langs -> trans ( " ListTaskTimeForTask " );
2019-03-29 15:27:00 +01:00
2021-01-18 13:47:29 +01:00
print_barre_liste ( $title , $page , $_SERVER [ " PHP_SELF " ], $param , $sortfield , $sortorder , $massactionbutton , $num , $nbtotalofrecords , 'clock' , 0 , $linktocreatetime , '' , $limit , 0 , 0 , 1 );
2019-03-29 15:27:00 +01:00
}
2016-02-28 00:00:08 +01:00
2009-07-28 02:52:34 +02:00
$i = 0 ;
2021-02-26 18:49:22 +01:00
while ( $i < $num ) {
2009-07-28 02:52:34 +02:00
$row = $db -> fetch_object ( $resql );
$tasks [ $i ] = $row ;
$i ++ ;
}
$db -> free ( $resql );
2020-05-21 15:05:19 +02:00
} else {
2009-07-28 02:52:34 +02:00
dol_print_error ( $db );
}
2010-02-28 02:33:12 +01:00
2018-02-26 11:57:29 +01:00
/*
2020-11-01 15:20:33 +01:00
* Form to add a new line of time spent
2018-02-26 11:57:29 +01:00
*/
2021-07-16 11:14:30 +02:00
if ( $action == 'createtime' && $user -> rights -> projet -> time ) {
2019-01-18 20:06:33 +01:00
print '<!-- table to add time spent -->' . " \n " ;
2021-02-26 18:49:22 +01:00
if ( ! empty ( $id )) {
print '<input type="hidden" name="taskid" value="' . $id . '">' ;
}
2018-02-26 11:57:29 +01:00
2019-12-29 20:47:18 +01:00
print '<div class="div-table-responsive-no-min">' ; // You can use div-table-responsive-no-min if you dont need reserved height for your table
2019-11-05 21:24:41 +01:00
print '<table class="noborder nohover centpercent">' ;
2018-02-26 11:57:29 +01:00
print '<tr class="liste_titre">' ;
print '<td>' . $langs -> trans ( " Date " ) . '</td>' ;
2021-12-20 17:50:59 +01:00
if ( ! empty ( $allprojectforuser )) {
print '<td>' . $langs -> trans ( " Project " ) . '</td>' ;
}
2021-02-26 18:49:22 +01:00
if ( empty ( $id )) {
print '<td>' . $langs -> trans ( " Task " ) . '</td>' ;
}
2018-02-26 11:57:29 +01:00
print '<td>' . $langs -> trans ( " By " ) . '</td>' ;
print '<td>' . $langs -> trans ( " Note " ) . '</td>' ;
print '<td>' . $langs -> trans ( " NewTimeSpent " ) . '</td>' ;
print '<td>' . $langs -> trans ( " ProgressDeclared " ) . '</td>' ;
2021-02-26 18:49:22 +01:00
if ( empty ( $conf -> global -> PROJECT_HIDE_TASKS ) && ! empty ( $conf -> global -> PROJECT_BILL_TIME_SPENT )) {
2019-12-29 20:47:18 +01:00
print '<td></td>' ;
2019-01-15 20:59:56 +01:00
}
2022-03-29 10:16:06 +02:00
// Hook fields
$parameters = array ( 'mode' => 'create' );
$reshook = $hookmanager -> executeHooks ( 'printFieldListTitle' , $parameters ); // Note that $action and $object may have been modified by hook
print $hookmanager -> resPrint ;
2018-02-26 11:57:29 +01:00
print '<td></td>' ;
print " </tr> \n " ;
2020-04-15 14:54:54 +02:00
print '<tr class="oddeven nohover">' ;
2018-02-26 11:57:29 +01:00
// Date
print '<td class="maxwidthonsmartphone">' ;
2019-11-13 19:35:02 +01:00
$newdate = '' ;
print $form -> selectDate ( $newdate , 'time' , ( $conf -> browser -> layout == 'phone' ? 2 : 1 ), 1 , 2 , " timespent_date " , 1 , 0 );
2018-02-26 11:57:29 +01:00
print '</td>' ;
2021-12-20 17:50:59 +01:00
if ( ! empty ( $allprojectforuser )) {
print '<td>' ;
// Add project selector
print '</td>' ;
}
2018-02-26 11:57:29 +01:00
// Task
2020-04-15 14:54:54 +02:00
$nboftasks = 0 ;
2021-02-26 18:49:22 +01:00
if ( empty ( $id )) {
2019-12-29 20:47:18 +01:00
print '<td class="maxwidthonsmartphone">' ;
2021-09-23 13:20:42 +02:00
$nboftasks = $formproject -> selectTasks ( - 1 , GETPOST ( 'taskid' , 'int' ), 'taskid' , 0 , 0 , 1 , 1 , 0 , 0 , 'maxwidth300' , $projectstatic -> id , 'progress' );
2019-12-29 20:47:18 +01:00
print '</td>' ;
2019-03-29 15:27:00 +01:00
}
2018-02-26 11:57:29 +01:00
// Contributor
2020-04-13 01:17:51 +02:00
print '<td class="maxwidthonsmartphone nowraponall">' ;
2019-11-13 19:35:02 +01:00
$contactsofproject = $projectstatic -> getListContactId ( 'internal' );
2021-02-26 18:49:22 +01:00
if ( count ( $contactsofproject ) > 0 ) {
2020-04-15 14:54:54 +02:00
print img_object ( '' , 'user' , 'class="hideonsmartphone"' );
2021-02-26 18:49:22 +01:00
if ( in_array ( $user -> id , $contactsofproject )) {
$userid = $user -> id ;
} else {
$userid = $contactsofproject [ 0 ];
}
2019-02-13 12:52:07 +01:00
2021-02-26 18:49:22 +01:00
if ( $projectstatic -> public ) {
$contactsofproject = array ();
}
2021-01-18 13:47:29 +01:00
print $form -> select_dolusers (( GETPOST ( 'userid' , 'int' ) ? GETPOST ( 'userid' , 'int' ) : $userid ), 'userid' , 0 , '' , 0 , '' , $contactsofproject , 0 , 0 , 0 , '' , 0 , $langs -> trans ( " ResourceNotAssignedToProject " ), 'maxwidth250' );
2020-05-21 15:05:19 +02:00
} else {
2020-04-15 14:54:54 +02:00
if ( $nboftasks ) {
print img_error ( $langs -> trans ( 'FirstAddRessourceToAllocateTime' )) . ' ' . $langs -> trans ( 'FirstAddRessourceToAllocateTime' );
}
2018-02-26 11:57:29 +01:00
}
print '</td>' ;
// Note
print '<td>' ;
2022-02-24 11:10:46 +01:00
print '<textarea name="timespent_note" class="maxwidth100onsmartphone" rows="' . ROWS_2 . '">' . ( GETPOST ( 'timespent_note' ) ? GETPOST ( 'timespent_note' ) : '' ) . '</textarea>' ;
2018-02-26 11:57:29 +01:00
print '</td>' ;
// Duration - Time spent
2021-08-19 16:12:13 +02:00
print '<td class="nowraponall">' ;
2022-02-24 11:10:46 +01:00
$durationtouse = ( GETPOST ( 'timespent_duration' ) ? GETPOST ( 'timespent_duration' ) : '' );
2021-02-26 18:49:22 +01:00
if ( GETPOSTISSET ( 'timespent_durationhour' ) || GETPOSTISSET ( 'timespent_durationmin' )) {
2019-06-16 22:17:04 +02:00
$durationtouse = ( GETPOST ( 'timespent_durationhour' ) * 3600 + GETPOST ( 'timespent_durationmin' ) * 60 );
}
print $form -> select_duration ( 'timespent_duration' , $durationtouse , 0 , 'text' );
2018-02-26 11:57:29 +01:00
print '</td>' ;
// Progress declared
print '<td class="nowrap">' ;
2019-11-13 19:35:02 +01:00
print $formother -> select_percent ( GETPOST ( 'progress' ) ? GETPOST ( 'progress' ) : $object -> progress , 'progress' , 0 , 5 , 0 , 100 , 1 );
2018-02-26 11:57:29 +01:00
print '</td>' ;
2019-01-15 20:59:56 +01:00
// Invoiced
2021-02-26 18:49:22 +01:00
if ( empty ( $conf -> global -> PROJECT_HIDE_TASKS ) && ! empty ( $conf -> global -> PROJECT_BILL_TIME_SPENT )) {
2019-12-29 20:47:18 +01:00
print '<td>' ;
print '</td>' ;
2019-01-15 20:59:56 +01:00
}
2022-03-29 10:16:06 +02:00
// Fields from hook
$parameters = array ( 'mode' => 'create' );
$reshook = $hookmanager -> executeHooks ( 'printFieldListValue' , $parameters ); // Note that $action and $object may have been modified by hook
print $hookmanager -> resPrint ;
2019-02-23 22:24:26 +01:00
print '<td class="center">' ;
2021-09-16 11:33:42 +02:00
$form -> buttonsSaveCancel ();
print '<input type="submit" name="save" class="button buttongen marginleftonly margintoponlyshort marginbottomonlyshort button-add" value="' . $langs -> trans ( " Add " ) . '">' ;
2020-11-23 15:12:52 +01:00
print '<input type="submit" name="cancel" class="button buttongen marginleftonly margintoponlyshort marginbottomonlyshort button-cancel" value="' . $langs -> trans ( " Cancel " ) . '">' ;
2018-02-26 11:57:29 +01:00
print '</td></tr>' ;
2019-01-18 20:06:33 +01:00
print '</table>' ;
2019-07-24 16:29:50 +02:00
print '</div>' ;
2018-02-26 11:57:29 +01:00
print '<br>' ;
}
2016-08-30 20:17:34 +02:00
$moreforfilter = '' ;
2017-06-07 10:55:39 +02:00
2019-11-13 19:35:02 +01:00
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'printFieldPreListTitle' , $parameters ); // Note that $action and $object may have been modified by hook
2021-02-26 18:49:22 +01:00
if ( empty ( $reshook )) {
$moreforfilter .= $hookmanager -> resPrint ;
} else {
$moreforfilter = $hookmanager -> resPrint ;
}
2017-06-07 10:55:39 +02:00
2021-02-26 18:49:22 +01:00
if ( ! empty ( $moreforfilter )) {
2019-12-29 20:47:18 +01:00
print '<div class="liste_titre liste_titre_bydiv centpercent">' ;
print $moreforfilter ;
print '</div>' ;
2015-07-28 12:49:29 +02:00
}
2017-06-07 10:55:39 +02:00
2019-11-13 19:35:02 +01:00
$varpage = empty ( $contextpage ) ? $_SERVER [ " PHP_SELF " ] : $contextpage ;
$selectedfields = $form -> multiSelectArrayWithCheckbox ( 'selectedfields' , $arrayfields , $varpage ); // This also change content of $arrayfields
$selectedfields .= ( is_array ( $arrayofmassactions ) && count ( $arrayofmassactions ) ? $form -> showCheckAddButtons ( 'checkforselect' , 1 ) : '' );
2017-06-07 10:55:39 +02:00
2019-12-29 20:47:18 +01:00
print '<div class="div-table-responsive">' ;
2019-11-13 19:35:02 +01:00
print '<table class="tagtable nobottomiftotal liste' . ( $moreforfilter ? " listwithfilterbefore " : " " ) . '">' . " \n " ;
2017-06-07 10:55:39 +02:00
2016-08-30 20:17:34 +02:00
// Fields title search
2017-04-05 14:48:24 +02:00
print '<tr class="liste_titre_filter">' ;
// Date
2021-02-26 18:49:22 +01:00
if ( ! empty ( $arrayfields [ 't.task_date' ][ 'checked' ])) {
2018-01-04 00:23:08 +01:00
print '<td class="liste_titre">' ;
2021-02-26 18:49:22 +01:00
if ( ! empty ( $conf -> global -> MAIN_LIST_FILTER_ON_DAY )) {
print '<input class="flat valignmiddle" type="text" size="1" maxlength="2" name="search_day" value="' . $search_day . '">' ;
}
2018-05-04 11:25:21 +02:00
print '<input class="flat valignmiddle" type="text" size="1" maxlength="2" name="search_month" value="' . $search_month . '">' ;
2022-05-18 11:38:56 +02:00
print $formother -> selectyear ( $search_year , 'search_year' , 1 , 20 , 5 );
2018-01-04 00:23:08 +01:00
print '</td>' ;
}
2021-12-20 17:50:59 +01:00
if ( ! empty ( $allprojectforuser )) {
2022-06-14 14:48:15 +02:00
print '<td class="liste_titre"></td>' ;
2021-12-20 17:50:59 +01:00
}
// Task
2021-02-26 18:49:22 +01:00
if (( empty ( $id ) && empty ( $ref )) || ! empty ( $projectidforalltimes )) { // Not a dedicated task
if ( ! empty ( $arrayfields [ 't.task_ref' ][ 'checked' ])) {
print '<td class="liste_titre"><input type="text" class="flat maxwidth100" name="search_task_ref" value="' . dol_escape_htmltag ( $search_task_ref ) . '"></td>' ;
}
if ( ! empty ( $arrayfields [ 't.task_label' ][ 'checked' ])) {
print '<td class="liste_titre"><input type="text" class="flat maxwidth100" name="search_task_label" value="' . dol_escape_htmltag ( $search_task_label ) . '"></td>' ;
}
2019-12-29 20:47:18 +01:00
}
// Author
2021-02-26 18:49:22 +01:00
if ( ! empty ( $arrayfields [ 'author' ][ 'checked' ])) {
print '<td class="liste_titre">' . $form -> select_dolusers (( $search_user > 0 ? $search_user : - 1 ), 'search_user' , 1 , null , 0 , '' , '' , 0 , 0 , 0 , '' , 0 , '' , 'maxwidth250' ) . '</td>' ;
}
2017-04-05 14:48:24 +02:00
// Note
2021-02-26 18:49:22 +01:00
if ( ! empty ( $arrayfields [ 't.note' ][ 'checked' ])) {
print '<td class="liste_titre"><input type="text" class="flat maxwidth100" name="search_note" value="' . dol_escape_htmltag ( $search_note ) . '"></td>' ;
}
2017-04-05 14:48:24 +02:00
// Duration
2021-02-26 18:49:22 +01:00
if ( ! empty ( $arrayfields [ 't.task_duration' ][ 'checked' ])) {
print '<td class="liste_titre right"></td>' ;
}
2018-02-26 13:21:16 +01:00
// Value in main currency
2021-02-26 18:49:22 +01:00
if ( ! empty ( $arrayfields [ 'value' ][ 'checked' ])) {
print '<td class="liste_titre"></td>' ;
}
2019-12-29 20:47:18 +01:00
// Value billed
2021-02-26 18:49:22 +01:00
if ( ! empty ( $arrayfields [ 'valuebilled' ][ 'checked' ])) {
print '<td class="liste_titre center">' . $form -> selectyesno ( 'search_valuebilled' , $search_valuebilled , 1 , false , 1 ) . '</td>' ;
}
2019-01-18 18:11:10 +01:00
2019-12-29 20:47:18 +01:00
/*
2017-11-27 15:24:29 +01:00
// Extra fields
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_search_input.tpl.php' ;
*/
2016-08-30 20:17:34 +02:00
// Fields from hook
2019-11-13 19:35:02 +01:00
$parameters = array ( 'arrayfields' => $arrayfields );
$reshook = $hookmanager -> executeHooks ( 'printFieldListOption' , $parameters ); // Note that $action and $object may have been modified by hook
2016-08-30 20:17:34 +02:00
print $hookmanager -> resPrint ;
// Action column
2017-04-05 14:48:24 +02:00
print '<td class="liste_titre center">' ;
2019-11-13 19:35:02 +01:00
$searchpicto = $form -> showFilterButtons ();
2017-05-14 21:20:35 +02:00
print $searchpicto ;
2016-08-30 20:17:34 +02:00
print '</td>' ;
2017-06-07 10:55:39 +02:00
print '</tr>' . " \n " ;
2017-04-05 14:48:24 +02:00
print '<tr class="liste_titre">' ;
2021-02-26 18:49:22 +01:00
if ( ! empty ( $arrayfields [ 't.task_date' ][ 'checked' ])) {
print_liste_field_titre ( $arrayfields [ 't.task_date' ][ 'label' ], $_SERVER [ 'PHP_SELF' ], 't.task_date,t.task_datehour,t.rowid' , '' , $param , '' , $sortfield , $sortorder );
}
2021-12-20 17:50:59 +01:00
if ( ! empty ( $allprojectforuser )) {
2021-12-20 20:07:29 +01:00
print_liste_field_titre ( " Project " , $_SERVER [ 'PHP_SELF' ], '' , '' , $param , '' , $sortfield , $sortorder );
2021-12-20 17:50:59 +01:00
}
2021-02-26 18:49:22 +01:00
if (( empty ( $id ) && empty ( $ref )) || ! empty ( $projectidforalltimes )) { // Not a dedicated task
if ( ! empty ( $arrayfields [ 't.task_ref' ][ 'checked' ])) {
print_liste_field_titre ( $arrayfields [ 't.task_ref' ][ 'label' ], $_SERVER [ 'PHP_SELF' ], 'pt.ref' , '' , $param , '' , $sortfield , $sortorder );
}
if ( ! empty ( $arrayfields [ 't.task_label' ][ 'checked' ])) {
print_liste_field_titre ( $arrayfields [ 't.task_label' ][ 'label' ], $_SERVER [ 'PHP_SELF' ], 'pt.label' , '' , $param , '' , $sortfield , $sortorder );
}
}
if ( ! empty ( $arrayfields [ 'author' ][ 'checked' ])) {
print_liste_field_titre ( $arrayfields [ 'author' ][ 'label' ], $_SERVER [ 'PHP_SELF' ], '' , '' , $param , '' , $sortfield , $sortorder );
}
if ( ! empty ( $arrayfields [ 't.note' ][ 'checked' ])) {
print_liste_field_titre ( $arrayfields [ 't.note' ][ 'label' ], $_SERVER [ 'PHP_SELF' ], 't.note' , '' , $param , '' , $sortfield , $sortorder );
}
if ( ! empty ( $arrayfields [ 't.task_duration' ][ 'checked' ])) {
print_liste_field_titre ( $arrayfields [ 't.task_duration' ][ 'label' ], $_SERVER [ 'PHP_SELF' ], 't.task_duration' , '' , $param , '' , $sortfield , $sortorder , 'right ' );
}
if ( ! empty ( $arrayfields [ 'value' ][ 'checked' ])) {
print_liste_field_titre ( $arrayfields [ 'value' ][ 'label' ], $_SERVER [ 'PHP_SELF' ], '' , '' , $param , '' , $sortfield , $sortorder , 'right ' );
}
if ( ! empty ( $arrayfields [ 'valuebilled' ][ 'checked' ])) {
2021-05-18 13:36:07 +02:00
print_liste_field_titre ( $arrayfields [ 'valuebilled' ][ 'label' ], $_SERVER [ 'PHP_SELF' ], 'il.total_ht' , '' , $param , '' , $sortfield , $sortorder , 'center ' , $langs -> trans ( " SelectLinesOfTimeSpentToInvoice " ));
2021-02-26 18:49:22 +01:00
}
2017-04-05 14:48:24 +02:00
/*
2019-12-29 20:47:18 +01:00
// Extra fields
2017-11-27 15:24:29 +01:00
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_search_title.tpl.php' ;
*/
2019-12-29 20:47:18 +01:00
// Hook fields
2019-11-13 19:35:02 +01:00
$parameters = array ( 'arrayfields' => $arrayfields , 'param' => $param , 'sortfield' => $sortfield , 'sortorder' => $sortorder );
2019-12-29 20:47:18 +01:00
$reshook = $hookmanager -> executeHooks ( 'printFieldListTitle' , $parameters ); // Note that $action and $object may have been modified by hook
print $hookmanager -> resPrint ;
print_liste_field_titre ( $selectedfields , $_SERVER [ " PHP_SELF " ], " " , '' , '' , 'width="80"' , $sortfield , $sortorder , 'center maxwidthsearch ' );
2017-04-05 14:48:24 +02:00
print " </tr> \n " ;
2016-08-31 00:16:07 +02:00
2016-08-30 20:16:58 +02:00
$tasktmp = new Task ( $db );
2019-02-01 22:39:36 +01:00
$tmpinvoice = new Facture ( $db );
2017-06-07 10:55:39 +02:00
2016-08-31 01:04:33 +02:00
$i = 0 ;
2017-01-13 16:49:18 +01:00
2011-07-14 17:37:37 +02:00
$total = 0 ;
2015-07-28 12:49:29 +02:00
$totalvalue = 0 ;
2019-11-13 19:35:02 +01:00
$totalarray = array ();
2021-02-26 18:49:22 +01:00
foreach ( $tasks as $task_time ) {
if ( $i >= $limit ) {
break ;
}
2019-01-18 20:06:33 +01:00
2019-11-13 19:35:02 +01:00
$date1 = $db -> jdate ( $task_time -> task_date );
$date2 = $db -> jdate ( $task_time -> task_datehour );
2015-03-05 13:48:57 +01:00
2021-07-12 23:01:34 +02:00
print '<tr class="oddeven">' ;
2013-05-14 20:22:33 +02:00
// Date
2021-02-26 18:49:22 +01:00
if ( ! empty ( $arrayfields [ 't.task_date' ][ 'checked' ])) {
2019-12-29 20:47:18 +01:00
print '<td class="nowrap">' ;
2022-07-26 12:54:19 +02:00
if ( $action == 'editline' && GETPOST ( 'lineid' , 'int' ) == $task_time -> rowid ) {
2021-02-26 18:49:22 +01:00
if ( empty ( $task_time -> task_date_withhour )) {
2019-12-29 20:47:18 +01:00
print $form -> selectDate (( $date2 ? $date2 : $date1 ), 'timeline' , 3 , 3 , 2 , " timespent_date " , 1 , 0 );
2021-02-26 18:49:22 +01:00
} else {
print $form -> selectDate (( $date2 ? $date2 : $date1 ), 'timeline' , 1 , 1 , 2 , " timespent_date " , 1 , 0 );
}
2020-05-21 15:05:19 +02:00
} else {
2019-12-29 20:47:18 +01:00
print dol_print_date (( $date2 ? $date2 : $date1 ), ( $task_time -> task_date_withhour ? 'dayhour' : 'day' ));
}
print '</td>' ;
2021-02-26 18:49:22 +01:00
if ( ! $i ) {
$totalarray [ 'nbfield' ] ++ ;
}
2013-05-14 20:22:33 +02:00
}
2016-08-31 00:16:07 +02:00
2021-12-20 17:50:59 +01:00
// Project ref
if ( ! empty ( $allprojectforuser )) {
2021-12-21 23:52:01 +01:00
print '<td class="nowraponall">' ;
2021-12-20 17:50:59 +01:00
if ( empty ( $conf -> cache [ 'project' ][ $task_time -> fk_projet ])) {
$tmpproject = new Project ( $db );
$tmpproject -> fetch ( $task_time -> fk_projet );
$conf -> cache [ 'project' ][ $task_time -> fk_projet ] = $tmpproject ;
} else {
$tmpproject = $conf -> cache [ 'project' ][ $task_time -> fk_projet ];
}
print $tmpproject -> getNomUrl ( 1 );
print '</td>' ;
2021-12-21 23:52:01 +01:00
if ( ! $i ) {
$totalarray [ 'nbfield' ] ++ ;
}
2021-12-20 17:50:59 +01:00
}
2016-10-24 18:43:17 +02:00
// Task ref
2021-02-26 18:49:22 +01:00
if ( ! empty ( $arrayfields [ 't.task_ref' ][ 'checked' ])) {
if (( empty ( $id ) && empty ( $ref )) || ! empty ( $projectidforalltimes )) { // Not a dedicated task
2020-10-31 14:32:18 +01:00
print '<td class="nowrap">' ;
2022-07-26 12:54:19 +02:00
if ( $action == 'editline' && GETPOST ( 'lineid' , 'int' ) == $task_time -> rowid ) {
2021-04-30 17:56:42 +02:00
$formproject -> selectTasks ( - 1 , GETPOST ( 'taskid' , 'int' ) ? GETPOST ( 'taskid' , 'int' ) : $task_time -> fk_task , 'taskid' , 0 , 0 , 1 , 1 , 0 , 0 , 'maxwidth300' , $projectstatic -> id , '' );
2020-05-21 15:05:19 +02:00
} else {
2019-11-22 15:14:55 +01:00
$tasktmp -> id = $task_time -> fk_task ;
$tasktmp -> ref = $task_time -> ref ;
$tasktmp -> label = $task_time -> label ;
print $tasktmp -> getNomUrl ( 1 , 'withproject' , 'time' );
}
2020-10-31 14:32:18 +01:00
print '</td>' ;
2021-02-26 18:49:22 +01:00
if ( ! $i ) {
$totalarray [ 'nbfield' ] ++ ;
}
2020-10-31 14:32:18 +01:00
}
2021-08-02 19:03:38 +02:00
} elseif ( $action !== 'createtime' ) {
2020-10-31 14:32:18 +01:00
print '<input type="hidden" name="taskid" value="' . $id . '">' ;
}
2017-06-07 10:55:39 +02:00
2016-10-24 18:43:17 +02:00
// Task label
2021-02-26 18:49:22 +01:00
if ( ! empty ( $arrayfields [ 't.task_label' ][ 'checked' ])) {
if (( empty ( $id ) && empty ( $ref )) || ! empty ( $projectidforalltimes )) { // Not a dedicated task
2021-04-30 17:56:42 +02:00
print '<td class="nowrap tdoverflowmax300" title="' . dol_escape_htmltag ( $task_time -> label ) . '">' ;
print dol_escape_htmltag ( $task_time -> label );
2019-12-29 20:47:18 +01:00
print '</td>' ;
2021-02-26 18:49:22 +01:00
if ( ! $i ) {
$totalarray [ 'nbfield' ] ++ ;
}
2019-12-29 20:47:18 +01:00
}
}
2017-06-07 10:55:39 +02:00
2020-04-28 11:24:13 +02:00
// By User
2021-02-26 18:49:22 +01:00
if ( ! empty ( $arrayfields [ 'author' ][ 'checked' ])) {
2021-06-30 15:00:04 +02:00
print '<td class="tdoverflowmax100">' ;
2022-07-26 12:54:19 +02:00
if ( $action == 'editline' && GETPOST ( 'lineid' , 'int' ) == $task_time -> rowid ) {
2021-02-26 18:49:22 +01:00
if ( empty ( $object -> id )) {
$object -> fetch ( $id );
}
2019-12-29 20:47:18 +01:00
$contactsoftask = $object -> getListContactId ( 'internal' );
if ( ! in_array ( $task_time -> fk_user , $contactsoftask )) {
$contactsoftask [] = $task_time -> fk_user ;
}
if ( count ( $contactsoftask ) > 0 ) {
print img_object ( '' , 'user' , 'class="hideonsmartphone"' );
2020-04-28 11:24:13 +02:00
print $form -> select_dolusers ( $task_time -> fk_user , 'userid_line' , 0 , '' , 0 , '' , $contactsoftask , '0' , 0 , 0 , '' , 0 , '' , 'maxwidth200' );
2019-12-29 20:47:18 +01:00
} else {
print img_error ( $langs -> trans ( 'FirstAddRessourceToAllocateTime' )) . $langs -> trans ( 'FirstAddRessourceToAllocateTime' );
}
2020-05-21 15:05:19 +02:00
} else {
2020-01-30 01:48:28 +01:00
$userstatic -> id = $task_time -> fk_user ;
2019-12-29 20:47:18 +01:00
$userstatic -> lastname = $task_time -> lastname ;
2020-01-30 01:48:28 +01:00
$userstatic -> firstname = $task_time -> firstname ;
$userstatic -> photo = $task_time -> photo ;
$userstatic -> statut = $task_time -> user_status ;
2019-12-29 20:47:18 +01:00
print $userstatic -> getNomUrl ( - 1 );
}
print '</td>' ;
2021-02-26 18:49:22 +01:00
if ( ! $i ) {
$totalarray [ 'nbfield' ] ++ ;
}
2019-12-29 20:47:18 +01:00
}
2013-05-14 20:22:33 +02:00
// Note
2021-02-26 18:49:22 +01:00
if ( ! empty ( $arrayfields [ 't.note' ][ 'checked' ])) {
2021-06-30 15:00:04 +02:00
print '<td class="small">' ;
2022-07-26 12:54:19 +02:00
if ( $action == 'editline' && GETPOST ( 'lineid' , 'int' ) == $task_time -> rowid ) {
2022-10-06 14:36:53 +02:00
print '<textarea name="timespent_note_line" width="95%" rows="' . ROWS_1 . '">' . dol_escape_htmltag ( $task_time -> note , 0 , 1 ) . '</textarea>' ;
2020-05-21 15:05:19 +02:00
} else {
2019-12-29 20:47:18 +01:00
print dol_nl2br ( $task_time -> note );
}
print '</td>' ;
2021-02-26 18:49:22 +01:00
if ( ! $i ) {
$totalarray [ 'nbfield' ] ++ ;
}
2022-07-26 12:54:19 +02:00
} elseif ( $action == 'editline' && GETPOST ( 'lineid' , 'int' ) == $task_time -> rowid ) {
2022-10-06 14:36:53 +02:00
print '<input type="hidden" name="timespent_note_line" value="' . dol_escape_htmltag ( $task_time -> note , 0 , 1 ) . '">' ;
2019-12-29 20:47:18 +01:00
}
2017-06-07 10:55:39 +02:00
2013-05-14 20:22:33 +02:00
// Time spent
2021-02-26 18:49:22 +01:00
if ( ! empty ( $arrayfields [ 't.task_duration' ][ 'checked' ])) {
2021-08-19 16:12:13 +02:00
print '<td class="right nowraponall">' ;
2022-07-26 12:54:19 +02:00
if ( $action == 'editline' && GETPOST ( 'lineid' , 'int' ) == $task_time -> rowid ) {
2019-12-29 20:47:18 +01:00
print '<input type="hidden" name="old_duration" value="' . $task_time -> task_duration . '">' ;
print $form -> select_duration ( 'new_duration' , $task_time -> task_duration , 0 , 'text' );
2020-05-21 15:05:19 +02:00
} else {
2019-12-29 20:47:18 +01:00
print convertSecondToTime ( $task_time -> task_duration , 'allhourmin' );
}
print '</td>' ;
2021-02-26 18:49:22 +01:00
if ( ! $i ) {
$totalarray [ 'nbfield' ] ++ ;
}
if ( ! $i ) {
$totalarray [ 'pos' ][ $totalarray [ 'nbfield' ]] = 't.task_duration' ;
}
2019-12-29 20:47:18 +01:00
$totalarray [ 'val' ][ 't.task_duration' ] += $task_time -> task_duration ;
2021-02-26 18:49:22 +01:00
if ( ! $i ) {
$totalarray [ 'totaldurationfield' ] = $totalarray [ 'nbfield' ];
}
2019-12-29 20:47:18 +01:00
$totalarray [ 'totalduration' ] += $task_time -> task_duration ;
}
2017-06-07 10:55:39 +02:00
2015-07-28 12:49:29 +02:00
// Value spent
2021-02-26 18:49:22 +01:00
if ( ! empty ( $arrayfields [ 'value' ][ 'checked' ])) {
2021-07-12 23:01:34 +02:00
$langs -> load ( " salaries " );
2022-06-20 02:10:27 +02:00
$value = price2num ( $task_time -> thm * $task_time -> task_duration / 3600 , 'MT' , 1 );
2021-07-12 23:01:34 +02:00
2020-04-28 11:24:13 +02:00
print '<td class="nowraponall right">' ;
2021-07-12 23:01:34 +02:00
print '<span class="amount" title="' . $langs -> trans ( " THM " ) . ': ' . price ( $task_time -> thm ) . '">' ;
2016-08-31 01:04:33 +02:00
print price ( $value , 1 , $langs , 1 , - 1 , - 1 , $conf -> currency );
2021-07-12 23:01:34 +02:00
print '</span>' ;
2015-07-28 12:49:29 +02:00
print '</td>' ;
2021-02-26 18:49:22 +01:00
if ( ! $i ) {
$totalarray [ 'nbfield' ] ++ ;
}
if ( ! $i ) {
$totalarray [ 'pos' ][ $totalarray [ 'nbfield' ]] = 'value' ;
}
2019-11-05 12:47:38 +01:00
$totalarray [ 'val' ][ 'value' ] += $value ;
2021-02-26 18:49:22 +01:00
if ( ! $i ) {
$totalarray [ 'totalvaluefield' ] = $totalarray [ 'nbfield' ];
}
2019-11-05 12:47:38 +01:00
$totalarray [ 'totalvalue' ] += $value ;
2019-12-29 20:47:18 +01:00
}
2015-07-28 12:49:29 +02:00
2019-12-29 20:47:18 +01:00
// Invoiced
2021-02-26 18:49:22 +01:00
if ( ! empty ( $arrayfields [ 'valuebilled' ][ 'checked' ])) {
2019-12-29 20:47:18 +01:00
print '<td class="center">' ; // invoice_id and invoice_line_id
2021-02-26 18:49:22 +01:00
if ( empty ( $conf -> global -> PROJECT_HIDE_TASKS ) && ! empty ( $conf -> global -> PROJECT_BILL_TIME_SPENT )) {
if ( $projectstatic -> usage_bill_time ) {
if ( $task_time -> invoice_id ) {
2019-12-29 20:47:18 +01:00
$result = $tmpinvoice -> fetch ( $task_time -> invoice_id );
2021-02-26 18:49:22 +01:00
if ( $result > 0 ) {
2019-12-29 20:47:18 +01:00
print $tmpinvoice -> getNomUrl ( 1 );
}
2020-05-21 15:05:19 +02:00
} else {
2019-12-29 20:47:18 +01:00
print $langs -> trans ( " No " );
}
2020-05-21 15:05:19 +02:00
} else {
2019-12-29 20:47:18 +01:00
print '<span class="opacitymedium">' . $langs -> trans ( " NA " ) . '</span>' ;
}
}
print '</td>' ;
2021-02-26 18:49:22 +01:00
if ( ! $i ) {
$totalarray [ 'nbfield' ] ++ ;
}
2019-12-29 20:47:18 +01:00
}
2018-02-26 13:21:16 +01:00
2019-12-29 20:47:18 +01:00
/*
// Extra fields
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_print_fields.tpl.php' ;
*/
2017-11-27 15:24:29 +01:00
2016-08-30 20:17:34 +02:00
// Fields from hook
2020-05-08 01:40:25 +02:00
$parameters = array ( 'arrayfields' => $arrayfields , 'obj' => $task_time , 'i' => $i , 'totalarray' =>& $totalarray );
2019-11-13 19:35:02 +01:00
$reshook = $hookmanager -> executeHooks ( 'printFieldListValue' , $parameters ); // Note that $action and $object may have been modified by hook
2016-08-30 20:17:34 +02:00
print $hookmanager -> resPrint ;
2017-06-07 10:55:39 +02:00
2019-12-29 20:47:18 +01:00
// Action column
2018-04-26 10:07:27 +02:00
print '<td class="center nowraponall">' ;
2022-06-14 14:39:32 +02:00
if (( $action == 'editline' || $action == 'splitline' ) && GETPOST ( 'lineid' , 'int' ) == $task_time -> rowid ) {
print '<input type="hidden" name="lineid" value="' . GETPOST ( 'lineid' , 'int' ) . '">' ;
2020-11-19 20:23:38 +01:00
print '<input type="submit" class="button buttongen margintoponlyshort marginbottomonlyshort button-save" name="save" value="' . $langs -> trans ( " Save " ) . '">' ;
2022-06-14 14:39:32 +02:00
print ' ' ;
2020-11-23 15:12:52 +01:00
print '<input type="submit" class="button buttongen margintoponlyshort marginbottomonlyshort button-cancel" name="cancel" value="' . $langs -> trans ( " Cancel " ) . '">' ;
2022-06-14 14:39:32 +02:00
} elseif ( $user -> hasRight ( 'projet' , 'time' ) || $user -> hasRight ( 'projet' , 'all' , 'creer' )) { // Read project and enter time consumed on assigned tasks
2023-04-26 10:25:08 +02:00
if ( in_array ( $task_time -> fk_user , $childids ) || $user -> hasRight ( 'projet' , 'all' , 'creer' )) {
2022-06-14 14:39:32 +02:00
if ( getDolGlobalString ( 'MAIN_FEATURES_LEVEL' ) >= 2 ) {
2019-12-29 20:47:18 +01:00
print ' ' ;
2022-06-20 02:10:27 +02:00
print '<a class="reposition" href="' . $_SERVER [ " PHP_SELF " ] . '?action=splitline&token=' . newToken () . '&lineid=' . $task_time -> rowid . $param . (( empty ( $id ) || $tab == 'timespent' ) ? '&tab=timespent' : '' ) . '">' ;
2022-06-14 14:39:32 +02:00
print img_split ( '' , 'class="pictofixedwidth"' );
2019-12-29 20:47:18 +01:00
print '</a>' ;
}
2021-09-27 12:24:01 +02:00
print '<a class="reposition editfielda" href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $task_time -> fk_task . '&action=editline&token=' . newToken () . '&lineid=' . $task_time -> rowid . $param . (( empty ( $id ) || $tab == 'timespent' ) ? '&tab=timespent' : '' ) . '">' ;
2022-06-14 14:39:32 +02:00
print img_edit ( 'default' , 0 , 'class="pictofixedwidth paddingleft"' );
2017-11-22 17:25:31 +01:00
print '</a>' ;
2021-09-18 22:04:41 +02:00
print '<a class="reposition paddingleft" href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $task_time -> fk_task . '&action=deleteline&token=' . newToken () . '&lineid=' . $task_time -> rowid . $param . (( empty ( $id ) || $tab == 'timespent' ) ? '&tab=timespent' : '' ) . '">' ;
2020-04-15 14:54:54 +02:00
print img_delete ( 'default' , 'class="pictodelete paddingleft"' );
2017-11-22 17:25:31 +01:00
print '</a>' ;
2019-01-18 18:11:10 +01:00
2021-02-26 18:49:22 +01:00
if ( $massactionbutton || $massaction ) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
2019-12-29 20:47:18 +01:00
$selected = 0 ;
2021-02-26 18:49:22 +01:00
if ( in_array ( $task_time -> rowid , $arrayofselected )) {
$selected = 1 ;
}
2019-12-29 20:47:18 +01:00
print ' ' ;
print '<input id="cb' . $task_time -> rowid . '" class="flat checkforselect marginleftonly" type="checkbox" name="toselect[]" value="' . $task_time -> rowid . '"' . ( $selected ? ' checked="checked"' : '' ) . '>' ;
2019-01-18 18:11:10 +01:00
}
2019-12-29 20:47:18 +01:00
}
2010-02-24 10:53:16 +01:00
}
2019-12-29 20:47:18 +01:00
print '</td>' ;
2021-02-26 18:49:22 +01:00
if ( ! $i ) {
$totalarray [ 'nbfield' ] ++ ;
}
2017-06-07 10:55:39 +02:00
2010-02-24 10:53:16 +01:00
print " </tr> \n " ;
2017-06-07 10:55:39 +02:00
2020-04-15 14:54:54 +02:00
2019-01-04 16:24:56 +01:00
// Add line to split
2022-07-26 12:54:19 +02:00
if ( $action == 'splitline' && GETPOST ( 'lineid' , 'int' ) == $task_time -> rowid ) {
2019-12-29 20:47:18 +01:00
print '<tr class="oddeven">' ;
// Date
2021-02-26 18:49:22 +01:00
if ( ! empty ( $arrayfields [ 't.task_date' ][ 'checked' ])) {
2019-12-29 20:47:18 +01:00
print '<td class="nowrap">' ;
2022-07-26 12:54:19 +02:00
if ( $action == 'splitline' && GETPOST ( 'lineid' , 'int' ) == $task_time -> rowid ) {
2021-02-26 18:49:22 +01:00
if ( empty ( $task_time -> task_date_withhour )) {
2019-12-29 20:47:18 +01:00
print $form -> selectDate (( $date2 ? $date2 : $date1 ), 'timeline' , 3 , 3 , 2 , " timespent_date " , 1 , 0 );
2021-02-26 18:49:22 +01:00
} else {
print $form -> selectDate (( $date2 ? $date2 : $date1 ), 'timeline' , 1 , 1 , 2 , " timespent_date " , 1 , 0 );
}
2020-05-21 15:05:19 +02:00
} else {
2019-12-29 20:47:18 +01:00
print dol_print_date (( $date2 ? $date2 : $date1 ), ( $task_time -> task_date_withhour ? 'dayhour' : 'day' ));
}
print '</td>' ;
}
2021-12-21 23:52:01 +01:00
// Project ref
if ( ! empty ( $allprojectforuser )) {
if (( empty ( $id ) && empty ( $ref )) || ! empty ( $projectidforalltimes )) { // Not a dedicated task
print '<td class="nowrap">' ;
print '</td>' ;
}
}
2019-12-29 20:47:18 +01:00
// Task ref
2021-02-26 18:49:22 +01:00
if ( ! empty ( $arrayfields [ 't.task_ref' ][ 'checked' ])) {
if (( empty ( $id ) && empty ( $ref )) || ! empty ( $projectidforalltimes )) { // Not a dedicated task
2019-12-29 20:47:18 +01:00
print '<td class="nowrap">' ;
$tasktmp -> id = $task_time -> fk_task ;
$tasktmp -> ref = $task_time -> ref ;
$tasktmp -> label = $task_time -> label ;
print $tasktmp -> getNomUrl ( 1 , 'withproject' , 'time' );
print '</td>' ;
}
}
// Task label
2021-02-26 18:49:22 +01:00
if ( ! empty ( $arrayfields [ 't.task_label' ][ 'checked' ])) {
if (( empty ( $id ) && empty ( $ref )) || ! empty ( $projectidforalltimes )) { // Not a dedicated task
2021-04-30 17:56:42 +02:00
print '<td class="tdoverflowmax300" title="' . dol_escape_htmltag ( $task_time -> label ) . '">' ;
print dol_escape_htmltag ( $task_time -> label );
2019-12-29 20:47:18 +01:00
print '</td>' ;
}
}
// User
2021-02-26 18:49:22 +01:00
if ( ! empty ( $arrayfields [ 'author' ][ 'checked' ])) {
2019-12-29 20:47:18 +01:00
print '<td>' ;
2022-07-26 12:54:19 +02:00
if ( $action == 'splitline' && GETPOST ( 'lineid' , 'int' ) == $task_time -> rowid ) {
2021-02-26 18:49:22 +01:00
if ( empty ( $object -> id )) {
$object -> fetch ( $id );
}
2019-12-29 20:47:18 +01:00
$contactsoftask = $object -> getListContactId ( 'internal' );
if ( ! in_array ( $task_time -> fk_user , $contactsoftask )) {
$contactsoftask [] = $task_time -> fk_user ;
}
if ( count ( $contactsoftask ) > 0 ) {
print img_object ( '' , 'user' , 'class="hideonsmartphone"' );
print $form -> select_dolusers ( $task_time -> fk_user , 'userid_line' , 0 , '' , 0 , '' , $contactsoftask );
} else {
print img_error ( $langs -> trans ( 'FirstAddRessourceToAllocateTime' )) . $langs -> trans ( 'FirstAddRessourceToAllocateTime' );
}
2020-05-21 15:05:19 +02:00
} else {
2020-01-30 01:48:28 +01:00
$userstatic -> id = $task_time -> fk_user ;
2019-12-29 20:47:18 +01:00
$userstatic -> lastname = $task_time -> lastname ;
2020-01-30 01:48:28 +01:00
$userstatic -> firstname = $task_time -> firstname ;
$userstatic -> photo = $task_time -> photo ;
$userstatic -> statut = $task_time -> user_status ;
2019-12-29 20:47:18 +01:00
print $userstatic -> getNomUrl ( - 1 );
}
print '</td>' ;
}
// Note
2021-02-26 18:49:22 +01:00
if ( ! empty ( $arrayfields [ 't.note' ][ 'checked' ])) {
2021-04-30 17:56:42 +02:00
print '<td class="tdoverflowmax300">' ;
2022-07-26 12:54:19 +02:00
if ( $action == 'splitline' && GETPOST ( 'lineid' , 'int' ) == $task_time -> rowid ) {
2022-10-06 14:36:53 +02:00
print '<textarea name="timespent_note_line" width="95%" rows="' . ROWS_1 . '">' . dol_escape_htmltag ( $task_time -> note , 0 , 1 ) . '</textarea>' ;
2020-05-21 15:05:19 +02:00
} else {
2019-12-29 20:47:18 +01:00
print dol_nl2br ( $task_time -> note );
}
print '</td>' ;
2022-07-26 12:54:19 +02:00
} elseif ( $action == 'splitline' && GETPOST ( 'lineid' , 'int' ) == $task_time -> rowid ) {
2022-10-06 14:36:53 +02:00
print '<input type="hidden" name="timespent_note_line" rows="' . ROWS_1 . '" value="' . dol_escape_htmltag ( $task_time -> note , 0 , 1 ) . '">' ;
2019-12-29 20:47:18 +01:00
}
// Time spent
2021-02-26 18:49:22 +01:00
if ( ! empty ( $arrayfields [ 't.task_duration' ][ 'checked' ])) {
2019-12-29 20:47:18 +01:00
print '<td class="right">' ;
2022-07-26 12:54:19 +02:00
if ( $action == 'splitline' && GETPOST ( 'lineid' , 'int' ) == $task_time -> rowid ) {
2019-12-29 20:47:18 +01:00
print '<input type="hidden" name="old_duration" value="' . $task_time -> task_duration . '">' ;
print $form -> select_duration ( 'new_duration' , $task_time -> task_duration , 0 , 'text' );
2020-05-21 15:05:19 +02:00
} else {
2019-12-29 20:47:18 +01:00
print convertSecondToTime ( $task_time -> task_duration , 'allhourmin' );
}
print '</td>' ;
}
// Value spent
2021-02-26 18:49:22 +01:00
if ( ! empty ( $arrayfields [ 'value' ][ 'checked' ])) {
2019-12-29 20:47:18 +01:00
print '<td class="right">' ;
2022-06-20 02:10:27 +02:00
print '<span class="amount">' ;
2020-11-27 14:24:15 +01:00
$value = price2num ( $task_time -> thm * $task_time -> task_duration / 3600 , 'MT' , 1 );
2019-12-29 20:47:18 +01:00
print price ( $value , 1 , $langs , 1 , - 1 , - 1 , $conf -> currency );
2022-06-20 02:10:27 +02:00
print '</span>' ;
2019-12-29 20:47:18 +01:00
print '</td>' ;
}
// Value billed
2021-02-26 18:49:22 +01:00
if ( ! empty ( $arrayfields [ 'valuebilled' ][ 'checked' ])) {
2019-12-29 20:47:18 +01:00
print '<td class="right">' ;
2020-11-27 14:24:15 +01:00
$valuebilled = price2num ( $task_time -> total_ht , '' , 1 );
2021-02-26 18:49:22 +01:00
if ( isset ( $task_time -> total_ht )) {
print price ( $valuebilled , 1 , $langs , 1 , - 1 , - 1 , $conf -> currency );
}
2019-12-29 20:47:18 +01:00
print '</td>' ;
}
/*
// Extra fields
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_print_fields.tpl.php' ;
*/
// Fields from hook
2022-03-29 10:16:06 +02:00
$parameters = array ( 'arrayfields' => $arrayfields , 'obj' => $task_time , 'mode' => 'split1' );
2019-12-29 20:47:18 +01:00
$reshook = $hookmanager -> executeHooks ( 'printFieldListValue' , $parameters ); // Note that $action and $object may have been modified by hook
print $hookmanager -> resPrint ;
// Action column
print '<td class="center nowraponall">' ;
print '</td>' ;
print " </tr> \n " ;
// Line for second dispatching
print '<tr class="oddeven">' ;
// Date
2021-02-26 18:49:22 +01:00
if ( ! empty ( $arrayfields [ 't.task_date' ][ 'checked' ])) {
2019-12-29 20:47:18 +01:00
print '<td class="nowrap">' ;
2022-07-26 12:54:19 +02:00
if ( $action == 'splitline' && GETPOST ( 'lineid' , 'int' ) == $task_time -> rowid ) {
2021-02-26 18:49:22 +01:00
if ( empty ( $task_time -> task_date_withhour )) {
2019-12-29 20:47:18 +01:00
print $form -> selectDate (( $date2 ? $date2 : $date1 ), 'timeline_2' , 3 , 3 , 2 , " timespent_date " , 1 , 0 );
2021-02-26 18:49:22 +01:00
} else {
print $form -> selectDate (( $date2 ? $date2 : $date1 ), 'timeline_2' , 1 , 1 , 2 , " timespent_date " , 1 , 0 );
}
2020-05-21 15:05:19 +02:00
} else {
2019-12-29 20:47:18 +01:00
print dol_print_date (( $date2 ? $date2 : $date1 ), ( $task_time -> task_date_withhour ? 'dayhour' : 'day' ));
}
print '</td>' ;
}
2021-12-21 23:52:01 +01:00
// Project ref
if ( ! empty ( $allprojectforuser )) {
if (( empty ( $id ) && empty ( $ref )) || ! empty ( $projectidforalltimes )) { // Not a dedicated task
print '<td class="nowrap">' ;
print '</td>' ;
}
}
2019-12-29 20:47:18 +01:00
// Task ref
2021-02-26 18:49:22 +01:00
if ( ! empty ( $arrayfields [ 't.task_ref' ][ 'checked' ])) {
if (( empty ( $id ) && empty ( $ref )) || ! empty ( $projectidforalltimes )) { // Not a dedicated task
2019-12-29 20:47:18 +01:00
print '<td class="nowrap">' ;
$tasktmp -> id = $task_time -> fk_task ;
$tasktmp -> ref = $task_time -> ref ;
$tasktmp -> label = $task_time -> label ;
print $tasktmp -> getNomUrl ( 1 , 'withproject' , 'time' );
print '</td>' ;
}
}
// Task label
2021-02-26 18:49:22 +01:00
if ( ! empty ( $arrayfields [ 't.task_label' ][ 'checked' ])) {
if (( empty ( $id ) && empty ( $ref )) || ! empty ( $projectidforalltimes )) { // Not a dedicated task
2019-12-29 20:47:18 +01:00
print '<td class="nowrap">' ;
print $task_time -> label ;
print '</td>' ;
}
}
// User
2021-02-26 18:49:22 +01:00
if ( ! empty ( $arrayfields [ 'author' ][ 'checked' ])) {
2019-12-29 20:47:18 +01:00
print '<td>' ;
2022-07-26 12:54:19 +02:00
if ( $action == 'splitline' && GETPOST ( 'lineid' , 'int' ) == $task_time -> rowid ) {
2021-02-26 18:49:22 +01:00
if ( empty ( $object -> id )) {
$object -> fetch ( $id );
}
2019-12-29 20:47:18 +01:00
$contactsoftask = $object -> getListContactId ( 'internal' );
if ( ! in_array ( $task_time -> fk_user , $contactsoftask )) {
$contactsoftask [] = $task_time -> fk_user ;
}
if ( count ( $contactsoftask ) > 0 ) {
print img_object ( '' , 'user' , 'class="hideonsmartphone"' );
print $form -> select_dolusers ( $task_time -> fk_user , 'userid_line_2' , 0 , '' , 0 , '' , $contactsoftask );
} else {
print img_error ( $langs -> trans ( 'FirstAddRessourceToAllocateTime' )) . $langs -> trans ( 'FirstAddRessourceToAllocateTime' );
}
2020-05-21 15:05:19 +02:00
} else {
2020-01-30 01:48:28 +01:00
$userstatic -> id = $task_time -> fk_user ;
2019-12-29 20:47:18 +01:00
$userstatic -> lastname = $task_time -> lastname ;
2020-01-30 01:48:28 +01:00
$userstatic -> firstname = $task_time -> firstname ;
$userstatic -> photo = $task_time -> photo ;
$userstatic -> statut = $task_time -> user_status ;
2019-12-29 20:47:18 +01:00
print $userstatic -> getNomUrl ( - 1 );
}
print '</td>' ;
}
// Note
2021-02-26 18:49:22 +01:00
if ( ! empty ( $arrayfields [ 't.note' ][ 'checked' ])) {
2021-06-30 15:00:04 +02:00
print '<td class="small tdoverflowmax300"">' ;
2022-07-26 12:54:19 +02:00
if ( $action == 'splitline' && GETPOST ( 'lineid' , 'int' ) == $task_time -> rowid ) {
2022-10-06 14:36:53 +02:00
print '<textarea name="timespent_note_line_2" width="95%" rows="' . ROWS_1 . '">' . dol_escape_htmltag ( $task_time -> note , 0 , 1 ) . '</textarea>' ;
2020-05-21 15:05:19 +02:00
} else {
2019-12-29 20:47:18 +01:00
print dol_nl2br ( $task_time -> note );
}
print '</td>' ;
2022-07-26 12:54:19 +02:00
} elseif ( $action == 'splitline' && GETPOST ( 'lineid' , 'int' ) == $task_time -> rowid ) {
2022-10-06 14:36:53 +02:00
print '<input type="hidden" name="timespent_note_line_2" value="' . dol_escape_htmltag ( $task_time -> note , 0 , 1 ) . '">' ;
2019-12-29 20:47:18 +01:00
}
// Time spent
2021-02-26 18:49:22 +01:00
if ( ! empty ( $arrayfields [ 't.task_duration' ][ 'checked' ])) {
2019-12-29 20:47:18 +01:00
print '<td class="right">' ;
2022-07-26 12:54:19 +02:00
if ( $action == 'splitline' && GETPOST ( 'lineid' , 'int' ) == $task_time -> rowid ) {
2019-12-29 20:47:18 +01:00
print '<input type="hidden" name="old_duration_2" value="0">' ;
print $form -> select_duration ( 'new_duration_2' , 0 , 0 , 'text' );
2020-05-21 15:05:19 +02:00
} else {
2019-12-29 20:47:18 +01:00
print convertSecondToTime ( $task_time -> task_duration , 'allhourmin' );
}
print '</td>' ;
}
// Value spent
2021-02-26 18:49:22 +01:00
if ( ! empty ( $arrayfields [ 'value' ][ 'checked' ])) {
2019-12-29 20:47:18 +01:00
print '<td class="right">' ;
2022-06-20 02:10:27 +02:00
print '<span class="amount">' ;
2019-12-29 20:47:18 +01:00
$value = 0 ;
print price ( $value , 1 , $langs , 1 , - 1 , - 1 , $conf -> currency );
2022-06-20 02:10:27 +02:00
print '</span>' ;
2019-12-29 20:47:18 +01:00
print '</td>' ;
}
// Value billed
2021-02-26 18:49:22 +01:00
if ( ! empty ( $arrayfields [ 'valuebilled' ][ 'checked' ])) {
2019-12-29 20:47:18 +01:00
print '<td class="right">' ;
2020-11-27 14:24:15 +01:00
$valuebilled = price2num ( $task_time -> total_ht , '' , 1 );
2021-02-26 18:49:22 +01:00
if ( isset ( $task_time -> total_ht )) {
2022-06-20 02:10:27 +02:00
print '<span class="amount">' ;
2021-02-26 18:49:22 +01:00
print price ( $valuebilled , 1 , $langs , 1 , - 1 , - 1 , $conf -> currency );
2022-06-20 02:10:27 +02:00
print '</span>' ;
2021-02-26 18:49:22 +01:00
}
2019-12-29 20:47:18 +01:00
print '</td>' ;
}
/*
// Extra fields
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_print_fields.tpl.php' ;
*/
// Fields from hook
2022-03-29 10:16:06 +02:00
$parameters = array ( 'arrayfields' => $arrayfields , 'obj' => $task_time , 'mode' => 'split2' );
2019-12-29 20:47:18 +01:00
$reshook = $hookmanager -> executeHooks ( 'printFieldListValue' , $parameters ); // Note that $action and $object may have been modified by hook
print $hookmanager -> resPrint ;
// Action column
print '<td class="center nowraponall">' ;
print '</td>' ;
print " </tr> \n " ;
2019-01-04 16:24:56 +01:00
}
2016-08-31 01:04:33 +02:00
$i ++ ;
2009-07-28 02:52:34 +02:00
}
2017-06-07 10:55:39 +02:00
2016-08-31 01:04:33 +02:00
// Show total line
2019-11-05 12:47:38 +01:00
//include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
2021-02-26 18:49:22 +01:00
if ( isset ( $totalarray [ 'totaldurationfield' ]) || isset ( $totalarray [ 'totalvaluefield' ])) {
2019-11-05 12:47:38 +01:00
print '<tr class="liste_total">' ;
2019-11-13 19:35:02 +01:00
$i = 0 ;
2021-02-26 18:49:22 +01:00
while ( $i < $totalarray [ 'nbfield' ]) {
2019-11-05 12:47:38 +01:00
$i ++ ;
2021-02-26 18:49:22 +01:00
if ( $i == 1 ) {
if ( $num < $limit && empty ( $offset )) {
print '<td class="left">' . $langs -> trans ( " Total " ) . '</td>' ;
} else {
print '<td class="left">' . $langs -> trans ( " Totalforthispage " ) . '</td>' ;
}
} elseif ( $totalarray [ 'totaldurationfield' ] == $i ) {
print '<td class="right">' . convertSecondToTime ( $totalarray [ 'totalduration' ], 'allhourmin' ) . '</td>' ;
} elseif ( $totalarray [ 'totalvaluefield' ] == $i ) {
print '<td class="right">' . price ( $totalarray [ 'totalvalue' ]) . '</td>' ;
//} elseif ($totalarray['totalvaluebilledfield'] == $i) { print '<td class="center">'.price($totalarray['totalvaluebilled']).'</td>';
} else {
print '<td></td>' ;
}
2019-11-05 12:47:38 +01:00
}
print '</tr>' ;
2015-07-28 12:49:29 +02:00
}
2019-11-05 15:48:41 +01:00
2021-02-26 18:49:22 +01:00
if ( ! count ( $tasks )) {
2019-08-21 04:02:30 +02:00
$totalnboffields = 1 ;
2021-02-26 18:49:22 +01:00
foreach ( $arrayfields as $value ) {
if ( $value [ 'checked' ]) {
$totalnboffields ++ ;
}
2019-08-21 04:02:30 +02:00
}
print '<tr class="oddeven"><td colspan="' . $totalnboffields . '">' ;
print '<span class="opacitymedium">' . $langs -> trans ( " None " ) . '</span>' ;
print '</td></tr>' ;
}
2022-03-29 10:16:06 +02:00
$parameters = array ( 'arrayfields' => $arrayfields , 'sql' => $sql );
$reshook = $hookmanager -> executeHooks ( 'printFieldListFooter' , $parameters ); // Note that $action and $object may have been modified by hook
print $hookmanager -> resPrint ;
2012-02-07 10:25:58 +01:00
2009-07-28 02:52:34 +02:00
print " </table> " ;
2016-11-27 11:41:10 +01:00
print '</div>' ;
2010-02-26 09:45:22 +01:00
print " </form> " ;
2009-07-28 02:52:34 +02:00
}
}
2018-08-15 12:48:13 +02:00
// End of page
2011-08-27 16:24:16 +02:00
llxFooter ();
2012-04-18 11:16:15 +02:00
$db -> close ();