mirror of
https://github.com/internetee/registry.git
synced 2025-08-04 00:42:04 +02:00
Invoice cancelling
This commit is contained in:
parent
56d7f9f2e2
commit
a26ce110b2
17 changed files with 113 additions and 25 deletions
|
@ -51,3 +51,6 @@
|
|||
@media (min-width: 768px) and (max-width: 991px)
|
||||
.control-label
|
||||
text-align: left !important
|
||||
|
||||
.text-grey
|
||||
color: grey
|
||||
|
|
|
@ -12,7 +12,7 @@ class Admin::BankTransactionsController < AdminController
|
|||
end
|
||||
|
||||
def bind
|
||||
if @bank_transaction.bind_invoice(params[:invoice_id])
|
||||
if @bank_transaction.bind_invoice(params[:invoice_no])
|
||||
flash[:notice] = I18n.t('record_created')
|
||||
redirect_to [:admin, @bank_transaction]
|
||||
else
|
||||
|
|
|
@ -28,6 +28,16 @@ class Registrar::InvoicesController < RegistrarController
|
|||
end
|
||||
end
|
||||
|
||||
def cancel
|
||||
if @invoice.cancel
|
||||
flash[:notice] = t('record_updated')
|
||||
redirect_to([:registrar, @invoice])
|
||||
else
|
||||
flash.now[:alert] = t('failed_to_update_record')
|
||||
render :show
|
||||
end
|
||||
end
|
||||
|
||||
def download_pdf
|
||||
# render 'pdf', layout: false
|
||||
|
||||
|
|
|
@ -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?
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
- content_for :actions do
|
||||
= link_to(t('back'), :back, class: 'btn btn-default')
|
||||
= link_to(t('back'), admin_bank_transaction_path(@bank_transaction), class: 'btn btn-default')
|
||||
= render 'shared/title', name: t(:bank_transaction)
|
||||
|
||||
= form_for([:admin, @bank_transaction], html: { class: 'form-horizontal' }) do |f|
|
||||
|
|
|
@ -57,5 +57,5 @@
|
|||
%dl.dl-horizontal
|
||||
%dt{style: 'padding-top: 5px'}= t('binded_invoice')
|
||||
%dd
|
||||
= text_field_tag(:invoice_id, params[:invoice_id], class: 'form-control')
|
||||
= text_field_tag(:invoice_no, params[:invoice_no], class: 'form-control')
|
||||
= button_tag(t('bind_manually'), class: 'btn btn-primary')
|
||||
|
|
|
@ -21,9 +21,15 @@
|
|||
%tr
|
||||
%td= link_to(x, [:admin, x])
|
||||
%td= link_to(x.buyer_name, admin_registrar_path(x.buyer_id))
|
||||
%td= l(x.due_date)
|
||||
- if x.cancelled?
|
||||
%td.text-grey= t('cancelled')
|
||||
- else
|
||||
%td= l(x.due_date)
|
||||
|
||||
- if x.binded?
|
||||
%td= l(x.receipt_date)
|
||||
- elsif x.cancelled?
|
||||
%td.text-grey= t('cancelled')
|
||||
- else
|
||||
%td.text-danger= t('unpaid')
|
||||
.row
|
||||
|
|
|
@ -25,9 +25,15 @@
|
|||
%td= link_to(x, [:registrar, x])
|
||||
- if x.receipt_date
|
||||
%td= l(x.receipt_date)
|
||||
- elsif x.cancelled?
|
||||
%td.text-grey= t('cancelled')
|
||||
- else
|
||||
%td{class: 'text-danger'}= t(:unpaid)
|
||||
%td= l(x.due_date)
|
||||
|
||||
- if x.cancelled?
|
||||
%td.text-grey= t('cancelled')
|
||||
- else
|
||||
%td= l(x.due_date)
|
||||
%td= x.sum
|
||||
.row
|
||||
.col-md-12
|
||||
|
|
|
@ -4,12 +4,21 @@
|
|||
%dt= t('issue_date')
|
||||
%dd= l(@invoice.created_at)
|
||||
|
||||
- if @invoice.cancelled?
|
||||
%dt= t('cancel_date')
|
||||
%dd= l(@invoice.cancelled_at)
|
||||
|
||||
%dt= t('due_date')
|
||||
%dd= l(@invoice.due_date)
|
||||
- if @invoice.cancelled?
|
||||
%dd.text-grey= t('cancelled')
|
||||
- else
|
||||
%dd= l(@invoice.due_date)
|
||||
|
||||
%dt= t('receipt_date')
|
||||
- if @invoice.binded?
|
||||
%dd= l(@invoice.receipt_date)
|
||||
- elsif @invoice.cancelled?
|
||||
%dd.text-grey= t('cancelled')
|
||||
- else
|
||||
%dd{class: 'text-danger'}= t('unpaid')
|
||||
|
||||
|
|
|
@ -151,12 +151,21 @@
|
|||
%dt= t('issue_date')
|
||||
%dd= l(@invoice.created_at)
|
||||
|
||||
- if @invoice.cancelled?
|
||||
%dt= t('cancel_date')
|
||||
%dd= l(@invoice.cancelled_at)
|
||||
|
||||
%dt= t('due_date')
|
||||
%dd= l(@invoice.due_date)
|
||||
- if @invoice.cancelled?
|
||||
%dd= t('cancelled')
|
||||
- else
|
||||
%dd= l(@invoice.due_date)
|
||||
|
||||
%dt= t('receipt_date')
|
||||
- if @invoice.binded?
|
||||
%dd= l(@invoice.receipt_date)
|
||||
- elsif @invoice.cancelled?
|
||||
%dd= t('cancelled')
|
||||
- else
|
||||
%dd{class: 'text-danger'}= t('unpaid')
|
||||
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
- content_for :actions do
|
||||
= link_to(t(:download), download_pdf_registrar_invoice_path(@invoice), class: 'btn btn-default')
|
||||
= link_to(t(:forward_invoice), forward_registrar_invoice_path(@invoice), class: 'btn btn-default')
|
||||
= link_to(t(:back), :back, class: 'btn btn-default')
|
||||
= link_to(t(:forward), forward_registrar_invoice_path(@invoice), class: 'btn btn-default')
|
||||
- if !@invoice.cancelled? && !@invoice.binded?
|
||||
= link_to(t(:cancel), cancel_registrar_invoice_path(@invoice), method: :patch, class: 'btn btn-default')
|
||||
= link_to(t(:back), registrar_invoices_path, class: 'btn btn-default')
|
||||
= render 'shared/title', name: @invoice.to_s
|
||||
= render 'shared/full_errors', object: @invoice
|
||||
|
||||
.row
|
||||
.col-md-6= render 'registrar/invoices/partials/details'
|
||||
|
@ -11,5 +14,7 @@
|
|||
.col-md-6= render 'registrar/invoices/partials/buyer'
|
||||
.row
|
||||
.col-md-12= render 'registrar/invoices/partials/items'
|
||||
.row.semifooter
|
||||
.col-md-12.text-right= render 'registrar/invoices/partials/banklinks'
|
||||
|
||||
- if !@invoice.cancelled? && !@invoice.binded?
|
||||
.row.semifooter
|
||||
.col-md-12.text-right= render 'registrar/invoices/partials/banklinks'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue