diff --git a/lib/secretariat/trade_party.rb b/lib/secretariat/trade_party.rb index 8ad0125..2105257 100644 --- a/lib/secretariat/trade_party.rb +++ b/lib/secretariat/trade_party.rb @@ -21,8 +21,19 @@ module Secretariat :id, :name, :street1, :street2, :city, :postal_code, :country_id, :vat_id, :global_id, :global_id_scheme_id, :tax_id, :person_name, :legal_organization, + :contact_name, :contact_phone, :contact_email, keyword_init: true, ) do + # BG-6 / BG-9 contact. contact_name is the fork's name for upstream's + # person_name (BT-56); both feed the single DefinedTradeContact element. + def contact? + contact_person_name.present? || contact_phone.present? || contact_email.present? + end + + def contact_person_name + contact_name.present? ? contact_name : person_name + end + def to_xml(xml, exclude_tax: false, version: 2) if id && !exclude_tax xml['ram'].ID id # BT-46 @@ -40,9 +51,22 @@ def to_xml(xml, exclude_tax: false, version: 2) end end end - if person_name + if version == 2 && contact? + # EN16931 BG-6 SELLER CONTACT (required by XRechnung CIUS rule BR-DE-2) xml['ram'].DefinedTradeContact do - xml['ram'].PersonName person_name + if contact_person_name.present? + xml['ram'].PersonName contact_person_name + end + if contact_phone.present? + xml['ram'].TelephoneUniversalCommunication do + xml['ram'].CompleteNumber contact_phone + end + end + if contact_email.present? + xml['ram'].EmailURIUniversalCommunication do + xml['ram'].URIID contact_email + end + end end end xml['ram'].PostalTradeAddress do diff --git a/test/invoice_test.rb b/test/invoice_test.rb index 8af2c76..5242786 100644 --- a/test/invoice_test.rb +++ b/test/invoice_test.rb @@ -291,7 +291,10 @@ def make_de_invoice city: 'Hamburg', postal_code: '20253', country_id: 'DE', - vat_id: 'DE304755032' + vat_id: 'DE304755032', + contact_name: 'Depfu Buchhaltung', + contact_phone: '+49 40 123456', + contact_email: 'billing@depfu.com' ) buyer = TradeParty.new( name: 'Depfu inc', @@ -709,6 +712,16 @@ def test_simple_eu_invoice_with_attachment_against_schematron assert_equal [], errors end + def test_seller_contact_is_rendered_for_v2 + xml = make_de_invoice.to_xml(version: 2) + doc = Nokogiri::XML(xml) + contact = doc.at_xpath('//ram:SellerTradeParty/ram:DefinedTradeContact', 'ram' => 'urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:100') + assert contact, 'expected DefinedTradeContact to be rendered' + assert_equal 'Depfu Buchhaltung', contact.at_xpath('ram:PersonName', 'ram' => 'urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:100').text + assert_equal '+49 40 123456', contact.at_xpath('ram:TelephoneUniversalCommunication/ram:CompleteNumber', 'ram' => 'urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:100').text + assert_equal 'billing@depfu.com', contact.at_xpath('ram:EmailURIUniversalCommunication/ram:URIID', 'ram' => 'urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:100').text + end + def test_simple_de_invoice_v2 xml = make_de_invoice.to_xml(version: 2) v = Validator.new(xml, version: 2)