From c9739c710e898882ee0dccd72bf8e84d96377608 Mon Sep 17 00:00:00 2001 From: Okan Date: Thu, 27 Jun 2024 17:34:17 +0300 Subject: [PATCH] Fixed uid generation. Fixed setting correlated invoices. --- src/Actions/GenerateUid.php | 39 ++++++++++++++++++++++++++++++++++++ src/Models/Invoice.php | 15 ++++++++++++++ src/Models/InvoiceHeader.php | 2 +- 3 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 src/Actions/GenerateUid.php diff --git a/src/Actions/GenerateUid.php b/src/Actions/GenerateUid.php new file mode 100644 index 0000000..bbef533 --- /dev/null +++ b/src/Actions/GenerateUid.php @@ -0,0 +1,39 @@ +value : $invoiceType, + $this->normalizeSeries($series), + $number + ]; + + if ($invoiceVariationType) { + $attributes[] = $invoiceVariationType instanceof InvoiceVariationType ? $invoiceVariationType->value : $invoiceVariationType; + } + + return strtoupper(sha1(implode('-', $attributes))); + } + + /** + * Converts series to iso-8859-7 to match myData's current format. + */ + private function normalizeSeries(string $series): string + { + return self::NORMALIZE_SERIES + ? mb_convert_encoding($series, 'ISO-8859-7', 'UTF-8') + : $series; + } +} diff --git a/src/Models/Invoice.php b/src/Models/Invoice.php index cb5ce7a..2b12625 100644 --- a/src/Models/Invoice.php +++ b/src/Models/Invoice.php @@ -4,6 +4,7 @@ use DOMDocument; +use Firebed\AadeMyData\Actions\GenerateUid; use Firebed\AadeMyData\Actions\SquashInvoiceRows; use Firebed\AadeMyData\Actions\SummarizeInvoice; use Firebed\AadeMyData\Enums\TransmissionFailure; @@ -51,6 +52,20 @@ public function getUid(): ?string return $this->get('uid'); } + public function guessUid(): ?string + { + $generator = new GenerateUid(); + return $generator->handle( + vatNumber: $this->getIssuer()->getVatNumber(), + issueDate: $this->getInvoiceHeader()->getIssueDate(), + branchId: $this->getIssuer()->getBranch(), + invoiceType: $this->getInvoiceHeader()->getInvoiceType(), + series: $this->getInvoiceHeader()->getSeries(), + number: $this->getInvoiceHeader()->getAa(), + invoiceVariationType: $this->getInvoiceHeader()->getInvoiceVariationType(), + ); + } + /** * Συμπληρώνεται από την Υπηρεσία. * diff --git a/src/Models/InvoiceHeader.php b/src/Models/InvoiceHeader.php index fc6b8e6..02d8b67 100644 --- a/src/Models/InvoiceHeader.php +++ b/src/Models/InvoiceHeader.php @@ -186,7 +186,7 @@ public function addCorrelatedInvoice(int $correlatedInvoice): static */ public function setCorrelatedInvoices(?array $correlatedInvoices): static { - return $this->push('correlatedInvoices', $correlatedInvoices); + return $this->set('correlatedInvoices', $correlatedInvoices); } /**