diff --git a/.rubocop.yml b/.rubocop.yml index af3510a15..e08da3315 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -3,7 +3,7 @@ Metrics/LineLength: Metrics/MethodLength: Max: 35 Metrics/CyclomaticComplexity: - Max: 12 + Max: 13 Metrics/PerceivedComplexity: Max: 9 Metrics/AbcSize: diff --git a/app/assets/javascripts/controllers/admin/invoices.js.erb b/app/assets/javascripts/controllers/admin/invoices.js.erb index acb651c0c..e9c94d315 100644 --- a/app/assets/javascripts/controllers/admin/invoices.js.erb +++ b/app/assets/javascripts/controllers/admin/invoices.js.erb @@ -413,9 +413,7 @@ Application.Controllers.controller('InvoicesController', ['$scope', '$state', 'I $scope.history.push({ date: rate.created_at, rate: rate.value, user: rate.user }) }); activeHistory.setting.history.forEach(function (v) { - if (v.value === 'false') { - $scope.history.push({ date: v.created_at, rate: 0, user: v.user }) - } + $scope.history.push({ date: v.created_at, enabled: v.value === 'true', user: v.user }) }); } diff --git a/app/assets/templates/admin/invoices/index.html.erb b/app/assets/templates/admin/invoices/index.html.erb index c24cbf563..1d7b9c703 100644 --- a/app/assets/templates/admin/invoices/index.html.erb +++ b/app/assets/templates/admin/invoices/index.html.erb @@ -518,8 +518,9 @@ - {{'invoices.VAT_disabled'}} - {{value.rate}} + {{'invoices.VAT_disabled'}} + {{'invoices.VAT_enabled'}} + {{value.rate}} {{value.date | amDateFormat:'L LT'}} {{value.user.name}}{{ 'invoices.deleted_user' }} diff --git a/app/services/accounting_export_service.rb b/app/services/accounting_export_service.rb index 6f07bfdaf..3212cc3e1 100644 --- a/app/services/accounting_export_service.rb +++ b/app/services/accounting_export_service.rb @@ -52,9 +52,10 @@ class AccountingExportService end def generate_rows(invoice) + vat = vat_row(invoice) "#{client_row(invoice)}\n" \ "#{items_rows(invoice)}" \ - "#{vat_row(invoice)}\n" + "#{vat.nil? ? '' : "#{vat}\n"}" end # Generate the "subscription" and "reservation" rows associated with the provided invoice @@ -181,9 +182,12 @@ class AccountingExportService # Generate the "VAT" row, which contains the credit to the VAT account, with VAT amount only def vat_row(invoice) - # FIXME, if VAT wasn't enabled, it's calculated anyway + rate = vat_service.invoice_vat(invoice) + # we do not render the VAT row if it was disabled for this invoice + return nil if rate.zero? + # FIXME, round at +/-0.01 if total > sum(items) - vat = (invoice.total - (invoice.total / (vat_service.invoice_vat(invoice) / 100.00 + 1))) / 100.00 + vat = (invoice.total - (invoice.total / (rate / 100.00 + 1))) / 100.00 row = '' columns.each do |column| case column diff --git a/app/services/vat_history_service.rb b/app/services/vat_history_service.rb index c5b302621..320f62d69 100644 --- a/app/services/vat_history_service.rb +++ b/app/services/vat_history_service.rb @@ -26,13 +26,21 @@ class VatHistoryService private def vat_history - key_dates = [] - Setting.find_by(name: 'invoice_VAT-rate').history_values.each do |rate| - key_dates.push(date: rate.created_at, rate: rate.value.to_i) + chronology = [] + end_date = DateTime.now + Setting.find_by(name: 'invoice_VAT-active').history_values.order(created_at: 'DESC').each do |v| + chronology.push(start: v.created_at, end: end_date, enabled: v.value == 'true') + end_date = v.created_at end - Setting.find_by(name: 'invoice_VAT-active').history_values.each do |v| - key_dates.push(date: v.created_at, rate: 0) if v.value == 'false' + date_rates = [] + Setting.find_by(name: 'invoice_VAT-rate').history_values.order(created_at: 'ASC').each do |rate| + range = chronology.select { |p| rate.created_at.between?(p[:start], p[:end]) }.first + date = range[:enabled] ? rate.created_at : range[:end] + date_rates.push(date: date, rate: rate.value.to_i) end - key_dates.sort_by { |k| k[:date] } + chronology.reverse_each do |period| + date_rates.push(date: period[:start], rate: 0) unless period[:enabled] + end + date_rates.sort_by { |k| k[:date] } end -end \ No newline at end of file +end diff --git a/config/locales/app.admin.en.yml b/config/locales/app.admin.en.yml index 649149bee..602993f5f 100644 --- a/config/locales/app.admin.en.yml +++ b/config/locales/app.admin.en.yml @@ -322,6 +322,7 @@ en: total_amount: "Total amount" total_including_all_taxes: "Total incl. all taxes" VAT_disabled: "VAT disabled" + VAT_enabled: "VAT enabled" including_VAT: "Including VAT" including_total_excluding_taxes: "Including Total excl. taxes" including_amount_payed_on_ordering: "Including Amount payed on ordering" diff --git a/config/locales/app.admin.es.yml b/config/locales/app.admin.es.yml index fb31aab90..e96f7c807 100644 --- a/config/locales/app.admin.es.yml +++ b/config/locales/app.admin.es.yml @@ -321,8 +321,9 @@ es: machine_booking-3D_printer: "Reserva de la máquina- Impresora 3D" total_amount: "Cantidad total" total_including_all_taxes: "Total incl. todos los impuestos" - VAT_disabled: "VAT disabled" - including_VAT: "IVA desactivado" + VAT_disabled: "IVA desactivado" + VAT_enabled: "IVA activado" + including_VAT: "Incluido IVA" including_total_excluding_taxes: "Incluido Total excl. impuestos" including_amount_payed_on_ordering: "Incluido el monto pagado en el pedido" settlement_by_debit_card_on_DATE_at_TIME_for_an_amount_of_AMOUNT: "Liquidación por tarjeta de débito el {{DATE}} a las {{TIME}}, por una cantidad de {{AMOUNT}}" diff --git a/config/locales/app.admin.fr.yml b/config/locales/app.admin.fr.yml index 58247168c..6e58acb50 100644 --- a/config/locales/app.admin.fr.yml +++ b/config/locales/app.admin.fr.yml @@ -322,6 +322,7 @@ fr: total_amount: "Montant total" total_including_all_taxes: "Total TTC" VAT_disabled: "TVA désactivée" + VAT_enabled: "TVA activée" including_VAT: "Dont TVA" including_total_excluding_taxes: "Dont total HT" including_amount_payed_on_ordering: "Dont montant payé à la commande" diff --git a/config/locales/app.admin.pt.yml b/config/locales/app.admin.pt.yml index abf71fea4..86025e5ea 100755 --- a/config/locales/app.admin.pt.yml +++ b/config/locales/app.admin.pt.yml @@ -321,8 +321,9 @@ pt: machine_booking-3D_printer: "Reserva de máquina - 3D printer" total_amount: "Montante total" total_including_all_taxes: "Total incluindo todas as taxas" - VAT_disabled: "VAT desativado" - including_VAT: "Incluindo VAT" + VAT_disabled: "IVA desativado" + VAT_enabled: "IVA activado" + including_VAT: "Incluindo IVA" including_total_excluding_taxes: "Incluindo o total de taxas excluidas" including_amount_payed_on_ordering: "Incluindo o valor pago na compra" settlement_by_debit_card_on_DATE_at_TIME_for_an_amount_of_AMOUNT: "Pagamento por cartão de débito em {{DATE}} ás {{TIME}}, no valor de {{AMOUNT}}"