From 872ca929349c843a16490ad15c33fa9444596a6c Mon Sep 17 00:00:00 2001 From: daaric Date: Sun, 8 Feb 2026 19:00:38 +0100 Subject: [PATCH] initial commit, code generated by AI --- class/actions_czqrpay.class.php | 28 +++++++++++++++++++++++++ core/modules/modCzQrPay.class.php | 23 +++++++++++++++++++++ lib/czqrpay.lib.php | 34 +++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+) create mode 100644 class/actions_czqrpay.class.php create mode 100644 core/modules/modCzQrPay.class.php create mode 100644 lib/czqrpay.lib.php diff --git a/class/actions_czqrpay.class.php b/class/actions_czqrpay.class.php new file mode 100644 index 0000000..74bdf04 --- /dev/null +++ b/class/actions_czqrpay.class.php @@ -0,0 +1,28 @@ +element != 'facture') return 0; + + $account = czqrpay_get_bank_account($db); + if (!$account) return 0; + + $vs = preg_replace('/\D/', '', $object->ref); + $msg = "Faktura ".$object->ref; + $spd = czqrpay_build_spd($account, $object->total_ttc, $vs, $msg); + + $pdf->write2DBarcode($spd, 'QRCODE,M', 160, 230, 35, 35); + + return 1; + } +} diff --git a/core/modules/modCzQrPay.class.php b/core/modules/modCzQrPay.class.php new file mode 100644 index 0000000..ce68333 --- /dev/null +++ b/core/modules/modCzQrPay.class.php @@ -0,0 +1,23 @@ +db = $db; + $this->numero = 104000; + $this->rights_class = 'czqrpay'; + + $this->family = "financial"; + $this->name = 'czqrpay'; + $this->description = "CZ QR Platba (SPD) for invoices and POS"; + $this->version = '0.1'; + $this->const_name = 'MAIN_MODULE_CZQRPAY'; + $this->picto = 'payment'; + + $this->module_parts = array( + 'hooks' => array('invoicecard','pdfgeneration','posreceipt') + ); + } +} diff --git a/lib/czqrpay.lib.php b/lib/czqrpay.lib.php new file mode 100644 index 0000000..f66d8b3 --- /dev/null +++ b/lib/czqrpay.lib.php @@ -0,0 +1,34 @@ +query($sql); + + if ($resql) { + while ($obj = $db->fetch_object($resql)) { + if (!empty($obj->account_number)) return $obj->account_number; + if (!empty($obj->iban)) return czqrpay_iban_to_cz($obj->iban); + } + } + return null; +} + +function czqrpay_iban_to_cz($iban) +{ + $iban = str_replace(' ', '', $iban); + if (substr($iban, 0, 2) !== 'CZ') return null; + + $bank = substr($iban, 4, 4); + $prefix = ltrim(substr($iban, 8, 6), '0'); + $account = ltrim(substr($iban, 14, 10), '0'); + + if ($prefix) return "$prefix-$account/$bank"; + return "$account/$bank"; +} + +function czqrpay_build_spd($account, $amount, $vs, $msg) +{ + $amount = number_format($amount, 2, '.', ''); + return "SPD*1.0*ACC:$account*AM:$amount*CC:CZK*X-VS:$vs*MSG:$msg"; +}