Skip to content

Commit

Permalink
add CN logic
Browse files Browse the repository at this point in the history
  • Loading branch information
lovrocolic committed Sep 27, 2024
1 parent 2ea1089 commit a262b57
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions app/services/credit_notes/apply_taxes_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ def call
result.applied_taxes << applied_tax

base_amount_cents = compute_base_amount_cents(tax_code)
applied_tax.base_amount_cents = base_amount_cents.round
applied_tax.base_amount_cents = (base_amount_cents.round * taxes_base_rate(invoice_applied_tax)).round

tax_amount_cents = (base_amount_cents * invoice_applied_tax.tax_rate).fdiv(100)
tax_amount_cents = (applied_tax.base_amount_cents * invoice_applied_tax.tax_rate).fdiv(100)
applied_tax.amount_cents = tax_amount_cents.round

applied_taxes_amount_cents += tax_amount_cents
Expand Down Expand Up @@ -102,5 +102,11 @@ def pro_rated_taxes_rate(applied_tax)
def find_invoice_applied_tax(tax_code)
invoice.applied_taxes.find_by(tax_code: tax_code)
end

def taxes_base_rate(applied_tax)
return 1 if applied_tax.fees_amount_cents.blank? || applied_tax.fees_amount_cents.zero?

applied_tax.taxable_base_amount_cents.fdiv(applied_tax.fees_amount_cents)
end
end
end
2 changes: 1 addition & 1 deletion app/services/fees/apply_provider_taxes_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def taxes_base_rate(tax)
tax_amount_cents = (fee.sub_total_excluding_taxes_amount_cents * tax_rate).fdiv(100)

if tax.tax_amount < tax_amount_cents
tax.tax_amount.fdiv(tax_amount_cents.round)
tax.tax_amount.fdiv(tax_amount_cents)
else
1
end
Expand Down

0 comments on commit a262b57

Please sign in to comment.