dolibarr  16.0.1
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'=>'minus',
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  'margin'=>'minus',
588  'table'=>'stock_mouvement',
589  'datefieldname'=>'datem',
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 foreach ($listofreferent as $key => $value) {
756  $parameters = array(
757  'total_revenue_ht' =>& $total_revenue_ht,
758  'balance_ht' =>& $balance_ht,
759  'balance_ttc' =>& $balance_ttc,
760  'key' => $key,
761  'value' =>& $value,
762  'dates' => $dates,
763  'datee' => $datee
764  );
765  $reshook = $hookmanager->executeHooks('printOverviewProfit', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
766  if ($reshook < 0) {
767  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
768  } elseif ($reshook > 0) {
769  print $hookmanager->resPrint;
770  continue;
771  }
772 
773  $name = $langs->trans($value['name']);
774  $title = $value['title'];
775  $classname = $value['class'];
776  $tablename = $value['table'];
777  $datefieldname = $value['datefieldname'];
778  $qualified = $value['test'];
779  $margin = $value['margin'];
780  $project_field = $value['project_field'];
781  if ($qualified && isset($margin)) { // If this element must be included into profit calculation ($margin is 'minus' or 'add')
782  $element = new $classname($db);
783 
784  $elementarray = $object->get_element_list($key, $tablename, $datefieldname, $dates, $datee, !empty($project_field) ? $project_field : 'fk_projet');
785 
786  if (is_array($elementarray) && count($elementarray) > 0) {
787  $total_ht = 0;
788  $total_ttc = 0;
789 
790  $num = count($elementarray);
791  for ($i = 0; $i < $num; $i++) {
792  $tmp = explode('_', $elementarray[$i]);
793  $idofelement = $tmp[0];
794  $idofelementuser = $tmp[1];
795 
796  $element->fetch($idofelement);
797  if ($idofelementuser) {
798  $elementuser->fetch($idofelementuser);
799  }
800 
801  // Define if record must be used for total or not
802  $qualifiedfortotal = true;
803  if ($key == 'invoice') {
804  if (!empty($element->close_code) && $element->close_code == 'replaced') {
805  $qualifiedfortotal = false; // Replacement invoice, do not include into total
806  }
807  if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS) && $element->type == Facture::TYPE_DEPOSIT) {
808  $qualifiedfortotal = false; // If hidden option to use deposits as payment (deprecated, not recommended to use this), deposits are not included
809  }
810  }
811  if ($key == 'propal') {
812  if ($element->status != Propal::STATUS_SIGNED && $element->status != Propal::STATUS_BILLED) {
813  $qualifiedfortotal = false; // Only signed proposal must not be included in total
814  }
815  }
816 
817  if ($tablename != 'expensereport_det' && method_exists($element, 'fetch_thirdparty')) {
818  $element->fetch_thirdparty();
819  }
820 
821  // Define $total_ht_by_line
822  if ($tablename == 'don' || $tablename == 'chargesociales' || $tablename == 'payment_various' || $tablename == 'salary') {
823  $total_ht_by_line = $element->amount;
824  } elseif ($tablename == 'fichinter') {
825  $total_ht_by_line = $element->getAmount();
826  } elseif ($tablename == 'stock_mouvement') {
827  $total_ht_by_line = $element->price * abs($element->qty);
828  } elseif ($tablename == 'projet_task') {
829  if ($idofelementuser) {
830  $tmp = $element->getSumOfAmount($elementuser, $dates, $datee);
831  $total_ht_by_line = price2num($tmp['amount'], 'MT');
832  } else {
833  $tmp = $element->getSumOfAmount('', $dates, $datee);
834  $total_ht_by_line = price2num($tmp['amount'], 'MT');
835  }
836  } elseif ($key == 'loan') {
837  if ((empty($dates) && empty($datee)) || (intval($dates) <= $element->datestart && intval($datee) >= $element->dateend)) {
838  // Get total loan
839  $total_ht_by_line = -$element->capital;
840  } else {
841  // Get loan schedule according to date filter
842  $total_ht_by_line = 0;
843  $loanScheduleStatic = new LoanSchedule($element->db);
844  $loanScheduleStatic->fetchAll($element->id);
845  if (!empty($loanScheduleStatic->lines)) {
846  foreach ($loanScheduleStatic->lines as $loanSchedule) {
850  if (($loanSchedule->datep >= $dates && $loanSchedule->datep <= $datee) // dates filter is defined
851  || !empty($dates) && empty($datee) && $loanSchedule->datep >= $dates && $loanSchedule->datep <= dol_now()
852  || empty($dates) && !empty($datee) && $loanSchedule->datep <= $datee
853  ) {
854  $total_ht_by_line -= $loanSchedule->amount_capital;
855  }
856  }
857  }
858  }
859  } else {
860  $total_ht_by_line = $element->total_ht;
861  }
862 
863  // Define $total_ttc_by_line
864  if ($tablename == 'don' || $tablename == 'chargesociales' || $tablename == 'payment_various' || $tablename == 'salary') {
865  $total_ttc_by_line = $element->amount;
866  } elseif ($tablename == 'fichinter') {
867  $total_ttc_by_line = $element->getAmount();
868  } elseif ($tablename == 'stock_mouvement') {
869  $total_ttc_by_line = $element->price * abs($element->qty);
870  } elseif ($tablename == 'projet_task') {
871  $defaultvat = get_default_tva($mysoc, $mysoc);
872  $total_ttc_by_line = price2num($total_ht_by_line * (1 + ($defaultvat / 100)), 'MT');
873  } elseif ($key == 'loan') {
874  $total_ttc_by_line = $total_ht_by_line; // For loan there is actually no taxe managed in Dolibarr
875  } else {
876  $total_ttc_by_line = $element->total_ttc;
877  }
878 
879  // Change sign of $total_ht_by_line and $total_ttc_by_line for some cases
880  if ($tablename == 'payment_various') {
881  if ($element->sens == 1) {
882  $total_ht_by_line = -$total_ht_by_line;
883  $total_ttc_by_line = -$total_ttc_by_line;
884  }
885  }
886 
887  // Add total if we have to
888  if ($qualifiedfortotal) {
889  $total_ht = $total_ht + $total_ht_by_line;
890  $total_ttc = $total_ttc + $total_ttc_by_line;
891  }
892  }
893 
894  // Each element with at least one line is output
895  $qualifiedforfinalprofit = true;
896  if ($key == 'intervention' && empty($conf->global->PROJECT_INCLUDE_INTERVENTION_AMOUNT_IN_PROFIT)) {
897  $qualifiedforfinalprofit = false;
898  }
899  //var_dump($key.' '.$qualifiedforfinalprofit);
900 
901  // Calculate margin
902  if ($qualifiedforfinalprofit) {
903  if ($margin == 'add') {
904  $total_revenue_ht += $total_ht;
905  }
906 
907  if ($margin != "add") { // Revert sign
908  $total_ht = -$total_ht;
909  $total_ttc = -$total_ttc;
910  }
911 
912  $balance_ht += $total_ht;
913  $balance_ttc += $total_ttc;
914  }
915 
916  print '<tr class="oddeven">';
917  // Module
918  print '<td class="left">'.$name.'</td>';
919  // Nb
920  print '<td class="right">'.$i.'</td>';
921  // Amount HT
922  print '<td class="right">';
923  if ($key == 'intervention' && !$qualifiedforfinalprofit) {
924  print '<span class="opacitymedium">'.$form->textwithpicto($langs->trans("NA"), $langs->trans("AmountOfInteventionNotIncludedByDefault")).'</span>';
925  } else {
926  print price($total_ht);
927  if ($key == 'propal') {
928  print '<span class="opacitymedium">'.$form->textwithpicto('', $langs->trans("SignedOnly")).'</span>';
929  }
930  }
931  print '</td>';
932  // Amount TTC
933  print '<td class="right">';
934  if ($key == 'intervention' && !$qualifiedforfinalprofit) {
935  print '<span class="opacitymedium">'.$form->textwithpicto($langs->trans("NA"), $langs->trans("AmountOfInteventionNotIncludedByDefault")).'</span>';
936  } else {
937  print price($total_ttc);
938  if ($key == 'propal') {
939  print '<span class="opacitymedium">'.$form->textwithpicto('', $langs->trans("SignedOnly")).'</span>';
940  }
941  }
942  print '</td>';
943  print '</tr>';
944  }
945  }
946 }
947 // and the final balance
948 print '<tr class="liste_total">';
949 print '<td class="right" colspan="2">'.$langs->trans("Profit").'</td>';
950 print '<td class="right">'.price(price2num($balance_ht, 'MT')).'</td>';
951 print '<td class="right">'.price(price2num($balance_ttc, 'MT')).'</td>';
952 print '</tr>';
953 
954 // and the margin (profit / revenues)
955 if ($total_revenue_ht) {
956  print '<tr class="liste_total">';
957  print '<td class="right" colspan="2">'.$langs->trans("Margin").'</td>';
958  print '<td class="right">'.round(100 * $balance_ht / $total_revenue_ht, 1).'%</td>';
959  print '<td class="right"></td>';
960  print '</tr>';
961 }
962 
963 print "</table>";
964 
965 
966 print '<br><br>';
967 print '<br>';
968 
969 
970 
971 // Detail
972 foreach ($listofreferent as $key => $value) {
973  $parameters = array(
974  'key' => $key,
975  'value' =>& $value,
976  'dates' => $dates,
977  'datee' => $datee
978  );
979  $reshook = $hookmanager->executeHooks('printOverviewDetail', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
980  if ($reshook < 0) {
981  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
982  } elseif ($reshook > 0) {
983  print $hookmanager->resPrint;
984  continue;
985  }
986 
987  $title = $value['title'];
988  $classname = $value['class'];
989  $tablename = $value['table'];
990  $datefieldname = $value['datefieldname'];
991  $qualified = $value['test'];
992  $langtoload = $value['lang'];
993  $urlnew = $value['urlnew'];
994  $buttonnew = $value['buttonnew'];
995  $testnew = $value['testnew'];
996  $project_field = $value['project_field'];
997 
998  $exclude_select_element = array('payment_various');
999  if (!empty($value['exclude_select_element'])) {
1000  $exclude_select_element[] = $value['exclude_select_element'];
1001  }
1002 
1003  if ($qualified) {
1004  // If we want the project task array to have details of users
1005  //if ($key == 'project_task') $key = 'project_task_time';
1006 
1007  if ($langtoload) {
1008  $langs->load($langtoload);
1009  }
1010 
1011  $element = new $classname($db);
1012 
1013  $addform = '';
1014 
1015  $idtofilterthirdparty = 0;
1016  $array_of_element_linkable_with_different_thirdparty = array('facture_fourn', 'commande_fournisseur');
1017  if (!in_array($tablename, $array_of_element_linkable_with_different_thirdparty)) {
1018  $idtofilterthirdparty = $object->thirdparty->id;
1019  if (!empty($conf->global->PROJECT_OTHER_THIRDPARTY_ID_TO_ADD_ELEMENTS)) {
1020  $idtofilterthirdparty .= ','.$conf->global->PROJECT_OTHER_THIRDPARTY_ID_TO_ADD_ELEMENTS;
1021  }
1022  }
1023 
1024  $elementarray = $object->get_element_list($key, $tablename, $datefieldname, $dates, $datee, !empty($project_field) ? $project_field : 'fk_projet');
1025 
1026 
1027  if (empty($conf->global->PROJECT_LINK_ON_OVERWIEW_DISABLED) && $idtofilterthirdparty && !in_array($tablename, $exclude_select_element)) {
1028  $selectList = $formproject->select_element($tablename, $idtofilterthirdparty, 'minwidth300 minwidth75imp', -2, empty($project_field) ? 'fk_projet' : $project_field, $langs->trans("SelectElement"));
1029  if ($selectList < 0) {
1030  setEventMessages($formproject->error, $formproject->errors, 'errors');
1031  } elseif ($selectList) {
1032  // Define form with the combo list of elements to link
1033  $addform .= '<div class="inline-block valignmiddle">';
1034  $addform .= '<form action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post">';
1035  $addform .= '<input type="hidden" name="token" value="'.newToken().'">';
1036  $addform .= '<input type="hidden" name="tablename" value="'.$tablename.'">';
1037  $addform .= '<input type="hidden" name="action" value="addelement">';
1038  $addform .= '<input type="hidden" name="datesrfc" value="'.dol_print_date($dates, 'dayhourrfc').'">';
1039  $addform .= '<input type="hidden" name="dateerfc" value="'.dol_print_date($datee, 'dayhourrfc').'">';
1040  $addform .= '<table><tr>';
1041  //$addform .= '<td><span class="hideonsmartphone opacitymedium">'.$langs->trans("SelectElement").'</span></td>';
1042  $addform .= '<td>'.$selectList.'</td>';
1043  $addform .= '<td><input type="submit" class="button button-linkto smallpaddingimp" value="'.dol_escape_htmltag($langs->trans("LinkToElementShort")).'"></td>';
1044  $addform .= '</tr></table>';
1045  $addform .= '</form>';
1046  $addform .= '</div>';
1047  }
1048  }
1049  if (empty($conf->global->PROJECT_CREATE_ON_OVERVIEW_DISABLED) && $urlnew) {
1050  $addform .= '<div class="inline-block valignmiddle">';
1051  if ($testnew) {
1052  $addform .= '<a class="buttonxxx marginleftonly" href="'.$urlnew.'" title="'.dol_escape_htmltag($langs->trans($buttonnew)).'"><span class="fa fa-plus-circle valignmiddle paddingleft"></span></a>';
1053  } elseif (empty($conf->global->MAIN_BUTTON_HIDE_UNAUTHORIZED)) {
1054  $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>';
1055  }
1056  $addform .= '<div>';
1057  }
1058 
1059  if (is_array($elementarray) && count($elementarray) > 0 && $key == "order_supplier") {
1060  $addform = '<div class="inline-block valignmiddle"><a id="btnShow" class="buttonxxx marginleftonly" href="#" onClick="return false;">
1061  <span id="textBtnShow" class="valignmiddle text-plus-circle hideonsmartphone">'.$langs->trans("CanceledShown").'</span><span id="minus-circle" class="fa fa-eye valignmiddle paddingleft"></span>
1062  </a>
1063  <script>
1064  $("#btnShow").on("click", function () {
1065  console.log("We click to show or hide the canceled lines");
1066  var attr = $(this).attr("data-canceledarehidden");
1067  if (typeof attr !== "undefined" && attr !== false) {
1068  console.log("Show canceled");
1069  $(".tr_canceled").show();
1070  $("#textBtnShow").text("'.dol_escape_js($langs->transnoentitiesnoconv("CanceledShown")).'");
1071  $("#btnShow").removeAttr("data-canceledarehidden");
1072  $("#minus-circle").removeClass("fa-eye-slash").addClass("fa-eye");
1073  } else {
1074  console.log("Hide canceled");
1075  $(".tr_canceled").hide();
1076  $("#textBtnShow").text("'.dol_escape_js($langs->transnoentitiesnoconv("CanceledHidden")).'");
1077  $("#btnShow").attr("data-canceledarehidden", 1);
1078  $("#minus-circle").removeClass("fa-eye").addClass("fa-eye-slash");
1079  }
1080  });
1081  </script></div> '.$addform;
1082  }
1083 
1084  print load_fiche_titre($langs->trans($title), $addform, '');
1085 
1086  print "\n".'<!-- Table for tablename = '.$tablename.' -->'."\n";
1087  print '<div class="div-table-responsive">';
1088  print '<table class="noborder centpercent">';
1089 
1090  print '<tr class="liste_titre">';
1091  // Remove link column
1092  print '<td style="width: 24px"></td>';
1093  // Ref
1094  print '<td'.(($tablename != 'actioncomm' && $tablename != 'projet_task') ? ' style="width: 200px"' : '').'>'.$langs->trans("Ref").'</td>';
1095  // Date
1096  print '<td'.(($tablename != 'actioncomm' && $tablename != 'projet_task') ? ' style="width: 200px"' : '').' class="center">';
1097  if (in_array($tablename, array('projet_task'))) {
1098  print $langs->trans("TimeSpent");
1099  }
1100  if (!in_array($tablename, array('projet_task'))) {
1101  print $langs->trans("Date");
1102  }
1103  print '</td>';
1104  // Thirdparty or user
1105  print '<td>';
1106  if (in_array($tablename, array('projet_task')) && $key == 'project_task') {
1107  print ''; // if $key == 'project_task', we don't want details per user
1108  } elseif (in_array($tablename, array('payment_various'))) {
1109  print ''; // if $key == 'payment_various', we don't have any thirdparty
1110  } elseif (in_array($tablename, array('expensereport_det', 'don', 'projet_task', 'stock_mouvement', 'salary'))) {
1111  print $langs->trans("User");
1112  } else {
1113  print $langs->trans("ThirdParty");
1114  }
1115  print '</td>';
1116  // Duration of intervention
1117  if ($tablename == 'fichinter') {
1118  print '<td>';
1119  print $langs->trans("TotalDuration");
1120  $total_duration = 0;
1121  print '</td>';
1122  }
1123  // Amount HT
1124  //if (empty($value['disableamount']) && ! in_array($tablename, array('projet_task'))) print '<td class="right" width="120">'.$langs->trans("AmountHT").'</td>';
1125  //elseif (empty($value['disableamount']) && in_array($tablename, array('projet_task'))) print '<td class="right" width="120">'.$langs->trans("Amount").'</td>';
1126  if ($key == 'loan') {
1127  print '<td class="right" width="120">'.$langs->trans("LoanCapital").'</td>';
1128  } elseif (empty($value['disableamount'])) {
1129  print '<td class="right" width="120">'.$langs->trans("AmountHT").'</td>';
1130  } else {
1131  print '<td width="120"></td>';
1132  }
1133  // Amount TTC
1134  //if (empty($value['disableamount']) && ! in_array($tablename, array('projet_task'))) print '<td class="right" width="120">'.$langs->trans("AmountTTC").'</td>';
1135  if ($key == 'loan') {
1136  print '<td class="right" width="120">'.$langs->trans("RemainderToPay").'</td>';
1137  } elseif (empty($value['disableamount'])) {
1138  print '<td class="right" width="120">'.$langs->trans("AmountTTC").'</td>';
1139  } else {
1140  print '<td width="120"></td>';
1141  }
1142  // Status
1143  if (in_array($tablename, array('projet_task'))) {
1144  print '<td class="right" width="200">'.$langs->trans("ProgressDeclared").'</td>';
1145  } else {
1146  print '<td class="right" width="200">'.$langs->trans("Status").'</td>';
1147  }
1148  print '</tr>';
1149 
1150  if (is_array($elementarray) && count($elementarray) > 0) {
1151  $total_ht = 0;
1152  $total_ttc = 0;
1153 
1154  $total_ht_by_third = 0;
1155  $total_ttc_by_third = 0;
1156 
1157  $saved_third_id = 0;
1158  $breakline = '';
1159 
1160  if (canApplySubtotalOn($tablename)) {
1161  // Sort
1162  $elementarray = sortElementsByClientName($elementarray);
1163  }
1164 
1165  $num = count($elementarray);
1166  for ($i = 0; $i < $num; $i++) {
1167  $tmp = explode('_', $elementarray[$i]);
1168  $idofelement = $tmp[0];
1169  $idofelementuser = $tmp[1];
1170 
1171  $element->fetch($idofelement);
1172  if ($idofelementuser) {
1173  $elementuser->fetch($idofelementuser);
1174  }
1175 
1176  // Special cases
1177  if ($tablename != 'expensereport_det') {
1178  if (method_exists($element, 'fetch_thirdparty')) {
1179  $element->fetch_thirdparty();
1180  }
1181  } else {
1182  $expensereport = new ExpenseReport($db);
1183  $expensereport->fetch($element->fk_expensereport);
1184  }
1185 
1186  //print 'xxx'.$tablename.'yyy'.$classname;
1187 
1188  if ($breakline && $saved_third_id != $element->thirdparty->id) {
1189  print $breakline;
1190 
1191  $saved_third_id = $element->thirdparty->id;
1192  $breakline = '';
1193 
1194  $total_ht_by_third = 0;
1195  $total_ttc_by_third = 0;
1196  }
1197  $saved_third_id = $element->thirdparty->id;
1198 
1199  $qualifiedfortotal = true;
1200  if ($key == 'invoice') {
1201  if (!empty($element->close_code) && $element->close_code == 'replaced') {
1202  $qualifiedfortotal = false; // Replacement invoice, do not include into total
1203  }
1204  } elseif ($key == 'order_supplier' && $element->status == 7) {
1205  $qualifiedfortotal = false; // It makes no sense to include canceled orders in the total
1206  }
1207 
1208  if ($key == "order_supplier" && $element->status == 7) {
1209  print '<tr class="oddeven tr_canceled" style=display:none>';
1210  } else {
1211  print '<tr class="oddeven" >';
1212  }
1213 
1214 
1215  // Remove link
1216  print '<td style="width: 24px">';
1217  if ($tablename != 'projet_task' && $tablename != 'stock_mouvement') {
1218  if (empty($conf->global->PROJECT_DISABLE_UNLINK_FROM_OVERVIEW) || $user->admin) { // PROJECT_DISABLE_UNLINK_FROM_OVERVIEW is empty by defaut, so this test true
1219  print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=unlink&tablename='.$tablename.'&elementselect='.$element->id.($project_field ? '&projectfield='.$project_field : '').'" class="reposition">';
1220  print img_picto($langs->trans('Unlink'), 'unlink');
1221  print '</a>';
1222  }
1223  }
1224  print "</td>\n";
1225 
1226  // Ref
1227  print '<td class="left nowraponall">';
1228  if ($tablename == 'expensereport_det') {
1229  print $expensereport->getNomUrl(1);
1230  } else {
1231  // Show ref with link
1232  if ($element instanceof Task) {
1233  print $element->getNomUrl(1, 'withproject', 'time');
1234  print ' - '.dol_trunc($element->label, 48);
1235  } elseif ($key == 'loan') {
1236  print $element->getNomUrl(1);
1237  print ' - '.dol_trunc($element->label, 48);
1238  } else {
1239  print $element->getNomUrl(1);
1240  }
1241 
1242  $element_doc = $element->element;
1243  $filename = dol_sanitizeFileName($element->ref);
1244  $filedir = $conf->{$element_doc}->multidir_output[$element->entity].'/'.dol_sanitizeFileName($element->ref);
1245 
1246  if ($element_doc === 'order_supplier') {
1247  $element_doc = 'commande_fournisseur';
1248  $filedir = $conf->fournisseur->commande->multidir_output[$element->entity].'/'.dol_sanitizeFileName($element->ref);
1249  } elseif ($element_doc === 'invoice_supplier') {
1250  $element_doc = 'facture_fournisseur';
1251  $filename = get_exdir($element->id, 2, 0, 0, $element, 'product').dol_sanitizeFileName($element->ref);
1252  $filedir = $conf->fournisseur->facture->multidir_output[$element->entity].'/'.get_exdir($element->id, 2, 0, 0, $element, 'invoice_supplier').dol_sanitizeFileName($element->ref);
1253  }
1254 
1255  print '<div class="inline-block valignmiddle">'.$formfile->getDocumentsLink($element_doc, $filename, $filedir).'</div>';
1256 
1257  // Show supplier ref
1258  if (!empty($element->ref_supplier)) {
1259  print ' - '.$element->ref_supplier;
1260  }
1261  // Show customer ref
1262  if (!empty($element->ref_customer)) {
1263  print ' - '.$element->ref_customer;
1264  }
1265  }
1266  print "</td>\n";
1267 
1268  // Date or TimeSpent
1269  $date = ''; $total_time_by_line = null;
1270  if ($tablename == 'expensereport_det') {
1271  $date = $element->date; // No draft status on lines
1272  } elseif ($tablename == 'stock_mouvement') {
1273  $date = $element->datem;
1274  } elseif ($tablename == 'salary') {
1275  $date = $element->datesp;
1276  } elseif ($tablename == 'payment_various') {
1277  $date = $element->datev;
1278  } elseif ($tablename == 'chargesociales') {
1279  $date = $element->date_ech;
1280  } elseif (!empty($element->status) || !empty($element->statut) || !empty($element->fk_status)) {
1281  if ($tablename == 'don') {
1282  $date = $element->datedon;
1283  }
1284  if ($tablename == 'commande_fournisseur' || $tablename == 'supplier_order') {
1285  $date = ($element->date_commande ? $element->date_commande : $element->date_valid);
1286  } elseif ($tablename == 'supplier_proposal') {
1287  $date = $element->date_validation; // There is no other date for this
1288  } elseif ($tablename == 'fichinter') {
1289  $date = $element->datev; // There is no other date for this
1290  } elseif ($tablename == 'projet_task') {
1291  $date = ''; // We show no date. Showing date of beginning of task make user think it is date of time consumed
1292  } else {
1293  $date = $element->date; // invoice, ...
1294  if (empty($date)) {
1295  $date = $element->date_contrat;
1296  }
1297  if (empty($date)) {
1298  $date = $element->datev;
1299  }
1300  if (empty($date) && !empty($datefieldname)) {
1301  $date = $element->$datefieldname;
1302  }
1303  }
1304  } elseif ($key == 'loan') {
1305  $date = $element->datestart;
1306  }
1307 
1308  print '<td class="center">';
1309  if ($tablename == 'actioncomm') {
1310  print dol_print_date($element->datep, 'dayhour');
1311  if ($element->datef && $element->datef > $element->datep) {
1312  print " - ".dol_print_date($element->datef, 'dayhour');
1313  }
1314  } elseif (in_array($tablename, array('projet_task'))) {
1315  $tmpprojtime = $element->getSumOfAmount($elementuser, $dates, $datee); // $element is a task. $elementuser may be empty
1316  print '<a href="'.DOL_URL_ROOT.'/projet/tasks/time.php?id='.$idofelement.'&withproject=1">';
1317  print convertSecondToTime($tmpprojtime['nbseconds'], 'allhourmin');
1318  print '</a>';
1319  $total_time_by_line = $tmpprojtime['nbseconds'];
1320  } else {
1321  print dol_print_date($date, 'day');
1322  }
1323  print '</td>';
1324 
1325  // Third party or user
1326  print '<td class="left">';
1327  if (is_object($element->thirdparty)) {
1328  print $element->thirdparty->getNomUrl(1, '', 48);
1329  } elseif ($tablename == 'expensereport_det') {
1330  $tmpuser = new User($db);
1331  $tmpuser->fetch($expensereport->fk_user_author);
1332  print $tmpuser->getNomUrl(1, '', 48);
1333  } elseif ($tablename == 'salary') {
1334  $tmpuser = new User($db);
1335  $tmpuser->fetch($element->fk_user);
1336  print $tmpuser->getNomUrl(1, '', 48);
1337  } elseif ($tablename == 'don' || $tablename == 'stock_mouvement') {
1338  if ($element->fk_user_author > 0) {
1339  $tmpuser2 = new User($db);
1340  $tmpuser2->fetch($element->fk_user_author);
1341  print $tmpuser2->getNomUrl(1, '', 48);
1342  }
1343  } elseif ($tablename == 'projet_task' && $key == 'project_task_time') { // if $key == 'project_task', we don't want details per user
1344  print $elementuser->getNomUrl(1);
1345  }
1346  print '</td>';
1347 
1348  // Add duration and store it in counter for fichinter
1349  if ($tablename == 'fichinter') {
1350  print '<td>';
1351  print convertSecondToTime($element->duration, 'all', $conf->global->MAIN_DURATION_OF_WORKDAY);
1352  $total_duration += $element->duration;
1353  print '</td>';
1354  }
1355 
1356  // Amount without tax
1357  $warning = '';
1358  if (empty($value['disableamount'])) {
1359  $total_ht_by_line = null;
1360  $othermessage = '';
1361  if ($tablename == 'don' || $tablename == 'chargesociales' || $tablename == 'payment_various' || $tablename == 'salary') {
1362  $total_ht_by_line = $element->amount;
1363  } elseif ($tablename == 'fichinter') {
1364  $total_ht_by_line = $element->getAmount();
1365  } elseif ($tablename == 'stock_mouvement') {
1366  $total_ht_by_line = $element->price * abs($element->qty);
1367  } elseif (in_array($tablename, array('projet_task'))) {
1368  if (!empty($conf->salaries->enabled)) {
1369  // TODO Permission to read daily rate to show value
1370  $total_ht_by_line = price2num($tmpprojtime['amount'], 'MT');
1371  if ($tmpprojtime['nblinesnull'] > 0) {
1372  $langs->load("errors");
1373  $warning = $langs->trans("WarningSomeLinesWithNullHourlyRate", $conf->currency);
1374  }
1375  } else {
1376  $othermessage = $form->textwithpicto($langs->trans("NotAvailable"), $langs->trans("ModuleSalaryToDefineHourlyRateMustBeEnabled"));
1377  }
1378  } elseif ($key == 'loan') {
1379  $total_ht_by_line = $element->capital;
1380  } else {
1381  $total_ht_by_line = $element->total_ht;
1382  }
1383 
1384  // Change sign of $total_ht_by_line and $total_ttc_by_line for some cases
1385  if ($tablename == 'payment_various') {
1386  if ($element->sens == 0) {
1387  $total_ht_by_line = -$total_ht_by_line;
1388  }
1389  }
1390 
1391  print '<td class="right">';
1392  if ($othermessage) {
1393  print $othermessage;
1394  }
1395  if (isset($total_ht_by_line)) {
1396  if (!$qualifiedfortotal) {
1397  print '<strike>';
1398  }
1399  print '<span class="amount">'.price($total_ht_by_line).'</span>';
1400  if (!$qualifiedfortotal) {
1401  print '</strike>';
1402  }
1403  }
1404  if ($warning) {
1405  print ' '.img_warning($warning);
1406  }
1407  print '</td>';
1408  } else {
1409  print '<td></td>';
1410  }
1411 
1412  // Amount inc tax
1413  if (empty($value['disableamount'])) {
1414  $total_ttc_by_line = null;
1415  if ($tablename == 'don' || $tablename == 'chargesociales' || $tablename == 'payment_various' || $tablename == 'salary') {
1416  $total_ttc_by_line = $element->amount;
1417  } elseif ($tablename == 'fichinter') {
1418  $total_ttc_by_line = $element->getAmount();
1419  } elseif ($tablename == 'stock_mouvement') {
1420  $total_ttc_by_line = $element->price * abs($element->qty);
1421  } elseif ($tablename == 'projet_task') {
1422  if (!empty($conf->salaries->enabled)) {
1423  // TODO Permission to read daily rate
1424  $defaultvat = get_default_tva($mysoc, $mysoc);
1425  $total_ttc_by_line = price2num($total_ht_by_line * (1 + ($defaultvat / 100)), 'MT');
1426  } else {
1427  $othermessage = $form->textwithpicto($langs->trans("NotAvailable"), $langs->trans("ModuleSalaryToDefineHourlyRateMustBeEnabled"));
1428  }
1429  } elseif ($key == 'loan') {
1430  $total_ttc_by_line = $element->capital - $element->getSumPayment();
1431  } else {
1432  $total_ttc_by_line = $element->total_ttc;
1433  }
1434 
1435  // Change sign of $total_ht_by_line and $total_ttc_by_line for some cases
1436  if ($tablename == 'payment_various') {
1437  if ($element->sens == 0) {
1438  $total_ttc_by_line = -$total_ttc_by_line;
1439  }
1440  }
1441 
1442  print '<td class="right">';
1443  if ($othermessage) {
1444  print $othermessage;
1445  }
1446  if (isset($total_ttc_by_line)) {
1447  if (!$qualifiedfortotal) {
1448  print '<strike>';
1449  }
1450  print '<span class="amount">'.price($total_ttc_by_line).'</span>';
1451  if (!$qualifiedfortotal) {
1452  print '</strike>';
1453  }
1454  }
1455  if ($warning) {
1456  print ' '.img_warning($warning);
1457  }
1458  print '</td>';
1459  } else {
1460  print '<td></td>';
1461  }
1462 
1463  // Status
1464  print '<td class="right">';
1465  if ($tablename == 'expensereport_det') {
1466  print $expensereport->getLibStatut(5);
1467  } elseif ($element instanceof CommonInvoice) {
1468  //This applies for Facture and FactureFournisseur
1469  print $element->getLibStatut(5, $element->getSommePaiement());
1470  } elseif ($element instanceof Task) {
1471  if ($element->progress != '') {
1472  print $element->progress.' %';
1473  }
1474  } elseif ($tablename == 'stock_mouvement') {
1475  print $element->getLibStatut(3);
1476  } else {
1477  print $element->getLibStatut(5);
1478  }
1479  print '</td>';
1480 
1481  print '</tr>';
1482 
1483  if ($qualifiedfortotal) {
1484  $total_ht = $total_ht + $total_ht_by_line;
1485  $total_ttc = $total_ttc + $total_ttc_by_line;
1486 
1487  $total_ht_by_third += $total_ht_by_line;
1488  $total_ttc_by_third += $total_ttc_by_line;
1489 
1490  $total_time = $total_time + $total_time_by_line;
1491  }
1492 
1493  if (canApplySubtotalOn($tablename)) {
1494  $breakline = '<tr class="liste_total liste_sub_total">';
1495  $breakline .= '<td colspan="2">';
1496  $breakline .= '</td>';
1497  $breakline .= '<td>';
1498  $breakline .= '</td>';
1499  $breakline .= '<td class="right">';
1500  $breakline .= $langs->trans('SubTotal').' : ';
1501  if (is_object($element->thirdparty)) {
1502  $breakline .= $element->thirdparty->getNomUrl(0, '', 48);
1503  }
1504  $breakline .= '</td>';
1505  $breakline .= '<td class="right">'.price($total_ht_by_third).'</td>';
1506  $breakline .= '<td class="right">'.price($total_ttc_by_third).'</td>';
1507  $breakline .= '<td></td>';
1508  $breakline .= '</tr>';
1509  }
1510 
1511  //var_dump($element->thirdparty->name.' - '.$saved_third_id.' - '.$element->thirdparty->id);
1512  }
1513 
1514  if ($breakline) {
1515  print $breakline;
1516  }
1517 
1518  // Total
1519  $colspan = 4;
1520  if (in_array($tablename, array('projet_task'))) {
1521  $colspan = 2;
1522  }
1523 
1524  print '<tr class="liste_total"><td colspan="'.$colspan.'">'.$langs->trans("Number").': '.$i.'</td>';
1525  if (in_array($tablename, array('projet_task'))) {
1526  print '<td class="center">';
1527  print convertSecondToTime($total_time, 'allhourmin');
1528  print '</td>';
1529  print '<td>';
1530  print '</td>';
1531  }
1532  //if (empty($value['disableamount']) && ! in_array($tablename, array('projet_task'))) print '<td class="right" width="100">'.$langs->trans("TotalHT").' : '.price($total_ht).'</td>';
1533  //elseif (empty($value['disableamount']) && in_array($tablename, array('projet_task'))) print '<td class="right" width="100">'.$langs->trans("Total").' : '.price($total_ht).'</td>';
1534  // If fichinter add the total_duration
1535  if ($tablename == 'fichinter') {
1536  print '<td class="left">'.convertSecondToTime($total_duration, 'all', $conf->global->MAIN_DURATION_OF_WORKDAY).'</td>';
1537  }
1538  print '<td class="right">';
1539  if (empty($value['disableamount'])) {
1540  if ($key == 'loan') {
1541  print $langs->trans("Total").' '.$langs->trans("LoanCapital").' : '.price($total_ttc);
1542  } elseif ($tablename != 'projet_task' || !empty($conf->salaries->enabled)) {
1543  print ''.$langs->trans("TotalHT").' : '.price($total_ht);
1544  }
1545  }
1546  print '</td>';
1547  //if (empty($value['disableamount']) && ! in_array($tablename, array('projet_task'))) print '<td class="right" width="100">'.$langs->trans("TotalTTC").' : '.price($total_ttc).'</td>';
1548  //elseif (empty($value['disableamount']) && in_array($tablename, array('projet_task'))) print '<td class="right" width="100"></td>';
1549  print '<td class="right">';
1550  if (empty($value['disableamount'])) {
1551  if ($key == 'loan') {
1552  print $langs->trans("Total").' '.$langs->trans("RemainderToPay").' : '.price($total_ttc);
1553  } elseif ($tablename != 'projet_task' || !empty($conf->salaries->enabled)) {
1554  print $langs->trans("TotalTTC").' : '.price($total_ttc);
1555  }
1556  }
1557  print '</td>';
1558  print '<td>&nbsp;</td>';
1559  print '</tr>';
1560  } else {
1561  if (!is_array($elementarray)) { // error
1562  print '<tr><td>'.$elementarray.'</td></tr>';
1563  } else {
1564  $colspan = 7;
1565  if (in_array($tablename, array('projet_task'))) {
1566  $colspan = 5;
1567  }
1568  if ($tablename == 'fichinter') {
1569  $colspan++;
1570  }
1571  print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("None").'</td></tr>';
1572  }
1573  }
1574  print "</table>";
1575  print '</div>';
1576  print "<br>\n";
1577  }
1578 }
1579 
1580 // Enhance with select2
1581 if ($conf->use_javascript_ajax) {
1582  include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
1583  $comboenhancement = ajax_combobox('.elementselect');
1584 
1585  print $comboenhancement;
1586 }
1587 
1588 // End of page
1589 llxFooter();
1590 $db->close();
1591 
1592 
1593 
1600 function canApplySubtotalOn($tablename)
1601 {
1602  global $conf;
1603 
1604  if (empty($conf->global->PROJECT_ADD_SUBTOTAL_LINES)) {
1605  return false;
1606  }
1607  return in_array($tablename, array('facture_fourn', 'commande_fournisseur'));
1608 }
1609 
1616 function sortElementsByClientName($elementarray)
1617 {
1618  global $db, $classname;
1619 
1620  $element = new $classname($db);
1621 
1622  $clientname = array();
1623  foreach ($elementarray as $key => $id) { // id = id of object
1624  if (empty($clientname[$id])) {
1625  $element->fetch($id);
1626  $element->fetch_thirdparty();
1627 
1628  $clientname[$id] = $element->thirdparty->name;
1629  }
1630  }
1631 
1632  //var_dump($clientname);
1633  asort($clientname); // sort on name
1634 
1635  $elementarray = array();
1636  foreach ($clientname as $id => $name) {
1637  $elementarray[] = $id;
1638  }
1639 
1640  return $elementarray;
1641 }
project_prepare_head(Project $project, $moreparam= '')
Prepare array with list of tabs.
Definition: project.lib.php:38
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
if($cancel &&!$id) if($action== 'add'&&!$cancel) if($action== 'delete') if($id) $form
Actions.
Definition: card.php:142
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...
sortElementsByClientName($elementarray)
sortElementsByClientName
Definition: element.php:1616
dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into javascript code.
dol_now($mode= 'auto')
Return date for now.
Class to manage Dolibarr users.
Definition: user.class.php:44
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
setEventMessage($mesgs, $style= 'mesgs')
Set event message in dol_events session object.
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_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
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...
dol_getIdFromCode($db, $key, $tablename, $fieldkey= 'code', $fieldid= 'id', $entityfilter=0, $filters= '')
Return an id or code from a code or id.
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
img_warning($titlealt= 'default', $moreatt= '', $morecss= 'pictowarning')
Show warning logo.
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...
Class to manage Schedule of loans.
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
Class to manage generation of HTML components Only common components must be here.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form...
Class to manage projects.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
const STATUS_BILLED
Billed or processed quote.
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is &#39;...
Class to manage building of HTML components.
const STATUS_SIGNED
Signed quote.
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it&#39;s its name (generic function)
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.
dol_sanitizeFileName($str, $newstr= '_', $unaccent=1)
Clean a string to use it as a file name.
Class to manage Trips and Expenses.
Class to offer components to list and upload files.
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:429
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.
Superclass for invoices classes.
const TYPE_DEPOSIT
Deposit invoice.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
Class to manage tasks.
Definition: task.class.php:37
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
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...
dol_get_fiche_end($notab=0)
Return tab footer of a card.
canApplySubtotalOn($tablename)
Return if we should do a group by customer with sub-total.
Definition: element.php:1600
isModEnabled($module)
Is Dolibarr module enabled.
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.
llxFooter()
Empty footer.
Definition: wrapper.php:73
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