dolibarr 20.0.0
object_discounts.tpl.php
1<?php
2/* Copyright (C) 2018 ATM Consulting <support@atm-consulting.fr>
3 * Copyright (C) 2021-2024 Frédéric France <frederic.france@free.fr>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 *
18 * Needs the following variables defined:
19 * $object Proposal, order, invoice (including supplier versions)
20 * $thirdparty Thirdparty of object
21 * $absolute_discount Amount of fixed discounts available
22 * $absolute_creditnote Amount of credit notes available
23 * $discount_type 0 => Customer discounts, 1 => Supplier discounts
24 * $cannotApplyDiscount Set it to prevent form to apply discount
25 * $backtopage URL to come back to from discount modification pages
26 */
27
28print '<!-- BEGIN object_discounts.tpl.php -->'."\n";
29
30$objclassname = get_class($object);
31$isInvoice = in_array($object->element, array('facture', 'invoice', 'facture_fourn', 'invoice_supplier'));
32$isNewObject = empty($object->id) && empty($object->rowid);
33
34// Clean variables not defined
35if (empty($absolute_discount)) {
36 $absolute_discount = 0;
37}
38if (empty($absolute_creditnote)) {
39 $absolute_creditnote = 0;
40}
41
42
43// Relative and absolute discounts
44$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>';
45$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>';
46$viewabsolutediscount = '<a class="editfielda" href="'.DOL_URL_ROOT.'/comm/remx.php?id='.((int) $thirdparty->id).'&backtopage='.urlencode($backtopage).'">'.$langs->trans("ViewAvailableGlobalDiscounts").'</a>';
47
48$fixedDiscount = $thirdparty->remise_percent;
49if (!empty($discount_type)) {
50 $fixedDiscount = $thirdparty->remise_supplier_percent;
51}
52
53if ($fixedDiscount > 0) {
54 $translationKey = (empty($discount_type)) ? 'CompanyHasRelativeDiscount' : 'HasRelativeDiscountFromSupplier';
55 print $langs->trans($translationKey, $fixedDiscount);
56} else {
57 if ($conf->dol_optimize_smallscreen) {
58 $translationKey = 'RelativeDiscount';
59 } else {
60 $translationKey = (empty($discount_type)) ? 'CompanyHasNoRelativeDiscount' : 'HasNoRelativeDiscountFromSupplier';
61 }
62 print '<span class="opacitymedium">'.$langs->trans($translationKey).'</span>';
63}
64// Add link to edit the relative discount
65print ' '.$addrelativediscount;
66
67
68// Is there is commercial discount or down payment available ?
69if ($absolute_discount > 0) {
70 print '<!-- absolute_discount -->';
71 if (!empty($cannotApplyDiscount) || !$isInvoice || $isNewObject || $object->statut > $objclassname::STATUS_DRAFT || $object->type == $objclassname::TYPE_CREDIT_NOTE || $object->type == $objclassname::TYPE_DEPOSIT) {
72 $translationKey = empty($discount_type) ? 'CompanyHasDownPaymentOrCommercialDiscount' : 'HasDownPaymentOrCommercialDiscountFromSupplier';
73 $text = $langs->trans($translationKey, price($absolute_discount, 0, $langs, 1, -1, -1, $conf->currency)).'.';
74
75 if ($isInvoice && !$isNewObject && $object->statut > $objclassname::STATUS_DRAFT && $object->type != $objclassname::TYPE_CREDIT_NOTE && $object->type != $objclassname::TYPE_DEPOSIT) {
76 $text = $form->textwithpicto($text, $langs->trans('AbsoluteDiscountUse'));
77 }
78
79 if ($isNewObject) {
80 $text .= ' '.$addabsolutediscount;
81 }
82
83 if ($isNewObject) {
84 print '<br>'.$text;
85 } else {
86 print '<div class="inline-block clearboth">'.$text.'</div>';
87 }
88 } else {
89 // Discount available of type fixed amount (not credit note)
90 $more = $addabsolutediscount;
91 $form->form_remise_dispo($_SERVER["PHP_SELF"].'?facid='.$object->id, GETPOST('discountid'), 'remise_id', $thirdparty->id, $absolute_discount, $filterabsolutediscount, $resteapayer, $more, 0, $discount_type);
92 }
93}
94
95
96// Is there credit notes availables ?
97if ($absolute_creditnote > 0) {
98 print '<!-- absolute_creditnote -->';
99 // If validated, we show link "add credit note to payment"
100 if (!empty($cannotApplyDiscount) || !$isInvoice || $isNewObject || $object->statut != $objclassname::STATUS_VALIDATED || $object->type == $objclassname::TYPE_CREDIT_NOTE) {
101 $translationKey = empty($discount_type) ? 'CompanyHasCreditNote' : 'HasCreditNoteFromSupplier';
102 $text = $langs->trans($translationKey, price($absolute_creditnote, 0, $langs, 1, -1, -1, $conf->currency));
103
104 if ($isInvoice && !$isNewObject && $object->statut == $objclassname::STATUS_DRAFT && $object->type != $objclassname::TYPE_DEPOSIT) {
105 $text = $form->textwithpicto($text, $langs->trans('CreditNoteDepositUse'));
106 }
107
108 if ($absolute_discount <= 0 || $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 { // We can add a credit note on a down payment or standard invoice or situation invoice
118 // There is credit notes discounts available
119 $more = $isInvoice && !$isNewObject ? ' ('.$viewabsolutediscount.')' : '';
120 $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
121 }
122}
123
124if ($absolute_discount <= 0 && $absolute_creditnote <= 0) {
125 if ($conf->dol_optimize_smallscreen) {
126 $translationKey = 'AbsoluteDiscount';
127 } else {
128 $translationKey = !empty($discount_type) ? 'HasNoAbsoluteDiscountFromSupplier' : 'CompanyHasNoAbsoluteDiscount';
129 }
130 print '<br><span class="opacitymedium">'.$langs->trans($translationKey).'</span>';
131
132 if ($isInvoice && $object->statut == $objclassname::STATUS_DRAFT && $object->type != $objclassname::TYPE_CREDIT_NOTE && $object->type != $objclassname::TYPE_DEPOSIT) {
133 print ' '.$addabsolutediscount;
134 }
135}
136
137print '<!-- END template -->';
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
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'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify fiche.