diff --git a/app/models/data_digest_templates/accounting_journal_entry.rb b/app/models/data_digest_templates/accounting_journal_entry.rb index 38c687281..b81ba4110 100644 --- a/app/models/data_digest_templates/accounting_journal_entry.rb +++ b/app/models/data_digest_templates/accounting_journal_entry.rb @@ -94,10 +94,7 @@ def crunch(records) formatter(:taf) do |_options = {}| records.keys.map do |source| - TafBlock::Collection.new do - derive(source.booking.tenant) - derive(source) - end + TafBlock::Collection.new { derive(source) } end.join("\n\n") end diff --git a/app/models/invoice.rb b/app/models/invoice.rb index 01bea0730..b517ecb1d 100644 --- a/app/models/invoice.rb +++ b/app/models/invoice.rb @@ -191,16 +191,16 @@ def journal_entries [debitor_journal_entry] + invoice_parts.map(&:journal_entries) end - def human_ref - format('HV%05d', id) + def accounting_ref + format('HV%05d', id + 1) end def debitor_journal_entry Accounting::JournalEntry.new( - account: booking.tenant.accounting_debitor_account_nr, + account: organisation.accounting_settings.debitor_account_nr, date: issued_at, amount:, amount_type: :brutto, side: :soll, - reference: human_ref, source: self, currency:, booking:, - text: [self.class.model_name.human, human_ref].join(' ') + reference: accounting_ref, source: self, currency:, booking:, + text: "#{self.class.model_name.human} #{accounting_ref} - #{booking.tenant.last_name}" ) end end diff --git a/app/models/invoice_part.rb b/app/models/invoice_part.rb index cbd995cee..f834f9d93 100644 --- a/app/models/invoice_part.rb +++ b/app/models/invoice_part.rb @@ -70,10 +70,6 @@ def journal_entries nil end - # def amount_netto - # amount - (vat_category&.amount_tax(amount) || 0) - # end - def self.from_usage(usage, **attributes) return unless usage diff --git a/app/models/invoice_parts/add.rb b/app/models/invoice_parts/add.rb index 19f9c04e1..5a7f15dc6 100644 --- a/app/models/invoice_parts/add.rb +++ b/app/models/invoice_parts/add.rb @@ -35,9 +35,9 @@ def journal_entries # rubocop:disable Metrics/AbcSize [ Accounting::JournalEntry.new( account: tarif&.accounting_account_nr, date: invoice.issued_at, amount: amount.abs, amount_type: :brutto, - side: :haben, tax_code: vat_category&.accounting_vat_code, reference: invoice.human_ref, source: self, + side: :haben, tax_code: vat_category&.accounting_vat_code, reference: invoice.accounting_ref, source: self, currency: organisation.currency, booking:, cost_center: tarif&.accounting_profit_center_nr, - text: [invoice.class.model_name.human, invoice.human_ref, label].join(' ') + text: "#{invoice.class.model_name.human} #{invoice.accounting_ref} #{label}" ) ] end diff --git a/app/models/vat_category.rb b/app/models/vat_category.rb index 5491431e7..12266b891 100644 --- a/app/models/vat_category.rb +++ b/app/models/vat_category.rb @@ -20,9 +20,9 @@ def to_s "#{label} (#{formatted_percentage})" end - def amount_tax(amount) - return 0 if percentage.blank? || percentage.zero? - - (amount / (100 + percentage)) * percentage + def breakdown(amount) + tax = 0 + tax = (amount / (100 + percentage)) * percentage if percentage.present? + { tax:, brutto: amount, netto: (amount - tax) } end end diff --git a/app/services/export/pdf/renderables/invoice/invoice_parts_table.rb b/app/services/export/pdf/renderables/invoice/invoice_parts_table.rb index b80dc4d24..561e3450c 100644 --- a/app/services/export/pdf/renderables/invoice/invoice_parts_table.rb +++ b/app/services/export/pdf/renderables/invoice/invoice_parts_table.rb @@ -96,7 +96,7 @@ def vat_table_data number_to_percentage(vat_category.percentage, precision: 2), organisation.currency, number_to_currency(amount, unit: ''), - number_to_currency(vat_category.amount_tax(amount), unit: '') + number_to_currency(vat_category.breakdown(amount)[:tax], unit: '') ] end end diff --git a/app/services/taf_block.rb b/app/services/taf_block.rb index e9c32ce0b..673509a56 100644 --- a/app/services/taf_block.rb +++ b/app/services/taf_block.rb @@ -28,11 +28,9 @@ def self.block(...) }.freeze CAST_CLASSES = { # rubocop:disable Lint/ConstantDefinitionInBlock - boolean: [::FalseClass, ::TrueClass], - decimal: [::BigDecimal, ::Float], - number: [::Numeric], - date: [::Date, ::DateTime, ::ActiveSupport::TimeWithZone], - string: [::String] + boolean: [::FalseClass, ::TrueClass], decimal: [::BigDecimal, ::Float], + number: [::Numeric], date: [::Date, ::DateTime, ::ActiveSupport::TimeWithZone], + string: [::String], symbol: [::Symbol] }.freeze def self.cast(value, as: nil) @@ -142,6 +140,8 @@ def self.derive(value, **override) # String[5]; The Id of the tax. [MWSt-Kürzel] TaxId: journal_entry.tax_code, + MkTxB: journal_entry.tax_code.present?, + # String[61*]; This string specifies the first line of the booking text. Text: journal_entry.text&.slice(0..59)&.lines&.first&.strip || '-', # rubocop:disable Style/SafeNavigationChainLength @@ -187,16 +187,17 @@ def self.derive(value, **override) derive_from Invoice do |invoice, **_override| next unless invoice.is_a?(Invoices::Invoice) || invoice.is_a?(Invoices::Deposit) - op_id = Value.cast(invoice.human_ref, as: :symbol) + op_id = Value.cast(invoice.accounting_ref, as: :symbol) pk_key = [invoice.booking.tenant.accounting_debitor_account_nr, invoice.organisation.accounting_settings.currency_account_nr].then { "[#{_1.join(',')}]" } journal_entries = invoice.journal_entries.flatten.compact [ + derive(invoice.booking.tenant), new(:OPd, **{ PkKey: pk_key, OpId: op_id, ZabId: '15T' }), - new(:Blg, **{ OpId: op_id, Date: invoice.issued_at, Orig: true }) do - derive(journal_entries.shift, Flags: 1, OpId: op_id) + new(:Blg, **{ Date: invoice.issued_at, Orig: true }) do + derive(journal_entries.shift, Flags: 1, OpId: op_id, PkKey: pk_key, CAcc: :div) journal_entries.each { derive(_1, OpId: op_id) } end ] diff --git a/app/views/renderables/invoice_parts/deposit/_form_fields.html.slim b/app/views/renderables/invoice_parts/deposit/_form_fields.html.slim new file mode 100644 index 000000000..25fde7e25 --- /dev/null +++ b/app/views/renderables/invoice_parts/deposit/_form_fields.html.slim @@ -0,0 +1,19 @@ +div + = f.hidden_field :id + = f.hidden_field :usage_id + = f.hidden_field :type + = f.hidden_field :vat_category_id + + .row + .col-1.py-2 + = f.check_box :_destroy, { checked: invoice_part.apply, hide_label: true }, '0', '1' + .col-4 + = f.text_field :label, hide_label: true + .col-4 + = f.text_field :breakdown, hide_label: true + .col-2 + = f.text_field :amount, hide_label: true, class: 'text-end', inputmode: "numeric" + .col-1.p-2 + - unless invoice_part.new_record? || invoice_part.invoice.blank? + = link_to edit_manage_invoice_invoice_part_path(invoice_part.invoice, invoice_part) + i.fa.fa-pencil