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