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