time.php 86 KB

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