Send invoice to Registrar's billing email after topup

This commit is contained in:
Karl Erik Õunapuu 2020-09-10 12:24:38 +03:00
parent 33c14fb957
commit b3fd31f679
No known key found for this signature in database
GPG key ID: C9DD647298A34764
2 changed files with 7 additions and 4 deletions

View file

@ -82,7 +82,7 @@ class Invoice < ApplicationRecord
end
def vat_amount
(subtotal * vat_rate / 100)
subtotal * vat_rate / 100
end
def total
@ -117,9 +117,8 @@ class Invoice < ApplicationRecord
return unless registrar_user
vat = VatRateCalculator.new(registrar: registrar_user).calculate
wo_vat = (transaction.sum / (1 + (vat / 100)))
registrar_user.issue_prepayment_invoice(wo_vat, 'Direct top-up via bank transfer',
payable: false)
net = (transaction.sum / (1 + (vat / 100)))
registrar_user.issue_prepayment_invoice(net, 'Direct top-up via bank transfer', payable: false)
end
private

View file

@ -101,6 +101,10 @@ class Registrar < ApplicationRecord
)
SendEInvoiceJob.enqueue(invoice.id, payable: payable)
unless payable
InvoiceMailer.invoice_email(invoice: invoice, recipient: billing_email).deliver_now
end
invoice
end