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 $total_time = 0;
1197 for ($i = 0; $i < $num; $i++) {
1198 $tmp = explode('_', $elementarray[$i]);
1199 $idofelement = $tmp[0];
1200 $idofelementuser = isset($tmp[1]) ? $tmp[1] : "";
1201
1202 $element->fetch($idofelement);
1203 if ($idofelementuser) {
1204 $elementuser->fetch($idofelementuser);
1205 }
1206
1207 // Special cases
1208 if ($tablename != 'expensereport_det') {
1209 if (method_exists($element, 'fetch_thirdparty')) {
1210 $element->fetch_thirdparty();
1211 }
1212 } else {
1213 $expensereport = new ExpenseReport($db);
1214 $expensereport->fetch($element->fk_expensereport);
1215 }
1216
1217 //print 'xxx'.$tablename.'yyy'.$classname;
1218
1219 if ($breakline && $saved_third_id != $element->thirdparty->id) {
1220 print $breakline;
1221
1222 $saved_third_id = $element->thirdparty->id;
1223 $breakline = '';
1224
1225 $total_ht_by_third = 0;
1226 $total_ttc_by_third = 0;
1227 }
1228
1229 $saved_third_id = empty($element->thirdparty->id) ? 0 : $element->thirdparty->id;
1230
1231 $qualifiedfortotal = true;
1232 if ($key == 'invoice') {
1233 if (!empty($element->close_code) && $element->close_code == 'replaced') {
1234 $qualifiedfortotal = false; // Replacement invoice, do not include into total
1235 }
1236 } elseif ($key == 'order_supplier' && $element->status == 7) {
1237 $qualifiedfortotal = false; // It makes no sense to include canceled orders in the total
1238 }
1239
1240 if ($key == "order_supplier" && $element->status == 7) {
1241 print '<tr class="oddeven tr_canceled" style=display:none>';
1242 } else {
1243 print '<tr class="oddeven" >';
1244 }
1245
1246
1247 // Remove link
1248 print '<td style="width: 24px">';
1249 if ($tablename != 'projet_task' && $tablename != 'stock_mouvement') {
1250 if (empty($conf->global->PROJECT_DISABLE_UNLINK_FROM_OVERVIEW) || $user->admin) { // PROJECT_DISABLE_UNLINK_FROM_OVERVIEW is empty by defaut, so this test true
1251 print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=unlink&tablename='.$tablename.'&elementselect='.$element->id.($project_field ? '&projectfield='.$project_field : '').'" class="reposition">';
1252 print img_picto($langs->trans('Unlink'), 'unlink');
1253 print '</a>';
1254 }
1255 }
1256 print "</td>\n";
1257
1258 // Ref
1259 print '<td class="left nowraponall">';
1260 if ($tablename == 'expensereport_det') {
1261 print $expensereport->getNomUrl(1);
1262 } else {
1263 // Show ref with link
1264 if ($element instanceof Task) {
1265 print $element->getNomUrl(1, 'withproject', 'time');
1266 print ' - '.dol_trunc($element->label, 48);
1267 } elseif ($key == 'loan') {
1268 print $element->getNomUrl(1);
1269 print ' - '.dol_trunc($element->label, 48);
1270 } else {
1271 print $element->getNomUrl(1);
1272 }
1273
1274 $element_doc = $element->element;
1275 $filename = dol_sanitizeFileName($element->ref);
1276 if (!empty($conf->$element_doc)) {
1277 $confelementdoc = $conf->$element_doc;
1278 $filedir = $confelementdoc->multidir_output[$element->entity].'/'.dol_sanitizeFileName($element->ref);
1279 } else {
1280 $filedir = '';
1281 }
1282
1283 if ($element_doc === 'order_supplier') {
1284 $element_doc = 'commande_fournisseur';
1285 $filedir = $conf->fournisseur->commande->multidir_output[$element->entity].'/'.dol_sanitizeFileName($element->ref);
1286 } elseif ($element_doc === 'invoice_supplier') {
1287 $element_doc = 'facture_fournisseur';
1288 $filename = get_exdir($element->id, 2, 0, 0, $element, 'invoice_supplier').dol_sanitizeFileName($element->ref);
1289 $filedir = $conf->fournisseur->facture->multidir_output[$element->entity].'/'.$filename;
1290 }
1291
1292 print '<div class="inline-block valignmiddle">';
1293 if ($filedir) {
1294 print $formfile->getDocumentsLink($element_doc, $filename, $filedir);
1295 }
1296 print '</div>';
1297
1298 // Show supplier ref
1299 if (!empty($element->ref_supplier)) {
1300 print ' - '.$element->ref_supplier;
1301 }
1302 // Show customer ref
1303 if (!empty($element->ref_customer)) {
1304 print ' - '.$element->ref_customer;
1305 }
1306 // Compatibility propale
1307 if (empty($element->ref_customer) && !empty($element->ref_client)) {
1308 print ' - '.$element->ref_client;
1309 }
1310 }
1311 print "</td>\n";
1312
1313 // Date or TimeSpent
1314 $date = ''; $total_time_by_line = null;
1315 if ($tablename == 'expensereport_det') {
1316 $date = $element->date; // No draft status on lines
1317 } elseif ($tablename == 'stock_mouvement') {
1318 $date = $element->datem;
1319 } elseif ($tablename == 'salary') {
1320 $date = $element->datesp;
1321 } elseif ($tablename == 'payment_various') {
1322 $date = $element->datev;
1323 } elseif ($tablename == 'chargesociales') {
1324 $date = $element->date_ech;
1325 } elseif (!empty($element->status) || !empty($element->statut) || !empty($element->fk_status)) {
1326 if ($tablename == 'don') {
1327 $date = $element->datedon;
1328 }
1329 if ($tablename == 'commande_fournisseur' || $tablename == 'supplier_order') {
1330 $date = ($element->date_commande ? $element->date_commande : $element->date_valid);
1331 } elseif ($tablename == 'supplier_proposal') {
1332 $date = $element->date_validation; // There is no other date for this
1333 } elseif ($tablename == 'fichinter') {
1334 $date = $element->datev; // There is no other date for this
1335 } elseif ($tablename == 'projet_task') {
1336 $date = ''; // We show no date. Showing date of beginning of task make user think it is date of time consumed
1337 } else {
1338 $date = $element->date; // invoice, ...
1339 if (empty($date)) {
1340 $date = $element->date_contrat;
1341 }
1342 if (empty($date)) {
1343 $date = $element->datev;
1344 }
1345 if (empty($date) && !empty($datefieldname)) {
1346 $date = $element->$datefieldname;
1347 }
1348 }
1349 } elseif ($key == 'loan') {
1350 $date = $element->datestart;
1351 }
1352
1353 print '<td class="center">';
1354 if ($tablename == 'actioncomm') {
1355 print dol_print_date($element->datep, 'dayhour');
1356 if ($element->datef && $element->datef > $element->datep) {
1357 print " - ".dol_print_date($element->datef, 'dayhour');
1358 }
1359 } elseif (in_array($tablename, array('projet_task'))) {
1360 $tmpprojtime = $element->getSumOfAmount($elementuser, $dates, $datee); // $element is a task. $elementuser may be empty
1361 print '<a href="'.DOL_URL_ROOT.'/projet/tasks/time.php?id='.$idofelement.'&withproject=1">';
1362 print convertSecondToTime($tmpprojtime['nbseconds'], 'allhourmin');
1363 print '</a>';
1364 $total_time_by_line = $tmpprojtime['nbseconds'];
1365 } else {
1366 print dol_print_date($date, 'day');
1367 }
1368 print '</td>';
1369
1370 // Third party or user
1371 print '<td class="left">';
1372 if (is_object($element->thirdparty)) {
1373 print $element->thirdparty->getNomUrl(1, '', 48);
1374 } elseif ($tablename == 'expensereport_det') {
1375 $tmpuser = new User($db);
1376 $tmpuser->fetch($expensereport->fk_user_author);
1377 print $tmpuser->getNomUrl(1, '', 48);
1378 } elseif ($tablename == 'salary') {
1379 $tmpuser = new User($db);
1380 $tmpuser->fetch($element->fk_user);
1381 print $tmpuser->getNomUrl(1, '', 48);
1382 } elseif ($tablename == 'don' || $tablename == 'stock_mouvement') {
1383 if ($element->fk_user_author > 0) {
1384 $tmpuser2 = new User($db);
1385 $tmpuser2->fetch($element->fk_user_author);
1386 print $tmpuser2->getNomUrl(1, '', 48);
1387 }
1388 } elseif ($tablename == 'projet_task' && $key == 'element_time') { // if $key == 'project_task', we don't want details per user
1389 print $elementuser->getNomUrl(1);
1390 }
1391 print '</td>';
1392
1393 // Add duration and store it in counter for fichinter
1394 if ($tablename == 'fichinter') {
1395 print '<td>';
1396 print convertSecondToTime($element->duration, 'all', $conf->global->MAIN_DURATION_OF_WORKDAY);
1397 $total_duration += $element->duration;
1398 print '</td>';
1399 }
1400
1401 // Amount without tax
1402 $warning = '';
1403 if (empty($value['disableamount'])) {
1404 $total_ht_by_line = null;
1405 $othermessage = '';
1406 if ($tablename == 'don' || $tablename == 'chargesociales' || $tablename == 'payment_various' || $tablename == 'salary') {
1407 $total_ht_by_line = $element->amount;
1408 } elseif ($tablename == 'fichinter') {
1409 $total_ht_by_line = $element->getAmount();
1410 } elseif ($tablename == 'stock_mouvement') {
1411 $total_ht_by_line = $element->price * abs($element->qty);
1412 } elseif (in_array($tablename, array('projet_task'))) {
1413 if (isModEnabled('salaries')) {
1414 // TODO Permission to read daily rate to show value
1415 $total_ht_by_line = price2num($tmpprojtime['amount'], 'MT');
1416 if ($tmpprojtime['nblinesnull'] > 0) {
1417 $langs->load("errors");
1418 $warning = $langs->trans("WarningSomeLinesWithNullHourlyRate", $conf->currency);
1419 }
1420 } else {
1421 $othermessage = $form->textwithpicto($langs->trans("NotAvailable"), $langs->trans("ModuleSalaryToDefineHourlyRateMustBeEnabled"));
1422 }
1423 } elseif ($key == 'loan') {
1424 $total_ht_by_line = $element->capital;
1425 } else {
1426 $total_ht_by_line = $element->total_ht;
1427 }
1428
1429 // Change sign of $total_ht_by_line and $total_ttc_by_line for some cases
1430 if ($tablename == 'payment_various') {
1431 if ($element->sens == 0) {
1432 $total_ht_by_line = -$total_ht_by_line;
1433 }
1434 }
1435
1436 print '<td class="right">';
1437 if ($othermessage) {
1438 print $othermessage;
1439 }
1440 if (isset($total_ht_by_line)) {
1441 if (!$qualifiedfortotal) {
1442 print '<strike>';
1443 }
1444 print '<span class="amount">'.price($total_ht_by_line).'</span>';
1445 if (!$qualifiedfortotal) {
1446 print '</strike>';
1447 }
1448 }
1449 if ($warning) {
1450 print ' '.img_warning($warning);
1451 }
1452 print '</td>';
1453 } else {
1454 print '<td></td>';
1455 }
1456
1457 // Amount inc tax
1458 if (empty($value['disableamount'])) {
1459 $total_ttc_by_line = null;
1460 if ($tablename == 'don' || $tablename == 'chargesociales' || $tablename == 'payment_various' || $tablename == 'salary') {
1461 $total_ttc_by_line = $element->amount;
1462 } elseif ($tablename == 'fichinter') {
1463 $total_ttc_by_line = $element->getAmount();
1464 } elseif ($tablename == 'stock_mouvement') {
1465 $total_ttc_by_line = $element->price * abs($element->qty);
1466 } elseif ($tablename == 'projet_task') {
1467 if (isModEnabled('salaries')) {
1468 // TODO Permission to read daily rate
1469 $defaultvat = get_default_tva($mysoc, $mysoc);
1470 $total_ttc_by_line = price2num($total_ht_by_line * (1 + ($defaultvat / 100)), 'MT');
1471 } else {
1472 $othermessage = $form->textwithpicto($langs->trans("NotAvailable"), $langs->trans("ModuleSalaryToDefineHourlyRateMustBeEnabled"));
1473 }
1474 } elseif ($key == 'loan') {
1475 $total_ttc_by_line = $element->capital - $element->getSumPayment();
1476 } else {
1477 $total_ttc_by_line = $element->total_ttc;
1478 }
1479
1480 // Change sign of $total_ht_by_line and $total_ttc_by_line for some cases
1481 if ($tablename == 'payment_various') {
1482 if ($element->sens == 0) {
1483 $total_ttc_by_line = -$total_ttc_by_line;
1484 }
1485 }
1486
1487 print '<td class="right">';
1488 if ($othermessage) {
1489 print $othermessage;
1490 }
1491 if (isset($total_ttc_by_line)) {
1492 if (!$qualifiedfortotal) {
1493 print '<strike>';
1494 }
1495 print '<span class="amount">'.price($total_ttc_by_line).'</span>';
1496 if (!$qualifiedfortotal) {
1497 print '</strike>';
1498 }
1499 }
1500 if ($warning) {
1501 print ' '.img_warning($warning);
1502 }
1503 print '</td>';
1504 } else {
1505 print '<td></td>';
1506 }
1507
1508 // Status
1509 print '<td class="right">';
1510 if ($tablename == 'expensereport_det') {
1511 print $expensereport->getLibStatut(5);
1512 } elseif ($element instanceof CommonInvoice) {
1513 //This applies for Facture and FactureFournisseur
1514 print $element->getLibStatut(5, $element->getSommePaiement());
1515 } elseif ($element instanceof Task) {
1516 if ($element->progress != '') {
1517 print $element->progress.' %';
1518 }
1519 } elseif ($tablename == 'stock_mouvement') {
1520 print $element->getLibStatut(3);
1521 } else {
1522 print $element->getLibStatut(5);
1523 }
1524 print '</td>';
1525
1526 print '</tr>';
1527
1528 if ($qualifiedfortotal) {
1529 $total_ht = $total_ht + $total_ht_by_line;
1530 $total_ttc = $total_ttc + $total_ttc_by_line;
1531
1532 $total_ht_by_third += $total_ht_by_line;
1533 $total_ttc_by_third += $total_ttc_by_line;
1534
1535 if (!isset($total_time)) $total_time = $total_time_by_line;
1536 else $total_time += $total_time_by_line;
1537 }
1538
1539 if (canApplySubtotalOn($tablename)) {
1540 $breakline = '<tr class="liste_total liste_sub_total">';
1541 $breakline .= '<td colspan="2">';
1542 $breakline .= '</td>';
1543 $breakline .= '<td>';
1544 $breakline .= '</td>';
1545 $breakline .= '<td class="right">';
1546 $breakline .= $langs->trans('SubTotal').' : ';
1547 if (is_object($element->thirdparty)) {
1548 $breakline .= $element->thirdparty->getNomUrl(0, '', 48);
1549 }
1550 $breakline .= '</td>';
1551 $breakline .= '<td class="right">'.price($total_ht_by_third).'</td>';
1552 $breakline .= '<td class="right">'.price($total_ttc_by_third).'</td>';
1553 $breakline .= '<td></td>';
1554 $breakline .= '</tr>';
1555 }
1556
1557 //var_dump($element->thirdparty->name.' - '.$saved_third_id.' - '.$element->thirdparty->id);
1558 }
1559
1560 if ($breakline) {
1561 print $breakline;
1562 }
1563
1564 // Total
1565 if (empty($nototal)) {
1566 $colspan = 4;
1567 if (in_array($tablename, array('projet_task'))) {
1568 $colspan = 2;
1569 }
1570
1571 print '<tr class="liste_total"><td colspan="'.$colspan.'">'.$langs->trans("Number").': '.$i.'</td>';
1572 if (in_array($tablename, array('projet_task'))) {
1573 print '<td class="center">';
1574 print convertSecondToTime($total_time, 'allhourmin');
1575 print '</td>';
1576 print '<td>';
1577 print '</td>';
1578 }
1579 //if (empty($value['disableamount']) && ! in_array($tablename, array('projet_task'))) print '<td class="right" width="100">'.$langs->trans("TotalHT").' : '.price($total_ht).'</td>';
1580 //elseif (empty($value['disableamount']) && in_array($tablename, array('projet_task'))) print '<td class="right" width="100">'.$langs->trans("Total").' : '.price($total_ht).'</td>';
1581 // If fichinter add the total_duration
1582 if ($tablename == 'fichinter') {
1583 print '<td class="left">'.convertSecondToTime($total_duration, 'all', $conf->global->MAIN_DURATION_OF_WORKDAY).'</td>';
1584 }
1585 print '<td class="right">';
1586 if (empty($value['disableamount'])) {
1587 if ($key == 'loan') {
1588 print $langs->trans("Total").' '.$langs->trans("LoanCapital").' : '.price($total_ttc);
1589 } elseif ($tablename != 'projet_task' || isModEnabled('salaries')) {
1590 print ''.$langs->trans("TotalHT").' : '.price($total_ht);
1591 }
1592 }
1593 print '</td>';
1594 //if (empty($value['disableamount']) && ! in_array($tablename, array('projet_task'))) print '<td class="right" width="100">'.$langs->trans("TotalTTC").' : '.price($total_ttc).'</td>';
1595 //elseif (empty($value['disableamount']) && in_array($tablename, array('projet_task'))) print '<td class="right" width="100"></td>';
1596 print '<td class="right">';
1597 if (empty($value['disableamount'])) {
1598 if ($key == 'loan') {
1599 print $langs->trans("Total").' '.$langs->trans("RemainderToPay").' : '.price($total_ttc);
1600 } elseif ($tablename != 'projet_task' || isModEnabled('salaries')) {
1601 print $langs->trans("TotalTTC").' : '.price($total_ttc);
1602 }
1603 }
1604 print '</td>';
1605 print '<td>&nbsp;</td>';
1606 print '</tr>';
1607 }
1608 } else {
1609 if (!is_array($elementarray)) { // error
1610 print '<tr><td>'.$elementarray.'</td></tr>';
1611 } else {
1612 $colspan = 7;
1613 if (in_array($tablename, array('projet_task'))) {
1614 $colspan = 5;
1615 }
1616 if ($tablename == 'fichinter') {
1617 $colspan++;
1618 }
1619 print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("None").'</td></tr>';
1620 }
1621 }
1622 print "</table>";
1623 print '</div>';
1624 print "<br>\n";
1625 }
1626}
1627
1628// Enhance with select2
1629if ($conf->use_javascript_ajax) {
1630 include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
1631 $comboenhancement = ajax_combobox('.elementselect');
1632
1633 print $comboenhancement;
1634}
1635
1636// End of page
1637llxFooter();
1638$db->close();
1639
1640
1641
1648function canApplySubtotalOn($tablename)
1649{
1650 global $conf;
1651
1652 if (empty($conf->global->PROJECT_ADD_SUBTOTAL_LINES)) {
1653 return false;
1654 }
1655 return in_array($tablename, array('facture_fourn', 'commande_fournisseur'));
1656}
1657
1664function sortElementsByClientName($elementarray)
1665{
1666 global $db, $classname;
1667
1668 $element = new $classname($db);
1669
1670 $clientname = array();
1671 foreach ($elementarray as $key => $id) { // id = id of object
1672 if (empty($clientname[$id])) {
1673 $element->fetch($id);
1674 $element->fetch_thirdparty();
1675
1676 $clientname[$id] = $element->thirdparty->name;
1677 }
1678 }
1679
1680 //var_dump($clientname);
1681 asort($clientname); // sort on name
1682
1683 $elementarray = array();
1684 foreach ($clientname as $id => $name) {
1685 $elementarray[] = $id;
1686 }
1687
1688 return $elementarray;
1689}
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:1664
canApplySubtotalOn($tablename)
Return if we should do a group by customer with sub-total.
Definition element.php:1648
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.