dolibarr 22.0.5
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 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
37print '<!-- BEGIN object_discounts.tpl.php -->'."\n";
38
39'
40@phan-var-force Propal|Commande|CommandeFournisseur|Facture|FactureFournisseur $object
41@phan-var-force Societe $thirdparty
42@phan-var-force string $backtopage
43@phan-var-force string $filtercreditnote
44@phan-var-force string $filterabsolutediscount
45@phan-var-force int<0,1> $discount_type
46@phan-var-force int $resteapayer
47';
48
49$objclassname = get_class($object);
50$isInvoice = in_array($object->element, array('facture', 'invoice', 'facture_fourn', 'invoice_supplier'));
51$isNewObject = empty($object->id) && empty($object->rowid);
52
53// Clean variables not defined
54if (empty($absolute_discount)) {
55 $absolute_discount = 0;
56}
57if (empty($absolute_creditnote)) {
58 $absolute_creditnote = 0;
59}
60
61
62// Relative and absolute discounts
63$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>';
64$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>';
65$viewabsolutediscount = '<a class="editfielda" href="'.DOL_URL_ROOT.'/comm/remx.php?id='.((int) $thirdparty->id).'&backtopage='.urlencode($backtopage).'">'.$langs->trans("ViewAvailableGlobalDiscounts").'</a>';
66
67$fixedDiscount = $thirdparty->remise_percent;
68if (!empty($discount_type)) {
69 $fixedDiscount = $thirdparty->remise_supplier_percent;
70}
71
72if ($fixedDiscount > 0) {
73 $translationKey = (empty($discount_type)) ? 'CompanyHasRelativeDiscount' : 'HasRelativeDiscountFromSupplier';
74 print $langs->trans($translationKey, $fixedDiscount);
75} else {
76 if ($conf->dol_optimize_smallscreen) {
77 $translationKey = 'RelativeDiscount';
78 } else {
79 $translationKey = (empty($discount_type)) ? 'CompanyHasNoRelativeDiscount' : 'HasNoRelativeDiscountFromSupplier';
80 }
81 print '<span class="opacitymedium">'.$langs->trans($translationKey).'</span>';
82}
83// Add link to edit the relative discount
84print ' '.$addrelativediscount;
85
86
87// Is there is commercial discount or down payment available ?
88if ($absolute_discount > 0) {
89 print '<!-- absolute_discount -->';
90 if (!empty($cannotApplyDiscount) || !$isInvoice || $isNewObject || $object->statut > $objclassname::STATUS_DRAFT || $object->type == $objclassname::TYPE_CREDIT_NOTE || $object->type == $objclassname::TYPE_DEPOSIT) {
91 $translationKey = empty($discount_type) ? 'CompanyHasDownPaymentOrCommercialDiscount' : 'HasDownPaymentOrCommercialDiscountFromSupplier';
92 $text = $langs->trans($translationKey, price($absolute_discount, 0, $langs, 1, -1, -1, $conf->currency));
93
94 if ($isInvoice && !$isNewObject && $object->statut > $objclassname::STATUS_DRAFT && $object->type != $objclassname::TYPE_CREDIT_NOTE && $object->type != $objclassname::TYPE_DEPOSIT) {
95 $text = $form->textwithpicto($text, $langs->trans('AbsoluteDiscountUse'));
96 }
97 if ($isNewObject) {
98 $text .= ' '.$addabsolutediscount;
99 }
100
101 if ($isNewObject) {
102 print '<br>'.$text;
103 } else {
104 print '<div class="inline-block clearboth">'.$text.'</div>';
105 }
106 } else {
107 // Discount available of type fixed amount (not credit note)
108 $more = $addabsolutediscount;
109 // TODO: Check $resteapayer - is '$maxvalue' in form_remise_dispo()
110 $form->form_remise_dispo($_SERVER["PHP_SELF"].'?facid='.$object->id, GETPOSTINT('discountid'), 'remise_id', $thirdparty->id, $absolute_discount, $filterabsolutediscount, $resteapayer, $more, 0, $discount_type);
111 }
112}
113
114
115// Is there credit notes availables ?
116if ($absolute_creditnote > 0) {
117 print '<!-- absolute_creditnote -->';
118 // If validated, we show link "add credit note to payment"
119 if (!empty($cannotApplyDiscount) || !$isInvoice || $isNewObject || $object->statut != $objclassname::STATUS_VALIDATED || $object->type == $objclassname::TYPE_CREDIT_NOTE) {
120 $translationKey = empty($discount_type) ? 'CompanyHasCreditNote' : 'HasCreditNoteFromSupplier';
121 $text = $langs->trans($translationKey, price($absolute_creditnote, 0, $langs, 1, -1, -1, $conf->currency));
122
123 if ($isInvoice && !$isNewObject && $object->statut == $objclassname::STATUS_DRAFT && $object->type != $objclassname::TYPE_DEPOSIT) {
124 $text = $form->textwithpicto($text, $langs->trans('CreditNoteDepositUse'));
125 }
126
127 if ($absolute_discount <= 0 || $isNewObject) {
128 $text .= ' '.$addabsolutediscount;
129 }
130
131 if ($isNewObject) {
132 print '<br>'.$text;
133 } else {
134 print '<div class="inline-block clearboth">'.$text.'</div>';
135 }
136 } else { // We can add a credit note on a down payment or standard invoice or situation invoice
137 // There is credit notes discounts available
138 $more = $isInvoice && !$isNewObject ? ' ('.$viewabsolutediscount.')' : '';
139 $form->form_remise_dispo($_SERVER["PHP_SELF"].'?facid='.$object->id, 0, 'remise_id_for_payment', $thirdparty->id, $absolute_creditnote, $filtercreditnote, 0, $more, 0, $discount_type); // We allow credit note even if amount is higher
140 }
141}
142
143if ($absolute_discount <= 0 && $absolute_creditnote <= 0) {
144 if ($conf->dol_optimize_smallscreen) {
145 $translationKey = 'AbsoluteDiscount';
146 } else {
147 $translationKey = !empty($discount_type) ? 'HasNoAbsoluteDiscountFromSupplier' : 'CompanyHasNoAbsoluteDiscount';
148 }
149 print '<br><span class="opacitymedium">'.$langs->trans($translationKey).'</span>';
150
151 if ($isInvoice && $object->statut == $objclassname::STATUS_DRAFT && $object->type != $objclassname::TYPE_CREDIT_NOTE && $object->type != $objclassname::TYPE_DEPOSIT) {
152 print ' '.$addabsolutediscount;
153 }
154}
155
156print '<!-- END template -->';
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:67
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.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify fiche.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79