Hay una nueva regulación del Gobierno que solicita a todas las empresas registradas de IVA que implementen el CÓDIGO QR en la nueva factura electrónica.
Los campos de código QR se codificarán en formato Tag-Length-Value (TLV) con los valores de etiqueta especificados en la columna "Etiqueta" de la tabla adyacente.
La codificación TLV será la siguiente:
¿Cómo creo TLV a partir de una matriz de información? ¿Hay una biblioteca que pueda usar?
$arr = [ 1 => 'Company Name', 2 => '1234567890', 3 => '2021/10/11 17:20:00', 4 => '1000', 5 => '150' ];Sí, el código QR requerido no es un código QR normal con un enlace. Debe estar codificado en TLV base64. Se puede hacer muy fácilmente. los valores deben ser hexadecimales y luego combinados, lo que contendrá caracteres de control ASCII.
Si aún no lo obtiene, afortunadamente, puede usar el siguiente paquete de Salla para generar un código QR desde la matriz.
https://github.com/SallaApp/ZATCA
Asegúrese de seguir la estructura de etiquetas proporcionada por la ZATCA (GAZT anteriormente). El ejemplo del paquete tiene la matriz correcta:
$generatedString = GenerateQrCode::fromArray([ new Seller('Salla'), // seller name new TaxNumber('1234567891'), // seller tax number new InvoiceDate('2021-07-12T14:25:09Z'), // invoice date as Zulu ISO8601 @see https://en.wikipedia.org/wiki/ISO_8601 new InvoiceTotalAmount('100.00'), // invoice total amount new InvoiceTaxAmount('15.00') // invoice tax amount // TODO :: Support others tags ])->toTLV();Para aquellos que todavía usan php5 basado en https://github.com/SallaApp/ZATCA
/* * QR Encoding Functions */ function __getLength($value) { return strlen($value); } function __toHex($value) { return pack("H*", sprintf("%02X", $value)); } function __toString($__tag, $__value, $__length) { $value = (string) $__value; return __toHex($__tag) . __toHex($__length) . $value; } function __getTLV($dataToEncode) { $__TLVS = ''; for ($i = 0; $i < count($dataToEncode); $i++) { $__tag = $dataToEncode[$i][0]; $__value = $dataToEncode[$i][1]; $__length = __getLength($__value); $__TLVS .= __toString($__tag, $__value, $__length); } return $__TLVS; } /* * QR Encoding Functions */ /* * QR Code */ $dataToEncode = [ [1, 'SellerName'], [2, 'VATNumber'], [3, 'invoiceDatetime'], [4, 'AmtwithVAT'], [5, 'VATamt'] ]; $__TLV = __getTLV($dataToEncode); $__QR = base64_encode($__TLV); echo $__QR; /* * QR Code */1-- Instalar ZATCA SDK https://zatca.gov.sa/en/E-Invoicing/SystemsDevelopers/ComplianceEnablementToolbox/Pages/DownloadSDK.aspx
2 -- fatoorah validarqr -qr "$__QR"
function einv_generate_tlv_qr_code($array_tag=array()){ $index=1; foreach($array_tag as $tag_val){ $tlv_string.=pack("H*", sprintf("%02X",(string) "$index")). pack("H*", sprintf("%02X",strlen((string) "$tag_val"))). (string) "$tag_val"; $index++; } return base64_encode($tlv_string); }Simplemente envíele valores de etiquetas en matriz a la función y le devolverá el contenido TLV de QRcode
$data_tlv=einv_generate_tlv_qr_code(array($company_name,$vat_reference,$timestamp,$total,$vat);