object_discounts.tpl.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. print '<!-- BEGIN object_discounts.tpl.php -->'."\n";
  28. $objclassname = get_class($object);
  29. $isInvoice = in_array($object->element, array('facture', 'invoice', 'facture_fourn', 'invoice_supplier'));
  30. $isNewObject = empty($object->id) && empty($object->rowid);
  31. // Clean variables not defined
  32. if (!isset($absolute_discount)) {
  33. $absolute_discount = 0;
  34. }
  35. if (!isset($absolute_creditnote)) {
  36. $absolute_creditnote = 0;
  37. }
  38. // Relative and absolute discounts
  39. $addrelativediscount = '<a href="'.DOL_URL_ROOT.'/comm/remise.php?id='.$thirdparty->id.'&backtopage='.$backtopage.'&action=create&token='.newToken().'">'.$langs->trans("EditRelativeDiscount").'</a>';
  40. $addabsolutediscount = '<a href="'.DOL_URL_ROOT.'/comm/remx.php?id='.$thirdparty->id.'&backtopage='.$backtopage.'&action=create&token='.newToken().'">'.$langs->trans("EditGlobalDiscounts").'</a>';
  41. $viewabsolutediscount = '<a href="'.DOL_URL_ROOT.'/comm/remx.php?id='.$thirdparty->id.'&backtopage='.$backtopage.'">'.$langs->trans("ViewAvailableGlobalDiscounts").'</a>';
  42. $fixedDiscount = $thirdparty->remise_percent;
  43. if (!empty($discount_type)) {
  44. $fixedDiscount = $thirdparty->remise_supplier_percent;
  45. }
  46. if ($fixedDiscount > 0) {
  47. $translationKey = (!empty($discount_type)) ? 'HasRelativeDiscountFromSupplier' : 'CompanyHasRelativeDiscount';
  48. print $langs->trans($translationKey, $fixedDiscount).'.';
  49. } else {
  50. $translationKey = (!empty($discount_type)) ? 'HasNoRelativeDiscountFromSupplier' : 'CompanyHasNoRelativeDiscount';
  51. print '<span class="opacitymedium hideonsmartphone">'.$langs->trans($translationKey).'.</span>';
  52. }
  53. if ($isNewObject) {
  54. print ' ('.$addrelativediscount.')';
  55. }
  56. // Is there is commercial discount or down payment available ?
  57. if ($absolute_discount > 0) {
  58. if (!empty($cannotApplyDiscount) || !$isInvoice || $isNewObject || $object->statut > $objclassname::STATUS_DRAFT || $object->type == $objclassname::TYPE_CREDIT_NOTE || $object->type == $objclassname::TYPE_DEPOSIT) {
  59. $translationKey = !empty($discount_type) ? 'HasAbsoluteDiscountFromSupplier' : 'CompanyHasAbsoluteDiscount';
  60. $text = $langs->trans($translationKey, price($absolute_discount), $langs->transnoentities("Currency".$conf->currency)).'.';
  61. if ($isInvoice && !$isNewObject && $object->statut > $objclassname::STATUS_DRAFT && $object->type != $objclassname::TYPE_CREDIT_NOTE && $object->type != $objclassname::TYPE_DEPOSIT) {
  62. $text = $form->textwithpicto($text, $langs->trans('AbsoluteDiscountUse'));
  63. }
  64. if ($isNewObject) {
  65. $text .= ' ('.$addabsolutediscount.')';
  66. }
  67. if ($isNewObject) {
  68. print '<br>'.$text;
  69. } else {
  70. print '<div class="inline-block clearboth">'.$text.'</div>';
  71. }
  72. } else {
  73. // Discount available of type fixed amount (not credit note)
  74. $more = '('.$addabsolutediscount.')';
  75. $form->form_remise_dispo($_SERVER["PHP_SELF"].'?facid='.$object->id, GETPOST('discountid'), 'remise_id', $thirdparty->id, $absolute_discount, $filterabsolutediscount, $resteapayer, $more, 0, $discount_type);
  76. }
  77. }
  78. // Is there credit notes availables ?
  79. if ($absolute_creditnote > 0) {
  80. // If validated, we show link "add credit note to payment"
  81. if (!empty($cannotApplyDiscount) || !$isInvoice || $isNewObject || $object->statut != $objclassname::STATUS_VALIDATED || $object->type == $objclassname::TYPE_CREDIT_NOTE) {
  82. $translationKey = !empty($discount_type) ? 'HasCreditNoteFromSupplier' : 'CompanyHasCreditNote';
  83. $text = $langs->trans($translationKey, price($absolute_creditnote), $langs->transnoentities("Currency".$conf->currency)).'.';
  84. if ($isInvoice && !$isNewObject && $object->statut == $objclassname::STATUS_DRAFT && $object->type != $objclassname::TYPE_DEPOSIT) {
  85. $text = $form->textwithpicto($text, $langs->trans('CreditNoteDepositUse'));
  86. }
  87. if ($absolute_discount <= 0 || $isNewObject) {
  88. $text .= ' ('.$addabsolutediscount.')';
  89. }
  90. if ($isNewObject) {
  91. print '<br>'.$text;
  92. } else {
  93. print '<div class="inline-block clearboth">'.$text.'</div>';
  94. }
  95. } else { // We can add a credit note on a down payment or standard invoice or situation invoice
  96. // There is credit notes discounts available
  97. $more = $isInvoice && !$isNewObject ? ' ('.$viewabsolutediscount.')' : '';
  98. $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
  99. }
  100. }
  101. if ($absolute_discount <= 0 && $absolute_creditnote <= 0) {
  102. $translationKey = !empty($discount_type) ? 'HasNoAbsoluteDiscountFromSupplier' : 'CompanyHasNoAbsoluteDiscount';
  103. print '<br class="hideonsmartphone"><span class="opacitymedium hideonsmartphone">'.$langs->trans($translationKey).'.</span>';
  104. if ($isInvoice && $object->statut == $objclassname::STATUS_DRAFT && $object->type != $objclassname::TYPE_CREDIT_NOTE && $object->type != $objclassname::TYPE_DEPOSIT) {
  105. print ' ('.$addabsolutediscount.')';
  106. }
  107. }
  108. print '<!-- END template -->';