mirror of
https://github.com/internetee/registry.git
synced 2025-08-04 08:52:04 +02:00
Invoice cancelling
This commit is contained in:
parent
56d7f9f2e2
commit
a26ce110b2
17 changed files with 113 additions and 25 deletions
|
@ -25,13 +25,14 @@ class BankTransaction < ActiveRecord::Base
|
|||
match = description.match(/^[^\d]*(\d+)/)
|
||||
return unless match
|
||||
|
||||
invoice_id = match[1].to_i
|
||||
return unless invoice_id
|
||||
invoice_no = match[1].to_i
|
||||
return unless invoice_no
|
||||
|
||||
invoice = registrar.invoices.find_by(id: invoice_id)
|
||||
invoice = registrar.invoices.find_by(number: invoice_no)
|
||||
return unless invoice
|
||||
|
||||
return if invoice.binded?
|
||||
return if invoice.cancelled?
|
||||
|
||||
return if invoice.sum != sum
|
||||
create_activity(registrar, invoice)
|
||||
|
@ -39,13 +40,13 @@ class BankTransaction < ActiveRecord::Base
|
|||
# rubocop: enable Metrics/PerceivedComplexity
|
||||
# rubocop: enable Metrics/CyclomaticComplexity
|
||||
|
||||
def bind_invoice(invoice_id)
|
||||
def bind_invoice(invoice_no)
|
||||
if binded?
|
||||
errors.add(:base, I18n.t('transaction_is_already_binded'))
|
||||
return
|
||||
end
|
||||
|
||||
invoice = Invoice.find_by(id: invoice_id)
|
||||
invoice = Invoice.find_by(number: invoice_no)
|
||||
|
||||
unless invoice
|
||||
errors.add(:base, I18n.t('invoice_was_not_found'))
|
||||
|
@ -57,6 +58,11 @@ class BankTransaction < ActiveRecord::Base
|
|||
return
|
||||
end
|
||||
|
||||
if invoice.cancelled?
|
||||
errors.add(:base, I18n.t('cannot_bind_cancelled_invoice'))
|
||||
return
|
||||
end
|
||||
|
||||
if invoice.sum != sum
|
||||
errors.add(:base, I18n.t('invoice_and_transaction_sums_do_not_match'))
|
||||
return
|
||||
|
|
|
@ -67,6 +67,19 @@ class Invoice < ActiveRecord::Base
|
|||
"invoice-#{number}.pdf"
|
||||
end
|
||||
|
||||
def cancel
|
||||
if binded?
|
||||
errors.add(:base, I18n.t('cannot_cancel_paid_invoice'))
|
||||
return false
|
||||
end
|
||||
self.cancelled_at = Time.zone.now
|
||||
save
|
||||
end
|
||||
|
||||
def cancelled?
|
||||
cancelled_at.present?
|
||||
end
|
||||
|
||||
def forward(html)
|
||||
return false unless valid?
|
||||
return false unless billing_email.present?
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue