stephanstapel/ZUGFeRD-csharp

ram:Name is written twice

alexruett opened this issue · 6 comments

In the save method in InvoiceDescriptor21Writer the ram:Name is written twice:

[...]
_writeOptionalElementString(Writer, "ram:BuyerAssignedID", tradeLineItem.BuyerAssignedID, Profile.Comfort | Profile.Extended | Profile.XRechnung1 | Profile.XRechnung);
_writeOptionalElementString(Writer, "ram:Name", tradeLineItem.Name, Profile.Basic | Profile.Comfort | Profile.Extended);
_writeOptionalElementString(Writer, "ram:Name", !isCommentItem ? tradeLineItem.Name : "TEXT", Profile.XRechnung1 | Profile.XRechnung); // XRechnung erfordert einen Item-Namen
_writeOptionalElementString(Writer, "ram:Description", tradeLineItem.Description, Profile.Comfort | Profile.Extended | Profile.XRechnung1 | Profile.XRechnung);
[...]

That doesn't seem right, does it?

I'm not familar with the x-rechnung standard, but to me it would make sense to always write tradelineItem.Name if it is filled, even then, when it is a comment item. Something like this:

_writeOptionalElementString(Writer, "ram:Name", !String.IsNullOrEmpty(tradeLineItem.Name) ? tradeLineItem.Name : isCommentItem ? "TEXT" : String.Empty, Profile.XRechnung1 | Profile.XRechnung); 

I don't know, what should happen, if tradeLineItem.Name is empty and it isn't a comment, but that case wasn't handled before either.

What do you think?
Thanks.

Not quite. The first line is written in case of profiles basic, comfort or extended.
The second line is written in case of profiles xrechnung 1 oder xrechnung 2.x

But I guess a good comment would help here.

Thanks for your quick reply. I wouldn't have done it that way, but ok.
So, if Description is passed, Name is never used but instead always "TEXT" is exported?

!isCommentItem ? tradeLineItem.Name : "TEXT"
if it is a comment item, "TEXT" is written. If not, the name is writtten instead.

If you have an example about a comment line, feel free to drop it here. I'm not understanding yet where you are aiming at.

if it is a comment item, "TEXT" is written. If not, the name is writtten instead.

That caused problems in my case.
I was passing both Name and Description and wondered, why name wasn't exported but "TEXT" instead.
I think, it's good, that "TEXT" is exported in case of a comment and if Name is empty, but I'm not sure, if it's good/correct to always export Name as "TEXT", but again: I don't know, if this was intentionally and according to the xrechnung standard or if this indeed is a bug.
I expected, that both Name and Description were written, but maybe my expectations are just wrong ;-).

ok, thanks. After reviewing the code, I found my old comment that xrechnung trade line items require the name to be filled:

grafik

That seems to be the reason why I'm writing 'TEXT' in this case.
I'm only wondering why it is written twice in your use case. Which profile are you using?

To be it looks like the two statements are mutually exclusive:

grafik

By "written twice" I meant, that there are two lines of code, that write the element ram:Name. I only realized through this conversation, that they are mutually exclusive (which I would never have done this way (no offense) and that's probably the reason, why I missed that). In the exported file there is only one entry for the item.
I still find it questionable, that the Name isn't used, even if it is filled, but my solution for creating a comment item in the xrechnung now is, that I write the whole text in the Description and let Name empty.
That should do it, even if the implementation in InvoiceDescriptor21Writer may change someday.
Thanks.