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