Add support for multicurrency

This commit is contained in:
Benoit Vianin 2025-08-30 11:16:05 +00:00
parent 9678ee536d
commit 5ad5a0ba56
1 changed files with 22 additions and 18 deletions

View File

@ -39,17 +39,17 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
*/
class pdf_swissqr extends pdf_sponge
{
/**
* Constructor
*
* @param DoliDB $db Database handler
*/
public function __construct($db)
{
/**
* Constructor
*
* @param DoliDB $db Database handler
*/
public function __construct($db)
{
parent::__construct($db);
$this->name = "SwissQR";
$this->description = 'Swiss QR invoice based on sponge model';
}
$this->description = 'Swiss QR invoice based on sponge model';
}
public function addBottomQRInvoice($pdf, $object, $langs): bool
{
@ -84,9 +84,9 @@ class pdf_swissqr extends pdf_sponge
protected function qrinvoice($pdf, $object, $langs)
{
if (empty($object->fk_account)) {
$this->error = 'Bank account must be defined to use this feature';
return false;
}
$this->error = 'Bank account must be defined to use this feature';
return false;
}
// Create a new instance of QrBill, containing default headers with fixed values
$qrBill = QrBill\QrBill::create();
@ -171,19 +171,23 @@ class pdf_swissqr extends pdf_sponge
// Calculate total with taxes
$deja_regle = $object->getSommePaiement((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
$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');
$amount_credit_notes_included = $object->getSumCreditNotesUsed((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
$amount_deposits_included = $object->getSumDepositsUsed((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
$total_ttc = (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ttc : $object->total_ttc;
$balance = price2num($total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 'MT');
if ($balance < 0) {
$balance = 0;
}
$currencyinvoicecode = $object->multicurrency_code ? $object->multicurrency_code : $conf->currency;
// Add payment amount information
// What amount is to be paid?
$qrBill->setPaymentAmountInformation(
QrBill\DataGroup\Element\PaymentAmountInformation::create(
'CHF',
$currencyinvoicecode,
$balance
));