time.php 104 KB

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