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 = [
80 public function addSubtotalLine($langs, $desc, $depth, $options = array(), $parent_line = 0)
83 $this->errors[] = $langs->trans(
"TitleNeedDesc");
86 $current_module = $this->element;
88 if (!in_array($current_module, self::$ALLOWED_TYPES)) {
89 $this->errors[] = $langs->trans(
"UnsupportedModuleError");
98 if ($depth < 0 && $current_module !=
'shipping') {
99 foreach ($this->lines as $line) {
100 if (!$next_line && $line->desc == $desc && $line->qty == -$depth) {
104 if ($next_line && $line->desc == $desc && $line->qty == $depth) {
108 if ($next_line && $line->special_code == SUBTOTALS_SPECIAL_CODE && abs($line->qty) <= abs($depth)) {
115 if ($depth > 0 && $current_module !=
'shipping') {
116 $max_existing_level = 0;
118 foreach ($this->lines as $line) {
119 if ($line->special_code == SUBTOTALS_SPECIAL_CODE && $line->qty > $max_existing_level) {
120 $max_existing_level = $line->qty;
124 if ($max_existing_level+1 < $depth) {
125 $depth = $max_existing_level+1;
126 $this->errors[] = $langs->trans(
"TitleAddedLevelTooHigh", $depth);
133 if ($current_module ==
'facture' && $this instanceof
Facture) {
134 $result = $this->addline(
152 SUBTOTALS_SPECIAL_CODE
154 } elseif ($current_module ==
'propal' && $this instanceof
Propal) {
155 $result = $this->addline(
169 SUBTOTALS_SPECIAL_CODE
171 } elseif ($current_module ==
'commande' && $this instanceof
Commande) {
172 $result = $this->addline(
189 SUBTOTALS_SPECIAL_CODE
191 } elseif ($current_module ==
'shipping' && $this instanceof
Expedition) {
192 $result = $this->addline(
197 } elseif ($current_module ==
'facturerec' && $this instanceof
FactureRec) {
198 $rang = $rang == -1 ? $rang : $rang-1;
199 $result = $this->addline(
214 SUBTOTALS_SPECIAL_CODE
216 $this->fetch_lines();
217 } elseif ($current_module ==
'supplier_proposal' && $this instanceof
SupplierProposal) {
218 $rang = $rang == -1 ? $rang : $rang-1;
219 $result = $this->addline(
233 SUBTOTALS_SPECIAL_CODE
236 $rang = $rang == -1 ? $rang : $rang-1;
237 $result = $this->addline(
261 SUBTOTALS_SPECIAL_CODE
263 } elseif ($current_module ==
'invoice_supplier' && $this instanceof
FactureFournisseur) {
264 $rang = $rang == -1 ? $rang : $rang-1;
265 $result = $this->addline(
287 SUBTOTALS_SPECIAL_CODE
289 } elseif ($current_module ==
'fichinter' && $this instanceof
Fichinter) {
291 $result = $this->addline(
300 SUBTOTALS_SPECIAL_CODE
305 if ($current_module !=
'shipping') {
306 foreach ($this->lines as $line) {
307 '@phan-var-force CommonObjectLine $line';
309 if ($line->id == $result) {
310 $line->extraparams[
"subtotal"] = $options;
311 $line->setExtraParameters();
320 return $error > 0 ? 0 : $result;
336 public function deleteSubtotalLine($langs,
$id, $correspondingstline =
false, $user =
null)
338 $current_module = $this->element;
340 if (!in_array($current_module, self::$ALLOWED_TYPES)) {
341 $this->errors[] = $langs->trans(
"UnsupportedModuleError");
347 if ($correspondingstline) {
350 foreach ($this->lines as $line) {
351 if ($line->id ==
$id) {
352 $oldDesc = $line->desc;
353 $oldDepth = $line->qty;
355 if ($line->special_code == SUBTOTALS_SPECIAL_CODE && $line->qty == -$oldDepth && $line->desc == $oldDesc) {
356 $this->deleteSubtotalLine($langs, $line->id,
false, $user);
363 if ($current_module ==
'facture' && $this instanceof
Facture) {
365 $result = $this->deleteLine($rowid);
366 } elseif ($current_module ==
'propal' && $this instanceof
Propal) {
368 $result = $this->deleteLine($rowid);
369 } elseif ($current_module ==
'commande' && $this instanceof
Commande) {
371 $result = $this->deleteLine($user, $lineid);
372 } elseif ($current_module ==
'facturerec') {
375 $result = $line->delete($user);
376 } elseif ($current_module ==
'shipping') {
379 $result = $line->delete($user);
380 } elseif ($current_module ==
'supplier_proposal') {
383 $result = $line->delete($user);
384 } elseif ($current_module ==
'order_supplier') {
387 $result = $line->delete($user);
388 } elseif ($current_module ==
'invoice_supplier') {
391 $result = $line->delete();
392 } elseif ($current_module ==
'fichinter') {
395 $result = $line->deleteLine($user);
398 return $result >= 0 ? $result : -1;
416 public function updateSubtotalLine($langs, $lineid, $desc, $depth, $options)
418 $current_module = $this->element;
420 if (!in_array($current_module, self::$ALLOWED_TYPES)) {
421 $this->errors[] = $langs->trans(
"UnsupportedModuleError");
428 $max_existing_level = 0;
431 foreach ($this->lines as $line) {
432 if ($line->special_code == SUBTOTALS_SPECIAL_CODE && $line->qty > $max_existing_level && $line->id != $lineid) {
433 $max_existing_level = $line->qty;
438 if ($max_existing_level+1 < $depth) {
439 $depth = $max_existing_level+1;
440 $this->errors[] = $langs->trans(
"TitleEditedLevelTooHigh");
447 foreach ($this->lines as $line) {
448 if ($line->id == $lineid) {
449 $oldDesc = $line->desc;
450 $oldDepth = $line->qty;
452 if ($line->special_code == SUBTOTALS_SPECIAL_CODE && $line->qty == -$oldDepth && $line->desc == $oldDesc) {
453 $this->updateSubtotalLine($langs, $line->id, $desc, -$depth, !empty($line->extraparams[
"subtotal"]) ? $line->extraparams[
"subtotal"] : array());
460 if ($current_module ==
'facture' && $this instanceof
Facture) {
461 $result = $this->updateline(
480 SUBTOTALS_SPECIAL_CODE
482 } elseif ($current_module ==
'propal' && $this instanceof
Propal) {
483 $result = $this->updateline(
494 SUBTOTALS_SPECIAL_CODE,
502 } elseif ($current_module ==
'commande' && $this instanceof
Commande) {
503 $result = $this->updateline(
522 SUBTOTALS_SPECIAL_CODE
524 } elseif ($current_module ==
'facturerec' && $this instanceof
FactureRec) {
526 $objectline->fetch($lineid);
527 $line_rang = $objectline->rang;
528 $result = $this->updateline(
544 SUBTOTALS_SPECIAL_CODE
546 } elseif ($current_module ==
'supplier_proposal' && $this instanceof
SupplierProposal) {
548 $objectline->fetch($lineid);
549 $line_rang = $objectline->rang;
550 $result = $this->updateline(
561 SUBTOTALS_SPECIAL_CODE,
571 $objectline->fetch($lineid);
572 $line_rang = $objectline->rang;
574 $result = $this->updateline(
592 } elseif ($current_module ==
'invoice_supplier' && $this instanceof
FactureFournisseur) {
594 $objectline->fetch($lineid);
595 $line_rang = $objectline->rang;
596 $result = $this->updateline(
612 foreach ($this->lines as $line) {
613 '@phan-var-force CommonObjectLine $line';
615 if ($line->id == $lineid) {
616 $line->extraparams[
"subtotal"] = $options;
617 $line->setExtraParameters();
625 return $error > 0 ? 0 : $result;
640 public function updateSubtotalLineBlockLines($langs, $linerang, $mode, $value)
642 $current_module = $this->element;
644 if (!in_array($current_module, self::$ALLOWED_TYPES)) {
645 $this->errors[] = $langs->trans(
"UnsupportedModuleError");
652 $nb_lines = count($this->lines)+1;
654 for ($i = $linerang+1; $i < $nb_lines; $i++) {
655 if ($this->lines[$i]->special_code == SUBTOTALS_SPECIAL_CODE) {
656 if (abs($this->lines[$i]->qty) <= (
int) $this->lines[$linerang]->qty) {
660 if ($current_module ==
'facture' && $this instanceof
Facture) {
662 $line_price_base_type = $this->lines[$i]->getPriceBaseType();
663 $line_pu = ($line_price_base_type ===
'TTC') ? $this->lines[$i]->subprice_ttc : $this->lines[$i]->subprice;
664 $result = $this->updateline(
665 $this->lines[$i]->
id,
666 $this->lines[$i]->desc,
668 $this->lines[$i]->qty,
669 $mode ==
'discount' ? $value : $this->lines[$i]->remise_percent,
670 $this->lines[$i]->date_start,
671 $this->lines[$i]->date_end,
672 $mode ==
'tva' ? $value : $this->lines[$i]->tva_tx,
673 $this->lines[$i]->localtax1_tx,
674 $this->lines[$i]->localtax2_tx,
675 $line_price_base_type,
676 $this->lines[$i]->info_bits,
677 $this->lines[$i]->product_type,
678 $this->lines[$i]->fk_parent_line,
680 $this->lines[$i]->fk_fournprice,
681 $this->lines[$i]->pa_ht,
682 $this->lines[$i]->label,
683 $this->lines[$i]->special_code,
684 $this->lines[$i]->array_options,
685 $this->lines[$i]->situation_percent,
686 $this->lines[$i]->fk_unit,
687 $this->lines[$i]->multicurrency_subprice
689 } elseif ($current_module ==
'commande' && $this instanceof
Commande) {
691 $line_price_base_type = $this->lines[$i]->getPriceBaseType();
692 $line_pu = ($line_price_base_type ===
'TTC') ? $this->lines[$i]->subprice_ttc : $this->lines[$i]->subprice;
693 $result = $this->updateline(
694 $this->lines[$i]->
id,
695 $this->lines[$i]->desc,
697 $this->lines[$i]->qty,
698 $mode ==
'discount' ? $value : $this->lines[$i]->remise_percent,
699 $mode ==
'tva' ? $value : $this->lines[$i]->tva_tx,
700 $this->lines[$i]->localtax1_rate,
701 $this->lines[$i]->localtax2_rate,
702 $line_price_base_type,
703 $this->lines[$i]->info_bits,
704 $this->lines[$i]->date_start,
705 $this->lines[$i]->date_end,
706 $this->lines[$i]->product_type,
707 $this->lines[$i]->fk_parent_line,
709 $this->lines[$i]->fk_fournprice,
710 $this->lines[$i]->pa_ht,
711 $this->lines[$i]->label,
712 $this->lines[$i]->special_code,
713 $this->lines[$i]->array_options,
714 $this->lines[$i]->fk_unit,
715 $this->lines[$i]->multicurrency_subprice
717 } elseif ($current_module ==
'propal' && $this instanceof
Propal) {
719 $line_price_base_type = $this->lines[$i]->getPriceBaseType();
720 $line_pu = ($line_price_base_type ===
'TTC') ? $this->lines[$i]->subprice_ttc : $this->lines[$i]->subprice;
721 $result = $this->updateline(
722 $this->lines[$i]->
id,
724 $this->lines[$i]->qty,
725 $mode ==
'discount' ? $value : $this->lines[$i]->remise_percent,
726 $mode ==
'tva' ? $value : $this->lines[$i]->tva_tx,
727 $this->lines[$i]->localtax1_rate,
728 $this->lines[$i]->localtax2_rate,
729 $this->lines[$i]->desc,
730 $line_price_base_type,
731 $this->lines[$i]->info_bits,
732 $this->lines[$i]->special_code,
733 $this->lines[$i]->fk_parent_line,
735 $this->lines[$i]->fk_fournprice,
736 $this->lines[$i]->pa_ht,
737 $this->lines[$i]->label,
738 $this->lines[$i]->product_type,
739 $this->lines[$i]->date_start,
740 $this->lines[$i]->date_end,
741 $this->lines[$i]->array_options,
742 $this->lines[$i]->fk_unit,
743 $this->lines[$i]->multicurrency_subprice
763 public function getSubtotalLineAmount($line)
766 for ($i = $line->rang-1; $i > 0; $i--) {
767 if (is_null($this->lines[$i-1]) || $this->lines[$i-1]->rang >= $line->rang) {
770 if ($this->lines[$i-1]->special_code == SUBTOTALS_SPECIAL_CODE && $this->lines[$i-1]->qty > 0) {
771 if ($this->lines[$i-1]->qty <= abs($line->qty)) {
772 return price($final_amount);
775 $final_amount += $this->lines[$i-1]->total_ht;
778 return price($final_amount);
790 public function getSubtotalLineMulticurrencyAmount($line)
793 for ($i = $line->rang-1; $i > 0; $i--) {
794 if (is_null($this->lines[$i-1]) || $this->lines[$i-1]->rang >= $line->rang) {
797 if ($this->lines[$i-1]->special_code == SUBTOTALS_SPECIAL_CODE && $this->lines[$i-1]->qty>0) {
798 if ($this->lines[$i-1]->qty <= abs($line->qty)) {
799 return price($final_amount);
802 $final_amount += $this->lines[$i-1]->multicurrency_total_ht;
805 return price($final_amount);
814 public function getSubtotalColors($level)
826 public function getPossibleTitles()
829 foreach ($this->lines as $line) {
830 if ($line->special_code == SUBTOTALS_SPECIAL_CODE && $line->qty > 0) {
831 $titles[$line->desc] = $line->desc;
833 if ($line->special_code == SUBTOTALS_SPECIAL_CODE && $line->qty < 0) {
834 unset($titles[$line->desc]);
848 public function getPossibleLevels($langs)
850 $depth_array = array();
851 $max_depth =
getDolGlobalString(
'SUBTOTAL_'.strtoupper($this->element).
'_MAX_DEPTH', 2);
852 for ($i = 0; $i < $max_depth; $i++) {
853 $depth_array[$i + 1] = $langs->trans(
"SubtotalLevel", $i + 1);
866 public function getPredefinedTitles()
870 $sql =
"SELECT label FROM ".MAIN_DB_PREFIX.
"c_subtotals_titles";
871 $sql .=
" WHERE active = 1 AND entity IN (".getEntity(
'c_subtotals_titles').
")";
872 $sql .=
" ORDER BY label ASC";
874 $resql = $this->db->query($sql);
876 while ($obj = $this->db->fetch_object($resql)) {
892 public function getPredefinedTexts()
896 $sql =
"SELECT rowid, label, content FROM ".MAIN_DB_PREFIX.
"c_subtotals_texts";
897 $sql .=
" WHERE active = 1 AND entity IN (".getEntity(
'c_subtotals_texts').
")";
898 $sql .=
" ORDER BY label ASC";
900 $resql = $this->db->query($sql);
902 while ($obj = $this->db->fetch_object($resql)) {
903 $texts[(int) $obj->rowid] = array(
'label' => $obj->label,
'content' => $obj->content);
917 public function getDisabledShippmentSubtotalLines()
919 $toDisableLines = array();
924 foreach ($this->lines as $titleLine) {
925 if ($titleLine->special_code != SUBTOTALS_SPECIAL_CODE || $titleLine->qty <= 0) {
928 foreach ($this->lines as $line) {
929 if ($line->id == $titleLine->id) {
930 $oldDesc = $line->desc;
931 $oldDepth = $line->qty;
933 if ($line->special_code != SUBTOTALS_SPECIAL_CODE && $line->fk_product_type == 0 && !empty($oldDesc) && !empty($oldDepth)) {
936 if ($line->special_code == SUBTOTALS_SPECIAL_CODE && $line->qty == -$oldDepth && $line->desc == $oldDesc) {
938 $toDisableLines = array_merge($toDisableLines, array($titleLine->id, $line->id));
947 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 intervention lines.
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.
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...