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