initial commit, code generated by AI

This commit is contained in:
daaric 2026-02-08 19:00:38 +01:00
commit 872ca92934
3 changed files with 85 additions and 0 deletions

View file

@ -0,0 +1,28 @@
<?php
require_once DOL_DOCUMENT_ROOT.'/custom/czqrpay/lib/czqrpay.lib.php';
class ActionsCzQrPay
{
function addMoreActionsButtons($parameters, &$object, &$action, $hookmanager)
{
return 0;
}
function beforePDFCreation($parameters, &$object, &$action, $hookmanager)
{
global $db, $pdf;
if ($object->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;
}
}

View file

@ -0,0 +1,23 @@
<?php
include_once DOL_DOCUMENT_ROOT .'/core/modules/DolibarrModules.class.php';
class modCzQrPay extends DolibarrModules
{
public function __construct($db)
{
$this->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')
);
}
}

34
lib/czqrpay.lib.php Normal file
View file

@ -0,0 +1,34 @@
<?php
function czqrpay_get_bank_account($db)
{
$sql = "SELECT rowid, iban, account_number FROM ".MAIN_DB_PREFIX."bank_account";
$resql = $db->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";
}