1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-01 12:24:28 +01:00

compute total without taxes + fix close period date pickers + improved archived % number format

This commit is contained in:
Sylvain 2019-03-12 13:36:10 +01:00
parent b9e427a9fc
commit 4f418cc3fb
3 changed files with 23 additions and 11 deletions

View File

@ -666,7 +666,7 @@ Application.Controllers.controller('ClosePeriodModalController', ['$scope', '$ui
// date pickers values are bound to these variables
$scope.period = {
start_at: LAST_CLOSING,
end_at: moment(YESTERDAY).isBefore(MAX_END) ? YESTERDAY : MAX_END,
end_at: moment(YESTERDAY).isBefore(MAX_END) ? YESTERDAY : MAX_END
};
// any form errors will come here
@ -712,17 +712,22 @@ Application.Controllers.controller('ClosePeriodModalController', ['$scope', '$ui
title: _t('invoices.confirmation_required'),
msg: _t(
'invoices.confirm_close_START_END',
{ START: moment($scope.period.start_at).format('LL'), END: moment($scope.period.end_at).format('LL') }
{ START: moment.utc($scope.period.start_at).format('LL'), END: moment.utc($scope.period.end_at).format('LL') }
)
};
}
}
},
function () { // creation confirmed
AccountingPeriod.save({ accounting_period: $scope.period }, function (resp) {
AccountingPeriod.save({
accounting_period: {
start_at: moment.utc($scope.period.start_at).toDate(),
end_at: moment.utc($scope.period.end_at).endOf('day').toDate()
}
}, function (resp) {
growl.success(_t(
'invoices.period_START_END_closed_success',
{ START: moment(resp.start_at).format('LL'), END: moment(resp.end_at).format('LL') }
{ START: moment.utc(resp.start_at).format('LL'), END: moment.utc(resp.end_at).format('LL') }
));
$uibModalInstance.close(resp);
}

View File

@ -99,13 +99,20 @@ class AccountingPeriod < ActiveRecord::Base
File.write(archive_file, to_json_archive(data))
end
def price_without_taxe(invoice)
invoice[:invoice].total - (invoice[:invoice].total * invoice[:vat_rate])
end
def compute_totals
self.period_total = (invoices.where(type: nil).all.map(&:total).reduce(:+) || 0) -
(invoices.where(type: 'Avoir').all.map(&:total).reduce(:+) || 0)
self.perpetual_total = (Invoice.where('CAST(created_at AS DATE) <= :end_date AND type IS NULL', end_date: end_at)
.all.map(&:total).reduce(:+) || 0) -
(Invoice.where("CAST(created_at AS DATE) <= :end_date AND type = 'Avoir'", end_date: end_at)
.all.map(&:total).reduce(:+) || 0)
period_invoices = invoices_with_vat(invoices.where(type: nil))
period_avoirs = invoices_with_vat(invoices.where(type: 'Avoir'))
self.period_total = (period_invoices.map(&method(:price_without_taxe)).reduce(:+) || 0) -
(period_avoirs.map(&method(:price_without_taxe)).reduce(:+) || 0)
all_invoices = invoices_with_vat(Invoice.where('CAST(created_at AS DATE) <= :end_date AND type IS NULL', end_date: end_at))
all_avoirs = invoices_with_vat(Invoice.where("CAST(created_at AS DATE) <= :end_date AND type = 'Avoir'", end_date: end_at))
self.perpetual_total = (all_invoices.map(&method(:price_without_taxe)).reduce(:+) || 0) -
(all_avoirs.map(&method(:price_without_taxe)).reduce(:+) || 0)
self.footprint = compute_footprint
end

View File

@ -3,5 +3,5 @@
json.amount do
json.without_tax number_to_currency((price - (price * vat_rate)) / 100.0)
json.all_taxes_included number_to_currency(price / 100.0)
json.vat_rate vat_rate.positive? ? "#{vat_rate * 100} %" : 'none'
json.vat_rate vat_rate.positive? ? number_to_percentage(vat_rate * 100) : 'none'
end