From b3fd31f679bdd9a84d31e9e642db0a0fe938e257 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Erik=20=C3=95unapuu?= Date: Thu, 10 Sep 2020 12:24:38 +0300 Subject: [PATCH] Send invoice to Registrar's billing email after topup --- app/models/invoice.rb | 7 +++---- app/models/registrar.rb | 4 ++++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/app/models/invoice.rb b/app/models/invoice.rb index 2f4be2e60..8e82bbea6 100644 --- a/app/models/invoice.rb +++ b/app/models/invoice.rb @@ -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 diff --git a/app/models/registrar.rb b/app/models/registrar.rb index 86ff5ef4d..4d3d9f926 100644 --- a/app/models/registrar.rb +++ b/app/models/registrar.rb @@ -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