project.lib.php 118 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019
  1. <?php
  2. /* Copyright (C) 2006-2015 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2010 Regis Houssin <regis.houssin@inodbox.com>
  4. * Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
  5. * Copyright (C) 2018-2021 Frédéric France <frederic.france@netlogic.fr>
  6. * Copyright (C) 2022 Charlene Benke <charlene@patas-monkey.com>
  7. * Copyright (C) 2023 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  21. * or see https://www.gnu.org/
  22. */
  23. /**
  24. * \file htdocs/core/lib/project.lib.php
  25. * \brief Functions used by project module
  26. * \ingroup project
  27. */
  28. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  29. /**
  30. * Prepare array with list of tabs
  31. *
  32. * @param Project $project Object related to tabs
  33. * @param string $moreparam More param on url
  34. * @return array Array of tabs to show
  35. */
  36. function project_prepare_head(Project $project, $moreparam = '')
  37. {
  38. global $db, $langs, $conf, $user;
  39. $h = 0;
  40. $head = array();
  41. $head[$h][0] = DOL_URL_ROOT.'/projet/card.php?id='.((int) $project->id).($moreparam ? '&'.$moreparam : '');
  42. $head[$h][1] = $langs->trans("Project");
  43. $head[$h][2] = 'project';
  44. $h++;
  45. $nbContacts = 0;
  46. // Enable caching of project count Contacts
  47. require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';
  48. $cachekey = 'count_contacts_project_'.$project->id;
  49. $dataretrieved = dol_getcache($cachekey);
  50. if (!is_null($dataretrieved)) {
  51. $nbContacts = $dataretrieved;
  52. } else {
  53. $nbContacts = count($project->liste_contact(-1, 'internal')) + count($project->liste_contact(-1, 'external'));
  54. dol_setcache($cachekey, $nbContacts, 120); // If setting cache fails, this is not a problem, so we do not test result.
  55. }
  56. $head[$h][0] = DOL_URL_ROOT.'/projet/contact.php?id='.((int) $project->id).($moreparam ? '&'.$moreparam : '');
  57. $head[$h][1] = $langs->trans("ProjectContact");
  58. if ($nbContacts > 0) {
  59. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbContacts.'</span>';
  60. }
  61. $head[$h][2] = 'contact';
  62. $h++;
  63. if (!getDolGlobalString('PROJECT_HIDE_TASKS')) {
  64. // Then tab for sub level of projet, i mean tasks
  65. $nbTasks = 0;
  66. // Enable caching of project count Tasks
  67. require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';
  68. $cachekey = 'count_tasks_project_'.$project->id;
  69. $dataretrieved = dol_getcache($cachekey);
  70. if (!is_null($dataretrieved)) {
  71. $nbTasks = $dataretrieved;
  72. } else {
  73. require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php';
  74. $taskstatic = new Task($db);
  75. $nbTasks = count($taskstatic->getTasksArray(0, 0, $project->id, 0, 0));
  76. dol_setcache($cachekey, $nbTasks, 120); // If setting cache fails, this is not a problem, so we do not test result.
  77. }
  78. $head[$h][0] = DOL_URL_ROOT.'/projet/tasks.php?id='.((int) $project->id).($moreparam ? '&'.$moreparam : '');
  79. $head[$h][1] = $langs->trans("Tasks");
  80. if ($nbTasks > 0) {
  81. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.($nbTasks).'</span>';
  82. }
  83. $head[$h][2] = 'tasks';
  84. $h++;
  85. $nbTimeSpent = 0;
  86. // Enable caching of project count Timespent
  87. $cachekey = 'count_timespent_project_'.$project->id;
  88. $dataretrieved = dol_getcache($cachekey);
  89. if (!is_null($dataretrieved)) {
  90. $nbTimeSpent = $dataretrieved;
  91. } else {
  92. $sql = "SELECT t.rowid";
  93. //$sql .= " FROM ".MAIN_DB_PREFIX."element_time as t, ".MAIN_DB_PREFIX."projet_task as pt, ".MAIN_DB_PREFIX."user as u";
  94. //$sql .= " WHERE t.fk_user = u.rowid AND t.fk_task = pt.rowid";
  95. $sql .= " FROM ".MAIN_DB_PREFIX."element_time as t, ".MAIN_DB_PREFIX."projet_task as pt";
  96. $sql .= " WHERE t.fk_element = pt.rowid";
  97. $sql .= " AND t.elementtype = 'task'";
  98. $sql .= " AND pt.fk_projet =".((int) $project->id);
  99. $resql = $db->query($sql);
  100. if ($resql) {
  101. $obj = $db->fetch_object($resql);
  102. if ($obj) {
  103. $nbTimeSpent = 1;
  104. dol_setcache($cachekey, $nbTimeSpent, 120); // If setting cache fails, this is not a problem, so we do not test result.
  105. }
  106. } else {
  107. dol_print_error($db);
  108. }
  109. }
  110. $head[$h][0] = DOL_URL_ROOT.'/projet/tasks/time.php?withproject=1&projectid='.((int) $project->id).($moreparam ? '&'.$moreparam : '');
  111. $head[$h][1] = $langs->trans("TimeSpent");
  112. if ($nbTimeSpent > 0) {
  113. $head[$h][1] .= '<span class="badge marginleftonlyshort">...</span>';
  114. }
  115. $head[$h][2] = 'timespent';
  116. $h++;
  117. }
  118. if (isModEnabled("supplier_proposal") || isModEnabled("supplier_order") || isModEnabled("supplier_invoice")
  119. || isModEnabled("propal") || isModEnabled('commande')
  120. || isModEnabled('facture') || isModEnabled('contrat')
  121. || isModEnabled('ficheinter') || isModEnabled('agenda') || isModEnabled('deplacement') || isModEnabled('stock')) {
  122. $nbElements = 0;
  123. // Enable caching of thirdrparty count Contacts
  124. $cachekey = 'count_elements_project_'.$project->id;
  125. $dataretrieved = dol_getcache($cachekey);
  126. if (!is_null($dataretrieved)) {
  127. $nbElements = $dataretrieved;
  128. } else {
  129. if (isModEnabled('stock')) {
  130. $nbElements += $project->getElementCount('stock', 'entrepot', 'fk_project');
  131. }
  132. if (isModEnabled("propal")) {
  133. $nbElements += $project->getElementCount('propal', 'propal');
  134. }
  135. if (isModEnabled('commande')) {
  136. $nbElements += $project->getElementCount('order', 'commande');
  137. }
  138. if (isModEnabled('facture')) {
  139. $nbElements += $project->getElementCount('invoice', 'facture');
  140. }
  141. if (isModEnabled('facture')) {
  142. $nbElements += $project->getElementCount('invoice_predefined', 'facture_rec');
  143. }
  144. if (isModEnabled('supplier_proposal')) {
  145. $nbElements += $project->getElementCount('proposal_supplier', 'supplier_proposal');
  146. }
  147. if (isModEnabled("supplier_order")) {
  148. $nbElements += $project->getElementCount('order_supplier', 'commande_fournisseur');
  149. }
  150. if (isModEnabled("supplier_invoice")) {
  151. $nbElements += $project->getElementCount('invoice_supplier', 'facture_fourn');
  152. }
  153. if (isModEnabled('contrat')) {
  154. $nbElements += $project->getElementCount('contract', 'contrat');
  155. }
  156. if (isModEnabled('ficheinter')) {
  157. $nbElements += $project->getElementCount('intervention', 'fichinter');
  158. }
  159. if (isModEnabled("expedition")) {
  160. $nbElements += $project->getElementCount('shipping', 'expedition');
  161. }
  162. if (isModEnabled('mrp')) {
  163. $nbElements += $project->getElementCount('mrp', 'mrp_mo', 'fk_project');
  164. }
  165. if (isModEnabled('deplacement')) {
  166. $nbElements += $project->getElementCount('trip', 'deplacement');
  167. }
  168. if (isModEnabled('expensereport')) {
  169. $nbElements += $project->getElementCount('expensereport', 'expensereport');
  170. }
  171. if (isModEnabled('don')) {
  172. $nbElements += $project->getElementCount('donation', 'don');
  173. }
  174. if (isModEnabled('loan')) {
  175. $nbElements += $project->getElementCount('loan', 'loan');
  176. }
  177. if (isModEnabled('tax')) {
  178. $nbElements += $project->getElementCount('chargesociales', 'chargesociales');
  179. }
  180. if (isModEnabled('project')) {
  181. $nbElements += $project->getElementCount('project_task', 'projet_task');
  182. }
  183. if (isModEnabled('stock')) {
  184. $nbElements += $project->getElementCount('stock_mouvement', 'stock');
  185. }
  186. if (isModEnabled('salaries')) {
  187. $nbElements += $project->getElementCount('salaries', 'payment_salary');
  188. }
  189. if (isModEnabled("banque")) {
  190. $nbElements += $project->getElementCount('variouspayment', 'payment_various');
  191. }
  192. dol_setcache($cachekey, $nbElements, 120); // If setting cache fails, this is not a problem, so we do not test result.
  193. }
  194. $head[$h][0] = DOL_URL_ROOT.'/projet/element.php?id='.$project->id;
  195. $head[$h][1] = $langs->trans("ProjectOverview");
  196. if ($nbElements > 0) {
  197. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbElements.'</span>';
  198. }
  199. $head[$h][2] = 'element';
  200. $h++;
  201. }
  202. if (isModEnabled('ticket') && $user->hasRight('ticket', 'read')) {
  203. require_once DOL_DOCUMENT_ROOT.'/ticket/class/ticket.class.php';
  204. $Tickettatic = new Ticket($db);
  205. $nbTicket = $Tickettatic->getCountOfItemsLinkedByObjectID($project->id, 'fk_project', 'ticket');
  206. $head[$h][0] = DOL_URL_ROOT.'/ticket/list.php?projectid='.((int) $project->id);
  207. $head[$h][1] = $langs->trans("Ticket");
  208. if ($nbTicket > 0) {
  209. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.($nbTicket).'</span>';
  210. }
  211. $head[$h][2] = 'ticket';
  212. $h++;
  213. }
  214. if (isModEnabled('eventorganization') && !empty($project->usage_organize_event)) {
  215. $langs->load('eventorganization');
  216. $head[$h][0] = DOL_URL_ROOT . '/eventorganization/conferenceorbooth_list.php?projectid=' . $project->id;
  217. $head[$h][1] = $langs->trans("EventOrganization");
  218. // Enable caching of conf or booth count
  219. $nbConfOrBooth = 0;
  220. $nbAttendees = 0;
  221. require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';
  222. $cachekey = 'count_conferenceorbooth_'.$project->id;
  223. $dataretrieved = dol_getcache($cachekey);
  224. if (!is_null($dataretrieved)) {
  225. $nbConfOrBooth = $dataretrieved;
  226. } else {
  227. require_once DOL_DOCUMENT_ROOT.'/eventorganization/class/conferenceorbooth.class.php';
  228. $conforbooth=new ConferenceOrBooth($db);
  229. $result = $conforbooth->fetchAll('', '', 0, 0, array('t.fk_project'=>$project->id));
  230. //,
  231. if (!is_array($result) && $result<0) {
  232. setEventMessages($conforbooth->error, $conforbooth->errors, 'errors');
  233. } else {
  234. $nbConfOrBooth = count($result);
  235. }
  236. dol_setcache($cachekey, $nbConfOrBooth, 120); // If setting cache fails, this is not a problem, so we do not test result.
  237. }
  238. $cachekey = 'count_attendees_'.$project->id;
  239. $dataretrieved = dol_getcache($cachekey);
  240. if (!is_null($dataretrieved)) {
  241. $nbAttendees = $dataretrieved;
  242. } else {
  243. require_once DOL_DOCUMENT_ROOT.'/eventorganization/class/conferenceorboothattendee.class.php';
  244. $conforboothattendee=new ConferenceOrBoothAttendee($db);
  245. $result = $conforboothattendee->fetchAll('', '', 0, 0, array('t.fk_project'=>$project->id));
  246. //,
  247. if (!is_array($result) && $result<0) {
  248. setEventMessages($conforboothattendee->error, $conforboothattendee->errors, 'errors');
  249. } else {
  250. $nbAttendees = count($result);
  251. }
  252. dol_setcache($cachekey, $nbAttendees, 120); // If setting cache fails, this is not a problem, so we do not test result.
  253. }
  254. if ($nbConfOrBooth > 0 || $nbAttendees > 0) {
  255. $head[$h][1] .= '<span class="badge marginleftonlyshort">';
  256. $head[$h][1] .= '<span title="'.dol_escape_htmltag($langs->trans("ConferenceOrBooth")).'">'.$nbConfOrBooth.'</span>';
  257. if ($nbConfOrBooth > 0 && $nbAttendees > 0) {
  258. $head[$h][1] .= ' + ';
  259. }
  260. $head[$h][1] .= '<span title="'.dol_escape_htmltag($langs->trans("Attendees")).'">'.$nbAttendees.'</span>';
  261. $head[$h][1] .= '</span>';
  262. }
  263. $head[$h][2] = 'eventorganisation';
  264. $h++;
  265. }
  266. // Show more tabs from modules
  267. // Entries must be declared in modules descriptor with line
  268. // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
  269. // $this->tabs = array('entity:-tabname); to remove a tab
  270. complete_head_from_modules($conf, $langs, $project, $head, $h, 'project', 'add', 'core');
  271. if (!getDolGlobalString('MAIN_DISABLE_NOTES_TAB')) {
  272. $nbNote = 0;
  273. if (!empty($project->note_private)) {
  274. $nbNote++;
  275. }
  276. if (!empty($project->note_public)) {
  277. $nbNote++;
  278. }
  279. $head[$h][0] = DOL_URL_ROOT.'/projet/note.php?id='.$project->id;
  280. $head[$h][1] = $langs->trans('Notes');
  281. if ($nbNote > 0) {
  282. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbNote.'</span>';
  283. }
  284. $head[$h][2] = 'notes';
  285. $h++;
  286. }
  287. // Attached files and Links
  288. $totalAttached = 0;
  289. // Enable caching of thirdrparty count attached files and links
  290. require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';
  291. $cachekey = 'count_attached_project_'.$project->id;
  292. $dataretrieved = dol_getcache($cachekey);
  293. if (!is_null($dataretrieved)) {
  294. $totalAttached = $dataretrieved;
  295. } else {
  296. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  297. require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
  298. $upload_dir = $conf->project->multidir_output[empty($project->entity) ? 1 : $project->entity]."/".dol_sanitizeFileName($project->ref);
  299. $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
  300. $nbLinks = Link::count($db, $project->element, $project->id);
  301. $totalAttached = $nbFiles + $nbLinks;
  302. dol_setcache($cachekey, $totalAttached, 120); // If setting cache fails, this is not a problem, so we do not test result.
  303. }
  304. $head[$h][0] = DOL_URL_ROOT.'/projet/document.php?id='.$project->id;
  305. $head[$h][1] = $langs->trans('Documents');
  306. if (($totalAttached) > 0) {
  307. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.($totalAttached).'</span>';
  308. }
  309. $head[$h][2] = 'document';
  310. $h++;
  311. // Manage discussion
  312. if (getDolGlobalString('PROJECT_ALLOW_COMMENT_ON_PROJECT')) {
  313. $nbComments = 0;
  314. // Enable caching of thirdrparty count attached files and links
  315. require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';
  316. $cachekey = 'count_attached_project_'.$project->id;
  317. $dataretrieved = dol_getcache($cachekey);
  318. if (!is_null($dataretrieved)) {
  319. $nbComments = $dataretrieved;
  320. } else {
  321. $nbComments = $project->getNbComments();
  322. dol_setcache($cachekey, $nbComments, 120); // If setting cache fails, this is not a problem, so we do not test result.
  323. }
  324. $head[$h][0] = DOL_URL_ROOT.'/projet/comment.php?id='.$project->id;
  325. $head[$h][1] = $langs->trans("CommentLink");
  326. if ($nbComments > 0) {
  327. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbComments.'</span>';
  328. }
  329. $head[$h][2] = 'project_comment';
  330. $h++;
  331. }
  332. $head[$h][0] = DOL_URL_ROOT.'/projet/messaging.php?id='.$project->id;
  333. $head[$h][1] = $langs->trans("Events");
  334. if (isModEnabled('agenda') && ($user->hasRight('agenda', 'myactions', 'read') || $user->hasRight('agenda', 'allactions', 'read'))) {
  335. $head[$h][1] .= '/';
  336. $head[$h][1] .= $langs->trans("Agenda");
  337. }
  338. $head[$h][2] = 'agenda';
  339. $h++;
  340. complete_head_from_modules($conf, $langs, $project, $head, $h, 'project', 'add', 'external');
  341. complete_head_from_modules($conf, $langs, $project, $head, $h, 'project', 'remove');
  342. return $head;
  343. }
  344. /**
  345. * Prepare array with list of tabs
  346. *
  347. * @param Object $object Object related to tabs
  348. * @return array Array of tabs to show
  349. */
  350. function task_prepare_head($object)
  351. {
  352. global $db, $langs, $conf, $user;
  353. $h = 0;
  354. $head = array();
  355. $head[$h][0] = DOL_URL_ROOT.'/projet/tasks/task.php?id='.$object->id.(GETPOST('withproject') ? '&withproject=1' : '');
  356. $head[$h][1] = $langs->trans("Task");
  357. $head[$h][2] = 'task_task';
  358. $h++;
  359. $nbContact = count($object->liste_contact(-1, 'internal')) + count($object->liste_contact(-1, 'external'));
  360. $head[$h][0] = DOL_URL_ROOT.'/projet/tasks/contact.php?id='.$object->id.(GETPOST('withproject') ? '&withproject=1' : '');
  361. $head[$h][1] = $langs->trans("TaskRessourceLinks");
  362. if ($nbContact > 0) {
  363. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbContact.'</span>';
  364. }
  365. $head[$h][2] = 'task_contact';
  366. $h++;
  367. // Is there timespent ?
  368. $nbTimeSpent = 0;
  369. $sql = "SELECT t.rowid";
  370. //$sql .= " FROM ".MAIN_DB_PREFIX."element_time as t, ".MAIN_DB_PREFIX."projet_task as pt, ".MAIN_DB_PREFIX."user as u";
  371. //$sql .= " WHERE t.fk_user = u.rowid AND t.fk_task = pt.rowid";
  372. $sql .= " FROM ".MAIN_DB_PREFIX."element_time as t";
  373. $sql .= " WHERE t.elementtype='task' AND t.fk_element = ".((int) $object->id);
  374. $resql = $db->query($sql);
  375. if ($resql) {
  376. $obj = $db->fetch_object($resql);
  377. if ($obj) {
  378. $nbTimeSpent = 1;
  379. }
  380. } else {
  381. dol_print_error($db);
  382. }
  383. $head[$h][0] = DOL_URL_ROOT.'/projet/tasks/time.php?id='.urlencode($object->id).(GETPOST('withproject') ? '&withproject=1' : '');
  384. $head[$h][1] = $langs->trans("TimeSpent");
  385. if ($nbTimeSpent > 0) {
  386. $head[$h][1] .= '<span class="badge marginleftonlyshort">...</span>';
  387. }
  388. $head[$h][2] = 'task_time';
  389. $h++;
  390. // Show more tabs from modules
  391. // Entries must be declared in modules descriptor with line
  392. // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
  393. // $this->tabs = array('entity:-tabname); to remove a tab
  394. complete_head_from_modules($conf, $langs, $object, $head, $h, 'task', 'add', 'core');
  395. if (!getDolGlobalString('MAIN_DISABLE_NOTES_TAB')) {
  396. $nbNote = 0;
  397. if (!empty($object->note_private)) {
  398. $nbNote++;
  399. }
  400. if (!empty($object->note_public)) {
  401. $nbNote++;
  402. }
  403. $head[$h][0] = DOL_URL_ROOT.'/projet/tasks/note.php?id='.urlencode($object->id).(GETPOST('withproject') ? '&withproject=1' : '');
  404. $head[$h][1] = $langs->trans('Notes');
  405. if ($nbNote > 0) {
  406. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbNote.'</span>';
  407. }
  408. $head[$h][2] = 'task_notes';
  409. $h++;
  410. }
  411. $head[$h][0] = DOL_URL_ROOT.'/projet/tasks/document.php?id='.$object->id.(GETPOST('withproject') ? '&withproject=1' : '');
  412. $filesdir = $conf->project->multidir_output[$object->entity]."/".dol_sanitizeFileName($object->project->ref).'/'.dol_sanitizeFileName($object->ref);
  413. include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  414. include_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
  415. $nbFiles = count(dol_dir_list($filesdir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
  416. $nbLinks = Link::count($db, $object->element, $object->id);
  417. $head[$h][1] = $langs->trans('Documents');
  418. if (($nbFiles + $nbLinks) > 0) {
  419. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.($nbFiles + $nbLinks).'</span>';
  420. }
  421. $head[$h][2] = 'task_document';
  422. $h++;
  423. // Manage discussion
  424. if (getDolGlobalString('PROJECT_ALLOW_COMMENT_ON_TASK')) {
  425. $nbComments = $object->getNbComments();
  426. $head[$h][0] = DOL_URL_ROOT.'/projet/tasks/comment.php?id='.$object->id.(GETPOST('withproject') ? '&withproject=1' : '');
  427. $head[$h][1] = $langs->trans("CommentLink");
  428. if ($nbComments > 0) {
  429. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbComments.'</span>';
  430. }
  431. $head[$h][2] = 'task_comment';
  432. $h++;
  433. }
  434. complete_head_from_modules($conf, $langs, $object, $head, $h, 'task', 'add', 'external');
  435. complete_head_from_modules($conf, $langs, $object, $head, $h, 'task', 'remove');
  436. return $head;
  437. }
  438. /**
  439. * Prepare array with list of tabs
  440. *
  441. * @param string $mode Mode
  442. * @param string $fuser Filter on user
  443. * @return array Array of tabs to show
  444. */
  445. function project_timesheet_prepare_head($mode, $fuser = null)
  446. {
  447. global $langs, $conf, $user;
  448. $h = 0;
  449. $head = array();
  450. $h = 0;
  451. $param = '';
  452. $param .= ($mode ? '&mode='.$mode : '');
  453. if (is_object($fuser) && $fuser->id > 0 && $fuser->id != $user->id) {
  454. $param .= '&search_usertoprocessid='.$fuser->id;
  455. }
  456. if (!getDolGlobalString('PROJECT_DISABLE_TIMESHEET_PERMONTH')) {
  457. $head[$h][0] = DOL_URL_ROOT."/projet/activity/permonth.php".($param ? '?'.$param : '');
  458. $head[$h][1] = $langs->trans("InputPerMonth");
  459. $head[$h][2] = 'inputpermonth';
  460. $h++;
  461. }
  462. if (!getDolGlobalString('PROJECT_DISABLE_TIMESHEET_PERWEEK')) {
  463. $head[$h][0] = DOL_URL_ROOT."/projet/activity/perweek.php".($param ? '?'.$param : '');
  464. $head[$h][1] = $langs->trans("InputPerWeek");
  465. $head[$h][2] = 'inputperweek';
  466. $h++;
  467. }
  468. if (!getDolGlobalString('PROJECT_DISABLE_TIMESHEET_PERTIME')) {
  469. $head[$h][0] = DOL_URL_ROOT."/projet/activity/perday.php".($param ? '?'.$param : '');
  470. $head[$h][1] = $langs->trans("InputPerDay");
  471. $head[$h][2] = 'inputperday';
  472. $h++;
  473. }
  474. complete_head_from_modules($conf, $langs, null, $head, $h, 'project_timesheet');
  475. complete_head_from_modules($conf, $langs, null, $head, $h, 'project_timesheet', 'remove');
  476. return $head;
  477. }
  478. /**
  479. * Prepare array with list of tabs
  480. *
  481. * @return array Array of tabs to show
  482. */
  483. function project_admin_prepare_head()
  484. {
  485. global $langs, $conf, $user, $db;
  486. $extrafields = new ExtraFields($db);
  487. $extrafields->fetch_name_optionals_label('projet');
  488. $extrafields->fetch_name_optionals_label('projet_task');
  489. $h = 0;
  490. $head = array();
  491. $head[$h][0] = DOL_URL_ROOT."/projet/admin/project.php";
  492. $head[$h][1] = $langs->trans("Projects");
  493. $head[$h][2] = 'project';
  494. $h++;
  495. complete_head_from_modules($conf, $langs, null, $head, $h, 'project_admin');
  496. $head[$h][0] = DOL_URL_ROOT."/projet/admin/project_extrafields.php";
  497. $head[$h][1] = $langs->trans("ExtraFieldsProject");
  498. $nbExtrafields = $extrafields->attributes['projet']['count'];
  499. if ($nbExtrafields > 0) {
  500. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
  501. }
  502. $head[$h][2] = 'attributes';
  503. $h++;
  504. $head[$h][0] = DOL_URL_ROOT.'/projet/admin/project_task_extrafields.php';
  505. $head[$h][1] = $langs->trans("ExtraFieldsProjectTask");
  506. $nbExtrafields = $extrafields->attributes['projet_task']['count'];
  507. if ($nbExtrafields > 0) {
  508. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
  509. }
  510. $head[$h][2] = 'attributes_task';
  511. $h++;
  512. if (getDolGlobalString('PROJECT_USE_OPPORTUNITIES')) {
  513. $langs->load("members");
  514. $head[$h][0] = DOL_URL_ROOT.'/projet/admin/website.php';
  515. $head[$h][1] = $langs->trans("BlankSubscriptionForm");
  516. $head[$h][2] = 'website';
  517. $h++;
  518. }
  519. complete_head_from_modules($conf, $langs, null, $head, $h, 'project_admin', 'remove');
  520. return $head;
  521. }
  522. /**
  523. * Show task lines with a particular parent
  524. *
  525. * @param string $inc Line number (start to 0, then increased by recursive call)
  526. * @param string $parent Id of parent task to show (0 to show all)
  527. * @param Task[] $lines Array of lines
  528. * @param int $level Level (start to 0, then increased/decrease by recursive call), or -1 to show all level in order of $lines without the recursive groupment feature.
  529. * @param string $var Color
  530. * @param int $showproject Show project columns
  531. * @param int $taskrole Array of roles of user for each tasks
  532. * @param int $projectsListId List of id of project allowed to user (string separated with comma)
  533. * @param int $addordertick Add a tick to move task
  534. * @param int $projectidfortotallink 0 or Id of project to use on total line (link to see all time consumed for project)
  535. * @param string $dummy Not used.
  536. * @param string $showbilltime Add the column 'TimeToBill' and 'TimeBilled'
  537. * @param array $arrayfields Array with displayed coloumn information
  538. * @param array $arrayofselected Array with selected fields
  539. * @return int Nb of tasks shown
  540. */
  541. function projectLinesa(&$inc, $parent, &$lines, &$level, $var, $showproject, &$taskrole, $projectsListId = '', $addordertick = 0, $projectidfortotallink = 0, $dummy = '', $showbilltime = 0, $arrayfields = array(), $arrayofselected = array())
  542. {
  543. global $user, $langs, $conf, $db, $hookmanager;
  544. global $projectstatic, $taskstatic, $extrafields;
  545. $lastprojectid = 0;
  546. $projectsArrayId = explode(',', $projectsListId);
  547. $numlines = count($lines);
  548. // We declare counter as global because we want to edit them into recursive call
  549. global $total_projectlinesa_spent, $total_projectlinesa_planned, $total_projectlinesa_spent_if_planned, $total_projectlinesa_declared_if_planned, $total_projectlinesa_tobill, $total_projectlinesa_billed, $total_budget_amount;
  550. global $totalarray;
  551. if ($level == 0) {
  552. $total_projectlinesa_spent = 0;
  553. $total_projectlinesa_planned = 0;
  554. $total_projectlinesa_spent_if_planned = 0;
  555. $total_projectlinesa_declared_if_planned = 0;
  556. $total_projectlinesa_tobill = 0;
  557. $total_projectlinesa_billed = 0;
  558. $total_budget_amount = 0;
  559. $totalarray = array();
  560. }
  561. for ($i = 0; $i < $numlines; $i++) {
  562. if ($parent == 0 && $level >= 0) {
  563. $level = 0; // if $level = -1, we dont' use sublevel recursion, we show all lines
  564. }
  565. // Process line
  566. // print "i:".$i."-".$lines[$i]->fk_project.'<br>';
  567. if ($lines[$i]->fk_task_parent == $parent || $level < 0) { // if $level = -1, we dont' use sublevel recursion, we show all lines
  568. // Show task line.
  569. $showline = 1;
  570. $showlineingray = 0;
  571. // If there is filters to use
  572. if (is_array($taskrole)) {
  573. // If task not legitimate to show, search if a legitimate task exists later in tree
  574. if (!isset($taskrole[$lines[$i]->id]) && $lines[$i]->id != $lines[$i]->fk_task_parent) {
  575. // So search if task has a subtask legitimate to show
  576. $foundtaskforuserdeeper = 0;
  577. searchTaskInChild($foundtaskforuserdeeper, $lines[$i]->id, $lines, $taskrole);
  578. //print '$foundtaskforuserpeeper='.$foundtaskforuserdeeper.'<br>';
  579. if ($foundtaskforuserdeeper > 0) {
  580. $showlineingray = 1; // We will show line but in gray
  581. } else {
  582. $showline = 0; // No reason to show line
  583. }
  584. }
  585. } else {
  586. // Caller did not ask to filter on tasks of a specific user (this probably means he want also tasks of all users, into public project
  587. // or into all other projects if user has permission to).
  588. if (!$user->hasRight('projet', 'all', 'lire')) {
  589. // User is not allowed on this project and project is not public, so we hide line
  590. if (!in_array($lines[$i]->fk_project, $projectsArrayId)) {
  591. // Note that having a user assigned to a task into a project user has no permission on, should not be possible
  592. // because assignement on task can be done only on contact of project.
  593. // If assignement was done and after, was removed from contact of project, then we can hide the line.
  594. $showline = 0;
  595. }
  596. }
  597. }
  598. if ($showline) {
  599. // Break on a new project
  600. if ($parent == 0 && $lines[$i]->fk_project != $lastprojectid) {
  601. $var = !$var;
  602. $lastprojectid = $lines[$i]->fk_project;
  603. }
  604. print '<tr class="oddeven" id="row-'.$lines[$i]->id.'">'."\n";
  605. $projectstatic->id = $lines[$i]->fk_project;
  606. $projectstatic->ref = $lines[$i]->projectref;
  607. $projectstatic->public = $lines[$i]->public;
  608. $projectstatic->title = $lines[$i]->projectlabel;
  609. $projectstatic->usage_bill_time = $lines[$i]->usage_bill_time;
  610. $projectstatic->status = $lines[$i]->projectstatus;
  611. $taskstatic->id = $lines[$i]->id;
  612. $taskstatic->ref = $lines[$i]->ref;
  613. $taskstatic->label = (!empty($taskrole[$lines[$i]->id]) ? $langs->trans("YourRole").': '.$taskrole[$lines[$i]->id] : '');
  614. $taskstatic->projectstatus = $lines[$i]->projectstatus;
  615. $taskstatic->progress = $lines[$i]->progress;
  616. $taskstatic->fk_statut = $lines[$i]->status;
  617. $taskstatic->date_start = $lines[$i]->date_start;
  618. $taskstatic->date_end = $lines[$i]->date_end;
  619. $taskstatic->datee = $lines[$i]->date_end; // deprecated
  620. $taskstatic->planned_workload = $lines[$i]->planned_workload;
  621. $taskstatic->duration_effective = $lines[$i]->duration_effective;
  622. $taskstatic->budget_amount = $lines[$i]->budget_amount;
  623. // Action column
  624. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  625. print '<td class="nowrap center">';
  626. $selected = 0;
  627. if (in_array($lines[$i]->id, $arrayofselected)) {
  628. $selected = 1;
  629. }
  630. print '<input id="cb' . $lines[$i]->id . '" class="flat checkforselect" type="checkbox" name="toselect[]" value="' . $lines[$i]->id . '"' . ($selected ? ' checked="checked"' : '') . '>';
  631. print '</td>';
  632. }
  633. if ($showproject) {
  634. // Project ref
  635. print '<td class="nowraponall">';
  636. //if ($showlineingray) print '<i>';
  637. if ($lines[$i]->public || in_array($lines[$i]->fk_project, $projectsArrayId) || $user->hasRight('projet', 'all', 'lire')) {
  638. print $projectstatic->getNomUrl(1);
  639. } else {
  640. print $projectstatic->getNomUrl(1, 'nolink');
  641. }
  642. //if ($showlineingray) print '</i>';
  643. print "</td>";
  644. // Project status
  645. print '<td>';
  646. $projectstatic->statut = $lines[$i]->projectstatus;
  647. print $projectstatic->getLibStatut(2);
  648. print "</td>";
  649. }
  650. // Ref of task
  651. if (count($arrayfields) > 0 && !empty($arrayfields['t.ref']['checked'])) {
  652. print '<td class="nowraponall">';
  653. if ($showlineingray) {
  654. print '<i>'.img_object('', 'projecttask').' '.$lines[$i]->ref.'</i>';
  655. } else {
  656. print $taskstatic->getNomUrl(1, 'withproject');
  657. }
  658. print '</td>';
  659. }
  660. // Title of task
  661. if (count($arrayfields) > 0 && !empty($arrayfields['t.label']['checked'])) {
  662. $labeltoshow = '';
  663. if ($showlineingray) {
  664. $labeltoshow .= '<i>';
  665. }
  666. //else print '<a href="'.DOL_URL_ROOT.'/projet/tasks/task.php?id='.$lines[$i]->id.'&withproject=1">';
  667. for ($k = 0; $k < $level; $k++) {
  668. $labeltoshow .= '<div class="marginleftonly">';
  669. }
  670. $labeltoshow .= dol_escape_htmltag($lines[$i]->label);
  671. for ($k = 0; $k < $level; $k++) {
  672. $labeltoshow .= '</div>';
  673. }
  674. if ($showlineingray) {
  675. $labeltoshow .= '</i>';
  676. }
  677. print '<td class="tdoverflowmax200" title="'.dol_escape_htmltag($labeltoshow).'">';
  678. print $labeltoshow;
  679. print "</td>\n";
  680. }
  681. if (count($arrayfields) > 0 && !empty($arrayfields['t.description']['checked'])) {
  682. print '<td class="tdoverflowmax200" title="'.dol_escape_htmltag($lines[$i]->description).'">';
  683. print $lines[$i]->description;
  684. print "</td>\n";
  685. }
  686. // Date start
  687. if (count($arrayfields) > 0 && !empty($arrayfields['t.dateo']['checked'])) {
  688. print '<td class="center nowraponall">';
  689. print dol_print_date($lines[$i]->date_start, 'dayhour');
  690. print '</td>';
  691. }
  692. // Date end
  693. if (count($arrayfields) > 0 && !empty($arrayfields['t.datee']['checked'])) {
  694. print '<td class="center nowraponall">';
  695. print dol_print_date($lines[$i]->date_end, 'dayhour');
  696. if ($taskstatic->hasDelay()) {
  697. print img_warning($langs->trans("Late"));
  698. }
  699. print '</td>';
  700. }
  701. $plannedworkloadoutputformat = 'allhourmin';
  702. $timespentoutputformat = 'allhourmin';
  703. if (getDolGlobalString('PROJECT_PLANNED_WORKLOAD_FORMAT')) {
  704. $plannedworkloadoutputformat = $conf->global->PROJECT_PLANNED_WORKLOAD_FORMAT;
  705. }
  706. if (getDolGlobalString('PROJECT_TIMES_SPENT_FORMAT')) {
  707. $timespentoutputformat = $conf->global->PROJECT_TIME_SPENT_FORMAT;
  708. }
  709. // Planned Workload (in working hours)
  710. if (count($arrayfields) > 0 && !empty($arrayfields['t.planned_workload']['checked'])) {
  711. print '<td class="right">';
  712. $fullhour = convertSecondToTime($lines[$i]->planned_workload, $plannedworkloadoutputformat);
  713. $workingdelay = convertSecondToTime($lines[$i]->planned_workload, 'all', 86400, 7); // TODO Replace 86400 and 7 to take account working hours per day and working day per weeks
  714. if ($lines[$i]->planned_workload != '') {
  715. print $fullhour;
  716. // TODO Add delay taking account of working hours per day and working day per week
  717. //if ($workingdelay != $fullhour) print '<br>('.$workingdelay.')';
  718. }
  719. //else print '--:--';
  720. print '</td>';
  721. }
  722. // Time spent
  723. if (count($arrayfields) > 0 && !empty($arrayfields['t.duration_effective']['checked'])) {
  724. print '<td class="right">';
  725. if ($showlineingray) {
  726. print '<i>';
  727. } else {
  728. print '<a href="'.DOL_URL_ROOT.'/projet/tasks/time.php?id='.$lines[$i]->id.($showproject ? '' : '&withproject=1').'">';
  729. }
  730. if ($lines[$i]->duration_effective) {
  731. print convertSecondToTime($lines[$i]->duration_effective, $timespentoutputformat);
  732. } else {
  733. print '--:--';
  734. }
  735. if ($showlineingray) {
  736. print '</i>';
  737. } else {
  738. print '</a>';
  739. }
  740. print '</td>';
  741. }
  742. // Progress calculated (Note: ->duration_effective is time spent)
  743. if (count($arrayfields) > 0 && !empty($arrayfields['t.progress_calculated']['checked'])) {
  744. $s = '';
  745. $shtml = '';
  746. if ($lines[$i]->planned_workload || $lines[$i]->duration_effective) {
  747. if ($lines[$i]->planned_workload) {
  748. $s = round(100 * $lines[$i]->duration_effective / $lines[$i]->planned_workload, 2).' %';
  749. $shtml = $s;
  750. } else {
  751. $s = $langs->trans('WorkloadNotDefined');
  752. $shtml = '<span class="opacitymedium">'.$s.'</span>';
  753. }
  754. }
  755. print '<td class="right tdoverflowmax100" title="'.dol_escape_htmltag($s).'">';
  756. print $shtml;
  757. print '</td>';
  758. }
  759. // Progress declared
  760. if (count($arrayfields) > 0 && !empty($arrayfields['t.progress']['checked'])) {
  761. print '<td class="right">';
  762. if ($lines[$i]->progress != '') {
  763. print getTaskProgressBadge($taskstatic);
  764. }
  765. print '</td>';
  766. }
  767. // resume
  768. if (count($arrayfields) > 0 && !empty($arrayfields['t.progress_summary']['checked'])) {
  769. print '<td class="right">';
  770. if ($lines[$i]->progress != '' && $lines[$i]->duration_effective) {
  771. print getTaskProgressView($taskstatic, false, false);
  772. }
  773. print '</td>';
  774. }
  775. if ($showbilltime) {
  776. // Time not billed
  777. if (count($arrayfields) > 0 && !empty($arrayfields['t.tobill']['checked'])) {
  778. print '<td class="right">';
  779. if ($lines[$i]->usage_bill_time) {
  780. print convertSecondToTime($lines[$i]->tobill, 'allhourmin');
  781. $total_projectlinesa_tobill += $lines[$i]->tobill;
  782. } else {
  783. print '<span class="opacitymedium">'.$langs->trans("NA").'</span>';
  784. }
  785. print '</td>';
  786. }
  787. // Time billed
  788. if (count($arrayfields) > 0 && !empty($arrayfields['t.billed']['checked'])) {
  789. print '<td class="right">';
  790. if ($lines[$i]->usage_bill_time) {
  791. print convertSecondToTime($lines[$i]->billed, 'allhourmin');
  792. $total_projectlinesa_billed += $lines[$i]->billed;
  793. } else {
  794. print '<span class="opacitymedium">'.$langs->trans("NA").'</span>';
  795. }
  796. print '</td>';
  797. }
  798. }
  799. // Budget task
  800. if (count($arrayfields) > 0 && !empty($arrayfields['t.budget_amount']['checked'])) {
  801. print '<td class="center">';
  802. if ($lines[$i]->budget_amount) {
  803. print '<span class="amount">'.price($lines[$i]->budget_amount, 0, $langs, 1, 0, 0, $conf->currency).'</span>';
  804. $total_budget_amount += $lines[$i]->budget_amount;
  805. }
  806. print '</td>';
  807. }
  808. // Contacts of task
  809. if (count($arrayfields) > 0 && !empty($arrayfields['c.assigned']['checked'])) {
  810. print '<td class="center">';
  811. $ifisrt = 1;
  812. foreach (array('internal', 'external') as $source) {
  813. //$tab = $lines[$i]->liste_contact(-1, $source);
  814. $tab = $lines[$i]->liste_contact(-1, $source, 0, '', 1);
  815. $numcontact = count($tab);
  816. if (!empty($numcontact)) {
  817. foreach ($tab as $contacttask) {
  818. //var_dump($contacttask);
  819. if ($source == 'internal') {
  820. $c = new User($db);
  821. } else {
  822. $c = new Contact($db);
  823. }
  824. $c->fetch($contacttask['id']);
  825. if (!empty($c->photo)) {
  826. if (get_class($c) == 'User') {
  827. print $c->getNomUrl(-2, '', 0, 0, 24, 1, '', ($ifisrt ? '' : 'notfirst'));
  828. } else {
  829. print $c->getNomUrl(-2, '', 0, '', -1, 0, ($ifisrt ? '' : 'notfirst'));
  830. }
  831. } else {
  832. if (get_class($c) == 'User') {
  833. print $c->getNomUrl(2, '', 0, 0, 24, 1, '', ($ifisrt ? '' : 'notfirst'));
  834. } else {
  835. print $c->getNomUrl(2, '', 0, '', -1, 0, ($ifisrt ? '' : 'notfirst'));
  836. }
  837. }
  838. $ifisrt = 0;
  839. }
  840. }
  841. }
  842. print '</td>';
  843. }
  844. // Extra fields
  845. $extrafieldsobjectkey = $taskstatic->table_element;
  846. $extrafieldsobjectprefix = 'efpt.';
  847. $obj = $lines[$i]->obj;
  848. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  849. // Fields from hook
  850. $parameters = array('arrayfields'=>$arrayfields, 'obj'=>$lines[$i]);
  851. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook
  852. print $hookmanager->resPrint;
  853. // Tick to drag and drop
  854. print '<td class="tdlineupdown center"></td>';
  855. // Action column
  856. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  857. print '<td class="nowrap center">';
  858. $selected = 0;
  859. if (in_array($lines[$i]->id, $arrayofselected)) {
  860. $selected = 1;
  861. }
  862. print '<input id="cb' . $lines[$i]->id . '" class="flat checkforselect" type="checkbox" name="toselect[]" value="' . $lines[$i]->id . '"' . ($selected ? ' checked="checked"' : '') . '>';
  863. print '</td>';
  864. }
  865. print "</tr>\n";
  866. if (!$showlineingray) {
  867. $inc++;
  868. }
  869. if ($level >= 0) { // Call sublevels
  870. $level++;
  871. if ($lines[$i]->id) {
  872. projectLinesa($inc, $lines[$i]->id, $lines, $level, $var, $showproject, $taskrole, $projectsListId, $addordertick, $projectidfortotallink, '', $showbilltime, $arrayfields);
  873. }
  874. $level--;
  875. }
  876. $total_projectlinesa_spent += $lines[$i]->duration_effective;
  877. $total_projectlinesa_planned += $lines[$i]->planned_workload;
  878. if ($lines[$i]->planned_workload) {
  879. $total_projectlinesa_spent_if_planned += $lines[$i]->duration_effective;
  880. }
  881. if ($lines[$i]->planned_workload) {
  882. $total_projectlinesa_declared_if_planned += $lines[$i]->planned_workload * $lines[$i]->progress / 100;
  883. }
  884. }
  885. } else {
  886. //$level--;
  887. }
  888. }
  889. // Total line
  890. if (($total_projectlinesa_planned > 0 || $total_projectlinesa_spent > 0 || $total_projectlinesa_tobill > 0 || $total_projectlinesa_billed > 0 || $total_budget_amount > 0)
  891. && $level <= 0) {
  892. print '<tr class="liste_total nodrag nodrop">';
  893. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  894. print '<td class="liste_total"></td>';
  895. }
  896. print '<td class="liste_total">'.$langs->trans("Total").'</td>';
  897. if ($showproject) {
  898. print '<td></td><td></td>';
  899. }
  900. if (count($arrayfields) > 0 && !empty($arrayfields['t.label']['checked'])) {
  901. print '<td></td>';
  902. }
  903. if (count($arrayfields) > 0 && !empty($arrayfields['t.description']['checked'])) {
  904. print '<td></td>';
  905. }
  906. if (count($arrayfields) > 0 && !empty($arrayfields['t.dateo']['checked'])) {
  907. print '<td></td>';
  908. }
  909. if (count($arrayfields) > 0 && !empty($arrayfields['t.datee']['checked'])) {
  910. print '<td></td>';
  911. }
  912. if (count($arrayfields) > 0 && !empty($arrayfields['t.planned_workload']['checked'])) {
  913. print '<td class="nowrap liste_total right">';
  914. print convertSecondToTime($total_projectlinesa_planned, 'allhourmin');
  915. print '</td>';
  916. }
  917. if (count($arrayfields) > 0 && !empty($arrayfields['t.duration_effective']['checked'])) {
  918. print '<td class="nowrap liste_total right">';
  919. if ($projectidfortotallink > 0) {
  920. print '<a href="'.DOL_URL_ROOT.'/projet/tasks/time.php?projectid='.$projectidfortotallink.($showproject ? '' : '&withproject=1').'">';
  921. }
  922. print convertSecondToTime($total_projectlinesa_spent, 'allhourmin');
  923. if ($projectidfortotallink > 0) {
  924. print '</a>';
  925. }
  926. print '</td>';
  927. }
  928. if ($total_projectlinesa_planned) {
  929. $totalAverageDeclaredProgress = round(100 * $total_projectlinesa_declared_if_planned / $total_projectlinesa_planned, 2);
  930. $totalCalculatedProgress = round(100 * $total_projectlinesa_spent / $total_projectlinesa_planned, 2);
  931. // this conf is actually hidden, by default we use 10% for "be carefull or warning"
  932. $warningRatio = getDolGlobalString('PROJECT_TIME_SPEND_WARNING_PERCENT') ? (1 + $conf->global->PROJECT_TIME_SPEND_WARNING_PERCENT / 100) : 1.10;
  933. // define progress color according to time spend vs workload
  934. $progressBarClass = 'progress-bar-info';
  935. $badgeClass = 'badge ';
  936. if ($totalCalculatedProgress > $totalAverageDeclaredProgress) {
  937. $progressBarClass = 'progress-bar-danger';
  938. $badgeClass .= 'badge-danger';
  939. } elseif ($totalCalculatedProgress * $warningRatio >= $totalAverageDeclaredProgress) { // warning if close at 1%
  940. $progressBarClass = 'progress-bar-warning';
  941. $badgeClass .= 'badge-warning';
  942. } else {
  943. $progressBarClass = 'progress-bar-success';
  944. $badgeClass .= 'badge-success';
  945. }
  946. }
  947. // Computed progress
  948. if (count($arrayfields) > 0 && !empty($arrayfields['t.progress_calculated']['checked'])) {
  949. print '<td class="nowrap liste_total right">';
  950. if ($total_projectlinesa_planned) {
  951. print $totalCalculatedProgress.' %';
  952. }
  953. print '</td>';
  954. }
  955. // Declared progress
  956. if (count($arrayfields) > 0 && !empty($arrayfields['t.progress']['checked'])) {
  957. print '<td class="nowrap liste_total right">';
  958. if ($total_projectlinesa_planned) {
  959. print '<span class="'.$badgeClass.'" >'.$totalAverageDeclaredProgress.' %</span>';
  960. }
  961. print '</td>';
  962. }
  963. // Progress
  964. if (count($arrayfields) > 0 && !empty($arrayfields['t.progress_summary']['checked'])) {
  965. print '<td class="right">';
  966. if ($total_projectlinesa_planned) {
  967. print '</span>';
  968. print ' <div class="progress sm" title="'.$totalAverageDeclaredProgress.'%" >';
  969. print ' <div class="progress-bar '.$progressBarClass.'" style="width: '.$totalAverageDeclaredProgress.'%"></div>';
  970. print ' </div>';
  971. print '</div>';
  972. }
  973. print '</td>';
  974. }
  975. if ($showbilltime) {
  976. if (count($arrayfields) > 0 && !empty($arrayfields['t.tobill']['checked'])) {
  977. print '<td class="nowrap liste_total right">';
  978. print convertSecondToTime($total_projectlinesa_tobill, 'allhourmin');
  979. print '</td>';
  980. }
  981. if (count($arrayfields) > 0 && !empty($arrayfields['t.billed']['checked'])) {
  982. print '<td class="nowrap liste_total right">';
  983. print convertSecondToTime($total_projectlinesa_billed, 'allhourmin');
  984. print '</td>';
  985. }
  986. }
  987. // Budget task
  988. if (count($arrayfields) > 0 && !empty($arrayfields['t.budget_amount']['checked'])) {
  989. print '<td class="nowrap liste_total center">';
  990. if (strcmp($total_budget_amount, '')) {
  991. print price($total_budget_amount, 0, $langs, 1, 0, 0, $conf->currency);
  992. }
  993. print '</td>';
  994. }
  995. // Contacts of task for backward compatibility,
  996. if (getDolGlobalString('PROJECT_SHOW_CONTACTS_IN_LIST')) {
  997. print '<td></td>';
  998. }
  999. // Contacts of task
  1000. if (count($arrayfields) > 0 && !empty($arrayfields['c.assigned']['checked'])) {
  1001. print '<td></td>';
  1002. }
  1003. // Check if Extrafields is totalizable
  1004. if (!empty($extrafields->attributes['projet_task']['totalizable'])) {
  1005. foreach ($extrafields->attributes['projet_task']['totalizable'] as $key => $value) {
  1006. if (!empty($arrayfields['efpt.'.$key]['checked']) && $arrayfields['ef.'.$key]['checked'] == 1) {
  1007. print '<td class="right">';
  1008. if ($value == 1) {
  1009. print empty($totalarray['totalizable'][$key]['total']) ? '' : $totalarray['totalizable'][$key]['total'];
  1010. }
  1011. print '</td>';
  1012. }
  1013. }
  1014. }
  1015. // Column for the drag and drop
  1016. print '<td class="liste_total"></td>';
  1017. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  1018. print '<td class="liste_total"></td>';
  1019. }
  1020. print '</tr>';
  1021. }
  1022. return $inc;
  1023. }
  1024. /**
  1025. * Output a task line into a pertime intput mode
  1026. *
  1027. * @param string $inc Line number (start to 0, then increased by recursive call)
  1028. * @param string $parent Id of parent task to show (0 to show all)
  1029. * @param User|null $fuser Restrict list to user if defined
  1030. * @param Task[] $lines Array of lines
  1031. * @param int $level Level (start to 0, then increased/decrease by recursive call)
  1032. * @param string $projectsrole Array of roles user has on project
  1033. * @param string $tasksrole Array of roles user has on task
  1034. * @param string $mine Show only task lines I am assigned to
  1035. * @param int $restricteditformytask 0=No restriction, 1=Enable add time only if task is a task i am affected to
  1036. * @param int $preselectedday Preselected day
  1037. * @param array $isavailable Array with data that say if user is available for several days for morning and afternoon
  1038. * @param int $oldprojectforbreak Old project id of last project break
  1039. * @return array Array with time spent for $fuser for each day of week on tasks in $lines and substasks
  1040. */
  1041. function projectLinesPerAction(&$inc, $parent, $fuser, $lines, &$level, &$projectsrole, &$tasksrole, $mine, $restricteditformytask, $preselectedday, &$isavailable, $oldprojectforbreak = 0)
  1042. {
  1043. global $conf, $db, $user, $langs;
  1044. global $form, $formother, $projectstatic, $taskstatic, $thirdpartystatic;
  1045. $lastprojectid = 0;
  1046. $totalforeachline = array();
  1047. $workloadforid = array();
  1048. $lineswithoutlevel0 = array();
  1049. $numlines = count($lines);
  1050. // Create a smaller array with sublevels only to be used later. This increase dramatically performances.
  1051. if ($parent == 0) { // Always and only if at first level
  1052. for ($i = 0; $i < $numlines; $i++) {
  1053. if ($lines[$i]->fk_task_parent) {
  1054. $lineswithoutlevel0[] = $lines[$i];
  1055. }
  1056. }
  1057. }
  1058. if (empty($oldprojectforbreak)) {
  1059. $oldprojectforbreak = (!getDolGlobalString('PROJECT_TIMESHEET_DISABLEBREAK_ON_PROJECT') ? 0 : -1); // 0 to start break , -1 no break
  1060. }
  1061. //dol_syslog('projectLinesPerDay inc='.$inc.' preselectedday='.$preselectedday.' task parent id='.$parent.' level='.$level." count(lines)=".$numlines." count(lineswithoutlevel0)=".count($lineswithoutlevel0));
  1062. for ($i = 0; $i < $numlines; $i++) {
  1063. if ($parent == 0) {
  1064. $level = 0;
  1065. }
  1066. //if ($lines[$i]->fk_task_parent == $parent)
  1067. //{
  1068. // If we want all or we have a role on task, we show it
  1069. if (empty($mine) || !empty($tasksrole[$lines[$i]->id])) {
  1070. //dol_syslog("projectLinesPerWeek Found line ".$i.", a qualified task (i have role or want to show all tasks) with id=".$lines[$i]->id." project id=".$lines[$i]->fk_project);
  1071. // Break on a new project
  1072. if ($parent == 0 && $lines[$i]->fk_project != $lastprojectid) {
  1073. $lastprojectid = $lines[$i]->fk_project;
  1074. if ($preselectedday) {
  1075. $projectstatic->id = $lines[$i]->fk_project;
  1076. }
  1077. }
  1078. if (empty($workloadforid[$projectstatic->id])) {
  1079. if ($preselectedday) {
  1080. $projectstatic->loadTimeSpent($preselectedday, 0, $fuser->id); // Load time spent from table element_time for the project into this->weekWorkLoad and this->weekWorkLoadPerTask for all days of a week
  1081. $workloadforid[$projectstatic->id] = 1;
  1082. }
  1083. }
  1084. $projectstatic->id = $lines[$i]->fk_project;
  1085. $projectstatic->ref = $lines[$i]->project_ref;
  1086. $projectstatic->title = $lines[$i]->project_label;
  1087. $projectstatic->public = $lines[$i]->public;
  1088. $projectstatic->status = $lines[$i]->project->status;
  1089. $taskstatic->id = $lines[$i]->fk_statut;
  1090. $taskstatic->ref = ($lines[$i]->task_ref ? $lines[$i]->task_ref : $lines[$i]->task_id);
  1091. $taskstatic->label = $lines[$i]->task_label;
  1092. $taskstatic->date_start = $lines[$i]->date_start;
  1093. $taskstatic->date_end = $lines[$i]->date_end;
  1094. $thirdpartystatic->id = $lines[$i]->socid;
  1095. $thirdpartystatic->name = $lines[$i]->thirdparty_name;
  1096. $thirdpartystatic->email = $lines[$i]->thirdparty_email;
  1097. if (empty($oldprojectforbreak) || ($oldprojectforbreak != -1 && $oldprojectforbreak != $projectstatic->id)) {
  1098. print '<tr class="oddeven trforbreak nobold">'."\n";
  1099. print '<td colspan="11">';
  1100. print $projectstatic->getNomUrl(1, '', 0, $langs->transnoentitiesnoconv("YourRole").': '.$projectsrole[$lines[$i]->fk_project]);
  1101. if ($projectstatic->title) {
  1102. print ' - ';
  1103. print $projectstatic->title;
  1104. }
  1105. print '</td>';
  1106. print '</tr>';
  1107. }
  1108. if ($oldprojectforbreak != -1) {
  1109. $oldprojectforbreak = $projectstatic->id;
  1110. }
  1111. print '<tr class="oddeven">'."\n";
  1112. // User
  1113. /*
  1114. print '<td class="nowrap">';
  1115. print $fuser->getNomUrl(1, 'withproject', 'time');
  1116. print '</td>';
  1117. */
  1118. // Project
  1119. print "<td>";
  1120. if ($oldprojectforbreak == -1) {
  1121. print $projectstatic->getNomUrl(1, '', 0, $langs->transnoentitiesnoconv("YourRole").': '.$projectsrole[$lines[$i]->fk_project]);
  1122. print '<br>'.$projectstatic->title;
  1123. }
  1124. print "</td>";
  1125. // Thirdparty
  1126. print '<td class="tdoverflowmax100">';
  1127. if ($thirdpartystatic->id > 0) {
  1128. print $thirdpartystatic->getNomUrl(1, 'project', 10);
  1129. }
  1130. print '</td>';
  1131. // Ref
  1132. print '<td>';
  1133. print '<!-- Task id = '.$lines[$i]->id.' (projectlinesperaction) -->';
  1134. for ($k = 0; $k < $level; $k++) {
  1135. print '<div class="marginleftonly">';
  1136. }
  1137. print $taskstatic->getNomUrl(1, 'withproject', 'time');
  1138. // Label task
  1139. print '<br>';
  1140. print '<div class="opacitymedium tdoverflowmax500" title="'.dol_escape_htmltag($taskstatic->label).'">'.dol_escape_htmltag($taskstatic->label).'</div>';
  1141. for ($k = 0; $k < $level; $k++) {
  1142. print "</div>";
  1143. }
  1144. print "</td>\n";
  1145. // Date
  1146. print '<td class="center">';
  1147. print dol_print_date($lines[$i]->timespent_datehour, 'day');
  1148. print '</td>';
  1149. $disabledproject = 1;
  1150. $disabledtask = 1;
  1151. //print "x".$lines[$i]->fk_project;
  1152. //var_dump($lines[$i]);
  1153. //var_dump($projectsrole[$lines[$i]->fk_project]);
  1154. // If at least one role for project
  1155. if ($lines[$i]->public || !empty($projectsrole[$lines[$i]->fk_project]) || $user->hasRight('projet', 'all', 'creer')) {
  1156. $disabledproject = 0;
  1157. $disabledtask = 0;
  1158. }
  1159. // If $restricteditformytask is on and I have no role on task, i disable edit
  1160. if ($restricteditformytask && empty($tasksrole[$lines[$i]->id])) {
  1161. $disabledtask = 1;
  1162. }
  1163. // Hour
  1164. print '<td class="nowrap center">';
  1165. print dol_print_date($lines[$i]->timespent_datehour, 'hour');
  1166. print '</td>';
  1167. $cssonholiday = '';
  1168. if (!$isavailable[$preselectedday]['morning'] && !$isavailable[$preselectedday]['afternoon']) {
  1169. $cssonholiday .= 'onholidayallday ';
  1170. } elseif (!$isavailable[$preselectedday]['morning']) {
  1171. $cssonholiday .= 'onholidaymorning ';
  1172. } elseif (!$isavailable[$preselectedday]['afternoon']) {
  1173. $cssonholiday .= 'onholidayafternoon ';
  1174. }
  1175. // Duration
  1176. print '<td class="duration'.($cssonholiday ? ' '.$cssonholiday : '').' center">';
  1177. $dayWorkLoad = $lines[$i]->timespent_duration;
  1178. $totalforeachline[$preselectedday] += $lines[$i]->timespent_duration;
  1179. $alreadyspent = '';
  1180. if ($dayWorkLoad > 0) {
  1181. $alreadyspent = convertSecondToTime($lines[$i]->timespent_duration, 'allhourmin');
  1182. }
  1183. print convertSecondToTime($lines[$i]->timespent_duration, 'allhourmin');
  1184. print '</td>';
  1185. // Note
  1186. print '<td class="center">';
  1187. print '<textarea name="'.$lines[$i]->id.'note" rows="'.ROWS_2.'" id="'.$lines[$i]->id.'note"'.($disabledtask ? ' disabled="disabled"' : '').'>';
  1188. print $lines[$i]->timespent_note;
  1189. print '</textarea>';
  1190. print '</td>';
  1191. // Warning
  1192. print '<td class="right">';
  1193. /*if ((! $lines[$i]->public) && $disabledproject) print $form->textwithpicto('',$langs->trans("UserIsNotContactOfProject"));
  1194. elseif ($disabledtask)
  1195. {
  1196. $titleassigntask = $langs->trans("AssignTaskToMe");
  1197. if ($fuser->id != $user->id) $titleassigntask = $langs->trans("AssignTaskToUser", '...');
  1198. print $form->textwithpicto('',$langs->trans("TaskIsNotAssignedToUser", $titleassigntask));
  1199. }*/
  1200. print '</td>';
  1201. print "</tr>\n";
  1202. }
  1203. //}
  1204. //else
  1205. //{
  1206. //$level--;
  1207. //}
  1208. }
  1209. return $totalforeachline;
  1210. }
  1211. /**
  1212. * Output a task line into a pertime intput mode
  1213. *
  1214. * @param string $inc Line number (start to 0, then increased by recursive call)
  1215. * @param string $parent Id of parent task to show (0 to show all)
  1216. * @param User|null $fuser Restrict list to user if defined
  1217. * @param Task[] $lines Array of lines
  1218. * @param int $level Level (start to 0, then increased/decrease by recursive call)
  1219. * @param string $projectsrole Array of roles user has on project
  1220. * @param string $tasksrole Array of roles user has on task
  1221. * @param string $mine Show only task lines I am assigned to
  1222. * @param int $restricteditformytask 0=No restriction, 1=Enable add time only if task is assigned to me, 2=Enable add time only if tasks is assigned to me and hide others
  1223. * @param int $preselectedday Preselected day
  1224. * @param array $isavailable Array with data that say if user is available for several days for morning and afternoon
  1225. * @param int $oldprojectforbreak Old project id of last project break
  1226. * @param array $arrayfields Array of additional column
  1227. * @param Extrafields $extrafields Object extrafields
  1228. * @return array Array with time spent for $fuser for each day of week on tasks in $lines and substasks
  1229. */
  1230. function projectLinesPerDay(&$inc, $parent, $fuser, $lines, &$level, &$projectsrole, &$tasksrole, $mine, $restricteditformytask, $preselectedday, &$isavailable, $oldprojectforbreak = 0, $arrayfields = array(), $extrafields = null)
  1231. {
  1232. global $conf, $db, $user, $langs;
  1233. global $form, $formother, $projectstatic, $taskstatic, $thirdpartystatic;
  1234. $lastprojectid = 0;
  1235. $totalforeachday = array();
  1236. $workloadforid = array();
  1237. $lineswithoutlevel0 = array();
  1238. $numlines = count($lines);
  1239. // Create a smaller array with sublevels only to be used later. This increase dramatically performances.
  1240. if ($parent == 0) { // Always and only if at first level
  1241. for ($i = 0; $i < $numlines; $i++) {
  1242. if ($lines[$i]->fk_task_parent) {
  1243. $lineswithoutlevel0[] = $lines[$i];
  1244. }
  1245. }
  1246. }
  1247. if (empty($oldprojectforbreak)) {
  1248. $oldprojectforbreak = (!getDolGlobalString('PROJECT_TIMESHEET_DISABLEBREAK_ON_PROJECT') ? 0 : -1); // 0 to start break , -1 no break
  1249. }
  1250. $restrictBefore = null;
  1251. if (getDolGlobalString('PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS')) {
  1252. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  1253. $restrictBefore = dol_time_plus_duree(dol_now(), - $conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS, 'm');
  1254. }
  1255. //dol_syslog('projectLinesPerDay inc='.$inc.' preselectedday='.$preselectedday.' task parent id='.$parent.' level='.$level." count(lines)=".$numlines." count(lineswithoutlevel0)=".count($lineswithoutlevel0));
  1256. for ($i = 0; $i < $numlines; $i++) {
  1257. if ($parent == 0) {
  1258. $level = 0;
  1259. }
  1260. if ($lines[$i]->fk_task_parent == $parent) {
  1261. $obj = &$lines[$i]; // To display extrafields
  1262. // If we want all or we have a role on task, we show it
  1263. if (empty($mine) || !empty($tasksrole[$lines[$i]->id])) {
  1264. //dol_syslog("projectLinesPerWeek Found line ".$i.", a qualified task (i have role or want to show all tasks) with id=".$lines[$i]->id." project id=".$lines[$i]->fk_project);
  1265. if ($restricteditformytask == 2 && empty($tasksrole[$lines[$i]->id])) { // we have no role on task and we request to hide such cases
  1266. continue;
  1267. }
  1268. // Break on a new project
  1269. if ($parent == 0 && $lines[$i]->fk_project != $lastprojectid) {
  1270. $lastprojectid = $lines[$i]->fk_project;
  1271. if ($preselectedday) {
  1272. $projectstatic->id = $lines[$i]->fk_project;
  1273. }
  1274. }
  1275. if (empty($workloadforid[$projectstatic->id])) {
  1276. if ($preselectedday) {
  1277. $projectstatic->loadTimeSpent($preselectedday, 0, $fuser->id); // Load time spent from table element_time for the project into this->weekWorkLoad and this->weekWorkLoadPerTask for all days of a week
  1278. $workloadforid[$projectstatic->id] = 1;
  1279. }
  1280. }
  1281. $projectstatic->id = $lines[$i]->fk_project;
  1282. $projectstatic->ref = $lines[$i]->projectref;
  1283. $projectstatic->title = $lines[$i]->projectlabel;
  1284. $projectstatic->public = $lines[$i]->public;
  1285. $projectstatic->status = $lines[$i]->projectstatus;
  1286. $taskstatic->id = $lines[$i]->id;
  1287. $taskstatic->ref = ($lines[$i]->ref ? $lines[$i]->ref : $lines[$i]->id);
  1288. $taskstatic->label = $lines[$i]->label;
  1289. $taskstatic->date_start = $lines[$i]->date_start;
  1290. $taskstatic->date_end = $lines[$i]->date_end;
  1291. $thirdpartystatic->id = $lines[$i]->socid;
  1292. $thirdpartystatic->name = $lines[$i]->thirdparty_name;
  1293. $thirdpartystatic->email = $lines[$i]->thirdparty_email;
  1294. if (empty($oldprojectforbreak) || ($oldprojectforbreak != -1 && $oldprojectforbreak != $projectstatic->id)) {
  1295. $addcolspan = 0;
  1296. if (!empty($arrayfields['t.planned_workload']['checked'])) {
  1297. $addcolspan++;
  1298. }
  1299. if (!empty($arrayfields['t.progress']['checked'])) {
  1300. $addcolspan++;
  1301. }
  1302. foreach ($arrayfields as $key => $val) {
  1303. if ($val['checked'] && substr($key, 0, 5) == 'efpt.') {
  1304. $addcolspan++;
  1305. }
  1306. }
  1307. print '<tr class="oddeven trforbreak nobold">'."\n";
  1308. print '<td colspan="'.(7 + $addcolspan).'">';
  1309. print $projectstatic->getNomUrl(1, '', 0, '<strong>'.$langs->transnoentitiesnoconv("YourRole").':</strong> '.$projectsrole[$lines[$i]->fk_project]);
  1310. if ($thirdpartystatic->id > 0) {
  1311. print ' - '.$thirdpartystatic->getNomUrl(1);
  1312. }
  1313. if ($projectstatic->title) {
  1314. print ' - ';
  1315. print '<span class="secondary">'.$projectstatic->title.'</span>';
  1316. }
  1317. /*
  1318. $colspan=5+(empty($conf->global->PROJECT_TIMESHEET_DISABLEBREAK_ON_PROJECT)?0:2);
  1319. print '<table class="">';
  1320. print '<tr class="liste_titre">';
  1321. // PROJECT fields
  1322. if (!empty($arrayfields['p.fk_opp_status']['checked'])) print_liste_field_titre($arrayfields['p.fk_opp_status']['label'], $_SERVER["PHP_SELF"], 'p.fk_opp_status', "", $param, '', $sortfield, $sortorder, 'center ');
  1323. if (!empty($arrayfields['p.opp_amount']['checked'])) print_liste_field_titre($arrayfields['p.opp_amount']['label'], $_SERVER["PHP_SELF"], 'p.opp_amount', "", $param, '', $sortfield, $sortorder, 'right ');
  1324. if (!empty($arrayfields['p.opp_percent']['checked'])) print_liste_field_titre($arrayfields['p.opp_percent']['label'], $_SERVER["PHP_SELF"], 'p.opp_percent', "", $param, '', $sortfield, $sortorder, 'right ');
  1325. if (!empty($arrayfields['p.budget_amount']['checked'])) print_liste_field_titre($arrayfields['p.budget_amount']['label'], $_SERVER["PHP_SELF"], 'p.budget_amount', "", $param, '', $sortfield, $sortorder, 'right ');
  1326. if (!empty($arrayfields['p.usage_bill_time']['checked'])) print_liste_field_titre($arrayfields['p.usage_bill_time']['label'], $_SERVER["PHP_SELF"], 'p.usage_bill_time', "", $param, '', $sortfield, $sortorder, 'right ');
  1327. $extrafieldsobjectkey='projet';
  1328. $extrafieldsobjectprefix='efp.';
  1329. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  1330. print '</tr>';
  1331. print '<tr>';
  1332. // PROJECT fields
  1333. if (!empty($arrayfields['p.fk_opp_status']['checked']))
  1334. {
  1335. print '<td class="nowrap">';
  1336. $code = dol_getIdFromCode($db, $lines[$i]->fk_opp_status, 'c_lead_status', 'rowid', 'code');
  1337. if ($code) print $langs->trans("OppStatus".$code);
  1338. print "</td>\n";
  1339. }
  1340. if (!empty($arrayfields['p.opp_amount']['checked']))
  1341. {
  1342. print '<td class="nowrap">';
  1343. print price($lines[$i]->opp_amount, 0, $langs, 1, 0, -1, $conf->currency);
  1344. print "</td>\n";
  1345. }
  1346. if (!empty($arrayfields['p.opp_percent']['checked']))
  1347. {
  1348. print '<td class="nowrap">';
  1349. print price($lines[$i]->opp_percent, 0, $langs, 1, 0).' %';
  1350. print "</td>\n";
  1351. }
  1352. if (!empty($arrayfields['p.budget_amount']['checked']))
  1353. {
  1354. print '<td class="nowrap">';
  1355. print price($lines[$i]->budget_amount, 0, $langs, 1, 0, 0, $conf->currency);
  1356. print "</td>\n";
  1357. }
  1358. if (!empty($arrayfields['p.usage_bill_time']['checked']))
  1359. {
  1360. print '<td class="nowrap">';
  1361. print yn($lines[$i]->usage_bill_time);
  1362. print "</td>\n";
  1363. }
  1364. $extrafieldsobjectkey='projet';
  1365. $extrafieldsobjectprefix='efp.';
  1366. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  1367. print '</tr>';
  1368. print '</table>';
  1369. */
  1370. print '</td>';
  1371. print '</tr>';
  1372. }
  1373. if ($oldprojectforbreak != -1) {
  1374. $oldprojectforbreak = $projectstatic->id;
  1375. }
  1376. print '<tr class="oddeven" data-taskid="'.$lines[$i]->id.'">'."\n";
  1377. // User
  1378. /*
  1379. print '<td class="nowrap">';
  1380. print $fuser->getNomUrl(1, 'withproject', 'time');
  1381. print '</td>';
  1382. */
  1383. // Project
  1384. if (getDolGlobalString('PROJECT_TIMESHEET_DISABLEBREAK_ON_PROJECT')) {
  1385. print "<td>";
  1386. if ($oldprojectforbreak == -1) {
  1387. print $projectstatic->getNomUrl(1, '', 0, $langs->transnoentitiesnoconv("YourRole").': '.$projectsrole[$lines[$i]->fk_project]);
  1388. }
  1389. print "</td>";
  1390. }
  1391. // Thirdparty
  1392. if (getDolGlobalString('PROJECT_TIMESHEET_DISABLEBREAK_ON_PROJECT')) {
  1393. print '<td class="tdoverflowmax100">';
  1394. if ($thirdpartystatic->id > 0) {
  1395. print $thirdpartystatic->getNomUrl(1, 'project', 10);
  1396. }
  1397. print '</td>';
  1398. }
  1399. // Ref
  1400. print '<td>';
  1401. print '<!-- Task id = '.$lines[$i]->id.' (projectlinesperday) -->';
  1402. for ($k = 0; $k < $level; $k++) {
  1403. print '<div class="marginleftonly">';
  1404. }
  1405. print $taskstatic->getNomUrl(1, 'withproject', 'time');
  1406. // Label task
  1407. print '<br>';
  1408. print '<div class="opacitymedium tdoverflowmax500" title="'.dol_escape_htmltag($taskstatic->label).'">'.dol_escape_htmltag($taskstatic->label).'</div>';
  1409. for ($k = 0; $k < $level; $k++) {
  1410. print "</div>";
  1411. }
  1412. print "</td>\n";
  1413. // TASK extrafields
  1414. $extrafieldsobjectkey = 'projet_task';
  1415. $extrafieldsobjectprefix = 'efpt.';
  1416. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  1417. // Planned Workload
  1418. if (!empty($arrayfields['t.planned_workload']['checked'])) {
  1419. print '<td class="leftborder plannedworkload right">';
  1420. if ($lines[$i]->planned_workload) {
  1421. print convertSecondToTime($lines[$i]->planned_workload, 'allhourmin');
  1422. } else {
  1423. print '--:--';
  1424. }
  1425. print '</td>';
  1426. }
  1427. // Progress declared %
  1428. if (!empty($arrayfields['t.progress']['checked'])) {
  1429. print '<td class="right">';
  1430. print $formother->select_percent($lines[$i]->progress, $lines[$i]->id.'progress');
  1431. print '</td>';
  1432. }
  1433. if (!empty($arrayfields['timeconsumed']['checked'])) {
  1434. // Time spent by everybody
  1435. print '<td class="right">';
  1436. // $lines[$i]->duration_effective is a denormalised field = summ of time spent by everybody for task. What we need is time consumed by user
  1437. if ($lines[$i]->duration_effective) {
  1438. print '<a href="'.DOL_URL_ROOT.'/projet/tasks/time.php?id='.$lines[$i]->id.'">';
  1439. print convertSecondToTime($lines[$i]->duration_effective, 'allhourmin');
  1440. print '</a>';
  1441. } else {
  1442. print '--:--';
  1443. }
  1444. print "</td>\n";
  1445. // Time spent by user
  1446. print '<td class="right">';
  1447. $tmptimespent = $taskstatic->getSummaryOfTimeSpent($fuser->id);
  1448. if ($tmptimespent['total_duration']) {
  1449. print convertSecondToTime($tmptimespent['total_duration'], 'allhourmin');
  1450. } else {
  1451. print '--:--';
  1452. }
  1453. print "</td>\n";
  1454. }
  1455. $disabledproject = 1;
  1456. $disabledtask = 1;
  1457. //print "x".$lines[$i]->fk_project;
  1458. //var_dump($lines[$i]);
  1459. //var_dump($projectsrole[$lines[$i]->fk_project]);
  1460. // If at least one role for project
  1461. if ($lines[$i]->public || !empty($projectsrole[$lines[$i]->fk_project]) || $user->hasRight('projet', 'all', 'creer')) {
  1462. $disabledproject = 0;
  1463. $disabledtask = 0;
  1464. }
  1465. // If $restricteditformytask is on and I have no role on task, i disable edit
  1466. if ($restricteditformytask && empty($tasksrole[$lines[$i]->id])) {
  1467. $disabledtask = 1;
  1468. }
  1469. if ($restrictBefore && $preselectedday < $restrictBefore) {
  1470. $disabledtask = 1;
  1471. }
  1472. // Select hour
  1473. print '<td class="nowraponall leftborder center minwidth150imp">';
  1474. $tableCell = $form->selectDate($preselectedday, $lines[$i]->id, 1, 1, 2, "addtime", 0, 0, $disabledtask);
  1475. print $tableCell;
  1476. print '</td>';
  1477. $cssonholiday = '';
  1478. if (!$isavailable[$preselectedday]['morning'] && !$isavailable[$preselectedday]['afternoon']) {
  1479. $cssonholiday .= 'onholidayallday ';
  1480. } elseif (!$isavailable[$preselectedday]['morning']) {
  1481. $cssonholiday .= 'onholidaymorning ';
  1482. } elseif (!$isavailable[$preselectedday]['afternoon']) {
  1483. $cssonholiday .= 'onholidayafternoon ';
  1484. }
  1485. global $daytoparse;
  1486. $tmparray = dol_getdate($daytoparse, true); // detail of current day
  1487. $idw = ($tmparray['wday'] - (!getDolGlobalString('MAIN_START_WEEK') ? 0 : 1));
  1488. global $numstartworkingday, $numendworkingday;
  1489. $cssweekend = '';
  1490. if ((($idw + 1) < $numstartworkingday) || (($idw + 1) > $numendworkingday)) { // This is a day is not inside the setup of working days, so we use a week-end css.
  1491. $cssweekend = 'weekend';
  1492. }
  1493. // Duration
  1494. print '<td class="center duration'.($cssonholiday ? ' '.$cssonholiday : '').($cssweekend ? ' '.$cssweekend : '').'">';
  1495. $dayWorkLoad = empty($projectstatic->weekWorkLoadPerTask[$preselectedday][$lines[$i]->id]) ? 0 : $projectstatic->weekWorkLoadPerTask[$preselectedday][$lines[$i]->id];
  1496. if (!isset($totalforeachday[$preselectedday])) {
  1497. $totalforeachday[$preselectedday] = 0;
  1498. }
  1499. $totalforeachday[$preselectedday] += $dayWorkLoad;
  1500. $alreadyspent = '';
  1501. if ($dayWorkLoad > 0) {
  1502. $alreadyspent = convertSecondToTime($dayWorkLoad, 'allhourmin');
  1503. }
  1504. $idw = 0;
  1505. $tableCell = '';
  1506. $tableCell .= '<span class="timesheetalreadyrecorded" title="texttoreplace"><input type="text" class="center" size="2" disabled id="timespent['.$inc.']['.$idw.']" name="task['.$lines[$i]->id.']['.$idw.']" value="'.$alreadyspent.'"></span>';
  1507. $tableCell .= '<span class="hideonsmartphone"> + </span>';
  1508. //$tableCell.='&nbsp;&nbsp;&nbsp;';
  1509. $tableCell .= $form->select_duration($lines[$i]->id.'duration', '', $disabledtask, 'text', 0, 1);
  1510. //$tableCell.='&nbsp;<input type="submit" class="button"'.($disabledtask?' disabled':'').' value="'.$langs->trans("Add").'">';
  1511. print $tableCell;
  1512. print '</td>';
  1513. // Note
  1514. print '<td class="center">';
  1515. print '<textarea name="'.$lines[$i]->id.'note" rows="'.ROWS_2.'" id="'.$lines[$i]->id.'note"'.($disabledtask ? ' disabled="disabled"' : '').'>';
  1516. print '</textarea>';
  1517. print '</td>';
  1518. // Warning
  1519. print '<td class="right">';
  1520. if ((!$lines[$i]->public) && $disabledproject) {
  1521. print $form->textwithpicto('', $langs->trans("UserIsNotContactOfProject"));
  1522. } elseif ($disabledtask) {
  1523. $titleassigntask = $langs->trans("AssignTaskToMe");
  1524. if ($fuser->id != $user->id) {
  1525. $titleassigntask = $langs->trans("AssignTaskToUser", '...');
  1526. }
  1527. print $form->textwithpicto('', $langs->trans("TaskIsNotAssignedToUser", $titleassigntask));
  1528. }
  1529. print '</td>';
  1530. print "</tr>\n";
  1531. }
  1532. $inc++;
  1533. $level++;
  1534. if ($lines[$i]->id > 0) {
  1535. //var_dump('totalforeachday after taskid='.$lines[$i]->id.' and previous one on level '.$level);
  1536. //var_dump($totalforeachday);
  1537. $ret = projectLinesPerDay($inc, $lines[$i]->id, $fuser, ($parent == 0 ? $lineswithoutlevel0 : $lines), $level, $projectsrole, $tasksrole, $mine, $restricteditformytask, $preselectedday, $isavailable, $oldprojectforbreak, $arrayfields, $extrafields);
  1538. //var_dump('ret with parent='.$lines[$i]->id.' level='.$level);
  1539. //var_dump($ret);
  1540. foreach ($ret as $key => $val) {
  1541. $totalforeachday[$key] += $val;
  1542. }
  1543. //var_dump('totalforeachday after taskid='.$lines[$i]->id.' and previous one on level '.$level.' + subtasks');
  1544. //var_dump($totalforeachday);
  1545. }
  1546. $level--;
  1547. } else {
  1548. //$level--;
  1549. }
  1550. }
  1551. return $totalforeachday;
  1552. }
  1553. /**
  1554. * Output a task line into a perday intput mode
  1555. *
  1556. * @param string $inc Line output identificator (start to 0, then increased by recursive call)
  1557. * @param int $firstdaytoshow First day to show
  1558. * @param User|null $fuser Restrict list to user if defined
  1559. * @param string $parent Id of parent task to show (0 to show all)
  1560. * @param Task[] $lines Array of lines (list of tasks but we will show only if we have a specific role on task)
  1561. * @param int $level Level (start to 0, then increased/decrease by recursive call)
  1562. * @param string $projectsrole Array of roles user has on project
  1563. * @param string $tasksrole Array of roles user has on task
  1564. * @param string $mine Show only task lines I am assigned to
  1565. * @param int $restricteditformytask 0=No restriction, 1=Enable add time only if task is assigned to me, 2=Enable add time only if tasks is assigned to me and hide others
  1566. * @param array $isavailable Array with data that say if user is available for several days for morning and afternoon
  1567. * @param int $oldprojectforbreak Old project id of last project break
  1568. * @param array $arrayfields Array of additional column
  1569. * @param Extrafields $extrafields Object extrafields
  1570. * @return array Array with time spent for $fuser for each day of week on tasks in $lines and substasks
  1571. */
  1572. function projectLinesPerWeek(&$inc, $firstdaytoshow, $fuser, $parent, $lines, &$level, &$projectsrole, &$tasksrole, $mine, $restricteditformytask, &$isavailable, $oldprojectforbreak = 0, $arrayfields = array(), $extrafields = null)
  1573. {
  1574. global $conf, $db, $user, $langs;
  1575. global $form, $formother, $projectstatic, $taskstatic, $thirdpartystatic;
  1576. $numlines = count($lines);
  1577. $lastprojectid = 0;
  1578. $workloadforid = array();
  1579. $totalforeachday = array();
  1580. $lineswithoutlevel0 = array();
  1581. // Create a smaller array with sublevels only to be used later. This increase dramatically performances.
  1582. if ($parent == 0) { // Always and only if at first level
  1583. for ($i = 0; $i < $numlines; $i++) {
  1584. if ($lines[$i]->fk_task_parent) {
  1585. $lineswithoutlevel0[] = $lines[$i];
  1586. }
  1587. }
  1588. }
  1589. //dol_syslog('projectLinesPerWeek inc='.$inc.' firstdaytoshow='.$firstdaytoshow.' task parent id='.$parent.' level='.$level." count(lines)=".$numlines." count(lineswithoutlevel0)=".count($lineswithoutlevel0));
  1590. if (empty($oldprojectforbreak)) {
  1591. $oldprojectforbreak = (!getDolGlobalString('PROJECT_TIMESHEET_DISABLEBREAK_ON_PROJECT') ? 0 : -1); // 0 = start break, -1 = never break
  1592. }
  1593. $restrictBefore = null;
  1594. if (getDolGlobalString('PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS')) {
  1595. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  1596. $restrictBefore = dol_time_plus_duree(dol_now(), - $conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS, 'm');
  1597. }
  1598. for ($i = 0; $i < $numlines; $i++) {
  1599. if ($parent == 0) {
  1600. $level = 0;
  1601. }
  1602. if ($lines[$i]->fk_task_parent == $parent) {
  1603. $obj = &$lines[$i]; // To display extrafields
  1604. // If we want all or we have a role on task, we show it
  1605. if (empty($mine) || !empty($tasksrole[$lines[$i]->id])) {
  1606. //dol_syslog("projectLinesPerWeek Found line ".$i.", a qualified task (i have role or want to show all tasks) with id=".$lines[$i]->id." project id=".$lines[$i]->fk_project);
  1607. if ($restricteditformytask == 2 && empty($tasksrole[$lines[$i]->id])) { // we have no role on task and we request to hide such cases
  1608. continue;
  1609. }
  1610. // Break on a new project
  1611. if ($parent == 0 && $lines[$i]->fk_project != $lastprojectid) {
  1612. $lastprojectid = $lines[$i]->fk_project;
  1613. $projectstatic->id = $lines[$i]->fk_project;
  1614. }
  1615. //var_dump('--- '.$level.' '.$firstdaytoshow.' '.$fuser->id.' '.$projectstatic->id.' '.$workloadforid[$projectstatic->id]);
  1616. //var_dump($projectstatic->weekWorkLoadPerTask);
  1617. if (empty($workloadforid[$projectstatic->id])) {
  1618. $projectstatic->loadTimeSpent($firstdaytoshow, 0, $fuser->id); // Load time spent from table element_time for the project into this->weekWorkLoad and this->weekWorkLoadPerTask for all days of a week
  1619. $workloadforid[$projectstatic->id] = 1;
  1620. }
  1621. //var_dump($projectstatic->weekWorkLoadPerTask);
  1622. //var_dump('--- '.$projectstatic->id.' '.$workloadforid[$projectstatic->id]);
  1623. $projectstatic->id = $lines[$i]->fk_project;
  1624. $projectstatic->ref = $lines[$i]->projectref;
  1625. $projectstatic->title = $lines[$i]->projectlabel;
  1626. $projectstatic->public = $lines[$i]->public;
  1627. $projectstatic->thirdparty_name = $lines[$i]->thirdparty_name;
  1628. $projectstatic->status = $lines[$i]->projectstatus;
  1629. $taskstatic->id = $lines[$i]->id;
  1630. $taskstatic->ref = ($lines[$i]->ref ? $lines[$i]->ref : $lines[$i]->id);
  1631. $taskstatic->label = $lines[$i]->label;
  1632. $taskstatic->date_start = $lines[$i]->date_start;
  1633. $taskstatic->date_end = $lines[$i]->date_end;
  1634. $thirdpartystatic->id = $lines[$i]->thirdparty_id;
  1635. $thirdpartystatic->name = $lines[$i]->thirdparty_name;
  1636. $thirdpartystatic->email = $lines[$i]->thirdparty_email;
  1637. if (empty($oldprojectforbreak) || ($oldprojectforbreak != -1 && $oldprojectforbreak != $projectstatic->id)) {
  1638. $addcolspan = 0;
  1639. if (!empty($arrayfields['t.planned_workload']['checked'])) {
  1640. $addcolspan++;
  1641. }
  1642. if (!empty($arrayfields['t.progress']['checked'])) {
  1643. $addcolspan++;
  1644. }
  1645. foreach ($arrayfields as $key => $val) {
  1646. if ($val['checked'] && substr($key, 0, 5) == 'efpt.') {
  1647. $addcolspan++;
  1648. }
  1649. }
  1650. print '<tr class="oddeven trforbreak nobold">'."\n";
  1651. print '<td colspan="'.(11 + $addcolspan).'">';
  1652. print $projectstatic->getNomUrl(1, '', 0, '<strong>'.$langs->transnoentitiesnoconv("YourRole").':</strong> '.$projectsrole[$lines[$i]->fk_project]);
  1653. if ($thirdpartystatic->id > 0) {
  1654. print ' - '.$thirdpartystatic->getNomUrl(1);
  1655. }
  1656. if ($projectstatic->title) {
  1657. print ' - ';
  1658. print '<span class="secondary">'.$projectstatic->title.'</span>';
  1659. }
  1660. /*$colspan=5+(empty($conf->global->PROJECT_TIMESHEET_DISABLEBREAK_ON_PROJECT)?0:2);
  1661. print '<table class="">';
  1662. print '<tr class="liste_titre">';
  1663. // PROJECT fields
  1664. if (!empty($arrayfields['p.fk_opp_status']['checked'])) print_liste_field_titre($arrayfields['p.fk_opp_status']['label'], $_SERVER["PHP_SELF"], 'p.fk_opp_status', "", $param, '', $sortfield, $sortorder, 'center ');
  1665. if (!empty($arrayfields['p.opp_amount']['checked'])) print_liste_field_titre($arrayfields['p.opp_amount']['label'], $_SERVER["PHP_SELF"], 'p.opp_amount', "", $param, '', $sortfield, $sortorder, 'right ');
  1666. if (!empty($arrayfields['p.opp_percent']['checked'])) print_liste_field_titre($arrayfields['p.opp_percent']['label'], $_SERVER["PHP_SELF"], 'p.opp_percent', "", $param, '', $sortfield, $sortorder, 'right ');
  1667. if (!empty($arrayfields['p.budget_amount']['checked'])) print_liste_field_titre($arrayfields['p.budget_amount']['label'], $_SERVER["PHP_SELF"], 'p.budget_amount', "", $param, '', $sortfield, $sortorder, 'right ');
  1668. if (!empty($arrayfields['p.usage_bill_time']['checked'])) print_liste_field_titre($arrayfields['p.usage_bill_time']['label'], $_SERVER["PHP_SELF"], 'p.usage_bill_time', "", $param, '', $sortfield, $sortorder, 'right ');
  1669. $extrafieldsobjectkey='projet';
  1670. $extrafieldsobjectprefix='efp.';
  1671. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  1672. print '</tr>';
  1673. print '<tr>';
  1674. // PROJECT fields
  1675. if (!empty($arrayfields['p.fk_opp_status']['checked']))
  1676. {
  1677. print '<td class="nowrap">';
  1678. $code = dol_getIdFromCode($db, $lines[$i]->fk_opp_status, 'c_lead_status', 'rowid', 'code');
  1679. if ($code) print $langs->trans("OppStatus".$code);
  1680. print "</td>\n";
  1681. }
  1682. if (!empty($arrayfields['p.opp_amount']['checked']))
  1683. {
  1684. print '<td class="nowrap">';
  1685. print price($lines[$i]->opp_amount, 0, $langs, 1, 0, -1, $conf->currency);
  1686. print "</td>\n";
  1687. }
  1688. if (!empty($arrayfields['p.opp_percent']['checked']))
  1689. {
  1690. print '<td class="nowrap">';
  1691. print price($lines[$i]->opp_percent, 0, $langs, 1, 0).' %';
  1692. print "</td>\n";
  1693. }
  1694. if (!empty($arrayfields['p.budget_amount']['checked']))
  1695. {
  1696. print '<td class="nowrap">';
  1697. print price($lines[$i]->budget_amount, 0, $langs, 1, 0, 0, $conf->currency);
  1698. print "</td>\n";
  1699. }
  1700. if (!empty($arrayfields['p.usage_bill_time']['checked']))
  1701. {
  1702. print '<td class="nowrap">';
  1703. print yn($lines[$i]->usage_bill_time);
  1704. print "</td>\n";
  1705. }
  1706. $extrafieldsobjectkey='projet';
  1707. $extrafieldsobjectprefix='efp.';
  1708. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  1709. print '</tr>';
  1710. print '</table>';
  1711. */
  1712. print '</td>';
  1713. print '</tr>';
  1714. }
  1715. if ($oldprojectforbreak != -1) {
  1716. $oldprojectforbreak = $projectstatic->id;
  1717. }
  1718. print '<tr class="oddeven" data-taskid="'.$lines[$i]->id.'">'."\n";
  1719. // User
  1720. /*
  1721. print '<td class="nowrap">';
  1722. print $fuser->getNomUrl(1, 'withproject', 'time');
  1723. print '</td>';
  1724. */
  1725. // Project
  1726. if (getDolGlobalString('PROJECT_TIMESHEET_DISABLEBREAK_ON_PROJECT')) {
  1727. print '<td class="nowrap">';
  1728. if ($oldprojectforbreak == -1) {
  1729. print $projectstatic->getNomUrl(1, '', 0, $langs->transnoentitiesnoconv("YourRole").': '.$projectsrole[$lines[$i]->fk_project]);
  1730. }
  1731. print "</td>";
  1732. }
  1733. // Thirdparty
  1734. if (getDolGlobalString('PROJECT_TIMESHEET_DISABLEBREAK_ON_PROJECT')) {
  1735. print '<td class="tdoverflowmax100">';
  1736. if ($thirdpartystatic->id > 0) {
  1737. print $thirdpartystatic->getNomUrl(1, 'project');
  1738. }
  1739. print '</td>';
  1740. }
  1741. // Ref
  1742. print '<td class="tdoverflowmax300">';
  1743. print '<!-- Task id = '.$lines[$i]->id.' (projectlinesperweek) -->';
  1744. for ($k = 0; $k < $level; $k++) {
  1745. print '<div class="marginleftonly">';
  1746. }
  1747. print $taskstatic->getNomUrl(1, 'withproject', 'time');
  1748. // Label task
  1749. print '<br>';
  1750. print '<div class="opacitymedium tdoverflowmax500" title="'.dol_escape_htmltag($taskstatic->label).'">'.dol_escape_htmltag($taskstatic->label).'</div>';
  1751. for ($k = 0; $k < $level; $k++) {
  1752. print "</div>";
  1753. }
  1754. print "</td>\n";
  1755. // TASK extrafields
  1756. $extrafieldsobjectkey = 'projet_task';
  1757. $extrafieldsobjectprefix = 'efpt.';
  1758. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  1759. // Planned Workload
  1760. if (!empty($arrayfields['t.planned_workload']['checked'])) {
  1761. print '<td class="leftborder plannedworkload right">';
  1762. if ($lines[$i]->planned_workload) {
  1763. print convertSecondToTime($lines[$i]->planned_workload, 'allhourmin');
  1764. } else {
  1765. print '--:--';
  1766. }
  1767. print '</td>';
  1768. }
  1769. if (!empty($arrayfields['t.progress']['checked'])) {
  1770. // Progress declared %
  1771. print '<td class="right">';
  1772. print $formother->select_percent($lines[$i]->progress, $lines[$i]->id.'progress');
  1773. print '</td>';
  1774. }
  1775. if (!empty($arrayfields['timeconsumed']['checked'])) {
  1776. // Time spent by everybody
  1777. print '<td class="right">';
  1778. // $lines[$i]->duration_effective is a denormalised field = summ of time spent by everybody for task. What we need is time consumed by user
  1779. if ($lines[$i]->duration_effective) {
  1780. print '<a href="'.DOL_URL_ROOT.'/projet/tasks/time.php?id='.((int) $lines[$i]->id).'">';
  1781. print convertSecondToTime($lines[$i]->duration_effective, 'allhourmin');
  1782. print '</a>';
  1783. } else {
  1784. print '--:--';
  1785. }
  1786. print "</td>\n";
  1787. // Time spent by user
  1788. print '<td class="right">';
  1789. $tmptimespent = $taskstatic->getSummaryOfTimeSpent($fuser->id);
  1790. if ($tmptimespent['total_duration']) {
  1791. print '<a href="'.DOL_URL_ROOT.'/projet/tasks/time.php?id='.((int) $lines[$i]->id).'&search_user='.((int) $fuser->id).'">';
  1792. print convertSecondToTime($tmptimespent['total_duration'], 'allhourmin');
  1793. print '</a>';
  1794. } else {
  1795. print '--:--';
  1796. }
  1797. print "</td>\n";
  1798. }
  1799. $disabledproject = 1;
  1800. $disabledtask = 1;
  1801. //print "x".$lines[$i]->fk_project;
  1802. //var_dump($lines[$i]);
  1803. //var_dump($projectsrole[$lines[$i]->fk_project]);
  1804. // If at least one role for project
  1805. if ($lines[$i]->public || !empty($projectsrole[$lines[$i]->fk_project]) || $user->hasRight('projet', 'all', 'creer')) {
  1806. $disabledproject = 0;
  1807. $disabledtask = 0;
  1808. }
  1809. // If $restricteditformytask is on and I have no role on task, i disable edit
  1810. if ($restricteditformytask && empty($tasksrole[$lines[$i]->id])) {
  1811. $disabledtask = 1;
  1812. }
  1813. //var_dump($projectstatic->weekWorkLoadPerTask);
  1814. // Fields to show current time
  1815. $tableCell = '';
  1816. $modeinput = 'hours';
  1817. for ($idw = 0; $idw < 7; $idw++) {
  1818. $tmpday = dol_time_plus_duree($firstdaytoshow, $idw, 'd');
  1819. if (!isset($totalforeachday[$tmpday])) {
  1820. $totalforeachday[$tmpday] = 0;
  1821. }
  1822. $cssonholiday = '';
  1823. if (!$isavailable[$tmpday]['morning'] && !$isavailable[$tmpday]['afternoon']) {
  1824. $cssonholiday .= 'onholidayallday ';
  1825. } elseif (!$isavailable[$tmpday]['morning']) {
  1826. $cssonholiday .= 'onholidaymorning ';
  1827. } elseif (!$isavailable[$tmpday]['afternoon']) {
  1828. $cssonholiday .= 'onholidayafternoon ';
  1829. }
  1830. $tmparray = dol_getdate($tmpday);
  1831. $dayWorkLoad = (!empty($projectstatic->weekWorkLoadPerTask[$tmpday][$lines[$i]->id]) ? $projectstatic->weekWorkLoadPerTask[$tmpday][$lines[$i]->id] : 0);
  1832. $totalforeachday[$tmpday] += $dayWorkLoad;
  1833. $alreadyspent = '';
  1834. if ($dayWorkLoad > 0) {
  1835. $alreadyspent = convertSecondToTime($dayWorkLoad, 'allhourmin');
  1836. }
  1837. $alttitle = $langs->trans("AddHereTimeSpentForDay", !empty($tmparray['day']) ? $tmparray['day'] : 0, $tmparray['mon']);
  1838. global $numstartworkingday, $numendworkingday;
  1839. $cssweekend = '';
  1840. if (($idw + 1 < $numstartworkingday) || ($idw + 1 > $numendworkingday)) { // This is a day is not inside the setup of working days, so we use a week-end css.
  1841. $cssweekend = 'weekend';
  1842. }
  1843. $disabledtaskday = $disabledtask;
  1844. if (! $disabledtask && $restrictBefore && $tmpday < $restrictBefore) {
  1845. $disabledtaskday = 1;
  1846. }
  1847. $tableCell = '<td class="center hide'.$idw.($cssonholiday ? ' '.$cssonholiday : '').($cssweekend ? ' '.$cssweekend : '').'">';
  1848. //$tableCell .= 'idw='.$idw.' '.$conf->global->MAIN_START_WEEK.' '.$numstartworkingday.'-'.$numendworkingday;
  1849. $placeholder = '';
  1850. if ($alreadyspent) {
  1851. $tableCell .= '<span class="timesheetalreadyrecorded" title="texttoreplace"><input type="text" class="center smallpadd" size="2" disabled id="timespent['.$inc.']['.$idw.']" name="task['.$lines[$i]->id.']['.$idw.']" value="'.$alreadyspent.'"></span>';
  1852. //$placeholder=' placeholder="00:00"';
  1853. //$tableCell.='+';
  1854. }
  1855. $tableCell .= '<input type="text" alt="'.($disabledtaskday ? '' : $alttitle).'" title="'.($disabledtaskday ? '' : $alttitle).'" '.($disabledtaskday ? 'disabled' : $placeholder).' class="center smallpadd" size="2" id="timeadded['.$inc.']['.$idw.']" name="task['.$lines[$i]->id.']['.$idw.']" value="" cols="2" maxlength="5"';
  1856. $tableCell .= ' onkeypress="return regexEvent(this,event,\'timeChar\')"';
  1857. $tableCell .= ' onkeyup="updateTotal('.$idw.',\''.$modeinput.'\')"';
  1858. $tableCell .= ' onblur="regexEvent(this,event,\''.$modeinput.'\'); updateTotal('.$idw.',\''.$modeinput.'\')" />';
  1859. $tableCell .= '</td>';
  1860. print $tableCell;
  1861. }
  1862. // Warning
  1863. print '<td class="right">';
  1864. if ((!$lines[$i]->public) && $disabledproject) {
  1865. print $form->textwithpicto('', $langs->trans("UserIsNotContactOfProject"));
  1866. } elseif ($disabledtask) {
  1867. $titleassigntask = $langs->trans("AssignTaskToMe");
  1868. if ($fuser->id != $user->id) {
  1869. $titleassigntask = $langs->trans("AssignTaskToUser", '...');
  1870. }
  1871. print $form->textwithpicto('', $langs->trans("TaskIsNotAssignedToUser", $titleassigntask));
  1872. }
  1873. print '</td>';
  1874. print "</tr>\n";
  1875. }
  1876. // Call to show task with a lower level (task under the current task)
  1877. $inc++;
  1878. $level++;
  1879. if ($lines[$i]->id > 0) {
  1880. //var_dump('totalforeachday after taskid='.$lines[$i]->id.' and previous one on level '.$level);
  1881. //var_dump($totalforeachday);
  1882. $ret = projectLinesPerWeek($inc, $firstdaytoshow, $fuser, $lines[$i]->id, ($parent == 0 ? $lineswithoutlevel0 : $lines), $level, $projectsrole, $tasksrole, $mine, $restricteditformytask, $isavailable, $oldprojectforbreak, $arrayfields, $extrafields);
  1883. //var_dump('ret with parent='.$lines[$i]->id.' level='.$level);
  1884. //var_dump($ret);
  1885. foreach ($ret as $key => $val) {
  1886. $totalforeachday[$key] += $val;
  1887. }
  1888. //var_dump('totalforeachday after taskid='.$lines[$i]->id.' and previous one on level '.$level.' + subtasks');
  1889. //var_dump($totalforeachday);
  1890. }
  1891. $level--;
  1892. } else {
  1893. //$level--;
  1894. }
  1895. }
  1896. return $totalforeachday;
  1897. }
  1898. /**
  1899. * Output a task line into a perday intput mode
  1900. *
  1901. * @param string $inc Line output identificator (start to 0, then increased by recursive call)
  1902. * @param int $firstdaytoshow First day to show
  1903. * @param User|null $fuser Restrict list to user if defined
  1904. * @param string $parent Id of parent task to show (0 to show all)
  1905. * @param Task[] $lines Array of lines (list of tasks but we will show only if we have a specific role on task)
  1906. * @param int $level Level (start to 0, then increased/decrease by recursive call)
  1907. * @param string $projectsrole Array of roles user has on project
  1908. * @param string $tasksrole Array of roles user has on task
  1909. * @param string $mine Show only task lines I am assigned to
  1910. * @param int $restricteditformytask 0=No restriction, 1=Enable add time only if task is a task i am affected to
  1911. * @param array $isavailable Array with data that say if user is available for several days for morning and afternoon
  1912. * @param int $oldprojectforbreak Old project id of last project break
  1913. * @param array $TWeek Array of week numbers
  1914. * @return array Array with time spent for $fuser for each day of week on tasks in $lines and substasks
  1915. */
  1916. function projectLinesPerMonth(&$inc, $firstdaytoshow, $fuser, $parent, $lines, &$level, &$projectsrole, &$tasksrole, $mine, $restricteditformytask, &$isavailable, $oldprojectforbreak = 0, $TWeek = array())
  1917. {
  1918. global $conf, $db, $user, $langs;
  1919. global $form, $formother, $projectstatic, $taskstatic, $thirdpartystatic;
  1920. $numlines = count($lines);
  1921. $lastprojectid = 0;
  1922. $workloadforid = array();
  1923. $totalforeachweek = array();
  1924. $lineswithoutlevel0 = array();
  1925. // Create a smaller array with sublevels only to be used later. This increase dramatically performances.
  1926. if ($parent == 0) { // Always and only if at first level
  1927. for ($i = 0; $i < $numlines; $i++) {
  1928. if ($lines[$i]->fk_task_parent) {
  1929. $lineswithoutlevel0[] = $lines[$i];
  1930. }
  1931. }
  1932. }
  1933. //dol_syslog('projectLinesPerWeek inc='.$inc.' firstdaytoshow='.$firstdaytoshow.' task parent id='.$parent.' level='.$level." count(lines)=".$numlines." count(lineswithoutlevel0)=".count($lineswithoutlevel0));
  1934. if (empty($oldprojectforbreak)) {
  1935. $oldprojectforbreak = (!getDolGlobalString('PROJECT_TIMESHEET_DISABLEBREAK_ON_PROJECT') ? 0 : -1); // 0 = start break, -1 = never break
  1936. }
  1937. $restrictBefore = null;
  1938. if (getDolGlobalString('PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS')) {
  1939. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  1940. $restrictBefore = dol_time_plus_duree(dol_now(), - $conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS, 'm');
  1941. }
  1942. for ($i = 0; $i < $numlines; $i++) {
  1943. if ($parent == 0) {
  1944. $level = 0;
  1945. }
  1946. if ($lines[$i]->fk_task_parent == $parent) {
  1947. // If we want all or we have a role on task, we show it
  1948. if (empty($mine) || !empty($tasksrole[$lines[$i]->id])) {
  1949. //dol_syslog("projectLinesPerWeek Found line ".$i.", a qualified task (i have role or want to show all tasks) with id=".$lines[$i]->id." project id=".$lines[$i]->fk_project);
  1950. // Break on a new project
  1951. if ($parent == 0 && $lines[$i]->fk_project != $lastprojectid) {
  1952. $lastprojectid = $lines[$i]->fk_project;
  1953. $projectstatic->id = $lines[$i]->fk_project;
  1954. }
  1955. //var_dump('--- '.$level.' '.$firstdaytoshow.' '.$fuser->id.' '.$projectstatic->id.' '.$workloadforid[$projectstatic->id]);
  1956. //var_dump($projectstatic->weekWorkLoadPerTask);
  1957. if (empty($workloadforid[$projectstatic->id])) {
  1958. $projectstatic->loadTimeSpentMonth($firstdaytoshow, 0, $fuser->id); // Load time spent from table element_time for the project into this->weekWorkLoad and this->weekWorkLoadPerTask for all days of a week
  1959. $workloadforid[$projectstatic->id] = 1;
  1960. }
  1961. //var_dump($projectstatic->weekWorkLoadPerTask);
  1962. //var_dump('--- '.$projectstatic->id.' '.$workloadforid[$projectstatic->id]);
  1963. $projectstatic->id = $lines[$i]->fk_project;
  1964. $projectstatic->ref = $lines[$i]->projectref;
  1965. $projectstatic->title = $lines[$i]->projectlabel;
  1966. $projectstatic->public = $lines[$i]->public;
  1967. $projectstatic->thirdparty_name = $lines[$i]->thirdparty_name;
  1968. $projectstatic->status = $lines[$i]->projectstatus;
  1969. $taskstatic->id = $lines[$i]->id;
  1970. $taskstatic->ref = ($lines[$i]->ref ? $lines[$i]->ref : $lines[$i]->id);
  1971. $taskstatic->label = $lines[$i]->label;
  1972. $taskstatic->date_start = $lines[$i]->date_start;
  1973. $taskstatic->date_end = $lines[$i]->date_end;
  1974. $thirdpartystatic->id = $lines[$i]->thirdparty_id;
  1975. $thirdpartystatic->name = $lines[$i]->thirdparty_name;
  1976. $thirdpartystatic->email = $lines[$i]->thirdparty_email;
  1977. if (empty($oldprojectforbreak) || ($oldprojectforbreak != -1 && $oldprojectforbreak != $projectstatic->id)) {
  1978. print '<tr class="oddeven trforbreak nobold">'."\n";
  1979. print '<td colspan="'.(6 + count($TWeek)).'">';
  1980. print $projectstatic->getNomUrl(1, '', 0, '<strong>'.$langs->transnoentitiesnoconv("YourRole").':</strong> '.$projectsrole[$lines[$i]->fk_project]);
  1981. if ($thirdpartystatic->id > 0) {
  1982. print ' - '.$thirdpartystatic->getNomUrl(1);
  1983. }
  1984. if ($projectstatic->title) {
  1985. print ' - ';
  1986. print '<span class="secondary">'.$projectstatic->title.'</span>';
  1987. }
  1988. print '</td>';
  1989. print '</tr>';
  1990. }
  1991. if ($oldprojectforbreak != -1) {
  1992. $oldprojectforbreak = $projectstatic->id;
  1993. }
  1994. print '<tr class="oddeven" data-taskid="'.$lines[$i]->id.'">'."\n";
  1995. // User
  1996. /*
  1997. print '<td class="nowrap">';
  1998. print $fuser->getNomUrl(1, 'withproject', 'time');
  1999. print '</td>';
  2000. */
  2001. // Project
  2002. /*print '<td class="nowrap">';
  2003. if ($oldprojectforbreak == -1) print $projectstatic->getNomUrl(1,'',0,$langs->transnoentitiesnoconv("YourRole").': '.$projectsrole[$lines[$i]->fk_project]);
  2004. print "</td>";*/
  2005. // Thirdparty
  2006. /*print '<td class="tdoverflowmax100">';
  2007. if ($thirdpartystatic->id > 0) print $thirdpartystatic->getNomUrl(1, 'project');
  2008. print '</td>';*/
  2009. // Ref
  2010. print '<td class="nowrap">';
  2011. print '<!-- Task id = '.$lines[$i]->id.' (projectlinespermonth) -->';
  2012. for ($k = 0; $k < $level; $k++) {
  2013. print '<div class="marginleftonly">';
  2014. }
  2015. print $taskstatic->getNomUrl(1, 'withproject', 'time');
  2016. // Label task
  2017. print '<br>';
  2018. print '<div class="opacitymedium tdoverflowmax500" title="'.dol_escape_htmltag($taskstatic->label).'">'.dol_escape_htmltag($taskstatic->label).'</div>';
  2019. for ($k = 0; $k < $level; $k++) {
  2020. print "</div>";
  2021. }
  2022. print "</td>\n";
  2023. // Planned Workload
  2024. print '<td class="leftborder plannedworkload right">';
  2025. if ($lines[$i]->planned_workload) {
  2026. print convertSecondToTime($lines[$i]->planned_workload, 'allhourmin');
  2027. } else {
  2028. print '--:--';
  2029. }
  2030. print '</td>';
  2031. // Progress declared %
  2032. print '<td class="right">';
  2033. print $formother->select_percent($lines[$i]->progress, $lines[$i]->id.'progress');
  2034. print '</td>';
  2035. // Time spent by everybody
  2036. print '<td class="right">';
  2037. // $lines[$i]->duration_effective is a denormalised field = summ of time spent by everybody for task. What we need is time consumed by user
  2038. if ($lines[$i]->duration_effective) {
  2039. print '<a href="'.DOL_URL_ROOT.'/projet/tasks/time.php?id='.$lines[$i]->id.'">';
  2040. print convertSecondToTime($lines[$i]->duration_effective, 'allhourmin');
  2041. print '</a>';
  2042. } else {
  2043. print '--:--';
  2044. }
  2045. print "</td>\n";
  2046. // Time spent by user
  2047. print '<td class="right">';
  2048. $tmptimespent = $taskstatic->getSummaryOfTimeSpent($fuser->id);
  2049. if ($tmptimespent['total_duration']) {
  2050. print convertSecondToTime($tmptimespent['total_duration'], 'allhourmin');
  2051. } else {
  2052. print '--:--';
  2053. }
  2054. print "</td>\n";
  2055. $disabledproject = 1;
  2056. $disabledtask = 1;
  2057. //print "x".$lines[$i]->fk_project;
  2058. //var_dump($lines[$i]);
  2059. //var_dump($projectsrole[$lines[$i]->fk_project]);
  2060. // If at least one role for project
  2061. if ($lines[$i]->public || !empty($projectsrole[$lines[$i]->fk_project]) || $user->hasRight('projet', 'all', 'creer')) {
  2062. $disabledproject = 0;
  2063. $disabledtask = 0;
  2064. }
  2065. // If $restricteditformytask is on and I have no role on task, i disable edit
  2066. if ($restricteditformytask && empty($tasksrole[$lines[$i]->id])) {
  2067. $disabledtask = 1;
  2068. }
  2069. //var_dump($projectstatic->weekWorkLoadPerTask);
  2070. //TODO
  2071. // Fields to show current time
  2072. $tableCell = '';
  2073. $modeinput = 'hours';
  2074. $TFirstDay = getFirstDayOfEachWeek($TWeek, date('Y', $firstdaytoshow));
  2075. $TFirstDay[reset($TWeek)] = 1;
  2076. $firstdaytoshowarray = dol_getdate($firstdaytoshow);
  2077. $year = $firstdaytoshowarray['year'];
  2078. $month = $firstdaytoshowarray['mon'];
  2079. foreach ($TWeek as $weekIndex => $weekNb) {
  2080. $weekWorkLoad = !empty($projectstatic->monthWorkLoadPerTask[$weekNb][$lines[$i]->id]) ? $projectstatic->monthWorkLoadPerTask[$weekNb][$lines[$i]->id] : 0 ;
  2081. if (!isset($totalforeachweek[$weekNb])) {
  2082. $totalforeachweek[$weekNb] = 0;
  2083. }
  2084. $totalforeachweek[$weekNb] += $weekWorkLoad;
  2085. $alreadyspent = '';
  2086. if ($weekWorkLoad > 0) {
  2087. $alreadyspent = convertSecondToTime($weekWorkLoad, 'allhourmin');
  2088. }
  2089. $alttitle = $langs->trans("AddHereTimeSpentForWeek", $weekNb);
  2090. $disabledtaskweek = $disabledtask;
  2091. $firstdayofweek = dol_mktime(0, 0, 0, $month, $TFirstDay[$weekIndex], $year);
  2092. if (! $disabledtask && $restrictBefore && $firstdayofweek < $restrictBefore) {
  2093. $disabledtaskweek = 1;
  2094. }
  2095. $tableCell = '<td class="center hide weekend">';
  2096. $placeholder = '';
  2097. if ($alreadyspent) {
  2098. $tableCell .= '<span class="timesheetalreadyrecorded" title="texttoreplace"><input type="text" class="center smallpadd" size="2" disabled id="timespent['.$inc.']['.((int) $weekNb).']" name="task['.$lines[$i]->id.']['.$weekNb.']" value="'.$alreadyspent.'"></span>';
  2099. //$placeholder=' placeholder="00:00"';
  2100. //$tableCell.='+';
  2101. }
  2102. $tableCell .= '<input type="text" alt="'.($disabledtaskweek ? '' : $alttitle).'" title="'.($disabledtaskweek ? '' : $alttitle).'" '.($disabledtaskweek ? 'disabled' : $placeholder).' class="center smallpadd" size="2" id="timeadded['.$inc.']['.((int) $weekNb).']" name="task['.$lines[$i]->id.']['.($TFirstDay[$weekNb] - 1).']" value="" cols="2" maxlength="5"';
  2103. $tableCell .= ' onkeypress="return regexEvent(this,event,\'timeChar\')"';
  2104. $tableCell .= ' onkeyup="updateTotal('.$weekNb.',\''.$modeinput.'\')"';
  2105. $tableCell .= ' onblur="regexEvent(this,event,\''.$modeinput.'\'); updateTotal('.$weekNb.',\''.$modeinput.'\')" />';
  2106. $tableCell .= '</td>';
  2107. print $tableCell;
  2108. }
  2109. // Warning
  2110. print '<td class="right">';
  2111. if ((!$lines[$i]->public) && $disabledproject) {
  2112. print $form->textwithpicto('', $langs->trans("UserIsNotContactOfProject"));
  2113. } elseif ($disabledtask) {
  2114. $titleassigntask = $langs->trans("AssignTaskToMe");
  2115. if ($fuser->id != $user->id) {
  2116. $titleassigntask = $langs->trans("AssignTaskToUser", '...');
  2117. }
  2118. print $form->textwithpicto('', $langs->trans("TaskIsNotAssignedToUser", $titleassigntask));
  2119. }
  2120. print '</td>';
  2121. print "</tr>\n";
  2122. }
  2123. // Call to show task with a lower level (task under the current task)
  2124. $inc++;
  2125. $level++;
  2126. if ($lines[$i]->id > 0) {
  2127. //var_dump('totalforeachday after taskid='.$lines[$i]->id.' and previous one on level '.$level);
  2128. //var_dump($totalforeachday);
  2129. $ret = projectLinesPerMonth($inc, $firstdaytoshow, $fuser, $lines[$i]->id, ($parent == 0 ? $lineswithoutlevel0 : $lines), $level, $projectsrole, $tasksrole, $mine, $restricteditformytask, $isavailable, $oldprojectforbreak, $TWeek);
  2130. //var_dump('ret with parent='.$lines[$i]->id.' level='.$level);
  2131. //var_dump($ret);
  2132. foreach ($ret as $key => $val) {
  2133. $totalforeachweek[$key] += $val;
  2134. }
  2135. //var_dump('totalforeachday after taskid='.$lines[$i]->id.' and previous one on level '.$level.' + subtasks');
  2136. //var_dump($totalforeachday);
  2137. }
  2138. $level--;
  2139. } else {
  2140. //$level--;
  2141. }
  2142. }
  2143. return $totalforeachweek;
  2144. }
  2145. /**
  2146. * Search in task lines with a particular parent if there is a task for a particular user (in taskrole)
  2147. *
  2148. * @param string $inc Counter that count number of lines legitimate to show (for return)
  2149. * @param int $parent Id of parent task to start
  2150. * @param array $lines Array of all tasks
  2151. * @param string $taskrole Array of task filtered on a particular user
  2152. * @return int 1 if there is
  2153. */
  2154. function searchTaskInChild(&$inc, $parent, &$lines, &$taskrole)
  2155. {
  2156. //print 'Search in line with parent id = '.$parent.'<br>';
  2157. $numlines = count($lines);
  2158. for ($i = 0; $i < $numlines; $i++) {
  2159. // Process line $lines[$i]
  2160. if ($lines[$i]->fk_task_parent == $parent && $lines[$i]->id != $lines[$i]->fk_task_parent) {
  2161. // If task is legitimate to show, no more need to search deeper
  2162. if (isset($taskrole[$lines[$i]->id])) {
  2163. //print 'Found a legitimate task id='.$lines[$i]->id.'<br>';
  2164. $inc++;
  2165. return $inc;
  2166. }
  2167. searchTaskInChild($inc, $lines[$i]->id, $lines, $taskrole);
  2168. //print 'Found inc='.$inc.'<br>';
  2169. if ($inc > 0) {
  2170. return $inc;
  2171. }
  2172. }
  2173. }
  2174. return $inc;
  2175. }
  2176. /**
  2177. * Return HTML table with list of projects and number of opened tasks
  2178. *
  2179. * @param DoliDB $db Database handler
  2180. * @param Form $form Object form
  2181. * @param int $socid Id thirdparty
  2182. * @param int $projectsListId Id of project I have permission on
  2183. * @param int $mytasks Limited to task I am contact to
  2184. * @param int $status -1=No filter on statut, 0 or 1 = Filter on status
  2185. * @param array $listofoppstatus List of opportunity status
  2186. * @param array $hiddenfields List of info to not show ('projectlabel', 'declaredprogress', '...', )
  2187. * @param int $max Max nb of record to show in HTML list
  2188. * @return void
  2189. */
  2190. function print_projecttasks_array($db, $form, $socid, $projectsListId, $mytasks = 0, $status = -1, $listofoppstatus = array(), $hiddenfields = array(), $max = 0)
  2191. {
  2192. global $langs, $conf, $user;
  2193. global $theme_datacolor;
  2194. $maxofloop = (!getDolGlobalString('MAIN_MAXLIST_OVERLOAD') ? 500 : $conf->global->MAIN_MAXLIST_OVERLOAD);
  2195. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  2196. $listofstatus = array_keys($listofoppstatus);
  2197. if (is_array($listofstatus) && getDolGlobalString('USE_COLOR_FOR_PROSPECTION_STATUS')) {
  2198. // Define $themeColorId and array $statusOppList for each $listofstatus
  2199. $themeColorId = 0;
  2200. $statusOppList = array();
  2201. foreach ($listofstatus as $oppStatus) {
  2202. $oppStatusCode = dol_getIdFromCode($db, $oppStatus, 'c_lead_status', 'rowid', 'code');
  2203. if ($oppStatusCode) {
  2204. $statusOppList[$oppStatus]['code'] = $oppStatusCode;
  2205. $statusOppList[$oppStatus]['color'] = isset($theme_datacolor[$themeColorId]) ? implode(', ', $theme_datacolor[$themeColorId]) : '';
  2206. }
  2207. $themeColorId++;
  2208. }
  2209. }
  2210. $projectstatic = new Project($db);
  2211. $thirdpartystatic = new Societe($db);
  2212. $sortfield = '';
  2213. $sortorder = '';
  2214. $project_year_filter = 0;
  2215. $title = $langs->trans("Projects");
  2216. if (strcmp($status, '') && $status >= 0) {
  2217. $title = $langs->trans("Projects").' '.$langs->trans($projectstatic->labelStatus[$status]);
  2218. }
  2219. print '<!-- print_projecttasks_array -->';
  2220. print '<div class="div-table-responsive-no-min">';
  2221. print '<table class="noborder centpercent">';
  2222. $sql = " FROM ".MAIN_DB_PREFIX."projet as p";
  2223. if ($mytasks) {
  2224. $sql .= ", ".MAIN_DB_PREFIX."projet_task as t";
  2225. $sql .= ", ".MAIN_DB_PREFIX."element_contact as ec";
  2226. $sql .= ", ".MAIN_DB_PREFIX."c_type_contact as ctc";
  2227. } else {
  2228. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet_task as t ON p.rowid = t.fk_projet";
  2229. }
  2230. $sql .= " WHERE p.entity IN (".getEntity('project').")";
  2231. $sql .= " AND p.rowid IN (".$db->sanitize($projectsListId).")";
  2232. if ($socid) {
  2233. $sql .= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".((int) $socid).")";
  2234. }
  2235. if ($mytasks) {
  2236. $sql .= " AND p.rowid = t.fk_projet";
  2237. $sql .= " AND ec.element_id = t.rowid";
  2238. $sql .= " AND ec.fk_socpeople = ".((int) $user->id);
  2239. $sql .= " AND ec.fk_c_type_contact = ctc.rowid"; // Replace the 2 lines with ec.fk_c_type_contact in $arrayidtypeofcontact
  2240. $sql .= " AND ctc.element = 'project_task'";
  2241. }
  2242. if ($status >= 0) {
  2243. $sql .= " AND p.fk_statut = ".(int) $status;
  2244. }
  2245. if (getDolGlobalString('PROJECT_LIMIT_YEAR_RANGE')) {
  2246. $project_year_filter = GETPOST("project_year_filter");
  2247. //Check if empty or invalid year. Wildcard ignores the sql check
  2248. if ($project_year_filter != "*") {
  2249. if (empty($project_year_filter) || !ctype_digit($project_year_filter)) {
  2250. $project_year_filter = date("Y");
  2251. }
  2252. $sql .= " AND (p.dateo IS NULL OR p.dateo <= ".$db->idate(dol_get_last_day($project_year_filter, 12, false)).")";
  2253. $sql .= " AND (p.datee IS NULL OR p.datee >= ".$db->idate(dol_get_first_day($project_year_filter, 1, false)).")";
  2254. }
  2255. }
  2256. // Get id of project we must show tasks
  2257. $arrayidofprojects = array();
  2258. $sql1 = "SELECT p.rowid as projectid";
  2259. $sql1 .= $sql;
  2260. $resql = $db->query($sql1);
  2261. if ($resql) {
  2262. $i = 0;
  2263. $num = $db->num_rows($resql);
  2264. while ($i < $num) {
  2265. $objp = $db->fetch_object($resql);
  2266. $arrayidofprojects[$objp->projectid] = $objp->projectid;
  2267. $i++;
  2268. }
  2269. } else {
  2270. dol_print_error($db);
  2271. }
  2272. if (empty($arrayidofprojects)) {
  2273. $arrayidofprojects[0] = -1;
  2274. }
  2275. // Get list of project with calculation on tasks
  2276. $sql2 = "SELECT p.rowid as projectid, p.ref, p.title, p.fk_soc,";
  2277. $sql2 .= " s.rowid as socid, s.nom as socname, s.name_alias,";
  2278. $sql2 .= " s.code_client, s.code_compta, s.client,";
  2279. $sql2 .= " s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur,";
  2280. $sql2 .= " s.logo, s.email, s.entity,";
  2281. $sql2 .= " p.fk_user_creat, p.public, p.fk_statut as status, p.fk_opp_status as opp_status, p.opp_percent, p.opp_amount,";
  2282. $sql2 .= " p.dateo, p.datee,";
  2283. $sql2 .= " COUNT(t.rowid) as nb, SUM(t.planned_workload) as planned_workload, SUM(t.planned_workload * t.progress / 100) as declared_progess_workload";
  2284. $sql2 .= " FROM ".MAIN_DB_PREFIX."projet as p";
  2285. $sql2 .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = p.fk_soc";
  2286. $sql2 .= " LEFT JOIN ".MAIN_DB_PREFIX."projet_task as t ON p.rowid = t.fk_projet";
  2287. $sql2 .= " WHERE p.rowid IN (".$db->sanitize(join(',', $arrayidofprojects)).")";
  2288. $sql2 .= " GROUP BY p.rowid, p.ref, p.title, p.fk_soc, s.rowid, s.nom, s.name_alias, s.code_client, s.code_compta, s.client, s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur,";
  2289. $sql2 .= " s.logo, s.email, s.entity, p.fk_user_creat, p.public, p.fk_statut, p.fk_opp_status, p.opp_percent, p.opp_amount, p.dateo, p.datee";
  2290. $sql2 .= " ORDER BY p.title, p.ref";
  2291. $resql = $db->query($sql2);
  2292. if ($resql) {
  2293. $othernb = 0;
  2294. $total_task = 0;
  2295. $total_opp_amount = 0;
  2296. $ponderated_opp_amount = 0;
  2297. $total_plannedworkload = 0;
  2298. $total_declaredprogressworkload = 0;
  2299. $num = $db->num_rows($resql);
  2300. $nbofloop = min($num, (!getDolGlobalString('MAIN_MAXLIST_OVERLOAD') ? 500 : $conf->global->MAIN_MAXLIST_OVERLOAD));
  2301. $i = 0;
  2302. print '<tr class="liste_titre">';
  2303. print_liste_field_titre($title.'<a href="'.DOL_URL_ROOT.'/projet/list.php?search_status='.((int) $status).'"><span class="badge marginleftonlyshort">'.$num.'</span></a>', $_SERVER["PHP_SELF"], "", "", "", "", $sortfield, $sortorder);
  2304. print_liste_field_titre("ThirdParty", $_SERVER["PHP_SELF"], "", "", "", "", $sortfield, $sortorder);
  2305. if (getDolGlobalString('PROJECT_USE_OPPORTUNITIES')) {
  2306. if (!in_array('prospectionstatus', $hiddenfields)) {
  2307. print_liste_field_titre("OpportunityStatus", "", "", "", "", 'style="max-width: 100px"', $sortfield, $sortorder, 'center ');
  2308. }
  2309. print_liste_field_titre($form->textwithpicto($langs->trans("Amount"), $langs->trans("OpportunityAmount").' ('.$langs->trans("Tooltip").' = '.$langs->trans("OpportunityWeightedAmount").')'), "", "", "", "", 'style="max-width: 100px"', $sortfield, $sortorder, 'right ');
  2310. //print_liste_field_titre('OpportunityWeightedAmount', '', '', '', '', 'align="right"', $sortfield, $sortorder);
  2311. }
  2312. if (!getDolGlobalString('PROJECT_HIDE_TASKS')) {
  2313. print_liste_field_titre("Tasks", "", "", "", "", 'align="right"', $sortfield, $sortorder);
  2314. if (!in_array('plannedworkload', $hiddenfields)) {
  2315. print_liste_field_titre("PlannedWorkload", "", "", "", "", 'style="max-width: 100px"', $sortfield, $sortorder, 'right ');
  2316. }
  2317. if (!in_array('declaredprogress', $hiddenfields)) {
  2318. print_liste_field_titre("%", "", "", "", "", '', $sortfield, $sortorder, 'right ', $langs->trans("ProgressDeclared"));
  2319. }
  2320. }
  2321. if (!in_array('projectstatus', $hiddenfields)) {
  2322. print_liste_field_titre("Status", "", "", "", "", '', $sortfield, $sortorder, 'right ');
  2323. }
  2324. print "</tr>\n";
  2325. while ($i < $nbofloop) {
  2326. $objp = $db->fetch_object($resql);
  2327. if ($max && $i >= $max) {
  2328. $othernb++;
  2329. $i++;
  2330. $total_task += $objp->nb;
  2331. $total_opp_amount += $objp->opp_amount;
  2332. $opp_weighted_amount = $objp->opp_percent * $objp->opp_amount / 100;
  2333. $ponderated_opp_amount += price2num($opp_weighted_amount);
  2334. $plannedworkload = $objp->planned_workload;
  2335. $total_plannedworkload += $plannedworkload;
  2336. $declaredprogressworkload = $objp->declared_progess_workload;
  2337. $total_declaredprogressworkload += $declaredprogressworkload;
  2338. continue;
  2339. }
  2340. $projectstatic->id = $objp->projectid;
  2341. $projectstatic->user_author_id = $objp->fk_user_creat;
  2342. $projectstatic->public = $objp->public;
  2343. // Check is user has read permission on project
  2344. $userAccess = $projectstatic->restrictedProjectArea($user);
  2345. if ($userAccess >= 0) {
  2346. $projectstatic->ref = $objp->ref;
  2347. $projectstatic->status = $objp->status;
  2348. $projectstatic->title = $objp->title;
  2349. $projectstatic->date_end = $db->jdate($objp->datee);
  2350. $projectstatic->date_start = $db->jdate($objp->dateo);
  2351. print '<tr class="oddeven">';
  2352. print '<td class="tdoverflowmax150">';
  2353. print $projectstatic->getNomUrl(1, '', 0, '', '-', 0, -1, 'nowraponall');
  2354. if (!in_array('projectlabel', $hiddenfields)) {
  2355. print '<br><span class="opacitymedium small">'.dol_escape_htmltag($objp->title).'</span>';
  2356. }
  2357. print '</td>';
  2358. print '<td class="nowraponall tdoverflowmax100">';
  2359. if ($objp->fk_soc > 0) {
  2360. $thirdpartystatic->id = $objp->socid;
  2361. $thirdpartystatic->name = $objp->socname;
  2362. //$thirdpartystatic->name_alias = $objp->name_alias;
  2363. //$thirdpartystatic->code_client = $objp->code_client;
  2364. $thirdpartystatic->code_compta = $objp->code_compta;
  2365. $thirdpartystatic->client = $objp->client;
  2366. //$thirdpartystatic->code_fournisseur = $objp->code_fournisseur;
  2367. $thirdpartystatic->code_compta_fournisseur = $objp->code_compta_fournisseur;
  2368. $thirdpartystatic->fournisseur = $objp->fournisseur;
  2369. $thirdpartystatic->logo = $objp->logo;
  2370. $thirdpartystatic->email = $objp->email;
  2371. $thirdpartystatic->entity = $objp->entity;
  2372. print $thirdpartystatic->getNomUrl(1);
  2373. }
  2374. print '</td>';
  2375. if (getDolGlobalString('PROJECT_USE_OPPORTUNITIES')) {
  2376. if (!in_array('prospectionstatus', $hiddenfields)) {
  2377. print '<td class="center tdoverflowmax75">';
  2378. // Because color of prospection status has no meaning yet, it is used if hidden constant is set
  2379. if (!getDolGlobalString('USE_COLOR_FOR_PROSPECTION_STATUS')) {
  2380. $oppStatusCode = dol_getIdFromCode($db, $objp->opp_status, 'c_lead_status', 'rowid', 'code');
  2381. if ($langs->trans("OppStatus".$oppStatusCode) != "OppStatus".$oppStatusCode) {
  2382. print $langs->trans("OppStatus".$oppStatusCode);
  2383. }
  2384. } else {
  2385. if (isset($statusOppList[$objp->opp_status])) {
  2386. $oppStatusCode = $statusOppList[$objp->opp_status]['code'];
  2387. $oppStatusColor = $statusOppList[$objp->opp_status]['color'];
  2388. } else {
  2389. $oppStatusCode = dol_getIdFromCode($db, $objp->opp_status, 'c_lead_status', 'rowid', 'code');
  2390. $oppStatusColor = '';
  2391. }
  2392. if ($oppStatusCode) {
  2393. if (!empty($oppStatusColor)) {
  2394. print '<a href="'.dol_buildpath('/projet/list.php?search_opp_status='.$objp->opp_status, 1).'" style="display: inline-block; width: 4px; border: 5px solid rgb('.$oppStatusColor.'); border-radius: 2px;" title="'.$langs->trans("OppStatus".$oppStatusCode).'"></a>';
  2395. } else {
  2396. print '<a href="'.dol_buildpath('/projet/list.php?search_opp_status='.$objp->opp_status, 1).'" title="'.$langs->trans("OppStatus".$oppStatusCode).'">'.$oppStatusCode.'</a>';
  2397. }
  2398. }
  2399. }
  2400. print '</td>';
  2401. }
  2402. print '<td class="right">';
  2403. if ($objp->opp_percent && $objp->opp_amount) {
  2404. $opp_weighted_amount = $objp->opp_percent * $objp->opp_amount / 100;
  2405. $alttext = $langs->trans("OpportunityWeightedAmount").' '.price($opp_weighted_amount, 0, '', 1, -1, 0, $conf->currency);
  2406. $ponderated_opp_amount += price2num($opp_weighted_amount);
  2407. }
  2408. if ($objp->opp_amount) {
  2409. print '<span class="amount" title="'.$alttext.'">'.$form->textwithpicto(price($objp->opp_amount, 0, '', 1, -1, 0), $alttext).'</span>';
  2410. }
  2411. print '</td>';
  2412. }
  2413. if (!getDolGlobalString('PROJECT_HIDE_TASKS')) {
  2414. print '<td class="right">'.$objp->nb.'</td>';
  2415. $plannedworkload = $objp->planned_workload;
  2416. $total_plannedworkload += $plannedworkload;
  2417. if (!in_array('plannedworkload', $hiddenfields)) {
  2418. print '<td class="right nowraponall">'.($plannedworkload ? convertSecondToTime($plannedworkload) : '').'</td>';
  2419. }
  2420. if (!in_array('declaredprogress', $hiddenfields)) {
  2421. $declaredprogressworkload = $objp->declared_progess_workload;
  2422. $total_declaredprogressworkload += $declaredprogressworkload;
  2423. print '<td class="right nowraponall">';
  2424. //print $objp->planned_workload.'-'.$objp->declared_progess_workload."<br>";
  2425. print($plannedworkload ? round(100 * $declaredprogressworkload / $plannedworkload, 0).'%' : '');
  2426. print '</td>';
  2427. }
  2428. }
  2429. if (!in_array('projectstatus', $hiddenfields)) {
  2430. print '<td class="right">';
  2431. print $projectstatic->getLibStatut(3);
  2432. print '</td>';
  2433. }
  2434. print "</tr>\n";
  2435. $total_task += $objp->nb;
  2436. $total_opp_amount += $objp->opp_amount;
  2437. }
  2438. $i++;
  2439. }
  2440. if ($othernb) {
  2441. print '<tr class="oddeven">';
  2442. print '<td class="nowrap" colspan="5">';
  2443. print '<span class="opacitymedium">'.$langs->trans("More").'...'.($othernb < $maxofloop ? ' ('.$othernb.')' : '').'</span>';
  2444. print '</td>';
  2445. print "</tr>\n";
  2446. }
  2447. print '<tr class="liste_total">';
  2448. print '<td>'.$langs->trans("Total")."</td><td></td>";
  2449. if (getDolGlobalString('PROJECT_USE_OPPORTUNITIES')) {
  2450. if (!in_array('prospectionstatus', $hiddenfields)) {
  2451. print '<td class="liste_total"></td>';
  2452. }
  2453. print '<td class="liste_total right">';
  2454. //$form->textwithpicto(price($ponderated_opp_amount, 0, '', 1, -1, -1, $conf->currency), $langs->trans("OpportunityPonderatedAmountDesc"), 1);
  2455. print $form->textwithpicto(price($total_opp_amount, 0, '', 1, -1, 0), $langs->trans("OpportunityPonderatedAmountDesc").' : '.price($ponderated_opp_amount, 0, '', 1, -1, 0, $conf->currency));
  2456. print '</td>';
  2457. }
  2458. if (!getDolGlobalString('PROJECT_HIDE_TASKS')) {
  2459. print '<td class="liste_total right">'.$total_task.'</td>';
  2460. if (!in_array('plannedworkload', $hiddenfields)) {
  2461. print '<td class="liste_total right">'.($total_plannedworkload ? convertSecondToTime($total_plannedworkload) : '').'</td>';
  2462. }
  2463. if (!in_array('declaredprogress', $hiddenfields)) {
  2464. print '<td class="liste_total right">'.($total_plannedworkload ? round(100 * $total_declaredprogressworkload / $total_plannedworkload, 0).'%' : '').'</td>';
  2465. }
  2466. }
  2467. if (!in_array('projectstatus', $hiddenfields)) {
  2468. print '<td class="liste_total"></td>';
  2469. }
  2470. print '</tr>';
  2471. $db->free($resql);
  2472. } else {
  2473. dol_print_error($db);
  2474. }
  2475. print "</table>";
  2476. print '</div>';
  2477. if (getDolGlobalString('PROJECT_LIMIT_YEAR_RANGE')) {
  2478. //Add the year filter input
  2479. print '<form method="get" action="'.$_SERVER["PHP_SELF"].'">';
  2480. print '<table width="100%">';
  2481. print '<tr>';
  2482. print '<td>'.$langs->trans("Year").'</td>';
  2483. print '<td class="right"><input type="text" size="4" class="flat" name="project_year_filter" value="'.$project_year_filter.'"/>';
  2484. print "</tr>\n";
  2485. print '</table></form>';
  2486. }
  2487. }
  2488. /**
  2489. * @param Task $task the task object
  2490. * @param bool|string $label true = auto, false = dont display, string = replace output
  2491. * @param bool|string $progressNumber true = auto, false = dont display, string = replace output
  2492. * @param bool $hideOnProgressNull hide if progress is null
  2493. * @param bool $spaced used to add space at bottom (made by css)
  2494. * @return string
  2495. * @see getTaskProgressBadge()
  2496. */
  2497. function getTaskProgressView($task, $label = true, $progressNumber = true, $hideOnProgressNull = false, $spaced = false)
  2498. {
  2499. global $langs, $conf;
  2500. $out = '';
  2501. $plannedworkloadoutputformat = 'allhourmin';
  2502. $timespentoutputformat = 'allhourmin';
  2503. if (getDolGlobalString('PROJECT_PLANNED_WORKLOAD_FORMAT')) {
  2504. $plannedworkloadoutputformat = $conf->global->PROJECT_PLANNED_WORKLOAD_FORMAT;
  2505. }
  2506. if (getDolGlobalString('PROJECT_TIMES_SPENT_FORMAT')) {
  2507. $timespentoutputformat = $conf->global->PROJECT_TIME_SPENT_FORMAT;
  2508. }
  2509. if (empty($task->progress) && !empty($hideOnProgressNull)) {
  2510. return '';
  2511. }
  2512. $spaced = !empty($spaced) ? 'spaced' : '';
  2513. $diff = '';
  2514. // define progress color according to time spend vs workload
  2515. $progressBarClass = 'progress-bar-info';
  2516. $progressCalculated = 0;
  2517. if ($task->planned_workload) {
  2518. $progressCalculated = round(100 * (float) $task->duration_effective / (float) $task->planned_workload, 2);
  2519. // this conf is actually hidden, by default we use 10% for "be carefull or warning"
  2520. $warningRatio = getDolGlobalString('PROJECT_TIME_SPEND_WARNING_PERCENT') ? (1 + $conf->global->PROJECT_TIME_SPEND_WARNING_PERCENT / 100) : 1.10;
  2521. $diffTitle = '<br>'.$langs->trans('ProgressDeclared').' : '.$task->progress.(isset($task->progress) ? '%' : '');
  2522. $diffTitle .= '<br>'.$langs->trans('ProgressCalculated').' : '.$progressCalculated.(isset($progressCalculated) ? '%' : '');
  2523. //var_dump($progressCalculated.' '.$warningRatio.' '.$task->progress.' '.floatval($task->progress * $warningRatio));
  2524. if ((float) $progressCalculated > (float) ($task->progress * $warningRatio)) {
  2525. $progressBarClass = 'progress-bar-danger';
  2526. $title = $langs->trans('TheReportedProgressIsLessThanTheCalculatedProgressionByX', abs($task->progress - $progressCalculated).' '.$langs->trans("point"));
  2527. $diff = '<span class="text-danger classfortooltip paddingrightonly" title="'.dol_htmlentities($title.$diffTitle).'" ><i class="fa fa-caret-down"></i> '.($task->progress - $progressCalculated).'%</span>';
  2528. } elseif ((float) $progressCalculated > (float) $task->progress) { // warning if close at 10%
  2529. $progressBarClass = 'progress-bar-warning';
  2530. $title = $langs->trans('TheReportedProgressIsLessThanTheCalculatedProgressionByX', abs($task->progress - $progressCalculated).' '.$langs->trans("point"));
  2531. $diff = '<span class="text-warning classfortooltip paddingrightonly" title="'.dol_htmlentities($title.$diffTitle).'" ><i class="fa fa-caret-left"></i> '.($task->progress - $progressCalculated).'%</span>';
  2532. } else {
  2533. $progressBarClass = 'progress-bar-success';
  2534. $title = $langs->trans('TheReportedProgressIsMoreThanTheCalculatedProgressionByX', ($task->progress - $progressCalculated).' '.$langs->trans("point"));
  2535. $diff = '<span class="text-success classfortooltip paddingrightonly" title="'.dol_htmlentities($title.$diffTitle).'" ><i class="fa fa-caret-up"></i> '.($task->progress - $progressCalculated).'%</span>';
  2536. }
  2537. }
  2538. $out .= '<div class="progress-group">';
  2539. if ($label !== false) {
  2540. $out .= ' <span class="progress-text">';
  2541. if ($label !== true) {
  2542. $out .= $label; // replace label by param
  2543. } else {
  2544. $out .= $task->getNomUrl(1).' '.dol_htmlentities($task->label);
  2545. }
  2546. $out .= ' </span>';
  2547. }
  2548. if ($progressNumber !== false) {
  2549. $out .= ' <span class="progress-number">';
  2550. if ($progressNumber !== true) {
  2551. $out .= $progressNumber; // replace label by param
  2552. } else {
  2553. if ($task->hasDelay()) {
  2554. $out .= img_warning($langs->trans("Late")).' ';
  2555. }
  2556. $url = DOL_URL_ROOT.'/projet/tasks/time.php?id='.$task->id;
  2557. $out .= !empty($diff) ? $diff.' ' : '';
  2558. $out .= '<a href="'.$url.'" >';
  2559. $out .= '<b title="'.$langs->trans('TimeSpent').'" >';
  2560. if ($task->duration_effective) {
  2561. $out .= convertSecondToTime($task->duration_effective, $timespentoutputformat);
  2562. } else {
  2563. $out .= '--:--';
  2564. }
  2565. $out .= '</b>';
  2566. $out .= '</a>';
  2567. $out .= ' / ';
  2568. $out .= '<a href="'.$url.'" >';
  2569. $out .= '<span title="'.$langs->trans('PlannedWorkload').'" >';
  2570. if ($task->planned_workload) {
  2571. $out .= convertSecondToTime($task->planned_workload, $plannedworkloadoutputformat);
  2572. } else {
  2573. $out .= '--:--';
  2574. }
  2575. $out .= '</a>';
  2576. }
  2577. $out .= ' </span>';
  2578. }
  2579. $out .= '</span>';
  2580. $out .= ' <div class="progress sm '.$spaced.'">';
  2581. $diffval = (float) $task->progress - (float) $progressCalculated;
  2582. if ($diffval >= 0) {
  2583. // good
  2584. $out .= ' <div class="progress-bar '.$progressBarClass.'" style="width: '.(float) $task->progress.'%" title="'.(float) $task->progress.'%">';
  2585. if (!empty($task->progress)) {
  2586. $out .= ' <div class="progress-bar progress-bar-consumed" style="width: '.(float) ($progressCalculated / ((float) $task->progress == 0 ? 1 : $task->progress) * 100).'%" title="'.(float) $progressCalculated.'%"></div>';
  2587. }
  2588. $out .= ' </div>';
  2589. } else {
  2590. // bad
  2591. $out .= ' <div class="progress-bar progress-bar-consumed-late" style="width: '.(float) $progressCalculated.'%" title="'.(float) $progressCalculated.'%">';
  2592. $out .= ' <div class="progress-bar '.$progressBarClass.'" style="width: '.($task->progress ? (float) ($task->progress / ((float) $progressCalculated == 0 ? 1 : $progressCalculated) * 100).'%' : '1px').'" title="'.(float) $task->progress.'%"></div>';
  2593. $out .= ' </div>';
  2594. }
  2595. $out .= ' </div>';
  2596. $out .= '</div>';
  2597. return $out;
  2598. }
  2599. /**
  2600. * @param Task $task the task object
  2601. * @param string $label empty = auto (progress), string = replace output
  2602. * @param string $tooltip empty = auto , string = replace output
  2603. * @return string
  2604. * @see getTaskProgressView()
  2605. */
  2606. function getTaskProgressBadge($task, $label = '', $tooltip = '')
  2607. {
  2608. global $conf, $langs;
  2609. $out = '';
  2610. $badgeClass = '';
  2611. if ($task->progress != '') {
  2612. // TODO : manage 100%
  2613. // define color according to time spend vs workload
  2614. $badgeClass = 'badge ';
  2615. if ($task->planned_workload) {
  2616. $progressCalculated = round(100 * (float) $task->duration_effective / (float) $task->planned_workload, 2);
  2617. // this conf is actually hidden, by default we use 10% for "be carefull or warning"
  2618. $warningRatio = getDolGlobalString('PROJECT_TIME_SPEND_WARNING_PERCENT') ? (1 + $conf->global->PROJECT_TIME_SPEND_WARNING_PERCENT / 100) : 1.10;
  2619. if ((float) $progressCalculated > (float) ($task->progress * $warningRatio)) {
  2620. $badgeClass .= 'badge-danger';
  2621. if (empty($tooltip)) {
  2622. $tooltip = $task->progress.'% < '.$langs->trans("TimeConsumed").' '.$progressCalculated.'%';
  2623. }
  2624. } elseif ((float) $progressCalculated > (float) $task->progress) { // warning if close at 10%
  2625. $badgeClass .= 'badge-warning';
  2626. if (empty($tooltip)) {
  2627. $tooltip = $task->progress.'% < '.$langs->trans("TimeConsumed").' '.$progressCalculated.'%';
  2628. }
  2629. } else {
  2630. $badgeClass .= 'badge-success';
  2631. if (empty($tooltip)) {
  2632. $tooltip = $task->progress.'% >= '.$langs->trans("TimeConsumed").' '.$progressCalculated.'%';
  2633. }
  2634. }
  2635. }
  2636. }
  2637. $title = '';
  2638. if (!empty($tooltip)) {
  2639. $badgeClass .= ' classfortooltip';
  2640. $title = 'title="'.dol_htmlentities($tooltip).'"';
  2641. }
  2642. if (empty($label)) {
  2643. $label = $task->progress.' %';
  2644. }
  2645. if (!empty($label)) {
  2646. $out = '<span class="'.$badgeClass.'" '.$title.' >'.$label.'</span>';
  2647. }
  2648. return $out;
  2649. }