dolibarr 22.0.5
commonsubtotal.class.php
1<?php
2/* Copyright (C) 2014-2017 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
4 * Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
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 * or see https://www.gnu.org/
19 */
20
21if (!defined('SUBTOTALS_SPECIAL_CODE')) {
22 define('SUBTOTALS_SPECIAL_CODE', 81);
23}
24
31trait CommonSubtotal
32{
37 public static $PRODUCT_TYPE = 9;
38
43 public static $TITLE_OPTIONS = ['titleshowuponpdf', 'titleshowtotalexludingvatonpdf', 'titleforcepagebreak'];
44
49 public static $SUBTOTAL_OPTIONS = ['subtotalshowtotalexludingvatonpdf'];
50
65 public function addSubtotalLine($langs, $desc, $depth, $options = array(), $parent_line = 0)
66 {
67 if (empty($desc)) {
68 if (isset($this->errors)) {
69 $this->errors[] = $langs->trans("TitleNeedDesc");
70 }
71 return -1;
72 }
73 $current_module = $this->element;
74 // Ensure the object is one of the supported types
75 $allowed_types = array('propal', 'commande', 'facture', 'facturerec', 'shipping');
76 if (!in_array($current_module, $allowed_types)) {
77 if (isset($this->errors)) {
78 $this->errors[] = $langs->trans("UnsupportedModuleError");
79 }
80 return -1; // Unsupported type
81 }
82 $error = 0;
83 $desc = dol_html_entity_decode($desc, ENT_QUOTES);
84 $rang = -1;
85 $next_line = false;
86 $result = 0;
87
88 if ($depth < 0 && $current_module != 'shipping') {
89 foreach ($this->lines as $line) {
90 if (!$next_line && $line->desc == $desc && $line->qty == -$depth) {
91 $next_line = true;
92 continue;
93 }
94 if ($next_line && $line->desc == $desc && $line->qty == $depth) {
95 $next_line = false;
96 continue;
97 }
98 if ($next_line && $line->special_code == SUBTOTALS_SPECIAL_CODE && abs($line->qty) <= abs($depth)) {
99 $rang = $line->rang;
100 break;
101 }
102 }
103 }
104
105 if ($depth > 0 && $current_module != 'shipping') {
106 $max_existing_level = 0;
107
108 foreach ($this->lines as $line) {
109 if ($line->special_code == SUBTOTALS_SPECIAL_CODE && $line->qty > $max_existing_level) {
110 $max_existing_level = $line->qty;
111 }
112 }
113
114 if ($max_existing_level+1 < $depth) {
115 $depth = $max_existing_level+1;
116 if (isset($this->errors)) {
117 $this->errors[] = $langs->trans("TitleAddedLevelTooHigh", $depth);
118 }
119
120 $error ++;
121 }
122 }
123
124 // Add the line calling the right module
125 if ($current_module == 'facture') {
126 $result = $this->addline( // @phpstan-ignore-line
127 $desc, // Description @phpstan-ignore-line
128 0, // Unit price @phpstan-ignore-line
129 $depth, // Quantity @phpstan-ignore-line
130 0, // VAT rate @phpstan-ignore-line
131 0, // Local tax 1 @phpstan-ignore-line
132 0, // Local tax 2 @phpstan-ignore-line
133 0, // FK product @phpstan-ignore-line
134 0, // Discount percentage @phpstan-ignore-line
135 '', // Date start @phpstan-ignore-line
136 '', // Date end @phpstan-ignore-line
137 0, // FK code ventilation @phpstan-ignore-line
138 0, // Info bits @phpstan-ignore-line
139 0, // FK remise except @phpstan-ignore-line
140 '', // Price base type @phpstan-ignore-line
141 0, // PU ttc @phpstan-ignore-line
142 self::$PRODUCT_TYPE, // Type @phpstan-ignore-line
143 $rang, // Rang @phpstan-ignore-line
144 SUBTOTALS_SPECIAL_CODE // Special code @phpstan-ignore-line
145 );
146 } elseif ($current_module == 'propal') {
147 $result = $this->addline( // @phpstan-ignore-line
148 $desc, // Description @phpstan-ignore-line
149 0, // Unit price @phpstan-ignore-line
150 $depth, // Quantity @phpstan-ignore-line
151 0, // VAT rate @phpstan-ignore-line
152 0, // Local tax 1 @phpstan-ignore-line
153 0, // Local tax 2 @phpstan-ignore-line
154 0, // FK product @phpstan-ignore-line
155 0, // Discount percentage @phpstan-ignore-line
156 '', // Price base type @phpstan-ignore-line
157 0, // PU ttc @phpstan-ignore-line
158 0, // Info bits @phpstan-ignore-line
159 self::$PRODUCT_TYPE, // Type @phpstan-ignore-line
160 $rang, // Rang @phpstan-ignore-line
161 SUBTOTALS_SPECIAL_CODE // Special code @phpstan-ignore-line
162 );
163 } elseif ($current_module == 'commande') {
164 $result = $this->addline( // @phpstan-ignore-line
165 $desc, // Description @phpstan-ignore-line
166 0, // Unit price @phpstan-ignore-line
167 $depth, // Quantity @phpstan-ignore-line
168 0, // VAT rate @phpstan-ignore-line
169 0, // Local tax 1 @phpstan-ignore-line
170 0, // Local tax 2 @phpstan-ignore-line
171 0, // FK product @phpstan-ignore-line
172 0, // Discount percentage @phpstan-ignore-line
173 0, // Info bits @phpstan-ignore-line
174 0, // FK remise except @phpstan-ignore-line
175 '', // Price base type @phpstan-ignore-line
176 0, // PU ttc @phpstan-ignore-line
177 '', // Date start @phpstan-ignore-line
178 '', // Date end @phpstan-ignore-line
179 self::$PRODUCT_TYPE, // Type @phpstan-ignore-line
180 $rang, // Rang @phpstan-ignore-line
181 SUBTOTALS_SPECIAL_CODE // Special code @phpstan-ignore-line
182 );
183 } elseif ($current_module == 'shipping') {
184 $result = $this->addline( // @phpstan-ignore-line
185 '', // Warehouse ID @phpstan-ignore-line
186 (int) $parent_line, // Source line @phpstan-ignore-line
187 $depth // Quantity @phpstan-ignore-line
188 );
189 } elseif ($current_module == 'facturerec') {
190 $rang = $rang == -1 ? $rang : $rang-1;
191 $result = $this->addline( // @phpstan-ignore-line
192 $desc, // Description @phpstan-ignore-line
193 0, // Unit price @phpstan-ignore-line
194 $depth, // Quantity @phpstan-ignore-line
195 0, // VAT rate @phpstan-ignore-line
196 0, // Local tax 1 @phpstan-ignore-line
197 0, // Local tax 2 @phpstan-ignore-line
198 0, // FK product @phpstan-ignore-line
199 0, // Discount percentage @phpstan-ignore-line
200 '', // Price base type @phpstan-ignore-line
201 0, // Info bits @phpstan-ignore-line
202 0, // FK remise except @phpstan-ignore-line
203 0, // PU ttc @phpstan-ignore-line
204 self::$PRODUCT_TYPE, // Type @phpstan-ignore-line
205 $rang, // Rang @phpstan-ignore-line
206 SUBTOTALS_SPECIAL_CODE // Special code @phpstan-ignore-line
207 );
208 $this->fetch_lines();
209 }
210
211 if ($current_module != 'shipping') {
212 foreach ($this->lines as $line) {
213 '@phan-var-force CommonObjectLine $line';
214 if ($line->id == $result) {
215 $line->extraparams["subtotal"] = $options;
216 $line->setExtraParameters();
217 }
218 }
219 }
220
221 if ($result < 0) {
222 return $result;
223 }
224
225 return $error > 0 ? 0 : $result;
226 }
227
241 public function deleteSubtotalLine($langs, $id, $correspondingstline = false, $user = null)
242 {
243 $current_module = $this->element;
244 // Ensure the object is one of the supported types
245 $allowed_types = array('propal', 'commande', 'facture', 'facturerec', 'shipping');
246 if (!in_array($current_module, $allowed_types)) {
247 if (isset($this->errors)) {
248 $this->errors[] = $langs->trans("UnsupportedModuleError");
249 }
250 return -1; // Unsupported type
251 }
252
253 $result = 0;
254
255 if ($correspondingstline) {
256 $oldDesc = "";
257 $oldDepth = 0;
258 foreach ($this->lines as $line) {
259 if ($line->id == $id) {
260 $oldDesc = $line->desc;
261 $oldDepth = $line->qty;
262 }
263 if ($line->special_code == SUBTOTALS_SPECIAL_CODE && $line->qty == -$oldDepth && $line->desc == $oldDesc) {
264 $this->deleteSubtotalLine($langs, $line->id, false, $user);
265 break;
266 }
267 }
268 }
269
270 // Add the line calling the right module
271 if ($current_module == 'facture') {
272 $result = $this->deleteLine($id); // @phpstan-ignore-line
273 } elseif ($current_module == 'propal') {
274 $result = $this->deleteLine($id); // @phpstan-ignore-line
275 } elseif ($current_module == 'commande') {
276 $result = $this->deleteLine($user, $id); // @phpstan-ignore-line
277 } elseif ($current_module == 'facturerec') {
278 $line = new FactureLigneRec($this->db);
279 $line->id = $id;
280 $result = $line->delete($user); // @phpstan-ignore-line
281 } elseif ($current_module == 'shipping') {
282 $line = new ExpeditionLigne($this->db);
283 $line->id = $id;
284 $result = $line->delete($user); // @phpstan-ignore-line
285 }
286
287 return $result >= 0 ? $result : -1; // Return line ID or false
288 }
289
305 public function updateSubtotalLine($langs, $lineid, $desc, $depth, $options) // @phpstan-ignore-line
306 {
307 $current_module = $this->element;
308 // Ensure the object is one of the supported types
309 $allowed_types = array('propal', 'commande', 'facture', 'facturerec', 'shipping');
310 if (!in_array($current_module, $allowed_types)) {
311 if (isset($this->errors)) {
312 $this->errors[] = $langs->trans("UnsupportedModuleError");
313 }
314 return -1; // Unsupported type
315 }
316
317 $result = 0;
318 $error = 0;
319
320 $max_existing_level = 0;
321
322 if ($depth>0) {
323 foreach ($this->lines as $line) {
324 if ($line->special_code == SUBTOTALS_SPECIAL_CODE && $line->qty > $max_existing_level && $line->id != $lineid) {
325 $max_existing_level = $line->qty;
326 }
327 }
328 }
329
330 if ($max_existing_level+1 < $depth) {
331 $depth = $max_existing_level+1;
332 if (isset($this->errors)) {
333 $this->errors[] = $langs->trans("TitleEditedLevelTooHigh");
334 }
335 $error ++;
336 }
337
338 if ($depth>0) {
339 $oldDesc = "";
340 $oldDepth = 0;
341 foreach ($this->lines as $line) {
342 if ($line->id == $lineid) {
343 $oldDesc = $line->desc;
344 $oldDepth = $line->qty;
345 }
346 if ($line->special_code == SUBTOTALS_SPECIAL_CODE && $line->qty == -$oldDepth && $line->desc == $oldDesc) {
347 $this->updateSubtotalLine($langs, $line->id, $desc, -$depth, !empty($line->extraparams["subtotal"]) ? $line->extraparams["subtotal"] : array());
348 break;
349 }
350 }
351 }
352
353 // Update the line calling the right module
354 if ($current_module == 'facture') {
355 $result = $this->updateline( // @phpstan-ignore-line
356 $lineid, // ID of line to change @phpstan-ignore-line
357 $desc, // Description @phpstan-ignore-line
358 0, // Unit price @phpstan-ignore-line
359 $depth, // Quantity @phpstan-ignore-line
360 0, // Discount percentage @phpstan-ignore-line
361 '', // Date start @phpstan-ignore-line
362 '', // Date end @phpstan-ignore-line
363 0, // VAT rate @phpstan-ignore-line
364 0, // Local tax 1 @phpstan-ignore-line
365 0, // Local tax 2 @phpstan-ignore-line
366 '', // Price base type @phpstan-ignore-line
367 0, // Info bits @phpstan-ignore-line
368 self::$PRODUCT_TYPE, // Type @phpstan-ignore-line
369 0, // FK parent line @phpstan-ignore-line
370 0, // Skip update total @phpstan-ignore-line
371 0, // FK fournprice @phpstan-ignore-line
372 0, // PA ht @phpstan-ignore-line
373 '', // Label @phpstan-ignore-line
374 SUBTOTALS_SPECIAL_CODE // Special code @phpstan-ignore-line
375 );
376 } elseif ($current_module == 'propal') {
377 $result = $this->updateline( // @phpstan-ignore-line
378 $lineid, // ID of line to change @phpstan-ignore-line
379 0, // Unit price @phpstan-ignore-line
380 $depth, // Quantity @phpstan-ignore-line
381 0, // Discount percentage @phpstan-ignore-line
382 0, // VAT rate @phpstan-ignore-line
383 0, // Local tax 1 @phpstan-ignore-line
384 0, // Local tax 2 @phpstan-ignore-line
385 $desc, // Description @phpstan-ignore-line
386 '', // Price base type @phpstan-ignore-line
387 0, // Info bits @phpstan-ignore-line
388 SUBTOTALS_SPECIAL_CODE, // Special code @phpstan-ignore-line
389 0, // FK parent line @phpstan-ignore-line
390 0, // Skip update total @phpstan-ignore-line
391 0, // FK fournprice @phpstan-ignore-line
392 0, // PA ht @phpstan-ignore-line
393 '', // Label @phpstan-ignore-line
394 self::$PRODUCT_TYPE // Type @phpstan-ignore-line
395 );
396 } elseif ($current_module == 'commande') {
397 $result = $this->updateline( // @phpstan-ignore-line
398 $lineid, // ID of line to change @phpstan-ignore-line
399 $desc, // Description @phpstan-ignore-line
400 0, // Unit price @phpstan-ignore-line
401 $depth, // Quantity @phpstan-ignore-line
402 0, // Discount percentage @phpstan-ignore-line
403 0, // VAT rate @phpstan-ignore-line
404 0, // Local tax 1 @phpstan-ignore-line
405 0, // Local tax 2 @phpstan-ignore-line
406 '', // Price base type @phpstan-ignore-line
407 0, // Info bits @phpstan-ignore-line
408 '', // Date start @phpstan-ignore-line
409 '', // Date end @phpstan-ignore-line
410 self::$PRODUCT_TYPE, // Type @phpstan-ignore-line
411 0, // FK parent line @phpstan-ignore-line
412 0, // Skip update total @phpstan-ignore-line
413 0, // FK fournprice @phpstan-ignore-line
414 0, // PA ht @phpstan-ignore-line
415 '', // Label @phpstan-ignore-line
416 SUBTOTALS_SPECIAL_CODE // Special code @phpstan-ignore-line
417 );
418 } elseif ($current_module == 'facturerec') {
419 $objectline = new FactureLigneRec($this->db);
420 $objectline->fetch($lineid);
421 $line_rang = $objectline->rang;
422 $result = $this->updateline( // @phpstan-ignore-line
423 $lineid, // ID of line to change @phpstan-ignore-line
424 $desc, // Description @phpstan-ignore-line
425 0, // Unit price @phpstan-ignore-line
426 $depth, // Quantity @phpstan-ignore-line
427 0, // VAT rate @phpstan-ignore-line
428 0, // Local tax 1 @phpstan-ignore-line
429 0, // Local tax 2 @phpstan-ignore-line
430 0, // FK parent line @phpstan-ignore-line
431 0, // Discount percentage @phpstan-ignore-line
432 '', // Price base type @phpstan-ignore-line
433 0, // Info bits @phpstan-ignore-line
434 0, // FK parent line @phpstan-ignore-line
435 0, // PU ttc @phpstan-ignore-line
436 self::$PRODUCT_TYPE, // Type @phpstan-ignore-line
437 $line_rang, // Rang @phpstan-ignore-line
438 SUBTOTALS_SPECIAL_CODE // Special code @phpstan-ignore-line
439 );
440 }
441
442 foreach ($this->lines as $line) {
443 '@phan-var-force CommonObjectLine $line';
445 if ($line->id == $lineid) {
446 $line->extraparams["subtotal"] = $options;
447 $line->setExtraParameters();
448 }
449 }
450
451 if ($result < 0) {
452 return $result;
453 }
454
455 return $error > 0 ? 0 : $result;
456 }
457
470 public function updateSubtotalLineBlockLines($langs, $linerang, $mode, $value) // @phpstan-ignore-line
471 {
472 $current_module = $this->element;
473 // Ensure the object is one of the supported types
474 $allowed_types = array('propal', 'commande', 'facture', 'facturerec', 'shipping');
475 if (!in_array($current_module, $allowed_types)) {
476 if (isset($this->errors)) {
477 $this->errors[] = $langs->trans("UnsupportedModuleError");
478 }
479 return -1; // Unsupported type
480 }
481
482 $result = 0;
483 $linerang -= 1;
484
485 $nb_lines = count($this->lines)+1;
486
487 for ($i = $linerang+1; $i < $nb_lines; $i++) {
488 if ($this->lines[$i]->special_code == SUBTOTALS_SPECIAL_CODE) {
489 if (abs($this->lines[$i]->qty) <= (int) $this->lines[$linerang]->qty) {
490 return 1;
491 }
492 } else {
493 if ($current_module == 'facture') {
494 $result = $this->updateline( // @phpstan-ignore-line
495 $this->lines[$i]->id, // @phpstan-ignore-line
496 $this->lines[$i]->desc, // @phpstan-ignore-line
497 $this->lines[$i]->subprice, // @phpstan-ignore-line
498 $this->lines[$i]->qty, // @phpstan-ignore-line
499 $mode == 'discount' ? $value : $this->lines[$i]->remise_percent, // @phpstan-ignore-line
500 $this->lines[$i]->date_start, // @phpstan-ignore-line
501 $this->lines[$i]->date_end, // @phpstan-ignore-line
502 $mode == 'tva' ? $value : $this->lines[$i]->tva_tx, // @phpstan-ignore-line
503 $this->lines[$i]->localtax1_tx, // @phpstan-ignore-line
504 $this->lines[$i]->localtax2_tx, // @phpstan-ignore-line
505 'HT', // @phpstan-ignore-line
506 $this->lines[$i]->info_bits, // @phpstan-ignore-line
507 $this->lines[$i]->product_type, // @phpstan-ignore-line
508 $this->lines[$i]->fk_parent_line, 0, // @phpstan-ignore-line
509 $this->lines[$i]->fk_fournprice, // @phpstan-ignore-line
510 $this->lines[$i]->pa_ht, // @phpstan-ignore-line
511 $this->lines[$i]->label, // @phpstan-ignore-line
512 $this->lines[$i]->special_code, // @phpstan-ignore-line
513 $this->lines[$i]->array_options, // @phpstan-ignore-line
514 $this->lines[$i]->situation_percent, // @phpstan-ignore-line
515 $this->lines[$i]->fk_unit, // @phpstan-ignore-line
516 $this->lines[$i]->multicurrency_subprice // @phpstan-ignore-line
517 );
518 } elseif ($current_module == 'commande') {
519 $result = $this->updateline( // @phpstan-ignore-line
520 $this->lines[$i]->id, // @phpstan-ignore-line
521 $this->lines[$i]->desc, // @phpstan-ignore-line
522 $this->lines[$i]->subprice, // @phpstan-ignore-line
523 $this->lines[$i]->qty, // @phpstan-ignore-line
524 $mode == 'discount' ? $value : $this->lines[$i]->remise_percent, // @phpstan-ignore-line
525 $mode == 'tva' ? $value : $this->lines[$i]->tva_tx, // @phpstan-ignore-line
526 $this->lines[$i]->localtax1_rate, // @phpstan-ignore-line
527 $this->lines[$i]->localtax2_rate, // @phpstan-ignore-line
528 'HT', // @phpstan-ignore-line
529 $this->lines[$i]->info_bits, // @phpstan-ignore-line
530 $this->lines[$i]->date_start, // @phpstan-ignore-line
531 $this->lines[$i]->date_end, // @phpstan-ignore-line
532 $this->lines[$i]->product_type, // @phpstan-ignore-line
533 $this->lines[$i]->fk_parent_line, 0, // @phpstan-ignore-line
534 $this->lines[$i]->fk_fournprice, // @phpstan-ignore-line
535 $this->lines[$i]->pa_ht, // @phpstan-ignore-line
536 $this->lines[$i]->label, // @phpstan-ignore-line
537 $this->lines[$i]->special_code, // @phpstan-ignore-line
538 $this->lines[$i]->array_options, // @phpstan-ignore-line
539 $this->lines[$i]->fk_unit, // @phpstan-ignore-line
540 $this->lines[$i]->multicurrency_subprice // @phpstan-ignore-line
541 );
542 } elseif ($current_module == 'propal') {
543 $result = $this->updateline( // @phpstan-ignore-line
544 $this->lines[$i]->id, // @phpstan-ignore-line
545 $this->lines[$i]->subprice, // @phpstan-ignore-line
546 $this->lines[$i]->qty, // @phpstan-ignore-line
547 $mode == 'discount' ? $value : $this->lines[$i]->remise_percent, // @phpstan-ignore-line
548 $mode == 'tva' ? $value : $this->lines[$i]->tva_tx, // @phpstan-ignore-line
549 $this->lines[$i]->localtax1_rate, // @phpstan-ignore-line
550 $this->lines[$i]->localtax2_rate, // @phpstan-ignore-line
551 $this->lines[$i]->desc, // @phpstan-ignore-line
552 'HT', // @phpstan-ignore-line
553 $this->lines[$i]->info_bits, // @phpstan-ignore-line
554 $this->lines[$i]->special_code, // @phpstan-ignore-line
555 $this->lines[$i]->fk_parent_line, 0, // @phpstan-ignore-line
556 $this->lines[$i]->fk_fournprice, // @phpstan-ignore-line
557 $this->lines[$i]->pa_ht, // @phpstan-ignore-line
558 $this->lines[$i]->label, // @phpstan-ignore-line
559 $this->lines[$i]->product_type, // @phpstan-ignore-line
560 $this->lines[$i]->date_start, // @phpstan-ignore-line
561 $this->lines[$i]->date_end, // @phpstan-ignore-line
562 $this->lines[$i]->array_options, // @phpstan-ignore-line
563 $this->lines[$i]->fk_unit, // @phpstan-ignore-line
564 $this->lines[$i]->multicurrency_subprice // @phpstan-ignore-line
565 );
566 }
567 if ($result < 0) {
568 return $result;
569 }
570 }
571 }
572 return 1;
573 }
574
584 public function getSubtotalLineAmount($line)
585 {
586 $final_amount = 0;
587 for ($i = $line->rang-1; $i > 0; $i--) {
588 if (is_null($this->lines[$i-1]) || $this->lines[$i-1]->rang >= $line->rang) {
589 continue;
590 }
591 if ($this->lines[$i-1]->special_code == SUBTOTALS_SPECIAL_CODE && $this->lines[$i-1]->qty > 0) {
592 if ($this->lines[$i-1]->qty <= abs($line->qty)) {
593 return price($final_amount);
594 }
595 } else {
596 $final_amount += $this->lines[$i-1]->total_ht;
597 }
598 }
599 return price($final_amount);
600 }
601
611 public function getSubtotalLineMulticurrencyAmount($line)
612 {
613 $final_amount = 0;
614 for ($i = $line->rang-1; $i > 0; $i--) {
615 if (is_null($this->lines[$i-1]) || $this->lines[$i-1]->rang >= $line->rang) {
616 continue;
617 }
618 if ($this->lines[$i-1]->special_code == SUBTOTALS_SPECIAL_CODE && $this->lines[$i-1]->qty>0) {
619 if ($this->lines[$i-1]->qty <= abs($line->qty)) {
620 return price($final_amount);
621 }
622 } else {
623 $final_amount += $this->lines[$i-1]->multicurrency_total_ht;
624 }
625 }
626 return price($final_amount);
627 }
628
635 public function getSubtotalColors($level)
636 {
637 return getDolGlobalString('SUBTOTAL_BACK_COLOR_LEVEL_'.abs($level));
638 }
639
647 public function getPossibleTitles()
648 {
649 $titles = array();
650 foreach ($this->lines as $line) {
651 if ($line->special_code == SUBTOTALS_SPECIAL_CODE && $line->qty > 0) {
652 $titles[$line->desc] = $line->desc;
653 }
654 if ($line->special_code == SUBTOTALS_SPECIAL_CODE && $line->qty < 0) {
655 unset($titles[$line->desc]);
656 }
657 }
658 return $titles;
659 }
660
669 public function getPossibleLevels($langs)
670 {
671 $depth_array = array();
672 $max_depth = getDolGlobalString('SUBTOTAL_'.strtoupper($this->element).'_MAX_DEPTH', 2);
673 for ($i = 0; $i < $max_depth; $i++) {
674 $depth_array[$i + 1] = $langs->trans("SubtotalLevel", $i + 1);
675 }
676 return $depth_array;
677 }
678
686 public function getDisabledShippmentSubtotalLines()
687 {
688 $toDisableLines = array();
689 $toDisable = true;
690 $oldDesc = "";
691 $oldDepth = 0;
692
693 foreach ($this->lines as $titleLine) {
694 if ($titleLine->special_code != SUBTOTALS_SPECIAL_CODE || $titleLine->qty <= 0) {
695 continue;
696 }
697 foreach ($this->lines as $line) {
698 if ($line->id == $titleLine->id) {
699 $oldDesc = $line->desc;
700 $oldDepth = $line->qty;
701 }
702 if ($line->special_code != SUBTOTALS_SPECIAL_CODE && $line->fk_product_type == 0 && !empty($oldDesc) && !empty($oldDepth)) {
703 $toDisable = false;
704 }
705 if ($line->special_code == SUBTOTALS_SPECIAL_CODE && $line->qty == -$oldDepth && $line->desc == $oldDesc) {
706 if ($toDisable) {
707 $toDisableLines = array_merge($toDisableLines, array($titleLine->id, $line->id));
708 }
709 $oldDesc = "";
710 $oldDepth = 0;
711 $toDisable = true;
712 break;
713 }
714 }
715 }
716 return $toDisableLines;
717 }
718}
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:48
Class to manage lines of shipment.
Class to manage invoice lines of templates.
dol_html_entity_decode($a, $b, $c='UTF-8', $keepsomeentities=0)
Replace html_entity_decode functions to manage errors.
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.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.