Add form for bank statements #2733

This commit is contained in:
Martin Lensment 2015-06-26 14:53:49 +03:00
parent a6cc53a0bf
commit de082bb637
9 changed files with 73 additions and 24 deletions

View file

@ -22,6 +22,22 @@ class Admin::BankStatementsController < AdminController
def create def create
@bank_statement = BankStatement.new(bank_statement_params) @bank_statement = BankStatement.new(bank_statement_params)
if @bank_statement.save
flash[:notice] = I18n.t('record_created')
redirect_to [:admin, @bank_statement]
else
flash.now[:alert] = I18n.t('failed_to_create_record')
render 'new'
end
end
def import
@bank_statement = BankStatement.new
end
def create_from_import
@bank_statement = BankStatement.new(bank_statement_params)
if @bank_statement.import if @bank_statement.import
flash[:notice] = I18n.t('record_created') flash[:notice] = I18n.t('record_created')
redirect_to [:admin, @bank_statement] redirect_to [:admin, @bank_statement]
@ -53,6 +69,6 @@ class Admin::BankStatementsController < AdminController
end end
def bank_statement_params def bank_statement_params
params.require(:bank_statement).permit(:th6_file) params.require(:bank_statement).permit(:th6_file, :bank_code, :iban)
end end
end end

View file

@ -4,7 +4,7 @@ class BankStatement < ActiveRecord::Base
attr_accessor :th6_file attr_accessor :th6_file
validates :bank_code, :iban, :queried_at, presence: true validates :bank_code, :iban, presence: true
FULLY_BINDED = 'fully_binded' FULLY_BINDED = 'fully_binded'
PARTIALLY_BINDED = 'partially_binded' PARTIALLY_BINDED = 'partially_binded'

View file

@ -0,0 +1,19 @@
= form_for([:admin, @bank_statement], html: { class: 'form-horizontal' }) do |f|
= render 'shared/full_errors', object: @bank_statement
.row
.col-md-8
.form-group
.col-md-4.control-label
= f.label :bank_code
.col-md-8
= f.text_field(:bank_code, class: 'form-control')
.form-group
.col-md-4.control-label
= f.label :iban
.col-md-8
= f.text_field(:iban, class: 'form-control')
%hr
.row
.col-md-8.text-right
= button_tag(t(:save), class: 'btn btn-warning')

View file

@ -0,0 +1,20 @@
- content_for :actions do
= link_to(t(:back_to_bank_statements), admin_bank_statements_path, class: 'btn btn-default')
= render 'shared/title', name: t(:import_th6_bank_statement)
= form_for(@bank_statement, url: { action: :create_from_import }, multipart: true) do |f|
= render 'shared/full_errors', object: @bank_statement
.row
.col-md-8
.form-group
.col-md-4.control-label
= f.label :th6_file
.col-md-8
= f.file_field :th6_file
.col-md-4
%p= t(:bank_statement_desc).html_safe
%hr
.row
.col-md-8.text-right
= button_tag(t(:save), class: 'btn btn-primary')

View file

@ -1,5 +1,6 @@
- content_for :actions do - content_for :actions do
= link_to(t(:import), new_admin_bank_statement_path, class: 'btn btn-primary') = link_to(t(:add), new_admin_bank_statement_path, class: 'btn btn-primary')
= link_to(t(:import), import_admin_bank_statements_path, class: 'btn btn-primary')
= render 'shared/title', name: t(:bank_statements) = render 'shared/title', name: t(:bank_statements)
.row .row

View file

@ -1,20 +1,6 @@
- content_for :actions do - content_for :actions do
= link_to(t(:back_to_bank_statements), admin_bank_statements_path, class: 'btn btn-default') = link_to(t(:back), admin_bank_statements_path, class: 'btn btn-default')
= render 'shared/title', name: t(:import_th6_bank_statement)
= form_for([:admin, @bank_statement], multipart: true) do |f| = render 'shared/title', name: t(:create_bank_statement)
= render 'shared/full_errors', object: @bank_statement
.row = render 'form'
.col-md-8
.form-group
.col-md-4.control-label
= f.label :th6_file
.col-md-8
= f.file_field :th6_file
.col-md-4
%p= t(:bank_statement_desc).html_safe
%hr
.row
.col-md-8.text-right
= button_tag(t(:save), class: 'btn btn-primary')

View file

@ -23,10 +23,11 @@
- sc = 'text-danger' if @bank_statement.not_binded? - sc = 'text-danger' if @bank_statement.not_binded?
%dd{class: sc}= t(@bank_statement.status) %dd{class: sc}= t(@bank_statement.status)
%dt= t(:queried_at) - if @bank_statement.queried_at
%dd= l(@bank_statement.queried_at) %dt= t(:queried_at)
%dd= l(@bank_statement.queried_at)
%dt= t(:imported_at) %dt= t(:created_at)
%dd= l(@bank_statement.created_at) %dd= l(@bank_statement.created_at)
- if @bank_statement.import_file_path - if @bank_statement.import_file_path

View file

@ -831,3 +831,4 @@ en:
domain_expiring: 'Domain expiring' domain_expiring: 'Domain expiring'
domain_validation_rules: 'Domain validation rules' domain_validation_rules: 'Domain validation rules'
bank_statement_desc: 'Import file row will match only when matching following attributes: <b><br>ref number<br>payment amount<br>invoice number (the very first number in comment field)</b>.' bank_statement_desc: 'Import file row will match only when matching following attributes: <b><br>ref number<br>payment amount<br>invoice number (the very first number in comment field)</b>.'
create_bank_statement: 'Create bank statement'

View file

@ -161,6 +161,11 @@ Rails.application.routes.draw do
resources :pricelists resources :pricelists
resources :bank_statements do resources :bank_statements do
collection do
get 'import'
post 'create_from_import'
end
post 'bind_invoices', on: :member post 'bind_invoices', on: :member
get 'download_import_file', on: :member get 'download_import_file', on: :member
end end