time.php 82 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173
  1. <?php
  2. /* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2006-2021 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2010-2012 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
  6. * Copyright (C) 2018 Ferran Marcet <fmarcet@2byte.es>
  7. * Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
  8. * Copyright (C) 2019-2021 Christophe Battarel <christophe@altairis.fr>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  22. */
  23. /**
  24. * \file htdocs/projet/tasks/time.php
  25. * \ingroup project
  26. * \brief Page to add new time spent on a task
  27. */
  28. require '../../main.inc.php';
  29. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php';
  33. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  35. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
  36. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formintervention.class.php';
  37. // Load translation files required by the page
  38. $langsLoad=array('projects', 'bills', 'orders');
  39. if (!empty($conf->eventorganization->enabled)) {
  40. $langsLoad[]='eventorganization';
  41. }
  42. $langs->loadLangs($langsLoad);
  43. $action = GETPOST('action', 'alpha');
  44. $massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
  45. $confirm = GETPOST('confirm', 'alpha');
  46. $cancel = GETPOST('cancel', 'alpha');
  47. $toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list
  48. $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'timespentlist'; // To manage different context of search
  49. $backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page
  50. $optioncss = GETPOST('optioncss', 'alpha');
  51. $id = GETPOST('id', 'int');
  52. $projectid = GETPOST('projectid', 'int');
  53. $ref = GETPOST('ref', 'alpha');
  54. $withproject = GETPOST('withproject', 'int');
  55. $project_ref = GETPOST('project_ref', 'alpha');
  56. $tab = GETPOST('tab', 'aZ09');
  57. $search_day = GETPOST('search_day', 'int');
  58. $search_month = GETPOST('search_month', 'int');
  59. $search_year = GETPOST('search_year', 'int');
  60. $search_datehour = '';
  61. $search_datewithhour = '';
  62. $search_note = GETPOST('search_note', 'alpha');
  63. $search_duration = GETPOST('search_duration', 'int');
  64. $search_value = GETPOST('search_value', 'int');
  65. $search_task_ref = GETPOST('search_task_ref', 'alpha');
  66. $search_task_label = GETPOST('search_task_label', 'alpha');
  67. $search_user = GETPOST('search_user', 'int');
  68. $search_valuebilled = GETPOST('search_valuebilled', 'int');
  69. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
  70. $sortfield = GETPOST('sortfield', 'aZ09comma');
  71. $sortorder = GETPOST('sortorder', 'aZ09comma');
  72. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  73. if (empty($page) || $page == -1) {
  74. $page = 0;
  75. } // If $page is not defined, or '' or -1
  76. $offset = $limit * $page;
  77. $pageprev = $page - 1;
  78. $pagenext = $page + 1;
  79. if (!$sortfield) {
  80. $sortfield = 't.task_date,t.task_datehour,t.rowid';
  81. }
  82. if (!$sortorder) {
  83. $sortorder = 'DESC,DESC,DESC';
  84. }
  85. $childids = $user->getAllChildIds(1);
  86. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  87. //$object = new TaskTime($db);
  88. $hookmanager->initHooks(array('projecttasktime', 'globalcard'));
  89. $object = new Task($db);
  90. $projectstatic = new Project($db);
  91. $extrafields = new ExtraFields($db);
  92. $extrafields->fetch_name_optionals_label($projectstatic->table_element);
  93. $extrafields->fetch_name_optionals_label($object->table_element);
  94. // Load task
  95. if ($id > 0 || $ref) {
  96. $object->fetch($id, $ref);
  97. }
  98. // Security check
  99. $socid = 0;
  100. //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.
  101. if (!$user->rights->projet->lire) {
  102. accessforbidden();
  103. }
  104. if ($object->fk_project > 0) {
  105. restrictedArea($user, 'projet', $object->fk_project, 'projet&project');
  106. } else {
  107. restrictedArea($user, 'projet', null, 'projet&project');
  108. // We check user has permission to see all tasks of all users
  109. if (empty($projectid) && !$user->hasRight('projet', 'all', 'lire')) {
  110. $search_user = $user->id;
  111. }
  112. }
  113. /*
  114. * Actions
  115. */
  116. if (GETPOST('cancel', 'alpha')) {
  117. $action = '';
  118. }
  119. if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend' && $massaction != 'confirm_generateinvoice' && $massaction != 'confirm_generateinter') {
  120. $massaction = '';
  121. }
  122. $parameters = array('socid'=>$socid, 'projectid'=>$projectid);
  123. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  124. if ($reshook < 0) {
  125. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  126. }
  127. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  128. // Purge search criteria
  129. 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
  130. $search_day = '';
  131. $search_month = '';
  132. $search_year = '';
  133. $search_date = '';
  134. $search_datehour = '';
  135. $search_datewithhour = '';
  136. $search_note = '';
  137. $search_duration = '';
  138. $search_value = '';
  139. $search_date_creation = '';
  140. $search_date_update = '';
  141. $search_task_ref = '';
  142. $search_task_label = '';
  143. $search_user = 0;
  144. $search_valuebilled = '';
  145. $toselect = '';
  146. $search_array_options = array();
  147. $action = '';
  148. }
  149. if ($action == 'addtimespent' && $user->rights->projet->lire) {
  150. $error = 0;
  151. $timespent_durationhour = GETPOST('timespent_durationhour', 'int');
  152. $timespent_durationmin = GETPOST('timespent_durationmin', 'int');
  153. if (empty($timespent_durationhour) && empty($timespent_durationmin)) {
  154. setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("Duration")), null, 'errors');
  155. $error++;
  156. }
  157. if (!GETPOST("userid", 'int')) {
  158. $langs->load("errors");
  159. setEventMessages($langs->trans('ErrorUserNotAssignedToTask'), null, 'errors');
  160. $error++;
  161. }
  162. if (!$error) {
  163. if ($id || $ref) {
  164. $object->fetch($id, $ref);
  165. } else {
  166. if (!GETPOST('taskid', 'int') || GETPOST('taskid', 'int') < 0) {
  167. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Task")), null, 'errors');
  168. $action = 'createtime';
  169. $error++;
  170. } else {
  171. $object->fetch(GETPOST('taskid', 'int'));
  172. }
  173. }
  174. if (!$error) {
  175. $object->fetch_projet();
  176. if (empty($object->project->statut)) {
  177. setEventMessages($langs->trans("ProjectMustBeValidatedFirst"), null, 'errors');
  178. $action = 'createtime';
  179. $error++;
  180. } else {
  181. $object->timespent_note = GETPOST("timespent_note", 'alpha');
  182. if (GETPOST('progress', 'int') > 0) {
  183. $object->progress = GETPOST('progress', 'int'); // If progress is -1 (not defined), we do not change value
  184. }
  185. $object->timespent_duration = GETPOSTINT("timespent_durationhour") * 60 * 60; // We store duration in seconds
  186. $object->timespent_duration += (GETPOSTINT('timespent_durationmin') ? GETPOSTINT('timespent_durationmin') : 0) * 60; // We store duration in seconds
  187. if (GETPOST("timehour") != '' && GETPOST("timehour") >= 0) { // If hour was entered
  188. $object->timespent_date = dol_mktime(GETPOST("timehour", 'int'), GETPOST("timemin", 'int'), 0, GETPOST("timemonth", 'int'), GETPOST("timeday", 'int'), GETPOST("timeyear", 'int'));
  189. $object->timespent_withhour = 1;
  190. } else {
  191. $object->timespent_date = dol_mktime(12, 0, 0, GETPOST("timemonth", 'int'), GETPOST("timeday", 'int'), GETPOST("timeyear", 'int'));
  192. }
  193. $object->timespent_fk_user = GETPOST("userid", 'int');
  194. $result = $object->addTimeSpent($user);
  195. if ($result >= 0) {
  196. setEventMessages($langs->trans("RecordSaved"), null, 'mesgs');
  197. } else {
  198. setEventMessages($langs->trans($object->error), null, 'errors');
  199. $error++;
  200. }
  201. }
  202. }
  203. } else {
  204. if (empty($id)) {
  205. $action = 'createtime';
  206. } else {
  207. $action = 'createtime';
  208. }
  209. }
  210. }
  211. if (($action == 'updateline' || $action == 'updatesplitline') && !$cancel && $user->rights->projet->lire) {
  212. $error = 0;
  213. if (!GETPOST("new_durationhour") && !GETPOST("new_durationmin")) {
  214. setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("Duration")), null, 'errors');
  215. $error++;
  216. }
  217. if (!$error) {
  218. if (GETPOST('taskid', 'int') != $id) { // GETPOST('taskid') is id of new task
  219. $id = GETPOST('taskid', 'int');
  220. $object->fetchTimeSpent(GETPOST('lineid', 'int'));
  221. $result = 0;
  222. if (in_array($object->timespent_fk_user, $childids) || $user->rights->projet->all->creer) {
  223. $result = $object->delTimeSpent($user);
  224. }
  225. $object->fetch($id, $ref);
  226. $object->timespent_note = GETPOST("timespent_note_line", 'alpha');
  227. $object->timespent_old_duration = GETPOST("old_duration");
  228. $object->timespent_duration = GETPOSTINT("new_durationhour") * 60 * 60; // We store duration in seconds
  229. $object->timespent_duration += (GETPOSTINT("new_durationmin") ? GETPOSTINT('new_durationmin') : 0) * 60; // We store duration in seconds
  230. if (GETPOST("timelinehour") != '' && GETPOST("timelinehour") >= 0) { // If hour was entered
  231. $object->timespent_date = dol_mktime(GETPOST("timelinehour"), GETPOST("timelinemin"), 0, GETPOST("timelinemonth"), GETPOST("timelineday"), GETPOST("timelineyear"));
  232. $object->timespent_withhour = 1;
  233. } else {
  234. $object->timespent_date = dol_mktime(12, 0, 0, GETPOST("timelinemonth"), GETPOST("timelineday"), GETPOST("timelineyear"));
  235. }
  236. $object->timespent_fk_user = GETPOST("userid_line", 'int');
  237. $result = 0;
  238. if (in_array($object->timespent_fk_user, $childids) || $user->rights->projet->all->creer) {
  239. $result = $object->addTimeSpent($user);
  240. }
  241. if ($result >= 0) {
  242. setEventMessages($langs->trans("RecordSaved"), null, 'mesgs');
  243. } else {
  244. setEventMessages($langs->trans($object->error), null, 'errors');
  245. $error++;
  246. }
  247. } else {
  248. $object->fetch($id, $ref);
  249. $object->timespent_id = GETPOST("lineid", 'int');
  250. $object->timespent_note = GETPOST("timespent_note_line");
  251. $object->timespent_old_duration = GETPOST("old_duration");
  252. $object->timespent_duration = GETPOSTINT("new_durationhour") * 60 * 60; // We store duration in seconds
  253. $object->timespent_duration += (GETPOSTINT("new_durationmin") ? GETPOSTINT('new_durationmin') : 0) * 60; // We store duration in seconds
  254. if (GETPOST("timelinehour") != '' && GETPOST("timelinehour") >= 0) { // If hour was entered
  255. $object->timespent_date = dol_mktime(GETPOST("timelinehour", 'int'), GETPOST("timelinemin", 'int'), 0, GETPOST("timelinemonth", 'int'), GETPOST("timelineday", 'int'), GETPOST("timelineyear", 'int'));
  256. $object->timespent_withhour = 1;
  257. } else {
  258. $object->timespent_date = dol_mktime(12, 0, 0, GETPOST("timelinemonth", 'int'), GETPOST("timelineday", 'int'), GETPOST("timelineyear", 'int'));
  259. }
  260. $object->timespent_fk_user = GETPOST("userid_line", 'int');
  261. $result = 0;
  262. if (in_array($object->timespent_fk_user, $childids) || $user->rights->projet->all->creer) {
  263. $result = $object->updateTimeSpent($user);
  264. if ($result >= 0) {
  265. setEventMessages($langs->trans("RecordSaved"), null, 'mesgs');
  266. } else {
  267. setEventMessages($langs->trans($object->error), null, 'errors');
  268. $error++;
  269. }
  270. }
  271. }
  272. } else {
  273. $action = '';
  274. }
  275. }
  276. if ($action == 'confirm_deleteline' && $confirm == "yes" && $user->rights->projet->lire) {
  277. $object->fetchTimeSpent(GETPOST('lineid', 'int')); // load properties like $object->timespent_id
  278. if (in_array($object->timespent_fk_user, $childids) || $user->rights->projet->all->creer) {
  279. $result = $object->delTimeSpent($user); // delete line with $object->timespent_id
  280. if ($result < 0) {
  281. $langs->load("errors");
  282. setEventMessages($langs->trans($object->error), null, 'errors');
  283. $error++;
  284. $action = '';
  285. } else {
  286. setEventMessages($langs->trans("RecordDeleted"), null, 'mesgs');
  287. }
  288. }
  289. }
  290. // Retrieve First Task ID of Project if withprojet is on to allow project prev next to work
  291. if (!empty($project_ref) && !empty($withproject)) {
  292. if ($projectstatic->fetch(0, $project_ref) > 0) {
  293. $tasksarray = $object->getTasksArray(0, 0, $projectstatic->id, $socid, 0);
  294. if (count($tasksarray) > 0) {
  295. $id = $tasksarray[0]->id;
  296. } else {
  297. header("Location: ".DOL_URL_ROOT.'/projet/tasks.php?id='.$projectstatic->id.($withproject ? '&withproject=1' : '').(empty($mode) ? '' : '&mode='.$mode));
  298. exit;
  299. }
  300. }
  301. }
  302. // To show all time lines for project
  303. $projectidforalltimes = 0;
  304. if (GETPOST('projectid', 'int') > 0) {
  305. $projectidforalltimes = GETPOST('projectid', 'int');
  306. $result = $projectstatic->fetch($projectidforalltimes);
  307. if (!empty($projectstatic->socid)) {
  308. $projectstatic->fetch_thirdparty();
  309. }
  310. $res = $projectstatic->fetch_optionals();
  311. } elseif (GETPOST('project_ref', 'alpha')) {
  312. $projectstatic->fetch(0, GETPOST('project_ref', 'alpha'));
  313. $projectidforalltimes = $projectstatic->id;
  314. $withproject = 1;
  315. } elseif ($id > 0) {
  316. $object->fetch($id);
  317. $result = $projectstatic->fetch($object->fk_project);
  318. }
  319. // If not task selected and no project selected
  320. if ($id <= 0 && $projectidforalltimes == 0) {
  321. $allprojectforuser = $user->id;
  322. }
  323. if ($action == 'confirm_generateinvoice') {
  324. if (!empty($projectstatic->socid)) {
  325. $projectstatic->fetch_thirdparty();
  326. }
  327. if (!($projectstatic->thirdparty->id > 0)) {
  328. setEventMessages($langs->trans("ThirdPartyRequiredToGenerateInvoice"), null, 'errors');
  329. } else {
  330. include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
  331. include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  332. include_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  333. $tmpinvoice = new Facture($db);
  334. $tmptimespent = new Task($db);
  335. $tmpproduct = new Product($db);
  336. $fuser = new User($db);
  337. $db->begin();
  338. $idprod = GETPOST('productid', 'int');
  339. $generateinvoicemode = GETPOST('generateinvoicemode', 'string');
  340. $invoiceToUse = GETPOST('invoiceid', 'int');
  341. $prodDurationHours = 1.0;
  342. if ($idprod > 0) {
  343. $tmpproduct->fetch($idprod);
  344. if (empty($tmpproduct->duration_value)) {
  345. $error++;
  346. $langs->load("errors");
  347. setEventMessages($langs->trans("ErrorDurationForServiceNotDefinedCantCalculateHourlyPrice"), null, 'errors');
  348. }
  349. if ($tmpproduct->duration_unit == 'i') {
  350. $prodDurationHours = 1. / 60;
  351. }
  352. if ($tmpproduct->duration_unit == 'h') {
  353. $prodDurationHours = 1.;
  354. }
  355. if ($tmpproduct->duration_unit == 'd') {
  356. $prodDurationHours = 24.;
  357. }
  358. if ($tmpproduct->duration_unit == 'w') {
  359. $prodDurationHours = 24. * 7;
  360. }
  361. if ($tmpproduct->duration_unit == 'm') {
  362. $prodDurationHours = 24. * 30;
  363. }
  364. if ($tmpproduct->duration_unit == 'y') {
  365. $prodDurationHours = 24. * 365;
  366. }
  367. $prodDurationHours *= $tmpproduct->duration_value;
  368. $dataforprice = $tmpproduct->getSellPrice($mysoc, $projectstatic->thirdparty, 0);
  369. $pu_ht = empty($dataforprice['pu_ht']) ? 0 : $dataforprice['pu_ht'];
  370. $txtva = $dataforprice['tva_tx'];
  371. $localtax1 = $dataforprice['localtax1'];
  372. $localtax2 = $dataforprice['localtax2'];
  373. } else {
  374. $prodDurationHours = 1;
  375. $pu_ht = 0;
  376. $txtva = get_default_tva($mysoc, $projectstatic->thirdparty);
  377. $localtax1 = get_default_localtax($mysoc, $projectstatic->thirdparty, 1);
  378. $localtax2 = get_default_localtax($mysoc, $projectstatic->thirdparty, 2);
  379. }
  380. $tmpinvoice->socid = $projectstatic->thirdparty->id;
  381. $tmpinvoice->date = dol_mktime(GETPOST('rehour', 'int'), GETPOST('remin', 'int'), GETPOST('resec', 'int'), GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int'));
  382. $tmpinvoice->fk_project = $projectstatic->id;
  383. if ($invoiceToUse) {
  384. $tmpinvoice->fetch($invoiceToUse);
  385. } else {
  386. $result = $tmpinvoice->create($user);
  387. if ($result <= 0) {
  388. $error++;
  389. setEventMessages($tmpinvoice->error, $tmpinvoice->errors, 'errors');
  390. }
  391. }
  392. if (!$error) {
  393. if ($generateinvoicemode == 'onelineperuser') {
  394. $arrayoftasks = array();
  395. foreach ($toselect as $key => $value) {
  396. // Get userid, timepent
  397. $object->fetchTimeSpent($value);
  398. $arrayoftasks[$object->timespent_fk_user]['timespent'] += $object->timespent_duration;
  399. $arrayoftasks[$object->timespent_fk_user]['totalvaluetodivideby3600'] += ($object->timespent_duration * $object->timespent_thm);
  400. }
  401. foreach ($arrayoftasks as $userid => $value) {
  402. $fuser->fetch($userid);
  403. //$pu_ht = $value['timespent'] * $fuser->thm;
  404. $username = $fuser->getFullName($langs);
  405. // Define qty per hour
  406. $qtyhour = $value['timespent'] / 3600;
  407. $qtyhourtext = convertSecondToTime($value['timespent'], 'all', $conf->global->MAIN_DURATION_OF_WORKDAY);
  408. // If no unit price known
  409. if (empty($pu_ht)) {
  410. $pu_ht = price2num($value['totalvaluetodivideby3600'] / 3600, 'MU');
  411. }
  412. // Add lines
  413. $lineid = $tmpinvoice->addline($langs->trans("TimeSpentForInvoice", $username).' : '.$qtyhourtext, $pu_ht, round($qtyhour / $prodDurationHours, 2), $txtva, $localtax1, $localtax2, ($idprod > 0 ? $idprod : 0));
  414. // Update lineid into line of timespent
  415. $sql = 'UPDATE '.MAIN_DB_PREFIX.'projet_task_time SET invoice_line_id = '.((int) $lineid).', invoice_id = '.((int) $tmpinvoice->id);
  416. $sql .= ' WHERE rowid IN ('.$db->sanitize(join(',', $toselect)).') AND fk_user = '.((int) $userid);
  417. $result = $db->query($sql);
  418. if (!$result) {
  419. $error++;
  420. setEventMessages($db->lasterror(), null, 'errors');
  421. break;
  422. }
  423. }
  424. } elseif ($generateinvoicemode == 'onelineperperiod') { // One line for each time spent line
  425. $arrayoftasks = array();
  426. $withdetail=GETPOST('detail_time_duration', 'alpha');
  427. foreach ($toselect as $key => $value) {
  428. // Get userid, timepent
  429. $object->fetchTimeSpent($value);
  430. // $object->id is the task id
  431. $ftask = new Task($db);
  432. $ftask->fetch($object->id);
  433. $fuser->fetch($object->timespent_fk_user);
  434. $username = $fuser->getFullName($langs);
  435. $arrayoftasks[$object->timespent_id]['timespent'] = $object->timespent_duration;
  436. $arrayoftasks[$object->timespent_id]['totalvaluetodivideby3600'] = $object->timespent_duration * $object->timespent_thm;
  437. $arrayoftasks[$object->timespent_id]['note'] = $ftask->ref.' - '.$ftask->label.' - '.$username.($object->timespent_note ? ' - '.$object->timespent_note : ''); // TODO Add user name in note
  438. if (!empty($withdetail)) {
  439. if (!empty($conf->fckeditor->enabled) && !empty($conf->global->FCKEDITOR_ENABLE_DETAILS)) {
  440. $arrayoftasks[$object->timespent_id]['note'] .= "<br/>";
  441. } else {
  442. $arrayoftasks[$object->timespent_id]['note'] .= "\n";
  443. }
  444. if (!empty($object->timespent_withhour)) {
  445. $arrayoftasks[$object->timespent_id]['note'] .= $langs->trans("Date") . ': ' . dol_print_date($object->timespent_datehour);
  446. } else {
  447. $arrayoftasks[$object->timespent_id]['note'] .= $langs->trans("Date") . ': ' . dol_print_date($object->timespent_date);
  448. }
  449. $arrayoftasks[$object->timespent_id]['note'] .= ' - '.$langs->trans("Duration").': '.convertSecondToTime($object->timespent_duration, 'all', $conf->global->MAIN_DURATION_OF_WORKDAY);
  450. }
  451. $arrayoftasks[$object->timespent_id]['user'] = $object->timespent_fk_user;
  452. }
  453. foreach ($arrayoftasks as $timespent_id => $value) {
  454. $userid = $value['user'];
  455. //$pu_ht = $value['timespent'] * $fuser->thm;
  456. // Define qty per hour
  457. $qtyhour = $value['timespent'] / 3600;
  458. // If no unit price known
  459. if (empty($pu_ht)) {
  460. $pu_ht = price2num($value['totalvaluetodivideby3600'] / 3600, 'MU');
  461. }
  462. // Add lines
  463. $lineid = $tmpinvoice->addline($value['note'], $pu_ht, round($qtyhour / $prodDurationHours, 2), $txtva, $localtax1, $localtax2, ($idprod > 0 ? $idprod : 0));
  464. //var_dump($lineid);exit;
  465. // Update lineid into line of timespent
  466. $sql = 'UPDATE '.MAIN_DB_PREFIX.'projet_task_time SET invoice_line_id = '.((int) $lineid).', invoice_id = '.((int) $tmpinvoice->id);
  467. $sql .= ' WHERE rowid IN ('.$db->sanitize(join(',', $toselect)).') AND fk_user = '.((int) $userid);
  468. $result = $db->query($sql);
  469. if (!$result) {
  470. $error++;
  471. setEventMessages($db->lasterror(), null, 'errors');
  472. break;
  473. }
  474. }
  475. } elseif ($generateinvoicemode == 'onelinepertask') { // One line for each different task
  476. $arrayoftasks = array();
  477. foreach ($toselect as $key => $value) {
  478. // Get userid, timepent
  479. $object->fetchTimeSpent($value); // Call method to get list of timespent for a timespent line id (We use the utiliy method found into Task object)
  480. // $object->id is now the task id
  481. $arrayoftasks[$object->id]['timespent'] += $object->timespent_duration;
  482. $arrayoftasks[$object->id]['totalvaluetodivideby3600'] += ($object->timespent_duration * $object->timespent_thm);
  483. }
  484. foreach ($arrayoftasks as $task_id => $value) {
  485. $ftask = new Task($db);
  486. $ftask->fetch($task_id);
  487. // Define qty per hour
  488. $qtyhour = $value['timespent'] / 3600;
  489. $qtyhourtext = convertSecondToTime($value['timespent'], 'all', $conf->global->MAIN_DURATION_OF_WORKDAY);
  490. if ($idprod > 0) {
  491. // If a product is defined, we msut use the $prodDurationHours and $pu_ht of product (already set previously).
  492. $pu_ht_for_task = $pu_ht;
  493. // If we want to reuse the value of timespent (so use same price than cost price)
  494. if (!empty($conf->global->PROJECT_TIME_SPENT_INTO_INVOICE_USE_VALUE)) {
  495. $pu_ht_for_task = price2num($value['totalvaluetodivideby3600'] / $value['timespent'], 'MU') * $prodDurationHours;
  496. }
  497. $pa_ht = price2num($value['totalvaluetodivideby3600'] / $value['timespent'], 'MU') * $prodDurationHours;
  498. } else {
  499. // If not product used, we use the hour unit for duration and unit price.
  500. $pu_ht_for_task = 0;
  501. // If we want to reuse the value of timespent (so use same price than cost price)
  502. if (!empty($conf->global->PROJECT_TIME_SPENT_INTO_INVOICE_USE_VALUE)) {
  503. $pu_ht_for_task = price2num($value['totalvaluetodivideby3600'] / $value['timespent'], 'MU');
  504. }
  505. $pa_ht = price2num($value['totalvaluetodivideby3600'] / $value['timespent'], 'MU');
  506. }
  507. // Add lines
  508. $date_start = '';
  509. $date_end = '';
  510. $lineName = $ftask->ref.' - '.$ftask->label;
  511. $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);
  512. if ($lineid < 0) {
  513. $error++;
  514. setEventMessages($tmpinvoice->error, $tmpinvoice->errors, 'errors');
  515. break;
  516. }
  517. if (!$error) {
  518. // Update lineid into line of timespent
  519. $sql = 'UPDATE '.MAIN_DB_PREFIX.'projet_task_time SET invoice_line_id = '.((int) $lineid).', invoice_id = '.((int) $tmpinvoice->id);
  520. $sql .= ' WHERE rowid IN ('.$db->sanitize(join(',', $toselect)).')';
  521. $result = $db->query($sql);
  522. if (!$result) {
  523. $error++;
  524. setEventMessages($db->lasterror(), null, 'errors');
  525. break;
  526. }
  527. }
  528. }
  529. }
  530. }
  531. if (!$error) {
  532. $urltoinvoice = $tmpinvoice->getNomUrl(0);
  533. $mesg = $langs->trans("InvoiceGeneratedFromTimeSpent", '{s1}');
  534. $mesg = str_replace('{s1}', $urltoinvoice, $mesg);
  535. setEventMessages($mesg, null, 'mesgs');
  536. //var_dump($tmpinvoice);
  537. $db->commit();
  538. } else {
  539. $db->rollback();
  540. }
  541. }
  542. }
  543. if ($action == 'confirm_generateinter') {
  544. $langs->load('interventions');
  545. if (!empty($projectstatic->socid)) $projectstatic->fetch_thirdparty();
  546. if (!($projectstatic->thirdparty->id > 0)) {
  547. setEventMessages($langs->trans("ThirdPartyRequiredToGenerateIntervention"), null, 'errors');
  548. } else {
  549. include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
  550. include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  551. include_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  552. require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
  553. $tmpinter = new Fichinter($db);
  554. $tmptimespent = new Task($db);
  555. $fuser = new User($db);
  556. $db->begin();
  557. $interToUse = GETPOST('interid', 'int');
  558. $tmpinter->socid = $projectstatic->thirdparty->id;
  559. $tmpinter->date = dol_mktime(GETPOST('rehour', 'int'), GETPOST('remin', 'int'), GETPOST('resec', 'int'), GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int'));
  560. $tmpinter->fk_project = $projectstatic->id;
  561. $tmpinter->description = $projectstatic->title . ( ! empty($projectstatic->description) ? '-' . $projectstatic->label : '' );
  562. if ($interToUse) {
  563. $tmpinter->fetch($interToUse);
  564. } else {
  565. $result = $tmpinter->create($user);
  566. if ($result <= 0) {
  567. $error++;
  568. setEventMessages($tmpinter->error, $tmpinter->errors, 'errors');
  569. }
  570. }
  571. if (!$error) {
  572. $arrayoftasks = array();
  573. foreach ($toselect as $key => $value) {
  574. // Get userid, timepent
  575. $object->fetchTimeSpent($value);
  576. // $object->id is the task id
  577. $arrayoftasks[$object->timespent_id]['timespent'] = $object->timespent_duration;
  578. $arrayoftasks[$object->timespent_id]['totalvaluetodivideby3600'] = $object->timespent_duration * $object->timespent_thm;
  579. $arrayoftasks[$object->timespent_id]['note'] = $object->timespent_note;
  580. $arrayoftasks[$object->timespent_id]['date'] = date('Y-m-d H:i:s', $object->timespent_datehour);
  581. }
  582. foreach ($arrayoftasks as $timespent_id => $value) {
  583. $ftask = new Task($db);
  584. $ftask->fetch($object->id);
  585. // Define qty per hour
  586. $qtyhour = $value['timespent'] / 3600;
  587. $qtyhourtext = convertSecondToTime($value['timespent'], 'all', $conf->global->MAIN_DURATION_OF_WORKDAY);
  588. // Add lines
  589. $lineid = $tmpinter->addline($user, $tmpinter->id, $ftask->label . ( ! empty($value['note']) ? ' - ' . $value['note'] : '' ), $value['date'], $value['timespent']);
  590. }
  591. }
  592. if (!$error) {
  593. $urltointer = $tmpinter->getNomUrl(0);
  594. $mesg = $langs->trans("InterventionGeneratedFromTimeSpent", '{s1}');
  595. $mesg = str_replace('{s1}', $urltointer, $mesg);
  596. setEventMessages($mesg, null, 'mesgs');
  597. //var_dump($tmpinvoice);
  598. $db->commit();
  599. } else {
  600. $db->rollback();
  601. }
  602. }
  603. }
  604. /*
  605. * View
  606. */
  607. $arrayofselected = is_array($toselect) ? $toselect : array();
  608. llxHeader("", $langs->trans("Task"));
  609. $form = new Form($db);
  610. $formother = new FormOther($db);
  611. $formproject = new FormProjets($db);
  612. $userstatic = new User($db);
  613. if (($id > 0 || !empty($ref)) || $projectidforalltimes > 0 || $allprojectforuser > 0) {
  614. /*
  615. * Fiche projet en mode visu
  616. */
  617. if ($projectidforalltimes > 0) {
  618. $result = $projectstatic->fetch($projectidforalltimes);
  619. if (!empty($projectstatic->socid)) {
  620. $projectstatic->fetch_thirdparty();
  621. }
  622. $res = $projectstatic->fetch_optionals();
  623. } elseif ($object->fetch($id, $ref) >= 0) {
  624. if (!empty($conf->global->PROJECT_ALLOW_COMMENT_ON_TASK) && method_exists($object, 'fetchComments') && empty($object->comments)) {
  625. $object->fetchComments();
  626. }
  627. $result = $projectstatic->fetch($object->fk_project);
  628. if (!empty($conf->global->PROJECT_ALLOW_COMMENT_ON_PROJECT) && method_exists($projectstatic, 'fetchComments') && empty($projectstatic->comments)) {
  629. $projectstatic->fetchComments();
  630. }
  631. if (!empty($projectstatic->socid)) {
  632. $projectstatic->fetch_thirdparty();
  633. }
  634. $res = $projectstatic->fetch_optionals();
  635. $object->project = clone $projectstatic;
  636. }
  637. $userRead = $projectstatic->restrictedProjectArea($user, 'read');
  638. $linktocreatetime = '';
  639. if ($projectstatic->id > 0) {
  640. if ($withproject) {
  641. // Tabs for project
  642. if (empty($id) || $tab == 'timespent') {
  643. $tab = 'timespent';
  644. } else {
  645. $tab = 'tasks';
  646. }
  647. $head = project_prepare_head($projectstatic);
  648. print dol_get_fiche_head($head, $tab, $langs->trans("Project"), -1, ($projectstatic->public ? 'projectpub' : 'project'));
  649. $param = ((!empty($mode) && $mode == 'mine') ? '&mode=mine' : '');
  650. if ($search_user) {
  651. $param .= '&search_user='.((int) $search_user);
  652. }
  653. if ($search_month) {
  654. $param .= '&search_month='.((int) $search_month);
  655. }
  656. if ($search_year) {
  657. $param .= '&search_year='.((int) $search_year);
  658. }
  659. // Project card
  660. $linkback = '<a href="'.DOL_URL_ROOT.'/projet/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  661. $morehtmlref = '<div class="refidno">';
  662. // Title
  663. $morehtmlref .= $projectstatic->title;
  664. // Thirdparty
  665. if (!empty($projectstatic->thirdparty->id) && $projectstatic->thirdparty->id > 0) {
  666. $morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$projectstatic->thirdparty->getNomUrl(1, 'project');
  667. }
  668. $morehtmlref .= '</div>';
  669. // Define a complementary filter for search of next/prev ref.
  670. if (empty($user->rights->projet->all->lire)) {
  671. $objectsListId = $projectstatic->getProjectsAuthorizedForUser($user, 0, 0);
  672. $projectstatic->next_prev_filter = " rowid IN (".$db->sanitize(count($objectsListId) ?join(',', array_keys($objectsListId)) : '0').")";
  673. }
  674. dol_banner_tab($projectstatic, 'project_ref', $linkback, 1, 'ref', 'ref', $morehtmlref, $param);
  675. print '<div class="fichecenter">';
  676. print '<div class="fichehalfleft">';
  677. print '<div class="underbanner clearboth"></div>';
  678. print '<table class="border tableforfield centpercent">';
  679. // Usage
  680. if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES) || empty($conf->global->PROJECT_HIDE_TASKS) || !empty($conf->eventorganization->enabled)) {
  681. print '<tr><td class="tdtop">';
  682. print $langs->trans("Usage");
  683. print '</td>';
  684. print '<td>';
  685. if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES)) {
  686. print '<input type="checkbox" disabled name="usage_opportunity"'.(GETPOSTISSET('usage_opportunity') ? (GETPOST('usage_opportunity', 'alpha') != '' ? ' checked="checked"' : '') : ($projectstatic->usage_opportunity ? ' checked="checked"' : '')).'"> ';
  687. $htmltext = $langs->trans("ProjectFollowOpportunity");
  688. print $form->textwithpicto($langs->trans("ProjectFollowOpportunity"), $htmltext);
  689. print '<br>';
  690. }
  691. if (empty($conf->global->PROJECT_HIDE_TASKS)) {
  692. print '<input type="checkbox" disabled name="usage_task"'.(GETPOSTISSET('usage_task') ? (GETPOST('usage_task', 'alpha') != '' ? ' checked="checked"' : '') : ($projectstatic->usage_task ? ' checked="checked"' : '')).'"> ';
  693. $htmltext = $langs->trans("ProjectFollowTasks");
  694. print $form->textwithpicto($langs->trans("ProjectFollowTasks"), $htmltext);
  695. print '<br>';
  696. }
  697. if (empty($conf->global->PROJECT_HIDE_TASKS) && !empty($conf->global->PROJECT_BILL_TIME_SPENT)) {
  698. 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"' : '')).'"> ';
  699. $htmltext = $langs->trans("ProjectBillTimeDescription");
  700. print $form->textwithpicto($langs->trans("BillTime"), $htmltext);
  701. print '<br>';
  702. }
  703. if (!empty($conf->eventorganization->enabled)) {
  704. 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"' : '')).'"> ';
  705. $htmltext = $langs->trans("EventOrganizationDescriptionLong");
  706. print $form->textwithpicto($langs->trans("ManageOrganizeEvent"), $htmltext);
  707. }
  708. print '</td></tr>';
  709. }
  710. // Visibility
  711. print '<tr><td class="titlefield">'.$langs->trans("Visibility").'</td><td>';
  712. if ($projectstatic->public) {
  713. print $langs->trans('SharedProject');
  714. } else {
  715. print $langs->trans('PrivateProject');
  716. }
  717. print '</td></tr>';
  718. // Date start - end
  719. print '<tr><td>'.$langs->trans("DateStart").' - '.$langs->trans("DateEnd").'</td><td>';
  720. $start = dol_print_date($projectstatic->date_start, 'day');
  721. print ($start ? $start : '?');
  722. $end = dol_print_date($projectstatic->date_end, 'day');
  723. print ' - ';
  724. print ($end ? $end : '?');
  725. if ($projectstatic->hasDelay()) {
  726. print img_warning("Late");
  727. }
  728. print '</td></tr>';
  729. // Budget
  730. print '<tr><td>'.$langs->trans("Budget").'</td><td>';
  731. if (strcmp($projectstatic->budget_amount, '')) {
  732. print '<span class="amount">'.price($projectstatic->budget_amount, '', $langs, 1, 0, 0, $conf->currency).'</span>';
  733. }
  734. print '</td></tr>';
  735. // Other attributes
  736. $cols = 2;
  737. //include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
  738. print '</table>';
  739. print '</div>';
  740. print '<div class="fichehalfright">';
  741. print '<div class="underbanner clearboth"></div>';
  742. print '<table class="border tableforfield centpercent">';
  743. // Description
  744. print '<td class="titlefield tdtop">'.$langs->trans("Description").'</td><td>';
  745. print nl2br($projectstatic->description);
  746. print '</td></tr>';
  747. // Categories
  748. if ($conf->categorie->enabled) {
  749. print '<tr><td class="valignmiddle">'.$langs->trans("Categories").'</td><td>';
  750. print $form->showCategories($projectstatic->id, 'project', 1);
  751. print "</td></tr>";
  752. }
  753. print '</table>';
  754. print '</div>';
  755. print '</div>';
  756. print '<div class="clearboth"></div>';
  757. print dol_get_fiche_end();
  758. print '<br>';
  759. }
  760. // Link to create time
  761. $linktocreatetimeBtnStatus = 0;
  762. $linktocreatetimeUrl = '';
  763. $linktocreatetimeHelpText = '';
  764. if ($user->rights->projet->all->lire || $user->rights->projet->lire) { // To enter time, read permission is enough
  765. if ($projectstatic->public || $userRead > 0) {
  766. $linktocreatetimeBtnStatus = 1;
  767. if (!empty($projectidforalltimes)) { // We are on tab 'Time Spent' of project
  768. $backtourl = $_SERVER['PHP_SELF'].'?projectid='.$projectstatic->id.($withproject ? '&withproject=1' : '');
  769. $linktocreatetimeUrl = $_SERVER['PHP_SELF'].'?'.($withproject ? 'withproject=1' : '').'&projectid='.$projectstatic->id.'&action=createtime'.$param.'&backtopage='.urlencode($backtourl);
  770. } else // We are on tab 'Time Spent' of task
  771. {
  772. $backtourl = $_SERVER['PHP_SELF'].'?id='.$object->id.($withproject ? '&withproject=1' : '');
  773. $linktocreatetimeUrl = $_SERVER['PHP_SELF'].'?'.($withproject ? 'withproject=1' : '').($object->id > 0 ? '&id='.$object->id : '&projectid='.$projectstatic->id).'&action=createtime'.$param.'&backtopage='.urlencode($backtourl);
  774. }
  775. } else {
  776. $linktocreatetimeBtnStatus = -2;
  777. $linktocreatetimeHelpText = $langs->trans("NotOwnerOfProject");
  778. }
  779. }
  780. $paramsbutton = array('morecss'=>'reposition');
  781. $linktocreatetime = dolGetButtonTitle($langs->trans('AddTimeSpent'), $linktocreatetimeHelpText, 'fa fa-plus-circle', $linktocreatetimeUrl, '', $linktocreatetimeBtnStatus, $paramsbutton);
  782. }
  783. $massactionbutton = '';
  784. $arrayofmassactions = array();
  785. if ($projectstatic->usage_bill_time) {
  786. $arrayofmassactions = array(
  787. 'generateinvoice'=>$langs->trans("GenerateBill"),
  788. //'builddoc'=>$langs->trans("PDFMerge"),
  789. );
  790. }
  791. if ( ! empty($conf->ficheinter->enabled) && $user->rights->ficheinter->creer) {
  792. $langs->load("interventions");
  793. $arrayofmassactions['generateinter'] = $langs->trans("GenerateInter");
  794. }
  795. //if ($user->rights->projet->creer) $arrayofmassactions['predelete']='<span class="fa fa-trash paddingrightonly"></span>'.$langs->trans("Delete");
  796. if (in_array($massaction, array('presend', 'predelete', 'generateinvoice', 'generateinter'))) {
  797. $arrayofmassactions = array();
  798. }
  799. $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
  800. // Show section with information of task. If id of task is not defined and project id defined, then $projectidforalltimes is not empty.
  801. if (empty($projectidforalltimes) && empty($allprojectforuser)) {
  802. $head = task_prepare_head($object);
  803. print dol_get_fiche_head($head, 'task_time', $langs->trans("Task"), -1, 'projecttask', 0, '', 'reposition');
  804. if ($action == 'deleteline') {
  805. 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);
  806. }
  807. $param = ($withproject ? '&withproject=1' : '');
  808. $linkback = $withproject ? '<a href="'.DOL_URL_ROOT.'/projet/tasks.php?id='.$projectstatic->id.'">'.$langs->trans("BackToList").'</a>' : '';
  809. if (!GETPOST('withproject') || empty($projectstatic->id)) {
  810. $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1);
  811. $object->next_prev_filter = " fk_projet IN (".$db->sanitize($projectsListId).")";
  812. } else {
  813. $object->next_prev_filter = " fk_projet = ".$projectstatic->id;
  814. }
  815. $morehtmlref = '';
  816. // Project
  817. if (empty($withproject)) {
  818. $morehtmlref .= '<div class="refidno">';
  819. $morehtmlref .= $langs->trans("Project").': ';
  820. $morehtmlref .= $projectstatic->getNomUrl(1);
  821. $morehtmlref .= '<br>';
  822. // Third party
  823. $morehtmlref .= $langs->trans("ThirdParty").': ';
  824. if (is_object($projectstatic->thirdparty)) {
  825. $morehtmlref .= $projectstatic->thirdparty->getNomUrl(1);
  826. }
  827. $morehtmlref .= '</div>';
  828. }
  829. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, $param);
  830. print '<div class="fichecenter">';
  831. print '<div class="fichehalfleft">';
  832. print '<div class="underbanner clearboth"></div>';
  833. print '<table class="border tableforfield centpercent">';
  834. // Date start - Date end
  835. print '<tr><td class="titlefield">'.$langs->trans("DateStart").' - '.$langs->trans("DateEnd").'</td><td>';
  836. $start = dol_print_date($object->date_start, 'dayhour');
  837. print ($start ? $start : '?');
  838. $end = dol_print_date($object->date_end, 'dayhour');
  839. print ' - ';
  840. print ($end ? $end : '?');
  841. if ($object->hasDelay()) {
  842. print img_warning("Late");
  843. }
  844. print '</td></tr>';
  845. // Planned workload
  846. print '<tr><td>'.$langs->trans("PlannedWorkload").'</td><td>';
  847. if ($object->planned_workload) {
  848. print convertSecondToTime($object->planned_workload, 'allhourmin');
  849. }
  850. print '</td></tr>';
  851. print '</table>';
  852. print '</div>';
  853. print '<div class="fichehalfright">';
  854. print '<div class="underbanner clearboth"></div>';
  855. print '<table class="border tableforfield centpercent">';
  856. // Progress declared
  857. print '<tr><td class="titlefield">'.$langs->trans("ProgressDeclared").'</td><td>';
  858. print $object->progress != '' ? $object->progress.' %' : '';
  859. print '</td></tr>';
  860. // Progress calculated
  861. print '<tr><td>'.$langs->trans("ProgressCalculated").'</td><td>';
  862. if ($object->planned_workload) {
  863. $tmparray = $object->getSummaryOfTimeSpent();
  864. if ($tmparray['total_duration'] > 0) {
  865. print round($tmparray['total_duration'] / $object->planned_workload * 100, 2).' %';
  866. } else {
  867. print '0 %';
  868. }
  869. } else {
  870. print '<span class="opacitymedium">'.$langs->trans("WorkloadNotDefined").'</span>';
  871. }
  872. print '</td>';
  873. print '</tr>';
  874. print '</table>';
  875. print '</div>';
  876. print '</div>';
  877. print '<div class="clearboth"></div>';
  878. print dol_get_fiche_end();
  879. }
  880. if ($projectstatic->id > 0 || $allprojectforuser > 0) {
  881. if ($action == 'deleteline' && !empty($projectidforalltimes)) {
  882. 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);
  883. }
  884. // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array
  885. $hookmanager->initHooks(array('tasktimelist'));
  886. // Definition of fields for list
  887. $arrayfields = array();
  888. $arrayfields['t.task_date'] = array('label'=>$langs->trans("Date"), 'checked'=>1);
  889. if ((empty($id) && empty($ref)) || !empty($projectidforalltimes)) { // Not a dedicated task
  890. $arrayfields['t.task_ref'] = array('label'=>$langs->trans("RefTask"), 'checked'=>1);
  891. $arrayfields['t.task_label'] = array('label'=>$langs->trans("LabelTask"), 'checked'=>1);
  892. }
  893. $arrayfields['author'] = array('label'=>$langs->trans("By"), 'checked'=>1);
  894. $arrayfields['t.note'] = array('label'=>$langs->trans("Note"), 'checked'=>1);
  895. $arrayfields['t.task_duration'] = array('label'=>$langs->trans("Duration"), 'checked'=>1);
  896. $arrayfields['value'] = array('label'=>$langs->trans("Value"), 'checked'=>1, 'enabled'=>(empty($conf->salaries->enabled) ? 0 : 1));
  897. $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));
  898. // Extra fields
  899. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
  900. $arrayfields = dol_sort_array($arrayfields, 'position');
  901. $param = '';
  902. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  903. $param .= '&contextpage='.urlencode($contextpage);
  904. }
  905. if ($limit > 0 && $limit != $conf->liste_limit) {
  906. $param .= '&limit='.urlencode($limit);
  907. }
  908. if ($search_month > 0) {
  909. $param .= '&search_month='.urlencode($search_month);
  910. }
  911. if ($search_year > 0) {
  912. $param .= '&search_year='.urlencode($search_year);
  913. }
  914. if ($search_user > 0) {
  915. $param .= '&search_user='.urlencode($search_user);
  916. }
  917. if ($search_task_ref != '') {
  918. $param .= '&search_task_ref='.urlencode($search_task_ref);
  919. }
  920. if ($search_task_label != '') {
  921. $param .= '&search_task_label='.urlencode($search_task_label);
  922. }
  923. if ($search_note != '') {
  924. $param .= '&search_note='.urlencode($search_note);
  925. }
  926. if ($search_duration != '') {
  927. $param .= '&amp;search_field2='.urlencode($search_duration);
  928. }
  929. if ($optioncss != '') {
  930. $param .= '&optioncss='.urlencode($optioncss);
  931. }
  932. /*
  933. // Add $param from extra fields
  934. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
  935. */
  936. if ($id) {
  937. $param .= '&id='.urlencode($id);
  938. }
  939. if ($projectid) {
  940. $param .= '&projectid='.urlencode($projectid);
  941. }
  942. if ($withproject) {
  943. $param .= '&withproject='.urlencode($withproject);
  944. }
  945. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  946. if ($optioncss != '') {
  947. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  948. }
  949. print '<input type="hidden" name="token" value="'.newToken().'">';
  950. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  951. if ($action == 'editline') {
  952. print '<input type="hidden" name="action" value="updateline">';
  953. } elseif ($action == 'splitline') {
  954. print '<input type="hidden" name="action" value="updatesplitline">';
  955. } elseif ($action == 'createtime' && $user->rights->projet->lire) {
  956. print '<input type="hidden" name="action" value="addtimespent">';
  957. } elseif ($massaction == 'generateinvoice' && $user->rights->facture->lire) {
  958. print '<input type="hidden" name="action" value="confirm_generateinvoice">';
  959. } elseif ($massaction == 'generateinter' && $user->rights->ficheinter->lire) {
  960. print '<input type="hidden" name="action" value="confirm_generateinter">';
  961. } else {
  962. print '<input type="hidden" name="action" value="list">';
  963. }
  964. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  965. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  966. print '<input type="hidden" name="id" value="'.$id.'">';
  967. print '<input type="hidden" name="projectid" value="'.$projectidforalltimes.'">';
  968. print '<input type="hidden" name="withproject" value="'.$withproject.'">';
  969. print '<input type="hidden" name="tab" value="'.$tab.'">';
  970. print '<input type="hidden" name="page_y" value="">';
  971. // Form to convert time spent into invoice
  972. if ($massaction == 'generateinvoice') {
  973. print '<input type="hidden" name="massaction" value="confirm_createbills">';
  974. if ($projectstatic->thirdparty->id > 0) {
  975. print '<table class="noborder centerpercent">';
  976. print '<tr>';
  977. print '<td class="titlefield">';
  978. print $langs->trans('DateInvoice');
  979. print '</td>';
  980. print '<td>';
  981. print $form->selectDate('', '', '', '', '', '', 1, 1);
  982. print '</td>';
  983. print '</tr>';
  984. print '<tr>';
  985. print '<td>';
  986. print $langs->trans('Mode');
  987. print '</td>';
  988. print '<td>';
  989. $tmparray = array(
  990. 'onelineperuser'=>'OneLinePerUser',
  991. 'onelinepertask'=>'OneLinePerTask',
  992. 'onelineperperiod'=>'OneLinePerTimeSpentLine',
  993. );
  994. print $form->selectarray('generateinvoicemode', $tmparray, 'onelineperuser', 0, 0, 0, '', 1);
  995. print "\n".'<script type="text/javascript">';
  996. print '
  997. $(document).ready(function () {
  998. setDetailVisibility();
  999. $("#generateinvoicemode").change(function() {
  1000. setDetailVisibility();
  1001. });
  1002. function setDetailVisibility() {
  1003. generateinvoicemode = $("#generateinvoicemode option:selected").val();
  1004. if (generateinvoicemode=="onelineperperiod") {
  1005. $("#detail_time_duration").show();
  1006. } else {
  1007. $("#detail_time_duration").hide();
  1008. }
  1009. }
  1010. });
  1011. ';
  1012. print '</script>'."\n";
  1013. print '<span style="display:none" id="detail_time_duration"><input type="checkbox" value="detail" name="detail_time_duration"/>'.$langs->trans('AddDetailDateAndDuration').'</span>';
  1014. print '</td>';
  1015. print '</tr>';
  1016. if ($conf->service->enabled) {
  1017. print '<tr>';
  1018. print '<td>';
  1019. print $langs->trans('ServiceToUseOnLines');
  1020. print '</td>';
  1021. print '<td>';
  1022. $form->select_produits('', 'productid', '1', 0, $projectstatic->thirdparty->price_level, 1, 2, '', 0, array(), $projectstatic->thirdparty->id, 'None', 0, 'maxwidth500');
  1023. print '</td>';
  1024. print '</tr>';
  1025. }
  1026. print '<tr>';
  1027. print '<td class="titlefield">';
  1028. print $langs->trans('InvoiceToUse');
  1029. print '</td>';
  1030. print '<td>';
  1031. $form->selectInvoice('invoice', '', 'invoiceid', 24, 0, $langs->trans('NewInvoice'), 1, 0, 0, 'maxwidth500', '', 'all');
  1032. print '</td>';
  1033. print '</tr>';
  1034. /*print '<tr>';
  1035. print '<td>';
  1036. print $langs->trans('ValidateInvoices');
  1037. print '</td>';
  1038. print '<td>';
  1039. print $form->selectyesno('validate_invoices', 0, 1);
  1040. print '</td>';
  1041. print '</tr>';*/
  1042. print '</table>';
  1043. print '<br>';
  1044. print '<div class="center">';
  1045. print '<input type="submit" class="button" id="createbills" name="createbills" value="'.$langs->trans('GenerateBill').'"> ';
  1046. print '<input type="submit" class="button button-cancel" id="cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
  1047. print '</div>';
  1048. print '<br>';
  1049. } else {
  1050. print '<div class="warning">'.$langs->trans("ThirdPartyRequiredToGenerateInvoice").'</div>';
  1051. print '<div class="center">';
  1052. print '<input type="submit" class="button button-cancel" id="cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
  1053. print '</div>';
  1054. $massaction = '';
  1055. }
  1056. } elseif ($massaction == 'generateinter') {
  1057. // Form to convert time spent into invoice
  1058. print '<input type="hidden" name="massaction" value="confirm_createinter">';
  1059. if ($projectstatic->thirdparty->id > 0) {
  1060. print '<table class="noborder" width="100%" >';
  1061. print '<tr>';
  1062. print '<td class="titlefield">';
  1063. print $langs->trans('InterToUse');
  1064. print '</td>';
  1065. print '<td>';
  1066. $forminter = new FormIntervention($db);
  1067. print $forminter->select_interventions($projectstatic->thirdparty->id, '', 'interid', 24, $langs->trans('NewInter'), true);
  1068. print '</td>';
  1069. print '</tr>';
  1070. print '</table>';
  1071. print '<br>';
  1072. print '<div class="center">';
  1073. print '<input type="submit" class="button" id="createinter" name="createinter" value="'.$langs->trans('GenerateInter').'"> ';
  1074. print '<input type="submit" class="button" id="cancel" name="cancel" value="'.$langs->trans('Cancel').'">';
  1075. print '</div>';
  1076. print '<br>';
  1077. } else {
  1078. print '<div class="warning">'.$langs->trans("ThirdPartyRequiredToGenerateIntervention").'</div>';
  1079. print '<div class="center">';
  1080. print '<input type="submit" class="button" id="cancel" name="cancel" value="'.$langs->trans('Cancel').'">';
  1081. print '</div>';
  1082. $massaction = '';
  1083. }
  1084. }
  1085. /*
  1086. * List of time spent
  1087. */
  1088. $tasks = array();
  1089. $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,";
  1090. $sql .= " pt.ref, pt.label, pt.fk_projet,";
  1091. $sql .= " u.lastname, u.firstname, u.login, u.photo, u.statut as user_status,";
  1092. $sql .= " il.fk_facture as invoice_id, inv.fk_statut";
  1093. $sql .= " FROM ".MAIN_DB_PREFIX."projet_task_time as t";
  1094. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facturedet as il ON il.rowid = t.invoice_line_id";
  1095. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facture as inv ON inv.rowid = il.fk_facture,";
  1096. $sql .= " ".MAIN_DB_PREFIX."projet_task as pt, ".MAIN_DB_PREFIX."user as u";
  1097. $sql .= " WHERE t.fk_user = u.rowid AND t.fk_task = pt.rowid";
  1098. if (empty($projectidforalltimes) && empty($allprojectforuser)) {
  1099. // Limit on one task
  1100. $sql .= " AND t.fk_task =".((int) $object->id);
  1101. } elseif (!empty($projectidforalltimes)) {
  1102. // Limit on one project
  1103. $sql .= " AND pt.fk_projet IN (".$db->sanitize($projectidforalltimes).")";
  1104. } elseif (!empty($allprojectforuser)) {
  1105. // Limit on on user
  1106. if (empty($search_user)) {
  1107. $search_user = $user->id;
  1108. }
  1109. $sql .= " AND t.fk_user = ".((int) $search_user);
  1110. }
  1111. if ($search_note) {
  1112. $sql .= natural_search('t.note', $search_note);
  1113. }
  1114. if ($search_task_ref) {
  1115. $sql .= natural_search('pt.ref', $search_task_ref);
  1116. }
  1117. if ($search_task_label) {
  1118. $sql .= natural_search('pt.label', $search_task_label);
  1119. }
  1120. if ($search_user > 0) {
  1121. $sql .= natural_search('t.fk_user', $search_user, 2);
  1122. }
  1123. if ($search_valuebilled == '1') {
  1124. $sql .= ' AND t.invoice_id > 0';
  1125. }
  1126. if ($search_valuebilled == '0') {
  1127. $sql .= ' AND (t.invoice_id = 0 OR t.invoice_id IS NULL)';
  1128. }
  1129. $sql .= dolSqlDateFilter('t.task_datehour', $search_day, $search_month, $search_year);
  1130. $sql .= $db->order($sortfield, $sortorder);
  1131. // Count total nb of records
  1132. $nbtotalofrecords = '';
  1133. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
  1134. $resql = $db->query($sql);
  1135. if (! $resql) {
  1136. dol_print_error($db);
  1137. exit;
  1138. }
  1139. $nbtotalofrecords = $db->num_rows($resql);
  1140. if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0
  1141. $page = 0;
  1142. $offset = 0;
  1143. }
  1144. }
  1145. // if total of record found is smaller than limit, no need to do paging and to restart another select with limits set.
  1146. if (is_numeric($nbtotalofrecords) && $limit > $nbtotalofrecords) {
  1147. $num = $nbtotalofrecords;
  1148. } else {
  1149. $sql .= $db->plimit($limit + 1, $offset);
  1150. $resql = $db->query($sql);
  1151. if (!$resql) {
  1152. dol_print_error($db);
  1153. exit;
  1154. }
  1155. $num = $db->num_rows($resql);
  1156. }
  1157. if ($num >= 0) {
  1158. if (!empty($projectidforalltimes)) {
  1159. print '<!-- List of time spent for project -->'."\n";
  1160. $title = $langs->trans("ListTaskTimeUserProject");
  1161. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'clock', 0, $linktocreatetime, '', $limit, 0, 0, 1);
  1162. } else {
  1163. print '<!-- List of time spent -->'."\n";
  1164. $title = $langs->trans("ListTaskTimeForTask");
  1165. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'clock', 0, $linktocreatetime, '', $limit, 0, 0, 1);
  1166. }
  1167. $i = 0;
  1168. while ($i < $num) {
  1169. $row = $db->fetch_object($resql);
  1170. $tasks[$i] = $row;
  1171. $i++;
  1172. }
  1173. $db->free($resql);
  1174. } else {
  1175. dol_print_error($db);
  1176. }
  1177. /*
  1178. * Form to add a new line of time spent
  1179. */
  1180. if ($action == 'createtime' && $user->rights->projet->lire) {
  1181. print '<!-- table to add time spent -->'."\n";
  1182. if (!empty($id)) {
  1183. print '<input type="hidden" name="taskid" value="'.$id.'">';
  1184. }
  1185. 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
  1186. print '<table class="noborder nohover centpercent">';
  1187. print '<tr class="liste_titre">';
  1188. print '<td>'.$langs->trans("Date").'</td>';
  1189. if (!empty($allprojectforuser)) {
  1190. print '<td>'.$langs->trans("Project").'</td>';
  1191. }
  1192. if (empty($id)) {
  1193. print '<td>'.$langs->trans("Task").'</td>';
  1194. }
  1195. print '<td>'.$langs->trans("By").'</td>';
  1196. print '<td>'.$langs->trans("Note").'</td>';
  1197. print '<td>'.$langs->trans("NewTimeSpent").'</td>';
  1198. print '<td>'.$langs->trans("ProgressDeclared").'</td>';
  1199. if (empty($conf->global->PROJECT_HIDE_TASKS) && !empty($conf->global->PROJECT_BILL_TIME_SPENT)) {
  1200. print '<td></td>';
  1201. }
  1202. print '<td></td>';
  1203. print "</tr>\n";
  1204. print '<tr class="oddeven nohover">';
  1205. // Date
  1206. print '<td class="maxwidthonsmartphone">';
  1207. $newdate = '';
  1208. print $form->selectDate($newdate, 'time', ($conf->browser->layout == 'phone' ? 2 : 1), 1, 2, "timespent_date", 1, 0);
  1209. print '</td>';
  1210. if (!empty($allprojectforuser)) {
  1211. print '<td>';
  1212. // Add project selector
  1213. print '</td>';
  1214. }
  1215. // Task
  1216. $nboftasks = 0;
  1217. if (empty($id)) {
  1218. print '<td class="maxwidthonsmartphone">';
  1219. $nboftasks = $formproject->selectTasks(-1, GETPOST('taskid', 'int'), 'taskid', 0, 0, 1, 1, 0, 0, 'maxwidth300', $projectstatic->id, 'progress');
  1220. print '</td>';
  1221. }
  1222. // Contributor
  1223. print '<td class="maxwidthonsmartphone nowraponall">';
  1224. $contactsofproject = $projectstatic->getListContactId('internal');
  1225. if (count($contactsofproject) > 0) {
  1226. print img_object('', 'user', 'class="hideonsmartphone"');
  1227. if (in_array($user->id, $contactsofproject)) {
  1228. $userid = $user->id;
  1229. } else {
  1230. $userid = $contactsofproject[0];
  1231. }
  1232. if ($projectstatic->public) {
  1233. $contactsofproject = array();
  1234. }
  1235. print $form->select_dolusers((GETPOST('userid', 'int') ? GETPOST('userid', 'int') : $userid), 'userid', 0, '', 0, '', $contactsofproject, 0, 0, 0, '', 0, $langs->trans("ResourceNotAssignedToProject"), 'maxwidth250');
  1236. } else {
  1237. if ($nboftasks) {
  1238. print img_error($langs->trans('FirstAddRessourceToAllocateTime')).' '.$langs->trans('FirstAddRessourceToAllocateTime');
  1239. }
  1240. }
  1241. print '</td>';
  1242. // Note
  1243. print '<td>';
  1244. print '<textarea name="timespent_note" class="maxwidth100onsmartphone" rows="'.ROWS_2.'">'.(GETPOST('timespent_note') ? GETPOST('timespent_note') : '').'</textarea>';
  1245. print '</td>';
  1246. // Duration - Time spent
  1247. print '<td class="nowraponall">';
  1248. $durationtouse = (GETPOST('timespent_duration') ? GETPOST('timespent_duration') : '');
  1249. if (GETPOSTISSET('timespent_durationhour') || GETPOSTISSET('timespent_durationmin')) {
  1250. $durationtouse = (GETPOST('timespent_durationhour') * 3600 + GETPOST('timespent_durationmin') * 60);
  1251. }
  1252. print $form->select_duration('timespent_duration', $durationtouse, 0, 'text');
  1253. print '</td>';
  1254. // Progress declared
  1255. print '<td class="nowrap">';
  1256. print $formother->select_percent(GETPOST('progress') ?GETPOST('progress') : $object->progress, 'progress', 0, 5, 0, 100, 1);
  1257. print '</td>';
  1258. // Invoiced
  1259. if (empty($conf->global->PROJECT_HIDE_TASKS) && !empty($conf->global->PROJECT_BILL_TIME_SPENT)) {
  1260. print '<td>';
  1261. print '</td>';
  1262. }
  1263. print '<td class="center">';
  1264. $form->buttonsSaveCancel();
  1265. print '<input type="submit" name="save" class="button buttongen marginleftonly margintoponlyshort marginbottomonlyshort button-add" value="'.$langs->trans("Add").'">';
  1266. print '<input type="submit" name="cancel" class="button buttongen marginleftonly margintoponlyshort marginbottomonlyshort button-cancel" value="'.$langs->trans("Cancel").'">';
  1267. print '</td></tr>';
  1268. print '</table>';
  1269. print '</div>';
  1270. print '<br>';
  1271. }
  1272. $moreforfilter = '';
  1273. $parameters = array();
  1274. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook
  1275. if (empty($reshook)) {
  1276. $moreforfilter .= $hookmanager->resPrint;
  1277. } else {
  1278. $moreforfilter = $hookmanager->resPrint;
  1279. }
  1280. if (!empty($moreforfilter)) {
  1281. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  1282. print $moreforfilter;
  1283. print '</div>';
  1284. }
  1285. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  1286. $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
  1287. $selectedfields .= (is_array($arrayofmassactions) && count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
  1288. print '<div class="div-table-responsive">';
  1289. print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  1290. // Fields title search
  1291. print '<tr class="liste_titre_filter">';
  1292. // Date
  1293. if (!empty($arrayfields['t.task_date']['checked'])) {
  1294. print '<td class="liste_titre">';
  1295. if (!empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) {
  1296. print '<input class="flat valignmiddle" type="text" size="1" maxlength="2" name="search_day" value="'.$search_day.'">';
  1297. }
  1298. print '<input class="flat valignmiddle" type="text" size="1" maxlength="2" name="search_month" value="'.$search_month.'">';
  1299. $formother->select_year($search_year, 'search_year', 1, 20, 5);
  1300. print '</td>';
  1301. }
  1302. if (!empty($allprojectforuser)) {
  1303. print '<td></td>';
  1304. }
  1305. // Task
  1306. if ((empty($id) && empty($ref)) || !empty($projectidforalltimes)) { // Not a dedicated task
  1307. if (!empty($arrayfields['t.task_ref']['checked'])) {
  1308. print '<td class="liste_titre"><input type="text" class="flat maxwidth100" name="search_task_ref" value="'.dol_escape_htmltag($search_task_ref).'"></td>';
  1309. }
  1310. if (!empty($arrayfields['t.task_label']['checked'])) {
  1311. print '<td class="liste_titre"><input type="text" class="flat maxwidth100" name="search_task_label" value="'.dol_escape_htmltag($search_task_label).'"></td>';
  1312. }
  1313. }
  1314. // Author
  1315. if (!empty($arrayfields['author']['checked'])) {
  1316. 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>';
  1317. }
  1318. // Note
  1319. if (!empty($arrayfields['t.note']['checked'])) {
  1320. print '<td class="liste_titre"><input type="text" class="flat maxwidth100" name="search_note" value="'.dol_escape_htmltag($search_note).'"></td>';
  1321. }
  1322. // Duration
  1323. if (!empty($arrayfields['t.task_duration']['checked'])) {
  1324. print '<td class="liste_titre right"></td>';
  1325. }
  1326. // Value in main currency
  1327. if (!empty($arrayfields['value']['checked'])) {
  1328. print '<td class="liste_titre"></td>';
  1329. }
  1330. // Value billed
  1331. if (!empty($arrayfields['valuebilled']['checked'])) {
  1332. print '<td class="liste_titre center">'.$form->selectyesno('search_valuebilled', $search_valuebilled, 1, false, 1).'</td>';
  1333. }
  1334. /*
  1335. // Extra fields
  1336. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
  1337. */
  1338. // Fields from hook
  1339. $parameters = array('arrayfields'=>$arrayfields);
  1340. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook
  1341. print $hookmanager->resPrint;
  1342. // Action column
  1343. print '<td class="liste_titre center">';
  1344. $searchpicto = $form->showFilterButtons();
  1345. print $searchpicto;
  1346. print '</td>';
  1347. print '</tr>'."\n";
  1348. print '<tr class="liste_titre">';
  1349. if (!empty($arrayfields['t.task_date']['checked'])) {
  1350. print_liste_field_titre($arrayfields['t.task_date']['label'], $_SERVER['PHP_SELF'], 't.task_date,t.task_datehour,t.rowid', '', $param, '', $sortfield, $sortorder);
  1351. }
  1352. if (!empty($allprojectforuser)) {
  1353. print_liste_field_titre("Project", $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder);
  1354. }
  1355. if ((empty($id) && empty($ref)) || !empty($projectidforalltimes)) { // Not a dedicated task
  1356. if (!empty($arrayfields['t.task_ref']['checked'])) {
  1357. print_liste_field_titre($arrayfields['t.task_ref']['label'], $_SERVER['PHP_SELF'], 'pt.ref', '', $param, '', $sortfield, $sortorder);
  1358. }
  1359. if (!empty($arrayfields['t.task_label']['checked'])) {
  1360. print_liste_field_titre($arrayfields['t.task_label']['label'], $_SERVER['PHP_SELF'], 'pt.label', '', $param, '', $sortfield, $sortorder);
  1361. }
  1362. }
  1363. if (!empty($arrayfields['author']['checked'])) {
  1364. print_liste_field_titre($arrayfields['author']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder);
  1365. }
  1366. if (!empty($arrayfields['t.note']['checked'])) {
  1367. print_liste_field_titre($arrayfields['t.note']['label'], $_SERVER['PHP_SELF'], 't.note', '', $param, '', $sortfield, $sortorder);
  1368. }
  1369. if (!empty($arrayfields['t.task_duration']['checked'])) {
  1370. print_liste_field_titre($arrayfields['t.task_duration']['label'], $_SERVER['PHP_SELF'], 't.task_duration', '', $param, '', $sortfield, $sortorder, 'right ');
  1371. }
  1372. if (!empty($arrayfields['value']['checked'])) {
  1373. print_liste_field_titre($arrayfields['value']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'right ');
  1374. }
  1375. if (!empty($arrayfields['valuebilled']['checked'])) {
  1376. print_liste_field_titre($arrayfields['valuebilled']['label'], $_SERVER['PHP_SELF'], 'il.total_ht', '', $param, '', $sortfield, $sortorder, 'center ', $langs->trans("SelectLinesOfTimeSpentToInvoice"));
  1377. }
  1378. /*
  1379. // Extra fields
  1380. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  1381. */
  1382. // Hook fields
  1383. $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
  1384. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook
  1385. print $hookmanager->resPrint;
  1386. print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', 'width="80"', $sortfield, $sortorder, 'center maxwidthsearch ');
  1387. print "</tr>\n";
  1388. $tasktmp = new Task($db);
  1389. $tmpinvoice = new Facture($db);
  1390. $i = 0;
  1391. $total = 0;
  1392. $totalvalue = 0;
  1393. $totalarray = array();
  1394. foreach ($tasks as $task_time) {
  1395. if ($i >= $limit) {
  1396. break;
  1397. }
  1398. $date1 = $db->jdate($task_time->task_date);
  1399. $date2 = $db->jdate($task_time->task_datehour);
  1400. print '<tr class="oddeven">';
  1401. // Date
  1402. if (!empty($arrayfields['t.task_date']['checked'])) {
  1403. print '<td class="nowrap">';
  1404. if ($action == 'editline' && $_GET['lineid'] == $task_time->rowid) {
  1405. if (empty($task_time->task_date_withhour)) {
  1406. print $form->selectDate(($date2 ? $date2 : $date1), 'timeline', 3, 3, 2, "timespent_date", 1, 0);
  1407. } else {
  1408. print $form->selectDate(($date2 ? $date2 : $date1), 'timeline', 1, 1, 2, "timespent_date", 1, 0);
  1409. }
  1410. } else {
  1411. print dol_print_date(($date2 ? $date2 : $date1), ($task_time->task_date_withhour ? 'dayhour' : 'day'));
  1412. }
  1413. print '</td>';
  1414. if (!$i) {
  1415. $totalarray['nbfield']++;
  1416. }
  1417. }
  1418. // Project ref
  1419. if (!empty($allprojectforuser)) {
  1420. print '<td class="nowraponall">';
  1421. if (empty($conf->cache['project'][$task_time->fk_projet])) {
  1422. $tmpproject = new Project($db);
  1423. $tmpproject->fetch($task_time->fk_projet);
  1424. $conf->cache['project'][$task_time->fk_projet] = $tmpproject;
  1425. } else {
  1426. $tmpproject = $conf->cache['project'][$task_time->fk_projet];
  1427. }
  1428. print $tmpproject->getNomUrl(1);
  1429. print '</td>';
  1430. if (!$i) {
  1431. $totalarray['nbfield']++;
  1432. }
  1433. }
  1434. // Task ref
  1435. if (!empty($arrayfields['t.task_ref']['checked'])) {
  1436. if ((empty($id) && empty($ref)) || !empty($projectidforalltimes)) { // Not a dedicated task
  1437. print '<td class="nowrap">';
  1438. if ($action == 'editline' && $_GET['lineid'] == $task_time->rowid) {
  1439. $formproject->selectTasks(-1, GETPOST('taskid', 'int') ? GETPOST('taskid', 'int') : $task_time->fk_task, 'taskid', 0, 0, 1, 1, 0, 0, 'maxwidth300', $projectstatic->id, '');
  1440. } else {
  1441. $tasktmp->id = $task_time->fk_task;
  1442. $tasktmp->ref = $task_time->ref;
  1443. $tasktmp->label = $task_time->label;
  1444. print $tasktmp->getNomUrl(1, 'withproject', 'time');
  1445. }
  1446. print '</td>';
  1447. if (!$i) {
  1448. $totalarray['nbfield']++;
  1449. }
  1450. }
  1451. } elseif ($action !== 'createtime') {
  1452. print '<input type="hidden" name="taskid" value="'.$id.'">';
  1453. }
  1454. // Task label
  1455. if (!empty($arrayfields['t.task_label']['checked'])) {
  1456. if ((empty($id) && empty($ref)) || !empty($projectidforalltimes)) { // Not a dedicated task
  1457. print '<td class="nowrap tdoverflowmax300" title="'.dol_escape_htmltag($task_time->label).'">';
  1458. print dol_escape_htmltag($task_time->label);
  1459. print '</td>';
  1460. if (!$i) {
  1461. $totalarray['nbfield']++;
  1462. }
  1463. }
  1464. }
  1465. // By User
  1466. if (!empty($arrayfields['author']['checked'])) {
  1467. print '<td class="tdoverflowmax100">';
  1468. if ($action == 'editline' && $_GET['lineid'] == $task_time->rowid) {
  1469. if (empty($object->id)) {
  1470. $object->fetch($id);
  1471. }
  1472. $contactsoftask = $object->getListContactId('internal');
  1473. if (!in_array($task_time->fk_user, $contactsoftask)) {
  1474. $contactsoftask[] = $task_time->fk_user;
  1475. }
  1476. if (count($contactsoftask) > 0) {
  1477. print img_object('', 'user', 'class="hideonsmartphone"');
  1478. print $form->select_dolusers($task_time->fk_user, 'userid_line', 0, '', 0, '', $contactsoftask, '0', 0, 0, '', 0, '', 'maxwidth200');
  1479. } else {
  1480. print img_error($langs->trans('FirstAddRessourceToAllocateTime')).$langs->trans('FirstAddRessourceToAllocateTime');
  1481. }
  1482. } else {
  1483. $userstatic->id = $task_time->fk_user;
  1484. $userstatic->lastname = $task_time->lastname;
  1485. $userstatic->firstname = $task_time->firstname;
  1486. $userstatic->photo = $task_time->photo;
  1487. $userstatic->statut = $task_time->user_status;
  1488. print $userstatic->getNomUrl(-1);
  1489. }
  1490. print '</td>';
  1491. if (!$i) {
  1492. $totalarray['nbfield']++;
  1493. }
  1494. }
  1495. // Note
  1496. if (!empty($arrayfields['t.note']['checked'])) {
  1497. print '<td class="small">';
  1498. if ($action == 'editline' && $_GET['lineid'] == $task_time->rowid) {
  1499. print '<textarea name="timespent_note_line" width="95%" rows="'.ROWS_2.'">'.$task_time->note.'</textarea>';
  1500. } else {
  1501. print dol_nl2br($task_time->note);
  1502. }
  1503. print '</td>';
  1504. if (!$i) {
  1505. $totalarray['nbfield']++;
  1506. }
  1507. } elseif ($action == 'editline' && $_GET['lineid'] == $task_time->rowid) {
  1508. print '<input type="hidden" name="timespent_note_line" value="'.$task_time->note.'">';
  1509. }
  1510. // Time spent
  1511. if (!empty($arrayfields['t.task_duration']['checked'])) {
  1512. print '<td class="right nowraponall">';
  1513. if ($action == 'editline' && $_GET['lineid'] == $task_time->rowid) {
  1514. print '<input type="hidden" name="old_duration" value="'.$task_time->task_duration.'">';
  1515. print $form->select_duration('new_duration', $task_time->task_duration, 0, 'text');
  1516. } else {
  1517. print convertSecondToTime($task_time->task_duration, 'allhourmin');
  1518. }
  1519. print '</td>';
  1520. if (!$i) {
  1521. $totalarray['nbfield']++;
  1522. }
  1523. if (!$i) {
  1524. $totalarray['pos'][$totalarray['nbfield']] = 't.task_duration';
  1525. }
  1526. $totalarray['val']['t.task_duration'] += $task_time->task_duration;
  1527. if (!$i) {
  1528. $totalarray['totaldurationfield'] = $totalarray['nbfield'];
  1529. }
  1530. $totalarray['totalduration'] += $task_time->task_duration;
  1531. }
  1532. // Value spent
  1533. if (!empty($arrayfields['value']['checked'])) {
  1534. $langs->load("salaries");
  1535. print '<td class="nowraponall right">';
  1536. $value = price2num($task_time->thm * $task_time->task_duration / 3600, 'MT', 1);
  1537. print '<span class="amount" title="'.$langs->trans("THM").': '.price($task_time->thm).'">';
  1538. print price($value, 1, $langs, 1, -1, -1, $conf->currency);
  1539. print '</span>';
  1540. print '</td>';
  1541. if (!$i) {
  1542. $totalarray['nbfield']++;
  1543. }
  1544. if (!$i) {
  1545. $totalarray['pos'][$totalarray['nbfield']] = 'value';
  1546. }
  1547. $totalarray['val']['value'] += $value;
  1548. if (!$i) {
  1549. $totalarray['totalvaluefield'] = $totalarray['nbfield'];
  1550. }
  1551. $totalarray['totalvalue'] += $value;
  1552. }
  1553. // Invoiced
  1554. if (!empty($arrayfields['valuebilled']['checked'])) {
  1555. print '<td class="center">'; // invoice_id and invoice_line_id
  1556. if (empty($conf->global->PROJECT_HIDE_TASKS) && !empty($conf->global->PROJECT_BILL_TIME_SPENT)) {
  1557. if ($projectstatic->usage_bill_time) {
  1558. if ($task_time->invoice_id) {
  1559. $result = $tmpinvoice->fetch($task_time->invoice_id);
  1560. if ($result > 0) {
  1561. print $tmpinvoice->getNomUrl(1);
  1562. }
  1563. } else {
  1564. print $langs->trans("No");
  1565. }
  1566. } else {
  1567. print '<span class="opacitymedium">'.$langs->trans("NA").'</span>';
  1568. }
  1569. }
  1570. print '</td>';
  1571. if (!$i) {
  1572. $totalarray['nbfield']++;
  1573. }
  1574. }
  1575. /*
  1576. // Extra fields
  1577. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  1578. */
  1579. // Fields from hook
  1580. $parameters = array('arrayfields'=>$arrayfields, 'obj'=>$task_time, 'i'=>$i, 'totalarray'=>&$totalarray);
  1581. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook
  1582. print $hookmanager->resPrint;
  1583. // Action column
  1584. print '<td class="center nowraponall">';
  1585. if (($action == 'editline' || $action == 'splitline') && $_GET['lineid'] == $task_time->rowid) {
  1586. print '<input type="hidden" name="lineid" value="'.$_GET['lineid'].'">';
  1587. print '<input type="submit" class="button buttongen margintoponlyshort marginbottomonlyshort button-save" name="save" value="'.$langs->trans("Save").'">';
  1588. print '<br>';
  1589. print '<input type="submit" class="button buttongen margintoponlyshort marginbottomonlyshort button-cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
  1590. } elseif ($user->rights->projet->lire || $user->rights->projet->all->creer) { // Read project and enter time consumed on assigned tasks
  1591. if (in_array($task_time->fk_user, $childids) || $user->rights->projet->all->creer) {
  1592. if ($conf->MAIN_FEATURES_LEVEL >= 2) {
  1593. print '&nbsp;';
  1594. print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?id='.$task_time->fk_task.'&action=splitline&token='.newToken().'&lineid='.$task_time->rowid.$param.((empty($id) || $tab == 'timespent') ? '&tab=timespent' : '').'">';
  1595. print img_split();
  1596. print '</a>';
  1597. }
  1598. print '&nbsp;';
  1599. 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' : '').'">';
  1600. print img_edit();
  1601. print '</a>';
  1602. print '&nbsp;';
  1603. 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' : '').'">';
  1604. print img_delete('default', 'class="pictodelete paddingleft"');
  1605. print '</a>';
  1606. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  1607. $selected = 0;
  1608. if (in_array($task_time->rowid, $arrayofselected)) {
  1609. $selected = 1;
  1610. }
  1611. print '&nbsp;';
  1612. print '<input id="cb'.$task_time->rowid.'" class="flat checkforselect marginleftonly" type="checkbox" name="toselect[]" value="'.$task_time->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
  1613. }
  1614. }
  1615. }
  1616. print '</td>';
  1617. if (!$i) {
  1618. $totalarray['nbfield']++;
  1619. }
  1620. print "</tr>\n";
  1621. // Add line to split
  1622. if ($action == 'splitline' && $_GET['lineid'] == $task_time->rowid) {
  1623. print '<tr class="oddeven">';
  1624. // Date
  1625. if (!empty($arrayfields['t.task_date']['checked'])) {
  1626. print '<td class="nowrap">';
  1627. if ($action == 'splitline' && $_GET['lineid'] == $task_time->rowid) {
  1628. if (empty($task_time->task_date_withhour)) {
  1629. print $form->selectDate(($date2 ? $date2 : $date1), 'timeline', 3, 3, 2, "timespent_date", 1, 0);
  1630. } else {
  1631. print $form->selectDate(($date2 ? $date2 : $date1), 'timeline', 1, 1, 2, "timespent_date", 1, 0);
  1632. }
  1633. } else {
  1634. print dol_print_date(($date2 ? $date2 : $date1), ($task_time->task_date_withhour ? 'dayhour' : 'day'));
  1635. }
  1636. print '</td>';
  1637. }
  1638. // Project ref
  1639. if (!empty($allprojectforuser)) {
  1640. if ((empty($id) && empty($ref)) || !empty($projectidforalltimes)) { // Not a dedicated task
  1641. print '<td class="nowrap">';
  1642. print '</td>';
  1643. }
  1644. }
  1645. // Task ref
  1646. if (!empty($arrayfields['t.task_ref']['checked'])) {
  1647. if ((empty($id) && empty($ref)) || !empty($projectidforalltimes)) { // Not a dedicated task
  1648. print '<td class="nowrap">';
  1649. $tasktmp->id = $task_time->fk_task;
  1650. $tasktmp->ref = $task_time->ref;
  1651. $tasktmp->label = $task_time->label;
  1652. print $tasktmp->getNomUrl(1, 'withproject', 'time');
  1653. print '</td>';
  1654. }
  1655. }
  1656. // Task label
  1657. if (!empty($arrayfields['t.task_label']['checked'])) {
  1658. if ((empty($id) && empty($ref)) || !empty($projectidforalltimes)) { // Not a dedicated task
  1659. print '<td class="tdoverflowmax300" title="'.dol_escape_htmltag($task_time->label).'">';
  1660. print dol_escape_htmltag($task_time->label);
  1661. print '</td>';
  1662. }
  1663. }
  1664. // User
  1665. if (!empty($arrayfields['author']['checked'])) {
  1666. print '<td>';
  1667. if ($action == 'splitline' && $_GET['lineid'] == $task_time->rowid) {
  1668. if (empty($object->id)) {
  1669. $object->fetch($id);
  1670. }
  1671. $contactsoftask = $object->getListContactId('internal');
  1672. if (!in_array($task_time->fk_user, $contactsoftask)) {
  1673. $contactsoftask[] = $task_time->fk_user;
  1674. }
  1675. if (count($contactsoftask) > 0) {
  1676. print img_object('', 'user', 'class="hideonsmartphone"');
  1677. print $form->select_dolusers($task_time->fk_user, 'userid_line', 0, '', 0, '', $contactsoftask);
  1678. } else {
  1679. print img_error($langs->trans('FirstAddRessourceToAllocateTime')).$langs->trans('FirstAddRessourceToAllocateTime');
  1680. }
  1681. } else {
  1682. $userstatic->id = $task_time->fk_user;
  1683. $userstatic->lastname = $task_time->lastname;
  1684. $userstatic->firstname = $task_time->firstname;
  1685. $userstatic->photo = $task_time->photo;
  1686. $userstatic->statut = $task_time->user_status;
  1687. print $userstatic->getNomUrl(-1);
  1688. }
  1689. print '</td>';
  1690. }
  1691. // Note
  1692. if (!empty($arrayfields['t.note']['checked'])) {
  1693. print '<td class="tdoverflowmax300">';
  1694. if ($action == 'splitline' && $_GET['lineid'] == $task_time->rowid) {
  1695. print '<textarea name="timespent_note_line" width="95%" rows="'.ROWS_2.'">'.$task_time->note.'</textarea>';
  1696. } else {
  1697. print dol_nl2br($task_time->note);
  1698. }
  1699. print '</td>';
  1700. } elseif ($action == 'splitline' && $_GET['lineid'] == $task_time->rowid) {
  1701. print '<input type="hidden" name="timespent_note_line" value="'.$task_time->note.'">';
  1702. }
  1703. // Time spent
  1704. if (!empty($arrayfields['t.task_duration']['checked'])) {
  1705. print '<td class="right">';
  1706. if ($action == 'splitline' && $_GET['lineid'] == $task_time->rowid) {
  1707. print '<input type="hidden" name="old_duration" value="'.$task_time->task_duration.'">';
  1708. print $form->select_duration('new_duration', $task_time->task_duration, 0, 'text');
  1709. } else {
  1710. print convertSecondToTime($task_time->task_duration, 'allhourmin');
  1711. }
  1712. print '</td>';
  1713. }
  1714. // Value spent
  1715. if (!empty($arrayfields['value']['checked'])) {
  1716. print '<td class="right">';
  1717. $value = price2num($task_time->thm * $task_time->task_duration / 3600, 'MT', 1);
  1718. print price($value, 1, $langs, 1, -1, -1, $conf->currency);
  1719. print '</td>';
  1720. }
  1721. // Value billed
  1722. if (!empty($arrayfields['valuebilled']['checked'])) {
  1723. print '<td class="right">';
  1724. $valuebilled = price2num($task_time->total_ht, '', 1);
  1725. if (isset($task_time->total_ht)) {
  1726. print price($valuebilled, 1, $langs, 1, -1, -1, $conf->currency);
  1727. }
  1728. print '</td>';
  1729. }
  1730. /*
  1731. // Extra fields
  1732. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  1733. */
  1734. // Fields from hook
  1735. $parameters = array('arrayfields'=>$arrayfields, 'obj'=>$task_time);
  1736. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook
  1737. print $hookmanager->resPrint;
  1738. // Action column
  1739. print '<td class="center nowraponall">';
  1740. print '</td>';
  1741. print "</tr>\n";
  1742. // Line for second dispatching
  1743. print '<tr class="oddeven">';
  1744. // Date
  1745. if (!empty($arrayfields['t.task_date']['checked'])) {
  1746. print '<td class="nowrap">';
  1747. if ($action == 'splitline' && $_GET['lineid'] == $task_time->rowid) {
  1748. if (empty($task_time->task_date_withhour)) {
  1749. print $form->selectDate(($date2 ? $date2 : $date1), 'timeline_2', 3, 3, 2, "timespent_date", 1, 0);
  1750. } else {
  1751. print $form->selectDate(($date2 ? $date2 : $date1), 'timeline_2', 1, 1, 2, "timespent_date", 1, 0);
  1752. }
  1753. } else {
  1754. print dol_print_date(($date2 ? $date2 : $date1), ($task_time->task_date_withhour ? 'dayhour' : 'day'));
  1755. }
  1756. print '</td>';
  1757. }
  1758. // Project ref
  1759. if (!empty($allprojectforuser)) {
  1760. if ((empty($id) && empty($ref)) || !empty($projectidforalltimes)) { // Not a dedicated task
  1761. print '<td class="nowrap">';
  1762. print '</td>';
  1763. }
  1764. }
  1765. // Task ref
  1766. if (!empty($arrayfields['t.task_ref']['checked'])) {
  1767. if ((empty($id) && empty($ref)) || !empty($projectidforalltimes)) { // Not a dedicated task
  1768. print '<td class="nowrap">';
  1769. $tasktmp->id = $task_time->fk_task;
  1770. $tasktmp->ref = $task_time->ref;
  1771. $tasktmp->label = $task_time->label;
  1772. print $tasktmp->getNomUrl(1, 'withproject', 'time');
  1773. print '</td>';
  1774. }
  1775. }
  1776. // Task label
  1777. if (!empty($arrayfields['t.task_label']['checked'])) {
  1778. if ((empty($id) && empty($ref)) || !empty($projectidforalltimes)) { // Not a dedicated task
  1779. print '<td class="nowrap">';
  1780. print $task_time->label;
  1781. print '</td>';
  1782. }
  1783. }
  1784. // User
  1785. if (!empty($arrayfields['author']['checked'])) {
  1786. print '<td>';
  1787. if ($action == 'splitline' && $_GET['lineid'] == $task_time->rowid) {
  1788. if (empty($object->id)) {
  1789. $object->fetch($id);
  1790. }
  1791. $contactsoftask = $object->getListContactId('internal');
  1792. if (!in_array($task_time->fk_user, $contactsoftask)) {
  1793. $contactsoftask[] = $task_time->fk_user;
  1794. }
  1795. if (count($contactsoftask) > 0) {
  1796. print img_object('', 'user', 'class="hideonsmartphone"');
  1797. print $form->select_dolusers($task_time->fk_user, 'userid_line_2', 0, '', 0, '', $contactsoftask);
  1798. } else {
  1799. print img_error($langs->trans('FirstAddRessourceToAllocateTime')).$langs->trans('FirstAddRessourceToAllocateTime');
  1800. }
  1801. } else {
  1802. $userstatic->id = $task_time->fk_user;
  1803. $userstatic->lastname = $task_time->lastname;
  1804. $userstatic->firstname = $task_time->firstname;
  1805. $userstatic->photo = $task_time->photo;
  1806. $userstatic->statut = $task_time->user_status;
  1807. print $userstatic->getNomUrl(-1);
  1808. }
  1809. print '</td>';
  1810. }
  1811. // Note
  1812. if (!empty($arrayfields['t.note']['checked'])) {
  1813. print '<td class="small tdoverflowmax300"">';
  1814. if ($action == 'splitline' && $_GET['lineid'] == $task_time->rowid) {
  1815. print '<textarea name="timespent_note_line_2" width="95%" rows="'.ROWS_2.'">'.$task_time->note.'</textarea>';
  1816. } else {
  1817. print dol_nl2br($task_time->note);
  1818. }
  1819. print '</td>';
  1820. } elseif ($action == 'splitline' && $_GET['lineid'] == $task_time->rowid) {
  1821. print '<input type="hidden" name="timespent_note_line_2" value="'.$task_time->note.'">';
  1822. }
  1823. // Time spent
  1824. if (!empty($arrayfields['t.task_duration']['checked'])) {
  1825. print '<td class="right">';
  1826. if ($action == 'splitline' && $_GET['lineid'] == $task_time->rowid) {
  1827. print '<input type="hidden" name="old_duration_2" value="0">';
  1828. print $form->select_duration('new_duration_2', 0, 0, 'text');
  1829. } else {
  1830. print convertSecondToTime($task_time->task_duration, 'allhourmin');
  1831. }
  1832. print '</td>';
  1833. }
  1834. // Value spent
  1835. if (!empty($arrayfields['value']['checked'])) {
  1836. print '<td class="right">';
  1837. $value = 0;
  1838. print price($value, 1, $langs, 1, -1, -1, $conf->currency);
  1839. print '</td>';
  1840. }
  1841. // Value billed
  1842. if (!empty($arrayfields['valuebilled']['checked'])) {
  1843. print '<td class="right">';
  1844. $valuebilled = price2num($task_time->total_ht, '', 1);
  1845. if (isset($task_time->total_ht)) {
  1846. print price($valuebilled, 1, $langs, 1, -1, -1, $conf->currency);
  1847. }
  1848. print '</td>';
  1849. }
  1850. /*
  1851. // Extra fields
  1852. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  1853. */
  1854. // Fields from hook
  1855. $parameters = array('arrayfields'=>$arrayfields, 'obj'=>$task_time);
  1856. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook
  1857. print $hookmanager->resPrint;
  1858. // Action column
  1859. print '<td class="center nowraponall">';
  1860. print '</td>';
  1861. print "</tr>\n";
  1862. }
  1863. $i++;
  1864. }
  1865. // Show total line
  1866. //include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
  1867. if (isset($totalarray['totaldurationfield']) || isset($totalarray['totalvaluefield'])) {
  1868. print '<tr class="liste_total">';
  1869. $i = 0;
  1870. while ($i < $totalarray['nbfield']) {
  1871. $i++;
  1872. if ($i == 1) {
  1873. if ($num < $limit && empty($offset)) {
  1874. print '<td class="left">'.$langs->trans("Total").'</td>';
  1875. } else {
  1876. print '<td class="left">'.$langs->trans("Totalforthispage").'</td>';
  1877. }
  1878. } elseif ($totalarray['totaldurationfield'] == $i) {
  1879. print '<td class="right">'.convertSecondToTime($totalarray['totalduration'], 'allhourmin').'</td>';
  1880. } elseif ($totalarray['totalvaluefield'] == $i) {
  1881. print '<td class="right">'.price($totalarray['totalvalue']).'</td>';
  1882. //} elseif ($totalarray['totalvaluebilledfield'] == $i) { print '<td class="center">'.price($totalarray['totalvaluebilled']).'</td>';
  1883. } else {
  1884. print '<td></td>';
  1885. }
  1886. }
  1887. print '</tr>';
  1888. }
  1889. if (!count($tasks)) {
  1890. $totalnboffields = 1;
  1891. foreach ($arrayfields as $value) {
  1892. if ($value['checked']) {
  1893. $totalnboffields++;
  1894. }
  1895. }
  1896. print '<tr class="oddeven"><td colspan="'.$totalnboffields.'">';
  1897. print '<span class="opacitymedium">'.$langs->trans("None").'</span>';
  1898. print '</td></tr>';
  1899. }
  1900. print "</table>";
  1901. print '</div>';
  1902. print "</form>";
  1903. }
  1904. }
  1905. // End of page
  1906. llxFooter();
  1907. $db->close();