time.php 115 KB

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