element.php 59 KB

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