2018-03-02 16:48:25 +01:00
< ? php
/* Copyright ( C ) 2018 ATM Consulting < support @ atm - consulting . fr >
2021-10-31 19:36:31 +01:00
* Copyright ( C ) 2021 Frédéric France < frederic . france @ netlogic . fr >
2018-03-02 16:48:25 +01:00
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation ; either version 3 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
2019-09-23 21:55:30 +02:00
* along with this program . If not , see < https :// www . gnu . org / licenses />.
2018-03-02 16:48:25 +01:00
*
* Needs the following variables defined :
* $object Proposal , order , invoice ( including supplier versions )
* $thirdparty Thirdparty of object
* $absolute_discount Amount of fixed discounts available
* $absolute_creditnote Amount of credit notes available
* $discount_type 0 => Customer discounts , 1 => Supplier discounts
* $cannotApplyDiscount Set it to prevent form to apply discount
* $backtopage URL to come back to from discount modification pages
*/
2021-02-10 18:03:45 +01:00
print '<!-- BEGIN object_discounts.tpl.php -->' . " \n " ;
2019-07-15 10:19:06 +02:00
$objclassname = get_class ( $object );
2018-03-02 16:48:25 +01:00
$isInvoice = in_array ( $object -> element , array ( 'facture' , 'invoice' , 'facture_fourn' , 'invoice_supplier' ));
$isNewObject = empty ( $object -> id ) && empty ( $object -> rowid );
2021-09-01 17:33:18 +02:00
// Clean variables not defined
if ( ! isset ( $absolute_discount )) {
$absolute_discount = 0 ;
}
if ( ! isset ( $absolute_creditnote )) {
$absolute_creditnote = 0 ;
}
2021-09-01 17:35:23 +02:00
2018-03-02 16:48:25 +01:00
// Relative and absolute discounts
2021-12-16 13:35:17 +01:00
$addrelativediscount = '<a href="' . DOL_URL_ROOT . '/comm/remise.php?id=' . $thirdparty -> id . '&backtopage=' . $backtopage . '&action=create&token=' . newToken () . '">' . $langs -> trans ( " EditRelativeDiscount " ) . '</a>' ;
$addabsolutediscount = '<a href="' . DOL_URL_ROOT . '/comm/remx.php?id=' . $thirdparty -> id . '&backtopage=' . $backtopage . '&action=create&token=' . newToken () . '">' . $langs -> trans ( " EditGlobalDiscounts " ) . '</a>' ;
2019-11-14 12:09:15 +01:00
$viewabsolutediscount = '<a href="' . DOL_URL_ROOT . '/comm/remx.php?id=' . $thirdparty -> id . '&backtopage=' . $backtopage . '">' . $langs -> trans ( " ViewAvailableGlobalDiscounts " ) . '</a>' ;
2018-03-02 16:48:25 +01:00
$fixedDiscount = $thirdparty -> remise_percent ;
2019-11-14 12:09:15 +01:00
if ( ! empty ( $discount_type )) {
2018-03-02 16:48:25 +01:00
$fixedDiscount = $thirdparty -> remise_supplier_percent ;
}
2021-02-23 22:03:23 +01:00
if ( $fixedDiscount > 0 ) {
2019-11-14 12:09:15 +01:00
$translationKey = ( ! empty ( $discount_type )) ? 'HasRelativeDiscountFromSupplier' : 'CompanyHasRelativeDiscount' ;
2018-03-02 16:48:25 +01:00
print $langs -> trans ( $translationKey , $fixedDiscount ) . '.' ;
2020-05-21 15:05:19 +02:00
} else {
2019-11-14 12:09:15 +01:00
$translationKey = ( ! empty ( $discount_type )) ? 'HasNoRelativeDiscountFromSupplier' : 'CompanyHasNoRelativeDiscount' ;
2020-11-29 15:16:53 +01:00
print '<span class="opacitymedium">' . $langs -> trans ( $translationKey ) . '.</span>' ;
2018-04-06 20:18:36 +02:00
}
2021-02-23 22:03:23 +01:00
if ( $isNewObject ) {
print ' (' . $addrelativediscount . ')' ;
}
2018-03-02 16:48:25 +01:00
// Is there is commercial discount or down payment available ?
if ( $absolute_discount > 0 ) {
2021-06-28 20:00:10 +02:00
if ( ! empty ( $cannotApplyDiscount ) || ! $isInvoice || $isNewObject || $object -> statut > $objclassname :: STATUS_DRAFT || $object -> type == $objclassname :: TYPE_CREDIT_NOTE || $object -> type == $objclassname :: TYPE_DEPOSIT ) {
2019-11-14 12:09:15 +01:00
$translationKey = ! empty ( $discount_type ) ? 'HasAbsoluteDiscountFromSupplier' : 'CompanyHasAbsoluteDiscount' ;
$text = $langs -> trans ( $translationKey , price ( $absolute_discount ), $langs -> transnoentities ( " Currency " . $conf -> currency )) . '.' ;
2018-03-02 16:48:25 +01:00
2019-11-14 12:09:15 +01:00
if ( $isInvoice && ! $isNewObject && $object -> statut > $objclassname :: STATUS_DRAFT && $object -> type != $objclassname :: TYPE_CREDIT_NOTE && $object -> type != $objclassname :: TYPE_DEPOSIT ) {
2018-03-02 16:48:25 +01:00
$text = $form -> textwithpicto ( $text , $langs -> trans ( 'AbsoluteDiscountUse' ));
}
2018-04-06 20:18:36 +02:00
2018-03-02 16:48:25 +01:00
if ( $isNewObject ) {
2019-11-14 12:09:15 +01:00
$text .= ' (' . $addabsolutediscount . ')' ;
2018-03-02 16:48:25 +01:00
}
2021-01-04 15:32:18 +01:00
if ( $isNewObject ) {
print '<br>' . $text ;
} else {
print '<div class="inline-block clearboth">' . $text . '</div>' ;
}
2018-03-02 16:48:25 +01:00
} else {
// Discount available of type fixed amount (not credit note)
2019-11-14 12:09:15 +01:00
$more = '(' . $addabsolutediscount . ')' ;
$form -> form_remise_dispo ( $_SERVER [ " PHP_SELF " ] . '?facid=' . $object -> id , GETPOST ( 'discountid' ), 'remise_id' , $thirdparty -> id , $absolute_discount , $filterabsolutediscount , $resteapayer , $more , 0 , $discount_type );
2018-03-02 16:48:25 +01:00
}
}
// Is there credit notes availables ?
2021-09-01 17:33:18 +02:00
if ( $absolute_creditnote > 0 ) {
2018-03-02 16:48:25 +01:00
// If validated, we show link "add credit note to payment"
2021-10-31 19:36:31 +01:00
if ( ! empty ( $cannotApplyDiscount ) || ! $isInvoice || $isNewObject || $object -> statut != $objclassname :: STATUS_VALIDATED || $object -> type == $objclassname :: TYPE_CREDIT_NOTE ) {
2019-11-14 12:09:15 +01:00
$translationKey = ! empty ( $discount_type ) ? 'HasCreditNoteFromSupplier' : 'CompanyHasCreditNote' ;
$text = $langs -> trans ( $translationKey , price ( $absolute_creditnote ), $langs -> transnoentities ( " Currency " . $conf -> currency )) . '.' ;
2018-03-02 16:48:25 +01:00
2019-11-14 12:09:15 +01:00
if ( $isInvoice && ! $isNewObject && $object -> statut == $objclassname :: STATUS_DRAFT && $object -> type != $objclassname :: TYPE_DEPOSIT ) {
2018-03-02 16:48:25 +01:00
$text = $form -> textwithpicto ( $text , $langs -> trans ( 'CreditNoteDepositUse' ));
}
2018-04-06 20:18:36 +02:00
2018-03-02 16:48:25 +01:00
if ( $absolute_discount <= 0 || $isNewObject ) {
2021-02-15 14:19:05 +01:00
$text .= ' (' . $addabsolutediscount . ')' ;
2018-03-02 16:48:25 +01:00
}
2021-01-04 15:32:18 +01:00
if ( $isNewObject ) {
print '<br>' . $text ;
} else {
print '<div class="inline-block clearboth">' . $text . '</div>' ;
}
2018-03-02 16:48:25 +01:00
} else { // We can add a credit note on a down payment or standard invoice or situation invoice
// There is credit notes discounts available
2019-11-14 12:09:15 +01:00
$more = $isInvoice && ! $isNewObject ? ' (' . $viewabsolutediscount . ')' : '' ;
$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
2018-03-02 16:48:25 +01:00
}
}
2021-09-01 17:33:18 +02:00
if ( $absolute_discount <= 0 && $absolute_creditnote <= 0 ) {
2019-11-14 12:09:15 +01:00
$translationKey = ! empty ( $discount_type ) ? 'HasNoAbsoluteDiscountFromSupplier' : 'CompanyHasNoAbsoluteDiscount' ;
2020-11-29 15:16:53 +01:00
print '<br><span class="opacitymedium">' . $langs -> trans ( $translationKey ) . '.</span>' ;
2018-03-02 16:48:25 +01:00
2019-07-15 10:19:06 +02:00
if ( $isInvoice && $object -> statut == $objclassname :: STATUS_DRAFT && $object -> type != $objclassname :: TYPE_CREDIT_NOTE && $object -> type != $objclassname :: TYPE_DEPOSIT ) {
2019-11-14 12:09:15 +01:00
print ' (' . $addabsolutediscount . ')' ;
2018-03-02 16:48:25 +01:00
}
}
2021-02-10 18:03:45 +01:00
2021-02-11 01:59:13 +01:00
print '<!-- END template -->' ;