Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[QUESTION] xml_extended_1.xml from tests/assets not valid? #155

Closed
Nowocyn opened this issue Oct 31, 2024 · 1 comment
Closed

[QUESTION] xml_extended_1.xml from tests/assets not valid? #155

Nowocyn opened this issue Oct 31, 2024 · 1 comment
Assignees
Labels
question Further information is requested

Comments

@Nowocyn
Copy link

Nowocyn commented Oct 31, 2024

In my project I want to detect and make a simple validation of each pdf and xml file that could be converted into a ZugferdDocument through the readers. For that I tried some of your sample files that are included into your tests.
The file xml_extended_1.xml could not be validated with the ZugferdXsdValidator.

Is the file xml_extended_1.xml supposed to work but isn't compatible with the Xsd validation rules?

Error:

[ERROR] [line 359] 1871 : Element                                                                                      
         '{urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:100}FormattedIssueDateTime':  
         Missing child element(s). Expected is (                                                                        
         {urn:un:unece:uncefact:data:standard:QualifiedDataType:100}DateTimeString ).                                   
          [line 364] 1871 : Element                                                                                     
         '{urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:100}FormattedIssueDateTime':  
         Missing child element(s). Expected is (                                                                        
         {urn:un:unece:uncefact:data:standard:QualifiedDataType:100}DateTimeString ). 
php artisan app:validate ./vendor/horstoeko/zugferd/tests/assets/xml_extended_1.xml 

Laravel Console Command Class:

<?php

namespace App\Console\Commands;

use horstoeko\zugferd\ZugferdDocument;
use horstoeko\zugferd\ZugferdDocumentPdfReader;
use horstoeko\zugferd\ZugferdDocumentReader;
use horstoeko\zugferd\ZugferdKositValidator;
use horstoeko\zugferd\ZugferdXsdValidator;
use Illuminate\Console\Command;
use Illuminate\Support\Str;

class CheckIfZugferd extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'app:validate {filename}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        $filename = $this->argument('filename');
        if (strtolower(Str::afterLast($filename, '.')) == 'xml') {
            $document = ZugferdDocumentReader::readAndGuessFromFile($filename);
        } else {
            $document = ZugferdDocumentPdfReader::readAndGuessFromFile($filename);
        }

        if (!$document) {
            $this->output->error('Not a validate file.');
            return;
        }

        $xsdValidator = new ZugferdXsdValidator($document);

        $xsdValidator->validate();

        if ($xsdValidator->hasValidationErrors()) {
            $this->output->error('Validation errors:');
            $this->output->error(implode(' ', $xsdValidator->validationErrors()));
            return;
        }

        $document->getDocumentInformation($documentno, $documenttypecode, $documentdate, $invoiceCurrency, $taxCurrency, $documentname, $documentlanguage, $effectiveSpecifiedPeriod);

        echo "\r\nGeneral document information\r\n";
        echo "----------------------------------------------------------------------\r\n";
        echo "Profile:               {$document->getProfileDefinitionParameter("name")}\r\n";
        echo "Profile:               {$document->getProfileDefinitionParameter("altname")}\r\n";
        echo "Document No:           {$documentno}\r\n";
        echo "Document Type:         {$documenttypecode}\r\n";
        echo "Document Date:         {$documentdate->format("Y-m-d")}\r\n";
        echo "Invoice currency:      {$invoiceCurrency}\r\n";
        echo "Tax currency:          {$taxCurrency}\r\n";
        return 0;
    }
}
@Nowocyn Nowocyn added the question Further information is requested label Oct 31, 2024
horstoeko pushed a commit that referenced this issue Oct 31, 2024
@horstoeko
Copy link
Owner

Hi @Nowocyn,

Thanks for the tip. I have checked the file and fixed the error

Kind regards

Repository owner locked as resolved and limited conversation to collaborators Oct 31, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants