dolibarr 25.0.0-alpha
productMargins.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2012-2013 Christophe Battarel <christophe.battarel@altairis.fr>
3 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
4 * Copyright (C) 2025-2026 MDW <mdeweerd@users.noreply.github.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
26// Load Dolibarr environment
27require '../../main.inc.php';
28require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
29require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
30require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
31
40$langs->loadLangs(array("companies", "bills", "products", "margins"));
41
42$id = GETPOSTINT('id');
43$ref = GETPOST('ref', 'alpha');
44$action = GETPOST('action', 'aZ09');
45$confirm = GETPOST('confirm', 'alpha');
46
47// Security check
48$fieldvalue = (!empty($id) ? $id : (!empty($ref) ? $ref : ''));
49$fieldtype = (!empty($ref) ? 'ref' : 'rowid');
50if (!empty($user->socid)) {
51 $socid = $user->socid;
52}
53
54$object = new Product($db);
55
56$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
57$sortfield = GETPOST('sortfield', 'aZ09comma');
58$sortorder = GETPOST('sortorder', 'aZ09comma');
59$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
60if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
61 // If $page is not defined, or '' or -1 or if we click on clear filters
62 $page = 0;
63}
64$offset = $limit * $page;
65$pageprev = $page - 1;
66$pagenext = $page + 1;
67if (!$sortorder) {
68 $sortorder = "DESC";
69}
70if (!$sortfield) {
71 $sortfield = "f.datef";
72}
73
74$hookmanager->initHooks(array('tabproductmarginlist'));
75
76$result = restrictedArea($user, 'produit|service', $fieldvalue, 'product&product', '', '', $fieldtype);
77
78if (!$user->hasRight('margins', 'liretous')) {
80}
81
82$search_invoice_date_start = '';
83$search_invoice_date_end = '';
84if (GETPOSTINT('search_invoice_date_start_month')) {
85 $search_invoice_date_start = dol_mktime(0, 0, 0, GETPOSTINT('search_invoice_date_start_month'), GETPOSTINT('search_invoice_date_start_day'), GETPOSTINT('search_invoice_date_start_year'));
86}
87if (GETPOSTINT('search_invoice_date_end_month')) {
88 $search_invoice_date_end = dol_mktime(23, 59, 59, GETPOSTINT('search_invoice_date_end_month'), GETPOSTINT('search_invoice_date_end_day'), GETPOSTINT('search_invoice_date_end_year'));
89}
90
91// Purge search criteria
92if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers
93 $search_invoice_date_start = '';
94 $search_invoice_date_end = '';
95}
96
97// set default dates from fiscal year
98if (empty($search_invoice_date_start) && empty($search_invoice_date_end) && !GETPOSTISSET('restore_lastsearch_values')) {
99 $query = "SELECT date_start, date_end";
100 $query .= " FROM ".MAIN_DB_PREFIX."accounting_fiscalyear";
101 $query .= " WHERE date_start < '".$db->idate(dol_now())."' and date_end > '".$db->idate(dol_now())."' limit 1";
102 $res = $db->query($query);
103
104 if ($res && $db->num_rows($res) > 0) {
105 $fiscalYear = $db->fetch_object($res);
106 $search_invoice_date_start = strtotime($fiscalYear->date_start);
107 $search_invoice_date_end = strtotime($fiscalYear->date_end);
108 } else {
109 $month_start = getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1);
110 $year_start = (int) dol_print_date(dol_now(), '%Y');
111 if (dol_print_date(dol_now(), '%m') < $month_start) {
112 $year_start--; // If current month is lower that starting fiscal month, we start last year
113 }
114 $year_end = $year_start + 1;
115 $month_end = $month_start - 1;
116 if ($month_end < 1) {
117 $month_end = 12;
118 $year_end--;
119 }
120 $search_invoice_date_start = dol_mktime(0, 0, 0, $month_start, 1, $year_start);
121 $search_invoice_date_end = dol_get_last_day($year_end, $month_end);
122 }
123}
124
125
126/*
127 * View
128 */
129
130$invoicestatic = new Facture($db);
131
132$form = new Form($db);
133$totalMargin = 0;
134$marginRate = '';
135$markRate = '';
136if ($id > 0 || !empty($ref)) {
137 $result = $object->fetch($id, $ref);
138
139 $title = $langs->trans('ProductServiceCard');
140 $help_url = '';
141 $shortlabel = dol_trunc($object->label, 16);
142 if (GETPOST("type") == '0' || ($object->type == Product::TYPE_PRODUCT)) {
143 $title = $langs->trans('Product')." ".$shortlabel." - ".$langs->trans('Card');
144 $help_url = 'EN:Module_Products|FR:Module_Produits|ES:M&oacute;dulo_Productos';
145 }
146 if (GETPOST("type") == '1' || ($object->type == Product::TYPE_SERVICE)) {
147 $title = $langs->trans('Service')." ".$shortlabel." - ".$langs->trans('Card');
148 $help_url = 'EN:Module_Services_En|FR:Module_Services|ES:M&oacute;dulo_Servicios';
149 }
150
151 llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-margin page-tabs_productmargins');
152
153 $param = "&id=".$object->id;
154 if ($limit > 0 && $limit != $conf->liste_limit) {
155 $param .= '&limit='.((int) $limit);
156 }
157 if ($search_invoice_date_start) {
158 $param .= '&search_invoice_date_start_day='.dol_print_date($search_invoice_date_start, '%d').'&search_invoice_date_start_month='.dol_print_date($search_invoice_date_start, '%m').'&search_invoice_date_start_year='.dol_print_date($search_invoice_date_start, '%Y');
159 }
160 if ($search_invoice_date_end) {
161 $param .= '&search_invoice_date_end_day='.dol_print_date($search_invoice_date_end, '%d').'&search_invoice_date_end_month='.dol_print_date($search_invoice_date_end, '%m').'&search_invoice_date_end_year='.dol_print_date($search_invoice_date_end, '%Y');
162 }
163
164 // View mode
165 if ($result > 0) {
166 $head = product_prepare_head($object);
167 $titre = $langs->trans("CardProduct".$object->type);
168 $picto = ($object->type == Product::TYPE_SERVICE ? 'service' : 'product');
169 print dol_get_fiche_head($head, 'margin', $titre, -1, $picto);
170
171 $linkback = '<a href="'.DOL_URL_ROOT.'/product/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
172 $object->next_prev_filter = "(te.fk_product_type:=:".((int) $object->type).")";
173
174 dol_banner_tab($object, 'ref', $linkback, ($user->socid ? 0 : 1), 'ref');
175
176
177 print '<div class="fichecenter">';
178
179 print '<div class="underbanner clearboth"></div>';
180 print '<table class="border tableforfield centpercent">';
181
182 // Total Margin
183 print '<tr><td class="titlefield">'.$langs->trans("TotalMargin").'</td><td>';
184 print '<span id="totalMargin" class="amount"></span>'; // set by jquery (see below)
185 print '</td></tr>';
186
187 // Margin Rate
188 if (getDolGlobalString('DISPLAY_MARGIN_RATES')) {
189 print '<tr><td>'.$langs->trans("MarginRate").'</td><td>';
190 print '<span id="marginRate"></span>'; // set by jquery (see below)
191 print '</td></tr>';
192 }
193
194 // Mark Rate
195 if (getDolGlobalString('DISPLAY_MARK_RATES')) {
196 print '<tr><td>'.$langs->trans("MarkRate").'</td><td>';
197 print '<span id="markRate"></span>'; // set by jquery (see below)
198 print '</td></tr>';
199 }
200
201 print "</table>";
202
203 print '</div>';
204 print '<div class="clearboth"></div>';
205
206 print dol_get_fiche_end();
207
208
209 if ($user->hasRight("facture", "read")) {
210 $sql = "SELECT s.nom as name, s.rowid as socid, s.code_client,";
211 $sql .= " f.rowid as facid, f.ref, f.total_ht,";
212 $sql .= " f.datef, f.paye, f.fk_statut as statut, f.type,";
213 if (!$user->hasRight('societe', 'client', 'voir')) {
214 $sql .= " sc.fk_soc, sc.fk_user,";
215 }
216 // Special case for old situation mode: total_ht is stored cumulatively, use delta percent to avoid cumulating margins
217 if (getDolGlobalInt('INVOICE_USE_SITUATION') == 1) {
218 $sql_delta_pct = 'CASE WHEN f.type = '.Facture::TYPE_SITUATION.' AND d.situation_percent > 0 THEN (d.situation_percent - COALESCE(prev_d.situation_percent, 0)) ELSE d.situation_percent END';
219 $sql_delta_ht = 'CASE WHEN f.type = '.Facture::TYPE_SITUATION.' AND d.situation_percent > 0 THEN d.total_ht * ((d.situation_percent - COALESCE(prev_d.situation_percent, 0)) / d.situation_percent) ELSE d.total_ht END';
220 $sql .= " sum($sql_delta_ht) as selling_price,"; // may be negative or positive
221 $sql .= " ".$db->ifsql('f.type = 2', '-1', '1')." * sum(d.qty) as qty,"; // not always positive in case of Credit note
222 $sql .= " ".$db->ifsql('f.type = 2', '-1', '1')." * sum(d.qty * d.buy_price_ht * ($sql_delta_pct / 100)) as buying_price,"; // not always positive in case of Credit note
223 $sql .= " ".$db->ifsql('f.type = 2', '-1', '1')." * sum(abs($sql_delta_ht) - (d.buy_price_ht * d.qty * ($sql_delta_pct / 100))) as marge"; // not always positive in case of Credit note
224 } else {
225 $sql .= " sum(d.total_ht) as selling_price,"; // may be negative or positive
226 $sql .= " ".$db->ifsql('f.type = 2', '-1', '1')." * sum(d.qty) as qty,"; // not always positive in case of Credit note
227 $sql .= " ".$db->ifsql('f.type = 2', '-1', '1')." * sum(d.qty * d.buy_price_ht * (d.situation_percent / 100)) as buying_price,"; // not always positive in case of Credit note
228 $sql .= " ".$db->ifsql('f.type = 2', '-1', '1')." * sum(abs(d.total_ht) - (d.buy_price_ht * d.qty * (d.situation_percent / 100))) as marge"; // not always positive in case of Credit note
229 }
230 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
231 $sql .= ", ".MAIN_DB_PREFIX."facture as f";
232 $sql .= ", ".MAIN_DB_PREFIX."facturedet as d";
233 if (getDolGlobalInt('INVOICE_USE_SITUATION') == 1) {
234 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facturedet AS prev_d ON prev_d.rowid = d.fk_prev_id";
235 }
236 if (!$user->hasRight('societe', 'client', 'voir')) {
237 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
238 }
239 $sql .= " WHERE f.fk_soc = s.rowid";
240 $sql .= " AND f.fk_statut > 0";
241 $sql .= " AND f.entity IN (".getEntity('invoice').")";
242 $sql .= " AND d.fk_facture = f.rowid";
243 $sql .= " AND d.fk_product = ".((int) $object->id);
244 if (!$user->hasRight('societe', 'client', 'voir')) {
245 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
246 }
247 if (!empty($socid)) {
248 $sql .= " AND f.fk_soc = ".((int) $socid);
249 }
250 $sql .= " AND d.buy_price_ht IS NOT NULL";
251 // We should not use this here. Option ForceBuyingPriceIfNull should have effect only when inserting data. Once data is recorded, it must be used as it is for report.
252 // We keep it with value ForceBuyingPriceIfNull = 2 for retroactive effect but results are unpredictable.
253 if (getDolGlobalInt('ForceBuyingPriceIfNull') == 2) {
254 $sql .= " AND d.buy_price_ht <> 0";
255 }
256 if (!empty($search_invoice_date_start)) {
257 $sql .= " AND f.datef >= '".$db->idate($search_invoice_date_start)."'";
258 }
259 if (!empty($search_invoice_date_end)) {
260 $sql .= " AND f.datef <= '".$db->idate($search_invoice_date_end)."'";
261 }
262 $sql .= " GROUP BY s.nom, s.rowid, s.code_client, f.rowid, f.ref, f.total_ht, f.datef, f.paye, f.fk_statut, f.type";
263 if (!$user->hasRight('societe', 'client', 'voir')) {
264 $sql .= ", sc.fk_soc, sc.fk_user";
265 }
266
267 // TODO: calculate total to display then restore pagination
268
269 $sql .= $db->order($sortfield, $sortorder);
270 if ($limit) {
271 $sql .= $db->plimit($limit + 1, $offset);
272 }
273 dol_syslog('margin:tabs:productMargins.php', LOG_DEBUG);
274 $result = $db->query($sql);
275 if ($result) {
276 $num = $db->num_rows($result);
277
278 print '<form method="post" action="'.$_SERVER ['PHP_SELF'].'?id='.$id.'" name="search_form">'."\n";
279 print '<input type="hidden" name="token" value="'.newToken().'">';
280 if (!empty($sortfield)) {
281 print '<input type="hidden" name="sortfield" value="'.$sortfield.'"/>';
282 }
283 if (!empty($sortorder)) {
284 print '<input type="hidden" name="sortorder" value="'.$sortorder.'"/>';
285 }
286
287 print_barre_liste($langs->trans("MarginDetails"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, '', '');
288
289 $moreforfilter = '';
290
291 $parameters = array();
292 $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
293 if (empty($reshook)) {
294 $moreforfilter .= $hookmanager->resPrint;
295 } else {
296 $moreforfilter = $hookmanager->resPrint;
297 }
298
299 if (!empty($moreforfilter)) {
300 print '<div class="liste_titre liste_titre_bydiv centpercent">';
301 print $moreforfilter;
302 print '</div>';
303 }
304
305 $selectedfields = '';
306
307 $i = 0;
308
309 print '<div class="div-table-responsive">';
310 print '<table class="noborder centpercent">';
311
312 // Fields title search
313 // --------------------------------------------------------------------
314 print '<tr class="liste_titre liste_titre_filter">';
315 // Action column
316 if ($conf->main_checkbox_left_column) {
317 print '<th class="liste_titre center maxwidthsearch">';
318 $searchpicto = $form->showFilterButtons('left');
319 print $searchpicto;
320 print '</th>';
321 }
322
323 // invoice ref
324 print '<th class="liste_titre">';
325 print '</th>';
326
327 // company name
328 print '<th class="liste_titre">';
329 print '</th>';
330
331 // customer code
332 print '<th class="liste_titre">';
333 print '</th>';
334
335 // invoice date
336 print '<th class="liste_titre center">';
337 print '<div class="nowrapfordate">';
338 print $form->selectDate($search_invoice_date_start ?: -1, 'search_invoice_date_start_', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
339 print '</div>';
340 print '<div class="nowrapfordate">';
341 print $form->selectDate($search_invoice_date_end ?: -1, 'search_invoice_date_end_', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
342 print '</div>';
343 print '</th>';
344
345 // selling price
346 print '<th class="liste_titre">';
347 print '</th>';
348
349 // buying price
350 print '<th class="liste_titre">';
351 print '</th>';
352
353 // qty
354 print '<th class="liste_titre">';
355 print '</th>';
356
357 // margin
358 print '<th class="liste_titre">';
359 print '</th>';
360
361 // margin rate
362 if (getDolGlobalString('DISPLAY_MARGIN_RATES')) {
363 print '<th class="liste_titre">';
364 print '</th>';
365 }
366
367 // mark rate
368 if (getDolGlobalString('DISPLAY_MARK_RATES')) {
369 print '<th class="liste_titre">';
370 print '</th>';
371 }
372
373 // status
374 print '<th class="liste_titre">';
375 print '</th>';
376
377 // Action column
378 if (!$conf->main_checkbox_left_column) {
379 print '<th class="liste_titre center maxwidthsearch">';
380 $searchpicto = $form->showFilterButtons();
381 print $searchpicto;
382 print '</th>';
383 }
384
385 print '</tr>'."\n";
386
387 print '<tr class="liste_titre">';
388 // Action column
389 if ($conf->main_checkbox_left_column) {
390 print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', $param, '', $sortfield, $sortorder, 'maxwidthsearch center ');
391 }
392 print_liste_field_titre("Invoice", $_SERVER["PHP_SELF"], "f.ref", "", $param, '', $sortfield, $sortorder);
393 print_liste_field_titre("Company", $_SERVER["PHP_SELF"], "s.nom", "", $param, '', $sortfield, $sortorder);
394 print_liste_field_titre("CustomerCode", $_SERVER["PHP_SELF"], "s.code_client", "", $param, '', $sortfield, $sortorder);
395 print_liste_field_titre("DateInvoice", $_SERVER["PHP_SELF"], "f.datef", "", $param, '', $sortfield, $sortorder, 'center ');
396 print_liste_field_titre("SellingPrice", $_SERVER["PHP_SELF"], "selling_price", "", $param, '', $sortfield, $sortorder, 'right ');
397 print_liste_field_titre("BuyingPrice", $_SERVER["PHP_SELF"], "buying_price", "", $param, '', $sortfield, $sortorder, 'right ');
398 print_liste_field_titre("Qty", $_SERVER["PHP_SELF"], "qty", "", $param, '', $sortfield, $sortorder, 'right ');
399 print_liste_field_titre("Margin", $_SERVER["PHP_SELF"], "marge", "", $param, '', $sortfield, $sortorder, 'right ');
400 if (getDolGlobalString('DISPLAY_MARGIN_RATES')) {
401 print_liste_field_titre("MarginRate", $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder, 'right ');
402 }
403 if (getDolGlobalString('DISPLAY_MARK_RATES')) {
404 print_liste_field_titre("MarkRate", $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder, 'right ');
405 }
406 print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "f.paye,f.fk_statut", "", $param, '', $sortfield, $sortorder, 'right ');
407 // Action column
408 if (!$conf->main_checkbox_left_column) {
409 print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', $param, '', $sortfield, $sortorder, 'maxwidthsearch center ');
410 }
411 print "</tr>\n";
412
413 $cumul_achat = 0;
414 $cumul_vente = 0;
415 $cumul_qty = 0;
416
417 if ($num > 0) {
418 $imaxinloop = ($limit ? min($num, $limit) : $num);
419 while ($i < $imaxinloop) {
420 $objp = $db->fetch_object($result);
421
422 $marginRate = ($objp->buying_price != 0) ? (100 * $objp->marge / $objp->buying_price) : '';
423 $markRate = ($objp->selling_price != 0) ? (100 * $objp->marge / $objp->selling_price) : '';
424
425 print '<tr class="oddeven">';
426 // Action column
427 if ($conf->main_checkbox_left_column) {
428 print '<td class="nowrap center">';
429 print '</td>';
430 }
431
432 print '<td>';
433 $invoicestatic->id = $objp->facid;
434 $invoicestatic->ref = $objp->ref;
435 print $invoicestatic->getNomUrl(1);
436 print "</td>\n";
437 print '<td><a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$objp->socid.'">'.img_object($langs->trans("ShowCompany"), "company").' '.dol_trunc($objp->name, 44).'</a></td>';
438 print "<td>".$objp->code_client."</td>\n";
439 print '<td class="center">';
440 print dol_print_date($db->jdate($objp->datef), 'day')."</td>";
441 print '<td class="right amount">'.price(price2num($objp->selling_price, 'MT'))."</td>\n";
442 print '<td class="right amount">'.price(price2num($objp->buying_price, 'MT'))."</td>\n";
443 print '<td class="right">'.price(price2num($objp->qty, 'MT'))."</td>\n";
444 print '<td class="right amount">'.price(price2num($objp->marge, 'MT'))."</td>\n";
445 if (getDolGlobalString('DISPLAY_MARGIN_RATES')) {
446 print "<td class=\"right\">".(($marginRate === '') ? 'n/a' : price(price2num($marginRate, 'MT'))."%")."</td>\n";
447 }
448 if (getDolGlobalString('DISPLAY_MARK_RATES')) {
449 print "<td class=\"right\">".(($markRate === '') ? 'n/a' : price(price2num($markRate, 'MT'))."%")."</td>\n";
450 }
451 print '<td class="right">'.$invoicestatic->LibStatut($objp->paye, $objp->statut, 5).'</td>';
452
453 // Action column
454 if (!$conf->main_checkbox_left_column) {
455 print '<td class="nowrap center">';
456 print '</td>';
457 }
458 print "</tr>\n";
459 $i++;
460 $cumul_achat += $objp->buying_price;
461 $cumul_vente += $objp->selling_price;
462 $cumul_qty += $objp->qty;
463 }
464 }
465
466 // affichage totaux marges
467
468 $totalMargin = $cumul_vente - $cumul_achat;
469 if ($totalMargin < 0) {
470 $marginRate = ($cumul_achat != 0) ? -1 * (100 * $totalMargin / $cumul_achat) : '';
471 $markRate = ($cumul_vente != 0) ? -1 * (100 * $totalMargin / $cumul_vente) : '';
472 } else {
473 $marginRate = ($cumul_achat != 0) ? (100 * $totalMargin / $cumul_achat) : '';
474 $markRate = ($cumul_vente != 0) ? (100 * $totalMargin / $cumul_vente) : '';
475 }
476 print '<tr class="liste_total">';
477 $colspan = 4;
478 if ($conf->main_checkbox_left_column) {
479 $colspan++; // add action column
480 }
481 print '<td colspan="'.$colspan.'">'.$langs->trans('TotalMargin')."</td>";
482 print '<td class="right amount">'.price(price2num($cumul_vente, 'MT'))."</td>\n";
483 print '<td class="right amount">'.price(price2num($cumul_achat, 'MT'))."</td>\n";
484 print '<td class="right">'.price(price2num($cumul_qty, 'MT'))."</td>\n";
485 print '<td class="right amount">'.price(price2num($totalMargin, 'MT'))."</td>\n";
486 if (getDolGlobalString('DISPLAY_MARGIN_RATES')) {
487 print '<td class="right">'.(($marginRate === '') ? 'n/a' : price(price2num($marginRate, 'MT'))."%")."</td>\n";
488 }
489 if (getDolGlobalString('DISPLAY_MARK_RATES')) {
490 print '<td class="right">'.(($markRate === '') ? 'n/a' : price(price2num($markRate, 'MT'))."%")."</td>\n";
491 }
492 print '<td class="right">&nbsp;</td>';
493 if (!$conf->main_checkbox_left_column) {
494 // add action column
495 print '<td class="center">';
496 print '</td>';
497 }
498 print "</tr>\n";
499 print "</table>";
500 print '</div>';
501 print '</form>';
502 } else {
504 }
505 $db->free($result);
506 }
507 }
508} else {
510}
511
512print '
513 <script type="text/javascript">
514 $(document).ready(function() {
515 $("#totalMargin").html("'. price(price2num($totalMargin, 'MT'), 1, $langs, 1, -1, -1, getDolCurrency()).'");
516 $("#marginRate").html("'.(($marginRate === '') ? 'n/a' : price(price2num($marginRate, 'MT'))."%").'");
517 $("#markRate").html("'.(($markRate === '') ? 'n/a' : price(price2num($markRate, 'MT'))."%").'");
518 });
519 </script>
520';
521
522// End of page
523llxFooter();
524$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
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:73
Class to manage invoices.
Class to manage generation of HTML components Only common components must be here.
Class to manage products or services.
const TYPE_PRODUCT
Regular product.
const TYPE_SERVICE
Service.
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition date.lib.php:624
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
dol_now($mode='gmt')
Return date for now.
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...
print_liste_field_titre($name, $file="", $field="", $begin="", $param="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
print_barre_liste($title, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $selectlimitsuffix=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
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.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
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.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
getDolCurrency()
Return the main currency ('EUR', 'USD', ...)
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '...' if string larger than length.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
product_prepare_head($object)
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.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.