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