náhrada EPC QR za CZ SPD QR, úprava generátoru kódu

This commit is contained in:
daaric 2026-02-09 17:58:04 +01:00
parent 573b4a7901
commit 57f5f13472
2 changed files with 79 additions and 56 deletions

View file

@ -30,5 +30,10 @@ function czqrpay_iban_to_cz($iban)
function czqrpay_build_spd($account, $amount, $vs, $msg) function czqrpay_build_spd($account, $amount, $vs, $msg)
{ {
$amount = number_format($amount, 2, '.', ''); $amount = number_format($amount, 2, '.', '');
return "SPD*1.0*ACC:$account*AM:$amount*CC:CZK*X-VS:$vs*MSG:$msg";
// odstranit diakritiku
$msg = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $msg);
$msg = preg_replace('/[^A-Za-z0-9 .,-]/', '', $msg);
return "SPD*1.0*ACC:$account*AM:$amount*CC:CZK*X-VS:$vs*MSG:$msg*";
} }

View file

@ -474,7 +474,25 @@ class pdf_sponge_czqr extends ModelePDFFactures
} }
} elseif (getDolGlobalString('INVOICE_ADD_EPC_QR_CODE') == '1' && (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'VIR')) { } elseif (getDolGlobalString('INVOICE_ADD_EPC_QR_CODE') == '1' && (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'VIR')) {
if ($object->fk_account > 0 || $object->fk_bank > 0 || getDolGlobalInt('FACTURE_RIB_NUMBER')) { if ($object->fk_account > 0 || $object->fk_bank > 0 || getDolGlobalInt('FACTURE_RIB_NUMBER')) {
$qrcodestring = $object->buildEPCQrCodeString(); require_once DOL_DOCUMENT_ROOT.'/custom/czqrpay/lib/czqrpay.lib.php';
$accountNumber = '';
if (!empty($account->account_number)) {
$accountNumber = $account->account_number;
} elseif (!empty($account->iban)) {
$accountNumber = czqrpay_iban_to_cz($account->iban);
}
$vs = preg_replace('/\D/', '', $object->ref);
$msg = "Faktura ".$object->ref;
$qrcodestring = czqrpay_build_spd(
$accountNumber,
$object->total_ttc,
$vs,
$msg
);
} }
} }
@ -1579,60 +1597,60 @@ class pdf_sponge_czqr extends ModelePDFFactures
$posy += 2; $posy += 2;
// ============================================ //// ============================================
// CZ QR PLATBA (náhrada EPC QR) //// CZ QR PLATBA (náhrada EPC QR)
// ============================================ //// ============================================
//
require_once DOL_DOCUMENT_ROOT.'/custom/czqrpay/lib/czqrpay.lib.php'; //require_once DOL_DOCUMENT_ROOT.'/custom/czqrpay/lib/czqrpay.lib.php';
//
// vezmeme účet z aktuální faktury //// vezmeme účet z aktuální faktury
$accountNumber = ''; //$accountNumber = '';
if (!empty($account->account_number)) { //if (!empty($account->account_number)) {
$accountNumber = $account->account_number; // $accountNumber = $account->account_number;
} elseif (!empty($account->iban)) { //} elseif (!empty($account->iban)) {
$accountNumber = czqrpay_iban_to_cz($account->iban); // $accountNumber = czqrpay_iban_to_cz($account->iban);
} //}
//
if (!empty($accountNumber) && !empty($object->total_ttc)) { //if (!empty($accountNumber) && !empty($object->total_ttc)) {
//
// VS jen čísla // // VS jen čísla
$vs = preg_replace('/\D/', '', $object->ref); // $vs = preg_replace('/\D/', '', $object->ref);
//
// zpráva pro příjemce // // zpráva pro příjemce
$msg = "Faktura ".$object->ref; // $msg = "Faktura ".$object->ref;
//
// SPD string // // SPD string
$spd = czqrpay_build_spd( // $spd = czqrpay_build_spd(
$accountNumber, // $accountNumber,
$object->total_ttc, // $object->total_ttc,
$vs, // $vs,
$msg // $msg
); // );
//
$qrPosX = 120; // $qrPosX = 120;
$qrPosY = $posy; // $qrPosY = $posy;
//
$qrCodeColor = array('25', '25', '25'); // $qrCodeColor = array('25', '25', '25');
//
$styleQr = array( // $styleQr = array(
'border' => false, // 'border' => false,
'padding' => 0, // 'padding' => 0,
'fgcolor' => $qrCodeColor, // 'fgcolor' => $qrCodeColor,
'bgcolor' => false, // 'bgcolor' => false,
'module_width' => 1, // 'module_width' => 1,
'module_height' => 1 // 'module_height' => 1
); // );
//
// vykreslení QR // // vykreslení QR
$pdf->write2DBarcode($spd, 'QRCODE,M', $qrPosX, $qrPosY, 30, 30, $styleQr, 'N'); // $pdf->write2DBarcode($spd, 'QRCODE,M', $qrPosX, $qrPosY, 30, 30, $styleQr, 'N');
//
// popisek vedle QR // // popisek vedle QR
$pdf->SetXY($qrPosX + 35, $posy + 6); // $pdf->SetXY($qrPosX + 35, $posy + 6);
$pdf->SetFont('', '', $default_font_size - 5); // $pdf->SetFont('', '', $default_font_size - 5);
$pdf->MultiCell(40, 3, "QR platba", 0, 'L', false); // $pdf->MultiCell(40, 3, "QR platba", 0, 'L', false);
//
$posy = $pdf->GetY() + 2; // $posy = $pdf->GetY() + 2;
} //}
// SHOW EPC QR CODE // SHOW EPC QR CODE