From ac1e8ac617878c0919cb5c95cf5d4fb54ac490ed Mon Sep 17 00:00:00 2001 From: Vincent Maury Date: Fri, 23 Feb 2024 17:25:10 +0100 Subject: [PATCH] Fix tva_tx on deposit invoice (#28305) * Fix tva_tx on deposit invoice * Update card.php * Update card.php Modifs according to Eldy's suggestions : introduce a hidden option INVOICE_VAT_TO_USE_ON_CREDIT_NOTE_WHEN_GENERATED_FROM_REMAIN_TO_PAY, with possible values: - not defined, we keep vat to 0 (current code): - if value is string 'default', we do what you suggest, we use the default vat for company (in most cases it will be the higher vat rate in dictionary). - if value is a float, we use this float value. * Update card.php --- htdocs/compta/facture/card.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/htdocs/compta/facture/card.php b/htdocs/compta/facture/card.php index 8923f6bb48a8e..d2c34bf03029c 100644 --- a/htdocs/compta/facture/card.php +++ b/htdocs/compta/facture/card.php @@ -1307,7 +1307,22 @@ $totaldeposits = $facture_source->getSumDepositsUsed(); $remain_to_pay = abs($facture_source->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits); - $object->addline($langs->trans('invoiceAvoirLineWithPaymentRestAmount'), $remain_to_pay, 1, 0, 0, 0, 0, 0, '', '', 'TTC'); + if (!empty($conf->global->INVOICE_VAT_TO_USE_ON_CREDIT_NOTE_WHEN_GENERATED_FROM_REMAIN_TO_PAY) && $conf->global->INVOICE_VAT_TO_USE_ON_CREDIT_NOTE_WHEN_GENERATED_FROM_REMAIN_TO_PAY == 'default') { + if ((empty($object->thirdparty) || !is_object($object->thirdparty) || get_class($object->thirdparty) != 'Societe')) { + $object->fetch_thirdparty(); + } + if (!empty($object->thirdparty) && is_object($object->thirdparty) && get_class($object->thirdparty) == 'Societe') { + $tva_tx = get_default_tva($mysoc, $object->thirdparty); + } else { + $tva_tx = 0; + } + } elseif ((float) $conf->global->INVOICE_VAT_TO_USE_ON_CREDIT_NOTE_WHEN_GENERATED_FROM_REMAIN_TO_PAY > 0) { + $tva_tx = (float) $conf->global->INVOICE_VAT_TO_USE_ON_CREDIT_NOTE_WHEN_GENERATED_FROM_REMAIN_TO_PAY; + } else { + $tva_tx = 0; + } + + $object->addline($langs->trans('invoiceAvoirLineWithPaymentRestAmount'), $remain_to_pay, 1, $tva_tx, 0, 0, 0, 0, '', '', 'TTC'); } }