mirror of
https://github.com/internetee/registry.git
synced 2025-07-21 10:16:01 +02:00
Send unpayable e-invoice when invoice has already been paid via wire transfer
This commit is contained in:
parent
6b2aaf305f
commit
17188ec635
4 changed files with 15 additions and 12 deletions
|
@ -1,8 +1,8 @@
|
||||||
class SendEInvoiceJob < Que::Job
|
class SendEInvoiceJob < Que::Job
|
||||||
def run(invoice_id)
|
def run(invoice_id, payable: true)
|
||||||
invoice = run_condition(Invoice.find_by(id: invoice_id))
|
invoice = run_condition(Invoice.find_by(id: invoice_id), payable: payable)
|
||||||
|
|
||||||
invoice.to_e_invoice.deliver
|
invoice.to_e_invoice(payable: payable).deliver
|
||||||
ActiveRecord::Base.transaction do
|
ActiveRecord::Base.transaction do
|
||||||
invoice.update(e_invoice_sent_at: Time.zone.now)
|
invoice.update(e_invoice_sent_at: Time.zone.now)
|
||||||
log_success(invoice)
|
log_success(invoice)
|
||||||
|
@ -15,9 +15,9 @@ class SendEInvoiceJob < Que::Job
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def run_condition(invoice)
|
def run_condition(invoice, payable: true)
|
||||||
destroy unless invoice
|
destroy unless invoice
|
||||||
destroy if invoice.do_not_send_e_invoice?
|
destroy if invoice.do_not_send_e_invoice? && payable
|
||||||
invoice
|
invoice
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -99,8 +99,8 @@ class Invoice < ApplicationRecord
|
||||||
generator.as_pdf
|
generator.as_pdf
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_e_invoice
|
def to_e_invoice(payable: true)
|
||||||
generator = Invoice::EInvoiceGenerator.new(self)
|
generator = Invoice::EInvoiceGenerator.new(self, payable: payable)
|
||||||
generator.generate
|
generator.generate
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -120,7 +120,7 @@ class Invoice < ApplicationRecord
|
||||||
wo_vat = transaction.sum / (1 + (vat / 100))
|
wo_vat = transaction.sum / (1 + (vat / 100))
|
||||||
registrar_user.issue_prepayment_invoice(amount: wo_vat,
|
registrar_user.issue_prepayment_invoice(amount: wo_vat,
|
||||||
description: 'Direct top-up via bank transfer',
|
description: 'Direct top-up via bank transfer',
|
||||||
paid: true)
|
payable: false)
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
class Invoice
|
class Invoice
|
||||||
class EInvoiceGenerator
|
class EInvoiceGenerator
|
||||||
attr_reader :invoice
|
attr_reader :invoice
|
||||||
|
attr_reader :payable
|
||||||
|
|
||||||
def initialize(invoice)
|
def initialize(invoice, payable)
|
||||||
@invoice = invoice
|
@invoice = invoice
|
||||||
|
@payable = payable
|
||||||
end
|
end
|
||||||
|
|
||||||
def generate
|
def generate
|
||||||
|
@ -70,9 +72,10 @@ class Invoice
|
||||||
i.total = invoice.total
|
i.total = invoice.total
|
||||||
i.currency = invoice.currency
|
i.currency = invoice.currency
|
||||||
i.delivery_channel = %i[internet_bank portal]
|
i.delivery_channel = %i[internet_bank portal]
|
||||||
|
i.payable = payable
|
||||||
end
|
end
|
||||||
|
|
||||||
EInvoice::EInvoice.new(date: Time.zone.today, invoice: e_invoice_invoice)
|
EInvoice::EInvoice.new(date: Time.zone.today, invoice: e_invoice_invoice)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -54,7 +54,7 @@ class Registrar < ApplicationRecord
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def issue_prepayment_invoice(amount, description = nil, paid: false)
|
def issue_prepayment_invoice(amount, description = nil, payable: true)
|
||||||
vat_rate = ::Invoice::VatRateCalculator.new(registrar: self).calculate
|
vat_rate = ::Invoice::VatRateCalculator.new(registrar: self).calculate
|
||||||
|
|
||||||
invoice = invoices.create!(
|
invoice = invoices.create!(
|
||||||
|
@ -99,7 +99,7 @@ class Registrar < ApplicationRecord
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
SendEInvoiceJob.enqueue(invoice.id) unless paid
|
SendEInvoiceJob.enqueue(invoice.id, payable: payable)
|
||||||
|
|
||||||
invoice
|
invoice
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue