project.lib.php 110 KB

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