project.lib.php 117 KB

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