time.php 115 KB

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