element.php 62 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638
  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 (isModEnabled('facture')) {
  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 (isModEnabled('agenda')) {
  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 (isModEnabled('facture')) {
  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 (!empty($object->thirdparty->id) && $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 (empty($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 img_picto($langs->trans('SharedProject'), 'world', 'class="paddingrightonly"');
  246. print $langs->trans('SharedProject');
  247. } else {
  248. print img_picto($langs->trans('PrivateProject'), 'private', 'class="paddingrightonly"');
  249. print $langs->trans('PrivateProject');
  250. }
  251. print '</td></tr>';
  252. if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES)) {
  253. // Opportunity status
  254. print '<tr><td>'.$langs->trans("OpportunityStatus").'</td><td>';
  255. $code = dol_getIdFromCode($db, $object->opp_status, 'c_lead_status', 'rowid', 'code');
  256. if ($code) {
  257. print $langs->trans("OppStatus".$code);
  258. }
  259. print '</td></tr>';
  260. // Opportunity percent
  261. print '<tr><td>'.$langs->trans("OpportunityProbability").'</td><td>';
  262. if (strcmp($object->opp_percent, '')) {
  263. print price($object->opp_percent, '', $langs, 1, 0).' %';
  264. }
  265. print '</td></tr>';
  266. // Opportunity Amount
  267. print '<tr><td>'.$langs->trans("OpportunityAmount").'</td><td>';
  268. if (strcmp($object->opp_amount, '')) {
  269. print '<span class="amount">'.price($object->opp_amount, '', $langs, 1, 0, 0, $conf->currency).'</span>';
  270. if (strcmp($object->opp_percent, '')) {
  271. 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>';
  272. }
  273. }
  274. print '</td></tr>';
  275. }
  276. // Date start - end
  277. print '<tr><td>'.$langs->trans("DateStart").' - '.$langs->trans("DateEnd").'</td><td>';
  278. $start = dol_print_date($object->date_start, 'day');
  279. print ($start ? $start : '?');
  280. $end = dol_print_date($object->date_end, 'day');
  281. print ' - ';
  282. print ($end ? $end : '?');
  283. if ($object->hasDelay()) {
  284. print img_warning("Late");
  285. }
  286. print '</td></tr>';
  287. // Budget
  288. print '<tr><td>'.$langs->trans("Budget").'</td><td>';
  289. if (strcmp($object->budget_amount, '')) {
  290. print '<span class="amount">'.price($object->budget_amount, '', $langs, 1, 0, 0, $conf->currency).'</span>';
  291. }
  292. print '</td></tr>';
  293. // Other attributes
  294. $cols = 2;
  295. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
  296. print '</table>';
  297. print '</div>';
  298. print '<div class="fichehalfright">';
  299. print '<div class="underbanner clearboth"></div>';
  300. print '<table class="border tableforfield centpercent">';
  301. // Description
  302. print '<td class="titlefield tdtop">'.$langs->trans("Description").'</td><td>';
  303. print nl2br($object->description);
  304. print '</td></tr>';
  305. // Categories
  306. if (isModEnabled('categorie')) {
  307. print '<tr><td class="valignmiddle">'.$langs->trans("Categories").'</td><td>';
  308. print $form->showCategories($object->id, Categorie::TYPE_PROJECT, 1);
  309. print "</td></tr>";
  310. }
  311. print '</table>';
  312. print '</div>';
  313. print '</div>';
  314. print '<div class="clearboth"></div>';
  315. print dol_get_fiche_end();
  316. print '<br>';
  317. /*
  318. * Referers types
  319. */
  320. $listofreferent = array(
  321. 'entrepot'=>array(
  322. 'name'=>"Warehouse",
  323. 'title'=>"ListWarehouseAssociatedProject",
  324. 'class'=>'Entrepot',
  325. 'table'=>'entrepot',
  326. 'datefieldname'=>'date_entrepot',
  327. 'urlnew'=>DOL_URL_ROOT.'/product/stock/card.php?action=create&projectid='.$id.'&backtopage='.urlencode($_SERVER['PHP_SELF'].'?id='.$id),
  328. 'lang'=>'entrepot',
  329. 'buttonnew'=>'AddWarehouse',
  330. 'project_field'=>'fk_project',
  331. 'testnew'=>$user->rights->stock->creer,
  332. 'test'=>$conf->stock->enabled && $user->rights->stock->lire && !empty($conf->global->WAREHOUSE_ASK_WAREHOUSE_DURING_PROJECT)),
  333. 'propal'=>array(
  334. 'name'=>"Proposals",
  335. 'title'=>"ListProposalsAssociatedProject",
  336. 'class'=>'Propal',
  337. 'table'=>'propal',
  338. 'datefieldname'=>'datep',
  339. 'urlnew'=>DOL_URL_ROOT.'/comm/propal/card.php?action=create&origin=project&originid='.$id.'&socid='.$socid.'&backtopage='.urlencode($_SERVER['PHP_SELF'].'?id='.$id),
  340. 'lang'=>'propal',
  341. 'buttonnew'=>'AddProp',
  342. 'testnew'=>$user->rights->propal->creer,
  343. 'test'=>$conf->propal->enabled && $user->rights->propale->lire),
  344. 'order'=>array(
  345. 'name'=>"CustomersOrders",
  346. 'title'=>"ListOrdersAssociatedProject",
  347. 'class'=>'Commande',
  348. 'table'=>'commande',
  349. 'datefieldname'=>'date_commande',
  350. 'urlnew'=>DOL_URL_ROOT.'/commande/card.php?action=create&projectid='.$id.'&socid='.$socid.'&backtopage='.urlencode($_SERVER['PHP_SELF'].'?id='.$id),
  351. 'lang'=>'orders',
  352. 'buttonnew'=>'CreateOrder',
  353. 'testnew'=>$user->rights->commande->creer,
  354. 'test'=>$conf->commande->enabled && $user->rights->commande->lire),
  355. 'invoice'=>array(
  356. 'name'=>"CustomersInvoices",
  357. 'title'=>"ListInvoicesAssociatedProject",
  358. 'class'=>'Facture',
  359. 'margin'=>'add',
  360. 'table'=>'facture',
  361. 'datefieldname'=>'datef',
  362. 'urlnew'=>DOL_URL_ROOT.'/compta/facture/card.php?action=create&projectid='.$id.'&socid='.$socid.'&backtopage='.urlencode($_SERVER['PHP_SELF'].'?id='.$id),
  363. 'lang'=>'bills',
  364. 'buttonnew'=>'CreateBill',
  365. 'testnew'=>$user->rights->facture->creer,
  366. 'test'=>$conf->facture->enabled && $user->rights->facture->lire),
  367. 'invoice_predefined'=>array(
  368. 'name'=>"PredefinedInvoices",
  369. 'title'=>"ListPredefinedInvoicesAssociatedProject",
  370. 'class'=>'FactureRec',
  371. 'table'=>'facture_rec',
  372. 'datefieldname'=>'datec',
  373. 'urlnew'=>DOL_URL_ROOT.'/compta/facture/card.php?action=create&projectid='.$id.'&socid='.$socid.'&backtopage='.urlencode($_SERVER['PHP_SELF'].'?id='.$id),
  374. 'lang'=>'bills',
  375. 'buttonnew'=>'CreateBill',
  376. 'testnew'=>$user->rights->facture->creer,
  377. 'test'=>$conf->facture->enabled && $user->rights->facture->lire),
  378. 'proposal_supplier'=>array(
  379. 'name'=>"SuppliersProposals",
  380. 'title'=>"ListSupplierProposalsAssociatedProject",
  381. 'class'=>'SupplierProposal',
  382. 'table'=>'supplier_proposal',
  383. 'datefieldname'=>'date_valid',
  384. '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
  385. 'lang'=>'supplier_proposal',
  386. 'buttonnew'=>'AddSupplierProposal',
  387. 'testnew'=>$user->rights->supplier_proposal->creer,
  388. 'test'=>$conf->supplier_proposal->enabled && $user->rights->supplier_proposal->lire),
  389. 'order_supplier'=>array(
  390. 'name'=>"SuppliersOrders",
  391. 'title'=>"ListSupplierOrdersAssociatedProject",
  392. 'class'=>'CommandeFournisseur',
  393. 'table'=>'commande_fournisseur',
  394. 'datefieldname'=>'date_commande',
  395. '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
  396. 'lang'=>'suppliers',
  397. 'buttonnew'=>'AddSupplierOrder',
  398. 'testnew'=>($user->rights->fournisseur->commande->creer || $user->rights->supplier_order->creer),
  399. 'test'=>$conf->supplier_order->enabled && ($user->rights->fournisseur->commande->lire || $user->rights->supplier_order->lire)),
  400. 'invoice_supplier'=>array(
  401. 'name'=>"BillsSuppliers",
  402. 'title'=>"ListSupplierInvoicesAssociatedProject",
  403. 'class'=>'FactureFournisseur',
  404. 'margin'=>'minus',
  405. 'table'=>'facture_fourn',
  406. 'datefieldname'=>'datef',
  407. '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
  408. 'lang'=>'suppliers',
  409. 'buttonnew'=>'AddSupplierInvoice',
  410. 'testnew'=>($user->rights->fournisseur->facture->creer || $user->rights->supplier_invoice->creer),
  411. 'test'=>$conf->supplier_invoice->enabled && ($user->rights->fournisseur->facture->lire || $user->rights->supplier_invoice->lire)),
  412. 'contract'=>array(
  413. 'name'=>"Contracts",
  414. 'title'=>"ListContractAssociatedProject",
  415. 'class'=>'Contrat',
  416. 'table'=>'contrat',
  417. 'datefieldname'=>'date_contrat',
  418. 'urlnew'=>DOL_URL_ROOT.'/contrat/card.php?action=create&projectid='.$id.'&socid='.$socid.'&backtopage='.urlencode($_SERVER['PHP_SELF'].'?id='.$id),
  419. 'lang'=>'contracts',
  420. 'buttonnew'=>'AddContract',
  421. 'testnew'=>$user->rights->contrat->creer,
  422. 'test'=>$conf->contrat->enabled && $user->rights->contrat->lire),
  423. 'intervention'=>array(
  424. 'name'=>"Interventions",
  425. 'title'=>"ListFichinterAssociatedProject",
  426. 'class'=>'Fichinter',
  427. 'table'=>'fichinter',
  428. 'datefieldname'=>'date_valid',
  429. 'disableamount'=>0,
  430. 'margin'=>'',
  431. 'urlnew'=>DOL_URL_ROOT.'/fichinter/card.php?action=create&origin=project&originid='.$id.'&socid='.$socid.'&backtopage='.urlencode($_SERVER['PHP_SELF'].'?id='.$id),
  432. 'lang'=>'interventions',
  433. 'buttonnew'=>'AddIntervention',
  434. 'testnew'=>$user->rights->ficheinter->creer,
  435. 'test'=>$conf->ficheinter->enabled && $user->rights->ficheinter->lire),
  436. 'shipping'=>array(
  437. 'name'=>"Shippings",
  438. 'title'=>"ListShippingAssociatedProject",
  439. 'class'=>'Expedition',
  440. 'table'=>'expedition',
  441. 'datefieldname'=>'date_valid',
  442. 'urlnew'=>DOL_URL_ROOT.'/expedition/card.php?action=create&origin=project&originid='.$id.'&socid='.$socid.'&backtopage='.urlencode($_SERVER['PHP_SELF'].'?id='.$id),
  443. 'lang'=>'sendings',
  444. 'buttonnew'=>'CreateShipment',
  445. 'testnew'=>0,
  446. 'test'=>$conf->expedition->enabled && $user->rights->expedition->lire),
  447. 'mrp'=>array(
  448. 'name'=>"MO",
  449. 'title'=>"ListMOAssociatedProject",
  450. 'class'=>'Mo',
  451. 'table'=>'mrp_mo',
  452. 'datefieldname'=>'date_valid',
  453. 'urlnew'=>DOL_URL_ROOT.'/mrp/mo_card.php?action=create&origin=project&originid='.$id.'&socid='.$socid.'&backtopage='.urlencode($_SERVER['PHP_SELF'].'?id='.$id),
  454. 'lang'=>'mrp',
  455. 'buttonnew'=>'CreateMO',
  456. 'testnew'=>'$user->rights->mrp->write',
  457. 'project_field'=>'fk_project',
  458. 'test'=>$conf->mrp->enabled && $user->rights->mrp->read),
  459. 'trip'=>array(
  460. 'name'=>"TripsAndExpenses",
  461. 'title'=>"ListExpenseReportsAssociatedProject",
  462. 'class'=>'Deplacement',
  463. 'table'=>'deplacement',
  464. 'datefieldname'=>'dated',
  465. 'margin'=>'minus',
  466. 'disableamount'=>1,
  467. 'urlnew'=>DOL_URL_ROOT.'/deplacement/card.php?action=create&projectid='.$id.'&socid='.$socid.'&backtopage='.urlencode($_SERVER['PHP_SELF'].'?id='.$id),
  468. 'lang'=>'trips',
  469. 'buttonnew'=>'AddTrip',
  470. 'testnew'=>$user->rights->deplacement->creer,
  471. 'test'=>$conf->deplacement->enabled && $user->rights->deplacement->lire),
  472. 'expensereport'=>array(
  473. 'name'=>"ExpenseReports",
  474. 'title'=>"ListExpenseReportsAssociatedProject",
  475. 'class'=>'ExpenseReportLine',
  476. 'table'=>'expensereport_det',
  477. 'datefieldname'=>'date',
  478. 'margin'=>'minus',
  479. 'disableamount'=>0,
  480. 'urlnew'=>DOL_URL_ROOT.'/expensereport/card.php?action=create&projectid='.$id.'&socid='.$socid.'&backtopage='.urlencode($_SERVER['PHP_SELF'].'?id='.$id),
  481. 'lang'=>'trips',
  482. 'buttonnew'=>'AddTrip',
  483. 'testnew'=>$user->rights->expensereport->creer,
  484. 'test'=>$conf->expensereport->enabled && $user->rights->expensereport->lire),
  485. 'donation'=>array(
  486. 'name'=>"Donation",
  487. 'title'=>"ListDonationsAssociatedProject",
  488. 'class'=>'Don',
  489. 'margin'=>'add',
  490. 'table'=>'don',
  491. 'datefieldname'=>'datedon',
  492. 'disableamount'=>0,
  493. 'urlnew'=>DOL_URL_ROOT.'/don/card.php?action=create&projectid='.$id.'&socid='.$socid.'&backtopage='.urlencode($_SERVER['PHP_SELF'].'?id='.$id),
  494. 'lang'=>'donations',
  495. 'buttonnew'=>'AddDonation',
  496. 'testnew'=>$user->rights->don->creer,
  497. 'test'=>$conf->don->enabled && $user->rights->don->lire),
  498. 'loan'=>array(
  499. 'name'=>"Loan",
  500. 'title'=>"ListLoanAssociatedProject",
  501. 'class'=>'Loan',
  502. 'margin'=>'add',
  503. 'table'=>'loan',
  504. 'datefieldname'=>'datestart',
  505. 'disableamount'=>0,
  506. 'urlnew'=>DOL_URL_ROOT.'/loan/card.php?action=create&projectid='.$id.'&socid='.$socid.'&backtopage='.urlencode($_SERVER['PHP_SELF'].'?id='.$id),
  507. 'lang'=>'loan',
  508. 'buttonnew'=>'AddLoan',
  509. 'testnew'=>$user->rights->loan->write,
  510. 'test'=>$conf->loan->enabled && $user->rights->loan->read),
  511. 'chargesociales'=>array(
  512. 'name'=>"SocialContribution",
  513. 'title'=>"ListSocialContributionAssociatedProject",
  514. 'class'=>'ChargeSociales',
  515. 'margin'=>'minus',
  516. 'table'=>'chargesociales',
  517. 'datefieldname'=>'date_ech',
  518. 'disableamount'=>0,
  519. 'urlnew'=>DOL_URL_ROOT.'/compta/sociales/card.php?action=create&projectid='.$id.'&backtopage='.urlencode($_SERVER['PHP_SELF'].'?id='.$id),
  520. 'lang'=>'compta',
  521. 'buttonnew'=>'AddSocialContribution',
  522. 'testnew'=>$user->rights->tax->charges->lire,
  523. 'test'=>$conf->tax->enabled && $user->rights->tax->charges->lire),
  524. 'project_task'=>array(
  525. 'name'=>"TaskTimeSpent",
  526. 'title'=>"ListTaskTimeUserProject",
  527. 'class'=>'Task',
  528. 'margin'=>'minus',
  529. 'table'=>'projet_task',
  530. 'datefieldname'=>'task_date',
  531. 'disableamount'=>0,
  532. 'urlnew'=>DOL_URL_ROOT.'/projet/tasks/time.php?withproject=1&action=createtime&projectid='.$id.'&backtopage='.urlencode($_SERVER['PHP_SELF'].'?id='.$id),
  533. 'buttonnew'=>'AddTimeSpent',
  534. 'testnew'=>$user->rights->projet->creer,
  535. 'test'=>($conf->project->enabled && $user->rights->projet->lire && empty($conf->global->PROJECT_HIDE_TASKS))),
  536. 'stock_mouvement'=>array(
  537. 'name'=>"MouvementStockAssociated",
  538. 'title'=>"ListMouvementStockProject",
  539. 'class'=>'MouvementStock',
  540. 'table'=>'stock_mouvement',
  541. 'datefieldname'=>'datem',
  542. 'margin'=>'minus',
  543. 'disableamount'=>0,
  544. 'test'=>($conf->stock->enabled && $user->rights->stock->mouvement->lire && !empty($conf->global->STOCK_MOVEMENT_INTO_PROJECT_OVERVIEW))),
  545. 'salaries'=>array(
  546. 'name'=>"Salaries",
  547. 'title'=>"ListSalariesAssociatedProject",
  548. 'class'=>'Salary',
  549. 'table'=>'salary',
  550. 'datefieldname'=>'datesp',
  551. 'margin'=>'minus',
  552. 'disableamount'=>0,
  553. 'urlnew'=>DOL_URL_ROOT.'/salaries/card.php?action=create&projectid='.$id.'&backtopage='.urlencode($_SERVER['PHP_SELF'].'?id='.$id),
  554. 'lang'=>'salaries',
  555. 'buttonnew'=>'AddSalary',
  556. 'testnew'=>$user->rights->salaries->write,
  557. 'test'=>$conf->salaries->enabled && $user->rights->salaries->read),
  558. 'variouspayment'=>array(
  559. 'name'=>"VariousPayments",
  560. 'title'=>"ListVariousPaymentsAssociatedProject",
  561. 'class'=>'PaymentVarious',
  562. 'table'=>'payment_various',
  563. 'datefieldname'=>'datev',
  564. 'margin'=>'minus',
  565. 'disableamount'=>0,
  566. 'urlnew'=>DOL_URL_ROOT.'/compta/bank/various_payment/card.php?action=create&projectid='.$id.'&backtopage='.urlencode($_SERVER['PHP_SELF'].'?id='.$id),
  567. 'lang'=>'banks',
  568. 'buttonnew'=>'AddVariousPayment',
  569. 'testnew'=>$user->rights->banque->modifier,
  570. 'test'=>$conf->banque->enabled && $user->rights->banque->lire && empty($conf->global->BANK_USE_OLD_VARIOUS_PAYMENT)),
  571. /* No need for this, available on dedicated tab "Agenda/Events"
  572. 'agenda'=>array(
  573. 'name'=>"Agenda",
  574. 'title'=>"ListActionsAssociatedProject",
  575. 'class'=>'ActionComm',
  576. 'table'=>'actioncomm',
  577. 'datefieldname'=>'datep',
  578. 'disableamount'=>1,
  579. 'urlnew'=>DOL_URL_ROOT.'/comm/action/card.php?action=create&projectid='.$id.'&socid='.$socid.'&backtopage='.urlencode($_SERVER['PHP_SELF'].'?id='.$id),
  580. 'lang'=>'agenda',
  581. 'buttonnew'=>'AddEvent',
  582. 'testnew'=>$user->rights->agenda->myactions->create,
  583. 'test'=>$conf->agenda->enabled && $user->rights->agenda->myactions->read),
  584. */
  585. );
  586. // Change rules for profit/benefit calculation
  587. if (!empty($conf->global->PROJECT_ELEMENTS_FOR_PLUS_MARGIN)) {
  588. foreach ($listofreferent as $key => $element) {
  589. if ($listofreferent[$key]['margin'] == 'add') {
  590. unset($listofreferent[$key]['margin']);
  591. }
  592. }
  593. $newelementforplusmargin = explode(',', $conf->global->PROJECT_ELEMENTS_FOR_PLUS_MARGIN);
  594. foreach ($newelementforplusmargin as $value) {
  595. $listofreferent[trim($value)]['margin'] = 'add';
  596. }
  597. }
  598. if (!empty($conf->global->PROJECT_ELEMENTS_FOR_MINUS_MARGIN)) {
  599. foreach ($listofreferent as $key => $element) {
  600. if ($listofreferent[$key]['margin'] == 'minus') {
  601. unset($listofreferent[$key]['margin']);
  602. }
  603. }
  604. $newelementforminusmargin = explode(',', $conf->global->PROJECT_ELEMENTS_FOR_MINUS_MARGIN);
  605. foreach ($newelementforminusmargin as $value) {
  606. $listofreferent[trim($value)]['margin'] = 'minus';
  607. }
  608. }
  609. $parameters = array('listofreferent'=>$listofreferent);
  610. $resHook = $hookmanager->executeHooks('completeListOfReferent', $parameters, $object, $action);
  611. if (!empty($hookmanager->resArray)) {
  612. $listofreferent = array_merge($listofreferent, $hookmanager->resArray);
  613. }
  614. if ($action == "addelement") {
  615. $tablename = GETPOST("tablename");
  616. $elementselectid = GETPOST("elementselect");
  617. $result = $object->update_element($tablename, $elementselectid);
  618. if ($result < 0) {
  619. setEventMessages($object->error, $object->errors, 'errors');
  620. }
  621. } elseif ($action == "unlink") {
  622. $tablename = GETPOST("tablename", "aZ09");
  623. $projectField = GETPOSTISSET('projectfield') ? GETPOST('projectfield', 'aZ09') : 'fk_projet';
  624. $elementselectid = GETPOST("elementselect", "int");
  625. $result = $object->remove_element($tablename, $elementselectid, $projectField);
  626. if ($result < 0) {
  627. setEventMessages($object->error, $object->errors, 'errors');
  628. }
  629. }
  630. $elementuser = new User($db);
  631. $showdatefilter = 0;
  632. // Show the filter on date on top of element list
  633. if (!$showdatefilter) {
  634. print '<div class="center centpercent">';
  635. print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="POST">';
  636. print '<input type="hidden" name="token" value="'.newToken().'">';
  637. print '<input type="hidden" name="tablename" value="'.$tablename.'">';
  638. print '<input type="hidden" name="action" value="view">';
  639. print '<div class="inline-block">';
  640. print $form->selectDate($dates, 'dates', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("From"));
  641. print '</div>';
  642. print '<div class="inline-block">';
  643. print $form->selectDate($datee, 'datee', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("to"));
  644. print '</div>';
  645. print '<div class="inline-block">';
  646. print '<input type="submit" name="refresh" value="'.$langs->trans("Refresh").'" class="button small">';
  647. print '</div>';
  648. print '</form>';
  649. print '</div>';
  650. $showdatefilter++;
  651. }
  652. // Show balance for whole project
  653. $langs->loadLangs(array("suppliers", "bills", "orders", "proposals", "margins"));
  654. if (!empty($conf->stock->enabled)) {
  655. $langs->load('stocks');
  656. }
  657. print load_fiche_titre($langs->trans("Profit"), '', 'title_accountancy');
  658. print '<table class="noborder centpercent">';
  659. print '<tr class="liste_titre">';
  660. print '<td class="left" width="200">';
  661. $tooltiponprofit = $langs->trans("ProfitIsCalculatedWith")."<br>\n";
  662. $tooltiponprofitplus = $tooltiponprofitminus = '';
  663. foreach ($listofreferent as $key => $value) {
  664. $name = $langs->trans($value['name']);
  665. $qualified = $value['test'];
  666. $margin = $value['margin'];
  667. if ($qualified && isset($margin)) { // If this element must be included into profit calculation ($margin is 'minus' or 'add')
  668. if ($margin == 'add') {
  669. $tooltiponprofitplus .= ' &gt; '.$name." (+)<br>\n";
  670. }
  671. if ($margin == 'minus') {
  672. $tooltiponprofitminus .= ' &gt; '.$name." (-)<br>\n";
  673. }
  674. }
  675. }
  676. $tooltiponprofit .= $tooltiponprofitplus;
  677. $tooltiponprofit .= $tooltiponprofitminus;
  678. print $form->textwithpicto($langs->trans("Element"), $tooltiponprofit);
  679. print '</td>';
  680. print '<td class="right" width="100">'.$langs->trans("Number").'</td>';
  681. print '<td class="right" width="100">'.$langs->trans("AmountHT").'</td>';
  682. print '<td class="right" width="100">'.$langs->trans("AmountTTC").'</td>';
  683. print '</tr>';
  684. $total_revenue_ht = 0;
  685. $balance_ht = 0;
  686. $balance_ttc = 0;
  687. // Loop on each element type (proposal, sale order, invoices, ...)
  688. foreach ($listofreferent as $key => $value) {
  689. $parameters = array(
  690. 'total_revenue_ht' =>& $total_revenue_ht,
  691. 'balance_ht' =>& $balance_ht,
  692. 'balance_ttc' =>& $balance_ttc,
  693. 'key' => $key,
  694. 'value' =>& $value,
  695. 'dates' => $dates,
  696. 'datee' => $datee
  697. );
  698. $reshook = $hookmanager->executeHooks('printOverviewProfit', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  699. if ($reshook < 0) {
  700. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  701. } elseif ($reshook > 0) {
  702. print $hookmanager->resPrint;
  703. continue;
  704. }
  705. $name = $langs->trans($value['name']);
  706. $title = $value['title'];
  707. $classname = $value['class'];
  708. $tablename = $value['table'];
  709. $datefieldname = $value['datefieldname'];
  710. $qualified = $value['test'];
  711. $margin = $value['margin'];
  712. $project_field = $value['project_field'];
  713. if ($qualified && isset($margin)) { // If this element must be included into profit calculation ($margin is 'minus' or 'add')
  714. $element = new $classname($db);
  715. $elementarray = $object->get_element_list($key, $tablename, $datefieldname, $dates, $datee, !empty($project_field) ? $project_field : 'fk_projet');
  716. if (is_array($elementarray) && count($elementarray) > 0) {
  717. $total_ht = 0;
  718. $total_ttc = 0;
  719. // Loop on each object for the current element type
  720. $num = count($elementarray);
  721. for ($i = 0; $i < $num; $i++) {
  722. $tmp = explode('_', $elementarray[$i]);
  723. $idofelement = $tmp[0];
  724. $idofelementuser = $tmp[1];
  725. $element->fetch($idofelement);
  726. if ($idofelementuser) {
  727. $elementuser->fetch($idofelementuser);
  728. }
  729. // Define if record must be used for total or not
  730. $qualifiedfortotal = true;
  731. if ($key == 'invoice') {
  732. if (!empty($element->close_code) && $element->close_code == 'replaced') {
  733. $qualifiedfortotal = false; // Replacement invoice, do not include into total
  734. }
  735. if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS) && $element->type == Facture::TYPE_DEPOSIT) {
  736. $qualifiedfortotal = false; // If hidden option to use deposits as payment (deprecated, not recommended to use this), deposits are not included
  737. }
  738. }
  739. if ($key == 'propal') {
  740. if ($element->status != Propal::STATUS_SIGNED && $element->status != Propal::STATUS_BILLED) {
  741. $qualifiedfortotal = false; // Only signed proposal must not be included in total
  742. }
  743. }
  744. if ($tablename != 'expensereport_det' && method_exists($element, 'fetch_thirdparty')) {
  745. $element->fetch_thirdparty();
  746. }
  747. // Define $total_ht_by_line
  748. if ($tablename == 'don' || $tablename == 'chargesociales' || $tablename == 'payment_various' || $tablename == 'salary') {
  749. $total_ht_by_line = $element->amount;
  750. } elseif ($tablename == 'fichinter') {
  751. $total_ht_by_line = $element->getAmount();
  752. } elseif ($tablename == 'stock_mouvement') {
  753. $total_ht_by_line = $element->price * abs($element->qty);
  754. } elseif ($tablename == 'projet_task') {
  755. if ($idofelementuser) {
  756. $tmp = $element->getSumOfAmount($elementuser, $dates, $datee);
  757. $total_ht_by_line = price2num($tmp['amount'], 'MT');
  758. } else {
  759. $tmp = $element->getSumOfAmount('', $dates, $datee);
  760. $total_ht_by_line = price2num($tmp['amount'], 'MT');
  761. }
  762. } elseif ($key == 'loan') {
  763. if ((empty($dates) && empty($datee)) || (intval($dates) <= $element->datestart && intval($datee) >= $element->dateend)) {
  764. // Get total loan
  765. $total_ht_by_line = -$element->capital;
  766. } else {
  767. // Get loan schedule according to date filter
  768. $total_ht_by_line = 0;
  769. $loanScheduleStatic = new LoanSchedule($element->db);
  770. $loanScheduleStatic->fetchAll($element->id);
  771. if (!empty($loanScheduleStatic->lines)) {
  772. foreach ($loanScheduleStatic->lines as $loanSchedule) {
  773. /**
  774. * @var $loanSchedule LoanSchedule
  775. */
  776. if (($loanSchedule->datep >= $dates && $loanSchedule->datep <= $datee) // dates filter is defined
  777. || !empty($dates) && empty($datee) && $loanSchedule->datep >= $dates && $loanSchedule->datep <= dol_now()
  778. || empty($dates) && !empty($datee) && $loanSchedule->datep <= $datee
  779. ) {
  780. $total_ht_by_line -= $loanSchedule->amount_capital;
  781. }
  782. }
  783. }
  784. }
  785. } else {
  786. $total_ht_by_line = $element->total_ht;
  787. }
  788. // Define $total_ttc_by_line
  789. if ($tablename == 'don' || $tablename == 'chargesociales' || $tablename == 'payment_various' || $tablename == 'salary') {
  790. $total_ttc_by_line = $element->amount;
  791. } elseif ($tablename == 'fichinter') {
  792. $total_ttc_by_line = $element->getAmount();
  793. } elseif ($tablename == 'stock_mouvement') {
  794. $total_ttc_by_line = $element->price * abs($element->qty);
  795. } elseif ($tablename == 'projet_task') {
  796. $defaultvat = get_default_tva($mysoc, $mysoc);
  797. $total_ttc_by_line = price2num($total_ht_by_line * (1 + ($defaultvat / 100)), 'MT');
  798. } elseif ($key == 'loan') {
  799. $total_ttc_by_line = $total_ht_by_line; // For loan there is actually no taxe managed in Dolibarr
  800. } else {
  801. $total_ttc_by_line = $element->total_ttc;
  802. }
  803. // Change sign of $total_ht_by_line and $total_ttc_by_line for some cases
  804. if ($tablename == 'payment_various') {
  805. if ($element->sens == 1) {
  806. $total_ht_by_line = -$total_ht_by_line;
  807. $total_ttc_by_line = -$total_ttc_by_line;
  808. }
  809. }
  810. // Add total if we have to
  811. if ($qualifiedfortotal) {
  812. $total_ht = $total_ht + $total_ht_by_line;
  813. $total_ttc = $total_ttc + $total_ttc_by_line;
  814. }
  815. }
  816. // Each element with at least one line is output
  817. // Calculate margin
  818. if ($margin) {
  819. if ($margin === 'add') {
  820. $total_revenue_ht += $total_ht;
  821. }
  822. if ($margin === "minus") { // 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' && !$margin) {
  837. print '<span class="opacitymedium">'.$form->textwithpicto($langs->trans("NA"), $langs->trans("AmountOfInteventionNotIncludedByDefault")).'</span>';
  838. } else {
  839. if ($key == 'propal') {
  840. print '<span class="opacitymedium">'.$form->textwithpicto('', $langs->trans("SignedOnly")).'</span>';
  841. }
  842. print price($total_ht);
  843. }
  844. print '</td>';
  845. // Amount TTC
  846. print '<td class="right">';
  847. if ($key == 'intervention' && !$margin) {
  848. print '<span class="opacitymedium">'.$form->textwithpicto($langs->trans("NA"), $langs->trans("AmountOfInteventionNotIncludedByDefault")).'</span>';
  849. } else {
  850. if ($key == 'propal') {
  851. print '<span class="opacitymedium">'.$form->textwithpicto('', $langs->trans("SignedOnly")).'</span>';
  852. }
  853. print price($total_ttc);
  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. $elementarray = $object->get_element_list($key, $tablename, $datefieldname, $dates, $datee, !empty($project_field) ? $project_field : 'fk_projet');
  923. if (empty($conf->global->PROJECT_LINK_ON_OVERWIEW_DISABLED) && $idtofilterthirdparty && !in_array($tablename, $exclude_select_element)) {
  924. $selectList = $formproject->select_element($tablename, $idtofilterthirdparty, 'minwidth300 minwidth75imp', -2, empty($project_field) ? 'fk_projet' : $project_field, $langs->trans("SelectElement"));
  925. if ($selectList < 0) {
  926. setEventMessages($formproject->error, $formproject->errors, 'errors');
  927. } elseif ($selectList) {
  928. // Define form with the combo list of elements to link
  929. $addform .= '<div class="inline-block valignmiddle">';
  930. $addform .= '<form action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post">';
  931. $addform .= '<input type="hidden" name="token" value="'.newToken().'">';
  932. $addform .= '<input type="hidden" name="tablename" value="'.$tablename.'">';
  933. $addform .= '<input type="hidden" name="action" value="addelement">';
  934. $addform .= '<input type="hidden" name="datesrfc" value="'.dol_print_date($dates, 'dayhourrfc').'">';
  935. $addform .= '<input type="hidden" name="dateerfc" value="'.dol_print_date($datee, 'dayhourrfc').'">';
  936. $addform .= '<table><tr>';
  937. //$addform .= '<td><span class="hideonsmartphone opacitymedium">'.$langs->trans("SelectElement").'</span></td>';
  938. $addform .= '<td>'.$selectList.'</td>';
  939. $addform .= '<td><input type="submit" class="button button-linkto smallpaddingimp" value="'.dol_escape_htmltag($langs->trans("LinkToElementShort")).'"></td>';
  940. $addform .= '</tr></table>';
  941. $addform .= '</form>';
  942. $addform .= '</div>';
  943. }
  944. }
  945. if (empty($conf->global->PROJECT_CREATE_ON_OVERVIEW_DISABLED) && $urlnew) {
  946. $addform .= '<div class="inline-block valignmiddle">';
  947. if ($testnew) {
  948. $addform .= '<a class="buttonxxx marginleftonly" href="'.$urlnew.'" title="'.dol_escape_htmltag($langs->trans($buttonnew)).'"><span class="fa fa-plus-circle valignmiddle paddingleft"></span></a>';
  949. } elseif (empty($conf->global->MAIN_BUTTON_HIDE_UNAUTHORIZED)) {
  950. $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>';
  951. }
  952. $addform .= '<div>';
  953. }
  954. if (is_array($elementarray) && count($elementarray) > 0 && $key == "order_supplier") {
  955. $addform = '<div class="inline-block valignmiddle"><a id="btnShow" class="buttonxxx marginleftonly" href="#" onClick="return false;">
  956. <span id="textBtnShow" class="valignmiddle text-plus-circle hideonsmartphone">'.$langs->trans("CanceledShown").'</span><span id="minus-circle" class="fa fa-eye valignmiddle paddingleft"></span>
  957. </a>
  958. <script>
  959. $("#btnShow").on("click", function () {
  960. console.log("We click to show or hide the canceled lines");
  961. var attr = $(this).attr("data-canceledarehidden");
  962. if (typeof attr !== "undefined" && attr !== false) {
  963. console.log("Show canceled");
  964. $(".tr_canceled").show();
  965. $("#textBtnShow").text("'.dol_escape_js($langs->transnoentitiesnoconv("CanceledShown")).'");
  966. $("#btnShow").removeAttr("data-canceledarehidden");
  967. $("#minus-circle").removeClass("fa-eye-slash").addClass("fa-eye");
  968. } else {
  969. console.log("Hide canceled");
  970. $(".tr_canceled").hide();
  971. $("#textBtnShow").text("'.dol_escape_js($langs->transnoentitiesnoconv("CanceledHidden")).'");
  972. $("#btnShow").attr("data-canceledarehidden", 1);
  973. $("#minus-circle").removeClass("fa-eye").addClass("fa-eye-slash");
  974. }
  975. });
  976. </script></div> '.$addform;
  977. }
  978. print load_fiche_titre($langs->trans($title), $addform, '');
  979. print "\n".'<!-- Table for tablename = '.$tablename.' -->'."\n";
  980. print '<div class="div-table-responsive">';
  981. print '<table class="noborder centpercent">';
  982. print '<tr class="liste_titre">';
  983. // Remove link column
  984. print '<td style="width: 24px"></td>';
  985. // Ref
  986. print '<td'.(($tablename != 'actioncomm' && $tablename != 'projet_task') ? ' style="width: 200px"' : '').'>'.$langs->trans("Ref").'</td>';
  987. // Date
  988. print '<td'.(($tablename != 'actioncomm' && $tablename != 'projet_task') ? ' style="width: 200px"' : '').' class="center">';
  989. if (in_array($tablename, array('projet_task'))) {
  990. print $langs->trans("TimeSpent");
  991. }
  992. if (!in_array($tablename, array('projet_task'))) {
  993. print $langs->trans("Date");
  994. }
  995. print '</td>';
  996. // Thirdparty or user
  997. print '<td>';
  998. if (in_array($tablename, array('projet_task')) && $key == 'project_task') {
  999. print ''; // if $key == 'project_task', we don't want details per user
  1000. } elseif (in_array($tablename, array('payment_various'))) {
  1001. print ''; // if $key == 'payment_various', we don't have any thirdparty
  1002. } elseif (in_array($tablename, array('expensereport_det', 'don', 'projet_task', 'stock_mouvement', 'salary'))) {
  1003. print $langs->trans("User");
  1004. } else {
  1005. print $langs->trans("ThirdParty");
  1006. }
  1007. print '</td>';
  1008. // Duration of intervention
  1009. if ($tablename == 'fichinter') {
  1010. print '<td>';
  1011. print $langs->trans("TotalDuration");
  1012. $total_duration = 0;
  1013. print '</td>';
  1014. }
  1015. // Amount HT
  1016. //if (empty($value['disableamount']) && ! in_array($tablename, array('projet_task'))) print '<td class="right" width="120">'.$langs->trans("AmountHT").'</td>';
  1017. //elseif (empty($value['disableamount']) && in_array($tablename, array('projet_task'))) print '<td class="right" width="120">'.$langs->trans("Amount").'</td>';
  1018. if ($key == 'loan') {
  1019. print '<td class="right" width="120">'.$langs->trans("LoanCapital").'</td>';
  1020. } elseif (empty($value['disableamount'])) {
  1021. print '<td class="right" width="120">'.$langs->trans("AmountHT").'</td>';
  1022. } else {
  1023. print '<td width="120"></td>';
  1024. }
  1025. // Amount TTC
  1026. //if (empty($value['disableamount']) && ! in_array($tablename, array('projet_task'))) print '<td class="right" width="120">'.$langs->trans("AmountTTC").'</td>';
  1027. if ($key == 'loan') {
  1028. print '<td class="right" width="120">'.$langs->trans("RemainderToPay").'</td>';
  1029. } elseif (empty($value['disableamount'])) {
  1030. print '<td class="right" width="120">'.$langs->trans("AmountTTC").'</td>';
  1031. } else {
  1032. print '<td width="120"></td>';
  1033. }
  1034. // Status
  1035. if (in_array($tablename, array('projet_task'))) {
  1036. print '<td class="right" width="200">'.$langs->trans("ProgressDeclared").'</td>';
  1037. } else {
  1038. print '<td class="right" width="200">'.$langs->trans("Status").'</td>';
  1039. }
  1040. print '</tr>';
  1041. if (is_array($elementarray) && count($elementarray) > 0) {
  1042. $total_ht = 0;
  1043. $total_ttc = 0;
  1044. $total_ht_by_third = 0;
  1045. $total_ttc_by_third = 0;
  1046. $saved_third_id = 0;
  1047. $breakline = '';
  1048. if (canApplySubtotalOn($tablename)) {
  1049. // Sort
  1050. $elementarray = sortElementsByClientName($elementarray);
  1051. }
  1052. $num = count($elementarray);
  1053. for ($i = 0; $i < $num; $i++) {
  1054. $tmp = explode('_', $elementarray[$i]);
  1055. $idofelement = $tmp[0];
  1056. $idofelementuser = $tmp[1];
  1057. $element->fetch($idofelement);
  1058. if ($idofelementuser) {
  1059. $elementuser->fetch($idofelementuser);
  1060. }
  1061. // Special cases
  1062. if ($tablename != 'expensereport_det') {
  1063. if (method_exists($element, 'fetch_thirdparty')) {
  1064. $element->fetch_thirdparty();
  1065. }
  1066. } else {
  1067. $expensereport = new ExpenseReport($db);
  1068. $expensereport->fetch($element->fk_expensereport);
  1069. }
  1070. //print 'xxx'.$tablename.'yyy'.$classname;
  1071. if ($breakline && $saved_third_id != $element->thirdparty->id) {
  1072. print $breakline;
  1073. $saved_third_id = $element->thirdparty->id;
  1074. $breakline = '';
  1075. $total_ht_by_third = 0;
  1076. $total_ttc_by_third = 0;
  1077. }
  1078. $saved_third_id = $element->thirdparty->id;
  1079. $qualifiedfortotal = true;
  1080. if ($key == 'invoice') {
  1081. if (!empty($element->close_code) && $element->close_code == 'replaced') {
  1082. $qualifiedfortotal = false; // Replacement invoice, do not include into total
  1083. }
  1084. } elseif ($key == 'order_supplier' && $element->status == 7) {
  1085. $qualifiedfortotal = false; // It makes no sense to include canceled orders in the total
  1086. }
  1087. if ($key == "order_supplier" && $element->status == 7) {
  1088. print '<tr class="oddeven tr_canceled" style=display:none>';
  1089. } else {
  1090. print '<tr class="oddeven" >';
  1091. }
  1092. // Remove link
  1093. print '<td style="width: 24px">';
  1094. if ($tablename != 'projet_task' && $tablename != 'stock_mouvement') {
  1095. if (empty($conf->global->PROJECT_DISABLE_UNLINK_FROM_OVERVIEW) || $user->admin) { // PROJECT_DISABLE_UNLINK_FROM_OVERVIEW is empty by defaut, so this test true
  1096. print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=unlink&tablename='.$tablename.'&elementselect='.$element->id.($project_field ? '&projectfield='.$project_field : '').'" class="reposition">';
  1097. print img_picto($langs->trans('Unlink'), 'unlink');
  1098. print '</a>';
  1099. }
  1100. }
  1101. print "</td>\n";
  1102. // Ref
  1103. print '<td class="left nowraponall">';
  1104. if ($tablename == 'expensereport_det') {
  1105. print $expensereport->getNomUrl(1);
  1106. } else {
  1107. // Show ref with link
  1108. if ($element instanceof Task) {
  1109. print $element->getNomUrl(1, 'withproject', 'time');
  1110. print ' - '.dol_trunc($element->label, 48);
  1111. } elseif ($key == 'loan') {
  1112. print $element->getNomUrl(1);
  1113. print ' - '.dol_trunc($element->label, 48);
  1114. } else {
  1115. print $element->getNomUrl(1);
  1116. }
  1117. $element_doc = $element->element;
  1118. $filename = dol_sanitizeFileName($element->ref);
  1119. $filedir = $conf->{$element_doc}->multidir_output[$element->entity].'/'.dol_sanitizeFileName($element->ref);
  1120. if ($element_doc === 'order_supplier') {
  1121. $element_doc = 'commande_fournisseur';
  1122. $filedir = $conf->fournisseur->commande->multidir_output[$element->entity].'/'.dol_sanitizeFileName($element->ref);
  1123. } elseif ($element_doc === 'invoice_supplier') {
  1124. $element_doc = 'facture_fournisseur';
  1125. $filename = get_exdir($element->id, 2, 0, 0, $element, 'product').dol_sanitizeFileName($element->ref);
  1126. $filedir = $conf->fournisseur->facture->multidir_output[$element->entity].'/'.get_exdir($element->id, 2, 0, 0, $element, 'invoice_supplier').dol_sanitizeFileName($element->ref);
  1127. }
  1128. print '<div class="inline-block valignmiddle">'.$formfile->getDocumentsLink($element_doc, $filename, $filedir).'</div>';
  1129. // Show supplier ref
  1130. if (!empty($element->ref_supplier)) {
  1131. print ' - '.$element->ref_supplier;
  1132. }
  1133. // Show customer ref
  1134. if (!empty($element->ref_customer)) {
  1135. print ' - '.$element->ref_customer;
  1136. }
  1137. }
  1138. print "</td>\n";
  1139. // Date or TimeSpent
  1140. $date = ''; $total_time_by_line = null;
  1141. if ($tablename == 'expensereport_det') {
  1142. $date = $element->date; // No draft status on lines
  1143. } elseif ($tablename == 'stock_mouvement') {
  1144. $date = $element->datem;
  1145. } elseif ($tablename == 'salary') {
  1146. $date = $element->datesp;
  1147. } elseif ($tablename == 'payment_various') {
  1148. $date = $element->datev;
  1149. } elseif ($tablename == 'chargesociales') {
  1150. $date = $element->date_ech;
  1151. } elseif (!empty($element->status) || !empty($element->statut) || !empty($element->fk_status)) {
  1152. if ($tablename == 'don') {
  1153. $date = $element->datedon;
  1154. }
  1155. if ($tablename == 'commande_fournisseur' || $tablename == 'supplier_order') {
  1156. $date = ($element->date_commande ? $element->date_commande : $element->date_valid);
  1157. } elseif ($tablename == 'supplier_proposal') {
  1158. $date = $element->date_validation; // There is no other date for this
  1159. } elseif ($tablename == 'fichinter') {
  1160. $date = $element->datev; // There is no other date for this
  1161. } elseif ($tablename == 'projet_task') {
  1162. $date = ''; // We show no date. Showing date of beginning of task make user think it is date of time consumed
  1163. } else {
  1164. $date = $element->date; // invoice, ...
  1165. if (empty($date)) {
  1166. $date = $element->date_contrat;
  1167. }
  1168. if (empty($date)) {
  1169. $date = $element->datev;
  1170. }
  1171. if (empty($date) && !empty($datefieldname)) {
  1172. $date = $element->$datefieldname;
  1173. }
  1174. }
  1175. } elseif ($key == 'loan') {
  1176. $date = $element->datestart;
  1177. }
  1178. print '<td class="center">';
  1179. if ($tablename == 'actioncomm') {
  1180. print dol_print_date($element->datep, 'dayhour');
  1181. if ($element->datef && $element->datef > $element->datep) {
  1182. print " - ".dol_print_date($element->datef, 'dayhour');
  1183. }
  1184. } elseif (in_array($tablename, array('projet_task'))) {
  1185. $tmpprojtime = $element->getSumOfAmount($elementuser, $dates, $datee); // $element is a task. $elementuser may be empty
  1186. print '<a href="'.DOL_URL_ROOT.'/projet/tasks/time.php?id='.$idofelement.'&withproject=1">';
  1187. print convertSecondToTime($tmpprojtime['nbseconds'], 'allhourmin');
  1188. print '</a>';
  1189. $total_time_by_line = $tmpprojtime['nbseconds'];
  1190. } else {
  1191. print dol_print_date($date, 'day');
  1192. }
  1193. print '</td>';
  1194. // Third party or user
  1195. print '<td class="left">';
  1196. if (is_object($element->thirdparty)) {
  1197. print $element->thirdparty->getNomUrl(1, '', 48);
  1198. } elseif ($tablename == 'expensereport_det') {
  1199. $tmpuser = new User($db);
  1200. $tmpuser->fetch($expensereport->fk_user_author);
  1201. print $tmpuser->getNomUrl(1, '', 48);
  1202. } elseif ($tablename == 'salary') {
  1203. $tmpuser = new User($db);
  1204. $tmpuser->fetch($element->fk_user);
  1205. print $tmpuser->getNomUrl(1, '', 48);
  1206. } elseif ($tablename == 'don' || $tablename == 'stock_mouvement') {
  1207. if ($element->fk_user_author > 0) {
  1208. $tmpuser2 = new User($db);
  1209. $tmpuser2->fetch($element->fk_user_author);
  1210. print $tmpuser2->getNomUrl(1, '', 48);
  1211. }
  1212. } elseif ($tablename == 'projet_task' && $key == 'project_task_time') { // if $key == 'project_task', we don't want details per user
  1213. print $elementuser->getNomUrl(1);
  1214. }
  1215. print '</td>';
  1216. // Add duration and store it in counter for fichinter
  1217. if ($tablename == 'fichinter') {
  1218. print '<td>';
  1219. print convertSecondToTime($element->duration, 'all', $conf->global->MAIN_DURATION_OF_WORKDAY);
  1220. $total_duration += $element->duration;
  1221. print '</td>';
  1222. }
  1223. // Amount without tax
  1224. $warning = '';
  1225. if (empty($value['disableamount'])) {
  1226. $total_ht_by_line = null;
  1227. $othermessage = '';
  1228. if ($tablename == 'don' || $tablename == 'chargesociales' || $tablename == 'payment_various' || $tablename == 'salary') {
  1229. $total_ht_by_line = $element->amount;
  1230. } elseif ($tablename == 'fichinter') {
  1231. $total_ht_by_line = $element->getAmount();
  1232. } elseif ($tablename == 'stock_mouvement') {
  1233. $total_ht_by_line = $element->price * abs($element->qty);
  1234. } elseif (in_array($tablename, array('projet_task'))) {
  1235. if (!empty($conf->salaries->enabled)) {
  1236. // TODO Permission to read daily rate to show value
  1237. $total_ht_by_line = price2num($tmpprojtime['amount'], 'MT');
  1238. if ($tmpprojtime['nblinesnull'] > 0) {
  1239. $langs->load("errors");
  1240. $warning = $langs->trans("WarningSomeLinesWithNullHourlyRate", $conf->currency);
  1241. }
  1242. } else {
  1243. $othermessage = $form->textwithpicto($langs->trans("NotAvailable"), $langs->trans("ModuleSalaryToDefineHourlyRateMustBeEnabled"));
  1244. }
  1245. } elseif ($key == 'loan') {
  1246. $total_ht_by_line = $element->capital;
  1247. } else {
  1248. $total_ht_by_line = $element->total_ht;
  1249. }
  1250. // Change sign of $total_ht_by_line and $total_ttc_by_line for some cases
  1251. if ($tablename == 'payment_various') {
  1252. if ($element->sens == 0) {
  1253. $total_ht_by_line = -$total_ht_by_line;
  1254. }
  1255. }
  1256. print '<td class="right">';
  1257. if ($othermessage) {
  1258. print $othermessage;
  1259. }
  1260. if (isset($total_ht_by_line)) {
  1261. if (!$qualifiedfortotal) {
  1262. print '<strike>';
  1263. }
  1264. print '<span class="amount">'.price($total_ht_by_line).'</span>';
  1265. if (!$qualifiedfortotal) {
  1266. print '</strike>';
  1267. }
  1268. }
  1269. if ($warning) {
  1270. print ' '.img_warning($warning);
  1271. }
  1272. print '</td>';
  1273. } else {
  1274. print '<td></td>';
  1275. }
  1276. // Amount inc tax
  1277. if (empty($value['disableamount'])) {
  1278. $total_ttc_by_line = null;
  1279. if ($tablename == 'don' || $tablename == 'chargesociales' || $tablename == 'payment_various' || $tablename == 'salary') {
  1280. $total_ttc_by_line = $element->amount;
  1281. } elseif ($tablename == 'fichinter') {
  1282. $total_ttc_by_line = $element->getAmount();
  1283. } elseif ($tablename == 'stock_mouvement') {
  1284. $total_ttc_by_line = $element->price * abs($element->qty);
  1285. } elseif ($tablename == 'projet_task') {
  1286. if (!empty($conf->salaries->enabled)) {
  1287. // TODO Permission to read daily rate
  1288. $defaultvat = get_default_tva($mysoc, $mysoc);
  1289. $total_ttc_by_line = price2num($total_ht_by_line * (1 + ($defaultvat / 100)), 'MT');
  1290. } else {
  1291. $othermessage = $form->textwithpicto($langs->trans("NotAvailable"), $langs->trans("ModuleSalaryToDefineHourlyRateMustBeEnabled"));
  1292. }
  1293. } elseif ($key == 'loan') {
  1294. $total_ttc_by_line = $element->capital - $element->getSumPayment();
  1295. } else {
  1296. $total_ttc_by_line = $element->total_ttc;
  1297. }
  1298. // Change sign of $total_ht_by_line and $total_ttc_by_line for some cases
  1299. if ($tablename == 'payment_various') {
  1300. if ($element->sens == 0) {
  1301. $total_ttc_by_line = -$total_ttc_by_line;
  1302. }
  1303. }
  1304. print '<td class="right">';
  1305. if ($othermessage) {
  1306. print $othermessage;
  1307. }
  1308. if (isset($total_ttc_by_line)) {
  1309. if (!$qualifiedfortotal) {
  1310. print '<strike>';
  1311. }
  1312. print '<span class="amount">'.price($total_ttc_by_line).'</span>';
  1313. if (!$qualifiedfortotal) {
  1314. print '</strike>';
  1315. }
  1316. }
  1317. if ($warning) {
  1318. print ' '.img_warning($warning);
  1319. }
  1320. print '</td>';
  1321. } else {
  1322. print '<td></td>';
  1323. }
  1324. // Status
  1325. print '<td class="right">';
  1326. if ($tablename == 'expensereport_det') {
  1327. print $expensereport->getLibStatut(5);
  1328. } elseif ($element instanceof CommonInvoice) {
  1329. //This applies for Facture and FactureFournisseur
  1330. print $element->getLibStatut(5, $element->getSommePaiement());
  1331. } elseif ($element instanceof Task) {
  1332. if ($element->progress != '') {
  1333. print $element->progress.' %';
  1334. }
  1335. } elseif ($tablename == 'stock_mouvement') {
  1336. print $element->getLibStatut(3);
  1337. } else {
  1338. print $element->getLibStatut(5);
  1339. }
  1340. print '</td>';
  1341. print '</tr>';
  1342. if ($qualifiedfortotal) {
  1343. $total_ht = $total_ht + $total_ht_by_line;
  1344. $total_ttc = $total_ttc + $total_ttc_by_line;
  1345. $total_ht_by_third += $total_ht_by_line;
  1346. $total_ttc_by_third += $total_ttc_by_line;
  1347. $total_time = $total_time + $total_time_by_line;
  1348. }
  1349. if (canApplySubtotalOn($tablename)) {
  1350. $breakline = '<tr class="liste_total liste_sub_total">';
  1351. $breakline .= '<td colspan="2">';
  1352. $breakline .= '</td>';
  1353. $breakline .= '<td>';
  1354. $breakline .= '</td>';
  1355. $breakline .= '<td class="right">';
  1356. $breakline .= $langs->trans('SubTotal').' : ';
  1357. if (is_object($element->thirdparty)) {
  1358. $breakline .= $element->thirdparty->getNomUrl(0, '', 48);
  1359. }
  1360. $breakline .= '</td>';
  1361. $breakline .= '<td class="right">'.price($total_ht_by_third).'</td>';
  1362. $breakline .= '<td class="right">'.price($total_ttc_by_third).'</td>';
  1363. $breakline .= '<td></td>';
  1364. $breakline .= '</tr>';
  1365. }
  1366. //var_dump($element->thirdparty->name.' - '.$saved_third_id.' - '.$element->thirdparty->id);
  1367. }
  1368. if ($breakline) {
  1369. print $breakline;
  1370. }
  1371. // Total
  1372. $colspan = 4;
  1373. if (in_array($tablename, array('projet_task'))) {
  1374. $colspan = 2;
  1375. }
  1376. print '<tr class="liste_total"><td colspan="'.$colspan.'">'.$langs->trans("Number").': '.$i.'</td>';
  1377. if (in_array($tablename, array('projet_task'))) {
  1378. print '<td class="center">';
  1379. print convertSecondToTime($total_time, 'allhourmin');
  1380. print '</td>';
  1381. print '<td>';
  1382. print '</td>';
  1383. }
  1384. //if (empty($value['disableamount']) && ! in_array($tablename, array('projet_task'))) print '<td class="right" width="100">'.$langs->trans("TotalHT").' : '.price($total_ht).'</td>';
  1385. //elseif (empty($value['disableamount']) && in_array($tablename, array('projet_task'))) print '<td class="right" width="100">'.$langs->trans("Total").' : '.price($total_ht).'</td>';
  1386. // If fichinter add the total_duration
  1387. if ($tablename == 'fichinter') {
  1388. print '<td class="left">'.convertSecondToTime($total_duration, 'all', $conf->global->MAIN_DURATION_OF_WORKDAY).'</td>';
  1389. }
  1390. print '<td class="right">';
  1391. if (empty($value['disableamount'])) {
  1392. if ($key == 'loan') {
  1393. print $langs->trans("Total").' '.$langs->trans("LoanCapital").' : '.price($total_ttc);
  1394. } elseif ($tablename != 'projet_task' || !empty($conf->salaries->enabled)) {
  1395. print ''.$langs->trans("TotalHT").' : '.price($total_ht);
  1396. }
  1397. }
  1398. print '</td>';
  1399. //if (empty($value['disableamount']) && ! in_array($tablename, array('projet_task'))) print '<td class="right" width="100">'.$langs->trans("TotalTTC").' : '.price($total_ttc).'</td>';
  1400. //elseif (empty($value['disableamount']) && in_array($tablename, array('projet_task'))) print '<td class="right" width="100"></td>';
  1401. print '<td class="right">';
  1402. if (empty($value['disableamount'])) {
  1403. if ($key == 'loan') {
  1404. print $langs->trans("Total").' '.$langs->trans("RemainderToPay").' : '.price($total_ttc);
  1405. } elseif ($tablename != 'projet_task' || !empty($conf->salaries->enabled)) {
  1406. print $langs->trans("TotalTTC").' : '.price($total_ttc);
  1407. }
  1408. }
  1409. print '</td>';
  1410. print '<td>&nbsp;</td>';
  1411. print '</tr>';
  1412. } else {
  1413. if (!is_array($elementarray)) { // error
  1414. print '<tr><td>'.$elementarray.'</td></tr>';
  1415. } else {
  1416. $colspan = 7;
  1417. if (in_array($tablename, array('projet_task'))) {
  1418. $colspan = 5;
  1419. }
  1420. if ($tablename == 'fichinter') {
  1421. $colspan++;
  1422. }
  1423. print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("None").'</td></tr>';
  1424. }
  1425. }
  1426. print "</table>";
  1427. print '</div>';
  1428. print "<br>\n";
  1429. }
  1430. }
  1431. // Enhance with select2
  1432. if ($conf->use_javascript_ajax) {
  1433. include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
  1434. $comboenhancement = ajax_combobox('.elementselect');
  1435. print $comboenhancement;
  1436. }
  1437. // End of page
  1438. llxFooter();
  1439. $db->close();
  1440. /**
  1441. * Return if we should do a group by customer with sub-total
  1442. *
  1443. * @param string $tablename Name of table
  1444. * @return boolean True to tell to make a group by sub-total
  1445. */
  1446. function canApplySubtotalOn($tablename)
  1447. {
  1448. global $conf;
  1449. if (empty($conf->global->PROJECT_ADD_SUBTOTAL_LINES)) {
  1450. return false;
  1451. }
  1452. return in_array($tablename, array('facture_fourn', 'commande_fournisseur'));
  1453. }
  1454. /**
  1455. * sortElementsByClientName
  1456. *
  1457. * @param array $elementarray Element array
  1458. * @return array Element array sorted
  1459. */
  1460. function sortElementsByClientName($elementarray)
  1461. {
  1462. global $db, $classname;
  1463. $element = new $classname($db);
  1464. $clientname = array();
  1465. foreach ($elementarray as $key => $id) { // id = id of object
  1466. if (empty($clientname[$id])) {
  1467. $element->fetch($id);
  1468. $element->fetch_thirdparty();
  1469. $clientname[$id] = $element->thirdparty->name;
  1470. }
  1471. }
  1472. //var_dump($clientname);
  1473. asort($clientname); // sort on name
  1474. $elementarray = array();
  1475. foreach ($clientname as $id => $name) {
  1476. $elementarray[] = $id;
  1477. }
  1478. return $elementarray;
  1479. }