element.php 63 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656
  1. <?php
  2. /* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2020 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2010 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2012-2016 Juanjo Menent <jmenent@2byte.es>
  6. * Copyright (C) 2015-2021 Alexandre Spangaro <aspangaro@open-dsi.fr>
  7. * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
  8. * Copyright (C) 2016 Josep Lluís Amador <joseplluis@lliuretic.cat>
  9. * Copyright (C) 2021 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
  10. * Copyright (C) 2021 Noé Cendrier <noe.cendrier@altairis.fr>
  11. * Copyright (C) 2023 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
  12. *
  13. * This program is free software; you can redistribute it and/or modify
  14. * it under the terms of the GNU General Public License as published by
  15. * the Free Software Foundation; either version 3 of the License, or
  16. * (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  25. */
  26. /**
  27. * \file htdocs/projet/element.php
  28. * \ingroup projet
  29. * \brief Page of project referrers
  30. */
  31. // Load Dolibarr environment
  32. require '../main.inc.php';
  33. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  34. require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php';
  35. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
  36. require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php';
  37. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  38. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  39. if (isModEnabled('stock')) {
  40. require_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php';
  41. }
  42. if (isModEnabled("propal")) {
  43. require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
  44. }
  45. if (isModEnabled('facture')) {
  46. require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
  47. require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture-rec.class.php';
  48. }
  49. if (isModEnabled('commande')) {
  50. require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
  51. }
  52. if (isModEnabled('supplier_proposal')) {
  53. require_once DOL_DOCUMENT_ROOT.'/supplier_proposal/class/supplier_proposal.class.php';
  54. }
  55. if (isModEnabled("supplier_invoice")) {
  56. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
  57. }
  58. if (isModEnabled("supplier_order")) {
  59. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
  60. }
  61. if (isModEnabled('contrat')) {
  62. require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
  63. }
  64. if (isModEnabled('ficheinter')) {
  65. require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
  66. }
  67. if (isModEnabled("expedition")) {
  68. require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php';
  69. }
  70. if (isModEnabled('deplacement')) {
  71. require_once DOL_DOCUMENT_ROOT.'/compta/deplacement/class/deplacement.class.php';
  72. }
  73. if (isModEnabled('expensereport')) {
  74. require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php';
  75. }
  76. if (isModEnabled('agenda')) {
  77. require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
  78. }
  79. if (isModEnabled('don')) {
  80. require_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php';
  81. }
  82. if (!empty($conf->loan->enabled)) {
  83. require_once DOL_DOCUMENT_ROOT.'/loan/class/loan.class.php';
  84. require_once DOL_DOCUMENT_ROOT.'/loan/class/loanschedule.class.php';
  85. }
  86. if (isModEnabled('stock')) {
  87. require_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php';
  88. }
  89. if (isModEnabled('tax')) {
  90. require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php';
  91. }
  92. if (isModEnabled("banque")) {
  93. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/paymentvarious.class.php';
  94. }
  95. if (!empty($conf->salaries->enabled)) {
  96. require_once DOL_DOCUMENT_ROOT.'/salaries/class/salary.class.php';
  97. }
  98. if (isModEnabled('categorie')) {
  99. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  100. }
  101. if (isModEnabled('mrp')) {
  102. require_once DOL_DOCUMENT_ROOT.'/mrp/class/mo.class.php';
  103. }
  104. // Load translation files required by the page
  105. $langs->loadLangs(array('projects', 'companies', 'suppliers', 'compta'));
  106. if (isModEnabled('facture')) {
  107. $langs->load("bills");
  108. }
  109. if (isModEnabled('commande')) {
  110. $langs->load("orders");
  111. }
  112. if (isModEnabled("propal")) {
  113. $langs->load("propal");
  114. }
  115. if (isModEnabled('ficheinter')) {
  116. $langs->load("interventions");
  117. }
  118. if (isModEnabled('deplacement')) {
  119. $langs->load("trips");
  120. }
  121. if (isModEnabled('expensereport')) {
  122. $langs->load("trips");
  123. }
  124. if (isModEnabled('don')) {
  125. $langs->load("donations");
  126. }
  127. if (!empty($conf->loan->enabled)) {
  128. $langs->load("loan");
  129. }
  130. if (!empty($conf->salaries->enabled)) {
  131. $langs->load("salaries");
  132. }
  133. if (isModEnabled('mrp')) {
  134. $langs->load("mrp");
  135. }
  136. if (isModEnabled('eventorganization')) {
  137. $langs->load("eventorganization");
  138. }
  139. $id = GETPOST('id', 'int');
  140. $ref = GETPOST('ref', 'alpha');
  141. $action = GETPOST('action', 'aZ09');
  142. $datesrfc = GETPOST('datesrfc');
  143. $dateerfc = GETPOST('dateerfc');
  144. $dates = dol_mktime(0, 0, 0, GETPOST('datesmonth'), GETPOST('datesday'), GETPOST('datesyear'));
  145. $datee = dol_mktime(23, 59, 59, GETPOST('dateemonth'), GETPOST('dateeday'), GETPOST('dateeyear'));
  146. if (empty($dates) && !empty($datesrfc)) {
  147. $dates = dol_stringtotime($datesrfc);
  148. }
  149. if (empty($datee) && !empty($dateerfc)) {
  150. $datee = dol_stringtotime($dateerfc);
  151. }
  152. if (!GETPOSTISSET('datesrfc') && !GETPOSTISSET('datesday') && !empty($conf->global->PROJECT_LINKED_ELEMENT_DEFAULT_FILTER_YEAR)) {
  153. $new = dol_now();
  154. $tmp = dol_getdate($new);
  155. //$datee=$now
  156. //$dates=dol_time_plus_duree($datee, -1, 'y');
  157. $dates = dol_get_first_day($tmp['year'], 1);
  158. }
  159. if ($id == '' && $ref == '') {
  160. setEventMessage($langs->trans('ErrorBadParameters'), 'errors');
  161. header('Location: list.php');
  162. exit();
  163. }
  164. $mine = GETPOST('mode') == 'mine' ? 1 : 0;
  165. //if (! $user->rights->projet->all->lire) $mine=1; // Special for projects
  166. $object = new Project($db);
  167. include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once
  168. if (!empty($conf->global->PROJECT_ALLOW_COMMENT_ON_PROJECT) && method_exists($object, 'fetchComments') && empty($object->comments)) {
  169. $object->fetchComments();
  170. }
  171. // Security check
  172. $socid = $object->socid;
  173. //if ($user->socid > 0) $socid = $user->socid; // For external user, no check is done on company because readability is managed by public status of project and assignement.
  174. $result = restrictedArea($user, 'projet', $object->id, 'projet&project');
  175. $hookmanager->initHooks(array('projectOverview'));
  176. /*
  177. * View
  178. */
  179. $title = $langs->trans('ProjectReferers').' - '.$object->ref.' '.$object->name;
  180. if (!empty($conf->global->MAIN_HTML_TITLE) && preg_match('/projectnameonly/', $conf->global->MAIN_HTML_TITLE) && $object->name) {
  181. $title = $object->ref.' '.$object->name.' - '.$langs->trans('ProjectReferers');
  182. }
  183. $help_url = 'EN:Module_Projects|FR:Module_Projets|ES:M&oacute;dulo_Proyectos|DE:Modul_Projekte';
  184. llxHeader('', $title, $help_url);
  185. $form = new Form($db);
  186. $formproject = new FormProjets($db);
  187. $formfile = new FormFile($db);
  188. $userstatic = new User($db);
  189. // To verify role of users
  190. $userAccess = $object->restrictedProjectArea($user);
  191. $head = project_prepare_head($object);
  192. print dol_get_fiche_head($head, 'element', $langs->trans("Project"), -1, ($object->public ? 'projectpub' : 'project'));
  193. // Project card
  194. $linkback = '<a href="'.DOL_URL_ROOT.'/projet/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  195. $morehtmlref = '<div class="refidno">';
  196. // Title
  197. $morehtmlref .= $object->title;
  198. // Thirdparty
  199. if (!empty($object->thirdparty->id) && $object->thirdparty->id > 0) {
  200. $morehtmlref .= '<br>'.$object->thirdparty->getNomUrl(1, 'project');
  201. }
  202. $morehtmlref .= '</div>';
  203. // Define a complementary filter for search of next/prev ref.
  204. if (empty($user->rights->projet->all->lire)) {
  205. $objectsListId = $object->getProjectsAuthorizedForUser($user, 0, 0);
  206. $object->next_prev_filter = " te.rowid IN (".$db->sanitize(count($objectsListId) ?join(',', array_keys($objectsListId)) : '0').")";
  207. }
  208. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
  209. print '<div class="fichecenter">';
  210. print '<div class="fichehalfleft">';
  211. print '<div class="underbanner clearboth"></div>';
  212. print '<table class="border tableforfield centpercent">';
  213. // Usage
  214. if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES) || empty($conf->global->PROJECT_HIDE_TASKS) || isModEnabled('eventorganization')) {
  215. print '<tr><td class="tdtop">';
  216. print $langs->trans("Usage");
  217. print '</td>';
  218. print '<td>';
  219. if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES)) {
  220. print '<input type="checkbox" disabled name="usage_opportunity"'.(GETPOSTISSET('usage_opportunity') ? (GETPOST('usage_opportunity', 'alpha') != '' ? ' checked="checked"' : '') : ($object->usage_opportunity ? ' checked="checked"' : '')).'"> ';
  221. $htmltext = $langs->trans("ProjectFollowOpportunity");
  222. print $form->textwithpicto($langs->trans("ProjectFollowOpportunity"), $htmltext);
  223. print '<br>';
  224. }
  225. if (empty($conf->global->PROJECT_HIDE_TASKS)) {
  226. print '<input type="checkbox" disabled name="usage_task"'.(GETPOSTISSET('usage_task') ? (GETPOST('usage_task', 'alpha') != '' ? ' checked="checked"' : '') : ($object->usage_task ? ' checked="checked"' : '')).'"> ';
  227. $htmltext = $langs->trans("ProjectFollowTasks");
  228. print $form->textwithpicto($langs->trans("ProjectFollowTasks"), $htmltext);
  229. print '<br>';
  230. }
  231. if (empty($conf->global->PROJECT_HIDE_TASKS) && !empty($conf->global->PROJECT_BILL_TIME_SPENT)) {
  232. print '<input type="checkbox" disabled name="usage_bill_time"'.(GETPOSTISSET('usage_bill_time') ? (GETPOST('usage_bill_time', 'alpha') != '' ? ' checked="checked"' : '') : ($object->usage_bill_time ? ' checked="checked"' : '')).'"> ';
  233. $htmltext = $langs->trans("ProjectBillTimeDescription");
  234. print $form->textwithpicto($langs->trans("BillTime"), $htmltext);
  235. print '<br>';
  236. }
  237. if (isModEnabled('eventorganization')) {
  238. print '<input type="checkbox" disabled name="usage_organize_event"'.(GETPOSTISSET('usage_organize_event') ? (GETPOST('usage_organize_event', 'alpha') != '' ? ' checked="checked"' : '') : ($object->usage_organize_event ? ' checked="checked"' : '')).'"> ';
  239. $htmltext = $langs->trans("EventOrganizationDescriptionLong");
  240. print $form->textwithpicto($langs->trans("ManageOrganizeEvent"), $htmltext);
  241. }
  242. print '</td></tr>';
  243. }
  244. // Visibility
  245. print '<tr><td class="titlefield">'.$langs->trans("Visibility").'</td><td>';
  246. if ($object->public) {
  247. print img_picto($langs->trans('SharedProject'), 'world', 'class="paddingrightonly"');
  248. print $langs->trans('SharedProject');
  249. } else {
  250. print img_picto($langs->trans('PrivateProject'), 'private', 'class="paddingrightonly"');
  251. print $langs->trans('PrivateProject');
  252. }
  253. print '</td></tr>';
  254. if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES)) {
  255. // Opportunity status
  256. print '<tr><td>'.$langs->trans("OpportunityStatus").'</td><td>';
  257. $code = dol_getIdFromCode($db, $object->opp_status, 'c_lead_status', 'rowid', 'code');
  258. if ($code) {
  259. print $langs->trans("OppStatus".$code);
  260. }
  261. print '</td></tr>';
  262. // Opportunity percent
  263. print '<tr><td>'.$langs->trans("OpportunityProbability").'</td><td>';
  264. if (!is_null($object->opp_percent) && strcmp($object->opp_percent, '')) {
  265. print price($object->opp_percent, '', $langs, 1, 0).' %';
  266. }
  267. print '</td></tr>';
  268. // Opportunity Amount
  269. print '<tr><td>'.$langs->trans("OpportunityAmount").'</td><td>';
  270. if (!is_null($object->opp_amount) && strcmp($object->opp_amount, '')) {
  271. print '<span class="amount">'.price($object->opp_amount, '', $langs, 1, 0, 0, $conf->currency).'</span>';
  272. if (strcmp($object->opp_percent, '')) {
  273. print ' &nbsp; &nbsp; &nbsp; <span title="'.dol_escape_htmltag($langs->trans('OpportunityWeightedAmount')).'"><span class="opacitymedium">'.$langs->trans("Weighted").'</span>: <span class="amount">'.price($object->opp_amount * $object->opp_percent / 100, 0, $langs, 1, 0, -1, $conf->currency).'</span></span>';
  274. }
  275. }
  276. print '</td></tr>';
  277. }
  278. // Budget
  279. print '<tr><td>'.$langs->trans("Budget").'</td><td>';
  280. if (!is_null($object->budget_amount) && strcmp($object->budget_amount, '')) {
  281. print '<span class="amount">'.price($object->budget_amount, '', $langs, 1, 0, 0, $conf->currency).'</span>';
  282. }
  283. print '</td></tr>';
  284. // Date start - end project
  285. print '<tr><td>'.$langs->trans("Dates").'</td><td>';
  286. $start = dol_print_date($object->date_start, 'day');
  287. print ($start ? $start : '?');
  288. $end = dol_print_date($object->date_end, 'day');
  289. print ' - ';
  290. print ($end ? $end : '?');
  291. if ($object->hasDelay()) {
  292. print img_warning("Late");
  293. }
  294. print '</td></tr>';
  295. // Other attributes
  296. $cols = 2;
  297. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
  298. print '</table>';
  299. print '</div>';
  300. print '<div class="fichehalfright">';
  301. print '<div class="underbanner clearboth"></div>';
  302. print '<table class="border tableforfield centpercent">';
  303. // Description
  304. print '<td class="titlefield tdtop">'.$langs->trans("Description").'</td><td>';
  305. print dol_htmlentitiesbr($object->description);
  306. print '</td></tr>';
  307. // Categories
  308. if (isModEnabled('categorie')) {
  309. print '<tr><td class="valignmiddle">'.$langs->trans("Categories").'</td><td>';
  310. print $form->showCategories($object->id, Categorie::TYPE_PROJECT, 1);
  311. print "</td></tr>";
  312. }
  313. print '</table>';
  314. print '</div>';
  315. print '</div>';
  316. print '<div class="clearboth"></div>';
  317. print dol_get_fiche_end();
  318. print '<br>';
  319. /*
  320. * Referers types
  321. */
  322. $listofreferent = array(
  323. 'entrepot'=>array(
  324. 'name'=>"Warehouse",
  325. 'title'=>"ListWarehouseAssociatedProject",
  326. 'class'=>'Entrepot',
  327. 'table'=>'entrepot',
  328. 'datefieldname'=>'date_entrepot',
  329. 'urlnew'=>DOL_URL_ROOT.'/product/stock/card.php?action=create&projectid='.$id.'&backtopage='.urlencode($_SERVER['PHP_SELF'].'?id='.$id),
  330. 'lang'=>'entrepot',
  331. 'buttonnew'=>'AddWarehouse',
  332. 'project_field'=>'fk_project',
  333. 'testnew'=>$user->hasRight('stock', 'creer'),
  334. 'test'=>!empty($conf->stock->enabled) && $user->hasRight('stock', 'lire') && !empty($conf->global->WAREHOUSE_ASK_WAREHOUSE_DURING_PROJECT)),
  335. 'propal'=>array(
  336. 'name'=>"Proposals",
  337. 'title'=>"ListProposalsAssociatedProject",
  338. 'class'=>'Propal',
  339. 'table'=>'propal',
  340. 'datefieldname'=>'datep',
  341. 'urlnew'=>DOL_URL_ROOT.'/comm/propal/card.php?action=create&origin=project&originid='.$id.'&socid='.$socid.'&backtopage='.urlencode($_SERVER['PHP_SELF'].'?id='.$id),
  342. 'lang'=>'propal',
  343. 'buttonnew'=>'AddProp',
  344. 'testnew'=>$user->hasRight('propal', 'creer'),
  345. 'test'=>!empty($conf->propal->enabled) && $user->hasRight('propal', 'lire')),
  346. 'order'=>array(
  347. 'name'=>"CustomersOrders",
  348. 'title'=>"ListOrdersAssociatedProject",
  349. 'class'=>'Commande',
  350. 'table'=>'commande',
  351. 'datefieldname'=>'date_commande',
  352. 'urlnew'=>DOL_URL_ROOT.'/commande/card.php?action=create&projectid='.$id.'&socid='.$socid.'&backtopage='.urlencode($_SERVER['PHP_SELF'].'?id='.$id),
  353. 'lang'=>'orders',
  354. 'buttonnew'=>'CreateOrder',
  355. 'testnew'=>$user->hasRight('commande', 'creer'),
  356. 'test'=>!empty($conf->commande->enabled) && $user->hasRight('commande', 'lire')),
  357. 'invoice'=>array(
  358. 'name'=>"CustomersInvoices",
  359. 'title'=>"ListInvoicesAssociatedProject",
  360. 'class'=>'Facture',
  361. 'margin'=>'add',
  362. 'table'=>'facture',
  363. 'datefieldname'=>'datef',
  364. 'urlnew'=>DOL_URL_ROOT.'/compta/facture/card.php?action=create&projectid='.$id.'&socid='.$socid.'&backtopage='.urlencode($_SERVER['PHP_SELF'].'?id='.$id),
  365. 'lang'=>'bills',
  366. 'buttonnew'=>'CreateBill',
  367. 'testnew'=>$user->hasRight('facture', 'creer'),
  368. 'test'=>isModEnabled('facture') && $user->hasRight('facture', 'lire')),
  369. 'invoice_predefined'=>array(
  370. 'name'=>"PredefinedInvoices",
  371. 'title'=>"ListPredefinedInvoicesAssociatedProject",
  372. 'class'=>'FactureRec',
  373. 'table'=>'facture_rec',
  374. 'datefieldname'=>'datec',
  375. 'urlnew'=>DOL_URL_ROOT.'/compta/facture/card.php?action=create&projectid='.$id.'&socid='.$socid.'&backtopage='.urlencode($_SERVER['PHP_SELF'].'?id='.$id),
  376. 'lang'=>'bills',
  377. 'buttonnew'=>'CreateBill',
  378. 'testnew'=>$user->hasRight('facture', 'creer'),
  379. 'test'=>isModEnabled('facture') && $user->hasRight('facture', 'lire')),
  380. 'proposal_supplier'=>array(
  381. 'name'=>"SupplierProposals",
  382. 'title'=>"ListSupplierProposalsAssociatedProject",
  383. 'class'=>'SupplierProposal',
  384. 'table'=>'supplier_proposal',
  385. 'datefieldname'=>'date_valid',
  386. 'urlnew'=>DOL_URL_ROOT.'/supplier_proposal/card.php?action=create&projectid='.$id.'&backtopage='.urlencode($_SERVER['PHP_SELF'].'?id='.$id), // No socid parameter here, the socid is often the customer and we create a supplier object
  387. 'lang'=>'supplier_proposal',
  388. 'buttonnew'=>'AddSupplierProposal',
  389. 'testnew'=>$user->hasRight('supplier_proposal', 'creer'),
  390. 'test'=>!empty($conf->supplier_proposal->enabled) && $user->hasRight('supplier_proposal', 'lire')),
  391. 'order_supplier'=>array(
  392. 'name'=>"SuppliersOrders",
  393. 'title'=>"ListSupplierOrdersAssociatedProject",
  394. 'class'=>'CommandeFournisseur',
  395. 'table'=>'commande_fournisseur',
  396. 'datefieldname'=>'date_commande',
  397. 'urlnew'=>DOL_URL_ROOT.'/fourn/commande/card.php?action=create&projectid='.$id.'&backtopage='.urlencode($_SERVER['PHP_SELF'].'?id='.$id), // No socid parameter here, the socid is often the customer and we create a supplier object
  398. 'lang'=>'suppliers',
  399. 'buttonnew'=>'AddSupplierOrder',
  400. 'testnew'=>$user->hasRight('fournisseur', 'commande', 'creer') || $user->hasRight('supplier_order', 'creer'),
  401. 'test'=>!empty($conf->supplier_order->enabled) && $user->hasRight('fournisseur', 'commande', 'lire') || $user->hasRight('supplier_order', 'lire')),
  402. 'invoice_supplier'=>array(
  403. 'name'=>"BillsSuppliers",
  404. 'title'=>"ListSupplierInvoicesAssociatedProject",
  405. 'class'=>'FactureFournisseur',
  406. 'margin'=>'minus',
  407. 'table'=>'facture_fourn',
  408. 'datefieldname'=>'datef',
  409. 'urlnew'=>DOL_URL_ROOT.'/fourn/facture/card.php?action=create&projectid='.$id.'&backtopage='.urlencode($_SERVER['PHP_SELF'].'?id='.$id), // No socid parameter here, the socid is often the customer and we create a supplier object
  410. 'lang'=>'suppliers',
  411. 'buttonnew'=>'AddSupplierInvoice',
  412. 'testnew'=>$user->hasRight('fournisseur', 'facture', 'creer') || $user->hasRight('supplier_invoice', 'creer'),
  413. 'test'=>!empty($conf->supplier_invoice->enabled) && $user->hasRight('fournisseur', 'facture', 'lire') || $user->hasRight('supplier_invoice', 'lire')),
  414. 'contract'=>array(
  415. 'name'=>"Contracts",
  416. 'title'=>"ListContractAssociatedProject",
  417. 'class'=>'Contrat',
  418. 'table'=>'contrat',
  419. 'datefieldname'=>'date_contrat',
  420. 'urlnew'=>DOL_URL_ROOT.'/contrat/card.php?action=create&projectid='.$id.'&socid='.$socid.'&backtopage='.urlencode($_SERVER['PHP_SELF'].'?id='.$id),
  421. 'lang'=>'contracts',
  422. 'buttonnew'=>'AddContract',
  423. 'testnew'=>$user->hasRight('contrat', 'creer'),
  424. 'test'=>!empty($conf->contrat->enabled) && $user->hasRight('contrat', 'lire')),
  425. 'intervention'=>array(
  426. 'name'=>"Interventions",
  427. 'title'=>"ListFichinterAssociatedProject",
  428. 'class'=>'Fichinter',
  429. 'table'=>'fichinter',
  430. 'datefieldname'=>'date_valid',
  431. 'disableamount'=>0,
  432. 'margin'=>'',
  433. 'urlnew'=>DOL_URL_ROOT.'/fichinter/card.php?action=create&origin=project&originid='.$id.'&socid='.$socid.'&backtopage='.urlencode($_SERVER['PHP_SELF'].'?id='.$id),
  434. 'lang'=>'interventions',
  435. 'buttonnew'=>'AddIntervention',
  436. 'testnew'=>$user->hasRight('ficheinter', 'creer'),
  437. 'test'=>!empty($conf->ficheinter->enabled) && $user->hasRight('ficheinter', 'lire')),
  438. 'shipping'=>array(
  439. 'name'=>"Shippings",
  440. 'title'=>"ListShippingAssociatedProject",
  441. 'class'=>'Expedition',
  442. 'table'=>'expedition',
  443. 'datefieldname'=>'date_valid',
  444. 'urlnew'=>DOL_URL_ROOT.'/expedition/card.php?action=create&origin=project&originid='.$id.'&socid='.$socid.'&backtopage='.urlencode($_SERVER['PHP_SELF'].'?id='.$id),
  445. 'lang'=>'sendings',
  446. 'buttonnew'=>'CreateShipment',
  447. 'testnew'=>0,
  448. 'test'=>isModEnabled('expedition') && $user->hasRight('expedition', 'lire')),
  449. 'mrp'=>array(
  450. 'name'=>"MO",
  451. 'title'=>"ListMOAssociatedProject",
  452. 'class'=>'Mo',
  453. 'table'=>'mrp_mo',
  454. 'datefieldname'=>'date_valid',
  455. 'urlnew'=>DOL_URL_ROOT.'/mrp/mo_card.php?action=create&origin=project&originid='.$id.'&socid='.$socid.'&backtopage='.urlencode($_SERVER['PHP_SELF'].'?id='.$id),
  456. 'lang'=>'mrp',
  457. 'buttonnew'=>'CreateMO',
  458. 'testnew'=>$user->hasRight('mrp', 'write'),
  459. 'project_field'=>'fk_project',
  460. 'nototal'=>1,
  461. 'test'=>!empty($conf->mrp->enabled) && $user->hasRight('mrp', 'read')),
  462. 'trip'=>array(
  463. 'name'=>"TripsAndExpenses",
  464. 'title'=>"ListExpenseReportsAssociatedProject",
  465. 'class'=>'Deplacement',
  466. 'table'=>'deplacement',
  467. 'datefieldname'=>'dated',
  468. 'margin'=>'minus',
  469. 'disableamount'=>1,
  470. 'urlnew'=>DOL_URL_ROOT.'/deplacement/card.php?action=create&projectid='.$id.'&socid='.$socid.'&backtopage='.urlencode($_SERVER['PHP_SELF'].'?id='.$id),
  471. 'lang'=>'trips',
  472. 'buttonnew'=>'AddTrip',
  473. 'testnew'=>$user->hasRight('deplacement', 'creer'),
  474. 'test'=>!empty($conf->deplacement->enabled) && $user->hasRight('deplacement', 'lire')),
  475. 'expensereport'=>array(
  476. 'name'=>"ExpenseReports",
  477. 'title'=>"ListExpenseReportsAssociatedProject",
  478. 'class'=>'ExpenseReportLine',
  479. 'table'=>'expensereport_det',
  480. 'datefieldname'=>'date',
  481. 'margin'=>'minus',
  482. 'disableamount'=>0,
  483. 'urlnew'=>DOL_URL_ROOT.'/expensereport/card.php?action=create&projectid='.$id.'&socid='.$socid.'&backtopage='.urlencode($_SERVER['PHP_SELF'].'?id='.$id),
  484. 'lang'=>'trips',
  485. 'buttonnew'=>'AddTrip',
  486. 'testnew'=>$user->hasRight('expensereport', 'creer'),
  487. 'test'=>!empty($conf->expensereport->enabled) && $user->hasRight('expensereport', 'lire')),
  488. 'donation'=>array(
  489. 'name'=>"Donation",
  490. 'title'=>"ListDonationsAssociatedProject",
  491. 'class'=>'Don',
  492. 'margin'=>'add',
  493. 'table'=>'don',
  494. 'datefieldname'=>'datedon',
  495. 'disableamount'=>0,
  496. 'urlnew'=>DOL_URL_ROOT.'/don/card.php?action=create&projectid='.$id.'&socid='.$socid.'&backtopage='.urlencode($_SERVER['PHP_SELF'].'?id='.$id),
  497. 'lang'=>'donations',
  498. 'buttonnew'=>'AddDonation',
  499. 'testnew'=>$user->hasRight('don', 'creer'),
  500. 'test'=>!empty($conf->don->enabled) && $user->hasRight('don', 'lire')),
  501. 'loan'=>array(
  502. 'name'=>"Loan",
  503. 'title'=>"ListLoanAssociatedProject",
  504. 'class'=>'Loan',
  505. 'margin'=>'add',
  506. 'table'=>'loan',
  507. 'datefieldname'=>'datestart',
  508. 'disableamount'=>0,
  509. 'urlnew'=>DOL_URL_ROOT.'/loan/card.php?action=create&projectid='.$id.'&socid='.$socid.'&backtopage='.urlencode($_SERVER['PHP_SELF'].'?id='.$id),
  510. 'lang'=>'loan',
  511. 'buttonnew'=>'AddLoan',
  512. 'testnew'=>$user->hasRight('loan', 'write'),
  513. 'test'=>!empty($conf->loan->enabled) && $user->hasRight('loan', 'read')),
  514. 'chargesociales'=>array(
  515. 'name'=>"SocialContribution",
  516. 'title'=>"ListSocialContributionAssociatedProject",
  517. 'class'=>'ChargeSociales',
  518. 'margin'=>'minus',
  519. 'table'=>'chargesociales',
  520. 'datefieldname'=>'date_ech',
  521. 'disableamount'=>0,
  522. 'urlnew'=>DOL_URL_ROOT.'/compta/sociales/card.php?action=create&projectid='.$id.'&backtopage='.urlencode($_SERVER['PHP_SELF'].'?id='.$id),
  523. 'lang'=>'compta',
  524. 'buttonnew'=>'AddSocialContribution',
  525. 'testnew'=>$user->hasRight('tax', 'charges', 'lire'),
  526. 'test'=>!empty($conf->tax->enabled) && $user->hasRight('tax', 'charges', 'lire')),
  527. 'project_task'=>array(
  528. 'name'=>"TaskTimeSpent",
  529. 'title'=>"ListTaskTimeUserProject",
  530. 'class'=>'Task',
  531. 'margin'=>'minus',
  532. 'table'=>'projet_task',
  533. 'datefieldname'=>'element_date',
  534. 'disableamount'=>0,
  535. 'urlnew'=>DOL_URL_ROOT.'/projet/tasks/time.php?withproject=1&action=createtime&projectid='.$id.'&backtopage='.urlencode($_SERVER['PHP_SELF'].'?id='.$id),
  536. 'buttonnew'=>'AddTimeSpent',
  537. 'testnew'=>$user->hasRight('project', 'creer'),
  538. 'test'=>!empty($conf->project->enabled) && $user->hasRight('projet', 'lire') && empty($conf->global->PROJECT_HIDE_TASKS)),
  539. 'stock_mouvement'=>array(
  540. 'name'=>"MouvementStockAssociated",
  541. 'title'=>"ListMouvementStockProject",
  542. 'class'=>'MouvementStock',
  543. 'table'=>'stock_mouvement',
  544. 'datefieldname'=>'datem',
  545. 'margin'=>'minus',
  546. 'disableamount'=>0,
  547. 'test'=>!empty($conf->stock->enabled) && $user->hasRight('stock', 'mouvement', 'lire') && !empty($conf->global->STOCK_MOVEMENT_INTO_PROJECT_OVERVIEW)),
  548. 'salaries'=>array(
  549. 'name'=>"Salaries",
  550. 'title'=>"ListSalariesAssociatedProject",
  551. 'class'=>'Salary',
  552. 'table'=>'salary',
  553. 'datefieldname'=>'datesp',
  554. 'margin'=>'minus',
  555. 'disableamount'=>0,
  556. 'urlnew'=>DOL_URL_ROOT.'/salaries/card.php?action=create&projectid='.$id.'&backtopage='.urlencode($_SERVER['PHP_SELF'].'?id='.$id),
  557. 'lang'=>'salaries',
  558. 'buttonnew'=>'AddSalary',
  559. 'testnew'=>$user->hasRight('salaries', 'write'),
  560. 'test'=>!empty($conf->salaries->enabled) && $user->hasRight('salaries', 'read')),
  561. 'variouspayment'=>array(
  562. 'name'=>"VariousPayments",
  563. 'title'=>"ListVariousPaymentsAssociatedProject",
  564. 'class'=>'PaymentVarious',
  565. 'table'=>'payment_various',
  566. 'datefieldname'=>'datev',
  567. 'margin'=>'minus',
  568. 'disableamount'=>0,
  569. 'urlnew'=>DOL_URL_ROOT.'/compta/bank/various_payment/card.php?action=create&projectid='.$id.'&backtopage='.urlencode($_SERVER['PHP_SELF'].'?id='.$id),
  570. 'lang'=>'banks',
  571. 'buttonnew'=>'AddVariousPayment',
  572. 'testnew'=>$user->hasRight('banque', 'modifier'),
  573. 'test'=>isModEnabled("banque") && $user->hasRight('banque', 'lire') && !empty($conf->global->BANK_USE_OLD_VARIOUS_PAYMENT)),
  574. /* No need for this, available on dedicated tab "Agenda/Events"
  575. 'agenda'=>array(
  576. 'name'=>"Agenda",
  577. 'title'=>"ListActionsAssociatedProject",
  578. 'class'=>'ActionComm',
  579. 'table'=>'actioncomm',
  580. 'datefieldname'=>'datep',
  581. 'disableamount'=>1,
  582. 'urlnew'=>DOL_URL_ROOT.'/comm/action/card.php?action=create&projectid='.$id.'&socid='.$socid.'&backtopage='.urlencode($_SERVER['PHP_SELF'].'?id='.$id),
  583. 'lang'=>'agenda',
  584. 'buttonnew'=>'AddEvent',
  585. 'testnew'=>$user->rights->agenda->myactions->create,
  586. 'test'=> isModEnabled('agenda') && $user->hasRight('agenda', 'myactions', 'read')),
  587. */
  588. );
  589. // Change rules for profit/benefit calculation
  590. if (!empty($conf->global->PROJECT_ELEMENTS_FOR_PLUS_MARGIN)) {
  591. foreach ($listofreferent as $key => $element) {
  592. if ($listofreferent[$key]['margin'] == 'add') {
  593. unset($listofreferent[$key]['margin']);
  594. }
  595. }
  596. $newelementforplusmargin = explode(',', $conf->global->PROJECT_ELEMENTS_FOR_PLUS_MARGIN);
  597. foreach ($newelementforplusmargin as $value) {
  598. $listofreferent[trim($value)]['margin'] = 'add';
  599. }
  600. }
  601. if (!empty($conf->global->PROJECT_ELEMENTS_FOR_MINUS_MARGIN)) {
  602. foreach ($listofreferent as $key => $element) {
  603. if ($listofreferent[$key]['margin'] == 'minus') {
  604. unset($listofreferent[$key]['margin']);
  605. }
  606. }
  607. $newelementforminusmargin = explode(',', $conf->global->PROJECT_ELEMENTS_FOR_MINUS_MARGIN);
  608. foreach ($newelementforminusmargin as $value) {
  609. $listofreferent[trim($value)]['margin'] = 'minus';
  610. }
  611. }
  612. $parameters = array('listofreferent'=>$listofreferent);
  613. $resHook = $hookmanager->executeHooks('completeListOfReferent', $parameters, $object, $action);
  614. if (!empty($hookmanager->resArray)) {
  615. $listofreferent = array_merge($listofreferent, $hookmanager->resArray);
  616. }
  617. if ($action == "addelement") {
  618. $tablename = GETPOST("tablename");
  619. $elementselectid = GETPOST("elementselect");
  620. $result = $object->update_element($tablename, $elementselectid);
  621. if ($result < 0) {
  622. setEventMessages($object->error, $object->errors, 'errors');
  623. }
  624. } elseif ($action == "unlink") {
  625. $tablename = GETPOST("tablename", "aZ09");
  626. $projectField = GETPOSTISSET('projectfield') ? GETPOST('projectfield', 'aZ09') : 'fk_projet';
  627. $elementselectid = GETPOST("elementselect", "int");
  628. $result = $object->remove_element($tablename, $elementselectid, $projectField);
  629. if ($result < 0) {
  630. setEventMessages($object->error, $object->errors, 'errors');
  631. }
  632. }
  633. $elementuser = new User($db);
  634. $showdatefilter = 0;
  635. // Show the filter on date on top of element list
  636. if (!$showdatefilter) {
  637. print '<div class="center centpercent">';
  638. print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="POST">';
  639. print '<input type="hidden" name="token" value="'.newToken().'">';
  640. print '<input type="hidden" name="tablename" value="'.(empty($tablename) ? '' : $tablename).'">';
  641. print '<input type="hidden" name="action" value="view">';
  642. print '<div class="inline-block">';
  643. print $form->selectDate($dates, 'dates', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("From"));
  644. print '</div>';
  645. print '<div class="inline-block">';
  646. print $form->selectDate($datee, 'datee', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("to"));
  647. print '</div>';
  648. print '<div class="inline-block">';
  649. print '<input type="submit" name="refresh" value="'.$langs->trans("Refresh").'" class="button small">';
  650. print '</div>';
  651. print '</form>';
  652. print '</div>';
  653. $showdatefilter++;
  654. }
  655. // Show balance for whole project
  656. $langs->loadLangs(array("suppliers", "bills", "orders", "proposals", "margins"));
  657. if (isModEnabled('stock')) {
  658. $langs->load('stocks');
  659. }
  660. print load_fiche_titre($langs->trans("Profit"), '', 'title_accountancy');
  661. print '<table class="noborder centpercent">';
  662. print '<tr class="liste_titre">';
  663. print '<td class="left" width="200">';
  664. $tooltiponprofit = $langs->trans("ProfitIsCalculatedWith")."<br>\n";
  665. $tooltiponprofitplus = $tooltiponprofitminus = '';
  666. foreach ($listofreferent as $key => $value) {
  667. if (!empty($value['lang'])) {
  668. $langs->load($value['lang']);
  669. }
  670. $name = $langs->trans($value['name']);
  671. $qualified = $value['test'];
  672. $margin = empty($value['margin']) ? 0 : $value['margin'];
  673. if ($qualified && isset($margin)) { // If this element must be included into profit calculation ($margin is 'minus' or 'add')
  674. if ($margin == 'add') {
  675. $tooltiponprofitplus .= ' &gt; '.$name." (+)<br>\n";
  676. }
  677. if ($margin == 'minus') {
  678. $tooltiponprofitminus .= ' &gt; '.$name." (-)<br>\n";
  679. }
  680. }
  681. }
  682. $tooltiponprofit .= $tooltiponprofitplus;
  683. $tooltiponprofit .= $tooltiponprofitminus;
  684. print $form->textwithpicto($langs->trans("Element"), $tooltiponprofit);
  685. print '</td>';
  686. print '<td class="right" width="100">'.$langs->trans("Number").'</td>';
  687. print '<td class="right" width="100">'.$langs->trans("AmountHT").'</td>';
  688. print '<td class="right" width="100">'.$langs->trans("AmountTTC").'</td>';
  689. print '</tr>';
  690. $total_revenue_ht = 0;
  691. $balance_ht = 0;
  692. $balance_ttc = 0;
  693. // Loop on each element type (proposal, sale order, invoices, ...)
  694. foreach ($listofreferent as $key => $value) {
  695. $parameters = array(
  696. 'total_revenue_ht' =>& $total_revenue_ht,
  697. 'balance_ht' =>& $balance_ht,
  698. 'balance_ttc' =>& $balance_ttc,
  699. 'key' => $key,
  700. 'value' =>& $value,
  701. 'dates' => $dates,
  702. 'datee' => $datee
  703. );
  704. $reshook = $hookmanager->executeHooks('printOverviewProfit', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  705. if ($reshook < 0) {
  706. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  707. } elseif ($reshook > 0) {
  708. print $hookmanager->resPrint;
  709. continue;
  710. }
  711. $name = $langs->trans($value['name']);
  712. $title = $value['title'];
  713. $classname = $value['class'];
  714. $tablename = $value['table'];
  715. $datefieldname = $value['datefieldname'];
  716. $qualified = $value['test'];
  717. $margin = empty($value['margin']) ? 0 : $value['margin'];
  718. $project_field = empty($value['project_field']) ? '' : $value['project_field'];
  719. if ($qualified && isset($margin)) { // If this element must be included into profit calculation ($margin is 'minus' or 'add')
  720. $element = new $classname($db);
  721. $elementarray = $object->get_element_list($key, $tablename, $datefieldname, $dates, $datee, !empty($project_field) ? $project_field : 'fk_projet');
  722. if (is_array($elementarray) && count($elementarray) > 0) {
  723. $total_ht = 0;
  724. $total_ttc = 0;
  725. // Loop on each object for the current element type
  726. $num = count($elementarray);
  727. for ($i = 0; $i < $num; $i++) {
  728. $tmp = explode('_', $elementarray[$i]);
  729. $idofelement = $tmp[0];
  730. $idofelementuser = !empty($tmp[1]) ? $tmp[1] : "";
  731. $element->fetch($idofelement);
  732. if ($idofelementuser) {
  733. $elementuser->fetch($idofelementuser);
  734. }
  735. // Define if record must be used for total or not
  736. $qualifiedfortotal = true;
  737. if ($key == 'invoice') {
  738. if (!empty($element->close_code) && $element->close_code == 'replaced') {
  739. $qualifiedfortotal = false; // Replacement invoice, do not include into total
  740. }
  741. if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS) && $element->type == Facture::TYPE_DEPOSIT) {
  742. $qualifiedfortotal = false; // If hidden option to use deposits as payment (deprecated, not recommended to use this), deposits are not included
  743. }
  744. }
  745. if ($key == 'propal') {
  746. if ($element->status != Propal::STATUS_SIGNED && $element->status != Propal::STATUS_BILLED) {
  747. $qualifiedfortotal = false; // Only signed proposal must not be included in total
  748. }
  749. }
  750. if ($tablename != 'expensereport_det' && method_exists($element, 'fetch_thirdparty')) {
  751. $element->fetch_thirdparty();
  752. }
  753. // Define $total_ht_by_line
  754. if ($tablename == 'don' || $tablename == 'chargesociales' || $tablename == 'payment_various' || $tablename == 'salary') {
  755. $total_ht_by_line = $element->amount;
  756. } elseif ($tablename == 'fichinter') {
  757. $total_ht_by_line = $element->getAmount();
  758. } elseif ($tablename == 'stock_mouvement') {
  759. $total_ht_by_line = $element->price * abs($element->qty);
  760. } elseif ($tablename == 'projet_task') {
  761. if ($idofelementuser) {
  762. $tmp = $element->getSumOfAmount($elementuser, $dates, $datee);
  763. $total_ht_by_line = price2num($tmp['amount'], 'MT');
  764. } else {
  765. $tmp = $element->getSumOfAmount('', $dates, $datee);
  766. $total_ht_by_line = price2num($tmp['amount'], 'MT');
  767. }
  768. } elseif ($key == 'loan') {
  769. if ((empty($dates) && empty($datee)) || (intval($dates) <= $element->datestart && intval($datee) >= $element->dateend)) {
  770. // Get total loan
  771. $total_ht_by_line = -$element->capital;
  772. } else {
  773. // Get loan schedule according to date filter
  774. $total_ht_by_line = 0;
  775. $loanScheduleStatic = new LoanSchedule($element->db);
  776. $loanScheduleStatic->fetchAll($element->id);
  777. if (!empty($loanScheduleStatic->lines)) {
  778. foreach ($loanScheduleStatic->lines as $loanSchedule) {
  779. /**
  780. * @var $loanSchedule LoanSchedule
  781. */
  782. if (($loanSchedule->datep >= $dates && $loanSchedule->datep <= $datee) // dates filter is defined
  783. || !empty($dates) && empty($datee) && $loanSchedule->datep >= $dates && $loanSchedule->datep <= dol_now()
  784. || empty($dates) && !empty($datee) && $loanSchedule->datep <= $datee
  785. ) {
  786. $total_ht_by_line -= $loanSchedule->amount_capital;
  787. }
  788. }
  789. }
  790. }
  791. } else {
  792. $total_ht_by_line = $element->total_ht;
  793. }
  794. // Define $total_ttc_by_line
  795. if ($tablename == 'don' || $tablename == 'chargesociales' || $tablename == 'payment_various' || $tablename == 'salary') {
  796. $total_ttc_by_line = $element->amount;
  797. } elseif ($tablename == 'fichinter') {
  798. $total_ttc_by_line = $element->getAmount();
  799. } elseif ($tablename == 'stock_mouvement') {
  800. $total_ttc_by_line = $element->price * abs($element->qty);
  801. } elseif ($tablename == 'projet_task') {
  802. $defaultvat = get_default_tva($mysoc, $mysoc);
  803. $total_ttc_by_line = price2num($total_ht_by_line * (1 + ($defaultvat / 100)), 'MT');
  804. } elseif ($key == 'loan') {
  805. $total_ttc_by_line = $total_ht_by_line; // For loan there is actually no taxe managed in Dolibarr
  806. } else {
  807. $total_ttc_by_line = $element->total_ttc;
  808. }
  809. // Change sign of $total_ht_by_line and $total_ttc_by_line for some cases
  810. if ($tablename == 'payment_various') {
  811. if ($element->sens == 1) {
  812. $total_ht_by_line = -$total_ht_by_line;
  813. $total_ttc_by_line = -$total_ttc_by_line;
  814. }
  815. }
  816. // Add total if we have to
  817. if ($qualifiedfortotal) {
  818. $total_ht = $total_ht + $total_ht_by_line;
  819. $total_ttc = $total_ttc + $total_ttc_by_line;
  820. }
  821. }
  822. // Each element with at least one line is output
  823. // Calculate margin
  824. if ($margin) {
  825. if ($margin === 'add') {
  826. $total_revenue_ht += $total_ht;
  827. }
  828. if ($margin === "minus") { // Revert sign
  829. $total_ht = -$total_ht;
  830. $total_ttc = -$total_ttc;
  831. }
  832. $balance_ht += $total_ht;
  833. $balance_ttc += $total_ttc;
  834. }
  835. print '<tr class="oddeven">';
  836. // Module
  837. print '<td class="left">'.$name.'</td>';
  838. // Nb
  839. print '<td class="right">'.$i.'</td>';
  840. // Amount HT
  841. print '<td class="right">';
  842. if ($key == 'intervention' && !$margin) {
  843. print '<span class="opacitymedium">'.$form->textwithpicto($langs->trans("NA"), $langs->trans("AmountOfInteventionNotIncludedByDefault")).'</span>';
  844. } else {
  845. if ($key == 'propal') {
  846. print '<span class="opacitymedium">'.$form->textwithpicto('', $langs->trans("SignedOnly")).'</span>';
  847. }
  848. print price($total_ht);
  849. }
  850. print '</td>';
  851. // Amount TTC
  852. print '<td class="right">';
  853. if ($key == 'intervention' && !$margin) {
  854. print '<span class="opacitymedium">'.$form->textwithpicto($langs->trans("NA"), $langs->trans("AmountOfInteventionNotIncludedByDefault")).'</span>';
  855. } else {
  856. if ($key == 'propal') {
  857. print '<span class="opacitymedium">'.$form->textwithpicto('', $langs->trans("SignedOnly")).'</span>';
  858. }
  859. print price($total_ttc);
  860. }
  861. print '</td>';
  862. print '</tr>';
  863. }
  864. }
  865. }
  866. // and the final balance
  867. print '<tr class="liste_total">';
  868. print '<td class="right" colspan="2">'.$langs->trans("Profit").'</td>';
  869. print '<td class="right">'.price(price2num($balance_ht, 'MT')).'</td>';
  870. print '<td class="right">'.price(price2num($balance_ttc, 'MT')).'</td>';
  871. print '</tr>';
  872. // and the margin (profit / revenues)
  873. if ($total_revenue_ht) {
  874. print '<tr class="liste_total">';
  875. print '<td class="right" colspan="2">'.$langs->trans("Margin").'</td>';
  876. print '<td class="right">'.round(100 * $balance_ht / $total_revenue_ht, 1).'%</td>';
  877. print '<td class="right"></td>';
  878. print '</tr>';
  879. }
  880. print "</table>";
  881. print '<br><br>';
  882. print '<br>';
  883. // Detail
  884. foreach ($listofreferent as $key => $value) {
  885. $parameters = array(
  886. 'key' => $key,
  887. 'value' =>& $value,
  888. 'dates' => $dates,
  889. 'datee' => $datee
  890. );
  891. $reshook = $hookmanager->executeHooks('printOverviewDetail', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  892. if ($reshook < 0) {
  893. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  894. } elseif ($reshook > 0) {
  895. print $hookmanager->resPrint;
  896. continue;
  897. }
  898. $title = $value['title'];
  899. $classname = $value['class'];
  900. $tablename = $value['table'];
  901. $datefieldname = $value['datefieldname'];
  902. $qualified = $value['test'];
  903. $urlnew = empty($value['urlnew']) ? '' : $value['urlnew'];
  904. $buttonnew = empty($value['buttonnew']) ? '' : $value['buttonnew'];
  905. $testnew = empty($value['testnew']) ? '' : $value['testnew'];
  906. $project_field = empty($value['project_field']) ? '' : $value['project_field'];
  907. $nototal = empty($value['nototal']) ? 0 : 1;
  908. $exclude_select_element = array('payment_various');
  909. if (!empty($value['exclude_select_element'])) {
  910. $exclude_select_element[] = $value['exclude_select_element'];
  911. }
  912. if ($qualified) {
  913. // If we want the project task array to have details of users
  914. //if ($key == 'project_task') $key = 'project_task_time';
  915. $element = new $classname($db);
  916. $addform = '';
  917. $idtofilterthirdparty = 0;
  918. $array_of_element_linkable_with_different_thirdparty = array('facture_fourn', 'commande_fournisseur');
  919. if (!in_array($tablename, $array_of_element_linkable_with_different_thirdparty)) {
  920. $idtofilterthirdparty = empty($object->thirdparty->id) ? 0 : $object->thirdparty->id;
  921. if (!empty($conf->global->PROJECT_OTHER_THIRDPARTY_ID_TO_ADD_ELEMENTS)) {
  922. $idtofilterthirdparty .= ','.$conf->global->PROJECT_OTHER_THIRDPARTY_ID_TO_ADD_ELEMENTS;
  923. }
  924. }
  925. $elementarray = $object->get_element_list($key, $tablename, $datefieldname, $dates, $datee, !empty($project_field) ? $project_field : 'fk_projet');
  926. if (empty($conf->global->PROJECT_LINK_ON_OVERWIEW_DISABLED) && $idtofilterthirdparty && !in_array($tablename, $exclude_select_element)) {
  927. $selectList = $formproject->select_element($tablename, $idtofilterthirdparty, 'minwidth300 minwidth75imp', -2, empty($project_field) ? 'fk_projet' : $project_field, $langs->trans("SelectElement"));
  928. if ($selectList < 0) {
  929. setEventMessages($formproject->error, $formproject->errors, 'errors');
  930. } elseif ($selectList) {
  931. // Define form with the combo list of elements to link
  932. $addform .= '<div class="inline-block valignmiddle">';
  933. $addform .= '<form action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post">';
  934. $addform .= '<input type="hidden" name="token" value="'.newToken().'">';
  935. $addform .= '<input type="hidden" name="tablename" value="'.$tablename.'">';
  936. $addform .= '<input type="hidden" name="action" value="addelement">';
  937. $addform .= '<input type="hidden" name="datesrfc" value="'.dol_print_date($dates, 'dayhourrfc').'">';
  938. $addform .= '<input type="hidden" name="dateerfc" value="'.dol_print_date($datee, 'dayhourrfc').'">';
  939. $addform .= '<table><tr>';
  940. //$addform .= '<td><span class="hideonsmartphone opacitymedium">'.$langs->trans("SelectElement").'</span></td>';
  941. $addform .= '<td>'.$selectList.'</td>';
  942. $addform .= '<td><input type="submit" class="button button-linkto smallpaddingimp" value="'.dol_escape_htmltag($langs->trans("LinkToElementShort")).'"></td>';
  943. $addform .= '</tr></table>';
  944. $addform .= '</form>';
  945. $addform .= '</div>';
  946. }
  947. }
  948. if (empty($conf->global->PROJECT_CREATE_ON_OVERVIEW_DISABLED) && $urlnew) {
  949. $addform .= '<div class="inline-block valignmiddle">';
  950. if ($testnew) {
  951. $addform .= '<a class="buttonxxx marginleftonly" href="'.$urlnew.'" title="'.dol_escape_htmltag($langs->trans($buttonnew)).'"><span class="fa fa-plus-circle valignmiddle paddingleft"></span></a>';
  952. } elseif (empty($conf->global->MAIN_BUTTON_HIDE_UNAUTHORIZED)) {
  953. $addform .= '<span title="'.dol_escape_htmltag($langs->trans($buttonnew)).'"><a class="buttonxxx marginleftonly buttonRefused" disabled="disabled" href="#"><span class="fa fa-plus-circle valignmiddle paddingleft"></span></a></span>';
  954. }
  955. $addform .= '<div>';
  956. }
  957. if (is_array($elementarray) && count($elementarray) > 0 && $key == "order_supplier") {
  958. $addform = '<div class="inline-block valignmiddle"><a id="btnShow" class="buttonxxx marginleftonly" href="#" onClick="return false;">
  959. <span id="textBtnShow" class="valignmiddle text-plus-circle hideonsmartphone">'.$langs->trans("CanceledShown").'</span><span id="minus-circle" class="fa fa-eye valignmiddle paddingleft"></span>
  960. </a>
  961. <script>
  962. $("#btnShow").on("click", function () {
  963. console.log("We click to show or hide the canceled lines");
  964. var attr = $(this).attr("data-canceledarehidden");
  965. if (typeof attr !== "undefined" && attr !== false) {
  966. console.log("Show canceled");
  967. $(".tr_canceled").show();
  968. $("#textBtnShow").text("'.dol_escape_js($langs->transnoentitiesnoconv("CanceledShown")).'");
  969. $("#btnShow").removeAttr("data-canceledarehidden");
  970. $("#minus-circle").removeClass("fa-eye-slash").addClass("fa-eye");
  971. } else {
  972. console.log("Hide canceled");
  973. $(".tr_canceled").hide();
  974. $("#textBtnShow").text("'.dol_escape_js($langs->transnoentitiesnoconv("CanceledHidden")).'");
  975. $("#btnShow").attr("data-canceledarehidden", 1);
  976. $("#minus-circle").removeClass("fa-eye").addClass("fa-eye-slash");
  977. }
  978. });
  979. </script></div> '.$addform;
  980. }
  981. print load_fiche_titre($langs->trans($title), $addform, '');
  982. print "\n".'<!-- Table for tablename = '.$tablename.' -->'."\n";
  983. print '<div class="div-table-responsive">';
  984. print '<table class="noborder centpercent">';
  985. print '<tr class="liste_titre">';
  986. // Remove link column
  987. print '<td style="width: 24px"></td>';
  988. // Ref
  989. print '<td'.(($tablename != 'actioncomm' && $tablename != 'projet_task') ? ' style="width: 200px"' : '').'>'.$langs->trans("Ref").'</td>';
  990. // Date
  991. print '<td'.(($tablename != 'actioncomm' && $tablename != 'projet_task') ? ' style="width: 200px"' : '').' class="center">';
  992. if (in_array($tablename, array('projet_task'))) {
  993. print $langs->trans("TimeSpent");
  994. }
  995. if (!in_array($tablename, array('projet_task'))) {
  996. print $langs->trans("Date");
  997. }
  998. print '</td>';
  999. // Thirdparty or user
  1000. print '<td>';
  1001. if (in_array($tablename, array('projet_task')) && $key == 'project_task') {
  1002. print ''; // if $key == 'project_task', we don't want details per user
  1003. } elseif (in_array($tablename, array('payment_various'))) {
  1004. print ''; // if $key == 'payment_various', we don't have any thirdparty
  1005. } elseif (in_array($tablename, array('expensereport_det', 'don', 'projet_task', 'stock_mouvement', 'salary'))) {
  1006. print $langs->trans("User");
  1007. } else {
  1008. print $langs->trans("ThirdParty");
  1009. }
  1010. print '</td>';
  1011. // Duration of intervention
  1012. if ($tablename == 'fichinter') {
  1013. print '<td>';
  1014. print $langs->trans("TotalDuration");
  1015. $total_duration = 0;
  1016. print '</td>';
  1017. }
  1018. // Amount HT
  1019. //if (empty($value['disableamount']) && ! in_array($tablename, array('projet_task'))) print '<td class="right" width="120">'.$langs->trans("AmountHT").'</td>';
  1020. //elseif (empty($value['disableamount']) && in_array($tablename, array('projet_task'))) print '<td class="right" width="120">'.$langs->trans("Amount").'</td>';
  1021. if ($key == 'loan') {
  1022. print '<td class="right" width="120">'.$langs->trans("LoanCapital").'</td>';
  1023. } elseif (empty($value['disableamount'])) {
  1024. print '<td class="right" width="120">'.$langs->trans("AmountHT").'</td>';
  1025. } else {
  1026. print '<td width="120"></td>';
  1027. }
  1028. // Amount TTC
  1029. //if (empty($value['disableamount']) && ! in_array($tablename, array('projet_task'))) print '<td class="right" width="120">'.$langs->trans("AmountTTC").'</td>';
  1030. if ($key == 'loan') {
  1031. print '<td class="right" width="120">'.$langs->trans("RemainderToPay").'</td>';
  1032. } elseif (empty($value['disableamount'])) {
  1033. print '<td class="right" width="120">'.$langs->trans("AmountTTC").'</td>';
  1034. } else {
  1035. print '<td width="120"></td>';
  1036. }
  1037. // Status
  1038. if (in_array($tablename, array('projet_task'))) {
  1039. print '<td class="right" width="200">'.$langs->trans("ProgressDeclared").'</td>';
  1040. } else {
  1041. print '<td class="right" width="200">'.$langs->trans("Status").'</td>';
  1042. }
  1043. print '</tr>';
  1044. if (is_array($elementarray) && count($elementarray) > 0) {
  1045. $total_ht = 0;
  1046. $total_ttc = 0;
  1047. $total_ht_by_third = 0;
  1048. $total_ttc_by_third = 0;
  1049. $saved_third_id = 0;
  1050. $breakline = '';
  1051. if (canApplySubtotalOn($tablename)) {
  1052. // Sort
  1053. $elementarray = sortElementsByClientName($elementarray);
  1054. }
  1055. $num = count($elementarray);
  1056. for ($i = 0; $i < $num; $i++) {
  1057. $tmp = explode('_', $elementarray[$i]);
  1058. $idofelement = $tmp[0];
  1059. $idofelementuser = isset($tmp[1]) ? $tmp[1] : "";
  1060. $element->fetch($idofelement);
  1061. if ($idofelementuser) {
  1062. $elementuser->fetch($idofelementuser);
  1063. }
  1064. // Special cases
  1065. if ($tablename != 'expensereport_det') {
  1066. if (method_exists($element, 'fetch_thirdparty')) {
  1067. $element->fetch_thirdparty();
  1068. }
  1069. } else {
  1070. $expensereport = new ExpenseReport($db);
  1071. $expensereport->fetch($element->fk_expensereport);
  1072. }
  1073. //print 'xxx'.$tablename.'yyy'.$classname;
  1074. if ($breakline && $saved_third_id != $element->thirdparty->id) {
  1075. print $breakline;
  1076. $saved_third_id = $element->thirdparty->id;
  1077. $breakline = '';
  1078. $total_ht_by_third = 0;
  1079. $total_ttc_by_third = 0;
  1080. }
  1081. $saved_third_id = empty($element->thirdparty->id) ? 0 : $element->thirdparty->id;
  1082. $qualifiedfortotal = true;
  1083. if ($key == 'invoice') {
  1084. if (!empty($element->close_code) && $element->close_code == 'replaced') {
  1085. $qualifiedfortotal = false; // Replacement invoice, do not include into total
  1086. }
  1087. } elseif ($key == 'order_supplier' && $element->status == 7) {
  1088. $qualifiedfortotal = false; // It makes no sense to include canceled orders in the total
  1089. }
  1090. if ($key == "order_supplier" && $element->status == 7) {
  1091. print '<tr class="oddeven tr_canceled" style=display:none>';
  1092. } else {
  1093. print '<tr class="oddeven" >';
  1094. }
  1095. // Remove link
  1096. print '<td style="width: 24px">';
  1097. if ($tablename != 'projet_task' && $tablename != 'stock_mouvement') {
  1098. if (empty($conf->global->PROJECT_DISABLE_UNLINK_FROM_OVERVIEW) || $user->admin) { // PROJECT_DISABLE_UNLINK_FROM_OVERVIEW is empty by defaut, so this test true
  1099. print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=unlink&tablename='.$tablename.'&elementselect='.$element->id.($project_field ? '&projectfield='.$project_field : '').'" class="reposition">';
  1100. print img_picto($langs->trans('Unlink'), 'unlink');
  1101. print '</a>';
  1102. }
  1103. }
  1104. print "</td>\n";
  1105. // Ref
  1106. print '<td class="left nowraponall">';
  1107. if ($tablename == 'expensereport_det') {
  1108. print $expensereport->getNomUrl(1);
  1109. } else {
  1110. // Show ref with link
  1111. if ($element instanceof Task) {
  1112. print $element->getNomUrl(1, 'withproject', 'time');
  1113. print ' - '.dol_trunc($element->label, 48);
  1114. } elseif ($key == 'loan') {
  1115. print $element->getNomUrl(1);
  1116. print ' - '.dol_trunc($element->label, 48);
  1117. } else {
  1118. print $element->getNomUrl(1);
  1119. }
  1120. $element_doc = $element->element;
  1121. $filename = dol_sanitizeFileName($element->ref);
  1122. if (!empty($conf->$element_doc)) {
  1123. $confelementdoc = $conf->$element_doc;
  1124. $filedir = $confelementdoc->multidir_output[$element->entity].'/'.dol_sanitizeFileName($element->ref);
  1125. } else {
  1126. $filedir = '';
  1127. }
  1128. if ($element_doc === 'order_supplier') {
  1129. $element_doc = 'commande_fournisseur';
  1130. $filedir = $conf->fournisseur->commande->multidir_output[$element->entity].'/'.dol_sanitizeFileName($element->ref);
  1131. } elseif ($element_doc === 'invoice_supplier') {
  1132. $element_doc = 'facture_fournisseur';
  1133. $filename = get_exdir($element->id, 2, 0, 0, $element, 'product').dol_sanitizeFileName($element->ref);
  1134. $filedir = $conf->fournisseur->facture->multidir_output[$element->entity].'/'.get_exdir($element->id, 2, 0, 0, $element, 'invoice_supplier').dol_sanitizeFileName($element->ref);
  1135. }
  1136. print '<div class="inline-block valignmiddle">';
  1137. if ($filedir) {
  1138. print $formfile->getDocumentsLink($element_doc, $filename, $filedir);
  1139. }
  1140. print '</div>';
  1141. // Show supplier ref
  1142. if (!empty($element->ref_supplier)) {
  1143. print ' - '.$element->ref_supplier;
  1144. }
  1145. // Show customer ref
  1146. if (!empty($element->ref_customer)) {
  1147. print ' - '.$element->ref_customer;
  1148. }
  1149. // Compatibility propale
  1150. if (empty($element->ref_customer) && !empty($element->ref_client)) {
  1151. print ' - '.$element->ref_client;
  1152. }
  1153. }
  1154. print "</td>\n";
  1155. // Date or TimeSpent
  1156. $date = ''; $total_time_by_line = null; $total_time = 0;
  1157. if ($tablename == 'expensereport_det') {
  1158. $date = $element->date; // No draft status on lines
  1159. } elseif ($tablename == 'stock_mouvement') {
  1160. $date = $element->datem;
  1161. } elseif ($tablename == 'salary') {
  1162. $date = $element->datesp;
  1163. } elseif ($tablename == 'payment_various') {
  1164. $date = $element->datev;
  1165. } elseif ($tablename == 'chargesociales') {
  1166. $date = $element->date_ech;
  1167. } elseif (!empty($element->status) || !empty($element->statut) || !empty($element->fk_status)) {
  1168. if ($tablename == 'don') {
  1169. $date = $element->datedon;
  1170. }
  1171. if ($tablename == 'commande_fournisseur' || $tablename == 'supplier_order') {
  1172. $date = ($element->date_commande ? $element->date_commande : $element->date_valid);
  1173. } elseif ($tablename == 'supplier_proposal') {
  1174. $date = $element->date_validation; // There is no other date for this
  1175. } elseif ($tablename == 'fichinter') {
  1176. $date = $element->datev; // There is no other date for this
  1177. } elseif ($tablename == 'projet_task') {
  1178. $date = ''; // We show no date. Showing date of beginning of task make user think it is date of time consumed
  1179. } else {
  1180. $date = $element->date; // invoice, ...
  1181. if (empty($date)) {
  1182. $date = $element->date_contrat;
  1183. }
  1184. if (empty($date)) {
  1185. $date = $element->datev;
  1186. }
  1187. if (empty($date) && !empty($datefieldname)) {
  1188. $date = $element->$datefieldname;
  1189. }
  1190. }
  1191. } elseif ($key == 'loan') {
  1192. $date = $element->datestart;
  1193. }
  1194. print '<td class="center">';
  1195. if ($tablename == 'actioncomm') {
  1196. print dol_print_date($element->datep, 'dayhour');
  1197. if ($element->datef && $element->datef > $element->datep) {
  1198. print " - ".dol_print_date($element->datef, 'dayhour');
  1199. }
  1200. } elseif (in_array($tablename, array('projet_task'))) {
  1201. $tmpprojtime = $element->getSumOfAmount($elementuser, $dates, $datee); // $element is a task. $elementuser may be empty
  1202. print '<a href="'.DOL_URL_ROOT.'/projet/tasks/time.php?id='.$idofelement.'&withproject=1">';
  1203. print convertSecondToTime($tmpprojtime['nbseconds'], 'allhourmin');
  1204. print '</a>';
  1205. $total_time_by_line = $tmpprojtime['nbseconds'];
  1206. } else {
  1207. print dol_print_date($date, 'day');
  1208. }
  1209. print '</td>';
  1210. // Third party or user
  1211. print '<td class="left">';
  1212. if (is_object($element->thirdparty)) {
  1213. print $element->thirdparty->getNomUrl(1, '', 48);
  1214. } elseif ($tablename == 'expensereport_det') {
  1215. $tmpuser = new User($db);
  1216. $tmpuser->fetch($expensereport->fk_user_author);
  1217. print $tmpuser->getNomUrl(1, '', 48);
  1218. } elseif ($tablename == 'salary') {
  1219. $tmpuser = new User($db);
  1220. $tmpuser->fetch($element->fk_user);
  1221. print $tmpuser->getNomUrl(1, '', 48);
  1222. } elseif ($tablename == 'don' || $tablename == 'stock_mouvement') {
  1223. if ($element->fk_user_author > 0) {
  1224. $tmpuser2 = new User($db);
  1225. $tmpuser2->fetch($element->fk_user_author);
  1226. print $tmpuser2->getNomUrl(1, '', 48);
  1227. }
  1228. } elseif ($tablename == 'projet_task' && $key == 'element_time') { // if $key == 'project_task', we don't want details per user
  1229. print $elementuser->getNomUrl(1);
  1230. }
  1231. print '</td>';
  1232. // Add duration and store it in counter for fichinter
  1233. if ($tablename == 'fichinter') {
  1234. print '<td>';
  1235. print convertSecondToTime($element->duration, 'all', $conf->global->MAIN_DURATION_OF_WORKDAY);
  1236. $total_duration += $element->duration;
  1237. print '</td>';
  1238. }
  1239. // Amount without tax
  1240. $warning = '';
  1241. if (empty($value['disableamount'])) {
  1242. $total_ht_by_line = null;
  1243. $othermessage = '';
  1244. if ($tablename == 'don' || $tablename == 'chargesociales' || $tablename == 'payment_various' || $tablename == 'salary') {
  1245. $total_ht_by_line = $element->amount;
  1246. } elseif ($tablename == 'fichinter') {
  1247. $total_ht_by_line = $element->getAmount();
  1248. } elseif ($tablename == 'stock_mouvement') {
  1249. $total_ht_by_line = $element->price * abs($element->qty);
  1250. } elseif (in_array($tablename, array('projet_task'))) {
  1251. if (!empty($conf->salaries->enabled)) {
  1252. // TODO Permission to read daily rate to show value
  1253. $total_ht_by_line = price2num($tmpprojtime['amount'], 'MT');
  1254. if ($tmpprojtime['nblinesnull'] > 0) {
  1255. $langs->load("errors");
  1256. $warning = $langs->trans("WarningSomeLinesWithNullHourlyRate", $conf->currency);
  1257. }
  1258. } else {
  1259. $othermessage = $form->textwithpicto($langs->trans("NotAvailable"), $langs->trans("ModuleSalaryToDefineHourlyRateMustBeEnabled"));
  1260. }
  1261. } elseif ($key == 'loan') {
  1262. $total_ht_by_line = $element->capital;
  1263. } else {
  1264. $total_ht_by_line = $element->total_ht;
  1265. }
  1266. // Change sign of $total_ht_by_line and $total_ttc_by_line for some cases
  1267. if ($tablename == 'payment_various') {
  1268. if ($element->sens == 0) {
  1269. $total_ht_by_line = -$total_ht_by_line;
  1270. }
  1271. }
  1272. print '<td class="right">';
  1273. if ($othermessage) {
  1274. print $othermessage;
  1275. }
  1276. if (isset($total_ht_by_line)) {
  1277. if (!$qualifiedfortotal) {
  1278. print '<strike>';
  1279. }
  1280. print '<span class="amount">'.price($total_ht_by_line).'</span>';
  1281. if (!$qualifiedfortotal) {
  1282. print '</strike>';
  1283. }
  1284. }
  1285. if ($warning) {
  1286. print ' '.img_warning($warning);
  1287. }
  1288. print '</td>';
  1289. } else {
  1290. print '<td></td>';
  1291. }
  1292. // Amount inc tax
  1293. if (empty($value['disableamount'])) {
  1294. $total_ttc_by_line = null;
  1295. if ($tablename == 'don' || $tablename == 'chargesociales' || $tablename == 'payment_various' || $tablename == 'salary') {
  1296. $total_ttc_by_line = $element->amount;
  1297. } elseif ($tablename == 'fichinter') {
  1298. $total_ttc_by_line = $element->getAmount();
  1299. } elseif ($tablename == 'stock_mouvement') {
  1300. $total_ttc_by_line = $element->price * abs($element->qty);
  1301. } elseif ($tablename == 'projet_task') {
  1302. if (!empty($conf->salaries->enabled)) {
  1303. // TODO Permission to read daily rate
  1304. $defaultvat = get_default_tva($mysoc, $mysoc);
  1305. $total_ttc_by_line = price2num($total_ht_by_line * (1 + ($defaultvat / 100)), 'MT');
  1306. } else {
  1307. $othermessage = $form->textwithpicto($langs->trans("NotAvailable"), $langs->trans("ModuleSalaryToDefineHourlyRateMustBeEnabled"));
  1308. }
  1309. } elseif ($key == 'loan') {
  1310. $total_ttc_by_line = $element->capital - $element->getSumPayment();
  1311. } else {
  1312. $total_ttc_by_line = $element->total_ttc;
  1313. }
  1314. // Change sign of $total_ht_by_line and $total_ttc_by_line for some cases
  1315. if ($tablename == 'payment_various') {
  1316. if ($element->sens == 0) {
  1317. $total_ttc_by_line = -$total_ttc_by_line;
  1318. }
  1319. }
  1320. print '<td class="right">';
  1321. if ($othermessage) {
  1322. print $othermessage;
  1323. }
  1324. if (isset($total_ttc_by_line)) {
  1325. if (!$qualifiedfortotal) {
  1326. print '<strike>';
  1327. }
  1328. print '<span class="amount">'.price($total_ttc_by_line).'</span>';
  1329. if (!$qualifiedfortotal) {
  1330. print '</strike>';
  1331. }
  1332. }
  1333. if ($warning) {
  1334. print ' '.img_warning($warning);
  1335. }
  1336. print '</td>';
  1337. } else {
  1338. print '<td></td>';
  1339. }
  1340. // Status
  1341. print '<td class="right">';
  1342. if ($tablename == 'expensereport_det') {
  1343. print $expensereport->getLibStatut(5);
  1344. } elseif ($element instanceof CommonInvoice) {
  1345. //This applies for Facture and FactureFournisseur
  1346. print $element->getLibStatut(5, $element->getSommePaiement());
  1347. } elseif ($element instanceof Task) {
  1348. if ($element->progress != '') {
  1349. print $element->progress.' %';
  1350. }
  1351. } elseif ($tablename == 'stock_mouvement') {
  1352. print $element->getLibStatut(3);
  1353. } else {
  1354. print $element->getLibStatut(5);
  1355. }
  1356. print '</td>';
  1357. print '</tr>';
  1358. if ($qualifiedfortotal) {
  1359. $total_ht = $total_ht + $total_ht_by_line;
  1360. $total_ttc = $total_ttc + $total_ttc_by_line;
  1361. $total_ht_by_third += $total_ht_by_line;
  1362. $total_ttc_by_third += $total_ttc_by_line;
  1363. if (!isset($total_time)) $total_time = $total_time_by_line;
  1364. else $total_time += $total_time_by_line;
  1365. }
  1366. if (canApplySubtotalOn($tablename)) {
  1367. $breakline = '<tr class="liste_total liste_sub_total">';
  1368. $breakline .= '<td colspan="2">';
  1369. $breakline .= '</td>';
  1370. $breakline .= '<td>';
  1371. $breakline .= '</td>';
  1372. $breakline .= '<td class="right">';
  1373. $breakline .= $langs->trans('SubTotal').' : ';
  1374. if (is_object($element->thirdparty)) {
  1375. $breakline .= $element->thirdparty->getNomUrl(0, '', 48);
  1376. }
  1377. $breakline .= '</td>';
  1378. $breakline .= '<td class="right">'.price($total_ht_by_third).'</td>';
  1379. $breakline .= '<td class="right">'.price($total_ttc_by_third).'</td>';
  1380. $breakline .= '<td></td>';
  1381. $breakline .= '</tr>';
  1382. }
  1383. //var_dump($element->thirdparty->name.' - '.$saved_third_id.' - '.$element->thirdparty->id);
  1384. }
  1385. if ($breakline) {
  1386. print $breakline;
  1387. }
  1388. // Total
  1389. if (empty($nototal)) {
  1390. $colspan = 4;
  1391. if (in_array($tablename, array('projet_task'))) {
  1392. $colspan = 2;
  1393. }
  1394. print '<tr class="liste_total"><td colspan="'.$colspan.'">'.$langs->trans("Number").': '.$i.'</td>';
  1395. if (in_array($tablename, array('projet_task'))) {
  1396. print '<td class="center">';
  1397. print convertSecondToTime($total_time, 'allhourmin');
  1398. print '</td>';
  1399. print '<td>';
  1400. print '</td>';
  1401. }
  1402. //if (empty($value['disableamount']) && ! in_array($tablename, array('projet_task'))) print '<td class="right" width="100">'.$langs->trans("TotalHT").' : '.price($total_ht).'</td>';
  1403. //elseif (empty($value['disableamount']) && in_array($tablename, array('projet_task'))) print '<td class="right" width="100">'.$langs->trans("Total").' : '.price($total_ht).'</td>';
  1404. // If fichinter add the total_duration
  1405. if ($tablename == 'fichinter') {
  1406. print '<td class="left">'.convertSecondToTime($total_duration, 'all', $conf->global->MAIN_DURATION_OF_WORKDAY).'</td>';
  1407. }
  1408. print '<td class="right">';
  1409. if (empty($value['disableamount'])) {
  1410. if ($key == 'loan') {
  1411. print $langs->trans("Total").' '.$langs->trans("LoanCapital").' : '.price($total_ttc);
  1412. } elseif ($tablename != 'projet_task' || !empty($conf->salaries->enabled)) {
  1413. print ''.$langs->trans("TotalHT").' : '.price($total_ht);
  1414. }
  1415. }
  1416. print '</td>';
  1417. //if (empty($value['disableamount']) && ! in_array($tablename, array('projet_task'))) print '<td class="right" width="100">'.$langs->trans("TotalTTC").' : '.price($total_ttc).'</td>';
  1418. //elseif (empty($value['disableamount']) && in_array($tablename, array('projet_task'))) print '<td class="right" width="100"></td>';
  1419. print '<td class="right">';
  1420. if (empty($value['disableamount'])) {
  1421. if ($key == 'loan') {
  1422. print $langs->trans("Total").' '.$langs->trans("RemainderToPay").' : '.price($total_ttc);
  1423. } elseif ($tablename != 'projet_task' || !empty($conf->salaries->enabled)) {
  1424. print $langs->trans("TotalTTC").' : '.price($total_ttc);
  1425. }
  1426. }
  1427. print '</td>';
  1428. print '<td>&nbsp;</td>';
  1429. print '</tr>';
  1430. }
  1431. } else {
  1432. if (!is_array($elementarray)) { // error
  1433. print '<tr><td>'.$elementarray.'</td></tr>';
  1434. } else {
  1435. $colspan = 7;
  1436. if (in_array($tablename, array('projet_task'))) {
  1437. $colspan = 5;
  1438. }
  1439. if ($tablename == 'fichinter') {
  1440. $colspan++;
  1441. }
  1442. print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("None").'</td></tr>';
  1443. }
  1444. }
  1445. print "</table>";
  1446. print '</div>';
  1447. print "<br>\n";
  1448. }
  1449. }
  1450. // Enhance with select2
  1451. if ($conf->use_javascript_ajax) {
  1452. include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
  1453. $comboenhancement = ajax_combobox('.elementselect');
  1454. print $comboenhancement;
  1455. }
  1456. // End of page
  1457. llxFooter();
  1458. $db->close();
  1459. /**
  1460. * Return if we should do a group by customer with sub-total
  1461. *
  1462. * @param string $tablename Name of table
  1463. * @return boolean True to tell to make a group by sub-total
  1464. */
  1465. function canApplySubtotalOn($tablename)
  1466. {
  1467. global $conf;
  1468. if (empty($conf->global->PROJECT_ADD_SUBTOTAL_LINES)) {
  1469. return false;
  1470. }
  1471. return in_array($tablename, array('facture_fourn', 'commande_fournisseur'));
  1472. }
  1473. /**
  1474. * sortElementsByClientName
  1475. *
  1476. * @param array $elementarray Element array
  1477. * @return array Element array sorted
  1478. */
  1479. function sortElementsByClientName($elementarray)
  1480. {
  1481. global $db, $classname;
  1482. $element = new $classname($db);
  1483. $clientname = array();
  1484. foreach ($elementarray as $key => $id) { // id = id of object
  1485. if (empty($clientname[$id])) {
  1486. $element->fetch($id);
  1487. $element->fetch_thirdparty();
  1488. $clientname[$id] = $element->thirdparty->name;
  1489. }
  1490. }
  1491. //var_dump($clientname);
  1492. asort($clientname); // sort on name
  1493. $elementarray = array();
  1494. foreach ($clientname as $id => $name) {
  1495. $elementarray[] = $id;
  1496. }
  1497. return $elementarray;
  1498. }