Skip to content

Commit c7fb4a0

Browse files
committed
fix(JF-1286): detect creditnotes as xrechnung
1 parent acf8b3a commit c7fb4a0

File tree

3 files changed

+165
-3
lines changed

3 files changed

+165
-3
lines changed

src/main/java/org/jadice/filetype/matchers/XMLMatcher.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,9 @@ public class XMLMatcher extends Matcher {
108108
private static final Map<String, String> X_RECHNUNG_ROOT_ELEMENT_XMLNS_PAIRS;
109109
static {
110110
X_RECHNUNG_ROOT_ELEMENT_XMLNS_PAIRS = new HashMap<>();
111-
X_RECHNUNG_ROOT_ELEMENT_XMLNS_PAIRS.put("Invoice", "urn:oasis:names:specification:ubl:schema:xsd:Invoice-2");
111+
X_RECHNUNG_ROOT_ELEMENT_XMLNS_PAIRS.put("Invoice", "urn:oasis:names:specification:ubl:schema:xsd:Invoice-");
112112
X_RECHNUNG_ROOT_ELEMENT_XMLNS_PAIRS.put("CrossIndustryInvoice", "urn:un:unece:uncefact:data:standard:CrossIndustryInvoice:100");
113+
X_RECHNUNG_ROOT_ELEMENT_XMLNS_PAIRS.put("CreditNote", "urn:oasis:names:specification:ubl:schema:xsd:CreditNote-");
113114
}
114115

115116
@Override
@@ -399,6 +400,6 @@ private static int determineMaxEntityExpansions() {
399400
* @return <code>true</code> if input matches X-Rechnung standard
400401
*/
401402
public static boolean matchesXRechnung(String rootElement, String namespaceURI) {
402-
return X_RECHNUNG_ROOT_ELEMENT_XMLNS_PAIRS.getOrDefault(rootElement, "").equals(namespaceURI);
403+
return namespaceURI != null && X_RECHNUNG_ROOT_ELEMENT_XMLNS_PAIRS.get(rootElement) != null && namespaceURI.startsWith(X_RECHNUNG_ROOT_ELEMENT_XMLNS_PAIRS.get(rootElement));
403404
}
404405
}

src/test/java/TestVariousTypes.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ public static Stream<Arguments> dataProviderXRechnung() {
9595
arguments("/various_types/EN16931_Einfach.pdf", "application/pdf"),
9696
arguments("/various_types/EN16931_Einfach.cii.xml", "application/xml;charset=UTF-8;x-rechnung=true"),
9797
arguments("/various_types/EN16931_Einfach.ubl.xml", "application/xml;charset=UTF-8;x-rechnung=true"),
98-
arguments("/various_types/ZUGFeRD-invoice_rabatte_3_abschlag_duepayableamount.xml", "application/xml;charset=UTF-8;x-rechnung=true")
98+
arguments("/various_types/ZUGFeRD-invoice_rabatte_3_abschlag_duepayableamount.xml", "application/xml;charset=UTF-8;x-rechnung=true"),
99+
arguments("/various_types/ubl-creditNote-2.0-Example.xml", "application/xml;charset=UTF-8;x-rechnung=true")
99100
);
100101
}
101102

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
<?xml version="1.0"?>
2+
<CreditNote xmlns="urn:oasis:names:specification:ubl:schema:xsd:CreditNote-2" xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">
3+
<cbc:UBLVersionID>2.0</cbc:UBLVersionID>
4+
<cbc:CustomizationID>urn:oasis:names:specification:ubl:xpath:CreditNote-2.0:sbs-1.0-draft</cbc:CustomizationID>
5+
<cbc:ProfileID>bpid:urn:oasis:names:draft:bpss:ubl-2-sbs-credit-notification-draft</cbc:ProfileID>
6+
<cbc:ID>CN758494</cbc:ID>
7+
<cbc:CopyIndicator>false</cbc:CopyIndicator>
8+
<cbc:UUID>349ABBAE-DF9D-40B4-849F-94C5FF9D1AF4</cbc:UUID>
9+
<cbc:IssueDate>2005-06-25</cbc:IssueDate>
10+
<cbc:TaxPointDate>2005-06-21</cbc:TaxPointDate>
11+
<cbc:Note>sample</cbc:Note>
12+
<cac:AccountingSupplierParty>
13+
<cbc:CustomerAssignedAccountID>CO001</cbc:CustomerAssignedAccountID>
14+
<cac:Party>
15+
<cac:PartyName>
16+
<cbc:Name>Consortial</cbc:Name>
17+
</cac:PartyName>
18+
<cac:PostalAddress>
19+
<cbc:StreetName>Busy Street</cbc:StreetName>
20+
<cbc:BuildingName>Thereabouts</cbc:BuildingName>
21+
<cbc:BuildingNumber>56A</cbc:BuildingNumber>
22+
<cbc:CityName>Farthing</cbc:CityName>
23+
<cbc:PostalZone>AA99 1BB</cbc:PostalZone>
24+
<cbc:CountrySubentity>Heremouthshire</cbc:CountrySubentity>
25+
<cac:AddressLine>
26+
<cbc:Line>The Roundabout</cbc:Line>
27+
</cac:AddressLine>
28+
<cac:Country>
29+
<cbc:IdentificationCode>GB</cbc:IdentificationCode>
30+
</cac:Country>
31+
</cac:PostalAddress>
32+
<cac:PartyTaxScheme>
33+
<cbc:RegistrationName>Farthing Purchasing Consortium</cbc:RegistrationName>
34+
<cbc:CompanyID>175 269 2355</cbc:CompanyID>
35+
<cbc:ExemptionReason>N/A</cbc:ExemptionReason>
36+
<cac:TaxScheme>
37+
<cbc:ID>VAT</cbc:ID>
38+
<cbc:TaxTypeCode>VAT</cbc:TaxTypeCode>
39+
</cac:TaxScheme>
40+
</cac:PartyTaxScheme>
41+
<cac:Contact>
42+
<cbc:Name>Mrs Bouquet</cbc:Name>
43+
<cbc:Telephone>0158 1233714</cbc:Telephone>
44+
<cbc:Telefax>0158 1233856</cbc:Telefax>
45+
<cbc:ElectronicMail>bouquet@fpconsortial.co.uk</cbc:ElectronicMail>
46+
</cac:Contact>
47+
</cac:Party>
48+
</cac:AccountingSupplierParty>
49+
<cac:AccountingCustomerParty>
50+
<cbc:CustomerAssignedAccountID>XFB01</cbc:CustomerAssignedAccountID>
51+
<cbc:SupplierAssignedAccountID>GT00978567</cbc:SupplierAssignedAccountID>
52+
<cac:Party>
53+
<cac:PartyName>
54+
<cbc:Name>IYT Corporation</cbc:Name>
55+
</cac:PartyName>
56+
<cac:PostalAddress>
57+
<cbc:StreetName>Avon Way</cbc:StreetName>
58+
<cbc:BuildingName>Thereabouts</cbc:BuildingName>
59+
<cbc:BuildingNumber>56A</cbc:BuildingNumber>
60+
<cbc:CityName>Bridgtow</cbc:CityName>
61+
<cbc:PostalZone>ZZ99 1ZZ</cbc:PostalZone>
62+
<cbc:CountrySubentity>Avon</cbc:CountrySubentity>
63+
<cac:AddressLine>
64+
<cbc:Line>3rd Floor, Room 5</cbc:Line>
65+
</cac:AddressLine>
66+
<cac:Country>
67+
<cbc:IdentificationCode>GB</cbc:IdentificationCode>
68+
</cac:Country>
69+
</cac:PostalAddress>
70+
<cac:PartyTaxScheme>
71+
<cbc:RegistrationName>Bridgtow District Council</cbc:RegistrationName>
72+
<cbc:CompanyID>12356478</cbc:CompanyID>
73+
<cbc:ExemptionReason>Local Authority</cbc:ExemptionReason>
74+
<cac:TaxScheme>
75+
<cbc:ID>UK VAT</cbc:ID>
76+
<cbc:TaxTypeCode>VAT</cbc:TaxTypeCode>
77+
</cac:TaxScheme>
78+
</cac:PartyTaxScheme>
79+
<cac:Contact>
80+
<cbc:Name>Mr Fred Churchill</cbc:Name>
81+
<cbc:Telephone>0127 2653214</cbc:Telephone>
82+
<cbc:Telefax>0127 2653215</cbc:Telefax>
83+
<cbc:ElectronicMail>fred@iytcorporation.gov.uk</cbc:ElectronicMail>
84+
</cac:Contact>
85+
</cac:Party>
86+
</cac:AccountingCustomerParty>
87+
<cac:TaxTotal>
88+
<cbc:TaxAmount currencyID="GBP">17.50</cbc:TaxAmount>
89+
<cbc:TaxEvidenceIndicator>true</cbc:TaxEvidenceIndicator>
90+
<cac:TaxSubtotal>
91+
<cbc:TaxableAmount currencyID="GBP">100.00</cbc:TaxableAmount>
92+
<cbc:TaxAmount currencyID="GBP">17.50</cbc:TaxAmount>
93+
<cac:TaxCategory>
94+
<cbc:ID>A</cbc:ID>
95+
<cac:TaxScheme>
96+
<cbc:ID>UK VAT</cbc:ID>
97+
<cbc:TaxTypeCode>VAT</cbc:TaxTypeCode>
98+
</cac:TaxScheme>
99+
</cac:TaxCategory>
100+
</cac:TaxSubtotal>
101+
</cac:TaxTotal>
102+
<cac:LegalMonetaryTotal>
103+
<cbc:LineExtensionAmount currencyID="GBP">100.00</cbc:LineExtensionAmount>
104+
<cbc:TaxExclusiveAmount currencyID="GBP">90.00</cbc:TaxExclusiveAmount>
105+
<cbc:PayableAmount currencyID="GBP">107.50</cbc:PayableAmount>
106+
</cac:LegalMonetaryTotal>
107+
<cac:CreditNoteLine>
108+
<cbc:ID>1</cbc:ID>
109+
<cbc:Note>as agreed on phone, the invoice should have been cancelled earlier, apologies</cbc:Note>
110+
<cbc:CreditedQuantity unitCode="KGM">100</cbc:CreditedQuantity>
111+
<cbc:LineExtensionAmount currencyID="GBP">100.00</cbc:LineExtensionAmount>
112+
<cbc:TaxPointDate>2005-06-21</cbc:TaxPointDate>
113+
<cac:DiscrepancyResponse>
114+
<cbc:ReferenceID>A00095678</cbc:ReferenceID>
115+
<cbc:Description>invoice cancelation</cbc:Description>
116+
</cac:DiscrepancyResponse>
117+
<cac:BillingReference>
118+
<cac:InvoiceDocumentReference>
119+
<cbc:ID>A00095678</cbc:ID>
120+
<cbc:UUID>849FBBCE-E081-40B4-906C-94C5FF9D1AC3</cbc:UUID>
121+
<cbc:IssueDate>2005-06-21</cbc:IssueDate>
122+
</cac:InvoiceDocumentReference>
123+
</cac:BillingReference>
124+
<cac:TaxTotal>
125+
<cbc:TaxAmount currencyID="GBP">17.50</cbc:TaxAmount>
126+
<cbc:TaxEvidenceIndicator>true</cbc:TaxEvidenceIndicator>
127+
<cac:TaxSubtotal>
128+
<cbc:TaxableAmount currencyID="GBP">100.00</cbc:TaxableAmount>
129+
<cbc:TaxAmount currencyID="GBP">17.50</cbc:TaxAmount>
130+
<cac:TaxCategory>
131+
<cbc:ID>A</cbc:ID>
132+
<cac:TaxScheme>
133+
<cbc:ID>UK VAT</cbc:ID>
134+
<cbc:TaxTypeCode>VAT</cbc:TaxTypeCode>
135+
</cac:TaxScheme>
136+
</cac:TaxCategory>
137+
</cac:TaxSubtotal>
138+
</cac:TaxTotal>
139+
<cac:Item>
140+
<cbc:Description>Acme beeswax</cbc:Description>
141+
<cbc:Name>beeswax</cbc:Name>
142+
<cac:BuyersItemIdentification>
143+
<cbc:ID>6578489</cbc:ID>
144+
</cac:BuyersItemIdentification>
145+
<cac:SellersItemIdentification>
146+
<cbc:ID>17589683</cbc:ID>
147+
</cac:SellersItemIdentification>
148+
<cac:ItemInstance>
149+
<cac:LotIdentification>
150+
<cbc:LotNumberID>546378239</cbc:LotNumberID>
151+
<cbc:ExpiryDate>2010-01-01</cbc:ExpiryDate>
152+
</cac:LotIdentification>
153+
</cac:ItemInstance>
154+
</cac:Item>
155+
<cac:Price>
156+
<cbc:PriceAmount currencyID="GBP">1.00</cbc:PriceAmount>
157+
<cbc:BaseQuantity unitCode="KGM">1</cbc:BaseQuantity>
158+
</cac:Price>
159+
</cac:CreditNoteLine>
160+
</CreditNote>

0 commit comments

Comments
 (0)