dolibarr 24.0.0-beta
price.lib.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2002-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2006-2008 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2010-2013 Juanjo Menent <jmenent@2byte.es>
5 * Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr>
6 * Copyright (C) 2012 Cédric Salvador <csalvador@gpcsolutions.fr>
7 * Copyright (C) 2012-2014 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
8 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
9 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <https://www.gnu.org/licenses/>.
23 */
24
90function calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $uselocaltax1_rate, $uselocaltax2_rate, $remise_percent_global, $price_base_type, $info_bits, $type, $seller = null, $localtaxes_array = [], $progress = 100, $multicurrency_tx = 1, $pu_devise = 0, $multicurrency_code = '') // @phpstan-ignore-line
91{
92 global $conf, $mysoc, $db, $hookmanager;
93
94 $result = array();
95
96 // Clean parameters
97 if (empty($info_bits)) {
98 $info_bits = 0;
99 }
100 if (empty($txtva)) {
101 $txtva = 0;
102 }
103 if (empty($seller) || !is_object($seller)) {
104 dol_syslog("Price.lib::calcul_price_total Warning: function is called with parameter seller that is missing", LOG_WARNING);
105 if (!is_object($mysoc)) { // mysoc may be not defined (during migration process)
106 $mysoc = new Societe($db);
107 $mysoc->setMysoc($conf);
108 }
109 $seller = $mysoc; // If sell is done to a customer, $seller is not provided, we use $mysoc
110 //var_dump($seller->country_id);exit;
111 }
112 if (empty($localtaxes_array) || !is_array($localtaxes_array)) {
113 dol_syslog("Price.lib::calcul_price_total Warning: function is called with parameter localtaxes_array that is missing or empty", LOG_WARNING);
114 }
115 if (!is_numeric($txtva)) {
116 dol_syslog("Price.lib::calcul_price_total Warning: function was called with a parameter vat rate that is not a real numeric value. There is surely a bug.", LOG_ERR);
117 } elseif ($txtva >= 1000) {
118 dol_syslog("Price.lib::calcul_price_total Warning: function was called with a bad value for vat rate (should be often < 100, always < 1000). There is surely a bug.", LOG_ERR);
119 }
120 // Too verbose. Enable for debug only
121 // dol_syslog("Price.lib::calcul_price_total qty=".$qty." pu=".$pu." remiserpercent_ligne=".$remise_percent_ligne." txtva=".$txtva." uselocaltax1_rate=".$uselocaltax1_rate." uselocaltax2_rate=".$uselocaltax2_rate.' remise_percent_global='.$remise_percent_global.' price_base_type='.$ice_base_type.' type='.$type.' progress='.$progress);
122
123 $countryid = $seller->country_id;
124
125 if (is_numeric($uselocaltax1_rate)) {
126 $uselocaltax1_rate = (float) $uselocaltax1_rate;
127 }
128 if (is_numeric($uselocaltax2_rate)) {
129 $uselocaltax2_rate = (float) $uselocaltax2_rate;
130 }
131
132 if ($uselocaltax1_rate < 0) {
133 $uselocaltax1_rate = $seller->localtax1_assuj;
134 }
135 if ($uselocaltax2_rate < 0) {
136 $uselocaltax2_rate = $seller->localtax2_assuj;
137 }
138
139 //var_dump($uselocaltax1_rate.' - '.$uselocaltax2_rate);
140 dol_syslog('Price.lib::calcul_price_total qty='.$qty.' pu='.$pu.' remise_percent_ligne='.$remise_percent_ligne.' txtva='.$txtva.' uselocaltax1_rate='.$uselocaltax1_rate.' uselocaltax2_rate='.$uselocaltax2_rate.' remise_percent_global='.$remise_percent_global.' price_base_type='.$price_base_type.' type='.$type.' progress='.$progress);
141
142 // Now we search localtaxes information ourself (rates and types).
143 $localtax1_type = 0;
144 $localtax2_type = 0;
145 $localtax1_rate = 1000; // For static analysis, exaggerated value to help detect bugs
146 $localtax2_rate = 1000; // For static analysis, exaggerated value to help detect bugs
147
148 if (is_array($localtaxes_array) && count($localtaxes_array)) {
149 $localtax1_type = $localtaxes_array[0];
150 $localtax1_rate = $localtaxes_array[1];
151 $localtax2_type = $localtaxes_array[2];
152 $localtax2_rate = $localtaxes_array[3];
153 } else {
154 // deprecated method. values and type for localtaxes must be provided by caller and loaded with getLocalTaxesFromRate using the full vat rate (including text code)
155 // also, with this method, we may get several possible values (for example with localtax2 in spain), so we take the first one.
156 dol_syslog("Price.lib::calcul_price_total search vat information using old deprecated method", LOG_WARNING);
157
158 $sql = "SELECT taux, localtax1, localtax2, localtax1_type, localtax2_type";
159 $sql .= " FROM ".MAIN_DB_PREFIX."c_tva as cv";
160 $sql .= " WHERE cv.taux = ".((float) $txtva);
161 $sql .= " AND cv.fk_pays = ".((int) $countryid);
162 $sql .= " AND cv.entity IN (".getEntity('c_tva').")";
163 $resql = $db->query($sql);
164 if ($resql) {
165 $obj = $db->fetch_object($resql);
166 if ($obj) {
167 $localtax1_rate = (float) $obj->localtax1; // Use float to force to get first numeric value when value is x:y:z
168 $localtax2_rate = (float) $obj->localtax2; // Use float to force to get first numeric value when value is -19:-15:-9
169 $localtax1_type = $obj->localtax1_type;
170 $localtax2_type = $obj->localtax2_type;
171 //var_dump($localtax1_rate.' '.$localtax2_rate.' '.$localtax1_type.' '.$localtax2_type);
172 }
173 } else {
175 }
176 }
177
178 // pu calculation from pu_devise if pu empty
179 if (empty($pu) && !empty($pu_devise)) {
180 if (!empty($multicurrency_tx)) {
181 $pu = $pu_devise / $multicurrency_tx;
182 } else {
183 dol_syslog('Price.lib::calcul_price_total function called with bad parameters combination (multicurrency_tx empty when pu_devise not) ', LOG_ERR);
184 return array();
185 }
186 }
187 if ($pu === '') {
188 $pu = 0;
189 }
190 // pu_devise calculation from pu
191 if (empty($pu_devise) && !empty($multicurrency_tx)) {
192 if (is_numeric($pu) && is_numeric($multicurrency_tx)) {
193 $pu_devise = $pu * $multicurrency_tx;
194 } else {
195 dol_syslog('Price.lib::calcul_price_total function called with bad parameters combination (pu or multicurrency_tx are not numeric)', LOG_ERR);
196 return array();
197 }
198 }
199
200 // Initialize total (may be HT or TTC depending on price_base_type)
201 // Note: For einvoice, we may need to have MAIN_APPLY_DISCOUNT_ON_UNIT_PRICE_THEN_ROUND_BEFORE_MULTIPLICATION_BY_QTY = 'MU' because, we must recalculate
202 // amounts using this rule when building a XML file.
203 if ($remise_percent_ligne && getDolGlobalString('MAIN_APPLY_DISCOUNT_ON_UNIT_PRICE_THEN_ROUND_BEFORE_MULTIPLICATION_BY_QTY')) { // MAIN_APPLY_DISCOUNT_ON_UNIT_PRICE_THEN_ROUND_BEFORE_MULTIPLICATION_BY_QTY can be 'MU', 2, ...
204 $tot_sans_remise = $pu * $qty * ($progress / 100);
205 $pudiscount = (float) price2num($pu * ((float) $remise_percent_ligne / 100), getDolGlobalString('MAIN_APPLY_DISCOUNT_ON_UNIT_PRICE_THEN_ROUND_BEFORE_MULTIPLICATION_BY_QTY'));
206 $tot_avec_remise_ligne = (float) price2num($pu - $pudiscount, getDolGlobalString('MAIN_APPLY_DISCOUNT_ON_UNIT_PRICE_THEN_ROUND_BEFORE_MULTIPLICATION_BY_QTY')) * $qty * ($progress / 100);
207 } else {
208 $tot_sans_remise = $pu * $qty * ($progress / 100);
209 $tot_avec_remise_ligne = $tot_sans_remise * (1 - ((float) $remise_percent_ligne / 100));
210 }
211 $tot_avec_remise = $tot_avec_remise_ligne * (1 - ((float) $remise_percent_global / 100));
212
213 // initialize result array
214 for ($i = 0; $i <= 15; $i++) {
215 $result[$i] = 0;
216 }
217
218 // if there's some localtax including vat, we calculate localtaxes (we will add later)
219
220 // if input unit price is 'HT', we need to have the totals with main VAT for a correct calculation
221 if ($price_base_type != 'TTC') {
222 $tot_sans_remise_withvat = price2num($tot_sans_remise * (1 + ($txtva / 100)), 'MU');
223 $tot_avec_remise_withvat = price2num($tot_avec_remise * (1 + ($txtva / 100)), 'MU');
224
225 $tot_sans_remise_withoutvat = $tot_sans_remise;
226 $tot_avec_remise_withoutvat = $tot_avec_remise;
227
228 $pu_withouttax = $pu;
229 $pu_withmainvat = price2num($pu * (1 + ($txtva / 100)), 'MU');
230 } else {
231 $tot_sans_remise_withvat = $tot_sans_remise;
232 $tot_avec_remise_withvat = $tot_avec_remise;
233
234 $tot_sans_remise_withoutvat = price2num($tot_sans_remise / (1 + ($txtva / 100)), 'MU');
235 $tot_avec_remise_withoutvat = price2num($tot_avec_remise / (1 + ($txtva / 100)), 'MU');
236
237 $pu_withouttax = price2num($pu / (1 + ($txtva / 100)), 'MU');
238 $pu_withmainvat = $pu;
239 }
240
241 //print 'rr'.$price_base_type.'-'.$txtva.'-'.$tot_sans_remise_withvat."-".$pu_withmainvat."-".$uselocaltax1_rate."-".$localtax1_rate."-".$localtax1_type."\n";
242
243 $localtaxes = array(0, 0, 0);
244 $apply_tax = false;
245 switch ($localtax1_type) {
246 case '2': // localtax on product or service
247 $apply_tax = true;
248 break;
249 case '4': // localtax on product
250 if ($type == 0) {
251 $apply_tax = true;
252 }
253 break;
254 case '6': // localtax on service
255 if ($type == 1) {
256 $apply_tax = true;
257 }
258 break;
259 }
260
261 if ($uselocaltax1_rate && $apply_tax) {
262 $result[14] = price2num(($tot_sans_remise_withvat * (1 + ($localtax1_rate / 100))) - $tot_sans_remise_withvat, 'MT');
263 $localtaxes[0] += $result[14];
264
265 $result[9] = price2num(($tot_avec_remise_withvat * (1 + ($localtax1_rate / 100))) - $tot_avec_remise_withvat, 'MT');
266 $localtaxes[1] += $result[9];
267
268 $result[11] = price2num(($pu_withmainvat * (1 + ($localtax1_rate / 100))) - $pu_withmainvat, 'MU');
269 $localtaxes[2] += $result[11];
270 }
271
272 $apply_tax = false;
273 switch ($localtax2_type) {
274 case '2': // localtax on product or service
275 $apply_tax = true;
276 break;
277 case '4': // localtax on product
278 if ($type == 0) {
279 $apply_tax = true;
280 }
281 break;
282 case '6': // localtax on service
283 if ($type == 1) {
284 $apply_tax = true;
285 }
286 break;
287 }
288 if ($uselocaltax2_rate && $apply_tax) {
289 $result[15] = price2num(($tot_sans_remise_withvat * (1 + ($localtax2_rate / 100))) - $tot_sans_remise_withvat, 'MT');
290 $localtaxes[0] += $result[15];
291
292 $result[10] = price2num(($tot_avec_remise_withvat * (1 + ($localtax2_rate / 100))) - $tot_avec_remise_withvat, 'MT');
293 $localtaxes[1] += $result[10];
294
295 $result[12] = price2num(($pu_withmainvat * (1 + ($localtax2_rate / 100))) - $pu_withmainvat, 'MU');
296 $localtaxes[2] += $result[12];
297 }
298
299 //dol_syslog("price.lib::calcul_price_total $qty, $pu, $remise_percent_ligne, $txtva, $price_base_type $info_bits");
300 if ($price_base_type != 'TTC') {
301 // We work to define prices using the price without tax
302 $result[6] = price2num($tot_sans_remise, 'MT');
303 $result[8] = price2num($tot_sans_remise * (1 + ((($info_bits & 1) ? 0 : $txtva) / 100)) + $localtaxes[0], 'MT'); // Selon TVA NPR ou non
304 $result8bis = price2num($tot_sans_remise * (1 + ($txtva / 100)) + $localtaxes[0], 'MT'); // Si TVA consideree normal (non NPR)
305 $result[7] = price2num((float) $result8bis - ((float) $result[6] + $localtaxes[0]), 'MT');
306
307 $result[0] = price2num($tot_avec_remise, 'MT');
308 $result[2] = price2num($tot_avec_remise * (1 + ((($info_bits & 1) ? 0 : $txtva) / 100)) + $localtaxes[1], 'MT'); // Selon TVA NPR ou non
309 $result2bis = price2num($tot_avec_remise * (1 + ($txtva / 100)) + $localtaxes[1], 'MT'); // Si TVA consideree normal (non NPR)
310 $result[1] = price2num((float) $result2bis - ((float) $result[0] + $localtaxes[1]), 'MT'); // Total VAT = TTC - (HT + localtax)
311
312 $result[3] = price2num($pu, 'MU');
313 $result[5] = price2num($pu * (1 + ((($info_bits & 1) ? 0 : $txtva) / 100)) + $localtaxes[2], 'MU'); // Selon TVA NPR ou non
314 $result5bis = price2num($pu * (1 + ($txtva / 100)) + $localtaxes[2], 'MU'); // Si TVA consideree normal (non NPR)
315 $result[4] = price2num((float) $result5bis - ((float) $result[3] + $localtaxes[2]), 'MU');
316 } else {
317 // We work to define prices using the price with tax
318 $result[8] = price2num($tot_sans_remise + $localtaxes[0], 'MT');
319 $result[6] = price2num($tot_sans_remise / (1 + ((($info_bits & 1) ? 0 : $txtva) / 100)), 'MT'); // Selon TVA NPR ou non
320 $result6bis = price2num($tot_sans_remise / (1 + ($txtva / 100)), 'MT'); // Si TVA consideree normal (non NPR)
321 $result[7] = price2num((float) $result[8] - ((float) $result6bis + $localtaxes[0]), 'MT');
322
323 $result[2] = price2num((float) $tot_avec_remise + (float) $localtaxes[1], 'MT');
324 $result[0] = price2num((float) $tot_avec_remise / (1 + ((($info_bits & 1) ? 0 : (float) $txtva) / 100)), 'MT'); // Selon TVA NPR ou non
325 $result0bis = price2num((float) $tot_avec_remise / (1 + ((float) $txtva / 100)), 'MT'); // Si TVA consideree normal (non NPR)
326 $result[1] = price2num((float) $result[2] - ((float) $result0bis + (float) $localtaxes[1]), 'MT'); // Total VAT = TTC - (HT + localtax)
327
328 $result[5] = price2num($pu + $localtaxes[2], 'MU');
329 $result[3] = price2num($pu / (1 + ((($info_bits & 1) ? 0 : $txtva) / 100)), 'MU'); // Selon TVA NPR ou non
330 $result3bis = price2num($pu / (1 + ($txtva / 100)), 'MU'); // Si TVA consideree normal (non NPR)
331 $result[4] = price2num((float) $result[5] - ((float) $result3bis + (float) $localtaxes[2]), 'MU');
332 }
333
334 // if there's some localtax without vat, we calculate localtaxes (we will add them at end)
335
336 $apply_tax = false;
337 switch ($localtax1_type) {
338 case '1': // localtax on product or service
339 $apply_tax = true;
340 break;
341 case '3': // localtax on product
342 if ($type == 0) {
343 $apply_tax = true;
344 }
345 break;
346 case '5': // localtax on service
347 if ($type == 1) {
348 $apply_tax = true;
349 }
350 break;
351 }
352 if ($uselocaltax1_rate && $apply_tax) {
353 $result[14] = price2num(($tot_sans_remise_withoutvat * (1 + ($localtax1_rate / 100))) - $tot_sans_remise_withoutvat, 'MT'); // amount tax1 for total_ht_without_discount
354 $result[8] += $result[14]; // total_ttc_without_discount + tax1
355
356 $result[9] = price2num(($tot_avec_remise_withoutvat * (1 + ($localtax1_rate / 100))) - $tot_avec_remise_withoutvat, 'MT'); // amount tax1 for total_ht
357 $result[2] += $result[9]; // total_ttc + tax1
358
359 $result[11] = price2num(($pu_withouttax * (1 + ($localtax1_rate / 100))) - $pu_withouttax, 'MU'); // amount tax1 for pu_ht
360 $result[5] += $result[11]; // pu_ht + tax1
361 }
362
363 $apply_tax = false;
364 switch ($localtax2_type) {
365 case '1': // localtax on product or service
366 $apply_tax = true;
367 break;
368 case '3': // localtax on product
369 if ($type == 0) {
370 $apply_tax = true;
371 }
372 break;
373 case '5': // localtax on service
374 if ($type == 1) {
375 $apply_tax = true;
376 }
377 break;
378 }
379 if ($uselocaltax2_rate && $apply_tax) {
380 $result[15] = price2num(($tot_sans_remise_withoutvat * (1 + ($localtax2_rate / 100))) - $tot_sans_remise_withoutvat, 'MT'); // amount tax2 for total_ht_without_discount
381 $result[8] += $result[15]; // total_ttc_without_discount + tax2
382
383 $result[10] = price2num(($tot_avec_remise_withoutvat * (1 + ($localtax2_rate / 100))) - $tot_avec_remise_withoutvat, 'MT'); // amount tax2 for total_ht
384 $result[2] += $result[10]; // total_ttc + tax2
385
386 $result[12] = price2num(($pu_withouttax * (1 + ($localtax2_rate / 100))) - $pu_withouttax, 'MU'); // amount tax2 for pu_ht
387 $result[5] += $result[12]; // pu_ht + tax2
388 }
389
390 // If rounding is not using base 10 (rare)
391 if (getDolGlobalString('MAIN_ROUNDING_RULE_TOT')) {
392 if ($price_base_type != 'TTC') {
393 $result[0] = price2num(round((float) $result[0] / getDolGlobalFloat('MAIN_ROUNDING_RULE_TOT'), 0) * getDolGlobalFloat('MAIN_ROUNDING_RULE_TOT'), 'MT');
394 $result[1] = price2num(round((float) $result[1] / getDolGlobalFloat('MAIN_ROUNDING_RULE_TOT'), 0) * getDolGlobalFloat('MAIN_ROUNDING_RULE_TOT'), 'MT');
395 $result[9] = price2num(round((float) $result[9] / getDolGlobalFloat('MAIN_ROUNDING_RULE_TOT'), 0) * getDolGlobalFloat('MAIN_ROUNDING_RULE_TOT'), 'MT');
396 $result[10] = price2num(round((float) $result[10] / getDolGlobalFloat('MAIN_ROUNDING_RULE_TOT'), 0) * getDolGlobalFloat('MAIN_ROUNDING_RULE_TOT'), 'MT');
397 $result[2] = price2num((float) $result[0] + (float) $result[1] + (float) $result[9] + (float) $result[10], 'MT');
398 } else {
399 $result[1] = price2num(round((float) $result[1] / getDolGlobalFloat('MAIN_ROUNDING_RULE_TOT'), 0) * getDolGlobalFloat('MAIN_ROUNDING_RULE_TOT'), 'MT');
400 $result[2] = price2num(round((float) $result[2] / getDolGlobalFloat('MAIN_ROUNDING_RULE_TOT'), 0) * getDolGlobalFloat('MAIN_ROUNDING_RULE_TOT'), 'MT');
401 $result[9] = price2num(round((float) $result[9] / getDolGlobalFloat('MAIN_ROUNDING_RULE_TOT'), 0) * getDolGlobalFloat('MAIN_ROUNDING_RULE_TOT'), 'MT');
402 $result[10] = price2num(round((float) $result[10] / getDolGlobalFloat('MAIN_ROUNDING_RULE_TOT'), 0) * getDolGlobalFloat('MAIN_ROUNDING_RULE_TOT'), 'MT');
403 $result[0] = price2num((float) $result[2] - (float) $result[1] - (float) $result[9] - (float) $result[10], 'MT');
404 }
405 }
406
407 // Multicurrency
408 if ($multicurrency_tx != 1) {
409 if ($multicurrency_code) {
410 $savMAIN_MAX_DECIMALS_UNIT = getDolGlobalString('MAIN_MAX_DECIMALS_UNIT');
411 $savMAIN_MAX_DECIMALS_TOT = getDolGlobalString('MAIN_MAX_DECIMALS_TOT');
412 $savMAIN_ROUNDING_RULE_TOT = getDolGlobalString('MAIN_ROUNDING_RULE_TOT');
413
414 // Set parameter for currency accurency according to the value of $multicurrency_code (this is because a foreign currency may have different rounding rules)
415 $keyforforeignMAIN_MAX_DECIMALS_UNIT = 'MAIN_MAX_DECIMALS_UNIT_'.$multicurrency_code;
416 $keyforforeignMAIN_MAX_DECIMALS_TOT = 'MAIN_MAX_DECIMALS_TOT_'.$multicurrency_code;
417 $keyforforeignMAIN_ROUNDING_RULE_TOT = 'MAIN_ROUNDING_RULE_TOT_'.$multicurrency_code;
418 if (getDolGlobalString($keyforforeignMAIN_ROUNDING_RULE_TOT)) {
419 $conf->global->MAIN_MAX_DECIMALS_UNIT = getDolGlobalString($keyforforeignMAIN_MAX_DECIMALS_UNIT);
420 $conf->global->MAIN_MAX_DECIMALS_TOT = getDolGlobalString($keyforforeignMAIN_MAX_DECIMALS_TOT);
421 $conf->global->MAIN_ROUNDING_RULE_TOT = getDolGlobalString($keyforforeignMAIN_ROUNDING_RULE_TOT);
422 }
423 }
424
425 // Recall function using the multicurrency price as reference price. We must set param $multicurrency_tx to 1 to avoid infinite loop.
426 $newresult = calcul_price_total($qty, $pu_devise, $remise_percent_ligne, $txtva, $uselocaltax1_rate, $uselocaltax2_rate, $remise_percent_global, $price_base_type, $info_bits, $type, $seller, $localtaxes_array, $progress, 1, 0, ''); // pu_devise is normally arg#15, here as arg#2 @phan-suppress-current-line PhanPluginSuspiciousParamPosition
427
428 if ($multicurrency_code) {
429 // Restore setup of currency accurency
430 $conf->global->MAIN_MAX_DECIMALS_UNIT = $savMAIN_MAX_DECIMALS_UNIT; // @phan-suppress-current-line PhanPossiblyUndeclaredVariable
431 $conf->global->MAIN_MAX_DECIMALS_TOT = $savMAIN_MAX_DECIMALS_TOT; // @phan-suppress-current-line PhanPossiblyUndeclaredVariable
432 $conf->global->MAIN_ROUNDING_RULE_TOT = $savMAIN_ROUNDING_RULE_TOT; // @phan-suppress-current-line PhanPossiblyUndeclaredVariable
433 }
434
435 $result[16] = $newresult[0];
436 $result[17] = $newresult[1];
437 $result[18] = $newresult[2];
438 $result[19] = $newresult[3];
439 $result[20] = $newresult[4];
440 $result[21] = $newresult[5];
441 $result[22] = $newresult[6];
442 $result[23] = $newresult[7];
443 $result[24] = $newresult[8];
444 $result[25] = $newresult[9];
445 $result[26] = $newresult[10];
446 } else {
447 $result[16] = $result[0];
448 $result[17] = $result[1];
449 $result[18] = $result[2];
450 $result[19] = $result[3];
451 $result[20] = $result[4];
452 $result[21] = $result[5];
453 $result[22] = $result[6];
454 $result[23] = $result[7];
455 $result[24] = $result[8];
456 $result[25] = $result[9];
457 $result[26] = $result[10];
458 }
459
460 dol_syslog('Price.lib::calcul_price_total MAIN_ROUNDING_RULE_TOT='.getDolGlobalString('MAIN_ROUNDING_RULE_TOT').' pu='.$pu.' qty='.$qty.' price_base_type='.$price_base_type.' total_ht='.$result[0].'-total_vat='.$result[1].'-total_ttc='.$result[2]);
461
462 // Allow an external module to bypass the calculation of prices
463 $parameters = array('result' => $result);
464 $tmpobject = null;
465 $tmpaction = '';
466 // @phan-suppress-next-line PhanPluginConstantVariableNull
467 $reshook = $hookmanager->executeHooks('calcul_price_total', $parameters, $tmpobject, $tmpaction); // @phan-suppress-current-line PhanPluginConstantVariableNull
468 if ($reshook > 0 && !empty($hookmanager->resArray['result'])) {
469 $result = $hookmanager->resArray['result'];
470 }
471
472 return $result;
473}
Class to manage third parties objects (customers, suppliers, prospects...)
global $mysoc
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.
getDolGlobalFloat($key, $default=0)
Return a Dolibarr global constant float value.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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.
calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $uselocaltax1_rate, $uselocaltax2_rate, $remise_percent_global, $price_base_type, $info_bits, $type, $seller=null, $localtaxes_array=[], $progress=100, $multicurrency_tx=1, $pu_devise=0, $multicurrency_code='')
Calculate totals (net, vat, ...) of a line.
Definition price.lib.php:90