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