project.lib.php 118 KB

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