Interface for manual binding

This commit is contained in:
Martin Lensment 2015-04-16 18:04:52 +03:00
parent adf321bafa
commit ccb44fa3b9
8 changed files with 189 additions and 23 deletions

View file

@ -1,5 +1,29 @@
class Admin::BankTransactionsController < AdminController
load_and_authorize_resource
def show; end
def update
if @bank_transaction.update(bank_transaction_params)
flash[:notice] = I18n.t('record_updated')
redirect_to [:admin, @bank_transaction]
else
flash.now[:alert] = I18n.t('failed_to_update_record')
render 'edit'
end
end
def bind
if @bank_transaction.bind_invoice(params[:invoice_id])
flash[:notice] = I18n.t('record_created')
redirect_to [:admin, @bank_transaction]
else
flash.now[:alert] = I18n.t('failed_to_create_record')
render 'show'
end
end
private
def bank_transaction_params
params.require(:bank_transaction).permit(:description, :sum, :reference_no)
end
end

View file

@ -16,7 +16,7 @@ class BankTransaction < ActiveRecord::Base
# For successful binding, reference number, invoice id and sum must match with the invoice
# rubocop: disable Metrics/PerceivedComplexity
# rubocop: disable Metrics/CyclomaticComplexity
def bind_invoice
def autobind_invoice
return if binded?
registrar = Registrar.find_by(reference_no: reference_no)
return unless registrar
@ -33,6 +33,38 @@ class BankTransaction < ActiveRecord::Base
return if invoice.binded?
return if invoice.sum != sum
create_activity(registrar, invoice)
end
# rubocop: enable Metrics/PerceivedComplexity
# rubocop: enable Metrics/CyclomaticComplexity
def bind_invoice(invoice_id)
if binded?
errors.add(:base, I18n.t('transaction_is_already_binded'))
return
end
invoice = Invoice.find_by(id: invoice_id)
unless invoice
errors.add(:base, I18n.t('invoice_was_not_found'))
return
end
if invoice.binded?
errors.add(:base, I18n.t('invoice_is_already_binded'))
return
end
if invoice.sum != sum
errors.add(:base, I18n.t('invoice_and_transaction_sums_do_not_match'))
return
end
create_activity(invoice.buyer, invoice)
end
def create_activity(registrar, invoice)
create_account_activity(
account: registrar.cash_account,
invoice: invoice,
@ -41,6 +73,4 @@ class BankTransaction < ActiveRecord::Base
description: description
)
end
# rubocop: enable Metrics/PerceivedComplexity
# rubocop: enable Metrics/CyclomaticComplexity
end

View file

@ -1,9 +1,7 @@
.row
.col-sm-6
%h2.text-center-xs= t('bank_statements')
.col-sm-6
%h2.text-right.text-center-xs
= link_to(t('import'), new_admin_bank_statement_path, class: 'btn btn-primary')
- content_for :actions do
= link_to(t('import'), new_admin_bank_statement_path, class: 'btn btn-default')
= render 'admin/shared/title', name: "#{t(:bank_statements)}"
%hr
.row
.col-md-12

View file

@ -0,0 +1,74 @@
- content_for :actions do
= link_to(t('back'), :back, class: 'btn btn-default')
= render 'admin/shared/title', name: "#{t('bank_transaction')}"
= form_for([:admin, @bank_transaction], html: { class: 'form-horizontal' }) do |f|
= render 'shared/full_errors', object: @bank_transaction
.row
.col-md-8
.form-group
= f.label :status, class: 'col-md-2 control-label'
- c = @bank_transaction.binded? ? 'text-success' : 'text-danger'
.col-md-10.form-control-static{class: c}
= @bank_transaction.binded? ? t('binded') : t('not_binded')
.form-group
= f.label :description, class: 'col-md-2 control-label'
.col-md-10
= f.text_field(:description, class: 'form-control')
.form-group
= f.label :sum, class: 'col-md-2 control-label'
.col-md-10
= f.text_field(:sum, class: 'form-control')
.form-group
= f.label :reference_no, class: 'col-md-2 control-label'
.col-md-10
= f.text_field(:reference_no, class: 'form-control')
.form-group
= f.label :document_no, class: 'col-md-2 control-label'
.col-md-10
= f.text_field(:document_no, class: 'form-control', disabled: :disabled)
.form-group
= f.label :bank_reference, class: 'col-md-2 control-label'
.col-md-10
= f.text_field(:bank_reference, class: 'form-control', disabled: :disabled)
.form-group
= f.label :iban, class: 'col-md-2 control-label'
.col-md-10
= f.text_field(:iban, class: 'form-control', disabled: :disabled)
.form-group
= f.label :buyer_bank_code, class: 'col-md-2 control-label'
.col-md-10
= f.text_field(:buyer_bank_code, class: 'form-control', disabled: :disabled)
.form-group
= f.label :buyer_iban, class: 'col-md-2 control-label'
.col-md-10
= f.text_field(:buyer_iban, class: 'form-control', disabled: :disabled)
.form-group
= f.label :buyer_name, class: 'col-md-2 control-label'
.col-md-10
= f.text_field(:buyer_name, class: 'form-control', disabled: :disabled)
.form-group
= f.label :currency, class: 'col-md-2 control-label'
.col-md-10
= f.text_field(:currency, class: 'form-control', disabled: :disabled)
.form-group
= f.label :paid_at, class: 'col-md-2 control-label'
.col-md-10
= f.text_field(:paid_at, class: 'form-control', disabled: :disabled)
%hr
.row
.col-md-8.text-right
= button_tag(t('save'), class: 'btn btn-primary')

