move to ajax function for every direct debit xml download

This commit is contained in:
viehlieb 2023-11-28 16:39:24 +01:00
parent 636aad0b3e
commit f98d083647
23 changed files with 158 additions and 128 deletions

View file

@ -5,41 +5,28 @@ class OrderCollectiveDirectDebitXml
def initialize(group_orders)
batch_booking = group_orders.count > 1 ? true : false
begin
sdd = SEPA::DirectDebit.new(
# Name of the initiating party and creditor, in German: "Auftraggeber"
# String, max. 70 char
#TODO: needed from config
name: FoodsoftConfig[:name],
sdd = SEPA::DirectDebit.new(
# Name of the initiating party and creditor, in German: "Auftraggeber"
# String, max. 70 char
name: FoodsoftConfig[:name],
# OPTIONAL: Business Identifier Code (SWIFT-Code) of the creditor
# String, 8 or 11 char
#TODO: needed - config
bic: FoodsoftConfig[:group_order_invoices][:bic],
#'BANKDEFFXXX',
# OPTIONAL: Business Identifier Code (SWIFT-Code) of the creditor
# String, 8 or 11 char
bic: FoodsoftConfig[:group_order_invoices][:bic],
# International Bank Account Number of the creditor
# String, max. 34 chars
#TODO: needed
iban: FoodsoftConfig[:group_order_invoices][:iban],
#'DE87200500001234567890',
# International Bank Account Number of the creditor
# String, max. 34 chars
iban: FoodsoftConfig[:group_order_invoices][:iban], # remove spaces
# Creditor Identifier, in German: Gläubiger-Identifikationsnummer
# String, max. 35 chars
#TODO: needed - config
creditor_identifier: FoodsoftConfig[:group_order_invoices][:creditor_identifier],
#'DE98ZZZ09999999999'
)
rescue StandardError => e
raise "SEPA Direct Debit XML could not be created: #{e.message}"
end
# Creditor Identifier, in German: Gläubiger-Identifikationsnummer
# String, max. 35 chars
creditor_identifier: FoodsoftConfig[:group_order_invoices][:creditor_identifier],
)
group_orders.each do |group_order|
# Second: Add transactions
# Second: Add transactions
sdd.add_transaction(
# Name of the debtor, in German: "Zahlungspflichtiger"
# String, max. 70 char
#TODO: From ordergroup
name: group_order.ordergroup.name,
#Ende zu Ende Referenz
@ -47,17 +34,14 @@ class OrderCollectiveDirectDebitXml
# OPTIONAL: Business Identifier Code (SWIFT-Code) of the debtor's account
# String, 8 or 11 char
#TODO: needed where does it come from?
bic: group_order.ordergroup.sepa_account_holder.bic,
bic: group_order.ordergroup.sepa_account_holder.bic.gsub(' ', ''),
# International Bank Account Number of the debtor's account
# String, max. 34 chars
#TODO: needed
iban: group_order.ordergroup.sepa_account_holder.iban,
iban: group_order.ordergroup.sepa_account_holder.iban.gsub(' ', ''),
# Amount
# Number with two decimal digit
#TODO: needed comesfrom group_order.price
amount: group_order.price,
# OPTIONAL: Currency, EUR by default (ISO 4217 standard)
@ -66,22 +50,18 @@ class OrderCollectiveDirectDebitXml
# OPTIONAL: Instruction Identification, will not be submitted to the debtor
# String, max. 35 char
#TODO: is this neccessary?
#instruction: '12345',
# OPTIONAL: Unstructured remittance information, in German "Verwendungszweck"
# String, max. 140 char
#TODO: invoice_number + supplier
remittance_information: "#{group_order.group_order_invoice.invoice_number} #{group_order.order.supplier.name}",
# Mandate identifikation, in German "Mandatsreferenz"
# String, max. 35 char
#TODO: get it from fsconfig? rather from SEPA
mandate_id: group_order.ordergroup.sepa_account_holder.mandate_id,
# Mandate Date of signature, in German "Datum, zu dem das Mandat unterschrieben wurde"
# Date
#TODO: neccessary?? if yes, get it from ordergroup
mandate_date_of_signature: group_order.ordergroup.sepa_account_holder.mandate_date_of_signature,
# Local instrument, in German "Lastschriftart"
@ -97,20 +77,18 @@ class OrderCollectiveDirectDebitXml
# 'RCUR' ("Folge-Lastschrift")
# 'OOFF' ("Einmalige Lastschrift")
# 'FNAL' ("Letztmalige Lastschrift")
#TODO: selectable and default RCUR
sequence_type: group_order.group_order_invoice.sepa_sequence_type || 'RCUR',
# OPTIONAL: Requested collection date, in German "Fälligkeitsdatum der Lastschrift"
# Date
#TODO: two weeks from now?
requested_date: Time.zone.today + 2.days,
# OPTIONAL: Enables or disables batch booking, in German "Sammelbuchung / Einzelbuchung"
# True or False
batch_booking: batch_booking
)
# Last: create XML string
# Last: create XML string
end
@xml_string = sdd.to_xml # Use schema pain.008.001.02
@xml_string = sdd.to_xml # Use schema pain.008.001.02
end
end