dolibarr  19.0.0-dev
object_discounts.tpl.php
1 <?php
2 /* Copyright (C) 2018 ATM Consulting <support@atm-consulting.fr>
3  * Copyright (C) 2021 Frédéric France <frederic.france@netlogic.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 
28 print '<!-- 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
35 if (!isset($absolute_discount)) {
36  $absolute_discount = 0;
37 }
38 if (!isset($absolute_creditnote)) {
39  $absolute_creditnote = 0;
40 }
41 
42 // Relative and absolute discounts
43 $addrelativediscount = '<a href="'.DOL_URL_ROOT.'/comm/remise.php?id='.((int) $thirdparty->id).'&backtopage='.urlencode($backtopage).'&action=create&token='.newToken().'">'.$langs->trans("EditRelativeDiscount").'</a>';
44 $addabsolutediscount = '<a href="'.DOL_URL_ROOT.'/comm/remx.php?id='.((int) $thirdparty->id).'&backtopage='.urlencode($backtopage).'&action=create&token='.newToken().'">'.$langs->trans("EditGlobalDiscounts").'</a>';
45 $viewabsolutediscount = '<a href="'.DOL_URL_ROOT.'/comm/remx.php?id='.((int) $thirdparty->id).'&backtopage='.urlencode($backtopage).'">'.$langs->trans("ViewAvailableGlobalDiscounts").'</a>';
46 
47 $fixedDiscount = $thirdparty->remise_percent;
48 if (!empty($discount_type)) {
49  $fixedDiscount = $thirdparty->remise_supplier_percent;
50 }
51 
52 if ($fixedDiscount > 0) {
53  $translationKey = (!empty($discount_type)) ? 'HasRelativeDiscountFromSupplier' : 'CompanyHasRelativeDiscount';
54  print $langs->trans($translationKey, $fixedDiscount).'.';
55 } else {
56  $translationKey = (!empty($discount_type)) ? 'HasNoRelativeDiscountFromSupplier' : 'CompanyHasNoRelativeDiscount';
57  print '<span class="opacitymedium hideonsmartphone">'.$langs->trans($translationKey).'.</span>';
58 }
59 if ($isNewObject) {
60  print ' ('.$addrelativediscount.')';
61 }
62 
63 // Is there is commercial discount or down payment available ?
64 if ($absolute_discount > 0) {
65  if (!empty($cannotApplyDiscount) || !$isInvoice || $isNewObject || $object->statut > $objclassname::STATUS_DRAFT || $object->type == $objclassname::TYPE_CREDIT_NOTE || $object->type == $objclassname::TYPE_DEPOSIT) {
66  $translationKey = !empty($discount_type) ? 'HasAbsoluteDiscountFromSupplier' : 'CompanyHasAbsoluteDiscount';
67  $text = $langs->trans($translationKey, price($absolute_discount), $langs->transnoentities("Currency".$conf->currency)).'.';
68 
69  if ($isInvoice && !$isNewObject && $object->statut > $objclassname::STATUS_DRAFT && $object->type != $objclassname::TYPE_CREDIT_NOTE && $object->type != $objclassname::TYPE_DEPOSIT) {
70  $text = $form->textwithpicto($text, $langs->trans('AbsoluteDiscountUse'));
71  }
72 
73  if ($isNewObject) {
74  $text .= ' ('.$addabsolutediscount.')';
75  }
76 
77  if ($isNewObject) {
78  print '<br>'.$text;
79  } else {
80  print '<div class="inline-block clearboth">'.$text.'</div>';
81  }
82  } else {
83  // Discount available of type fixed amount (not credit note)
84  $more = '('.$addabsolutediscount.')';
85  $form->form_remise_dispo($_SERVER["PHP_SELF"].'?facid='.$object->id, GETPOST('discountid'), 'remise_id', $thirdparty->id, $absolute_discount, $filterabsolutediscount, $resteapayer, $more, 0, $discount_type);
86  }
87 }
88 
89 // Is there credit notes availables ?
90 if ($absolute_creditnote > 0) {
91  // If validated, we show link "add credit note to payment"
92  if (!empty($cannotApplyDiscount) || !$isInvoice || $isNewObject || $object->statut != $objclassname::STATUS_VALIDATED || $object->type == $objclassname::TYPE_CREDIT_NOTE) {
93  $translationKey = !empty($discount_type) ? 'HasCreditNoteFromSupplier' : 'CompanyHasCreditNote';
94  $text = $langs->trans($translationKey, price($absolute_creditnote), $langs->transnoentities("Currency".$conf->currency)).'.';
95 
96  if ($isInvoice && !$isNewObject && $object->statut == $objclassname::STATUS_DRAFT && $object->type != $objclassname::TYPE_DEPOSIT) {
97  $text = $form->textwithpicto($text, $langs->trans('CreditNoteDepositUse'));
98  }
99 
100  if ($absolute_discount <= 0 || $isNewObject) {
101  $text .= ' ('.$addabsolutediscount.')';
102  }
103 
104  if ($isNewObject) {
105  print '<br>'.$text;
106  } else {
107  print '<div class="inline-block clearboth">'.$text.'</div>';
108  }
109  } else { // We can add a credit note on a down payment or standard invoice or situation invoice
110  // There is credit notes discounts available
111  $more = $isInvoice && !$isNewObject ? ' ('.$viewabsolutediscount.')' : '';
112  $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
113  }
114 }
115 
116 if ($absolute_discount <= 0 && $absolute_creditnote <= 0) {
117  $translationKey = !empty($discount_type) ? 'HasNoAbsoluteDiscountFromSupplier' : 'CompanyHasNoAbsoluteDiscount';
118  print '<br class="hideonsmartphone"><span class="opacitymedium hideonsmartphone">'.$langs->trans($translationKey).'.</span>';
119 
120  if ($isInvoice && $object->statut == $objclassname::STATUS_DRAFT && $object->type != $objclassname::TYPE_CREDIT_NOTE && $object->type != $objclassname::TYPE_DEPOSIT) {
121  print ' ('.$addabsolutediscount.')';
122  }
123 }
124 
125 print '<!-- END template -->';
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
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.