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