Rollback to svg for qr codes

This commit is contained in:
David Bomba
2026-01-19 12:10:34 +11:00
parent 154b74f9cc
commit 3a9b514ee8
6 changed files with 122 additions and 74 deletions

View File

@@ -40,9 +40,9 @@ class ValidCreditScheme implements ValidationRule, ValidatorAwareRule
$r = new EInvoice();
if (data_get($value, 'CreditNote.InvoiceDocumentReference.IssueDate') === null ||
data_get($value, 'CreditNote.InvoiceDocumentReference.IssueDate') === '') {
unset($value['CreditNote']['InvoiceDocumentReference']['IssueDate']);
if (data_get($value, 'CreditNote.BillingReference.0.InvoiceDocumentReference.IssueDate') === null ||
data_get($value, 'CreditNote.BillingReference.0.InvoiceDocumentReference.IssueDate') === '') {
unset($value['CreditNote']['BillingReference'][0]['InvoiceDocumentReference']['IssueDate']);
}
$errors = $r->validateRequest($value['CreditNote'], CreditLevel::class);
@@ -56,21 +56,20 @@ class ValidCreditScheme implements ValidationRule, ValidatorAwareRule
}
if (data_get($value, 'CreditNote.InvoiceDocumentReference.ID') === null ||
data_get($value, 'CreditNote.InvoiceDocumentReference.ID') === '') {
if (data_get($value, 'CreditNote.BillingReference.0.InvoiceDocumentReference.ID') === null ||
data_get($value, 'CreditNote.BillingReference.0.InvoiceDocumentReference.ID') === '') {
$this->validator->errors()->add(
"e_invoice.InvoiceDocumentReference.ID",
"e_invoice.BillingReference.0.InvoiceDocumentReference.ID",
"Invoice Reference/Number is required"
);
}
if (isset($value['CreditNote']['InvoiceDocumentReference']['IssueDate']) && strlen($value['CreditNote']['InvoiceDocumentReference']['IssueDate']) > 1 && !$this->isValidDateSyntax($value['CreditNote']['InvoiceDocumentReference']['IssueDate'])) {
if (isset($value['CreditNote']['BillingReference'][0]['InvoiceDocumentReference']['IssueDate']) && strlen($value['CreditNote']['BillingReference'][0]['InvoiceDocumentReference']['IssueDate']) > 1 && !$this->isValidDateSyntax($value['CreditNote']['BillingReference'][0]['InvoiceDocumentReference']['IssueDate'])) {
$this->validator->errors()->add(
"e_invoice.InvoiceDocumentReference.IssueDate",
"e_invoice.BillingReference.0.InvoiceDocumentReference.IssueDate",
"Invoice Issue Date is required"
);
@@ -83,14 +82,16 @@ class ValidCreditScheme implements ValidationRule, ValidatorAwareRule
private function isValidDateSyntax(string $date_string): bool
{
try {
$date = date_create($date_string);
return $date !== false && $date instanceof \DateTime;
} catch (\Exception $e) {
// Strict format validation: must be exactly Y-m-d
$date = \DateTime::createFromFormat('Y-m-d', $date_string);
if ($date === false) {
return false;
}
// Ensure the formatted date matches the input (catches overflow)
return $date->format('Y-m-d') === $date_string;
}
/**
* Set the current validator.
*/

View File

@@ -42,14 +42,15 @@ use InvoiceNinja\EInvoice\Models\Peppol\AmountType\TaxableAmount;
use InvoiceNinja\EInvoice\Models\Peppol\PeriodType\InvoicePeriod;
use InvoiceNinja\EInvoice\Models\Peppol\CodeType\IdentificationCode;
use InvoiceNinja\EInvoice\Models\Peppol\InvoiceLineType\InvoiceLine;
use InvoiceNinja\EInvoice\Models\Peppol\CreditNoteLineType\CreditNoteLine;
use InvoiceNinja\EInvoice\Models\Peppol\TaxCategoryType\TaxCategory;
use InvoiceNinja\EInvoice\Models\Peppol\TaxSubtotalType\TaxSubtotal;
use InvoiceNinja\EInvoice\Models\Peppol\AmountType\TaxExclusiveAmount;
use InvoiceNinja\EInvoice\Models\Peppol\AmountType\TaxInclusiveAmount;
use InvoiceNinja\EInvoice\Models\Peppol\AmountType\LineExtensionAmount;
use InvoiceNinja\EInvoice\Models\Peppol\CreditNoteLineType\CreditNoteLine;
use InvoiceNinja\EInvoice\Models\Peppol\OrderReferenceType\OrderReference;
use InvoiceNinja\EInvoice\Models\Peppol\MonetaryTotalType\LegalMonetaryTotal;
use InvoiceNinja\EInvoice\Models\Peppol\BillingReferenceType\BillingReference;
use InvoiceNinja\EInvoice\Models\Peppol\TaxCategoryType\ClassifiedTaxCategory;
use InvoiceNinja\EInvoice\Models\Peppol\CustomerPartyType\AccountingCustomerParty;
use InvoiceNinja\EInvoice\Models\Peppol\SupplierPartyType\AccountingSupplierParty;
@@ -507,22 +508,26 @@ class Peppol extends AbstractService
{
// InvoiceNinja\EInvoice\Models\Peppol\DocumentReferenceType
if($this->isCreditNote() && $this->invoice->e_invoice->CreditNote->InvoiceDocumentReference ?? false) {
if($this->isCreditNote() && isset($this->invoice->e_invoice->CreditNote->BillingReference) && isset($this->invoice->e_invoice->CreditNote->BillingReference[0]->InvoiceDocumentReference)) {
$document_reference = new \InvoiceNinja\EInvoice\Models\Peppol\DocumentReferenceType\InvoiceDocumentReference();
$_idr = reset($this->invoice->e_invoice->CreditNote->BillingReference);
$d_id = new ID();
$d_id->value = $this->invoice->e_invoice->CreditNote->InvoiceDocumentReference->ID;
$d_id->value = $_idr->InvoiceDocumentReference;
$document_reference->ID = $d_id;
if(isset($this->invoice->e_invoice->CreditNote->InvoiceDocumentReference->IssueDate)) {
$issue_date = new \DateTime($this->invoice->e_invoice->CreditNote->InvoiceDocumentReference->IssueDate);
if(isset($_idr->InvoiceDocumentReference->IssueDate)) {
$issue_date = new \DateTime($_idr->InvoiceDocumentReference->IssueDate);
$document_reference->IssueDate = $issue_date;
}
$this->p_invoice->InvoiceDocumentReference = $document_reference;
$billing_reference = new BillingReference();
$billing_reference->InvoiceDocumentReference = $document_reference;
$this->p_invoice->BillingReference[] = $billing_reference;
// $this->p_invoice->InvoiceDocumentReference = $this->invoice->e_invoice->CreditNote->InvoiceDocumentReference;
return $this;
}

View File

@@ -83,6 +83,27 @@ trait Inviteable
}
/**
* stubbed for future when we want to change from svg to png qrcodes.
*/
// public function getPaymentQrCodeRawPng()
// {
// $result = \Endroid\QrCode\Builder\Builder::create()
// ->writer(new \Endroid\QrCode\Writer\PngWriter())
// ->data($this->getPaymentLink())
// ->encoding(new \Endroid\QrCode\Encoding\Encoding('UTF-8'))
// ->errorCorrectionLevel(\Endroid\QrCode\ErrorCorrectionLevel::Medium)
// ->size(150)
// ->margin(0)
// ->build();
// $png = base64_encode($result->getString());
// return '<img src="data:image/png;base64,' . $png . '" alt="QR Code" />';
// }
public function getUnsubscribeLink()
{
if (Ninja::isHosted()) {

View File

@@ -32,12 +32,12 @@
"type": "project",
"require": {
"php": ">=8.2",
"ext-bcmath": "*",
"ext-curl": "*",
"ext-dom": "*",
"ext-json": "*",
"ext-libxml": "*",
"ext-simplexml": "*",
"ext-bcmath": "*",
"afosto/yaac": "^1.5",
"asm/php-ansible": "dev-main",
"authorizenet/authorizenet": "^2.0",
@@ -51,6 +51,7 @@
"braintree/braintree_php": "^6.28",
"btcpayserver/btcpayserver-greenfield-php": "^2.6",
"checkout/checkout-sdk-php": "^3.0",
"endroid/qr-code": "^5",
"eway/eway-rapid-php": "^1.3",
"fakerphp/faker": "^1.14",
"getbrevo/brevo-php": "^1.0",

80
composer.lock generated
View File

@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "007bf7c6e51e1a5429cf7fc81904a14e",
"content-hash": "d044985779d84769736a51fd6217b050",
"packages": [
{
"name": "afosto/yaac",
@@ -497,16 +497,16 @@
},
{
"name": "aws/aws-sdk-php",
"version": "3.369.14",
"version": "3.369.15",
"source": {
"type": "git",
"url": "https://github.com/aws/aws-sdk-php.git",
"reference": "b40eb1177d2e621c18cd797ca6cc9efb5a0e99d9"
"reference": "7c62f41fb0460c3e5d5c1f70e93e726f1daa75f5"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/b40eb1177d2e621c18cd797ca6cc9efb5a0e99d9",
"reference": "b40eb1177d2e621c18cd797ca6cc9efb5a0e99d9",
"url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/7c62f41fb0460c3e5d5c1f70e93e726f1daa75f5",
"reference": "7c62f41fb0460c3e5d5c1f70e93e726f1daa75f5",
"shasum": ""
},
"require": {
@@ -588,9 +588,9 @@
"support": {
"forum": "https://github.com/aws/aws-sdk-php/discussions",
"issues": "https://github.com/aws/aws-sdk-php/issues",
"source": "https://github.com/aws/aws-sdk-php/tree/3.369.14"
"source": "https://github.com/aws/aws-sdk-php/tree/3.369.15"
},
"time": "2026-01-15T19:10:54+00:00"
"time": "2026-01-16T19:18:57+00:00"
},
{
"name": "babenkoivan/elastic-adapter",
@@ -2907,22 +2907,22 @@
},
{
"name": "goetas-webservices/xsd2php-runtime",
"version": "v0.2.17",
"version": "0.2.18",
"source": {
"type": "git",
"url": "https://github.com/goetas-webservices/xsd2php-runtime.git",
"reference": "be15c48cda6adfab82e180a69dfa1937e208cfe1"
"reference": "1215ce8504f2726b1a0c5025478da86a2791a0ba"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/goetas-webservices/xsd2php-runtime/zipball/be15c48cda6adfab82e180a69dfa1937e208cfe1",
"reference": "be15c48cda6adfab82e180a69dfa1937e208cfe1",
"url": "https://api.github.com/repos/goetas-webservices/xsd2php-runtime/zipball/1215ce8504f2726b1a0c5025478da86a2791a0ba",
"reference": "1215ce8504f2726b1a0c5025478da86a2791a0ba",
"shasum": ""
},
"require": {
"jms/serializer": "^1.2|^2.0|^3.0",
"php": ">=7.1",
"symfony/yaml": "^2.2|^3.0|^4.0|^5.0|^6.0|^7.0"
"symfony/yaml": "^2.2|^3.0|^4.0|^5.0|^6.0|^7.0|^8.0"
},
"conflict": {
"jms/serializer": "1.4.1|1.6.1|1.6.2"
@@ -2961,9 +2961,9 @@
],
"support": {
"issues": "https://github.com/goetas-webservices/xsd2php-runtime/issues",
"source": "https://github.com/goetas-webservices/xsd2php-runtime/tree/v0.2.17"
"source": "https://github.com/goetas-webservices/xsd2php-runtime/tree/0.2.18"
},
"time": "2024-04-12T22:55:31+00:00"
"time": "2026-01-16T19:24:00+00:00"
},
{
"name": "google/apiclient",
@@ -6662,20 +6662,20 @@
},
{
"name": "league/uri",
"version": "7.7.0",
"version": "7.8.0",
"source": {
"type": "git",
"url": "https://github.com/thephpleague/uri.git",
"reference": "8d587cddee53490f9b82bf203d3a9aa7ea4f9807"
"reference": "4436c6ec8d458e4244448b069cc572d088230b76"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/thephpleague/uri/zipball/8d587cddee53490f9b82bf203d3a9aa7ea4f9807",
"reference": "8d587cddee53490f9b82bf203d3a9aa7ea4f9807",
"url": "https://api.github.com/repos/thephpleague/uri/zipball/4436c6ec8d458e4244448b069cc572d088230b76",
"reference": "4436c6ec8d458e4244448b069cc572d088230b76",
"shasum": ""
},
"require": {
"league/uri-interfaces": "^7.7",
"league/uri-interfaces": "^7.8",
"php": "^8.1",
"psr/http-factory": "^1"
},
@@ -6689,11 +6689,11 @@
"ext-gmp": "to improve IPV4 host parsing",
"ext-intl": "to handle IDN host with the best performance",
"ext-uri": "to use the PHP native URI class",
"jeremykendall/php-domain-parser": "to resolve Public Suffix and Top Level Domain",
"league/uri-components": "Needed to easily manipulate URI objects components",
"league/uri-polyfill": "Needed to backport the PHP URI extension for older versions of PHP",
"jeremykendall/php-domain-parser": "to further parse the URI host and resolve its Public Suffix and Top Level Domain",
"league/uri-components": "to provide additional tools to manipulate URI objects components",
"league/uri-polyfill": "to backport the PHP URI extension for older versions of PHP",
"php-64bit": "to improve IPV4 host parsing",
"rowbot/url": "to handle WHATWG URL",
"rowbot/url": "to handle URLs using the WHATWG URL Living Standard specification",
"symfony/polyfill-intl-idn": "to handle IDN host via the Symfony polyfill if ext-intl is not present"
},
"type": "library",
@@ -6748,7 +6748,7 @@
"docs": "https://uri.thephpleague.com",
"forum": "https://thephpleague.slack.com",
"issues": "https://github.com/thephpleague/uri-src/issues",
"source": "https://github.com/thephpleague/uri/tree/7.7.0"
"source": "https://github.com/thephpleague/uri/tree/7.8.0"
},
"funding": [
{
@@ -6756,20 +6756,20 @@
"type": "github"
}
],
"time": "2025-12-07T16:02:06+00:00"
"time": "2026-01-14T17:24:56+00:00"
},
{
"name": "league/uri-interfaces",
"version": "7.7.0",
"version": "7.8.0",
"source": {
"type": "git",
"url": "https://github.com/thephpleague/uri-interfaces.git",
"reference": "62ccc1a0435e1c54e10ee6022df28d6c04c2946c"
"reference": "c5c5cd056110fc8afaba29fa6b72a43ced42acd4"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/thephpleague/uri-interfaces/zipball/62ccc1a0435e1c54e10ee6022df28d6c04c2946c",
"reference": "62ccc1a0435e1c54e10ee6022df28d6c04c2946c",
"url": "https://api.github.com/repos/thephpleague/uri-interfaces/zipball/c5c5cd056110fc8afaba29fa6b72a43ced42acd4",
"reference": "c5c5cd056110fc8afaba29fa6b72a43ced42acd4",
"shasum": ""
},
"require": {
@@ -6782,7 +6782,7 @@
"ext-gmp": "to improve IPV4 host parsing",
"ext-intl": "to handle IDN host with the best performance",
"php-64bit": "to improve IPV4 host parsing",
"rowbot/url": "to handle WHATWG URL",
"rowbot/url": "to handle URLs using the WHATWG URL Living Standard specification",
"symfony/polyfill-intl-idn": "to handle IDN host via the Symfony polyfill if ext-intl is not present"
},
"type": "library",
@@ -6832,7 +6832,7 @@
"docs": "https://uri.thephpleague.com",
"forum": "https://thephpleague.slack.com",
"issues": "https://github.com/thephpleague/uri-src/issues",
"source": "https://github.com/thephpleague/uri-interfaces/tree/7.7.0"
"source": "https://github.com/thephpleague/uri-interfaces/tree/7.8.0"
},
"funding": [
{
@@ -6840,7 +6840,7 @@
"type": "github"
}
],
"time": "2025-12-07T16:03:21+00:00"
"time": "2026-01-15T06:54:53+00:00"
},
{
"name": "livewire/livewire",
@@ -19764,16 +19764,16 @@
},
{
"name": "phpunit/phpunit",
"version": "11.5.47",
"version": "11.5.48",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/phpunit.git",
"reference": "a8c3c540923f8a3d499659b927228059bb3809d8"
"reference": "fe3665c15e37140f55aaf658c81a2eb9030b6d89"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/a8c3c540923f8a3d499659b927228059bb3809d8",
"reference": "a8c3c540923f8a3d499659b927228059bb3809d8",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/fe3665c15e37140f55aaf658c81a2eb9030b6d89",
"reference": "fe3665c15e37140f55aaf658c81a2eb9030b6d89",
"shasum": ""
},
"require": {
@@ -19845,7 +19845,7 @@
"support": {
"issues": "https://github.com/sebastianbergmann/phpunit/issues",
"security": "https://github.com/sebastianbergmann/phpunit/security/policy",
"source": "https://github.com/sebastianbergmann/phpunit/tree/11.5.47"
"source": "https://github.com/sebastianbergmann/phpunit/tree/11.5.48"
},
"funding": [
{
@@ -19869,7 +19869,7 @@
"type": "tidelift"
}
],
"time": "2026-01-15T12:00:46+00:00"
"time": "2026-01-16T16:26:27+00:00"
},
{
"name": "react/cache",
@@ -22087,12 +22087,12 @@
"prefer-lowest": false,
"platform": {
"php": ">=8.2",
"ext-bcmath": "*",
"ext-curl": "*",
"ext-dom": "*",
"ext-json": "*",
"ext-libxml": "*",
"ext-simplexml": "*",
"ext-bcmath": "*"
"ext-simplexml": "*"
},
"platform-dev": [],
"plugin-api-version": "2.6.0"

View File

@@ -39,7 +39,6 @@ class CreditTest extends TestCase
Model::reguard();
$this->makeTestData();
// $this->withoutExceptionHandling();
}
public function testCreditEInvoiceValidation()
@@ -48,12 +47,17 @@ class CreditTest extends TestCase
$credit_update = [
'e_invoice' => [
'CreditNote' => [
'InvoiceDocumentReference' => [
'ID' => '',
'IssueDate' => '',
'BillingReference' => [
[
'InvoiceDocumentReference' => [
'ID' => '',
'IssueDate' => '',
],
]
],
],
],
],
];
$data = array_merge($this->credit->toArray(), $credit_update);
@@ -72,12 +76,16 @@ class CreditTest extends TestCase
$credit_update = [
'e_invoice' => [
'CreditNote' => [
'InvoiceDocumentReference' => [
'BillingReference' => [
[
'InvoiceDocumentReference' => [
'ID' => 'INV-123456S',
'IssueDate' => '',
],
],
],
],
],
];
$data = array_merge($this->credit->toArray(), $credit_update);
@@ -96,12 +104,16 @@ class CreditTest extends TestCase
$credit_update = [
'e_invoice' => [
'CreditNote' => [
'InvoiceDocumentReference' => [
'BillingReference' => [
[
'InvoiceDocumentReference' => [
'ID' => 'INV-123456S',
'IssueDate' => '2026-01-18',
],
],
],
],
],
];
$data = array_merge($this->credit->toArray(), $credit_update);
@@ -121,13 +133,17 @@ class CreditTest extends TestCase
$credit_update = [
'e_invoice' => [
'CreditNote' => [
'InvoiceDocumentReference' => [
'ID' => 'INV-123456S',
'IssueDate' => '203326-01-118',
'BillingReference' => [
[
'InvoiceDocumentReference' => [
'ID' => 'INV-123456S',
'IssueDate' => '203326-01-118',
],
],
],
],
],
],
];
];
$data = array_merge($this->credit->toArray(), $credit_update);
@@ -145,9 +161,13 @@ class CreditTest extends TestCase
$credit_update = [
'e_invoice' => [
'CreditNote' => [
'BillingReference' => [
[
'InvoiceDocumentReference' => [
'ID' => 'INV-123456S',
'IssueDate' => '3000-01-11',
],
],
],
],
],