1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-01-18 07:52:23 +01:00

[bug] (#140) VAT rate is erronous in invoices

This commit is contained in:
Sylvain 2019-08-14 10:56:30 +02:00
parent 13d3197069
commit bebb3354fb
10 changed files with 21 additions and 22 deletions

View File

@ -1,3 +1,3 @@
web: bundle exec rails server puma -p $PORT -b0.0.0.0
#worker: bundle exec sidekiq -C ./config/sidekiq.yml
worker: bundle exec sidekiq -C ./config/sidekiq.yml
mail: bundle exec mailcatcher --foreground

View File

@ -191,14 +191,14 @@ class PDF::Invoice < Prawn::Document
cp = invoice.coupon
discount = 0
if cp.type == 'percent_off'
discount = total_calc * cp.percent_off / 100.0
discount = total_calc * cp.percent_off / 100.00
elsif cp.type == 'amount_off'
# refunds of invoices with cash coupons: we need to ventilate coupons on paid items
if invoice.is_a?(Avoir)
paid_items = invoice.invoice.invoice_items.select{ |ii| ii.amount.positive? }.length
refund_items = invoice.invoice_items.select{ |ii| ii.amount.positive? }.length
discount = ((invoice.coupon.amount_off / paid_items) * refund_items) / 100.0
discount = ((invoice.coupon.amount_off / paid_items) * refund_items) / 100.00
else
discount = cp.amount_off / 100.00
end
@ -222,7 +222,7 @@ class PDF::Invoice < Prawn::Document
end
# total verification
total = invoice.total / 100.0
total = invoice.total / 100.00
puts "ERROR: totals are NOT equals => expected: #{total}, computed: #{total_calc}" if total_calc != total
# TVA
@ -231,7 +231,7 @@ class PDF::Invoice < Prawn::Document
vat_service = VatHistoryService.new
vat_rate = vat_service.invoice_vat(invoice)
vat = total / (vat_rate / 100 + 1)
vat = total / (vat_rate / 100.00 + 1)
data += [[I18n.t('invoices.including_VAT_RATE', RATE: vat_rate), number_to_currency(total - vat)]]
data += [[I18n.t('invoices.including_total_excluding_taxes'), number_to_currency(vat)]]
data += [[I18n.t('invoices.including_amount_payed_on_ordering'), number_to_currency(total)]]
@ -299,7 +299,7 @@ class PDF::Invoice < Prawn::Document
else
# subtract the wallet amount for this invoice from the total
if invoice.wallet_amount
wallet_amount = invoice.wallet_amount / 100.0
wallet_amount = invoice.wallet_amount / 100.00
total -= wallet_amount
else
wallet_amount = nil

View File

@ -55,7 +55,7 @@ class AccountingExportService
# Generate the "client" row, which contains the debit to the client account, all taxes included
def client_row(invoice)
total = invoice.total / 100.0
total = invoice.total / 100.00
row = ''
columns.each do |column|
case column
@ -91,7 +91,7 @@ class AccountingExportService
# Generate the "reservation" row, which contains the credit to the reservation account, all taxes excluded
def reservation_row(invoice, item)
wo_taxes = (item.amount / (vat_service.invoice_vat(invoice) / 100 + 1)) / 100.0
wo_taxes = (item.amount / (vat_service.invoice_vat(invoice) / 100.00 + 1)) / 100.00
row = ''
columns.each do |column|
case column
@ -128,7 +128,7 @@ class AccountingExportService
# Generate the "subscription" row, which contains the credit to the subscription account, all taxes excluded
def subscription_row(invoice)
subscription_item = invoice.invoice_items.select(&:subscription).first
wo_taxes = (subscription_item.amount / (vat_service.invoice_vat(invoice) / 100 + 1)) / 100.0
wo_taxes = (subscription_item.amount / (vat_service.invoice_vat(invoice) / 100.00 + 1)) / 100.00
row = ''
columns.each do |column|
case column
@ -164,7 +164,7 @@ class AccountingExportService
# Generate the "VAT" row, which contains the credit to the VAT account, with VAT amount only
def vat_row(invoice)
vat = (invoice.total - (invoice.total / (vat_service.invoice_vat(invoice) / 100 + 1))) / 100.0
vat = (invoice.total - (invoice.total / (vat_service.invoice_vat(invoice) / 100.00 + 1))) / 100.00
row = ''
columns.each do |column|
case column

View File

@ -22,7 +22,7 @@ class CouponService
unless _coupon.nil?
if _coupon.status(user_id, total) == 'active'
if _coupon.type == 'percent_off'
price = price - (price * _coupon.percent_off / 100.0)
price -= price * _coupon.percent_off / 100.00
elsif _coupon.type == 'amount_off'
# do not apply cash coupon unless it has a lower amount that the total price
if _coupon.amount_off <= price
@ -35,7 +35,6 @@ class CouponService
price
end
##
# Ventilate the discount of the provided coupon over the given amount proportionately to the invoice's total
# @param total {Number} total amount of the invoice expressed in monetary units
@ -44,11 +43,11 @@ class CouponService
##
def ventilate(total, amount, coupon)
price = amount
if !coupon.nil? and total != 0
if !coupon.nil? && total != 0
if coupon.type == 'percent_off'
price = amount - ( amount * coupon.percent_off / 100.0 )
price = amount - (amount * coupon.percent_off / 100.00)
elsif coupon.type == 'amount_off'
ratio = (coupon.amount_off / 100.0) / total
ratio = (coupon.amount_off / 100.00) / total
discount = amount * ratio.abs
price = amount - discount
else

View File

@ -28,7 +28,7 @@ class VatHistoryService
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 / 100.0))
key_dates.push(date: rate.created_at, rate: rate.value.to_i)
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'

