36 public static $PRODUCT_TYPE = 9;
42 public static $TITLE_OPTIONS = [
'titleshowuponpdf',
'titleshowtotalexludingvatonpdf',
'titleforcepagebreak'];
48 public static $SUBTOTAL_OPTIONS = [
'subtotalshowtotalexludingvatonpdf'];
53 public static $ALLOWED_TYPES = [
79 public function addSubtotalLine($langs, $desc, $depth, $options = array(), $parent_line = 0)
82 $this->errors[] = $langs->trans(
"TitleNeedDesc");
85 $current_module = $this->element;
87 if (!in_array($current_module, self::$ALLOWED_TYPES)) {
88 $this->errors[] = $langs->trans(
"UnsupportedModuleError");
97 if ($depth < 0 && $current_module !=
'shipping') {
98 foreach ($this->lines as $line) {
99 if (!$next_line && $line->desc == $desc && $line->qty == -$depth) {
103 if ($next_line && $line->desc == $desc && $line->qty == $depth) {
107 if ($next_line && $line->special_code == SUBTOTALS_SPECIAL_CODE && abs($line->qty) <= abs($depth)) {
114 if ($depth > 0 && $current_module !=
'shipping') {
115 $max_existing_level = 0;
117 foreach ($this->lines as $line) {
118 if ($line->special_code == SUBTOTALS_SPECIAL_CODE && $line->qty > $max_existing_level) {
119 $max_existing_level = $line->qty;
123 if ($max_existing_level+1 < $depth) {
124 $depth = $max_existing_level+1;
125 $this->errors[] = $langs->trans(
"TitleAddedLevelTooHigh", $depth);
132 if ($current_module ==
'facture' && $this instanceof
Facture) {
133 $result = $this->addline(
151 SUBTOTALS_SPECIAL_CODE
153 } elseif ($current_module ==
'propal' && $this instanceof
Propal) {
154 $result = $this->addline(
168 SUBTOTALS_SPECIAL_CODE
170 } elseif ($current_module ==
'commande' && $this instanceof
Commande) {
171 $result = $this->addline(
188 SUBTOTALS_SPECIAL_CODE
190 } elseif ($current_module ==
'shipping' && $this instanceof
Expedition) {
191 $result = $this->addline(
196 } elseif ($current_module ==
'facturerec' && $this instanceof
FactureRec) {
197 $rang = $rang == -1 ? $rang : $rang-1;
198 $result = $this->addline(
213 SUBTOTALS_SPECIAL_CODE
215 $this->fetch_lines();
216 } elseif ($current_module ==
'supplier_proposal' && $this instanceof
SupplierProposal) {
217 $rang = $rang == -1 ? $rang : $rang-1;
218 $result = $this->addline(
232 SUBTOTALS_SPECIAL_CODE
235 $rang = $rang == -1 ? $rang : $rang-1;
236 $result = $this->addline(
260 SUBTOTALS_SPECIAL_CODE
262 } elseif ($current_module ==
'invoice_supplier' && $this instanceof
FactureFournisseur) {
263 $rang = $rang == -1 ? $rang : $rang-1;
264 $result = $this->addline(
286 SUBTOTALS_SPECIAL_CODE
288 } elseif ($current_module ==
'fichinter' && $this instanceof
Fichinter) {
290 $result = $this->addline(
299 SUBTOTALS_SPECIAL_CODE
304 if ($current_module !=
'shipping') {
305 foreach ($this->lines as $line) {
306 '@phan-var-force CommonObjectLine $line';
308 if ($line->id == $result) {
309 $line->extraparams[
"subtotal"] = $options;
310 $line->setExtraParameters();
319 return $error > 0 ? 0 : $result;
335 public function deleteSubtotalLine($langs,
$id, $correspondingstline =
false, $user =
null)
337 $current_module = $this->element;
339 if (!in_array($current_module, self::$ALLOWED_TYPES)) {
340 $this->errors[] = $langs->trans(
"UnsupportedModuleError");
346 if ($correspondingstline) {
349 foreach ($this->lines as $line) {
350 if ($line->id ==
$id) {
351 $oldDesc = $line->desc;
352 $oldDepth = $line->qty;
354 if ($line->special_code == SUBTOTALS_SPECIAL_CODE && $line->qty == -$oldDepth && $line->desc == $oldDesc) {
355 $this->deleteSubtotalLine($langs, $line->id,
false, $user);
362 if ($current_module ==
'facture' && $this instanceof
Facture) {
364 $result = $this->deleteLine($rowid);
365 } elseif ($current_module ==
'propal' && $this instanceof
Propal) {
367 $result = $this->deleteLine($rowid);
368 } elseif ($current_module ==
'commande' && $this instanceof
Commande) {
370 $result = $this->deleteLine($user, $lineid);
371 } elseif ($current_module ==
'facturerec') {
374 $result = $line->delete($user);
375 } elseif ($current_module ==
'shipping') {
378 $result = $line->delete($user);
379 } elseif ($current_module ==
'supplier_proposal') {
382 $result = $line->delete($user);
383 } elseif ($current_module ==
'order_supplier') {
386 $result = $line->delete($user);
387 } elseif ($current_module ==
'invoice_supplier') {
390 $result = $line->delete();
393 return $result >= 0 ? $result : -1;
411 public function updateSubtotalLine($langs, $lineid, $desc, $depth, $options)
413 $current_module = $this->element;
415 if (!in_array($current_module, self::$ALLOWED_TYPES)) {
416 $this->errors[] = $langs->trans(
"UnsupportedModuleError");
423 $max_existing_level = 0;
426 foreach ($this->lines as $line) {
427 if ($line->special_code == SUBTOTALS_SPECIAL_CODE && $line->qty > $max_existing_level && $line->id != $lineid) {
428 $max_existing_level = $line->qty;
433 if ($max_existing_level+1 < $depth) {
434 $depth = $max_existing_level+1;
435 $this->errors[] = $langs->trans(
"TitleEditedLevelTooHigh");
442 foreach ($this->lines as $line) {
443 if ($line->id == $lineid) {
444 $oldDesc = $line->desc;
445 $oldDepth = $line->qty;
447 if ($line->special_code == SUBTOTALS_SPECIAL_CODE && $line->qty == -$oldDepth && $line->desc == $oldDesc) {
448 $this->updateSubtotalLine($langs, $line->id, $desc, -$depth, !empty($line->extraparams[
"subtotal"]) ? $line->extraparams[
"subtotal"] : array());
455 if ($current_module ==
'facture' && $this instanceof
Facture) {
456 $result = $this->updateline(
475 SUBTOTALS_SPECIAL_CODE
477 } elseif ($current_module ==
'propal' && $this instanceof
Propal) {
478 $result = $this->updateline(
489 SUBTOTALS_SPECIAL_CODE,
497 } elseif ($current_module ==
'commande' && $this instanceof
Commande) {
498 $result = $this->updateline(
517 SUBTOTALS_SPECIAL_CODE
519 } elseif ($current_module ==
'facturerec' && $this instanceof
FactureRec) {
521 $objectline->fetch($lineid);
522 $line_rang = $objectline->rang;
523 $result = $this->updateline(
539 SUBTOTALS_SPECIAL_CODE
541 } elseif ($current_module ==
'supplier_proposal' && $this instanceof
SupplierProposal) {
543 $objectline->fetch($lineid);
544 $line_rang = $objectline->rang;
545 $result = $this->updateline(
556 SUBTOTALS_SPECIAL_CODE,
566 $objectline->fetch($lineid);
567 $line_rang = $objectline->rang;
569 $result = $this->updateline(
587 } elseif ($current_module ==
'invoice_supplier' && $this instanceof
FactureFournisseur) {
589 $objectline->fetch($lineid);
590 $line_rang = $objectline->rang;
591 $result = $this->updateline(
607 foreach ($this->lines as $line) {
608 '@phan-var-force CommonObjectLine $line';
610 if ($line->id == $lineid) {
611 $line->extraparams[
"subtotal"] = $options;
612 $line->setExtraParameters();
620 return $error > 0 ? 0 : $result;
635 public function updateSubtotalLineBlockLines($langs, $linerang, $mode, $value)
637 $current_module = $this->element;
639 if (!in_array($current_module, self::$ALLOWED_TYPES)) {
640 $this->errors[] = $langs->trans(
"UnsupportedModuleError");
647 $nb_lines = count($this->lines)+1;
649 for ($i = $linerang+1; $i < $nb_lines; $i++) {
650 if ($this->lines[$i]->special_code == SUBTOTALS_SPECIAL_CODE) {
651 if (abs($this->lines[$i]->qty) <= (
int) $this->lines[$linerang]->qty) {
655 if ($current_module ==
'facture' && $this instanceof
Facture) {
656 $result = $this->updateline(
657 $this->lines[$i]->
id,
658 $this->lines[$i]->desc,
659 $this->lines[$i]->subprice,
660 $this->lines[$i]->qty,
661 $mode ==
'discount' ? $value : $this->lines[$i]->remise_percent,
662 $this->lines[$i]->date_start,
663 $this->lines[$i]->date_end,
664 $mode ==
'tva' ? $value : $this->lines[$i]->tva_tx,
665 $this->lines[$i]->localtax1_tx,
666 $this->lines[$i]->localtax2_tx,
668 $this->lines[$i]->info_bits,
669 $this->lines[$i]->product_type,
670 $this->lines[$i]->fk_parent_line,
672 $this->lines[$i]->fk_fournprice,
673 $this->lines[$i]->pa_ht,
674 $this->lines[$i]->label,
675 $this->lines[$i]->special_code,
676 $this->lines[$i]->array_options,
677 $this->lines[$i]->situation_percent,
678 $this->lines[$i]->fk_unit,
679 $this->lines[$i]->multicurrency_subprice
681 } elseif ($current_module ==
'commande' && $this instanceof
Commande) {
682 $result = $this->updateline(
683 $this->lines[$i]->
id,
684 $this->lines[$i]->desc,
685 $this->lines[$i]->subprice,
686 $this->lines[$i]->qty,
687 $mode ==
'discount' ? $value : $this->lines[$i]->remise_percent,
688 $mode ==
'tva' ? $value : $this->lines[$i]->tva_tx,
689 $this->lines[$i]->localtax1_rate,
690 $this->lines[$i]->localtax2_rate,
692 $this->lines[$i]->info_bits,
693 $this->lines[$i]->date_start,
694 $this->lines[$i]->date_end,
695 $this->lines[$i]->product_type,
696 $this->lines[$i]->fk_parent_line,
698 $this->lines[$i]->fk_fournprice,
699 $this->lines[$i]->pa_ht,
700 $this->lines[$i]->label,
701 $this->lines[$i]->special_code,
702 $this->lines[$i]->array_options,
703 $this->lines[$i]->fk_unit,
704 $this->lines[$i]->multicurrency_subprice
706 } elseif ($current_module ==
'propal' && $this instanceof
Propal) {
708 $line_price_base_type = $this->lines[$i]->wasEnteredIncludingTax() ?
'TTC' :
'HT';
709 $line_pu = ($line_price_base_type ===
'TTC') ? $this->lines[$i]->subprice_ttc : $this->lines[$i]->subprice;
710 $result = $this->updateline(
711 $this->lines[$i]->
id,
713 $this->lines[$i]->qty,
714 $mode ==
'discount' ? $value : $this->lines[$i]->remise_percent,
715 $mode ==
'tva' ? $value : $this->lines[$i]->tva_tx,
716 $this->lines[$i]->localtax1_rate,
717 $this->lines[$i]->localtax2_rate,
718 $this->lines[$i]->desc,
719 $line_price_base_type,
720 $this->lines[$i]->info_bits,
721 $this->lines[$i]->special_code,
722 $this->lines[$i]->fk_parent_line,
724 $this->lines[$i]->fk_fournprice,
725 $this->lines[$i]->pa_ht,
726 $this->lines[$i]->label,
727 $this->lines[$i]->product_type,
728 $this->lines[$i]->date_start,
729 $this->lines[$i]->date_end,
730 $this->lines[$i]->array_options,
731 $this->lines[$i]->fk_unit,
732 $this->lines[$i]->multicurrency_subprice
752 public function getSubtotalLineAmount($line)
755 for ($i = $line->rang-1; $i > 0; $i--) {
756 if (is_null($this->lines[$i-1]) || $this->lines[$i-1]->rang >= $line->rang) {
759 if ($this->lines[$i-1]->special_code == SUBTOTALS_SPECIAL_CODE && $this->lines[$i-1]->qty > 0) {
760 if ($this->lines[$i-1]->qty <= abs($line->qty)) {
761 return price($final_amount);
764 $final_amount += $this->lines[$i-1]->total_ht;
767 return price($final_amount);
779 public function getSubtotalLineMulticurrencyAmount($line)
782 for ($i = $line->rang-1; $i > 0; $i--) {
783 if (is_null($this->lines[$i-1]) || $this->lines[$i-1]->rang >= $line->rang) {
786 if ($this->lines[$i-1]->special_code == SUBTOTALS_SPECIAL_CODE && $this->lines[$i-1]->qty>0) {
787 if ($this->lines[$i-1]->qty <= abs($line->qty)) {
788 return price($final_amount);
791 $final_amount += $this->lines[$i-1]->multicurrency_total_ht;
794 return price($final_amount);
803 public function getSubtotalColors($level)
815 public function getPossibleTitles()
818 foreach ($this->lines as $line) {
819 if ($line->special_code == SUBTOTALS_SPECIAL_CODE && $line->qty > 0) {
820 $titles[$line->desc] = $line->desc;
822 if ($line->special_code == SUBTOTALS_SPECIAL_CODE && $line->qty < 0) {
823 unset($titles[$line->desc]);
837 public function getPossibleLevels($langs)
839 $depth_array = array();
840 $max_depth =
getDolGlobalString(
'SUBTOTAL_'.strtoupper($this->element).
'_MAX_DEPTH', 2);
841 for ($i = 0; $i < $max_depth; $i++) {
842 $depth_array[$i + 1] = $langs->trans(
"SubtotalLevel", $i + 1);
854 public function getDisabledShippmentSubtotalLines()
856 $toDisableLines = array();
861 foreach ($this->lines as $titleLine) {
862 if ($titleLine->special_code != SUBTOTALS_SPECIAL_CODE || $titleLine->qty <= 0) {
865 foreach ($this->lines as $line) {
866 if ($line->id == $titleLine->id) {
867 $oldDesc = $line->desc;
868 $oldDepth = $line->qty;
870 if ($line->special_code != SUBTOTALS_SPECIAL_CODE && $line->fk_product_type == 0 && !empty($oldDesc) && !empty($oldDepth)) {
873 if ($line->special_code == SUBTOTALS_SPECIAL_CODE && $line->qty == -$oldDepth && $line->desc == $oldDesc) {
875 $toDisableLines = array_merge($toDisableLines, array($titleLine->id, $line->id));
884 return $toDisableLines;
$id
Support class for third parties, contacts, members, users or resources.
Class to manage predefined suppliers products.
Class to manage line orders.
Class to manage customers orders.
Class to manage lines of shipment.
Class to manage suppliers invoices.
Class to manage invoices.
Class to manage invoice lines of templates.
Class to manage invoice templates.
Class to manage proposals.
Class to manage line invoices.
Class to manage price ask supplier.
Class to manage supplier_proposal lines.
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.