Binding interface for bank statements

This commit is contained in:
Martin Lensment 2015-04-15 11:32:51 +03:00
parent 2dfa65645b
commit 851e5368eb
15 changed files with 113 additions and 26 deletions

View file

@ -1,7 +1,7 @@
class Admin::BankStatementsController < AdminController
load_and_authorize_resource
before_action :set_bank_statement, only: [:show, :download_import_file]
before_action :set_bank_statement, only: [:show, :download_import_file, :bind_invoices]
def index
@q = BankStatement.search(params[:q])
@ -10,7 +10,8 @@ class Admin::BankStatementsController < AdminController
end
def show
@q = @bank_statement.bank_transactions.search(params[:q])
@q = @bank_statement.bank_transactions.includes(:account_activity).search(params[:q])
@q.sorts = 'account_activity_id desc' if @q.sorts.empty?
@bank_transactions = @q.result.page(params[:page])
end
@ -30,6 +31,16 @@ class Admin::BankStatementsController < AdminController
end
end
def bind_invoices
@bank_statement.bind_invoices
flash[:notice] = t('invoices_were_fully_binded') if @bank_statement.fully_binded?
flash[:warning] = t('invoices_were_partially_binded') if @bank_statement.partially_binded?
flash[:alert] = t('no_invoices_were_binded') if @bank_statement.not_binded?
redirect_to [:admin, @bank_statement]
end
def download_import_file
filename = @bank_statement.import_file_path.split('/').last
send_data File.open(@bank_statement.import_file_path, 'r').read, filename: filename