time.php 90 KB

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