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