time.php 85 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228
  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 = array();
  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, timespent
  575. $object->fetchTimeSpent($value);
  576. // $object->id is the task id
  577. $arrayoftasks[$object->timespent_id]['id'] = $object->id;
  578. $arrayoftasks[$object->timespent_id]['timespent'] = $object->timespent_duration;
  579. $arrayoftasks[$object->timespent_id]['totalvaluetodivideby3600'] = $object->timespent_duration * $object->timespent_thm;
  580. $arrayoftasks[$object->timespent_id]['note'] = $object->timespent_note;
  581. $arrayoftasks[$object->timespent_id]['date'] = date('Y-m-d H:i:s', $object->timespent_datehour);
  582. }
  583. foreach ($arrayoftasks as $timespent_id => $value) {
  584. $ftask = new Task($db);
  585. $ftask->fetch($value['id']);
  586. // Define qty per hour
  587. $qtyhour = $value['timespent'] / 3600;
  588. $qtyhourtext = convertSecondToTime($value['timespent'], 'all', $conf->global->MAIN_DURATION_OF_WORKDAY);
  589. // Add lines
  590. $lineid = $tmpinter->addline($user, $tmpinter->id, $ftask->label . ( ! empty($value['note']) ? ' - ' . $value['note'] : '' ), $value['date'], $value['timespent']);
  591. }
  592. }
  593. if (!$error) {
  594. $urltointer = $tmpinter->getNomUrl(0);
  595. $mesg = $langs->trans("InterventionGeneratedFromTimeSpent", '{s1}');
  596. $mesg = str_replace('{s1}', $urltointer, $mesg);
  597. setEventMessages($mesg, null, 'mesgs');
  598. //var_dump($tmpinvoice);
  599. $db->commit();
  600. } else {
  601. $db->rollback();
  602. }
  603. }
  604. }
  605. /*
  606. * View
  607. */
  608. $arrayofselected = is_array($toselect) ? $toselect : array();
  609. llxHeader("", $langs->trans("Task"));
  610. $form = new Form($db);
  611. $formother = new FormOther($db);
  612. $formproject = new FormProjets($db);
  613. $userstatic = new User($db);
  614. if (($id > 0 || !empty($ref)) || $projectidforalltimes > 0 || $allprojectforuser > 0) {
  615. /*
  616. * Fiche projet en mode visu
  617. */
  618. if ($projectidforalltimes > 0) {
  619. $result = $projectstatic->fetch($projectidforalltimes);
  620. if (!empty($projectstatic->socid)) {
  621. $projectstatic->fetch_thirdparty();
  622. }
  623. $res = $projectstatic->fetch_optionals();
  624. } elseif ($object->fetch($id, $ref) >= 0) {
  625. if (!empty($conf->global->PROJECT_ALLOW_COMMENT_ON_TASK) && method_exists($object, 'fetchComments') && empty($object->comments)) {
  626. $object->fetchComments();
  627. }
  628. $result = $projectstatic->fetch($object->fk_project);
  629. if (!empty($conf->global->PROJECT_ALLOW_COMMENT_ON_PROJECT) && method_exists($projectstatic, 'fetchComments') && empty($projectstatic->comments)) {
  630. $projectstatic->fetchComments();
  631. }
  632. if (!empty($projectstatic->socid)) {
  633. $projectstatic->fetch_thirdparty();
  634. }
  635. $res = $projectstatic->fetch_optionals();
  636. $object->project = clone $projectstatic;
  637. }
  638. $userRead = $projectstatic->restrictedProjectArea($user, 'read');
  639. $linktocreatetime = '';
  640. if ($projectstatic->id > 0) {
  641. if ($withproject) {
  642. // Tabs for project
  643. if (empty($id) || $tab == 'timespent') {
  644. $tab = 'timespent';
  645. } else {
  646. $tab = 'tasks';
  647. }
  648. $head = project_prepare_head($projectstatic);
  649. print dol_get_fiche_head($head, $tab, $langs->trans("Project"), -1, ($projectstatic->public ? 'projectpub' : 'project'));
  650. $param = ((!empty($mode) && $mode == 'mine') ? '&mode=mine' : '');
  651. if ($search_user) {
  652. $param .= '&search_user='.((int) $search_user);
  653. }
  654. if ($search_month) {
  655. $param .= '&search_month='.((int) $search_month);
  656. }
  657. if ($search_year) {
  658. $param .= '&search_year='.((int) $search_year);
  659. }
  660. // Project card
  661. $linkback = '<a href="'.DOL_URL_ROOT.'/projet/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  662. $morehtmlref = '<div class="refidno">';
  663. // Title
  664. $morehtmlref .= $projectstatic->title;
  665. // Thirdparty
  666. if (!empty($projectstatic->thirdparty->id) && $projectstatic->thirdparty->id > 0) {
  667. $morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$projectstatic->thirdparty->getNomUrl(1, 'project');
  668. }
  669. $morehtmlref .= '</div>';
  670. // Define a complementary filter for search of next/prev ref.
  671. if (empty($user->rights->projet->all->lire)) {
  672. $objectsListId = $projectstatic->getProjectsAuthorizedForUser($user, 0, 0);
  673. $projectstatic->next_prev_filter = " rowid IN (".$db->sanitize(count($objectsListId) ?join(',', array_keys($objectsListId)) : '0').")";
  674. }
  675. dol_banner_tab($projectstatic, 'project_ref', $linkback, 1, 'ref', 'ref', $morehtmlref, $param);
  676. print '<div class="fichecenter">';
  677. print '<div class="fichehalfleft">';
  678. print '<div class="underbanner clearboth"></div>';
  679. print '<table class="border tableforfield centpercent">';
  680. // Usage
  681. if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES) || empty($conf->global->PROJECT_HIDE_TASKS) || !empty($conf->eventorganization->enabled)) {
  682. print '<tr><td class="tdtop">';
  683. print $langs->trans("Usage");
  684. print '</td>';
  685. print '<td>';
  686. if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES)) {
  687. print '<input type="checkbox" disabled name="usage_opportunity"'.(GETPOSTISSET('usage_opportunity') ? (GETPOST('usage_opportunity', 'alpha') != '' ? ' checked="checked"' : '') : ($projectstatic->usage_opportunity ? ' checked="checked"' : '')).'"> ';
  688. $htmltext = $langs->trans("ProjectFollowOpportunity");
  689. print $form->textwithpicto($langs->trans("ProjectFollowOpportunity"), $htmltext);
  690. print '<br>';
  691. }
  692. if (empty($conf->global->PROJECT_HIDE_TASKS)) {
  693. print '<input type="checkbox" disabled name="usage_task"'.(GETPOSTISSET('usage_task') ? (GETPOST('usage_task', 'alpha') != '' ? ' checked="checked"' : '') : ($projectstatic->usage_task ? ' checked="checked"' : '')).'"> ';
  694. $htmltext = $langs->trans("ProjectFollowTasks");
  695. print $form->textwithpicto($langs->trans("ProjectFollowTasks"), $htmltext);
  696. print '<br>';
  697. }
  698. if (empty($conf->global->PROJECT_HIDE_TASKS) && !empty($conf->global->PROJECT_BILL_TIME_SPENT)) {
  699. 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"' : '')).'"> ';
  700. $htmltext = $langs->trans("ProjectBillTimeDescription");
  701. print $form->textwithpicto($langs->trans("BillTime"), $htmltext);
  702. print '<br>';
  703. }
  704. if (!empty($conf->eventorganization->enabled)) {
  705. 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"' : '')).'"> ';
  706. $htmltext = $langs->trans("EventOrganizationDescriptionLong");
  707. print $form->textwithpicto($langs->trans("ManageOrganizeEvent"), $htmltext);
  708. }
  709. print '</td></tr>';
  710. }
  711. // Visibility
  712. print '<tr><td class="titlefield">'.$langs->trans("Visibility").'</td><td>';
  713. if ($projectstatic->public) {
  714. print $langs->trans('SharedProject');
  715. } else {
  716. print $langs->trans('PrivateProject');
  717. }
  718. print '</td></tr>';
  719. // Date start - end
  720. print '<tr><td>'.$langs->trans("DateStart").' - '.$langs->trans("DateEnd").'</td><td>';
  721. $start = dol_print_date($projectstatic->date_start, 'day');
  722. print ($start ? $start : '?');
  723. $end = dol_print_date($projectstatic->date_end, 'day');
  724. print ' - ';
  725. print ($end ? $end : '?');
  726. if ($projectstatic->hasDelay()) {
  727. print img_warning("Late");
  728. }
  729. print '</td></tr>';
  730. // Budget
  731. print '<tr><td>'.$langs->trans("Budget").'</td><td>';
  732. if (strcmp($projectstatic->budget_amount, '')) {
  733. print '<span class="amount">'.price($projectstatic->budget_amount, '', $langs, 1, 0, 0, $conf->currency).'</span>';
  734. }
  735. print '</td></tr>';
  736. // Other attributes
  737. $cols = 2;
  738. //include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
  739. print '</table>';
  740. print '</div>';
  741. print '<div class="fichehalfright">';
  742. print '<div class="underbanner clearboth"></div>';
  743. print '<table class="border tableforfield centpercent">';
  744. // Description
  745. print '<td class="titlefield tdtop">'.$langs->trans("Description").'</td><td>';
  746. print nl2br($projectstatic->description);
  747. print '</td></tr>';
  748. // Categories
  749. if ($conf->categorie->enabled) {
  750. print '<tr><td class="valignmiddle">'.$langs->trans("Categories").'</td><td>';
  751. print $form->showCategories($projectstatic->id, 'project', 1);
  752. print "</td></tr>";
  753. }
  754. print '</table>';
  755. print '</div>';
  756. print '</div>';
  757. print '<div class="clearboth"></div>';
  758. print dol_get_fiche_end();
  759. print '<br>';
  760. }
  761. // Link to create time
  762. $linktocreatetimeBtnStatus = 0;
  763. $linktocreatetimeUrl = '';
  764. $linktocreatetimeHelpText = '';
  765. if ($user->rights->projet->all->lire || $user->rights->projet->lire) { // To enter time, read permission is enough
  766. if ($projectstatic->public || $userRead > 0) {
  767. $linktocreatetimeBtnStatus = 1;
  768. if (!empty($projectidforalltimes)) { // We are on tab 'Time Spent' of project
  769. $backtourl = $_SERVER['PHP_SELF'].'?projectid='.$projectstatic->id.($withproject ? '&withproject=1' : '');
  770. $linktocreatetimeUrl = $_SERVER['PHP_SELF'].'?'.($withproject ? 'withproject=1' : '').'&projectid='.$projectstatic->id.'&action=createtime'.$param.'&backtopage='.urlencode($backtourl);
  771. } else // We are on tab 'Time Spent' of task
  772. {
  773. $backtourl = $_SERVER['PHP_SELF'].'?id='.$object->id.($withproject ? '&withproject=1' : '');
  774. $linktocreatetimeUrl = $_SERVER['PHP_SELF'].'?'.($withproject ? 'withproject=1' : '').($object->id > 0 ? '&id='.$object->id : '&projectid='.$projectstatic->id).'&action=createtime'.$param.'&backtopage='.urlencode($backtourl);
  775. }
  776. } else {
  777. $linktocreatetimeBtnStatus = -2;
  778. $linktocreatetimeHelpText = $langs->trans("NotOwnerOfProject");
  779. }
  780. }
  781. $paramsbutton = array('morecss'=>'reposition');
  782. $linktocreatetime = dolGetButtonTitle($langs->trans('AddTimeSpent'), $linktocreatetimeHelpText, 'fa fa-plus-circle', $linktocreatetimeUrl, '', $linktocreatetimeBtnStatus, $paramsbutton);
  783. }
  784. $massactionbutton = '';
  785. $arrayofmassactions = array();
  786. if ($projectstatic->usage_bill_time) {
  787. $arrayofmassactions = array(
  788. 'generateinvoice'=>$langs->trans("GenerateBill"),
  789. //'builddoc'=>$langs->trans("PDFMerge"),
  790. );
  791. }
  792. if ( ! empty($conf->ficheinter->enabled) && $user->rights->ficheinter->creer) {
  793. $langs->load("interventions");
  794. $arrayofmassactions['generateinter'] = $langs->trans("GenerateInter");
  795. }
  796. //if ($user->rights->projet->creer) $arrayofmassactions['predelete']='<span class="fa fa-trash paddingrightonly"></span>'.$langs->trans("Delete");
  797. if (in_array($massaction, array('presend', 'predelete', 'generateinvoice', 'generateinter'))) {
  798. $arrayofmassactions = array();
  799. }
  800. $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
  801. // Show section with information of task. If id of task is not defined and project id defined, then $projectidforalltimes is not empty.
  802. if (empty($projectidforalltimes) && empty($allprojectforuser)) {
  803. $head = task_prepare_head($object);
  804. print dol_get_fiche_head($head, 'task_time', $langs->trans("Task"), -1, 'projecttask', 0, '', 'reposition');
  805. if ($action == 'deleteline') {
  806. 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);
  807. }
  808. $param = ($withproject ? '&withproject=1' : '');
  809. $linkback = $withproject ? '<a href="'.DOL_URL_ROOT.'/projet/tasks.php?id='.$projectstatic->id.'">'.$langs->trans("BackToList").'</a>' : '';
  810. if (!GETPOST('withproject') || empty($projectstatic->id)) {
  811. $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1);
  812. $object->next_prev_filter = " fk_projet IN (".$db->sanitize($projectsListId).")";
  813. } else {
  814. $object->next_prev_filter = " fk_projet = ".$projectstatic->id;
  815. }
  816. $morehtmlref = '';
  817. // Project
  818. if (empty($withproject)) {
  819. $morehtmlref .= '<div class="refidno">';
  820. $morehtmlref .= $langs->trans("Project").': ';
  821. $morehtmlref .= $projectstatic->getNomUrl(1);
  822. $morehtmlref .= '<br>';
  823. // Third party
  824. $morehtmlref .= $langs->trans("ThirdParty").': ';
  825. if (is_object($projectstatic->thirdparty)) {
  826. $morehtmlref .= $projectstatic->thirdparty->getNomUrl(1);
  827. }
  828. $morehtmlref .= '</div>';
  829. }
  830. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, $param);
  831. print '<div class="fichecenter">';
  832. print '<div class="fichehalfleft">';
  833. print '<div class="underbanner clearboth"></div>';
  834. print '<table class="border tableforfield centpercent">';
  835. // Date start - Date end
  836. print '<tr><td class="titlefield">'.$langs->trans("DateStart").' - '.$langs->trans("DateEnd").'</td><td>';
  837. $start = dol_print_date($object->date_start, 'dayhour');
  838. print ($start ? $start : '?');
  839. $end = dol_print_date($object->date_end, 'dayhour');
  840. print ' - ';
  841. print ($end ? $end : '?');
  842. if ($object->hasDelay()) {
  843. print img_warning("Late");
  844. }
  845. print '</td></tr>';
  846. // Planned workload
  847. print '<tr><td>'.$langs->trans("PlannedWorkload").'</td><td>';
  848. if ($object->planned_workload) {
  849. print convertSecondToTime($object->planned_workload, 'allhourmin');
  850. }
  851. print '</td></tr>';
  852. print '</table>';
  853. print '</div>';
  854. print '<div class="fichehalfright">';
  855. print '<div class="underbanner clearboth"></div>';
  856. print '<table class="border tableforfield centpercent">';
  857. // Progress declared
  858. print '<tr><td class="titlefield">'.$langs->trans("ProgressDeclared").'</td><td>';
  859. print $object->progress != '' ? $object->progress.' %' : '';
  860. print '</td></tr>';
  861. // Progress calculated
  862. print '<tr><td>'.$langs->trans("ProgressCalculated").'</td><td>';
  863. if ($object->planned_workload) {
  864. $tmparray = $object->getSummaryOfTimeSpent();
  865. if ($tmparray['total_duration'] > 0) {
  866. print round($tmparray['total_duration'] / $object->planned_workload * 100, 2).' %';
  867. } else {
  868. print '0 %';
  869. }
  870. } else {
  871. print '<span class="opacitymedium">'.$langs->trans("WorkloadNotDefined").'</span>';
  872. }
  873. print '</td>';
  874. print '</tr>';
  875. print '</table>';
  876. print '</div>';
  877. print '</div>';
  878. print '<div class="clearboth"></div>';
  879. print dol_get_fiche_end();
  880. }
  881. if ($projectstatic->id > 0 || $allprojectforuser > 0) {
  882. // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array
  883. $hookmanager->initHooks(array('tasktimelist'));
  884. $formconfirm = '';
  885. if ($action == 'deleteline' && !empty($projectidforalltimes)) {
  886. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"]."?".($object->id > 0 ? "id=".$object->id : 'projectid='.$projectstatic->id).'&lineid='.GETPOST('lineid', 'int').($withproject ? '&withproject=1' : ''), $langs->trans("DeleteATimeSpent"), $langs->trans("ConfirmDeleteATimeSpent"), "confirm_deleteline", '', '', 1);
  887. }
  888. // Call Hook formConfirm
  889. $parameters = array('formConfirm' => $formconfirm, 'lineid' => $lineid, "projectstatic" => $projectstatic, "withproject" => $withproject);
  890. $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  891. if (empty($reshook)) {
  892. $formconfirm .= $hookmanager->resPrint;
  893. } elseif ($reshook > 0) {
  894. $formconfirm = $hookmanager->resPrint;
  895. }
  896. // Print form confirm
  897. print $formconfirm;
  898. // Definition of fields for list
  899. $arrayfields = array();
  900. $arrayfields['t.task_date'] = array('label'=>$langs->trans("Date"), 'checked'=>1);
  901. if ((empty($id) && empty($ref)) || !empty($projectidforalltimes)) { // Not a dedicated task
  902. $arrayfields['t.task_ref'] = array('label'=>$langs->trans("RefTask"), 'checked'=>1);
  903. $arrayfields['t.task_label'] = array('label'=>$langs->trans("LabelTask"), 'checked'=>1);
  904. }
  905. $arrayfields['author'] = array('label'=>$langs->trans("By"), 'checked'=>1);
  906. $arrayfields['t.note'] = array('label'=>$langs->trans("Note"), 'checked'=>1);
  907. $arrayfields['t.task_duration'] = array('label'=>$langs->trans("Duration"), 'checked'=>1);
  908. $arrayfields['value'] = array('label'=>$langs->trans("Value"), 'checked'=>1, 'enabled'=>(empty($conf->salaries->enabled) ? 0 : 1));
  909. $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));
  910. // Extra fields
  911. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
  912. $arrayfields = dol_sort_array($arrayfields, 'position');
  913. $param = '';
  914. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  915. $param .= '&contextpage='.urlencode($contextpage);
  916. }
  917. if ($limit > 0 && $limit != $conf->liste_limit) {
  918. $param .= '&limit='.urlencode($limit);
  919. }
  920. if ($search_month > 0) {
  921. $param .= '&search_month='.urlencode($search_month);
  922. }
  923. if ($search_year > 0) {
  924. $param .= '&search_year='.urlencode($search_year);
  925. }
  926. if ($search_user > 0) {
  927. $param .= '&search_user='.urlencode($search_user);
  928. }
  929. if ($search_task_ref != '') {
  930. $param .= '&search_task_ref='.urlencode($search_task_ref);
  931. }
  932. if ($search_task_label != '') {
  933. $param .= '&search_task_label='.urlencode($search_task_label);
  934. }
  935. if ($search_note != '') {
  936. $param .= '&search_note='.urlencode($search_note);
  937. }
  938. if ($search_duration != '') {
  939. $param .= '&amp;search_field2='.urlencode($search_duration);
  940. }
  941. if ($optioncss != '') {
  942. $param .= '&optioncss='.urlencode($optioncss);
  943. }
  944. /*
  945. // Add $param from extra fields
  946. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
  947. */
  948. if ($id) {
  949. $param .= '&id='.urlencode($id);
  950. }
  951. if ($projectid) {
  952. $param .= '&projectid='.urlencode($projectid);
  953. }
  954. if ($withproject) {
  955. $param .= '&withproject='.urlencode($withproject);
  956. }
  957. // Add $param from hooks
  958. $parameters = array();
  959. $reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object); // Note that $action and $object may have been modified by hook
  960. $param .= $hookmanager->resPrint;
  961. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  962. if ($optioncss != '') {
  963. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  964. }
  965. print '<input type="hidden" name="token" value="'.newToken().'">';
  966. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  967. if ($action == 'editline') {
  968. print '<input type="hidden" name="action" value="updateline">';
  969. } elseif ($action == 'splitline') {
  970. print '<input type="hidden" name="action" value="updatesplitline">';
  971. } elseif ($action == 'createtime' && $user->rights->projet->lire) {
  972. print '<input type="hidden" name="action" value="addtimespent">';
  973. } elseif ($massaction == 'generateinvoice' && $user->rights->facture->lire) {
  974. print '<input type="hidden" name="action" value="confirm_generateinvoice">';
  975. } elseif ($massaction == 'generateinter' && $user->rights->ficheinter->lire) {
  976. print '<input type="hidden" name="action" value="confirm_generateinter">';
  977. } else {
  978. print '<input type="hidden" name="action" value="list">';
  979. }
  980. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  981. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  982. print '<input type="hidden" name="id" value="'.$id.'">';
  983. print '<input type="hidden" name="projectid" value="'.$projectidforalltimes.'">';
  984. print '<input type="hidden" name="withproject" value="'.$withproject.'">';
  985. print '<input type="hidden" name="tab" value="'.$tab.'">';
  986. print '<input type="hidden" name="page_y" value="">';
  987. // Form to convert time spent into invoice
  988. if ($massaction == 'generateinvoice') {
  989. if ($projectstatic->thirdparty->id > 0) {
  990. print '<table class="noborder centerpercent">';
  991. print '<tr>';
  992. print '<td class="titlefield">';
  993. print $langs->trans('DateInvoice');
  994. print '</td>';
  995. print '<td>';
  996. print $form->selectDate('', '', '', '', '', '', 1, 1);
  997. print '</td>';
  998. print '</tr>';
  999. print '<tr>';
  1000. print '<td>';
  1001. print $langs->trans('Mode');
  1002. print '</td>';
  1003. print '<td>';
  1004. $tmparray = array(
  1005. 'onelineperuser'=>'OneLinePerUser',
  1006. 'onelinepertask'=>'OneLinePerTask',
  1007. 'onelineperperiod'=>'OneLinePerTimeSpentLine',
  1008. );
  1009. print $form->selectarray('generateinvoicemode', $tmparray, 'onelineperuser', 0, 0, 0, '', 1);
  1010. print "\n".'<script type="text/javascript">';
  1011. print '
  1012. $(document).ready(function () {
  1013. setDetailVisibility();
  1014. $("#generateinvoicemode").change(function() {
  1015. setDetailVisibility();
  1016. });
  1017. function setDetailVisibility() {
  1018. generateinvoicemode = $("#generateinvoicemode option:selected").val();
  1019. if (generateinvoicemode=="onelineperperiod") {
  1020. $("#detail_time_duration").show();
  1021. } else {
  1022. $("#detail_time_duration").hide();
  1023. }
  1024. }
  1025. });
  1026. ';
  1027. print '</script>'."\n";
  1028. print '<span style="display:none" id="detail_time_duration"><input type="checkbox" value="detail" name="detail_time_duration"/>'.$langs->trans('AddDetailDateAndDuration').'</span>';
  1029. print '</td>';
  1030. print '</tr>';
  1031. if ($conf->service->enabled) {
  1032. print '<tr>';
  1033. print '<td>';
  1034. print $langs->trans('ServiceToUseOnLines');
  1035. print '</td>';
  1036. print '<td>';
  1037. $form->select_produits('', 'productid', '1', 0, $projectstatic->thirdparty->price_level, 1, 2, '', 0, array(), $projectstatic->thirdparty->id, 'None', 0, 'maxwidth500');
  1038. print '</td>';
  1039. print '</tr>';
  1040. }
  1041. print '<tr>';
  1042. print '<td class="titlefield">';
  1043. print $langs->trans('InvoiceToUse');
  1044. print '</td>';
  1045. print '<td>';
  1046. $form->selectInvoice('invoice', '', 'invoiceid', 24, 0, $langs->trans('NewInvoice'), 1, 0, 0, 'maxwidth500', '', 'all');
  1047. print '</td>';
  1048. print '</tr>';
  1049. /*print '<tr>';
  1050. print '<td>';
  1051. print $langs->trans('ValidateInvoices');
  1052. print '</td>';
  1053. print '<td>';
  1054. print $form->selectyesno('validate_invoices', 0, 1);
  1055. print '</td>';
  1056. print '</tr>';*/
  1057. print '</table>';
  1058. print '<br>';
  1059. print '<div class="center">';
  1060. print '<input type="submit" class="button" id="createbills" name="createbills" value="'.$langs->trans('GenerateBill').'"> ';
  1061. print '<input type="submit" class="button button-cancel" id="cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
  1062. print '</div>';
  1063. print '<br>';
  1064. } else {
  1065. print '<div class="warning">'.$langs->trans("ThirdPartyRequiredToGenerateInvoice").'</div>';
  1066. print '<div class="center">';
  1067. print '<input type="submit" class="button button-cancel" id="cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
  1068. print '</div>';
  1069. $massaction = '';
  1070. }
  1071. } elseif ($massaction == 'generateinter') {
  1072. // Form to convert time spent into invoice
  1073. print '<input type="hidden" name="massaction" value="confirm_createinter">';
  1074. if ($projectstatic->thirdparty->id > 0) {
  1075. print '<table class="noborder" width="100%" >';
  1076. print '<tr>';
  1077. print '<td class="titlefield">';
  1078. print $langs->trans('InterToUse');
  1079. print '</td>';
  1080. print '<td>';
  1081. $forminter = new FormIntervention($db);
  1082. print $forminter->select_interventions($projectstatic->thirdparty->id, '', 'interid', 24, $langs->trans('NewInter'), true);
  1083. print '</td>';
  1084. print '</tr>';
  1085. print '</table>';
  1086. print '<br>';
  1087. print '<div class="center">';
  1088. print '<input type="submit" class="button" id="createinter" name="createinter" value="'.$langs->trans('GenerateInter').'"> ';
  1089. print '<input type="submit" class="button" id="cancel" name="cancel" value="'.$langs->trans('Cancel').'">';
  1090. print '</div>';
  1091. print '<br>';
  1092. } else {
  1093. print '<div class="warning">'.$langs->trans("ThirdPartyRequiredToGenerateIntervention").'</div>';
  1094. print '<div class="center">';
  1095. print '<input type="submit" class="button" id="cancel" name="cancel" value="'.$langs->trans('Cancel').'">';
  1096. print '</div>';
  1097. $massaction = '';
  1098. }
  1099. }
  1100. // Allow Pre-Mass-Action hook (eg for confirmation dialog)
  1101. $parameters = array(
  1102. 'toselect' => $toselect,
  1103. 'uploaddir' => isset($uploaddir) ? $uploaddir : null
  1104. );
  1105. $reshook = $hookmanager->executeHooks('doPreMassActions', $parameters, $object, $action);
  1106. if ($reshook < 0) {
  1107. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  1108. } else {
  1109. print $hookmanager->resPrint;
  1110. }
  1111. /*
  1112. * List of time spent
  1113. */
  1114. $tasks = array();
  1115. $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,";
  1116. $sql .= " pt.ref, pt.label, pt.fk_projet,";
  1117. $sql .= " u.lastname, u.firstname, u.login, u.photo, u.statut as user_status,";
  1118. $sql .= " il.fk_facture as invoice_id, inv.fk_statut,";
  1119. // Add fields from hooks
  1120. $parameters = array();
  1121. $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook
  1122. $sql .= preg_replace('/^,/', '', $hookmanager->resPrint);
  1123. $sql = preg_replace('/,\s*$/', '', $sql);
  1124. $sql .= " FROM ".MAIN_DB_PREFIX."projet_task_time as t";
  1125. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facturedet as il ON il.rowid = t.invoice_line_id";
  1126. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facture as inv ON inv.rowid = il.fk_facture";
  1127. // Add table from hooks
  1128. $parameters = array();
  1129. $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object); // Note that $action and $object may have been modified by hook
  1130. $sql .= $hookmanager->resPrint;
  1131. $sql .= ", ".MAIN_DB_PREFIX."projet_task as pt, ".MAIN_DB_PREFIX."user as u";
  1132. $sql .= " WHERE t.fk_user = u.rowid AND t.fk_task = pt.rowid";
  1133. if (empty($projectidforalltimes) && empty($allprojectforuser)) {
  1134. // Limit on one task
  1135. $sql .= " AND t.fk_task =".((int) $object->id);
  1136. } elseif (!empty($projectidforalltimes)) {
  1137. // Limit on one project
  1138. $sql .= " AND pt.fk_projet IN (".$db->sanitize($projectidforalltimes).")";
  1139. } elseif (!empty($allprojectforuser)) {
  1140. // Limit on on user
  1141. if (empty($search_user)) {
  1142. $search_user = $user->id;
  1143. }
  1144. $sql .= " AND t.fk_user = ".((int) $search_user);
  1145. }
  1146. if ($search_note) {
  1147. $sql .= natural_search('t.note', $search_note);
  1148. }
  1149. if ($search_task_ref) {
  1150. $sql .= natural_search('pt.ref', $search_task_ref);
  1151. }
  1152. if ($search_task_label) {
  1153. $sql .= natural_search('pt.label', $search_task_label);
  1154. }
  1155. if ($search_user > 0) {
  1156. $sql .= natural_search('t.fk_user', $search_user, 2);
  1157. }
  1158. if ($search_valuebilled == '1') {
  1159. $sql .= ' AND t.invoice_id > 0';
  1160. }
  1161. if ($search_valuebilled == '0') {
  1162. $sql .= ' AND (t.invoice_id = 0 OR t.invoice_id IS NULL)';
  1163. }
  1164. $sql .= dolSqlDateFilter('t.task_datehour', $search_day, $search_month, $search_year);
  1165. // Add where from hooks
  1166. $parameters = array();
  1167. $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook
  1168. $sql .= $hookmanager->resPrint;
  1169. $sql .= $db->order($sortfield, $sortorder);
  1170. // Count total nb of records
  1171. $nbtotalofrecords = '';
  1172. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
  1173. $resql = $db->query($sql);
  1174. if (! $resql) {
  1175. dol_print_error($db);
  1176. exit;
  1177. }
  1178. $nbtotalofrecords = $db->num_rows($resql);
  1179. if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0
  1180. $page = 0;
  1181. $offset = 0;
  1182. }
  1183. }
  1184. // if total of record found is smaller than limit, no need to do paging and to restart another select with limits set.
  1185. if (is_numeric($nbtotalofrecords) && $limit > $nbtotalofrecords) {
  1186. $num = $nbtotalofrecords;
  1187. } else {
  1188. $sql .= $db->plimit($limit + 1, $offset);
  1189. $resql = $db->query($sql);
  1190. if (!$resql) {
  1191. dol_print_error($db);
  1192. exit;
  1193. }
  1194. $num = $db->num_rows($resql);
  1195. }
  1196. if ($num >= 0) {
  1197. if (!empty($projectidforalltimes)) {
  1198. print '<!-- List of time spent for project -->'."\n";
  1199. $title = $langs->trans("ListTaskTimeUserProject");
  1200. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'clock', 0, $linktocreatetime, '', $limit, 0, 0, 1);
  1201. } else {
  1202. print '<!-- List of time spent -->'."\n";
  1203. $title = $langs->trans("ListTaskTimeForTask");
  1204. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'clock', 0, $linktocreatetime, '', $limit, 0, 0, 1);
  1205. }
  1206. $i = 0;
  1207. while ($i < $num) {
  1208. $row = $db->fetch_object($resql);
  1209. $tasks[$i] = $row;
  1210. $i++;
  1211. }
  1212. $db->free($resql);
  1213. } else {
  1214. dol_print_error($db);
  1215. }
  1216. /*
  1217. * Form to add a new line of time spent
  1218. */
  1219. if ($action == 'createtime' && $user->rights->projet->lire) {
  1220. print '<!-- table to add time spent -->'."\n";
  1221. if (!empty($id)) {
  1222. print '<input type="hidden" name="taskid" value="'.$id.'">';
  1223. }
  1224. 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
  1225. print '<table class="noborder nohover centpercent">';
  1226. print '<tr class="liste_titre">';
  1227. print '<td>'.$langs->trans("Date").'</td>';
  1228. if (!empty($allprojectforuser)) {
  1229. print '<td>'.$langs->trans("Project").'</td>';
  1230. }
  1231. if (empty($id)) {
  1232. print '<td>'.$langs->trans("Task").'</td>';
  1233. }
  1234. print '<td>'.$langs->trans("By").'</td>';
  1235. print '<td>'.$langs->trans("Note").'</td>';
  1236. print '<td>'.$langs->trans("NewTimeSpent").'</td>';
  1237. print '<td>'.$langs->trans("ProgressDeclared").'</td>';
  1238. if (empty($conf->global->PROJECT_HIDE_TASKS) && !empty($conf->global->PROJECT_BILL_TIME_SPENT)) {
  1239. print '<td></td>';
  1240. }
  1241. // Hook fields
  1242. $parameters = array('mode' => 'create');
  1243. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook
  1244. print $hookmanager->resPrint;
  1245. print '<td></td>';
  1246. print "</tr>\n";
  1247. print '<tr class="oddeven nohover">';
  1248. // Date
  1249. print '<td class="maxwidthonsmartphone">';
  1250. $newdate = '';
  1251. print $form->selectDate($newdate, 'time', ($conf->browser->layout == 'phone' ? 2 : 1), 1, 2, "timespent_date", 1, 0);
  1252. print '</td>';
  1253. if (!empty($allprojectforuser)) {
  1254. print '<td>';
  1255. // Add project selector
  1256. print '</td>';
  1257. }
  1258. // Task
  1259. $nboftasks = 0;
  1260. if (empty($id)) {
  1261. print '<td class="maxwidthonsmartphone">';
  1262. $nboftasks = $formproject->selectTasks(-1, GETPOST('taskid', 'int'), 'taskid', 0, 0, 1, 1, 0, 0, 'maxwidth300', $projectstatic->id, 'progress');
  1263. print '</td>';
  1264. }
  1265. // Contributor
  1266. print '<td class="maxwidthonsmartphone nowraponall">';
  1267. $contactsofproject = $projectstatic->getListContactId('internal');
  1268. if (count($contactsofproject) > 0) {
  1269. print img_object('', 'user', 'class="hideonsmartphone"');
  1270. if (in_array($user->id, $contactsofproject)) {
  1271. $userid = $user->id;
  1272. } else {
  1273. $userid = $contactsofproject[0];
  1274. }
  1275. if ($projectstatic->public) {
  1276. $contactsofproject = array();
  1277. }
  1278. print $form->select_dolusers((GETPOST('userid', 'int') ? GETPOST('userid', 'int') : $userid), 'userid', 0, '', 0, '', $contactsofproject, 0, 0, 0, '', 0, $langs->trans("ResourceNotAssignedToProject"), 'maxwidth250');
  1279. } else {
  1280. if ($nboftasks) {
  1281. print img_error($langs->trans('FirstAddRessourceToAllocateTime')).' '.$langs->trans('FirstAddRessourceToAllocateTime');
  1282. }
  1283. }
  1284. print '</td>';
  1285. // Note
  1286. print '<td>';
  1287. print '<textarea name="timespent_note" class="maxwidth100onsmartphone" rows="'.ROWS_2.'">'.(GETPOST('timespent_note') ? GETPOST('timespent_note') : '').'</textarea>';
  1288. print '</td>';
  1289. // Duration - Time spent
  1290. print '<td class="nowraponall">';
  1291. $durationtouse = (GETPOST('timespent_duration') ? GETPOST('timespent_duration') : '');
  1292. if (GETPOSTISSET('timespent_durationhour') || GETPOSTISSET('timespent_durationmin')) {
  1293. $durationtouse = (GETPOST('timespent_durationhour') * 3600 + GETPOST('timespent_durationmin') * 60);
  1294. }
  1295. print $form->select_duration('timespent_duration', $durationtouse, 0, 'text');
  1296. print '</td>';
  1297. // Progress declared
  1298. print '<td class="nowrap">';
  1299. print $formother->select_percent(GETPOST('progress') ?GETPOST('progress') : $object->progress, 'progress', 0, 5, 0, 100, 1);
  1300. print '</td>';
  1301. // Invoiced
  1302. if (empty($conf->global->PROJECT_HIDE_TASKS) && !empty($conf->global->PROJECT_BILL_TIME_SPENT)) {
  1303. print '<td>';
  1304. print '</td>';
  1305. }
  1306. // Fields from hook
  1307. $parameters = array('mode' => 'create');
  1308. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook
  1309. print $hookmanager->resPrint;
  1310. print '<td class="center">';
  1311. $form->buttonsSaveCancel();
  1312. print '<input type="submit" name="save" class="button buttongen marginleftonly margintoponlyshort marginbottomonlyshort button-add" value="'.$langs->trans("Add").'">';
  1313. print '<input type="submit" name="cancel" class="button buttongen marginleftonly margintoponlyshort marginbottomonlyshort button-cancel" value="'.$langs->trans("Cancel").'">';
  1314. print '</td></tr>';
  1315. print '</table>';
  1316. print '</div>';
  1317. print '<br>';
  1318. }
  1319. $moreforfilter = '';
  1320. $parameters = array();
  1321. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook
  1322. if (empty($reshook)) {
  1323. $moreforfilter .= $hookmanager->resPrint;
  1324. } else {
  1325. $moreforfilter = $hookmanager->resPrint;
  1326. }
  1327. if (!empty($moreforfilter)) {
  1328. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  1329. print $moreforfilter;
  1330. print '</div>';
  1331. }
  1332. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  1333. $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
  1334. $selectedfields .= (is_array($arrayofmassactions) && count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
  1335. print '<div class="div-table-responsive">';
  1336. print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  1337. // Fields title search
  1338. print '<tr class="liste_titre_filter">';
  1339. // Date
  1340. if (!empty($arrayfields['t.task_date']['checked'])) {
  1341. print '<td class="liste_titre">';
  1342. if (!empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) {
  1343. print '<input class="flat valignmiddle" type="text" size="1" maxlength="2" name="search_day" value="'.$search_day.'">';
  1344. }
  1345. print '<input class="flat valignmiddle" type="text" size="1" maxlength="2" name="search_month" value="'.$search_month.'">';
  1346. $formother->select_year($search_year, 'search_year', 1, 20, 5);
  1347. print '</td>';
  1348. }
  1349. if (!empty($allprojectforuser)) {
  1350. print '<td></td>';
  1351. }
  1352. // Task
  1353. if ((empty($id) && empty($ref)) || !empty($projectidforalltimes)) { // Not a dedicated task
  1354. if (!empty($arrayfields['t.task_ref']['checked'])) {
  1355. print '<td class="liste_titre"><input type="text" class="flat maxwidth100" name="search_task_ref" value="'.dol_escape_htmltag($search_task_ref).'"></td>';
  1356. }
  1357. if (!empty($arrayfields['t.task_label']['checked'])) {
  1358. print '<td class="liste_titre"><input type="text" class="flat maxwidth100" name="search_task_label" value="'.dol_escape_htmltag($search_task_label).'"></td>';
  1359. }
  1360. }
  1361. // Author
  1362. if (!empty($arrayfields['author']['checked'])) {
  1363. 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>';
  1364. }
  1365. // Note
  1366. if (!empty($arrayfields['t.note']['checked'])) {
  1367. print '<td class="liste_titre"><input type="text" class="flat maxwidth100" name="search_note" value="'.dol_escape_htmltag($search_note).'"></td>';
  1368. }
  1369. // Duration
  1370. if (!empty($arrayfields['t.task_duration']['checked'])) {
  1371. print '<td class="liste_titre right"></td>';
  1372. }
  1373. // Value in main currency
  1374. if (!empty($arrayfields['value']['checked'])) {
  1375. print '<td class="liste_titre"></td>';
  1376. }
  1377. // Value billed
  1378. if (!empty($arrayfields['valuebilled']['checked'])) {
  1379. print '<td class="liste_titre center">'.$form->selectyesno('search_valuebilled', $search_valuebilled, 1, false, 1).'</td>';
  1380. }
  1381. /*
  1382. // Extra fields
  1383. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
  1384. */
  1385. // Fields from hook
  1386. $parameters = array('arrayfields'=>$arrayfields);
  1387. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook
  1388. print $hookmanager->resPrint;
  1389. // Action column
  1390. print '<td class="liste_titre center">';
  1391. $searchpicto = $form->showFilterButtons();
  1392. print $searchpicto;
  1393. print '</td>';
  1394. print '</tr>'."\n";
  1395. print '<tr class="liste_titre">';
  1396. if (!empty($arrayfields['t.task_date']['checked'])) {
  1397. print_liste_field_titre($arrayfields['t.task_date']['label'], $_SERVER['PHP_SELF'], 't.task_date,t.task_datehour,t.rowid', '', $param, '', $sortfield, $sortorder);
  1398. }
  1399. if (!empty($allprojectforuser)) {
  1400. print_liste_field_titre("Project", $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder);
  1401. }
  1402. if ((empty($id) && empty($ref)) || !empty($projectidforalltimes)) { // Not a dedicated task
  1403. if (!empty($arrayfields['t.task_ref']['checked'])) {
  1404. print_liste_field_titre($arrayfields['t.task_ref']['label'], $_SERVER['PHP_SELF'], 'pt.ref', '', $param, '', $sortfield, $sortorder);
  1405. }
  1406. if (!empty($arrayfields['t.task_label']['checked'])) {
  1407. print_liste_field_titre($arrayfields['t.task_label']['label'], $_SERVER['PHP_SELF'], 'pt.label', '', $param, '', $sortfield, $sortorder);
  1408. }
  1409. }
  1410. if (!empty($arrayfields['author']['checked'])) {
  1411. print_liste_field_titre($arrayfields['author']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder);
  1412. }
  1413. if (!empty($arrayfields['t.note']['checked'])) {
  1414. print_liste_field_titre($arrayfields['t.note']['label'], $_SERVER['PHP_SELF'], 't.note', '', $param, '', $sortfield, $sortorder);
  1415. }
  1416. if (!empty($arrayfields['t.task_duration']['checked'])) {
  1417. print_liste_field_titre($arrayfields['t.task_duration']['label'], $_SERVER['PHP_SELF'], 't.task_duration', '', $param, '', $sortfield, $sortorder, 'right ');
  1418. }
  1419. if (!empty($arrayfields['value']['checked'])) {
  1420. print_liste_field_titre($arrayfields['value']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'right ');
  1421. }
  1422. if (!empty($arrayfields['valuebilled']['checked'])) {
  1423. print_liste_field_titre($arrayfields['valuebilled']['label'], $_SERVER['PHP_SELF'], 'il.total_ht', '', $param, '', $sortfield, $sortorder, 'center ', $langs->trans("SelectLinesOfTimeSpentToInvoice"));
  1424. }
  1425. /*
  1426. // Extra fields
  1427. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  1428. */
  1429. // Hook fields
  1430. $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
  1431. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook
  1432. print $hookmanager->resPrint;
  1433. print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', 'width="80"', $sortfield, $sortorder, 'center maxwidthsearch ');
  1434. print "</tr>\n";
  1435. $tasktmp = new Task($db);
  1436. $tmpinvoice = new Facture($db);
  1437. $i = 0;
  1438. $total = 0;
  1439. $totalvalue = 0;
  1440. $totalarray = array();
  1441. foreach ($tasks as $task_time) {
  1442. if ($i >= $limit) {
  1443. break;
  1444. }
  1445. $date1 = $db->jdate($task_time->task_date);
  1446. $date2 = $db->jdate($task_time->task_datehour);
  1447. print '<tr class="oddeven">';
  1448. // Date
  1449. if (!empty($arrayfields['t.task_date']['checked'])) {
  1450. print '<td class="nowrap">';
  1451. if ($action == 'editline' && $_GET['lineid'] == $task_time->rowid) {
  1452. if (empty($task_time->task_date_withhour)) {
  1453. print $form->selectDate(($date2 ? $date2 : $date1), 'timeline', 3, 3, 2, "timespent_date", 1, 0);
  1454. } else {
  1455. print $form->selectDate(($date2 ? $date2 : $date1), 'timeline', 1, 1, 2, "timespent_date", 1, 0);
  1456. }
  1457. } else {
  1458. print dol_print_date(($date2 ? $date2 : $date1), ($task_time->task_date_withhour ? 'dayhour' : 'day'));
  1459. }
  1460. print '</td>';
  1461. if (!$i) {
  1462. $totalarray['nbfield']++;
  1463. }
  1464. }
  1465. // Project ref
  1466. if (!empty($allprojectforuser)) {
  1467. print '<td class="nowraponall">';
  1468. if (empty($conf->cache['project'][$task_time->fk_projet])) {
  1469. $tmpproject = new Project($db);
  1470. $tmpproject->fetch($task_time->fk_projet);
  1471. $conf->cache['project'][$task_time->fk_projet] = $tmpproject;
  1472. } else {
  1473. $tmpproject = $conf->cache['project'][$task_time->fk_projet];
  1474. }
  1475. print $tmpproject->getNomUrl(1);
  1476. print '</td>';
  1477. if (!$i) {
  1478. $totalarray['nbfield']++;
  1479. }
  1480. }
  1481. // Task ref
  1482. if (!empty($arrayfields['t.task_ref']['checked'])) {
  1483. if ((empty($id) && empty($ref)) || !empty($projectidforalltimes)) { // Not a dedicated task
  1484. print '<td class="nowrap">';
  1485. if ($action == 'editline' && $_GET['lineid'] == $task_time->rowid) {
  1486. $formproject->selectTasks(-1, GETPOST('taskid', 'int') ? GETPOST('taskid', 'int') : $task_time->fk_task, 'taskid', 0, 0, 1, 1, 0, 0, 'maxwidth300', $projectstatic->id, '');
  1487. } else {
  1488. $tasktmp->id = $task_time->fk_task;
  1489. $tasktmp->ref = $task_time->ref;
  1490. $tasktmp->label = $task_time->label;
  1491. print $tasktmp->getNomUrl(1, 'withproject', 'time');
  1492. }
  1493. print '</td>';
  1494. if (!$i) {
  1495. $totalarray['nbfield']++;
  1496. }
  1497. }
  1498. } elseif ($action !== 'createtime') {
  1499. print '<input type="hidden" name="taskid" value="'.$id.'">';
  1500. }
  1501. // Task label
  1502. if (!empty($arrayfields['t.task_label']['checked'])) {
  1503. if ((empty($id) && empty($ref)) || !empty($projectidforalltimes)) { // Not a dedicated task
  1504. print '<td class="nowrap tdoverflowmax300" title="'.dol_escape_htmltag($task_time->label).'">';
  1505. print dol_escape_htmltag($task_time->label);
  1506. print '</td>';
  1507. if (!$i) {
  1508. $totalarray['nbfield']++;
  1509. }
  1510. }
  1511. }
  1512. // By User
  1513. if (!empty($arrayfields['author']['checked'])) {
  1514. print '<td class="tdoverflowmax100">';
  1515. if ($action == 'editline' && $_GET['lineid'] == $task_time->rowid) {
  1516. if (empty($object->id)) {
  1517. $object->fetch($id);
  1518. }
  1519. $contactsoftask = $object->getListContactId('internal');
  1520. if (!in_array($task_time->fk_user, $contactsoftask)) {
  1521. $contactsoftask[] = $task_time->fk_user;
  1522. }
  1523. if (count($contactsoftask) > 0) {
  1524. print img_object('', 'user', 'class="hideonsmartphone"');
  1525. print $form->select_dolusers($task_time->fk_user, 'userid_line', 0, '', 0, '', $contactsoftask, '0', 0, 0, '', 0, '', 'maxwidth200');
  1526. } else {
  1527. print img_error($langs->trans('FirstAddRessourceToAllocateTime')).$langs->trans('FirstAddRessourceToAllocateTime');
  1528. }
  1529. } else {
  1530. $userstatic->id = $task_time->fk_user;
  1531. $userstatic->lastname = $task_time->lastname;
  1532. $userstatic->firstname = $task_time->firstname;
  1533. $userstatic->photo = $task_time->photo;
  1534. $userstatic->statut = $task_time->user_status;
  1535. print $userstatic->getNomUrl(-1);
  1536. }
  1537. print '</td>';
  1538. if (!$i) {
  1539. $totalarray['nbfield']++;
  1540. }
  1541. }
  1542. // Note
  1543. if (!empty($arrayfields['t.note']['checked'])) {
  1544. print '<td class="small">';
  1545. if ($action == 'editline' && $_GET['lineid'] == $task_time->rowid) {
  1546. print '<textarea name="timespent_note_line" width="95%" rows="'.ROWS_2.'">'.$task_time->note.'</textarea>';
  1547. } else {
  1548. print dol_nl2br($task_time->note);
  1549. }
  1550. print '</td>';
  1551. if (!$i) {
  1552. $totalarray['nbfield']++;
  1553. }
  1554. } elseif ($action == 'editline' && $_GET['lineid'] == $task_time->rowid) {
  1555. print '<input type="hidden" name="timespent_note_line" value="'.$task_time->note.'">';
  1556. }
  1557. // Time spent
  1558. if (!empty($arrayfields['t.task_duration']['checked'])) {
  1559. print '<td class="right nowraponall">';
  1560. if ($action == 'editline' && $_GET['lineid'] == $task_time->rowid) {
  1561. print '<input type="hidden" name="old_duration" value="'.$task_time->task_duration.'">';
  1562. print $form->select_duration('new_duration', $task_time->task_duration, 0, 'text');
  1563. } else {
  1564. print convertSecondToTime($task_time->task_duration, 'allhourmin');
  1565. }
  1566. print '</td>';
  1567. if (!$i) {
  1568. $totalarray['nbfield']++;
  1569. }
  1570. if (!$i) {
  1571. $totalarray['pos'][$totalarray['nbfield']] = 't.task_duration';
  1572. }
  1573. $totalarray['val']['t.task_duration'] += $task_time->task_duration;
  1574. if (!$i) {
  1575. $totalarray['totaldurationfield'] = $totalarray['nbfield'];
  1576. }
  1577. $totalarray['totalduration'] += $task_time->task_duration;
  1578. }
  1579. // Value spent
  1580. if (!empty($arrayfields['value']['checked'])) {
  1581. $langs->load("salaries");
  1582. print '<td class="nowraponall right">';
  1583. $value = price2num($task_time->thm * $task_time->task_duration / 3600, 'MT', 1);
  1584. print '<span class="amount" title="'.$langs->trans("THM").': '.price($task_time->thm).'">';
  1585. print price($value, 1, $langs, 1, -1, -1, $conf->currency);
  1586. print '</span>';
  1587. print '</td>';
  1588. if (!$i) {
  1589. $totalarray['nbfield']++;
  1590. }
  1591. if (!$i) {
  1592. $totalarray['pos'][$totalarray['nbfield']] = 'value';
  1593. }
  1594. $totalarray['val']['value'] += $value;
  1595. if (!$i) {
  1596. $totalarray['totalvaluefield'] = $totalarray['nbfield'];
  1597. }
  1598. $totalarray['totalvalue'] += $value;
  1599. }
  1600. // Invoiced
  1601. if (!empty($arrayfields['valuebilled']['checked'])) {
  1602. print '<td class="center">'; // invoice_id and invoice_line_id
  1603. if (empty($conf->global->PROJECT_HIDE_TASKS) && !empty($conf->global->PROJECT_BILL_TIME_SPENT)) {
  1604. if ($projectstatic->usage_bill_time) {
  1605. if ($task_time->invoice_id) {
  1606. $result = $tmpinvoice->fetch($task_time->invoice_id);
  1607. if ($result > 0) {
  1608. print $tmpinvoice->getNomUrl(1);
  1609. }
  1610. } else {
  1611. print $langs->trans("No");
  1612. }
  1613. } else {
  1614. print '<span class="opacitymedium">'.$langs->trans("NA").'</span>';
  1615. }
  1616. }
  1617. print '</td>';
  1618. if (!$i) {
  1619. $totalarray['nbfield']++;
  1620. }
  1621. }
  1622. /*
  1623. // Extra fields
  1624. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  1625. */
  1626. // Fields from hook
  1627. $parameters = array('arrayfields'=>$arrayfields, 'obj'=>$task_time, 'i'=>$i, 'totalarray'=>&$totalarray);
  1628. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook
  1629. print $hookmanager->resPrint;
  1630. // Action column
  1631. print '<td class="center nowraponall">';
  1632. if (($action == 'editline' || $action == 'splitline') && $_GET['lineid'] == $task_time->rowid) {
  1633. print '<input type="hidden" name="lineid" value="'.$_GET['lineid'].'">';
  1634. print '<input type="submit" class="button buttongen margintoponlyshort marginbottomonlyshort button-save" name="save" value="'.$langs->trans("Save").'">';
  1635. print '<br>';
  1636. print '<input type="submit" class="button buttongen margintoponlyshort marginbottomonlyshort button-cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
  1637. } elseif ($user->rights->projet->lire || $user->rights->projet->all->creer) { // Read project and enter time consumed on assigned tasks
  1638. if (in_array($task_time->fk_user, $childids) || $user->rights->projet->all->creer) {
  1639. if ($conf->MAIN_FEATURES_LEVEL >= 2) {
  1640. print '&nbsp;';
  1641. 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' : '').'">';
  1642. print img_split();
  1643. print '</a>';
  1644. }
  1645. print '&nbsp;';
  1646. 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' : '').'">';
  1647. print img_edit();
  1648. print '</a>';
  1649. print '&nbsp;';
  1650. 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' : '').'">';
  1651. print img_delete('default', 'class="pictodelete paddingleft"');
  1652. print '</a>';
  1653. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  1654. $selected = 0;
  1655. if (in_array($task_time->rowid, $arrayofselected)) {
  1656. $selected = 1;
  1657. }
  1658. print '&nbsp;';
  1659. print '<input id="cb'.$task_time->rowid.'" class="flat checkforselect marginleftonly" type="checkbox" name="toselect[]" value="'.$task_time->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
  1660. }
  1661. }
  1662. }
  1663. print '</td>';
  1664. if (!$i) {
  1665. $totalarray['nbfield']++;
  1666. }
  1667. print "</tr>\n";
  1668. // Add line to split
  1669. if ($action == 'splitline' && $_GET['lineid'] == $task_time->rowid) {
  1670. print '<tr class="oddeven">';
  1671. // Date
  1672. if (!empty($arrayfields['t.task_date']['checked'])) {
  1673. print '<td class="nowrap">';
  1674. if ($action == 'splitline' && $_GET['lineid'] == $task_time->rowid) {
  1675. if (empty($task_time->task_date_withhour)) {
  1676. print $form->selectDate(($date2 ? $date2 : $date1), 'timeline', 3, 3, 2, "timespent_date", 1, 0);
  1677. } else {
  1678. print $form->selectDate(($date2 ? $date2 : $date1), 'timeline', 1, 1, 2, "timespent_date", 1, 0);
  1679. }
  1680. } else {
  1681. print dol_print_date(($date2 ? $date2 : $date1), ($task_time->task_date_withhour ? 'dayhour' : 'day'));
  1682. }
  1683. print '</td>';
  1684. }
  1685. // Project ref
  1686. if (!empty($allprojectforuser)) {
  1687. if ((empty($id) && empty($ref)) || !empty($projectidforalltimes)) { // Not a dedicated task
  1688. print '<td class="nowrap">';
  1689. print '</td>';
  1690. }
  1691. }
  1692. // Task ref
  1693. if (!empty($arrayfields['t.task_ref']['checked'])) {
  1694. if ((empty($id) && empty($ref)) || !empty($projectidforalltimes)) { // Not a dedicated task
  1695. print '<td class="nowrap">';
  1696. $tasktmp->id = $task_time->fk_task;
  1697. $tasktmp->ref = $task_time->ref;
  1698. $tasktmp->label = $task_time->label;
  1699. print $tasktmp->getNomUrl(1, 'withproject', 'time');
  1700. print '</td>';
  1701. }
  1702. }
  1703. // Task label
  1704. if (!empty($arrayfields['t.task_label']['checked'])) {
  1705. if ((empty($id) && empty($ref)) || !empty($projectidforalltimes)) { // Not a dedicated task
  1706. print '<td class="tdoverflowmax300" title="'.dol_escape_htmltag($task_time->label).'">';
  1707. print dol_escape_htmltag($task_time->label);
  1708. print '</td>';
  1709. }
  1710. }
  1711. // User
  1712. if (!empty($arrayfields['author']['checked'])) {
  1713. print '<td>';
  1714. if ($action == 'splitline' && $_GET['lineid'] == $task_time->rowid) {
  1715. if (empty($object->id)) {
  1716. $object->fetch($id);
  1717. }
  1718. $contactsoftask = $object->getListContactId('internal');
  1719. if (!in_array($task_time->fk_user, $contactsoftask)) {
  1720. $contactsoftask[] = $task_time->fk_user;
  1721. }
  1722. if (count($contactsoftask) > 0) {
  1723. print img_object('', 'user', 'class="hideonsmartphone"');
  1724. print $form->select_dolusers($task_time->fk_user, 'userid_line', 0, '', 0, '', $contactsoftask);
  1725. } else {
  1726. print img_error($langs->trans('FirstAddRessourceToAllocateTime')).$langs->trans('FirstAddRessourceToAllocateTime');
  1727. }
  1728. } else {
  1729. $userstatic->id = $task_time->fk_user;
  1730. $userstatic->lastname = $task_time->lastname;
  1731. $userstatic->firstname = $task_time->firstname;
  1732. $userstatic->photo = $task_time->photo;
  1733. $userstatic->statut = $task_time->user_status;
  1734. print $userstatic->getNomUrl(-1);
  1735. }
  1736. print '</td>';
  1737. }
  1738. // Note
  1739. if (!empty($arrayfields['t.note']['checked'])) {
  1740. print '<td class="tdoverflowmax300">';
  1741. if ($action == 'splitline' && $_GET['lineid'] == $task_time->rowid) {
  1742. print '<textarea name="timespent_note_line" width="95%" rows="'.ROWS_2.'">'.$task_time->note.'</textarea>';
  1743. } else {
  1744. print dol_nl2br($task_time->note);
  1745. }
  1746. print '</td>';
  1747. } elseif ($action == 'splitline' && $_GET['lineid'] == $task_time->rowid) {
  1748. print '<input type="hidden" name="timespent_note_line" value="'.$task_time->note.'">';
  1749. }
  1750. // Time spent
  1751. if (!empty($arrayfields['t.task_duration']['checked'])) {
  1752. print '<td class="right">';
  1753. if ($action == 'splitline' && $_GET['lineid'] == $task_time->rowid) {
  1754. print '<input type="hidden" name="old_duration" value="'.$task_time->task_duration.'">';
  1755. print $form->select_duration('new_duration', $task_time->task_duration, 0, 'text');
  1756. } else {
  1757. print convertSecondToTime($task_time->task_duration, 'allhourmin');
  1758. }
  1759. print '</td>';
  1760. }
  1761. // Value spent
  1762. if (!empty($arrayfields['value']['checked'])) {
  1763. print '<td class="right">';
  1764. $value = price2num($task_time->thm * $task_time->task_duration / 3600, 'MT', 1);
  1765. print price($value, 1, $langs, 1, -1, -1, $conf->currency);
  1766. print '</td>';
  1767. }
  1768. // Value billed
  1769. if (!empty($arrayfields['valuebilled']['checked'])) {
  1770. print '<td class="right">';
  1771. $valuebilled = price2num($task_time->total_ht, '', 1);
  1772. if (isset($task_time->total_ht)) {
  1773. print price($valuebilled, 1, $langs, 1, -1, -1, $conf->currency);
  1774. }
  1775. print '</td>';
  1776. }
  1777. /*
  1778. // Extra fields
  1779. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  1780. */
  1781. // Fields from hook
  1782. $parameters = array('arrayfields'=>$arrayfields, 'obj'=>$task_time, 'mode' => 'split1');
  1783. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook
  1784. print $hookmanager->resPrint;
  1785. // Action column
  1786. print '<td class="center nowraponall">';
  1787. print '</td>';
  1788. print "</tr>\n";
  1789. // Line for second dispatching
  1790. print '<tr class="oddeven">';
  1791. // Date
  1792. if (!empty($arrayfields['t.task_date']['checked'])) {
  1793. print '<td class="nowrap">';
  1794. if ($action == 'splitline' && $_GET['lineid'] == $task_time->rowid) {
  1795. if (empty($task_time->task_date_withhour)) {
  1796. print $form->selectDate(($date2 ? $date2 : $date1), 'timeline_2', 3, 3, 2, "timespent_date", 1, 0);
  1797. } else {
  1798. print $form->selectDate(($date2 ? $date2 : $date1), 'timeline_2', 1, 1, 2, "timespent_date", 1, 0);
  1799. }
  1800. } else {
  1801. print dol_print_date(($date2 ? $date2 : $date1), ($task_time->task_date_withhour ? 'dayhour' : 'day'));
  1802. }
  1803. print '</td>';
  1804. }
  1805. // Project ref
  1806. if (!empty($allprojectforuser)) {
  1807. if ((empty($id) && empty($ref)) || !empty($projectidforalltimes)) { // Not a dedicated task
  1808. print '<td class="nowrap">';
  1809. print '</td>';
  1810. }
  1811. }
  1812. // Task ref
  1813. if (!empty($arrayfields['t.task_ref']['checked'])) {
  1814. if ((empty($id) && empty($ref)) || !empty($projectidforalltimes)) { // Not a dedicated task
  1815. print '<td class="nowrap">';
  1816. $tasktmp->id = $task_time->fk_task;
  1817. $tasktmp->ref = $task_time->ref;
  1818. $tasktmp->label = $task_time->label;
  1819. print $tasktmp->getNomUrl(1, 'withproject', 'time');
  1820. print '</td>';
  1821. }
  1822. }
  1823. // Task label
  1824. if (!empty($arrayfields['t.task_label']['checked'])) {
  1825. if ((empty($id) && empty($ref)) || !empty($projectidforalltimes)) { // Not a dedicated task
  1826. print '<td class="nowrap">';
  1827. print $task_time->label;
  1828. print '</td>';
  1829. }
  1830. }
  1831. // User
  1832. if (!empty($arrayfields['author']['checked'])) {
  1833. print '<td>';
  1834. if ($action == 'splitline' && $_GET['lineid'] == $task_time->rowid) {
  1835. if (empty($object->id)) {
  1836. $object->fetch($id);
  1837. }
  1838. $contactsoftask = $object->getListContactId('internal');
  1839. if (!in_array($task_time->fk_user, $contactsoftask)) {
  1840. $contactsoftask[] = $task_time->fk_user;
  1841. }
  1842. if (count($contactsoftask) > 0) {
  1843. print img_object('', 'user', 'class="hideonsmartphone"');
  1844. print $form->select_dolusers($task_time->fk_user, 'userid_line_2', 0, '', 0, '', $contactsoftask);
  1845. } else {
  1846. print img_error($langs->trans('FirstAddRessourceToAllocateTime')).$langs->trans('FirstAddRessourceToAllocateTime');
  1847. }
  1848. } else {
  1849. $userstatic->id = $task_time->fk_user;
  1850. $userstatic->lastname = $task_time->lastname;
  1851. $userstatic->firstname = $task_time->firstname;
  1852. $userstatic->photo = $task_time->photo;
  1853. $userstatic->statut = $task_time->user_status;
  1854. print $userstatic->getNomUrl(-1);
  1855. }
  1856. print '</td>';
  1857. }
  1858. // Note
  1859. if (!empty($arrayfields['t.note']['checked'])) {
  1860. print '<td class="small tdoverflowmax300"">';
  1861. if ($action == 'splitline' && $_GET['lineid'] == $task_time->rowid) {
  1862. print '<textarea name="timespent_note_line_2" width="95%" rows="'.ROWS_2.'">'.$task_time->note.'</textarea>';
  1863. } else {
  1864. print dol_nl2br($task_time->note);
  1865. }
  1866. print '</td>';
  1867. } elseif ($action == 'splitline' && $_GET['lineid'] == $task_time->rowid) {
  1868. print '<input type="hidden" name="timespent_note_line_2" value="'.$task_time->note.'">';
  1869. }
  1870. // Time spent
  1871. if (!empty($arrayfields['t.task_duration']['checked'])) {
  1872. print '<td class="right">';
  1873. if ($action == 'splitline' && $_GET['lineid'] == $task_time->rowid) {
  1874. print '<input type="hidden" name="old_duration_2" value="0">';
  1875. print $form->select_duration('new_duration_2', 0, 0, 'text');
  1876. } else {
  1877. print convertSecondToTime($task_time->task_duration, 'allhourmin');
  1878. }
  1879. print '</td>';
  1880. }
  1881. // Value spent
  1882. if (!empty($arrayfields['value']['checked'])) {
  1883. print '<td class="right">';
  1884. $value = 0;
  1885. print price($value, 1, $langs, 1, -1, -1, $conf->currency);
  1886. print '</td>';
  1887. }
  1888. // Value billed
  1889. if (!empty($arrayfields['valuebilled']['checked'])) {
  1890. print '<td class="right">';
  1891. $valuebilled = price2num($task_time->total_ht, '', 1);
  1892. if (isset($task_time->total_ht)) {
  1893. print price($valuebilled, 1, $langs, 1, -1, -1, $conf->currency);
  1894. }
  1895. print '</td>';
  1896. }
  1897. /*
  1898. // Extra fields
  1899. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  1900. */
  1901. // Fields from hook
  1902. $parameters = array('arrayfields'=>$arrayfields, 'obj'=>$task_time, 'mode' => 'split2');
  1903. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook
  1904. print $hookmanager->resPrint;
  1905. // Action column
  1906. print '<td class="center nowraponall">';
  1907. print '</td>';
  1908. print "</tr>\n";
  1909. }
  1910. $i++;
  1911. }
  1912. // Show total line
  1913. //include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
  1914. if (isset($totalarray['totaldurationfield']) || isset($totalarray['totalvaluefield'])) {
  1915. print '<tr class="liste_total">';
  1916. $i = 0;
  1917. while ($i < $totalarray['nbfield']) {
  1918. $i++;
  1919. if ($i == 1) {
  1920. if ($num < $limit && empty($offset)) {
  1921. print '<td class="left">'.$langs->trans("Total").'</td>';
  1922. } else {
  1923. print '<td class="left">'.$langs->trans("Totalforthispage").'</td>';
  1924. }
  1925. } elseif ($totalarray['totaldurationfield'] == $i) {
  1926. print '<td class="right">'.convertSecondToTime($totalarray['totalduration'], 'allhourmin').'</td>';
  1927. } elseif ($totalarray['totalvaluefield'] == $i) {
  1928. print '<td class="right">'.price($totalarray['totalvalue']).'</td>';
  1929. //} elseif ($totalarray['totalvaluebilledfield'] == $i) { print '<td class="center">'.price($totalarray['totalvaluebilled']).'</td>';
  1930. } else {
  1931. print '<td></td>';
  1932. }
  1933. }
  1934. print '</tr>';
  1935. }
  1936. if (!count($tasks)) {
  1937. $totalnboffields = 1;
  1938. foreach ($arrayfields as $value) {
  1939. if ($value['checked']) {
  1940. $totalnboffields++;
  1941. }
  1942. }
  1943. print '<tr class="oddeven"><td colspan="'.$totalnboffields.'">';
  1944. print '<span class="opacitymedium">'.$langs->trans("None").'</span>';
  1945. print '</td></tr>';
  1946. }
  1947. $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
  1948. $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters); // Note that $action and $object may have been modified by hook
  1949. print $hookmanager->resPrint;
  1950. print "</table>";
  1951. print '</div>';
  1952. print "</form>";
  1953. }
  1954. }
  1955. // End of page
  1956. llxFooter();
  1957. $db->close();