Merge pull request #24 from sinabe/v2-multicurrency

V2 multi currency
This commit is contained in:
benvia 2025-08-30 15:27:23 +02:00 committed by GitHub
commit 747979f1ba
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 33 additions and 24 deletions

View File

@ -39,17 +39,17 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
*/ */
class pdf_swissqr extends pdf_sponge class pdf_swissqr extends pdf_sponge
{ {
/** /**
* Constructor * Constructor
* *
* @param DoliDB $db Database handler * @param DoliDB $db Database handler
*/ */
public function __construct($db) public function __construct($db)
{ {
parent::__construct($db); parent::__construct($db);
$this->name = "SwissQR"; $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 public function addBottomQRInvoice($pdf, $object, $langs): bool
{ {
@ -84,9 +84,9 @@ class pdf_swissqr extends pdf_sponge
protected function qrinvoice($pdf, $object, $langs) protected function qrinvoice($pdf, $object, $langs)
{ {
if (empty($object->fk_account)) { if (empty($object->fk_account)) {
$this->error = 'Bank account must be defined to use this feature'; $this->error = 'Bank account must be defined to use this feature';
return false; return false;
} }
// 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();
@ -171,21 +171,30 @@ class pdf_swissqr extends pdf_sponge
// Calculate total with taxes // Calculate total with taxes
$deja_regle = $object->getSommePaiement((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0); $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 $amount_credit_notes_included = $object->getSumCreditNotesUsed((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
$depositsamount = $object->getSumDepositsUsed((!empty($conf->multicurrency->enabled) && $object->multicurrency_tx != 1) ? 1 : 0); $amount_deposits_included = $object->getSumDepositsUsed((isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? 1 : 0);
$balance = price2num($object->total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 'MT'); $total_ttc = (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ttc : $object->total_ttc;
$balance = price2num($total_ttc - $deja_regle - $amount_credit_notes_included - $amount_deposits_included, 'MT');
if ($balance < 0) { if ($balance < 0) {
$balance = 0; $balance = 0;
} }
// Add payment amount information $currencyinvoicecode = $object->multicurrency_code ? $object->multicurrency_code : $conf->currency;
// What amount is to be paid?
$qrBill->setPaymentAmountInformation( if ($currencyinvoicecode == "CHF" || $currencyinvoicecode == "EUR") {
QrBill\DataGroup\Element\PaymentAmountInformation::create( // Add payment amount information
'CHF', // What amount is to be paid?
$balance $qrBill->setPaymentAmountInformation(
)); QrBill\DataGroup\Element\PaymentAmountInformation::create(
$currencyinvoicecode,
$balance
));
} else {
$this->error = "Only CHF or EUR currencies accepted";
return false;
}
// Optionally, add some human-readable information about what the bill is for. // Optionally, add some human-readable information about what the bill is for.
$qrBill->setAdditionalInformation( $qrBill->setAdditionalInformation(