View File

@ -3,7 +3,7 @@ json.array!(@plans) do |plan|
json.ui_weight plan.ui_weight
json.group_id plan.group_id
json.base_name plan.base_name
json.amount plan.amount / 100.0
json.amount plan.amount / 100.00
json.interval plan.interval
json.interval_count plan.interval_count
json.type plan.type

View File

@ -22,7 +22,7 @@ wb.add_worksheet(name: t('export_subscriptions.subscriptions')) do |sheet|
t("duration.#{sub.plan.interval}", count: sub.plan.interval_count),
sub.created_at.to_date,
sub.expired_at.to_date,
number_to_currency(sub.plan.amount / 100),
number_to_currency(sub.plan.amount / 100.00),
(sub.stp_subscription_id.nil?)? t('export_subscriptions.local_payment') : t('export_subscriptions.online_payment')
]
styles = [nil, nil, nil, nil, nil, date, date, nil, nil]

View File

@ -46,7 +46,7 @@ module Subscriptions
# Check that the user benefit from prices of his plan
printer = Machine.find_by(slug: 'imprimante-3d')
assert_equal 15, (printer.prices.find_by(group_id: user.group_id, plan_id: user.subscription.plan_id).amount / 100), 'machine hourly price does not match'
assert_equal 15, (printer.prices.find_by(group_id: user.group_id, plan_id: user.subscription.plan_id).amount / 100.00), 'machine hourly price does not match'
# Check notification was sent to the user
notification = Notification.find_by(notification_type_id: NotificationType.find_by_name('notify_member_subscribed_plan'), attached_object_type: 'Subscription', attached_object_id: subscription[:id])

View File

@ -43,7 +43,7 @@ class Subscriptions::CreateAsUserTest < ActionDispatch::IntegrationTest
# Check that the user benefit from prices of his plan
printer = Machine.find_by(slug: 'imprimante-3d')
assert_equal 15,
(printer.prices.find_by(group_id: @user.group_id, plan_id: @user.subscription.plan_id).amount / 100),
(printer.prices.find_by(group_id: @user.group_id, plan_id: @user.subscription.plan_id).amount / 100.00),
'machine hourly price does not match'
# Check notifications were sent for every admins
@ -133,7 +133,7 @@ class Subscriptions::CreateAsUserTest < ActionDispatch::IntegrationTest
assert_equal 10,
(printer.prices.find_by(
group_id: @vlonchamp.group_id,
plan_id: @vlonchamp.subscription.plan_id).amount / 100
plan_id: @vlonchamp.subscription.plan_id).amount / 100.00
),
'machine hourly price does not match'

View File

@ -94,7 +94,7 @@ class ActiveSupport::TestCase
if Setting.find_by(name: 'invoice_VAT-active').value == 'true'
vat_service = VatHistoryService.new
vat_rate = vat_service.invoice_vat(invoice)
computed_ht = sprintf('%.2f', (invoice.total / (vat_rate / 100 + 1)) / 100.0).to_f
computed_ht = sprintf('%.2f', (invoice.total / (vat_rate / 100.00 + 1)) / 100.00).to_f
assert_equal computed_ht, ht_amount, 'Total excluding taxes rendered in the PDF file is not computed correctly'
else