project.lib.php 118 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027
  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. $fk_tasks = [];
  562. foreach($lines as $line)
  563. $fk_tasks[] = $line->id;
  564. for ($i = 0; $i < $numlines; $i++) {
  565. if ($parent == 0 && $level >= 0) {
  566. $level = 0; // if $level = -1, we dont' use sublevel recursion, we show all lines
  567. }
  568. // Process line
  569. // print "i:".$i."-".$lines[$i]->fk_project.'<br>';
  570. if ($lines[$i]->fk_task_parent == $parent || (getDolGlobalInt('PROJECT_TASK_SEARCH_SHOW_WO_PARENT') && !in_array($lines[$i]->fk_task_parent, $fk_tasks) && $parent == 0) || $level < 0) { // if $level = -1, we dont' use sublevel recursion, we show all lines
  571. // Show task line.
  572. $showline = 1;
  573. $showlineingray = 0;
  574. // If there is filters to use
  575. if (is_array($taskrole)) {
  576. // If task not legitimate to show, search if a legitimate task exists later in tree
  577. if (!isset($taskrole[$lines[$i]->id]) && $lines[$i]->id != $lines[$i]->fk_task_parent) {
  578. // So search if task has a subtask legitimate to show
  579. $foundtaskforuserdeeper = 0;
  580. searchTaskInChild($foundtaskforuserdeeper, $lines[$i]->id, $lines, $taskrole);
  581. //print '$foundtaskforuserpeeper='.$foundtaskforuserdeeper.'<br>';
  582. if ($foundtaskforuserdeeper > 0) {
  583. $showlineingray = 1; // We will show line but in gray
  584. } else {
  585. $showline = 0; // No reason to show line
  586. }
  587. }
  588. } else {
  589. // 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
  590. // or into all other projects if user has permission to).
  591. if (!$user->hasRight('projet', 'all', 'lire')) {
  592. // User is not allowed on this project and project is not public, so we hide line
  593. if (!in_array($lines[$i]->fk_project, $projectsArrayId)) {
  594. // Note that having a user assigned to a task into a project user has no permission on, should not be possible
  595. // because assignement on task can be done only on contact of project.
  596. // If assignement was done and after, was removed from contact of project, then we can hide the line.
  597. $showline = 0;
  598. }
  599. }
  600. }
  601. if ($showline) {
  602. // Break on a new project
  603. if ($parent == 0 && $lines[$i]->fk_project != $lastprojectid) {
  604. $var = !$var;
  605. $lastprojectid = $lines[$i]->fk_project;
  606. }
  607. print '<tr class="oddeven" id="row-'.$lines[$i]->id.'">'."\n";
  608. $projectstatic->id = $lines[$i]->fk_project;
  609. $projectstatic->ref = $lines[$i]->projectref;
  610. $projectstatic->public = $lines[$i]->public;
  611. $projectstatic->title = $lines[$i]->projectlabel;
  612. $projectstatic->usage_bill_time = $lines[$i]->usage_bill_time;
  613. $projectstatic->status = $lines[$i]->projectstatus;
  614. $taskstatic->id = $lines[$i]->id;
  615. $taskstatic->ref = $lines[$i]->ref;
  616. $taskstatic->label = (!empty($taskrole[$lines[$i]->id]) ? $langs->trans("YourRole").': '.$taskrole[$lines[$i]->id] : '');
  617. $taskstatic->projectstatus = $lines[$i]->projectstatus;
  618. $taskstatic->progress = $lines[$i]->progress;
  619. $taskstatic->fk_statut = $lines[$i]->status;
  620. $taskstatic->date_start = $lines[$i]->date_start;
  621. $taskstatic->date_end = $lines[$i]->date_end;
  622. $taskstatic->datee = $lines[$i]->date_end; // deprecated
  623. $taskstatic->planned_workload = $lines[$i]->planned_workload;
  624. $taskstatic->duration_effective = $lines[$i]->duration_effective;
  625. $taskstatic->budget_amount = $lines[$i]->budget_amount;
  626. // Action column
  627. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  628. print '<td class="nowrap center">';
  629. $selected = 0;
  630. if (in_array($lines[$i]->id, $arrayofselected)) {
  631. $selected = 1;
  632. }
  633. print '<input id="cb' . $lines[$i]->id . '" class="flat checkforselect" type="checkbox" name="toselect[]" value="' . $lines[$i]->id . '"' . ($selected ? ' checked="checked"' : '') . '>';
  634. print '</td>';
  635. }
  636. if ($showproject) {
  637. // Project ref
  638. print '<td class="nowraponall">';
  639. //if ($showlineingray) print '<i>';
  640. if ($lines[$i]->public || in_array($lines[$i]->fk_project, $projectsArrayId) || $user->hasRight('projet', 'all', 'lire')) {
  641. print $projectstatic->getNomUrl(1);
  642. } else {
  643. print $projectstatic->getNomUrl(1, 'nolink');
  644. }
  645. //if ($showlineingray) print '</i>';
  646. print "</td>";
  647. // Project status
  648. print '<td>';
  649. $projectstatic->statut = $lines[$i]->projectstatus;
  650. print $projectstatic->getLibStatut(2);
  651. print "</td>";
  652. }
  653. // Ref of task
  654. if (count($arrayfields) > 0 && !empty($arrayfields['t.ref']['checked'])) {
  655. print '<td class="nowraponall">';
  656. if ($showlineingray) {
  657. print '<i>'.img_object('', 'projecttask').' '.$lines[$i]->ref.'</i>';
  658. } else {
  659. print $taskstatic->getNomUrl(1, 'withproject');
  660. }
  661. print '</td>';
  662. }
  663. // Title of task
  664. if (count($arrayfields) > 0 && !empty($arrayfields['t.label']['checked'])) {
  665. $labeltoshow = '';
  666. if ($showlineingray) {
  667. $labeltoshow .= '<i>';
  668. }
  669. //else print '<a href="'.DOL_URL_ROOT.'/projet/tasks/task.php?id='.$lines[$i]->id.'&withproject=1">';
  670. for ($k = 0; $k < $level; $k++) {
  671. $labeltoshow .= '<div class="marginleftonly">';
  672. }
  673. $labeltoshow .= dol_escape_htmltag($lines[$i]->label);
  674. for ($k = 0; $k < $level; $k++) {
  675. $labeltoshow .= '</div>';
  676. }
  677. if ($showlineingray) {
  678. $labeltoshow .= '</i>';
  679. }
  680. print '<td class="tdoverflowmax200" title="'.dol_escape_htmltag($labeltoshow).'">';
  681. print $labeltoshow;
  682. print "</td>\n";
  683. }
  684. if (count($arrayfields) > 0 && !empty($arrayfields['t.description']['checked'])) {
  685. print '<td class="tdoverflowmax200" title="'.dol_escape_htmltag($lines[$i]->description).'">';
  686. print $lines[$i]->description;
  687. print "</td>\n";
  688. }
  689. // Date start
  690. if (count($arrayfields) > 0 && !empty($arrayfields['t.dateo']['checked'])) {
  691. print '<td class="center nowraponall">';
  692. print dol_print_date($lines[$i]->date_start, 'dayhour');
  693. print '</td>';
  694. }
  695. // Date end
  696. if (count($arrayfields) > 0 && !empty($arrayfields['t.datee']['checked'])) {
  697. print '<td class="center nowraponall">';
  698. print dol_print_date($lines[$i]->date_end, 'dayhour');
  699. if ($taskstatic->hasDelay()) {
  700. print img_warning($langs->trans("Late"));
  701. }
  702. print '</td>';
  703. }
  704. $plannedworkloadoutputformat = 'allhourmin';
  705. $timespentoutputformat = 'allhourmin';
  706. if (getDolGlobalString('PROJECT_PLANNED_WORKLOAD_FORMAT')) {
  707. $plannedworkloadoutputformat = $conf->global->PROJECT_PLANNED_WORKLOAD_FORMAT;
  708. }
  709. if (getDolGlobalString('PROJECT_TIMES_SPENT_FORMAT')) {
  710. $timespentoutputformat = $conf->global->PROJECT_TIME_SPENT_FORMAT;
  711. }
  712. // Planned Workload (in working hours)
  713. if (count($arrayfields) > 0 && !empty($arrayfields['t.planned_workload']['checked'])) {
  714. print '<td class="right">';
  715. $fullhour = convertSecondToTime($lines[$i]->planned_workload, $plannedworkloadoutputformat);
  716. $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
  717. if ($lines[$i]->planned_workload != '') {
  718. print $fullhour;
  719. // TODO Add delay taking account of working hours per day and working day per week
  720. //if ($workingdelay != $fullhour) print '<br>('.$workingdelay.')';
  721. }
  722. //else print '--:--';
  723. print '</td>';
  724. }
  725. // Time spent
  726. if (count($arrayfields) > 0 && !empty($arrayfields['t.duration_effective']['checked'])) {
  727. print '<td class="right">';
  728. if ($showlineingray) {
  729. print '<i>';
  730. } else {
  731. print '<a href="'.DOL_URL_ROOT.'/projet/tasks/time.php?id='.$lines[$i]->id.($showproject ? '' : '&withproject=1').'">';
  732. }
  733. if ($lines[$i]->duration_effective) {
  734. print convertSecondToTime($lines[$i]->duration_effective, $timespentoutputformat);
  735. } else {
  736. print '--:--';
  737. }
  738. if ($showlineingray) {
  739. print '</i>';
  740. } else {
  741. print '</a>';
  742. }
  743. print '</td>';
  744. }
  745. // Progress calculated (Note: ->duration_effective is time spent)
  746. if (count($arrayfields) > 0 && !empty($arrayfields['t.progress_calculated']['checked'])) {
  747. $s = '';
  748. $shtml = '';
  749. if ($lines[$i]->planned_workload || $lines[$i]->duration_effective) {
  750. if ($lines[$i]->planned_workload) {
  751. $s = round(100 * $lines[$i]->duration_effective / $lines[$i]->planned_workload, 2).' %';
  752. $shtml = $s;
  753. } else {
  754. $s = $langs->trans('WorkloadNotDefined');
  755. $shtml = '<span class="opacitymedium">'.$s.'</span>';
  756. }
  757. }
  758. print '<td class="right tdoverflowmax100" title="'.dol_escape_htmltag($s).'">';
  759. print $shtml;
  760. print '</td>';
  761. }
  762. // Progress declared
  763. if (count($arrayfields) > 0 && !empty($arrayfields['t.progress']['checked'])) {
  764. print '<td class="right">';
  765. if ($lines[$i]->progress != '') {
  766. print getTaskProgressBadge($taskstatic);
  767. }
  768. print '</td>';
  769. }
  770. // resume
  771. if (count($arrayfields) > 0 && !empty($arrayfields['t.progress_summary']['checked'])) {
  772. print '<td class="right">';
  773. if ($lines[$i]->progress != '' && $lines[$i]->duration_effective) {
  774. print getTaskProgressView($taskstatic, false, false);
  775. }
  776. print '</td>';
  777. }
  778. if ($showbilltime) {
  779. // Time not billed
  780. if (count($arrayfields) > 0 && !empty($arrayfields['t.tobill']['checked'])) {
  781. print '<td class="right">';
  782. if ($lines[$i]->usage_bill_time) {
  783. print convertSecondToTime($lines[$i]->tobill, 'allhourmin');
  784. $total_projectlinesa_tobill += $lines[$i]->tobill;
  785. } else {
  786. print '<span class="opacitymedium">'.$langs->trans("NA").'</span>';
  787. }
  788. print '</td>';
  789. }
  790. // Time billed
  791. if (count($arrayfields) > 0 && !empty($arrayfields['t.billed']['checked'])) {
  792. print '<td class="right">';
  793. if ($lines[$i]->usage_bill_time) {
  794. print convertSecondToTime($lines[$i]->billed, 'allhourmin');
  795. $total_projectlinesa_billed += $lines[$i]->billed;
  796. } else {
  797. print '<span class="opacitymedium">'.$langs->trans("NA").'</span>';
  798. }
  799. print '</td>';
  800. }
  801. }
  802. // Budget task
  803. if (count($arrayfields) > 0 && !empty($arrayfields['t.budget_amount']['checked'])) {
  804. print '<td class="center">';
  805. if ($lines[$i]->budget_amount) {
  806. print '<span class="amount">'.price($lines[$i]->budget_amount, 0, $langs, 1, 0, 0, $conf->currency).'</span>';
  807. $total_budget_amount += $lines[$i]->budget_amount;
  808. }
  809. print '</td>';
  810. }
  811. // Contacts of task
  812. if (count($arrayfields) > 0 && !empty($arrayfields['c.assigned']['checked'])) {
  813. print '<td class="center">';
  814. $ifisrt = 1;
  815. foreach (array('internal', 'external') as $source) {
  816. //$tab = $lines[$i]->liste_contact(-1, $source);
  817. $tab = $lines[$i]->liste_contact(-1, $source, 0, '', 1);
  818. $numcontact = count($tab);
  819. if (!empty($numcontact)) {
  820. foreach ($tab as $contacttask) {
  821. //var_dump($contacttask);
  822. if ($source == 'internal') {
  823. $c = new User($db);
  824. } else {
  825. $c = new Contact($db);
  826. }
  827. $c->fetch($contacttask['id']);
  828. if (!empty($c->photo)) {
  829. if (get_class($c) == 'User') {
  830. print $c->getNomUrl(-2, '', 0, 0, 24, 1, '', ($ifisrt ? '' : 'notfirst'));
  831. } else {
  832. print $c->getNomUrl(-2, '', 0, '', -1, 0, ($ifisrt ? '' : 'notfirst'));
  833. }
  834. } else {
  835. if (get_class($c) == 'User') {
  836. print $c->getNomUrl(2, '', 0, 0, 24, 1, '', ($ifisrt ? '' : 'notfirst'));
  837. } else {
  838. print $c->getNomUrl(2, '', 0, '', -1, 0, ($ifisrt ? '' : 'notfirst'));
  839. }
  840. }
  841. $ifisrt = 0;
  842. }
  843. }
  844. }
  845. print '</td>';
  846. }
  847. // Extra fields
  848. $extrafieldsobjectkey = $taskstatic->table_element;
  849. $extrafieldsobjectprefix = 'efpt.';
  850. $obj = $lines[$i]->obj;
  851. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  852. // Fields from hook
  853. $parameters = array('arrayfields'=>$arrayfields, 'obj'=>$lines[$i]);
  854. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook
  855. print $hookmanager->resPrint;
  856. // Tick to drag and drop
  857. print '<td class="tdlineupdown center"></td>';
  858. // Action column
  859. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  860. print '<td class="nowrap center">';
  861. $selected = 0;
  862. if (in_array($lines[$i]->id, $arrayofselected)) {
  863. $selected = 1;
  864. }
  865. print '<input id="cb' . $lines[$i]->id . '" class="flat checkforselect" type="checkbox" name="toselect[]" value="' . $lines[$i]->id . '"' . ($selected ? ' checked="checked"' : '') . '>';
  866. print '</td>';
  867. }
  868. print "</tr>\n";
  869. if (!$showlineingray) {
  870. $inc++;
  871. }
  872. if ($level >= 0) { // Call sublevels
  873. $level++;
  874. if ($lines[$i]->id) {
  875. projectLinesa($inc, $lines[$i]->id, $lines, $level, $var, $showproject, $taskrole, $projectsListId, $addordertick, $projectidfortotallink, '', $showbilltime, $arrayfields);
  876. }
  877. $level--;
  878. }
  879. $total_projectlinesa_spent += $lines[$i]->duration_effective;
  880. $total_projectlinesa_planned += $lines[$i]->planned_workload;
  881. if ($lines[$i]->planned_workload) {
  882. $total_projectlinesa_spent_if_planned += $lines[$i]->duration_effective;
  883. }
  884. if ($lines[$i]->planned_workload) {
  885. $total_projectlinesa_declared_if_planned += $lines[$i]->planned_workload * $lines[$i]->progress / 100;
  886. }
  887. }
  888. } else {
  889. //$level--;
  890. }
  891. }
  892. // Total line
  893. if (($total_projectlinesa_planned > 0 || $total_projectlinesa_spent > 0 || $total_projectlinesa_tobill > 0 || $total_projectlinesa_billed > 0 || $total_budget_amount > 0)
  894. && $level <= 0) {
  895. print '<tr class="liste_total nodrag nodrop">';
  896. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  897. print '<td class="liste_total"></td>';
  898. }
  899. print '<td class="liste_total">'.$langs->trans("Total").'</td>';
  900. if ($showproject) {
  901. print '<td></td><td></td>';
  902. }
  903. if (count($arrayfields) > 0 && !empty($arrayfields['t.label']['checked'])) {
  904. print '<td></td>';
  905. }
  906. if (count($arrayfields) > 0 && !empty($arrayfields['t.description']['checked'])) {
  907. print '<td></td>';
  908. }
  909. if (count($arrayfields) > 0 && !empty($arrayfields['t.dateo']['checked'])) {
  910. print '<td></td>';
  911. }
  912. if (count($arrayfields) > 0 && !empty($arrayfields['t.datee']['checked'])) {
  913. print '<td></td>';
  914. }
  915. if (count($arrayfields) > 0 && !empty($arrayfields['t.planned_workload']['checked'])) {
  916. print '<td class="nowrap liste_total right">';
  917. print convertSecondToTime($total_projectlinesa_planned, 'allhourmin');
  918. print '</td>';
  919. }
  920. if (count($arrayfields) > 0 && !empty($arrayfields['t.duration_effective']['checked'])) {
  921. print '<td class="nowrap liste_total right">';
  922. if ($projectidfortotallink > 0) {
  923. print '<a href="'.DOL_URL_ROOT.'/projet/tasks/time.php?projectid='.$projectidfortotallink.($showproject ? '' : '&withproject=1').'">';
  924. }
  925. print convertSecondToTime($total_projectlinesa_spent, 'allhourmin');
  926. if ($projectidfortotallink > 0) {
  927. print '</a>';
  928. }
  929. print '</td>';
  930. }
  931. if ($total_projectlinesa_planned) {
  932. $totalAverageDeclaredProgress = round(100 * $total_projectlinesa_declared_if_planned / $total_projectlinesa_planned, 2);
  933. $totalCalculatedProgress = round(100 * $total_projectlinesa_spent / $total_projectlinesa_planned, 2);
  934. // this conf is actually hidden, by default we use 10% for "be carefull or warning"
  935. $warningRatio = getDolGlobalString('PROJECT_TIME_SPEND_WARNING_PERCENT') ? (1 + $conf->global->PROJECT_TIME_SPEND_WARNING_PERCENT / 100) : 1.10;
  936. // define progress color according to time spend vs workload
  937. $progressBarClass = 'progress-bar-info';
  938. $badgeClass = 'badge ';
  939. if ($totalCalculatedProgress > $totalAverageDeclaredProgress) {
  940. $progressBarClass = 'progress-bar-danger';
  941. $badgeClass .= 'badge-danger';
  942. } elseif ($totalCalculatedProgress * $warningRatio >= $totalAverageDeclaredProgress) { // warning if close at 1%
  943. $progressBarClass = 'progress-bar-warning';
  944. $badgeClass .= 'badge-warning';
  945. } else {
  946. $progressBarClass = 'progress-bar-success';
  947. $badgeClass .= 'badge-success';
  948. }
  949. }
  950. // Computed progress
  951. if (count($arrayfields) > 0 && !empty($arrayfields['t.progress_calculated']['checked'])) {
  952. print '<td class="nowrap liste_total right">';
  953. if ($total_projectlinesa_planned) {
  954. print $totalCalculatedProgress.' %';
  955. }
  956. print '</td>';
  957. }
  958. // Declared progress
  959. if (count($arrayfields) > 0 && !empty($arrayfields['t.progress']['checked'])) {
  960. print '<td class="nowrap liste_total right">';
  961. if ($total_projectlinesa_planned) {
  962. print '<span class="'.$badgeClass.'" >'.$totalAverageDeclaredProgress.' %</span>';
  963. }
  964. print '</td>';
  965. }
  966. // Progress
  967. if (count($arrayfields) > 0 && !empty($arrayfields['t.progress_summary']['checked'])) {
  968. print '<td class="right">';
  969. if ($total_projectlinesa_planned) {
  970. print '</span>';
  971. print ' <div class="progress sm" title="'.$totalAverageDeclaredProgress.'%" >';
  972. print ' <div class="progress-bar '.$progressBarClass.'" style="width: '.$totalAverageDeclaredProgress.'%"></div>';
  973. print ' </div>';
  974. print '</div>';
  975. }
  976. print '</td>';
  977. }
  978. if ($showbilltime) {
  979. if (count($arrayfields) > 0 && !empty($arrayfields['t.tobill']['checked'])) {
  980. print '<td class="nowrap liste_total right">';
  981. print convertSecondToTime($total_projectlinesa_tobill, 'allhourmin');
  982. print '</td>';
  983. }
  984. if (count($arrayfields) > 0 && !empty($arrayfields['t.billed']['checked'])) {
  985. print '<td class="nowrap liste_total right">';
  986. print convertSecondToTime($total_projectlinesa_billed, 'allhourmin');
  987. print '</td>';
  988. }
  989. }
  990. // Budget task
  991. if (count($arrayfields) > 0 && !empty($arrayfields['t.budget_amount']['checked'])) {
  992. print '<td class="nowrap liste_total center">';
  993. if (strcmp($total_budget_amount, '')) {
  994. print price($total_budget_amount, 0, $langs, 1, 0, 0, $conf->currency);
  995. }
  996. print '</td>';
  997. }
  998. // Contacts of task for backward compatibility,
  999. if (getDolGlobalString('PROJECT_SHOW_CONTACTS_IN_LIST')) {
  1000. print '<td></td>';
  1001. }
  1002. // Contacts of task
  1003. if (count($arrayfields) > 0 && !empty($arrayfields['c.assigned']['checked'])) {
  1004. print '<td></td>';
  1005. }
  1006. // Check if Extrafields is totalizable
  1007. if (!empty($extrafields->attributes['projet_task']['totalizable'])) {
  1008. foreach ($extrafields->attributes['projet_task']['totalizable'] as $key => $value) {
  1009. if (!empty($arrayfields['efpt.'.$key]['checked']) && $arrayfields['efpt.'.$key]['checked'] == 1) {
  1010. print '<td class="right">';
  1011. if ($value == 1) {
  1012. print empty($totalarray['totalizable'][$key]['total']) ? '' : $totalarray['totalizable'][$key]['total'];
  1013. }
  1014. print '</td>';
  1015. }
  1016. }
  1017. }
  1018. // Column for the drag and drop
  1019. print '<td class="liste_total"></td>';
  1020. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  1021. print '<td class="liste_total"></td>';
  1022. }
  1023. print '</tr>';
  1024. }
  1025. return $inc;
  1026. }
  1027. /**
  1028. * Output a task line into a pertime intput mode
  1029. *
  1030. * @param string $inc Line number (start to 0, then increased by recursive call)
  1031. * @param string $parent Id of parent task to show (0 to show all)
  1032. * @param User|null $fuser Restrict list to user if defined
  1033. * @param Task[] $lines Array of lines
  1034. * @param int $level Level (start to 0, then increased/decrease by recursive call)
  1035. * @param string $projectsrole Array of roles user has on project
  1036. * @param string $tasksrole Array of roles user has on task
  1037. * @param string $mine Show only task lines I am assigned to
  1038. * @param int $restricteditformytask 0=No restriction, 1=Enable add time only if task is a task i am affected to
  1039. * @param int $preselectedday Preselected day
  1040. * @param array $isavailable Array with data that say if user is available for several days for morning and afternoon
  1041. * @param int $oldprojectforbreak Old project id of last project break
  1042. * @return array Array with time spent for $fuser for each day of week on tasks in $lines and substasks
  1043. */
  1044. function projectLinesPerAction(&$inc, $parent, $fuser, $lines, &$level, &$projectsrole, &$tasksrole, $mine, $restricteditformytask, $preselectedday, &$isavailable, $oldprojectforbreak = 0)
  1045. {
  1046. global $conf, $db, $user, $langs;
  1047. global $form, $formother, $projectstatic, $taskstatic, $thirdpartystatic;
  1048. $lastprojectid = 0;
  1049. $totalforeachline = array();
  1050. $workloadforid = array();
  1051. $lineswithoutlevel0 = array();
  1052. $numlines = count($lines);
  1053. // Create a smaller array with sublevels only to be used later. This increase dramatically performances.
  1054. if ($parent == 0) { // Always and only if at first level
  1055. for ($i = 0; $i < $numlines; $i++) {
  1056. if ($lines[$i]->fk_task_parent) {
  1057. $lineswithoutlevel0[] = $lines[$i];
  1058. }
  1059. }
  1060. }
  1061. if (empty($oldprojectforbreak)) {
  1062. $oldprojectforbreak = (!getDolGlobalString('PROJECT_TIMESHEET_DISABLEBREAK_ON_PROJECT') ? 0 : -1); // 0 to start break , -1 no break
  1063. }
  1064. //dol_syslog('projectLinesPerDay inc='.$inc.' preselectedday='.$preselectedday.' task parent id='.$parent.' level='.$level." count(lines)=".$numlines." count(lineswithoutlevel0)=".count($lineswithoutlevel0));
  1065. for ($i = 0; $i < $numlines; $i++) {
  1066. if ($parent == 0) {
  1067. $level = 0;
  1068. }
  1069. //if ($lines[$i]->fk_task_parent == $parent)
  1070. //{
  1071. // If we want all or we have a role on task, we show it
  1072. if (empty($mine) || !empty($tasksrole[$lines[$i]->id])) {
  1073. //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);
  1074. // Break on a new project
  1075. if ($parent == 0 && $lines[$i]->fk_project != $lastprojectid) {
  1076. $lastprojectid = $lines[$i]->fk_project;
  1077. if ($preselectedday) {
  1078. $projectstatic->id = $lines[$i]->fk_project;
  1079. }
  1080. }
  1081. if (empty($workloadforid[$projectstatic->id])) {
  1082. if ($preselectedday) {
  1083. $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
  1084. $workloadforid[$projectstatic->id] = 1;
  1085. }
  1086. }
  1087. $projectstatic->id = $lines[$i]->fk_project;
  1088. $projectstatic->ref = $lines[$i]->project_ref;
  1089. $projectstatic->title = $lines[$i]->project_label;
  1090. $projectstatic->public = $lines[$i]->public;
  1091. $projectstatic->status = $lines[$i]->project->status;
  1092. $taskstatic->id = $lines[$i]->fk_statut;
  1093. $taskstatic->ref = ($lines[$i]->task_ref ? $lines[$i]->task_ref : $lines[$i]->task_id);
  1094. $taskstatic->label = $lines[$i]->task_label;
  1095. $taskstatic->date_start = $lines[$i]->date_start;
  1096. $taskstatic->date_end = $lines[$i]->date_end;
  1097. $thirdpartystatic->id = $lines[$i]->socid;
  1098. $thirdpartystatic->name = $lines[$i]->thirdparty_name;
  1099. $thirdpartystatic->email = $lines[$i]->thirdparty_email;
  1100. if (empty($oldprojectforbreak) || ($oldprojectforbreak != -1 && $oldprojectforbreak != $projectstatic->id)) {
  1101. print '<tr class="oddeven trforbreak nobold">'."\n";
  1102. print '<td colspan="11">';
  1103. print $projectstatic->getNomUrl(1, '', 0, $langs->transnoentitiesnoconv("YourRole").': '.$projectsrole[$lines[$i]->fk_project]);
  1104. if ($projectstatic->title) {
  1105. print ' - ';
  1106. print $projectstatic->title;
  1107. }
  1108. print '</td>';
  1109. print '</tr>';
  1110. }
  1111. if ($oldprojectforbreak != -1) {
  1112. $oldprojectforbreak = $projectstatic->id;
  1113. }
  1114. print '<tr class="oddeven">'."\n";
  1115. // User
  1116. /*
  1117. print '<td class="nowrap">';
  1118. print $fuser->getNomUrl(1, 'withproject', 'time');
  1119. print '</td>';
  1120. */
  1121. // Project
  1122. print "<td>";
  1123. if ($oldprojectforbreak == -1) {
  1124. print $projectstatic->getNomUrl(1, '', 0, $langs->transnoentitiesnoconv("YourRole").': '.$projectsrole[$lines[$i]->fk_project]);
  1125. print '<br>'.$projectstatic->title;
  1126. }
  1127. print "</td>";
  1128. // Thirdparty
  1129. print '<td class="tdoverflowmax100">';
  1130. if ($thirdpartystatic->id > 0) {
  1131. print $thirdpartystatic->getNomUrl(1, 'project', 10);
  1132. }
  1133. print '</td>';
  1134. // Ref
  1135. print '<td>';
  1136. print '<!-- Task id = '.$lines[$i]->id.' (projectlinesperaction) -->';
  1137. for ($k = 0; $k < $level; $k++) {
  1138. print '<div class="marginleftonly">';
  1139. }
  1140. print $taskstatic->getNomUrl(1, 'withproject', 'time');
  1141. // Label task
  1142. print '<br>';
  1143. print '<div class="opacitymedium tdoverflowmax500" title="'.dol_escape_htmltag($taskstatic->label).'">'.dol_escape_htmltag($taskstatic->label).'</div>';
  1144. for ($k = 0; $k < $level; $k++) {
  1145. print "</div>";
  1146. }
  1147. print "</td>\n";
  1148. // Date
  1149. print '<td class="center">';
  1150. print dol_print_date($lines[$i]->timespent_datehour, 'day');
  1151. print '</td>';
  1152. $disabledproject = 1;
  1153. $disabledtask = 1;
  1154. //print "x".$lines[$i]->fk_project;
  1155. //var_dump($lines[$i]);
  1156. //var_dump($projectsrole[$lines[$i]->fk_project]);
  1157. // If at least one role for project
  1158. if ($lines[$i]->public || !empty($projectsrole[$lines[$i]->fk_project]) || $user->hasRight('projet', 'all', 'creer')) {
  1159. $disabledproject = 0;
  1160. $disabledtask = 0;
  1161. }
  1162. // If $restricteditformytask is on and I have no role on task, i disable edit
  1163. if ($restricteditformytask && empty($tasksrole[$lines[$i]->id])) {
  1164. $disabledtask = 1;
  1165. }
  1166. // Hour
  1167. print '<td class="nowrap center">';
  1168. print dol_print_date($lines[$i]->timespent_datehour, 'hour');
  1169. print '</td>';
  1170. $cssonholiday = '';
  1171. if (!$isavailable[$preselectedday]['morning'] && !$isavailable[$preselectedday]['afternoon']) {
  1172. $cssonholiday .= 'onholidayallday ';
  1173. } elseif (!$isavailable[$preselectedday]['morning']) {
  1174. $cssonholiday .= 'onholidaymorning ';
  1175. } elseif (!$isavailable[$preselectedday]['afternoon']) {
  1176. $cssonholiday .= 'onholidayafternoon ';
  1177. }
  1178. // Duration
  1179. print '<td class="duration'.($cssonholiday ? ' '.$cssonholiday : '').' center">';
  1180. $dayWorkLoad = $lines[$i]->timespent_duration;
  1181. $totalforeachline[$preselectedday] += $lines[$i]->timespent_duration;
  1182. $alreadyspent = '';
  1183. if ($dayWorkLoad > 0) {
  1184. $alreadyspent = convertSecondToTime($lines[$i]->timespent_duration, 'allhourmin');
  1185. }
  1186. print convertSecondToTime($lines[$i]->timespent_duration, 'allhourmin');
  1187. print '</td>';
  1188. // Note
  1189. print '<td class="center">';
  1190. print '<textarea name="'.$lines[$i]->id.'note" rows="'.ROWS_2.'" id="'.$lines[$i]->id.'note"'.($disabledtask ? ' disabled="disabled"' : '').'>';
  1191. print $lines[$i]->timespent_note;
  1192. print '</textarea>';
  1193. print '</td>';
  1194. // Warning
  1195. print '<td class="right">';
  1196. /*if ((! $lines[$i]->public) && $disabledproject) print $form->textwithpicto('',$langs->trans("UserIsNotContactOfProject"));
  1197. elseif ($disabledtask)
  1198. {
  1199. $titleassigntask = $langs->trans("AssignTaskToMe");
  1200. if ($fuser->id != $user->id) $titleassigntask = $langs->trans("AssignTaskToUser", '...');
  1201. print $form->textwithpicto('',$langs->trans("TaskIsNotAssignedToUser", $titleassigntask));
  1202. }*/
  1203. print '</td>';
  1204. print "</tr>\n";
  1205. }
  1206. //}
  1207. //else
  1208. //{
  1209. //$level--;
  1210. //}
  1211. }
  1212. return $totalforeachline;
  1213. }
  1214. /**
  1215. * Output a task line into a pertime intput mode
  1216. *
  1217. * @param string $inc Line number (start to 0, then increased by recursive call)
  1218. * @param string $parent Id of parent task to show (0 to show all)
  1219. * @param User|null $fuser Restrict list to user if defined
  1220. * @param Task[] $lines Array of lines
  1221. * @param int $level Level (start to 0, then increased/decrease by recursive call)
  1222. * @param string $projectsrole Array of roles user has on project
  1223. * @param string $tasksrole Array of roles user has on task
  1224. * @param string $mine Show only task lines I am assigned to
  1225. * @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
  1226. * @param int $preselectedday Preselected day
  1227. * @param array $isavailable Array with data that say if user is available for several days for morning and afternoon
  1228. * @param int $oldprojectforbreak Old project id of last project break
  1229. * @param array $arrayfields Array of additional column
  1230. * @param Extrafields $extrafields Object extrafields
  1231. * @return array Array with time spent for $fuser for each day of week on tasks in $lines and substasks
  1232. */
  1233. function projectLinesPerDay(&$inc, $parent, $fuser, $lines, &$level, &$projectsrole, &$tasksrole, $mine, $restricteditformytask, $preselectedday, &$isavailable, $oldprojectforbreak = 0, $arrayfields = array(), $extrafields = null)
  1234. {
  1235. global $conf, $db, $user, $langs;
  1236. global $form, $formother, $projectstatic, $taskstatic, $thirdpartystatic;
  1237. $lastprojectid = 0;
  1238. $totalforeachday = array();
  1239. $workloadforid = array();
  1240. $lineswithoutlevel0 = array();
  1241. $numlines = count($lines);
  1242. // Create a smaller array with sublevels only to be used later. This increase dramatically performances.
  1243. if ($parent == 0) { // Always and only if at first level
  1244. for ($i = 0; $i < $numlines; $i++) {
  1245. if ($lines[$i]->fk_task_parent) {
  1246. $lineswithoutlevel0[] = $lines[$i];
  1247. }
  1248. }
  1249. }
  1250. if (empty($oldprojectforbreak)) {
  1251. $oldprojectforbreak = (!getDolGlobalString('PROJECT_TIMESHEET_DISABLEBREAK_ON_PROJECT') ? 0 : -1); // 0 to start break , -1 no break
  1252. }
  1253. $restrictBefore = null;
  1254. if (getDolGlobalString('PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS')) {
  1255. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  1256. $restrictBefore = dol_time_plus_duree(dol_now(), - $conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS, 'm');
  1257. }
  1258. //dol_syslog('projectLinesPerDay inc='.$inc.' preselectedday='.$preselectedday.' task parent id='.$parent.' level='.$level." count(lines)=".$numlines." count(lineswithoutlevel0)=".count($lineswithoutlevel0));
  1259. for ($i = 0; $i < $numlines; $i++) {
  1260. if ($parent == 0) {
  1261. $level = 0;
  1262. }
  1263. if ($lines[$i]->fk_task_parent == $parent) {
  1264. $obj = &$lines[$i]; // To display extrafields
  1265. // If we want all or we have a role on task, we show it
  1266. if (empty($mine) || !empty($tasksrole[$lines[$i]->id])) {
  1267. //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);
  1268. if ($restricteditformytask == 2 && empty($tasksrole[$lines[$i]->id])) { // we have no role on task and we request to hide such cases
  1269. continue;
  1270. }
  1271. // Break on a new project
  1272. if ($parent == 0 && $lines[$i]->fk_project != $lastprojectid) {
  1273. $lastprojectid = $lines[$i]->fk_project;
  1274. if ($preselectedday) {
  1275. $projectstatic->id = $lines[$i]->fk_project;
  1276. }
  1277. }
  1278. if (empty($workloadforid[$projectstatic->id])) {
  1279. if ($preselectedday) {
  1280. $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
  1281. $workloadforid[$projectstatic->id] = 1;
  1282. }
  1283. }
  1284. $projectstatic->id = $lines[$i]->fk_project;
  1285. $projectstatic->ref = $lines[$i]->projectref;
  1286. $projectstatic->title = $lines[$i]->projectlabel;
  1287. $projectstatic->public = $lines[$i]->public;
  1288. $projectstatic->status = $lines[$i]->projectstatus;
  1289. $taskstatic->id = $lines[$i]->id;
  1290. $taskstatic->ref = ($lines[$i]->ref ? $lines[$i]->ref : $lines[$i]->id);
  1291. $taskstatic->label = $lines[$i]->label;
  1292. $taskstatic->date_start = $lines[$i]->date_start;
  1293. $taskstatic->date_end = $lines[$i]->date_end;
  1294. $thirdpartystatic->id = $lines[$i]->socid;
  1295. $thirdpartystatic->name = $lines[$i]->thirdparty_name;
  1296. $thirdpartystatic->email = $lines[$i]->thirdparty_email;
  1297. if (empty($oldprojectforbreak) || ($oldprojectforbreak != -1 && $oldprojectforbreak != $projectstatic->id)) {
  1298. $addcolspan = 0;
  1299. if (!empty($arrayfields['t.planned_workload']['checked'])) {
  1300. $addcolspan++;
  1301. }
  1302. if (!empty($arrayfields['t.progress']['checked'])) {
  1303. $addcolspan++;
  1304. }
  1305. foreach ($arrayfields as $key => $val) {
  1306. if ($val['checked'] && substr($key, 0, 5) == 'efpt.') {
  1307. $addcolspan++;
  1308. }
  1309. }
  1310. print '<tr class="oddeven trforbreak nobold">'."\n";
  1311. print '<td colspan="'.(7 + $addcolspan).'">';
  1312. print $projectstatic->getNomUrl(1, '', 0, '<strong>'.$langs->transnoentitiesnoconv("YourRole").':</strong> '.$projectsrole[$lines[$i]->fk_project]);
  1313. if ($thirdpartystatic->id > 0) {
  1314. print ' - '.$thirdpartystatic->getNomUrl(1);
  1315. }
  1316. if ($projectstatic->title) {
  1317. print ' - ';
  1318. print '<span class="secondary">'.$projectstatic->title.'</span>';
  1319. }
  1320. /*
  1321. $colspan=5+(empty($conf->global->PROJECT_TIMESHEET_DISABLEBREAK_ON_PROJECT)?0:2);
  1322. print '<table class="">';
  1323. print '<tr class="liste_titre">';
  1324. // PROJECT fields
  1325. 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 ');
  1326. 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 ');
  1327. 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 ');
  1328. 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 ');
  1329. 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 ');
  1330. $extrafieldsobjectkey='projet';
  1331. $extrafieldsobjectprefix='efp.';
  1332. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  1333. print '</tr>';
  1334. print '<tr>';
  1335. // PROJECT fields
  1336. if (!empty($arrayfields['p.fk_opp_status']['checked']))
  1337. {
  1338. print '<td class="nowrap">';
  1339. $code = dol_getIdFromCode($db, $lines[$i]->fk_opp_status, 'c_lead_status', 'rowid', 'code');
  1340. if ($code) print $langs->trans("OppStatus".$code);
  1341. print "</td>\n";
  1342. }
  1343. if (!empty($arrayfields['p.opp_amount']['checked']))
  1344. {
  1345. print '<td class="nowrap">';
  1346. print price($lines[$i]->opp_amount, 0, $langs, 1, 0, -1, $conf->currency);
  1347. print "</td>\n";
  1348. }
  1349. if (!empty($arrayfields['p.opp_percent']['checked']))
  1350. {
  1351. print '<td class="nowrap">';
  1352. print price($lines[$i]->opp_percent, 0, $langs, 1, 0).' %';
  1353. print "</td>\n";
  1354. }
  1355. if (!empty($arrayfields['p.budget_amount']['checked']))
  1356. {
  1357. print '<td class="nowrap">';
  1358. print price($lines[$i]->budget_amount, 0, $langs, 1, 0, 0, $conf->currency);
  1359. print "</td>\n";
  1360. }
  1361. if (!empty($arrayfields['p.usage_bill_time']['checked']))
  1362. {
  1363. print '<td class="nowrap">';
  1364. print yn($lines[$i]->usage_bill_time);
  1365. print "</td>\n";
  1366. }
  1367. $extrafieldsobjectkey='projet';
  1368. $extrafieldsobjectprefix='efp.';
  1369. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  1370. print '</tr>';
  1371. print '</table>';
  1372. */
  1373. print '</td>';
  1374. print '</tr>';
  1375. }
  1376. if ($oldprojectforbreak != -1) {
  1377. $oldprojectforbreak = $projectstatic->id;
  1378. }
  1379. print '<tr class="oddeven" data-taskid="'.$lines[$i]->id.'">'."\n";
  1380. // User
  1381. /*
  1382. print '<td class="nowrap">';
  1383. print $fuser->getNomUrl(1, 'withproject', 'time');
  1384. print '</td>';
  1385. */
  1386. // Project
  1387. if (getDolGlobalString('PROJECT_TIMESHEET_DISABLEBREAK_ON_PROJECT')) {
  1388. print "<td>";
  1389. if ($oldprojectforbreak == -1) {
  1390. print $projectstatic->getNomUrl(1, '', 0, $langs->transnoentitiesnoconv("YourRole").': '.$projectsrole[$lines[$i]->fk_project]);
  1391. }
  1392. print "</td>";
  1393. }
  1394. // Thirdparty
  1395. if (getDolGlobalString('PROJECT_TIMESHEET_DISABLEBREAK_ON_PROJECT')) {
  1396. print '<td class="tdoverflowmax100">';
  1397. if ($thirdpartystatic->id > 0) {
  1398. print $thirdpartystatic->getNomUrl(1, 'project', 10);
  1399. }
  1400. print '</td>';
  1401. }
  1402. // Ref
  1403. print '<td>';
  1404. print '<!-- Task id = '.$lines[$i]->id.' (projectlinesperday) -->';
  1405. for ($k = 0; $k < $level; $k++) {
  1406. print '<div class="marginleftonly">';
  1407. }
  1408. print $taskstatic->getNomUrl(1, 'withproject', 'time');
  1409. // Label task
  1410. print '<br>';
  1411. print '<div class="opacitymedium tdoverflowmax500" title="'.dol_escape_htmltag($taskstatic->label).'">'.dol_escape_htmltag($taskstatic->label).'</div>';
  1412. for ($k = 0; $k < $level; $k++) {
  1413. print "</div>";
  1414. }
  1415. print "</td>\n";
  1416. // TASK extrafields
  1417. $extrafieldsobjectkey = 'projet_task';
  1418. $extrafieldsobjectprefix = 'efpt.';
  1419. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  1420. // Planned Workload
  1421. if (!empty($arrayfields['t.planned_workload']['checked'])) {
  1422. print '<td class="leftborder plannedworkload right">';
  1423. if ($lines[$i]->planned_workload) {
  1424. print convertSecondToTime($lines[$i]->planned_workload, 'allhourmin');
  1425. } else {
  1426. print '--:--';
  1427. }
  1428. print '</td>';
  1429. }
  1430. // Progress declared %
  1431. if (!empty($arrayfields['t.progress']['checked'])) {
  1432. print '<td class="right">';
  1433. print $formother->select_percent($lines[$i]->progress, $lines[$i]->id.'progress');
  1434. print '</td>';
  1435. }
  1436. if (!empty($arrayfields['timeconsumed']['checked'])) {
  1437. // Time spent by everybody
  1438. print '<td class="right">';
  1439. // $lines[$i]->duration_effective is a denormalised field = summ of time spent by everybody for task. What we need is time consumed by user
  1440. if ($lines[$i]->duration_effective) {
  1441. print '<a href="'.DOL_URL_ROOT.'/projet/tasks/time.php?id='.$lines[$i]->id.'">';
  1442. print convertSecondToTime($lines[$i]->duration_effective, 'allhourmin');
  1443. print '</a>';
  1444. } else {
  1445. print '--:--';
  1446. }
  1447. print "</td>\n";
  1448. // Time spent by user
  1449. print '<td class="right">';
  1450. $tmptimespent = $taskstatic->getSummaryOfTimeSpent($fuser->id);
  1451. if ($tmptimespent['total_duration']) {
  1452. print convertSecondToTime($tmptimespent['total_duration'], 'allhourmin');
  1453. } else {
  1454. print '--:--';
  1455. }
  1456. print "</td>\n";
  1457. }
  1458. $disabledproject = 1;
  1459. $disabledtask = 1;
  1460. //print "x".$lines[$i]->fk_project;
  1461. //var_dump($lines[$i]);
  1462. //var_dump($projectsrole[$lines[$i]->fk_project]);
  1463. // If at least one role for project
  1464. if ($lines[$i]->public || !empty($projectsrole[$lines[$i]->fk_project]) || $user->hasRight('projet', 'all', 'creer')) {
  1465. $disabledproject = 0;
  1466. $disabledtask = 0;
  1467. }
  1468. // If $restricteditformytask is on and I have no role on task, i disable edit
  1469. if ($restricteditformytask && empty($tasksrole[$lines[$i]->id])) {
  1470. $disabledtask = 1;
  1471. }
  1472. if ($restrictBefore && $preselectedday < $restrictBefore) {
  1473. $disabledtask = 1;
  1474. }
  1475. // Select hour
  1476. print '<td class="nowraponall leftborder center minwidth150imp">';
  1477. $tableCell = $form->selectDate($preselectedday, $lines[$i]->id, 1, 1, 2, "addtime", 0, 0, $disabledtask);
  1478. print $tableCell;
  1479. print '</td>';
  1480. $cssonholiday = '';
  1481. if (!$isavailable[$preselectedday]['morning'] && !$isavailable[$preselectedday]['afternoon']) {
  1482. $cssonholiday .= 'onholidayallday ';
  1483. } elseif (!$isavailable[$preselectedday]['morning']) {
  1484. $cssonholiday .= 'onholidaymorning ';
  1485. } elseif (!$isavailable[$preselectedday]['afternoon']) {
  1486. $cssonholiday .= 'onholidayafternoon ';
  1487. }
  1488. global $daytoparse;
  1489. $tmparray = dol_getdate($daytoparse, true); // detail of current day
  1490. $idw = ($tmparray['wday'] - (!getDolGlobalString('MAIN_START_WEEK') ? 0 : 1));
  1491. global $numstartworkingday, $numendworkingday;
  1492. $cssweekend = '';
  1493. 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.
  1494. $cssweekend = 'weekend';
  1495. }
  1496. // Duration
  1497. print '<td class="center duration'.($cssonholiday ? ' '.$cssonholiday : '').($cssweekend ? ' '.$cssweekend : '').'">';
  1498. $dayWorkLoad = empty($projectstatic->weekWorkLoadPerTask[$preselectedday][$lines[$i]->id]) ? 0 : $projectstatic->weekWorkLoadPerTask[$preselectedday][$lines[$i]->id];
  1499. if (!isset($totalforeachday[$preselectedday])) {
  1500. $totalforeachday[$preselectedday] = 0;
  1501. }
  1502. $totalforeachday[$preselectedday] += $dayWorkLoad;
  1503. $alreadyspent = '';
  1504. if ($dayWorkLoad > 0) {
  1505. $alreadyspent = convertSecondToTime($dayWorkLoad, 'allhourmin');
  1506. }
  1507. $idw = 0;
  1508. $tableCell = '';
  1509. $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>';
  1510. $tableCell .= '<span class="hideonsmartphone"> + </span>';
  1511. //$tableCell.='&nbsp;&nbsp;&nbsp;';
  1512. $tableCell .= $form->select_duration($lines[$i]->id.'duration', '', $disabledtask, 'text', 0, 1);
  1513. //$tableCell.='&nbsp;<input type="submit" class="button"'.($disabledtask?' disabled':'').' value="'.$langs->trans("Add").'">';
  1514. print $tableCell;
  1515. print '</td>';
  1516. // Note
  1517. print '<td class="center">';
  1518. print '<textarea name="'.$lines[$i]->id.'note" rows="'.ROWS_2.'" id="'.$lines[$i]->id.'note"'.($disabledtask ? ' disabled="disabled"' : '').'>';
  1519. print '</textarea>';
  1520. print '</td>';
  1521. // Warning
  1522. print '<td class="right">';
  1523. if ((!$lines[$i]->public) && $disabledproject) {
  1524. print $form->textwithpicto('', $langs->trans("UserIsNotContactOfProject"));
  1525. } elseif ($disabledtask) {
  1526. $titleassigntask = $langs->trans("AssignTaskToMe");
  1527. if ($fuser->id != $user->id) {
  1528. $titleassigntask = $langs->trans("AssignTaskToUser", '...');
  1529. }
  1530. print $form->textwithpicto('', $langs->trans("TaskIsNotAssignedToUser", $titleassigntask));
  1531. }
  1532. print '</td>';
  1533. print "</tr>\n";
  1534. }
  1535. $inc++;
  1536. $level++;
  1537. if ($lines[$i]->id > 0) {
  1538. //var_dump('totalforeachday after taskid='.$lines[$i]->id.' and previous one on level '.$level);
  1539. //var_dump($totalforeachday);
  1540. $ret = projectLinesPerDay($inc, $lines[$i]->id, $fuser, ($parent == 0 ? $lineswithoutlevel0 : $lines), $level, $projectsrole, $tasksrole, $mine, $restricteditformytask, $preselectedday, $isavailable, $oldprojectforbreak, $arrayfields, $extrafields);
  1541. //var_dump('ret with parent='.$lines[$i]->id.' level='.$level);
  1542. //var_dump($ret);
  1543. foreach ($ret as $key => $val) {
  1544. $totalforeachday[$key] += $val;
  1545. }
  1546. //var_dump('totalforeachday after taskid='.$lines[$i]->id.' and previous one on level '.$level.' + subtasks');
  1547. //var_dump($totalforeachday);
  1548. }
  1549. $level--;
  1550. } else {
  1551. //$level--;
  1552. }
  1553. }
  1554. return $totalforeachday;
  1555. }
  1556. /**
  1557. * Output a task line into a perday intput mode
  1558. *
  1559. * @param string $inc Line output identificator (start to 0, then increased by recursive call)
  1560. * @param int $firstdaytoshow First day to show
  1561. * @param User|null $fuser Restrict list to user if defined
  1562. * @param string $parent Id of parent task to show (0 to show all)
  1563. * @param Task[] $lines Array of lines (list of tasks but we will show only if we have a specific role on task)
  1564. * @param int $level Level (start to 0, then increased/decrease by recursive call)
  1565. * @param string $projectsrole Array of roles user has on project
  1566. * @param string $tasksrole Array of roles user has on task
  1567. * @param string $mine Show only task lines I am assigned to
  1568. * @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
  1569. * @param array $isavailable Array with data that say if user is available for several days for morning and afternoon
  1570. * @param int $oldprojectforbreak Old project id of last project break
  1571. * @param array $arrayfields Array of additional column
  1572. * @param Extrafields $extrafields Object extrafields
  1573. * @return array Array with time spent for $fuser for each day of week on tasks in $lines and substasks
  1574. */
  1575. function projectLinesPerWeek(&$inc, $firstdaytoshow, $fuser, $parent, $lines, &$level, &$projectsrole, &$tasksrole, $mine, $restricteditformytask, &$isavailable, $oldprojectforbreak = 0, $arrayfields = array(), $extrafields = null)
  1576. {
  1577. global $conf, $db, $user, $langs;
  1578. global $form, $formother, $projectstatic, $taskstatic, $thirdpartystatic;
  1579. $numlines = count($lines);
  1580. $lastprojectid = 0;
  1581. $workloadforid = array();
  1582. $totalforeachday = array();
  1583. $lineswithoutlevel0 = array();
  1584. // Create a smaller array with sublevels only to be used later. This increase dramatically performances.
  1585. if ($parent == 0) { // Always and only if at first level
  1586. for ($i = 0; $i < $numlines; $i++) {
  1587. if ($lines[$i]->fk_task_parent) {
  1588. $lineswithoutlevel0[] = $lines[$i];
  1589. }
  1590. }
  1591. }
  1592. //dol_syslog('projectLinesPerWeek inc='.$inc.' firstdaytoshow='.$firstdaytoshow.' task parent id='.$parent.' level='.$level." count(lines)=".$numlines." count(lineswithoutlevel0)=".count($lineswithoutlevel0));
  1593. if (empty($oldprojectforbreak)) {
  1594. $oldprojectforbreak = (!getDolGlobalString('PROJECT_TIMESHEET_DISABLEBREAK_ON_PROJECT') ? 0 : -1); // 0 = start break, -1 = never break
  1595. }
  1596. $restrictBefore = null;
  1597. if (getDolGlobalString('PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS')) {
  1598. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  1599. $restrictBefore = dol_time_plus_duree(dol_now(), - $conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS, 'm');
  1600. }
  1601. for ($i = 0; $i < $numlines; $i++) {
  1602. if ($parent == 0) {
  1603. $level = 0;
  1604. }
  1605. if ($lines[$i]->fk_task_parent == $parent) {
  1606. $obj = &$lines[$i]; // To display extrafields
  1607. // If we want all or we have a role on task, we show it
  1608. if (empty($mine) || !empty($tasksrole[$lines[$i]->id])) {
  1609. //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);
  1610. if ($restricteditformytask == 2 && empty($tasksrole[$lines[$i]->id])) { // we have no role on task and we request to hide such cases
  1611. continue;
  1612. }
  1613. // Break on a new project
  1614. if ($parent == 0 && $lines[$i]->fk_project != $lastprojectid) {
  1615. $lastprojectid = $lines[$i]->fk_project;
  1616. $projectstatic->id = $lines[$i]->fk_project;
  1617. }
  1618. //var_dump('--- '.$level.' '.$firstdaytoshow.' '.$fuser->id.' '.$projectstatic->id.' '.$workloadforid[$projectstatic->id]);
  1619. //var_dump($projectstatic->weekWorkLoadPerTask);
  1620. if (empty($workloadforid[$projectstatic->id])) {
  1621. $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
  1622. $workloadforid[$projectstatic->id] = 1;
  1623. }
  1624. //var_dump($projectstatic->weekWorkLoadPerTask);
  1625. //var_dump('--- '.$projectstatic->id.' '.$workloadforid[$projectstatic->id]);
  1626. $projectstatic->id = $lines[$i]->fk_project;
  1627. $projectstatic->ref = $lines[$i]->projectref;
  1628. $projectstatic->title = $lines[$i]->projectlabel;
  1629. $projectstatic->public = $lines[$i]->public;
  1630. $projectstatic->thirdparty_name = $lines[$i]->thirdparty_name;
  1631. $projectstatic->status = $lines[$i]->projectstatus;
  1632. $taskstatic->id = $lines[$i]->id;
  1633. $taskstatic->ref = ($lines[$i]->ref ? $lines[$i]->ref : $lines[$i]->id);
  1634. $taskstatic->label = $lines[$i]->label;
  1635. $taskstatic->date_start = $lines[$i]->date_start;
  1636. $taskstatic->date_end = $lines[$i]->date_end;
  1637. $thirdpartystatic->id = $lines[$i]->thirdparty_id;
  1638. $thirdpartystatic->name = $lines[$i]->thirdparty_name;
  1639. $thirdpartystatic->email = $lines[$i]->thirdparty_email;
  1640. if (empty($oldprojectforbreak) || ($oldprojectforbreak != -1 && $oldprojectforbreak != $projectstatic->id)) {
  1641. $addcolspan = 0;
  1642. if (!empty($arrayfields['t.planned_workload']['checked'])) {
  1643. $addcolspan++;
  1644. }
  1645. if (!empty($arrayfields['t.progress']['checked'])) {
  1646. $addcolspan++;
  1647. }
  1648. foreach ($arrayfields as $key => $val) {
  1649. if ($val['checked'] && substr($key, 0, 5) == 'efpt.') {
  1650. $addcolspan++;
  1651. }
  1652. }
  1653. print '<tr class="oddeven trforbreak nobold">'."\n";
  1654. print '<td colspan="'.(11 + $addcolspan).'">';
  1655. print $projectstatic->getNomUrl(1, '', 0, '<strong>'.$langs->transnoentitiesnoconv("YourRole").':</strong> '.$projectsrole[$lines[$i]->fk_project]);
  1656. if ($thirdpartystatic->id > 0) {
  1657. print ' - '.$thirdpartystatic->getNomUrl(1);
  1658. }
  1659. if ($projectstatic->title) {
  1660. print ' - ';
  1661. print '<span class="secondary">'.$projectstatic->title.'</span>';
  1662. }
  1663. /*$colspan=5+(empty($conf->global->PROJECT_TIMESHEET_DISABLEBREAK_ON_PROJECT)?0:2);
  1664. print '<table class="">';
  1665. print '<tr class="liste_titre">';
  1666. // PROJECT fields
  1667. 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 ');
  1668. 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 ');
  1669. 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 ');
  1670. 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 ');
  1671. 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 ');
  1672. $extrafieldsobjectkey='projet';
  1673. $extrafieldsobjectprefix='efp.';
  1674. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  1675. print '</tr>';
  1676. print '<tr>';
  1677. // PROJECT fields
  1678. if (!empty($arrayfields['p.fk_opp_status']['checked']))
  1679. {
  1680. print '<td class="nowrap">';
  1681. $code = dol_getIdFromCode($db, $lines[$i]->fk_opp_status, 'c_lead_status', 'rowid', 'code');
  1682. if ($code) print $langs->trans("OppStatus".$code);
  1683. print "</td>\n";
  1684. }
  1685. if (!empty($arrayfields['p.opp_amount']['checked']))
  1686. {
  1687. print '<td class="nowrap">';
  1688. print price($lines[$i]->opp_amount, 0, $langs, 1, 0, -1, $conf->currency);
  1689. print "</td>\n";
  1690. }
  1691. if (!empty($arrayfields['p.opp_percent']['checked']))
  1692. {
  1693. print '<td class="nowrap">';
  1694. print price($lines[$i]->opp_percent, 0, $langs, 1, 0).' %';
  1695. print "</td>\n";
  1696. }
  1697. if (!empty($arrayfields['p.budget_amount']['checked']))
  1698. {
  1699. print '<td class="nowrap">';
  1700. print price($lines[$i]->budget_amount, 0, $langs, 1, 0, 0, $conf->currency);
  1701. print "</td>\n";
  1702. }
  1703. if (!empty($arrayfields['p.usage_bill_time']['checked']))
  1704. {
  1705. print '<td class="nowrap">';
  1706. print yn($lines[$i]->usage_bill_time);
  1707. print "</td>\n";
  1708. }
  1709. $extrafieldsobjectkey='projet';
  1710. $extrafieldsobjectprefix='efp.';
  1711. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  1712. print '</tr>';
  1713. print '</table>';
  1714. */
  1715. print '</td>';
  1716. print '</tr>';
  1717. }
  1718. if ($oldprojectforbreak != -1) {
  1719. $oldprojectforbreak = $projectstatic->id;
  1720. }
  1721. print '<tr class="oddeven" data-taskid="'.$lines[$i]->id.'">'."\n";
  1722. // User
  1723. /*
  1724. print '<td class="nowrap">';
  1725. print $fuser->getNomUrl(1, 'withproject', 'time');
  1726. print '</td>';
  1727. */
  1728. // Project
  1729. if (getDolGlobalString('PROJECT_TIMESHEET_DISABLEBREAK_ON_PROJECT')) {
  1730. print '<td class="nowrap">';
  1731. if ($oldprojectforbreak == -1) {
  1732. print $projectstatic->getNomUrl(1, '', 0, $langs->transnoentitiesnoconv("YourRole").': '.$projectsrole[$lines[$i]->fk_project]);
  1733. }
  1734. print "</td>";
  1735. }
  1736. // Thirdparty
  1737. if (getDolGlobalString('PROJECT_TIMESHEET_DISABLEBREAK_ON_PROJECT')) {
  1738. print '<td class="tdoverflowmax100">';
  1739. if ($thirdpartystatic->id > 0) {
  1740. print $thirdpartystatic->getNomUrl(1, 'project');
  1741. }
  1742. print '</td>';
  1743. }
  1744. // Ref
  1745. print '<td class="tdoverflowmax300">';
  1746. print '<!-- Task id = '.$lines[$i]->id.' (projectlinesperweek) -->';
  1747. for ($k = 0; $k < $level; $k++) {
  1748. print '<div class="marginleftonly">';
  1749. }
  1750. print $taskstatic->getNomUrl(1, 'withproject', 'time');
  1751. // Label task
  1752. print '<br>';
  1753. print '<div class="opacitymedium tdoverflowmax500" title="'.dol_escape_htmltag($taskstatic->label).'">'.dol_escape_htmltag($taskstatic->label).'</div>';
  1754. for ($k = 0; $k < $level; $k++) {
  1755. print "</div>";
  1756. }
  1757. print "</td>\n";
  1758. // TASK extrafields
  1759. $extrafieldsobjectkey = 'projet_task';
  1760. $extrafieldsobjectprefix = 'efpt.';
  1761. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  1762. // Planned Workload
  1763. if (!empty($arrayfields['t.planned_workload']['checked'])) {
  1764. print '<td class="leftborder plannedworkload right">';
  1765. if ($lines[$i]->planned_workload) {
  1766. print convertSecondToTime($lines[$i]->planned_workload, 'allhourmin');
  1767. } else {
  1768. print '--:--';
  1769. }
  1770. print '</td>';
  1771. }
  1772. if (!empty($arrayfields['t.progress']['checked'])) {
  1773. // Progress declared %
  1774. print '<td class="right">';
  1775. print $formother->select_percent($lines[$i]->progress, $lines[$i]->id.'progress');
  1776. print '</td>';
  1777. }
  1778. if (!empty($arrayfields['timeconsumed']['checked'])) {
  1779. // Time spent by everybody
  1780. print '<td class="right">';
  1781. // $lines[$i]->duration_effective is a denormalised field = summ of time spent by everybody for task. What we need is time consumed by user
  1782. if ($lines[$i]->duration_effective) {
  1783. print '<a href="'.DOL_URL_ROOT.'/projet/tasks/time.php?id='.((int) $lines[$i]->id).'">';
  1784. print convertSecondToTime($lines[$i]->duration_effective, 'allhourmin');
  1785. print '</a>';
  1786. } else {
  1787. print '--:--';
  1788. }
  1789. print "</td>\n";
  1790. // Time spent by user
  1791. print '<td class="right">';
  1792. $tmptimespent = $taskstatic->getSummaryOfTimeSpent($fuser->id);
  1793. if ($tmptimespent['total_duration']) {
  1794. print '<a href="'.DOL_URL_ROOT.'/projet/tasks/time.php?id='.((int) $lines[$i]->id).'&search_user='.((int) $fuser->id).'">';
  1795. print convertSecondToTime($tmptimespent['total_duration'], 'allhourmin');
  1796. print '</a>';
  1797. } else {
  1798. print '--:--';
  1799. }
  1800. print "</td>\n";
  1801. }
  1802. $disabledproject = 1;
  1803. $disabledtask = 1;
  1804. //print "x".$lines[$i]->fk_project;
  1805. //var_dump($lines[$i]);
  1806. //var_dump($projectsrole[$lines[$i]->fk_project]);
  1807. // If at least one role for project
  1808. if ($lines[$i]->public || !empty($projectsrole[$lines[$i]->fk_project]) || $user->hasRight('projet', 'all', 'creer')) {
  1809. $disabledproject = 0;
  1810. $disabledtask = 0;
  1811. }
  1812. // If $restricteditformytask is on and I have no role on task, i disable edit
  1813. if ($restricteditformytask && empty($tasksrole[$lines[$i]->id])) {
  1814. $disabledtask = 1;
  1815. }
  1816. //var_dump($projectstatic->weekWorkLoadPerTask);
  1817. // Fields to show current time
  1818. $tableCell = '';
  1819. $modeinput = 'hours';
  1820. for ($idw = 0; $idw < 7; $idw++) {
  1821. $tmpday = dol_time_plus_duree($firstdaytoshow, $idw, 'd');
  1822. if (!isset($totalforeachday[$tmpday])) {
  1823. $totalforeachday[$tmpday] = 0;
  1824. }
  1825. $cssonholiday = '';
  1826. if (!$isavailable[$tmpday]['morning'] && !$isavailable[$tmpday]['afternoon']) {
  1827. $cssonholiday .= 'onholidayallday ';
  1828. } elseif (!$isavailable[$tmpday]['morning']) {
  1829. $cssonholiday .= 'onholidaymorning ';
  1830. } elseif (!$isavailable[$tmpday]['afternoon']) {
  1831. $cssonholiday .= 'onholidayafternoon ';
  1832. }
  1833. $tmparray = dol_getdate($tmpday);
  1834. $dayWorkLoad = (!empty($projectstatic->weekWorkLoadPerTask[$tmpday][$lines[$i]->id]) ? $projectstatic->weekWorkLoadPerTask[$tmpday][$lines[$i]->id] : 0);
  1835. $totalforeachday[$tmpday] += $dayWorkLoad;
  1836. $alreadyspent = '';
  1837. if ($dayWorkLoad > 0) {
  1838. $alreadyspent = convertSecondToTime($dayWorkLoad, 'allhourmin');
  1839. }
  1840. $alttitle = $langs->trans("AddHereTimeSpentForDay", !empty($tmparray['day']) ? $tmparray['day'] : 0, $tmparray['mon']);
  1841. global $numstartworkingday, $numendworkingday;
  1842. $cssweekend = '';
  1843. 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.
  1844. $cssweekend = 'weekend';
  1845. }
  1846. $disabledtaskday = $disabledtask;
  1847. if (! $disabledtask && $restrictBefore && $tmpday < $restrictBefore) {
  1848. $disabledtaskday = 1;
  1849. }
  1850. $tableCell = '<td class="center hide'.$idw.($cssonholiday ? ' '.$cssonholiday : '').($cssweekend ? ' '.$cssweekend : '').'">';
  1851. //$tableCell .= 'idw='.$idw.' '.$conf->global->MAIN_START_WEEK.' '.$numstartworkingday.'-'.$numendworkingday;
  1852. $placeholder = '';
  1853. if ($alreadyspent) {
  1854. $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>';
  1855. //$placeholder=' placeholder="00:00"';
  1856. //$tableCell.='+';
  1857. }
  1858. $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"';
  1859. $tableCell .= ' onkeypress="return regexEvent(this,event,\'timeChar\')"';
  1860. $tableCell .= ' onkeyup="updateTotal('.$idw.',\''.$modeinput.'\')"';
  1861. $tableCell .= ' onblur="regexEvent(this,event,\''.$modeinput.'\'); updateTotal('.$idw.',\''.$modeinput.'\')" />';
  1862. $tableCell .= '</td>';
  1863. print $tableCell;
  1864. }
  1865. // Warning
  1866. print '<td class="right">';
  1867. if ((!$lines[$i]->public) && $disabledproject) {
  1868. print $form->textwithpicto('', $langs->trans("UserIsNotContactOfProject"));
  1869. } elseif ($disabledtask) {
  1870. $titleassigntask = $langs->trans("AssignTaskToMe");
  1871. if ($fuser->id != $user->id) {
  1872. $titleassigntask = $langs->trans("AssignTaskToUser", '...');
  1873. }
  1874. print $form->textwithpicto('', $langs->trans("TaskIsNotAssignedToUser", $titleassigntask));
  1875. }
  1876. print '</td>';
  1877. print "</tr>\n";
  1878. }
  1879. // Call to show task with a lower level (task under the current task)
  1880. $inc++;
  1881. $level++;
  1882. if ($lines[$i]->id > 0) {
  1883. //var_dump('totalforeachday after taskid='.$lines[$i]->id.' and previous one on level '.$level);
  1884. //var_dump($totalforeachday);
  1885. $ret = projectLinesPerWeek($inc, $firstdaytoshow, $fuser, $lines[$i]->id, ($parent == 0 ? $lineswithoutlevel0 : $lines), $level, $projectsrole, $tasksrole, $mine, $restricteditformytask, $isavailable, $oldprojectforbreak, $arrayfields, $extrafields);
  1886. //var_dump('ret with parent='.$lines[$i]->id.' level='.$level);
  1887. //var_dump($ret);
  1888. foreach ($ret as $key => $val) {
  1889. $totalforeachday[$key] += $val;
  1890. }
  1891. //var_dump('totalforeachday after taskid='.$lines[$i]->id.' and previous one on level '.$level.' + subtasks');
  1892. //var_dump($totalforeachday);
  1893. }
  1894. $level--;
  1895. } else {
  1896. //$level--;
  1897. }
  1898. }
  1899. return $totalforeachday;
  1900. }
  1901. /**
  1902. * Output a task line into a perday intput mode
  1903. *
  1904. * @param string $inc Line output identificator (start to 0, then increased by recursive call)
  1905. * @param int $firstdaytoshow First day to show
  1906. * @param User|null $fuser Restrict list to user if defined
  1907. * @param string $parent Id of parent task to show (0 to show all)
  1908. * @param Task[] $lines Array of lines (list of tasks but we will show only if we have a specific role on task)
  1909. * @param int $level Level (start to 0, then increased/decrease by recursive call)
  1910. * @param string $projectsrole Array of roles user has on project
  1911. * @param string $tasksrole Array of roles user has on task
  1912. * @param string $mine Show only task lines I am assigned to
  1913. * @param int $restricteditformytask 0=No restriction, 1=Enable add time only if task is a task i am affected to
  1914. * @param array $isavailable Array with data that say if user is available for several days for morning and afternoon
  1915. * @param int $oldprojectforbreak Old project id of last project break
  1916. * @param array $TWeek Array of week numbers
  1917. * @return array Array with time spent for $fuser for each day of week on tasks in $lines and substasks
  1918. */
  1919. function projectLinesPerMonth(&$inc, $firstdaytoshow, $fuser, $parent, $lines, &$level, &$projectsrole, &$tasksrole, $mine, $restricteditformytask, &$isavailable, $oldprojectforbreak = 0, $TWeek = array())
  1920. {
  1921. global $conf, $db, $user, $langs;
  1922. global $form, $formother, $projectstatic, $taskstatic, $thirdpartystatic;
  1923. $numlines = count($lines);
  1924. $lastprojectid = 0;
  1925. $workloadforid = array();
  1926. $totalforeachweek = array();
  1927. $lineswithoutlevel0 = array();
  1928. // Create a smaller array with sublevels only to be used later. This increase dramatically performances.
  1929. if ($parent == 0) { // Always and only if at first level
  1930. for ($i = 0; $i < $numlines; $i++) {
  1931. if ($lines[$i]->fk_task_parent) {
  1932. $lineswithoutlevel0[] = $lines[$i];
  1933. }
  1934. }
  1935. }
  1936. //dol_syslog('projectLinesPerWeek inc='.$inc.' firstdaytoshow='.$firstdaytoshow.' task parent id='.$parent.' level='.$level." count(lines)=".$numlines." count(lineswithoutlevel0)=".count($lineswithoutlevel0));
  1937. if (empty($oldprojectforbreak)) {
  1938. $oldprojectforbreak = (!getDolGlobalString('PROJECT_TIMESHEET_DISABLEBREAK_ON_PROJECT') ? 0 : -1); // 0 = start break, -1 = never break
  1939. }
  1940. $restrictBefore = null;
  1941. if (getDolGlobalString('PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS')) {
  1942. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  1943. $restrictBefore = dol_time_plus_duree(dol_now(), - $conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS, 'm');
  1944. }
  1945. for ($i = 0; $i < $numlines; $i++) {
  1946. if ($parent == 0) {
  1947. $level = 0;
  1948. }
  1949. if ($lines[$i]->fk_task_parent == $parent) {
  1950. // If we want all or we have a role on task, we show it
  1951. if (empty($mine) || !empty($tasksrole[$lines[$i]->id])) {
  1952. //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);
  1953. if ($restricteditformytask == 2 && empty($tasksrole[$lines[$i]->id])) { // we have no role on task and we request to hide such cases
  1954. continue;
  1955. }
  1956. // Break on a new project
  1957. if ($parent == 0 && $lines[$i]->fk_project != $lastprojectid) {
  1958. $lastprojectid = $lines[$i]->fk_project;
  1959. $projectstatic->id = $lines[$i]->fk_project;
  1960. }
  1961. //var_dump('--- '.$level.' '.$firstdaytoshow.' '.$fuser->id.' '.$projectstatic->id.' '.$workloadforid[$projectstatic->id]);
  1962. //var_dump($projectstatic->weekWorkLoadPerTask);
  1963. if (empty($workloadforid[$projectstatic->id])) {
  1964. $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
  1965. $workloadforid[$projectstatic->id] = 1;
  1966. }
  1967. //var_dump($projectstatic->weekWorkLoadPerTask);
  1968. //var_dump('--- '.$projectstatic->id.' '.$workloadforid[$projectstatic->id]);
  1969. $projectstatic->id = $lines[$i]->fk_project;
  1970. $projectstatic->ref = $lines[$i]->projectref;
  1971. $projectstatic->title = $lines[$i]->projectlabel;
  1972. $projectstatic->public = $lines[$i]->public;
  1973. $projectstatic->thirdparty_name = $lines[$i]->thirdparty_name;
  1974. $projectstatic->status = $lines[$i]->projectstatus;
  1975. $taskstatic->id = $lines[$i]->id;
  1976. $taskstatic->ref = ($lines[$i]->ref ? $lines[$i]->ref : $lines[$i]->id);
  1977. $taskstatic->label = $lines[$i]->label;
  1978. $taskstatic->date_start = $lines[$i]->date_start;
  1979. $taskstatic->date_end = $lines[$i]->date_end;
  1980. $thirdpartystatic->id = $lines[$i]->thirdparty_id;
  1981. $thirdpartystatic->name = $lines[$i]->thirdparty_name;
  1982. $thirdpartystatic->email = $lines[$i]->thirdparty_email;
  1983. if (empty($oldprojectforbreak) || ($oldprojectforbreak != -1 && $oldprojectforbreak != $projectstatic->id)) {
  1984. print '<tr class="oddeven trforbreak nobold">'."\n";
  1985. print '<td colspan="'.(6 + count($TWeek)).'">';
  1986. print $projectstatic->getNomUrl(1, '', 0, '<strong>'.$langs->transnoentitiesnoconv("YourRole").':</strong> '.$projectsrole[$lines[$i]->fk_project]);
  1987. if ($thirdpartystatic->id > 0) {
  1988. print ' - '.$thirdpartystatic->getNomUrl(1);
  1989. }
  1990. if ($projectstatic->title) {
  1991. print ' - ';
  1992. print '<span class="secondary">'.$projectstatic->title.'</span>';
  1993. }
  1994. print '</td>';
  1995. print '</tr>';
  1996. }
  1997. if ($oldprojectforbreak != -1) {
  1998. $oldprojectforbreak = $projectstatic->id;
  1999. }
  2000. print '<tr class="oddeven" data-taskid="'.$lines[$i]->id.'">'."\n";
  2001. // User
  2002. /*
  2003. print '<td class="nowrap">';
  2004. print $fuser->getNomUrl(1, 'withproject', 'time');
  2005. print '</td>';
  2006. */
  2007. // Project
  2008. /*print '<td class="nowrap">';
  2009. if ($oldprojectforbreak == -1) print $projectstatic->getNomUrl(1,'',0,$langs->transnoentitiesnoconv("YourRole").': '.$projectsrole[$lines[$i]->fk_project]);
  2010. print "</td>";*/
  2011. // Thirdparty
  2012. /*print '<td class="tdoverflowmax100">';
  2013. if ($thirdpartystatic->id > 0) print $thirdpartystatic->getNomUrl(1, 'project');
  2014. print '</td>';*/
  2015. // Ref
  2016. print '<td class="nowrap">';
  2017. print '<!-- Task id = '.$lines[$i]->id.' (projectlinespermonth) -->';
  2018. for ($k = 0; $k < $level; $k++) {
  2019. print '<div class="marginleftonly">';
  2020. }
  2021. print $taskstatic->getNomUrl(1, 'withproject', 'time');
  2022. // Label task
  2023. print '<br>';
  2024. print '<div class="opacitymedium tdoverflowmax500" title="'.dol_escape_htmltag($taskstatic->label).'">'.dol_escape_htmltag($taskstatic->label).'</div>';
  2025. for ($k = 0; $k < $level; $k++) {
  2026. print "</div>";
  2027. }
  2028. print "</td>\n";
  2029. // Planned Workload
  2030. print '<td class="leftborder plannedworkload right">';
  2031. if ($lines[$i]->planned_workload) {
  2032. print convertSecondToTime($lines[$i]->planned_workload, 'allhourmin');
  2033. } else {
  2034. print '--:--';
  2035. }
  2036. print '</td>';
  2037. // Progress declared %
  2038. print '<td class="right">';
  2039. print $formother->select_percent($lines[$i]->progress, $lines[$i]->id.'progress');
  2040. print '</td>';
  2041. // Time spent by everybody
  2042. print '<td class="right">';
  2043. // $lines[$i]->duration_effective is a denormalised field = summ of time spent by everybody for task. What we need is time consumed by user
  2044. if ($lines[$i]->duration_effective) {
  2045. print '<a href="'.DOL_URL_ROOT.'/projet/tasks/time.php?id='.$lines[$i]->id.'">';
  2046. print convertSecondToTime($lines[$i]->duration_effective, 'allhourmin');
  2047. print '</a>';
  2048. } else {
  2049. print '--:--';
  2050. }
  2051. print "</td>\n";
  2052. // Time spent by user
  2053. print '<td class="right">';
  2054. $tmptimespent = $taskstatic->getSummaryOfTimeSpent($fuser->id);
  2055. if ($tmptimespent['total_duration']) {
  2056. print convertSecondToTime($tmptimespent['total_duration'], 'allhourmin');
  2057. } else {
  2058. print '--:--';
  2059. }
  2060. print "</td>\n";
  2061. $disabledproject = 1;
  2062. $disabledtask = 1;
  2063. //print "x".$lines[$i]->fk_project;
  2064. //var_dump($lines[$i]);
  2065. //var_dump($projectsrole[$lines[$i]->fk_project]);
  2066. // If at least one role for project
  2067. if ($lines[$i]->public || !empty($projectsrole[$lines[$i]->fk_project]) || $user->hasRight('projet', 'all', 'creer')) {
  2068. $disabledproject = 0;
  2069. $disabledtask = 0;
  2070. }
  2071. // If $restricteditformytask is on and I have no role on task, i disable edit
  2072. if ($restricteditformytask && empty($tasksrole[$lines[$i]->id])) {
  2073. $disabledtask = 1;
  2074. }
  2075. //var_dump($projectstatic->weekWorkLoadPerTask);
  2076. //TODO
  2077. // Fields to show current time
  2078. $tableCell = '';
  2079. $modeinput = 'hours';
  2080. $TFirstDay = getFirstDayOfEachWeek($TWeek, date('Y', $firstdaytoshow));
  2081. $TFirstDay[reset($TWeek)] = 1;
  2082. $firstdaytoshowarray = dol_getdate($firstdaytoshow);
  2083. $year = $firstdaytoshowarray['year'];
  2084. $month = $firstdaytoshowarray['mon'];
  2085. foreach ($TWeek as $weekIndex => $weekNb) {
  2086. $weekWorkLoad = !empty($projectstatic->monthWorkLoadPerTask[$weekNb][$lines[$i]->id]) ? $projectstatic->monthWorkLoadPerTask[$weekNb][$lines[$i]->id] : 0 ;
  2087. if (!isset($totalforeachweek[$weekNb])) {
  2088. $totalforeachweek[$weekNb] = 0;
  2089. }
  2090. $totalforeachweek[$weekNb] += $weekWorkLoad;
  2091. $alreadyspent = '';
  2092. if ($weekWorkLoad > 0) {
  2093. $alreadyspent = convertSecondToTime($weekWorkLoad, 'allhourmin');
  2094. }
  2095. $alttitle = $langs->trans("AddHereTimeSpentForWeek", $weekNb);
  2096. $disabledtaskweek = $disabledtask;
  2097. $firstdayofweek = dol_mktime(0, 0, 0, $month, $TFirstDay[$weekIndex], $year);
  2098. if (! $disabledtask && $restrictBefore && $firstdayofweek < $restrictBefore) {
  2099. $disabledtaskweek = 1;
  2100. }
  2101. $tableCell = '<td class="center hide weekend">';
  2102. $placeholder = '';
  2103. if ($alreadyspent) {
  2104. $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>';
  2105. //$placeholder=' placeholder="00:00"';
  2106. //$tableCell.='+';
  2107. }
  2108. $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"';
  2109. $tableCell .= ' onkeypress="return regexEvent(this,event,\'timeChar\')"';
  2110. $tableCell .= ' onkeyup="updateTotal('.$weekNb.',\''.$modeinput.'\')"';
  2111. $tableCell .= ' onblur="regexEvent(this,event,\''.$modeinput.'\'); updateTotal('.$weekNb.',\''.$modeinput.'\')" />';
  2112. $tableCell .= '</td>';
  2113. print $tableCell;
  2114. }
  2115. // Warning
  2116. print '<td class="right">';
  2117. if ((!$lines[$i]->public) && $disabledproject) {
  2118. print $form->textwithpicto('', $langs->trans("UserIsNotContactOfProject"));
  2119. } elseif ($disabledtask) {
  2120. $titleassigntask = $langs->trans("AssignTaskToMe");
  2121. if ($fuser->id != $user->id) {
  2122. $titleassigntask = $langs->trans("AssignTaskToUser", '...');
  2123. }
  2124. print $form->textwithpicto('', $langs->trans("TaskIsNotAssignedToUser", $titleassigntask));
  2125. }
  2126. print '</td>';
  2127. print "</tr>\n";
  2128. }
  2129. // Call to show task with a lower level (task under the current task)
  2130. $inc++;
  2131. $level++;
  2132. if ($lines[$i]->id > 0) {
  2133. //var_dump('totalforeachday after taskid='.$lines[$i]->id.' and previous one on level '.$level);
  2134. //var_dump($totalforeachday);
  2135. $ret = projectLinesPerMonth($inc, $firstdaytoshow, $fuser, $lines[$i]->id, ($parent == 0 ? $lineswithoutlevel0 : $lines), $level, $projectsrole, $tasksrole, $mine, $restricteditformytask, $isavailable, $oldprojectforbreak, $TWeek);
  2136. //var_dump('ret with parent='.$lines[$i]->id.' level='.$level);
  2137. //var_dump($ret);
  2138. foreach ($ret as $key => $val) {
  2139. $totalforeachweek[$key] += $val;
  2140. }
  2141. //var_dump('totalforeachday after taskid='.$lines[$i]->id.' and previous one on level '.$level.' + subtasks');
  2142. //var_dump($totalforeachday);
  2143. }
  2144. $level--;
  2145. } else {
  2146. //$level--;
  2147. }
  2148. }
  2149. return $totalforeachweek;
  2150. }
  2151. /**
  2152. * Search in task lines with a particular parent if there is a task for a particular user (in taskrole)
  2153. *
  2154. * @param string $inc Counter that count number of lines legitimate to show (for return)
  2155. * @param int $parent Id of parent task to start
  2156. * @param array $lines Array of all tasks
  2157. * @param string $taskrole Array of task filtered on a particular user
  2158. * @return int 1 if there is
  2159. */
  2160. function searchTaskInChild(&$inc, $parent, &$lines, &$taskrole)
  2161. {
  2162. //print 'Search in line with parent id = '.$parent.'<br>';
  2163. $numlines = count($lines);
  2164. for ($i = 0; $i < $numlines; $i++) {
  2165. // Process line $lines[$i]
  2166. if ($lines[$i]->fk_task_parent == $parent && $lines[$i]->id != $lines[$i]->fk_task_parent) {
  2167. // If task is legitimate to show, no more need to search deeper
  2168. if (isset($taskrole[$lines[$i]->id])) {
  2169. //print 'Found a legitimate task id='.$lines[$i]->id.'<br>';
  2170. $inc++;
  2171. return $inc;
  2172. }
  2173. searchTaskInChild($inc, $lines[$i]->id, $lines, $taskrole);
  2174. //print 'Found inc='.$inc.'<br>';
  2175. if ($inc > 0) {
  2176. return $inc;
  2177. }
  2178. }
  2179. }
  2180. return $inc;
  2181. }
  2182. /**
  2183. * Return HTML table with list of projects and number of opened tasks
  2184. *
  2185. * @param DoliDB $db Database handler
  2186. * @param Form $form Object form
  2187. * @param int $socid Id thirdparty
  2188. * @param int $projectsListId Id of project I have permission on
  2189. * @param int $mytasks Limited to task I am contact to
  2190. * @param int $status -1=No filter on statut, 0 or 1 = Filter on status
  2191. * @param array $listofoppstatus List of opportunity status
  2192. * @param array $hiddenfields List of info to not show ('projectlabel', 'declaredprogress', '...', )
  2193. * @param int $max Max nb of record to show in HTML list
  2194. * @return void
  2195. */
  2196. function print_projecttasks_array($db, $form, $socid, $projectsListId, $mytasks = 0, $status = -1, $listofoppstatus = array(), $hiddenfields = array(), $max = 0)
  2197. {
  2198. global $langs, $conf, $user;
  2199. global $theme_datacolor;
  2200. $maxofloop = (!getDolGlobalString('MAIN_MAXLIST_OVERLOAD') ? 500 : $conf->global->MAIN_MAXLIST_OVERLOAD);
  2201. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  2202. $listofstatus = array_keys($listofoppstatus);
  2203. if (is_array($listofstatus) && getDolGlobalString('USE_COLOR_FOR_PROSPECTION_STATUS')) {
  2204. // Define $themeColorId and array $statusOppList for each $listofstatus
  2205. $themeColorId = 0;
  2206. $statusOppList = array();
  2207. foreach ($listofstatus as $oppStatus) {
  2208. $oppStatusCode = dol_getIdFromCode($db, $oppStatus, 'c_lead_status', 'rowid', 'code');
  2209. if ($oppStatusCode) {
  2210. $statusOppList[$oppStatus]['code'] = $oppStatusCode;
  2211. $statusOppList[$oppStatus]['color'] = isset($theme_datacolor[$themeColorId]) ? implode(', ', $theme_datacolor[$themeColorId]) : '';
  2212. }
  2213. $themeColorId++;
  2214. }
  2215. }
  2216. $projectstatic = new Project($db);
  2217. $thirdpartystatic = new Societe($db);
  2218. $sortfield = '';
  2219. $sortorder = '';
  2220. $project_year_filter = 0;
  2221. $title = $langs->trans("Projects");
  2222. if (strcmp($status, '') && $status >= 0) {
  2223. $title = $langs->trans("Projects").' '.$langs->trans($projectstatic->labelStatus[$status]);
  2224. }
  2225. print '<!-- print_projecttasks_array -->';
  2226. print '<div class="div-table-responsive-no-min">';
  2227. print '<table class="noborder centpercent">';
  2228. $sql = " FROM ".MAIN_DB_PREFIX."projet as p";
  2229. if ($mytasks) {
  2230. $sql .= ", ".MAIN_DB_PREFIX."projet_task as t";
  2231. $sql .= ", ".MAIN_DB_PREFIX."element_contact as ec";
  2232. $sql .= ", ".MAIN_DB_PREFIX."c_type_contact as ctc";
  2233. } else {
  2234. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet_task as t ON p.rowid = t.fk_projet";
  2235. }
  2236. $sql .= " WHERE p.entity IN (".getEntity('project').")";
  2237. $sql .= " AND p.rowid IN (".$db->sanitize($projectsListId).")";
  2238. if ($socid) {
  2239. $sql .= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".((int) $socid).")";
  2240. }
  2241. if ($mytasks) {
  2242. $sql .= " AND p.rowid = t.fk_projet";
  2243. $sql .= " AND ec.element_id = t.rowid";
  2244. $sql .= " AND ec.fk_socpeople = ".((int) $user->id);
  2245. $sql .= " AND ec.fk_c_type_contact = ctc.rowid"; // Replace the 2 lines with ec.fk_c_type_contact in $arrayidtypeofcontact
  2246. $sql .= " AND ctc.element = 'project_task'";
  2247. }
  2248. if ($status >= 0) {
  2249. $sql .= " AND p.fk_statut = ".(int) $status;
  2250. }
  2251. if (getDolGlobalString('PROJECT_LIMIT_YEAR_RANGE')) {
  2252. $project_year_filter = GETPOST("project_year_filter");
  2253. //Check if empty or invalid year. Wildcard ignores the sql check
  2254. if ($project_year_filter != "*") {
  2255. if (empty($project_year_filter) || !ctype_digit($project_year_filter)) {
  2256. $project_year_filter = date("Y");
  2257. }
  2258. $sql .= " AND (p.dateo IS NULL OR p.dateo <= ".$db->idate(dol_get_last_day($project_year_filter, 12, false)).")";
  2259. $sql .= " AND (p.datee IS NULL OR p.datee >= ".$db->idate(dol_get_first_day($project_year_filter, 1, false)).")";
  2260. }
  2261. }
  2262. // Get id of project we must show tasks
  2263. $arrayidofprojects = array();
  2264. $sql1 = "SELECT p.rowid as projectid";
  2265. $sql1 .= $sql;
  2266. $resql = $db->query($sql1);
  2267. if ($resql) {
  2268. $i = 0;
  2269. $num = $db->num_rows($resql);
  2270. while ($i < $num) {
  2271. $objp = $db->fetch_object($resql);
  2272. $arrayidofprojects[$objp->projectid] = $objp->projectid;
  2273. $i++;
  2274. }
  2275. } else {
  2276. dol_print_error($db);
  2277. }
  2278. if (empty($arrayidofprojects)) {
  2279. $arrayidofprojects[0] = -1;
  2280. }
  2281. // Get list of project with calculation on tasks
  2282. $sql2 = "SELECT p.rowid as projectid, p.ref, p.title, p.fk_soc,";
  2283. $sql2 .= " s.rowid as socid, s.nom as socname, s.name_alias,";
  2284. $sql2 .= " s.code_client, s.code_compta, s.client,";
  2285. $sql2 .= " s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur,";
  2286. $sql2 .= " s.logo, s.email, s.entity,";
  2287. $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,";
  2288. $sql2 .= " p.dateo, p.datee,";
  2289. $sql2 .= " COUNT(t.rowid) as nb, SUM(t.planned_workload) as planned_workload, SUM(t.planned_workload * t.progress / 100) as declared_progess_workload";
  2290. $sql2 .= " FROM ".MAIN_DB_PREFIX."projet as p";
  2291. $sql2 .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = p.fk_soc";
  2292. $sql2 .= " LEFT JOIN ".MAIN_DB_PREFIX."projet_task as t ON p.rowid = t.fk_projet";
  2293. $sql2 .= " WHERE p.rowid IN (".$db->sanitize(join(',', $arrayidofprojects)).")";
  2294. $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,";
  2295. $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";
  2296. $sql2 .= " ORDER BY p.title, p.ref";
  2297. $resql = $db->query($sql2);
  2298. if ($resql) {
  2299. $othernb = 0;
  2300. $total_task = 0;
  2301. $total_opp_amount = 0;
  2302. $ponderated_opp_amount = 0;
  2303. $total_plannedworkload = 0;
  2304. $total_declaredprogressworkload = 0;
  2305. $num = $db->num_rows($resql);
  2306. $nbofloop = min($num, (!getDolGlobalString('MAIN_MAXLIST_OVERLOAD') ? 500 : $conf->global->MAIN_MAXLIST_OVERLOAD));
  2307. $i = 0;
  2308. print '<tr class="liste_titre">';
  2309. 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);
  2310. print_liste_field_titre("ThirdParty", $_SERVER["PHP_SELF"], "", "", "", "", $sortfield, $sortorder);
  2311. if (getDolGlobalString('PROJECT_USE_OPPORTUNITIES')) {
  2312. if (!in_array('prospectionstatus', $hiddenfields)) {
  2313. print_liste_field_titre("OpportunityStatus", "", "", "", "", 'style="max-width: 100px"', $sortfield, $sortorder, 'center ');
  2314. }
  2315. 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 ');
  2316. //print_liste_field_titre('OpportunityWeightedAmount', '', '', '', '', 'align="right"', $sortfield, $sortorder);
  2317. }
  2318. if (!getDolGlobalString('PROJECT_HIDE_TASKS')) {
  2319. print_liste_field_titre("Tasks", "", "", "", "", 'align="right"', $sortfield, $sortorder);
  2320. if (!in_array('plannedworkload', $hiddenfields)) {
  2321. print_liste_field_titre("PlannedWorkload", "", "", "", "", 'style="max-width: 100px"', $sortfield, $sortorder, 'right ');
  2322. }
  2323. if (!in_array('declaredprogress', $hiddenfields)) {
  2324. print_liste_field_titre("%", "", "", "", "", '', $sortfield, $sortorder, 'right ', $langs->trans("ProgressDeclared"));
  2325. }
  2326. }
  2327. if (!in_array('projectstatus', $hiddenfields)) {
  2328. print_liste_field_titre("Status", "", "", "", "", '', $sortfield, $sortorder, 'right ');
  2329. }
  2330. print "</tr>\n";
  2331. while ($i < $nbofloop) {
  2332. $objp = $db->fetch_object($resql);
  2333. if ($max && $i >= $max) {
  2334. $othernb++;
  2335. $i++;
  2336. $total_task += $objp->nb;
  2337. $total_opp_amount += $objp->opp_amount;
  2338. $opp_weighted_amount = $objp->opp_percent * $objp->opp_amount / 100;
  2339. $ponderated_opp_amount += price2num($opp_weighted_amount);
  2340. $plannedworkload = $objp->planned_workload;
  2341. $total_plannedworkload += $plannedworkload;
  2342. $declaredprogressworkload = $objp->declared_progess_workload;
  2343. $total_declaredprogressworkload += $declaredprogressworkload;
  2344. continue;
  2345. }
  2346. $projectstatic->id = $objp->projectid;
  2347. $projectstatic->user_author_id = $objp->fk_user_creat;
  2348. $projectstatic->public = $objp->public;
  2349. // Check is user has read permission on project
  2350. $userAccess = $projectstatic->restrictedProjectArea($user);
  2351. if ($userAccess >= 0) {
  2352. $projectstatic->ref = $objp->ref;
  2353. $projectstatic->status = $objp->status;
  2354. $projectstatic->title = $objp->title;
  2355. $projectstatic->date_end = $db->jdate($objp->datee);
  2356. $projectstatic->date_start = $db->jdate($objp->dateo);
  2357. print '<tr class="oddeven">';
  2358. print '<td class="tdoverflowmax150">';
  2359. print $projectstatic->getNomUrl(1, '', 0, '', '-', 0, -1, 'nowraponall');
  2360. if (!in_array('projectlabel', $hiddenfields)) {
  2361. print '<br><span class="opacitymedium small">'.dol_escape_htmltag($objp->title).'</span>';
  2362. }
  2363. print '</td>';
  2364. print '<td class="nowraponall tdoverflowmax100">';
  2365. if ($objp->fk_soc > 0) {
  2366. $thirdpartystatic->id = $objp->socid;
  2367. $thirdpartystatic->name = $objp->socname;
  2368. //$thirdpartystatic->name_alias = $objp->name_alias;
  2369. //$thirdpartystatic->code_client = $objp->code_client;
  2370. $thirdpartystatic->code_compta = $objp->code_compta;
  2371. $thirdpartystatic->client = $objp->client;
  2372. //$thirdpartystatic->code_fournisseur = $objp->code_fournisseur;
  2373. $thirdpartystatic->code_compta_fournisseur = $objp->code_compta_fournisseur;
  2374. $thirdpartystatic->fournisseur = $objp->fournisseur;
  2375. $thirdpartystatic->logo = $objp->logo;
  2376. $thirdpartystatic->email = $objp->email;
  2377. $thirdpartystatic->entity = $objp->entity;
  2378. print $thirdpartystatic->getNomUrl(1);
  2379. }
  2380. print '</td>';
  2381. if (getDolGlobalString('PROJECT_USE_OPPORTUNITIES')) {
  2382. if (!in_array('prospectionstatus', $hiddenfields)) {
  2383. print '<td class="center tdoverflowmax75">';
  2384. // Because color of prospection status has no meaning yet, it is used if hidden constant is set
  2385. if (!getDolGlobalString('USE_COLOR_FOR_PROSPECTION_STATUS')) {
  2386. $oppStatusCode = dol_getIdFromCode($db, $objp->opp_status, 'c_lead_status', 'rowid', 'code');
  2387. if ($langs->trans("OppStatus".$oppStatusCode) != "OppStatus".$oppStatusCode) {
  2388. print $langs->trans("OppStatus".$oppStatusCode);
  2389. }
  2390. } else {
  2391. if (isset($statusOppList[$objp->opp_status])) {
  2392. $oppStatusCode = $statusOppList[$objp->opp_status]['code'];
  2393. $oppStatusColor = $statusOppList[$objp->opp_status]['color'];
  2394. } else {
  2395. $oppStatusCode = dol_getIdFromCode($db, $objp->opp_status, 'c_lead_status', 'rowid', 'code');
  2396. $oppStatusColor = '';
  2397. }
  2398. if ($oppStatusCode) {
  2399. if (!empty($oppStatusColor)) {
  2400. 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>';
  2401. } else {
  2402. print '<a href="'.dol_buildpath('/projet/list.php?search_opp_status='.$objp->opp_status, 1).'" title="'.$langs->trans("OppStatus".$oppStatusCode).'">'.$oppStatusCode.'</a>';
  2403. }
  2404. }
  2405. }
  2406. print '</td>';
  2407. }
  2408. print '<td class="right">';
  2409. if ($objp->opp_percent && $objp->opp_amount) {
  2410. $opp_weighted_amount = $objp->opp_percent * $objp->opp_amount / 100;
  2411. $alttext = $langs->trans("OpportunityWeightedAmount").' '.price($opp_weighted_amount, 0, '', 1, -1, 0, $conf->currency);
  2412. $ponderated_opp_amount += price2num($opp_weighted_amount);
  2413. }
  2414. if ($objp->opp_amount) {
  2415. print '<span class="amount" title="'.$alttext.'">'.$form->textwithpicto(price($objp->opp_amount, 0, '', 1, -1, 0), $alttext).'</span>';
  2416. }
  2417. print '</td>';
  2418. }
  2419. if (!getDolGlobalString('PROJECT_HIDE_TASKS')) {
  2420. print '<td class="right">'.$objp->nb.'</td>';
  2421. $plannedworkload = $objp->planned_workload;
  2422. $total_plannedworkload += $plannedworkload;
  2423. if (!in_array('plannedworkload', $hiddenfields)) {
  2424. print '<td class="right nowraponall">'.($plannedworkload ? convertSecondToTime($plannedworkload) : '').'</td>';
  2425. }
  2426. if (!in_array('declaredprogress', $hiddenfields)) {
  2427. $declaredprogressworkload = $objp->declared_progess_workload;
  2428. $total_declaredprogressworkload += $declaredprogressworkload;
  2429. print '<td class="right nowraponall">';
  2430. //print $objp->planned_workload.'-'.$objp->declared_progess_workload."<br>";
  2431. print($plannedworkload ? round(100 * $declaredprogressworkload / $plannedworkload, 0).'%' : '');
  2432. print '</td>';
  2433. }
  2434. }
  2435. if (!in_array('projectstatus', $hiddenfields)) {
  2436. print '<td class="right">';
  2437. print $projectstatic->getLibStatut(3);
  2438. print '</td>';
  2439. }
  2440. print "</tr>\n";
  2441. $total_task += $objp->nb;
  2442. $total_opp_amount += $objp->opp_amount;
  2443. }
  2444. $i++;
  2445. }
  2446. if ($othernb) {
  2447. print '<tr class="oddeven">';
  2448. print '<td class="nowrap" colspan="5">';
  2449. print '<span class="opacitymedium">'.$langs->trans("More").'...'.($othernb < $maxofloop ? ' ('.$othernb.')' : '').'</span>';
  2450. print '</td>';
  2451. print "</tr>\n";
  2452. }
  2453. print '<tr class="liste_total">';
  2454. print '<td>'.$langs->trans("Total")."</td><td></td>";
  2455. if (getDolGlobalString('PROJECT_USE_OPPORTUNITIES')) {
  2456. if (!in_array('prospectionstatus', $hiddenfields)) {
  2457. print '<td class="liste_total"></td>';
  2458. }
  2459. print '<td class="liste_total right">';
  2460. //$form->textwithpicto(price($ponderated_opp_amount, 0, '', 1, -1, -1, $conf->currency), $langs->trans("OpportunityPonderatedAmountDesc"), 1);
  2461. print $form->textwithpicto(price($total_opp_amount, 0, '', 1, -1, 0), $langs->trans("OpportunityPonderatedAmountDesc").' : '.price($ponderated_opp_amount, 0, '', 1, -1, 0, $conf->currency));
  2462. print '</td>';
  2463. }
  2464. if (!getDolGlobalString('PROJECT_HIDE_TASKS')) {
  2465. print '<td class="liste_total right">'.$total_task.'</td>';
  2466. if (!in_array('plannedworkload', $hiddenfields)) {
  2467. print '<td class="liste_total right">'.($total_plannedworkload ? convertSecondToTime($total_plannedworkload) : '').'</td>';
  2468. }
  2469. if (!in_array('declaredprogress', $hiddenfields)) {
  2470. print '<td class="liste_total right">'.($total_plannedworkload ? round(100 * $total_declaredprogressworkload / $total_plannedworkload, 0).'%' : '').'</td>';
  2471. }
  2472. }
  2473. if (!in_array('projectstatus', $hiddenfields)) {
  2474. print '<td class="liste_total"></td>';
  2475. }
  2476. print '</tr>';
  2477. $db->free($resql);
  2478. } else {
  2479. dol_print_error($db);
  2480. }
  2481. print "</table>";
  2482. print '</div>';
  2483. if (getDolGlobalString('PROJECT_LIMIT_YEAR_RANGE')) {
  2484. //Add the year filter input
  2485. print '<form method="get" action="'.$_SERVER["PHP_SELF"].'">';
  2486. print '<table width="100%">';
  2487. print '<tr>';
  2488. print '<td>'.$langs->trans("Year").'</td>';
  2489. print '<td class="right"><input type="text" size="4" class="flat" name="project_year_filter" value="'.((int) $project_year_filter).'"/>';
  2490. print "</tr>\n";
  2491. print '</table></form>';
  2492. }
  2493. }
  2494. /**
  2495. * @param Task $task the task object
  2496. * @param bool|string $label true = auto, false = dont display, string = replace output
  2497. * @param bool|string $progressNumber true = auto, false = dont display, string = replace output
  2498. * @param bool $hideOnProgressNull hide if progress is null
  2499. * @param bool $spaced used to add space at bottom (made by css)
  2500. * @return string
  2501. * @see getTaskProgressBadge()
  2502. */
  2503. function getTaskProgressView($task, $label = true, $progressNumber = true, $hideOnProgressNull = false, $spaced = false)
  2504. {
  2505. global $langs, $conf;
  2506. $out = '';
  2507. $plannedworkloadoutputformat = 'allhourmin';
  2508. $timespentoutputformat = 'allhourmin';
  2509. if (getDolGlobalString('PROJECT_PLANNED_WORKLOAD_FORMAT')) {
  2510. $plannedworkloadoutputformat = $conf->global->PROJECT_PLANNED_WORKLOAD_FORMAT;
  2511. }
  2512. if (getDolGlobalString('PROJECT_TIMES_SPENT_FORMAT')) {
  2513. $timespentoutputformat = $conf->global->PROJECT_TIME_SPENT_FORMAT;
  2514. }
  2515. if (empty($task->progress) && !empty($hideOnProgressNull)) {
  2516. return '';
  2517. }
  2518. $spaced = !empty($spaced) ? 'spaced' : '';
  2519. $diff = '';
  2520. // define progress color according to time spend vs workload
  2521. $progressBarClass = 'progress-bar-info';
  2522. $progressCalculated = 0;
  2523. if ($task->planned_workload) {
  2524. $progressCalculated = round(100 * (float) $task->duration_effective / (float) $task->planned_workload, 2);
  2525. // this conf is actually hidden, by default we use 10% for "be carefull or warning"
  2526. $warningRatio = getDolGlobalString('PROJECT_TIME_SPEND_WARNING_PERCENT') ? (1 + $conf->global->PROJECT_TIME_SPEND_WARNING_PERCENT / 100) : 1.10;
  2527. $diffTitle = '<br>'.$langs->trans('ProgressDeclared').' : '.$task->progress.(isset($task->progress) ? '%' : '');
  2528. $diffTitle .= '<br>'.$langs->trans('ProgressCalculated').' : '.$progressCalculated.(isset($progressCalculated) ? '%' : '');
  2529. //var_dump($progressCalculated.' '.$warningRatio.' '.$task->progress.' '.floatval($task->progress * $warningRatio));
  2530. if ((float) $progressCalculated > (float) ($task->progress * $warningRatio)) {
  2531. $progressBarClass = 'progress-bar-danger';
  2532. $title = $langs->trans('TheReportedProgressIsLessThanTheCalculatedProgressionByX', abs($task->progress - $progressCalculated).' '.$langs->trans("point"));
  2533. $diff = '<span class="text-danger classfortooltip paddingrightonly" title="'.dol_htmlentities($title.$diffTitle).'" ><i class="fa fa-caret-down"></i> '.($task->progress - $progressCalculated).'%</span>';
  2534. } elseif ((float) $progressCalculated > (float) $task->progress) { // warning if close at 10%
  2535. $progressBarClass = 'progress-bar-warning';
  2536. $title = $langs->trans('TheReportedProgressIsLessThanTheCalculatedProgressionByX', abs($task->progress - $progressCalculated).' '.$langs->trans("point"));
  2537. $diff = '<span class="text-warning classfortooltip paddingrightonly" title="'.dol_htmlentities($title.$diffTitle).'" ><i class="fa fa-caret-left"></i> '.($task->progress - $progressCalculated).'%</span>';
  2538. } else {
  2539. $progressBarClass = 'progress-bar-success';
  2540. $title = $langs->trans('TheReportedProgressIsMoreThanTheCalculatedProgressionByX', ($task->progress - $progressCalculated).' '.$langs->trans("point"));
  2541. $diff = '<span class="text-success classfortooltip paddingrightonly" title="'.dol_htmlentities($title.$diffTitle).'" ><i class="fa fa-caret-up"></i> '.($task->progress - $progressCalculated).'%</span>';
  2542. }
  2543. }
  2544. $out .= '<div class="progress-group">';
  2545. if ($label !== false) {
  2546. $out .= ' <span class="progress-text">';
  2547. if ($label !== true) {
  2548. $out .= $label; // replace label by param
  2549. } else {
  2550. $out .= $task->getNomUrl(1).' '.dol_htmlentities($task->label);
  2551. }
  2552. $out .= ' </span>';
  2553. }
  2554. if ($progressNumber !== false) {
  2555. $out .= ' <span class="progress-number">';
  2556. if ($progressNumber !== true) {
  2557. $out .= $progressNumber; // replace label by param
  2558. } else {
  2559. if ($task->hasDelay()) {
  2560. $out .= img_warning($langs->trans("Late")).' ';
  2561. }
  2562. $url = DOL_URL_ROOT.'/projet/tasks/time.php?id='.$task->id;
  2563. $out .= !empty($diff) ? $diff.' ' : '';
  2564. $out .= '<a href="'.$url.'" >';
  2565. $out .= '<b title="'.$langs->trans('TimeSpent').'" >';
  2566. if ($task->duration_effective) {
  2567. $out .= convertSecondToTime($task->duration_effective, $timespentoutputformat);
  2568. } else {
  2569. $out .= '--:--';
  2570. }
  2571. $out .= '</b>';
  2572. $out .= '</a>';
  2573. $out .= ' / ';
  2574. $out .= '<a href="'.$url.'" >';
  2575. $out .= '<span title="'.$langs->trans('PlannedWorkload').'" >';
  2576. if ($task->planned_workload) {
  2577. $out .= convertSecondToTime($task->planned_workload, $plannedworkloadoutputformat);
  2578. } else {
  2579. $out .= '--:--';
  2580. }
  2581. $out .= '</a>';
  2582. }
  2583. $out .= ' </span>';
  2584. }
  2585. $out .= '</span>';
  2586. $out .= ' <div class="progress sm '.$spaced.'">';
  2587. $diffval = (float) $task->progress - (float) $progressCalculated;
  2588. if ($diffval >= 0) {
  2589. // good
  2590. $out .= ' <div class="progress-bar '.$progressBarClass.'" style="width: '.(float) $task->progress.'%" title="'.(float) $task->progress.'%">';
  2591. if (!empty($task->progress)) {
  2592. $out .= ' <div class="progress-bar progress-bar-consumed" style="width: '.(float) ($progressCalculated / ((float) $task->progress == 0 ? 1 : $task->progress) * 100).'%" title="'.(float) $progressCalculated.'%"></div>';
  2593. }
  2594. $out .= ' </div>';
  2595. } else {
  2596. // bad
  2597. $out .= ' <div class="progress-bar progress-bar-consumed-late" style="width: '.(float) $progressCalculated.'%" title="'.(float) $progressCalculated.'%">';
  2598. $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>';
  2599. $out .= ' </div>';
  2600. }
  2601. $out .= ' </div>';
  2602. $out .= '</div>';
  2603. return $out;
  2604. }
  2605. /**
  2606. * @param Task $task the task object
  2607. * @param string $label empty = auto (progress), string = replace output
  2608. * @param string $tooltip empty = auto , string = replace output
  2609. * @return string
  2610. * @see getTaskProgressView()
  2611. */
  2612. function getTaskProgressBadge($task, $label = '', $tooltip = '')
  2613. {
  2614. global $conf, $langs;
  2615. $out = '';
  2616. $badgeClass = '';
  2617. if ($task->progress != '') {
  2618. // TODO : manage 100%
  2619. // define color according to time spend vs workload
  2620. $badgeClass = 'badge ';
  2621. if ($task->planned_workload) {
  2622. $progressCalculated = round(100 * (float) $task->duration_effective / (float) $task->planned_workload, 2);
  2623. // this conf is actually hidden, by default we use 10% for "be carefull or warning"
  2624. $warningRatio = getDolGlobalString('PROJECT_TIME_SPEND_WARNING_PERCENT') ? (1 + $conf->global->PROJECT_TIME_SPEND_WARNING_PERCENT / 100) : 1.10;
  2625. if ((float) $progressCalculated > (float) ($task->progress * $warningRatio)) {
  2626. $badgeClass .= 'badge-danger';
  2627. if (empty($tooltip)) {
  2628. $tooltip = $task->progress.'% < '.$langs->trans("TimeConsumed").' '.$progressCalculated.'%';
  2629. }
  2630. } elseif ((float) $progressCalculated > (float) $task->progress) { // warning if close at 10%
  2631. $badgeClass .= 'badge-warning';
  2632. if (empty($tooltip)) {
  2633. $tooltip = $task->progress.'% < '.$langs->trans("TimeConsumed").' '.$progressCalculated.'%';
  2634. }
  2635. } else {
  2636. $badgeClass .= 'badge-success';
  2637. if (empty($tooltip)) {
  2638. $tooltip = $task->progress.'% >= '.$langs->trans("TimeConsumed").' '.$progressCalculated.'%';
  2639. }
  2640. }
  2641. }
  2642. }
  2643. $title = '';
  2644. if (!empty($tooltip)) {
  2645. $badgeClass .= ' classfortooltip';
  2646. $title = 'title="'.dol_htmlentities($tooltip).'"';
  2647. }
  2648. if (empty($label)) {
  2649. $label = $task->progress.' %';
  2650. }
  2651. if (!empty($label)) {
  2652. $out = '<span class="'.$badgeClass.'" '.$title.' >'.$label.'</span>';
  2653. }
  2654. return $out;
  2655. }