-
Notifications
You must be signed in to change notification settings - Fork 50
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
[FEATURE] The invoice parser should support attachement that is not in the standard list #240
Comments
Hi @alimranahmed, Thanks for your contribution. This is indeed an interesting feature request. In fact, I haven't come across anything comparable so far. I wonder if the invoice sender is aware that he is violating the specification :-) Perhaps it would be possible to read the attachments using the following ZugferdDocumentPdfReaderExt methods and pass them manually to the ZugferdDocumentReader:
You should at least consider whether this would be an option. |
Wow, thanks for your quick response. Highly appreciated. Well yes it's no impossible, I have already overriden class ExtendedZugferdPdfReader extends ZugferdDocumentPdfReader
{
public static function getXmlFromContent(string $pdfContent): string
{
return ExtendedZugferdDocumentPdfReaderExt::getInvoiceDocumentContentFromContent($pdfContent);
}
} Now let's say instead of using my
By the way, I was fixing this issue the the code above mentioned and then class ExtendedZugferdDocumentPdfReaderExt extends ZugferdDocumentPdfReaderExt
{
#[Override]
public static function fromContent(string $pdfContent): ZugferdDocumentPdfReaderExt
{
return (new self)->collectAttachmentsFromPdfContent($pdfContent);
}
/**
* We are using reflection to get the attachmentContentList because this is defined as private property
* This is a limitation of the library as it isn't extendable enough
*/
public function getAttachmentContentList(): array
{
$reflection = new ReflectionClass(ZugferdDocumentPdfReaderExt::class);
$property = $reflection->getProperty('attachmentContentList');
$property->setAccessible(true);
return $property->getValue($this);
}
#[Override]
public function resolveInvoiceDocumentContent(): string
{
$attachments = $this->getAttachmentContentList();
return $attachments[0][ZugferdDocumentPdfReaderExt::ATTACHMENT_KEY_CONTENT];
}
} I am using reflection to access the private property, but as mentioned in my 2nd point, I can eleminate this extended class entirely. Still I would vote for this feature. |
Hi @alimranahmed, OK. I still haven't quite understood the “problem”, but if you are happy to extend the list of file names for the permitted invoice attachments, I'll think of something. Please give me some time to design this. Kind regards |
Until we have this feature to have any name as invoice attachement, here is what I am doing now. It may help others if they face the same issue: class ExtendedZugferdPdfReader extends ZugferdDocumentPdfReader
{
public static function getXmlFromContent(string $pdfContent): string
{
try {
$content = ZugferdDocumentPdfReaderExt::getInvoiceDocumentContentFromContent($pdfContent);
} catch (ZugferdNoPdfAttachmentFoundException) {
$additionalDocs = ZugferdDocumentPdfReaderExt::getAdditionalDocumentContentsFromContent($pdfContent);
$content = Arr::get($additionalDocs, '0.content');
}
return $content;
}
} Then, I can call |
Which way of implementing you would prefer? Do you have some ideas? Kind regards |
One simple idea can be to pass a flag with the pdf content to allow non-standard attachments. But I normally don't prefer passing flags. In the library we don't use builder patter to build a object of the reader. Using builder patter would have been a cleaner way to do this. ZugferdDocumentPdfReader::forContent($fileContent)
->allowCustomAttachementName(); // this can set a property to object. But builder pattern is not what this library used, as result adapting this can be too much change. So, may be something like: ZugferdDocumentPdfReader::readAndGuessFromContent(string $pdfContent, bool $allowCustomAttacnmentName); Or may be instead of passing it here, pass this flag where else you feel more suitable. |
Hi @alimranahmed, But that doesn't sound good to me. It is also common practice to add supplementary attachments to the PDF, such as time sheets or copies of delivery notes. Then your logic wouldn't work - he doesn't know which attachment is the right one. Kind regards |
Before Submitting an Issue
Thank you for contributing to our project! 🎉 Before opening a new issue, please review our Contributing Guidelines.
To help us assist you efficiently, we require confirmation of the following:
Issues that do not meet these requirements may be closed without further action. Thank you for your understanding and support! 🙏
Describe the feature
In
ZugferdDocumentPdfReaderExt
class, we have the latest list of allowed attached file defined in constant:But in some cases, a provider of invoice may not use any of this name. In reality, this is the case of many invoice provider. Some provider simply use the name like
{invoice_number}.xml
.So, the library should provide the flexibility to bypass this list or provide their custom list. This is not possible at this moment.
Is it possible by extending the current implementation?
As this is a constant defined and not possible to by pass the list, user may want to extend this whole class
ZugferdDocumentPdfReaderExt
and change only the methodcollectAttachmentsFromPdfContent
to bypass the alowed attachment list. But in this method, an array property called$attachmentContentList
used to store the list of invoice. In the extended class we cannot access this$attachmentContentList
as it's declared as private.For example:
Or if we try to override
resolveInvoiceDocumentContent()
, this is also not possible because this method usedattachmentContentList
which again private property.Expected behavior
There can be two solutions:
ZugferdDocumentPdfReaderExt
extendable so that using standard OOP someone can override the functionalities based on their need.Screenshots
Not applicable
Sample Code
Already mentioned in previous section.
Additional context
In German legal firms, many don't use the standard attachement that is listed in the library.
The text was updated successfully, but these errors were encountered: