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