dolibarr 25.0.0-alpha
object_discounts.tpl.php
1<?php
2
3/* Copyright (C) 2018 ATM Consulting <support@atm-consulting.fr>
4 * Copyright (C) 2021-2024 Frédéric France <frederic.france@free.fr>
5 * Copyright (C) 2025-2026 MDW <mdeweerd@users.noreply.github.com>
6 * Copyright (C) 2026 José MARTINEZ <jose.martinez@pichinov.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 *
21 * Needs the following variables defined:
22 * $object Proposal, order, invoice (including supplier versions)
23 * $thirdparty Third party of object
24 * $discount_type 0 => Customer discounts, 1 => Supplier discounts
25 * $backtopage URL to come back to from discount modification pages
26 */
27
46print '<!-- BEGIN object_discounts.tpl.php -->'."\n";
47
48'
49@phan-var-force Propal|Commande|CommandeFournisseur|Facture|FactureFournisseur $object
50@phan-var-force Societe $thirdparty
51@phan-var-force string $backtopage
52@phan-var-force string $filtercreditnote
53@phan-var-force string $filterabsolutediscount
54@phan-var-force int<0,1> $discount_type
55@phan-var-force int $resteapayer
56';
57
58$objclassname = get_class($object);
59$isInvoice = in_array($object->element, array('facture', 'invoice', 'facture_fourn', 'invoice_supplier'));
60$isNewObject = empty($object->id) && empty($object->rowid);
61
62// Clean variables not defined
63if (empty($absolute_discount)) {
64 $absolute_discount = 0;
65}
66if (empty($absolute_creditnote)) {
67 $absolute_creditnote = 0;
68}
69if (empty($nb_creditnote_notyetavailable)) {
70 $nb_creditnote_notyetavailable = 0;
71}
72
73
74// Relative and absolute discounts
75$addrelativediscount = '<a class="editfielda" href="'.DOL_URL_ROOT.'/comm/remise.php?id='.((int) $thirdparty->id).'&backtopage='.urlencode($backtopage).'&action=create&token='.newToken().(!empty($discount_type) ? '&discount_type=1' : '').'">'.img_edit($langs->trans("EditRelativeDiscount")).'</a>';
76$addabsolutediscount = '<a class="editfielda" href="'.DOL_URL_ROOT.'/comm/remx.php?id='.((int) $thirdparty->id).'&backtopage='.urlencode($backtopage).'&action=create&token='.newToken().'">'.img_edit($langs->trans("EditGlobalDiscounts")).'</a>';
77$viewabsolutediscount = '<a class="editfielda" href="'.DOL_URL_ROOT.'/comm/remx.php?id='.((int) $thirdparty->id).'&backtopage='.urlencode($backtopage).'">'.$langs->trans("ViewAvailableGlobalDiscounts").'</a>';
78
79$fixedDiscount = $thirdparty->remise_percent;
80if (!empty($discount_type)) {
81 $fixedDiscount = $thirdparty->remise_supplier_percent;
82}
83
84if ($fixedDiscount > 0) {
85 $translationKey = (empty($discount_type)) ? 'CompanyHasRelativeDiscount' : 'HasRelativeDiscountFromSupplier';
86 print $langs->trans($translationKey, $fixedDiscount);
87} else {
88 if ($conf->dol_optimize_smallscreen) {
89 $translationKey = 'RelativeDiscount';
90 } else {
91 $translationKey = (empty($discount_type)) ? 'CompanyHasNoRelativeDiscount' : 'HasNoRelativeDiscountFromSupplier';
92 }
93 print '<span class="opacitymedium">'.$langs->trans($translationKey).'</span>';
94}
95// Add link to edit the relative discount
96print ' '.$addrelativediscount;
97
98
99// Is there is commercial discount or down payment available ?
100if ($absolute_discount > 0) {
101 print '<!-- absolute_discount -->';
102 if (!empty($cannotApplyDiscount) || !$isInvoice || $isNewObject || $object->statut > $objclassname::STATUS_DRAFT || $object->type == $objclassname::TYPE_CREDIT_NOTE || $object->type == $objclassname::TYPE_DEPOSIT) {
103 $translationKey = empty($discount_type) ? 'CompanyHasDownPaymentOrCommercialDiscount' : 'HasDownPaymentOrCommercialDiscountFromSupplier';
104 $text = $langs->trans($translationKey, price($absolute_discount, 0, $langs, 1, -1, -1, $conf->currency));
105
106 if ($isInvoice && !$isNewObject && $object->statut > $objclassname::STATUS_DRAFT && $object->type != $objclassname::TYPE_CREDIT_NOTE && $object->type != $objclassname::TYPE_DEPOSIT) {
107 $text = $form->textwithpicto($text, $langs->trans('AbsoluteDiscountUse'));
108 }
109 if ($isNewObject) {
110 $text .= ' '.$addabsolutediscount;
111 }
112
113 if ($isNewObject) {
114 print '<br>'.$text;
115 } else {
116 print '<div class="inline-block clearboth">'.$text.'</div>';
117 }
118 } else {
119 // Discount available of type fixed amount (not credit note)
120 $more = $addabsolutediscount;
121 $filter = $filterabsolutediscount; // Fix PhanPluginSuspiciousParamPosition as filterabsolutescount is other argument name in form_remise_dispo
122 // No max value: a credit larger than the remaining amount is now split automatically when it is applied,
123 // only the required part being used. This mirrors what is already done for the credit notes below.
124 $form->form_remise_dispo($_SERVER["PHP_SELF"].'?facid='.$object->id, GETPOSTINT('discountid'), 'remise_id', $thirdparty->id, $absolute_discount, $filter, 0, $more, 0, $discount_type, 1);
125 }
126}
127
128
129// Is there credit notes availables ?
130if ($absolute_creditnote > 0) {
131 print '<!-- absolute_creditnote -->';
132 // If validated, we show link "add credit note to payment"
133 if (!empty($cannotApplyDiscount) || !$isInvoice || $isNewObject || $object->statut != $objclassname::STATUS_VALIDATED || $object->type == $objclassname::TYPE_CREDIT_NOTE) {
134 $translationKey = empty($discount_type) ? 'CompanyHasCreditNote' : 'HasCreditNoteFromSupplier';
135 $text = $langs->trans($translationKey, price($absolute_creditnote, 0, $langs, 1, -1, -1, $conf->currency));
136
137 if ($isInvoice && !$isNewObject && $object->statut == $objclassname::STATUS_DRAFT && $object->type != $objclassname::TYPE_DEPOSIT) {
138 $text = $form->textwithpicto($text, $langs->trans('CreditNoteDepositUse'));
139 }
140
141 if ($absolute_discount <= 0 || $isNewObject) {
142 $text .= ' '.$addabsolutediscount;
143 }
144
145 if ($isNewObject) {
146 print '<br>'.$text;
147 } else {
148 print '<div class="inline-block clearboth">'.$text.'</div>';
149 }
150 } else { // We can add a credit note on a down payment or standard invoice or situation invoice
151 // There is credit notes discounts available
152 $more = $isInvoice && !$isNewObject ? ' ('.$viewabsolutediscount.')' : '';
153 $filter = $filtercreditnote; // Avoid phan suspiscious order as $filtercreditnote is name of last argument for form_remise_dispo
154 $form->form_remise_dispo($_SERVER["PHP_SELF"].'?facid='.$object->id, 0, 'remise_id_for_payment', $thirdparty->id, $absolute_creditnote, $filter, 0, $more, 0, $discount_type, 0, 1); // We allow credit note even if amount is higher
155 }
156}
157
158if ($absolute_discount <= 0 && $absolute_creditnote <= 0) {
159 if ($conf->dol_optimize_smallscreen) {
160 $translationKey = 'AbsoluteDiscount';
161 } else {
162 $translationKey = !empty($discount_type) ? 'HasNoAbsoluteDiscountFromSupplier' : 'CompanyHasNoAbsoluteDiscount';
163 }
164 print '<br><span class="opacitymedium">'.$langs->trans($translationKey).'</span>';
165
166 if ($isInvoice && $object->statut == $objclassname::STATUS_DRAFT && $object->type != $objclassname::TYPE_CREDIT_NOTE && $object->type != $objclassname::TYPE_DEPOSIT) {
167 print ' '.$addabsolutediscount;
168 }
169}
170
171if ($nb_creditnote_notyetavailable > 0) {
172 print '<!-- absolute_creditnote not yet converted -->';
173 $translationKey = 'SomeNotConvertedCreditNoteExists';
174 print '<br><span class="opacitymedium">'.$langs->trans($translationKey, $nb_creditnote_notyetavailable).'</span>';
175}
176
177print '<!-- END template -->';
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
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.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.