mirror of
https://github.com/internetee/registry.git
synced 2025-06-10 14:44:47 +02:00
implement paid cancel
This commit is contained in:
parent
a1c38fb1cc
commit
af8bc41556
4 changed files with 29 additions and 0 deletions
|
@ -20,6 +20,23 @@ module Admin
|
|||
end
|
||||
end
|
||||
|
||||
def cancel_paid
|
||||
invoice_id = params[:invoice_id]
|
||||
invoice = Invoice.find(invoice_id)
|
||||
|
||||
account_activity = AccountActivity.find_by(invoice_id: invoice_id)
|
||||
account_activity_dup = account_activity.dup
|
||||
account_activity_dup.sum = -account_activity.sum
|
||||
|
||||
if account_activity_dup.save and invoice.update(cancelled_at: Time.zone.today)
|
||||
flash[:notice] = t(:payment_was_cancelled)
|
||||
redirect_to admin_invoices_path
|
||||
else
|
||||
flash[:alert] = t(:failed_to_payment_cancel)
|
||||
redirect_to admin_invoices_path
|
||||
end
|
||||
end
|
||||
|
||||
def index
|
||||
@q = Invoice.includes(:account_activity).search(params[:q])
|
||||
@q.sorts = 'number desc' if @q.sorts.empty?
|
||||
|
|
|
@ -6,6 +6,10 @@
|
|||
%h1.text-right.text-center-xs
|
||||
- if @invoice.unpaid?
|
||||
= link_to(t(:payment_received), new_admin_bank_statement_path(invoice_id: @invoice.id), class: 'btn btn-default')
|
||||
|
||||
- if @invoice.paid? and !@invoice.cancelled?
|
||||
= link_to(t(:cancel_payment), cancel_paid_admin_invoices_path(invoice_id: @invoice.id), method: 'post', data: { confirm: t(:are_you_sure) }, class: 'btn btn-warning')
|
||||
|
||||
= link_to(t('.download_btn'), download_admin_invoice_path(@invoice), class: 'btn btn-default')
|
||||
= link_to(t('.deliver_btn'), new_admin_invoice_delivery_path(@invoice), class: 'btn btn-default')
|
||||
- if @invoice.cancellable?
|
||||
|
|
|
@ -293,6 +293,9 @@ en:
|
|||
record_deleted: 'Record deleted'
|
||||
failed_to_delete_record: 'Failed to delete record'
|
||||
|
||||
payment_was_cancelled: 'Payment was cancelled'
|
||||
failed_to_payment_cancel: 'Failed to payment cancel'
|
||||
|
||||
authentication_error: 'Authentication error'
|
||||
|
||||
sign_in_cancelled: "Sign in cancelled"
|
||||
|
@ -601,6 +604,7 @@ en:
|
|||
no_transfers_found: 'No transfers found'
|
||||
parameter_value_range_error: 'Parameter value range error: %{key}'
|
||||
payment_received: 'Payment received'
|
||||
cancel_payment: 'Cancel Payment'
|
||||
api_user_not_found: 'API user not found'
|
||||
notes: Notes
|
||||
active_price_for_this_operation_is: 'Active price for this operation is %{price}'
|
||||
|
|
|
@ -231,6 +231,10 @@ Rails.application.routes.draw do
|
|||
end
|
||||
|
||||
resources :invoices, except: %i[edit update destroy] do
|
||||
collection do
|
||||
# get ':id/cancel_paid', to: 'invoices#cancel_paid', as: 'get_cancel_paid'
|
||||
post ':id/cancel_paid', to: 'invoices#cancel_paid', as: 'cancel_paid'
|
||||
end
|
||||
resource :delivery, controller: 'invoices/delivery', only: %i[new create]
|
||||
|
||||
member do
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue