firebed / aade-mydata

Interface for ΑΑΔΕ myDATA invoicing REST API. It handles all the boilerplate code for sending, cancelling and requesting invoices.
https://docs.invoicemaker.gr/getting-started
MIT License
61 stars 21 forks source link

summarizeInvoice() Error with InvoiceType: 9.3 #13

Closed memisibram closed 8 months ago

memisibram commented 8 months ago

Thanks for the v1.0.8 updates. First of all, summarizeInvoice() was very necessary, but there is a small error. If the document is only a transport document, that is, InvoiceType: 9.3, setClassificationType should not be sent because it does not update E3. In this document type, we only need to declare ClassificationCategory(IncomeClassificationCategory::CATEGORY_3) and setAmount(0).

For now, I changed the 50th line of firebed\aade-mydata\src\Actions\GroupClassifications.php to this way.

if($type != null) $icls->setClassificationType($type);

everything seems okay.

firebed commented 8 months ago

Thanks for the heads up.

I think the real problem is that the XMWriter is processing null values where it should not. Can you please verify that after this change you get the expected results?

Method Firebed\AadeMyData\Xml\XMLWriter::build (line 23)

    protected function build(DOMNode $parent, string $nodeName, mixed $nodeValue, $namespace = null): void
    {
        if (is_null($nodeValue)) { // <-- Add this check here
            return;
        }

        if ($nodeValue instanceof Type) {
            $this->buildType($parent, $nodeName, $nodeValue);
            return;
        }

        if (is_array($nodeValue)) {
            $this->buildArray($parent, $nodeName, $nodeValue);
            return;
        }

        $namespaceURI = $this->getNamespace($namespace);
        $child = $this->createElement($nodeName, $this->toValue($nodeValue), $namespaceURI);
        $parent->appendChild($child);
    }
memisibram commented 8 months ago

I tried but it didn't work

invoice Details section
["invoiceDetails"]
    ["incomeClassification"]=>
      array(1) {
        [0]=>
        object(Firebed\AadeMyData\Models\IncomeClassification)#106 (3) {
          ["attributes":protected]=>
          array(2) {
            ["classificationCategory"]=>
            enum(Firebed\AadeMyData\Enums\IncomeClassificationCategory::CATEGORY_3)
            ["amount"]=>
            float(0)
          }
        }
     }

invoice Summary section
`["invoiceSummary"]
   ["incomeClassification"]=>
      array(1) {
        [0]=>
        object(Firebed\AadeMyData\Models\IncomeClassification)#131 (3) {
          ["attributes":protected]=>
          array(3) {
            ["classificationType"]=> //< --This classificationType is redundant
            NULL
            ["classificationCategory"]=>
            enum(Firebed\AadeMyData\Enums\IncomeClassificationCategory::CATEGORY_3)
            ["amount"]=>
            float(0)
          }
        }
     }

must be invoice Summary section

["invoiceSummary"]
   ["incomeClassification"]=>
      array(1) {
        [0]=>
        object(Firebed\AadeMyData\Models\IncomeClassification)#131 (3) {
          ["attributes":protected]=>
          array(2) {
            ["classificationCategory"]=>
            enum(Firebed\AadeMyData\Enums\IncomeClassificationCategory::CATEGORY_3)
            ["amount"]=>
            float(0)
          }
        }
     }
firebed commented 8 months ago

That's the expected behavior. With the change I suggested though, the classificationType may be included in the type's attributes array with null value, but it will not be included in the xml.

memisibram commented 8 months ago

Yes, as you said, it is not included in the xml. I tried it in developer mode and it sends the document, no problem, thank you.

firebed commented 8 months ago

Fix available on v4.0.6