mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-01-17 06:52:27 +01:00
improved VAT history service + display dates when VAT was enabled in invoice configuration panel + do not render vat row in accouting export if vat was disabled
This commit is contained in:
parent
46c3497c85
commit
276a99c068
@ -3,7 +3,7 @@ Metrics/LineLength:
|
||||
Metrics/MethodLength:
|
||||
Max: 35
|
||||
Metrics/CyclomaticComplexity:
|
||||
Max: 12
|
||||
Max: 13
|
||||
Metrics/PerceivedComplexity:
|
||||
Max: 9
|
||||
Metrics/AbcSize:
|
||||
|
@ -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 })
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -518,8 +518,9 @@
|
||||
<tbody>
|
||||
<tr ng-repeat="value in history | orderBy:'-date'">
|
||||
<td>
|
||||
<span class="no-user-label" ng-show="value.rate === 0" translate>{{'invoices.VAT_disabled'}}</span>
|
||||
<span ng-hide="value.rate === 0">{{value.rate}}</span>
|
||||
<span class="no-user-label" ng-show="value.enabled === false" translate>{{'invoices.VAT_disabled'}}</span>
|
||||
<span class="no-user-label" ng-show="value.enabled === true" translate>{{'invoices.VAT_enabled'}}</span>
|
||||
<span ng-show="value.rate">{{value.rate}}</span>
|
||||
</td>
|
||||
<td>{{value.date | amDateFormat:'L LT'}}</td>
|
||||
<td>{{value.user.name}}<span class="no-user-label" ng-hide="value.user" translate>{{ 'invoices.deleted_user' }}</span></td>
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
end
|
||||
|
@ -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"
|
||||
|
@ -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}}"
|
||||
|
@ -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"
|
||||
|
@ -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}}"
|
||||
|
Loading…
x
Reference in New Issue
Block a user