diff --git a/app/assets/templates/admin/invoices/index.html.erb b/app/assets/templates/admin/invoices/index.html.erb index 4c96d3789..11d7b2ee3 100644 --- a/app/assets/templates/admin/invoices/index.html.erb +++ b/app/assets/templates/admin/invoices/index.html.erb @@ -154,11 +154,11 @@ {{ 'including_VAT' | translate }} {{invoice.VAT.rate}} % - {{30*invoice.VAT.rate/100 | currency}} + {{30/(invoice.VAT.rate/100+1) | currency}} {{ 'including_total_excluding_taxes' }} - {{30-(30*invoice.VAT.rate/100) | currency}} + {{30-(30/(invoice.VAT.rate/100+1)) | currency}} {{ 'including_amount_payed_on_ordering' }} diff --git a/app/models/invoice.rb b/app/models/invoice.rb index 0421c364d..787eec524 100644 --- a/app/models/invoice.rb +++ b/app/models/invoice.rb @@ -117,7 +117,7 @@ class Invoice < ActiveRecord::Base reference end - # only for debug + # for debug & used by rake task "fablab:regenerate_invoices" def regenerate_invoice_pdf pdf = ::PDF::Invoice.new(self).render File.binwrite(file, pdf) diff --git a/app/pdfs/pdf/invoice.rb b/app/pdfs/pdf/invoice.rb index 9651cca61..ce890dad0 100644 --- a/app/pdfs/pdf/invoice.rb +++ b/app/pdfs/pdf/invoice.rb @@ -138,7 +138,7 @@ module PDF data += [ [I18n.t('invoices.total_including_all_taxes'), number_to_currency(total)] ] vat_rate = Setting.find_by({name: 'invoice_VAT-rate'}).value.to_f - vat = total * vat_rate / 100 + vat = total / (vat_rate / 100 + 1) data += [ [I18n.t('invoices.including_VAT_RATE', RATE: vat_rate), number_to_currency(vat)] ] data += [ [I18n.t('invoices.including_total_excluding_taxes'), number_to_currency(total-vat)] ] data += [ [I18n.t('invoices.including_amount_payed_on_ordering'), number_to_currency(total)] ] diff --git a/lib/tasks/fablab.rake b/lib/tasks/fablab.rake index 7aa432945..8472698fa 100644 --- a/lib/tasks/fablab.rake +++ b/lib/tasks/fablab.rake @@ -26,14 +26,7 @@ namespace :fablab do start_date = Time.new(year.to_i, month.to_i, 1) end_date = start_date.next_month puts "-> Start regenerate the invoices between #{I18n.l start_date, format: :long} in #{I18n.l end_date-1.minute, format: :long}" - index = '000' invoices = Invoice.only_invoice.where("created_at >= :start_date AND created_at < :end_date", {start_date: start_date, end_date: end_date}).order(created_at: :asc) - invoices.each do |i| - i.update_columns(reference: "#{year.to_s[2..3]}#{'%02d' % month}#{index.next!}#{i.stp_invoice_id ? '/VL' : ''}") - if i.avoir - i.avoir.update_columns(reference: "#{year.to_s[2..3]}#{'%02d' % month}#{index.next!}/A") - end - end invoices.each(&:regenerate_invoice_pdf) puts "-> Done" end