Merge pull request #15 from sinabe/fix-balance

Fix balance for QR
This commit is contained in:
benvia 2024-08-11 13:10:11 +02:00 committed by GitHub
commit a98a201c95
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 9 additions and 4 deletions

View File

@ -9,7 +9,7 @@
* Copyright (C) 2015 Marcos García <marcosgdf@gmail.com> * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
* Copyright (C) 2017-2018 Ferran Marcet <fmarcet@2byte.es> * Copyright (C) 2017-2018 Ferran Marcet <fmarcet@2byte.es>
* Copyright (C) 2018-2020 Frédéric France <frederic.france@netlogic.fr> * Copyright (C) 2018-2020 Frédéric France <frederic.france@netlogic.fr>
* Copyright (C) 2022-2023 Sinabe Sàrl, Benoit Vianin * Copyright (C) 2022-2024 Sinabe Sàrl, Benoit Vianin
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -861,7 +861,7 @@ class pdf_swissqr extends ModelePDFFactures
$pdf->AddPage(); $pdf->AddPage();
$this->_pagehead($pdf, $object, 0, $outputlangs); $this->_pagehead($pdf, $object, 0, $outputlangs);
$pdf->SetTextColor(0, 0, 0); $pdf->SetTextColor(0, 0, 0);
$this->qrinvoice($pdf, $object, $outputlangs, $conf); $this->qrinvoice($pdf, $object, $deja_regle, $outputlangs, $conf);
} }
$pdf->Close(); $pdf->Close();
@ -905,7 +905,7 @@ class pdf_swissqr extends ModelePDFFactures
* @param object the Dolibarr langs object * @param object the Dolibarr langs object
* @param object the Dolibarr configuration * @param object the Dolibarr configuration
*/ */
protected function qrinvoice($pdf, $object, $langs, $conf) protected function qrinvoice($pdf, $object, $deja_regle, $langs, $conf)
{ {
// Create a new instance of QrBill, containing default headers with fixed values // Create a new instance of QrBill, containing default headers with fixed values
$qrBill = QrBill\QrBill::create(); $qrBill = QrBill\QrBill::create();
@ -970,12 +970,17 @@ class pdf_swissqr extends ModelePDFFactures
'CH' 'CH'
)); ));
// Calculate total with taxes
$creditnoteamount = $object->getSumCreditNotesUsed((!empty($conf->multicurrency->enabled) && $object->multicurrency_tx != 1) ? 1 : 0); // Warning, this also include excess received
$depositsamount = $object->getSumDepositsUsed((!empty($conf->multicurrency->enabled) && $object->multicurrency_tx != 1) ? 1 : 0);
$balance = price2num($object->total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 'MT');
// Add payment amount information // Add payment amount information
// What amount is to be paid? // What amount is to be paid?
$qrBill->setPaymentAmountInformation( $qrBill->setPaymentAmountInformation(
QrBill\DataGroup\Element\PaymentAmountInformation::create( QrBill\DataGroup\Element\PaymentAmountInformation::create(
'CHF', 'CHF',
$object->total_ttc $balance
)); ));
// Optionally, add some human-readable information about what the bill is for. // Optionally, add some human-readable information about what the bill is for.