View file

@ -0,0 +1,27 @@
- content_for :actions do
= link_to(t('back_to_bank_transaction'), [:admin, @bank_transaction], class: 'btn btn-default')
= render 'admin/shared/title', name: "#{t('manual_binding')}"
= form_for([:admin, @bank_transaction], url: {action: :bind}, html: { class: 'form-horizontal' }) do |f|
= render 'shared/full_errors', object: @bank_transaction
.row
.col-md-8
.form-group
= f.label :status, class: 'col-md-2 control-label'
- c = @bank_transaction.binded? ? 'text-success' : 'text-danger'
.col-md-10.form-control-static{class: c}
= @bank_transaction.binded? ? t('binded') : t('not_binded')
.form-group
= f.label :sum, class: 'col-md-2 control-label'
.col-md-10.form-control-static
= "#{@bank_transaction.sum} #{@bank_transaction.currency}"
.form-group
= label_tag :invoice_id, t('invoice'), class: 'col-md-2 control-label'
.col-md-10
= text_field_tag(:invoice_id, params[:invoice_id], class: 'form-control')
%hr
.row
.col-md-8.text-right
= button_tag(t('save'), class: 'btn btn-primary')

View file

@ -1,11 +1,8 @@
.row
.col-sm-6
%h2.text-center-xs
= t('bank_transaction')
.col-sm-6
%h2.text-right.text-center-xs
= link_to(t('back_to_bank_statement'), admin_bank_statement_path(@bank_transaction.bank_statement), class: 'btn btn-primary')
%hr
- content_for :actions do
= link_to(t('edit'), edit_admin_bank_transaction_path(@bank_transaction), class: 'btn btn-primary')
= link_to(t('back_to_bank_statement'), admin_bank_statement_path(@bank_transaction.bank_statement), class: 'btn btn-default')
= render 'admin/shared/title', name: "#{t('bank_transaction')}"
= render 'shared/full_errors', object: @bank_transaction
%row
.col-md-12
.panel.panel-default
@ -20,10 +17,6 @@
- c = @bank_transaction.binded? ? 'text-success' : 'text-danger'
%dd{class: c}= @bank_transaction.binded? ? t('binded') : t('not_binded')
- if @bank_transaction.binded?
%dt= t('binded_invoice')
%dd= link_to(@bank_transaction.binded_invoice, admin_invoice_path(@bank_transaction.binded_invoice))
%dt= t('bank_reference')
%dd= @bank_transaction.bank_reference
@ -53,3 +46,16 @@
%dt= t('paid_at')
%dd= l(@bank_transaction.paid_at, format: :date_long)
- if @bank_transaction.binded?
%dt= t('binded_invoice')
%dd= link_to(@bank_transaction.binded_invoice, admin_invoice_path(@bank_transaction.binded_invoice))
- unless @bank_transaction.binded?
= form_for([:admin, @bank_transaction], url: {action: :bind}, html: { class: 'form-inline' }) do |f|
.form-group
%dl.dl-horizontal
%dt{style: 'padding-top: 5px'}= t('binded_invoice')
%dd
= text_field_tag(:invoice_id, params[:invoice_id], class: 'form-control')
= button_tag(t('bind_manually'), class: 'btn btn-primary')

View file

@ -713,3 +713,8 @@ en:
is a computer that saves and forwards via a general-access data communications network such data that is connected with the domain name and corresponding IP addresses. Your IT helpdesk or Internet service provider will have the necessary information about the domain name servers.
account_activity: 'Account activity'
receipt_date: 'Receipt date'
manual_binding: 'Manual binding'
transaction_is_already_binded: 'Transaction is already binded'
invoice_was_not_found: 'Invoice was not found'
invoice_is_already_binded: 'Invoice is already binded'
invoice_and_transaction_sums_do_not_match: 'Invoice and transaction sums do not match'

View file

@ -91,7 +91,9 @@ Rails.application.routes.draw do
get 'download_import_file', on: :member
end
resources :bank_transactions
resources :bank_transactions do
patch 'bind', on: :member
end
resources :invoices