Merge branch 'master' of github.com:domify/registry

This commit is contained in:
Priit Tark 2015-06-26 18:45:10 +03:00
commit 5b2725144f
22 changed files with 323 additions and 107 deletions

View file

@ -22,6 +22,22 @@ class Admin::BankStatementsController < AdminController
def create
@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
flash[:notice] = I18n.t('record_created')
redirect_to [:admin, @bank_statement]
@ -53,6 +69,6 @@ class Admin::BankStatementsController < AdminController
end
def bank_statement_params
params.require(:bank_statement).permit(:th6_file)
params.require(:bank_statement).permit(:th6_file, :bank_code, :iban)
end
end

View file

@ -1,6 +1,25 @@
class Admin::BankTransactionsController < AdminController
load_and_authorize_resource
def new
@bank_statement = BankStatement.find(params[:bank_statement_id])
@bank_transaction = BankTransaction.new(currency: 'EUR')
end
def create
@bank_transaction = BankTransaction.new(
bank_transaction_params.merge(bank_statement_id: params[:bank_statement_id])
)
if @bank_transaction.save
flash[:notice] = I18n.t('record_created')
redirect_to [:admin, @bank_transaction]
else
flash.now[:alert] = I18n.t('failed_to_create_record')
render 'new'
end
end
def update
if @bank_transaction.update(bank_transaction_params)
flash[:notice] = I18n.t('record_updated')
@ -24,6 +43,10 @@ class Admin::BankTransactionsController < AdminController
private
def bank_transaction_params
params.require(:bank_transaction).permit(:description, :sum, :reference_no)
params.require(:bank_transaction).permit(
:description, :sum, :reference_no, :document_no,
:bank_reference, :iban, :buyer_bank_code, :buyer_iban,
:buyer_name, :currency, :paid_at
)
end
end

View file

@ -1,6 +1,24 @@
class Admin::InvoicesController < AdminController
load_and_authorize_resource
def new
@deposit = Deposit.new
end
def create
r = Registrar.find_by(id: deposit_params[:registrar_id])
@deposit = Deposit.new(deposit_params.merge(registrar: r))
@invoice = @deposit.issue_prepayment_invoice
if @invoice.persisted?
flash[:notice] = t(:record_created)
redirect_to [:admin, @invoice]
else
flash[:alert] = t(:failed_to_create_record)
render 'new'
end
end
def index
@q = Invoice.includes(:account_activity).search(params[:q])
@q.sorts = 'id desc' if @q.sorts.empty?
@ -20,4 +38,10 @@ class Admin::InvoicesController < AdminController
render :show
end
end
private
def deposit_params
params.require(:deposit).permit(:amount, :description, :registrar_id)
end
end

View file

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

View file

@ -4,7 +4,7 @@ class Deposit
extend ActiveModel::Naming
include DisableHtml5Validation
attr_accessor :amount, :description, :registrar
attr_accessor :amount, :description, :registrar, :registrar_id
validates :amount, :registrar, presence: true

View file

@ -15,7 +15,7 @@ class Invoice < ActiveRecord::Base
validates :invoice_type, :due_date, :currency, :seller_name,
:seller_iban, :buyer_name, :invoice_items, :vat_prc, presence: true
before_save :set_invoice_number
before_create :set_invoice_number
def set_invoice_number
last_no = Invoice.order(number: :desc).where('number IS NOT NULL').limit(1).pluck(:number).first

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
= 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)
.row

View file

@ -1,20 +1,6 @@
- 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)
= link_to(t(:back), admin_bank_statements_path, class: 'btn btn-default')
= form_for([:admin, @bank_statement], multipart: true) do |f|
= render 'shared/full_errors', object: @bank_statement
= render 'shared/title', name: t(:create_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')
= render 'form'

View file

@ -1,5 +1,5 @@
- content_for :actions do
= link_to(t(:bind_invoices), bind_invoices_admin_bank_statement_path,
= link_to(t(:bind_invoices), bind_invoices_admin_bank_statement_path,
class: 'btn btn-primary', method: :post)
= link_to(t(:back_to_bank_statements), admin_bank_statements_path, class: 'btn btn-default')
= render 'shared/title', name: t(:bank_statement)
@ -23,17 +23,24 @@
- sc = 'text-danger' if @bank_statement.not_binded?
%dd{class: sc}= t(@bank_statement.status)
%dt= t(:queried_at)
%dd= l(@bank_statement.queried_at)
- if @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)
- if @bank_statement.import_file_path
%dt= t(:import_file)
%dd= link_to(t(:download), download_import_file_admin_bank_statement_path(@bank_statement))
%h2.text-center-xs= t(:bank_transactions)
.row
.col-sm-6
%h3.text-center-xs
= t(:bank_transactions)
.col-sm-6.text-right
%h3.text-right.text-center-xs
= link_to(t(:add), new_admin_bank_statement_bank_transaction_path(@bank_statement), class: 'btn btn-primary')
%hr
.row
.col-md-12

View file

@ -0,0 +1,71 @@
= form_for([:admin, @bank_statement, @bank_transaction], html: { class: 'form-horizontal' }) do |f|
= render 'shared/full_errors', object: @bank_transaction
.row
.col-md-8
- if @bank_transaction.persisted?
.form-group
= f.label :status, class: 'col-md-4 control-label'
- c = @bank_transaction.binded? ? 'text-success' : 'text-danger'
.col-md-8.form-control-static{class: c}
= @bank_transaction.binded? ? t(:binded) : t(:not_binded)
.form-group
= f.label :description, class: 'col-md-4 control-label required'
.col-md-8
= f.text_field(:description, class: 'form-control', required: true)
.form-group
= f.label :sum, class: 'col-md-4 control-label required'
.col-md-8
= f.text_field(:sum, class: 'form-control', required: true)
.form-group
= f.label :reference_no, class: 'col-md-4 control-label required'
.col-md-8
= f.text_field(:reference_no, class: 'form-control', required: true)
.form-group
= f.label :document_no, class: 'col-md-4 control-label'
.col-md-8
= f.text_field(:document_no, class: 'form-control')
.form-group
= f.label :bank_reference, class: 'col-md-4 control-label'
.col-md-8
= f.text_field(:bank_reference, class: 'form-control')
.form-group
= f.label :iban, class: 'col-md-4 control-label'
.col-md-8
= f.text_field(:iban, class: 'form-control')
.form-group
= f.label :buyer_bank_code, class: 'col-md-4 control-label'
.col-md-8
= f.text_field(:buyer_bank_code, class: 'form-control')
.form-group
= f.label :buyer_iban, class: 'col-md-4 control-label'
.col-md-8
= f.text_field(:buyer_iban, class: 'form-control')
.form-group
= f.label :buyer_name, class: 'col-md-4 control-label'
.col-md-8
= f.text_field(:buyer_name, class: 'form-control')
.form-group
= f.label :currency, class: 'col-md-4 control-label'
.col-md-8
= f.text_field(:currency, class: 'form-control', readonly: true)
.form-group
= f.label :paid_at, class: 'col-md-4 control-label required'
.col-md-8
= f.text_field(:paid_at, class: 'form-control datepicker', required: true)
%hr
.row
.col-md-8.text-right
= button_tag(t(:save), class: 'btn btn-warning')

View file

@ -2,73 +2,4 @@
= 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|
= 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')
= render 'form'

View file

@ -0,0 +1,6 @@
- content_for :actions do
= link_to(t(:back), admin_bank_statement_path(@bank_statement), class: 'btn btn-default')
= render 'shared/title', name: t(:create_bank_transaction)
= render 'form'

View file

@ -1,7 +1,7 @@
.row
.col-sm-12
%h2.text-center-xs= t(:invoices)
%hr
- content_for :actions do
= link_to(t(:add), new_admin_invoice_path, class: 'btn btn-primary')
= render 'shared/title', name: t(:invoices)
.row
.col-md-12
.table-responsive

View file

@ -0,0 +1,33 @@
- content_for :actions do
= link_to(t(:back), admin_invoices_path, class: 'btn btn-default')
= render 'shared/title', name: t(:create_new_invoice)
= form_for([:admin, @deposit], url: admin_invoices_path, method: :post, html: { class: 'form-horizontal' }) do |f|
= render 'shared/full_errors', object: @deposit
.row
.col-md-8
.form-group
.col-md-4.control-label
= f.label :registrar_id, class: 'required'
.col-md-8
= f.select :registrar_id, Registrar.all.map { |r| [r.name, r.id] }, { include_blank: true }, class: 'form-control selectize', required: true
.form-group
.col-md-4.control-label
= f.label :amount, class: 'required'
.col-md-8
.input-group
= f.text_field :amount, class: 'form-control', required: true
.input-group-addon
EUR
.form-group
.col-md-4.control-label
= f.label :description
.col-md-8
= f.text_area :description, class: 'form-control'
%hr
.row
.col-md-8.text-right
= button_tag(t(:save), class: 'btn btn-warning')

View file

@ -5,7 +5,7 @@
.col-sm-6
%h1.text-right.text-center-xs
- if !@invoice.cancelled? && !@invoice.binded?
= link_to(t(:cancel), cancel_admin_invoice_path(@invoice), method: :patch, class: 'btn btn-default')
= link_to(t(:cancel), cancel_admin_invoice_path(@invoice), method: :patch, class: 'btn btn-warning')
= link_to(t(:back), admin_invoices_path, class: 'btn btn-default')
%hr
= render 'shared/full_errors', object: @invoice

View file

@ -831,3 +831,6 @@ en:
domain_expiring: 'Domain expiring'
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>.'
create_bank_statement: 'Create bank statement'
create_bank_transaction: 'Create bank transaction'
create_new_invoice: 'Create new invoice'

View file

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

View file

@ -0,0 +1,52 @@
require 'rails_helper'
feature 'BankStatement', type: :feature do
before :all do
@user = Fabricate(:admin_user)
end
before do
sign_in @user
end
it 'should add a bank statement and transactions manually' do
visit admin_bank_statements_url
click_link 'Add'
fill_in 'Bank code', with: '767'
fill_in 'Iban', with: 'EE557700771000598731'
click_button 'Save'
page.should have_content('Record created')
page.should have_content('Bank statement ')
page.should have_content('767')
page.should have_content('EE557700771000598731')
page.should have_content('Not binded')
click_link 'Add'
fill_in 'Description', with: 'Payment 12345'
fill_in 'Sum', with: '120'
fill_in 'Reference no', with: 'RF4663930489'
fill_in 'Document no', with: '123'
fill_in 'Bank reference', with: '767'
fill_in 'Iban', with: 'EE557700771000598731'
fill_in 'Buyer bank code', with: '767'
fill_in 'Buyer iban', with: 'EE557700771000598000'
fill_in 'Buyer name', with: 'Test buyer'
fill_in 'Paid at', with: '2015-01-01'
click_button 'Save'
page.should have_content('Record created')
page.should have_content('Bank transaction')
page.should have_content('RF4663930489')
page.should have_content('EE557700771000598000')
page.should have_content('Not binded')
page.should have_content('Bind manually')
click_link 'Back to bank statement'
page.should have_content('120.0')
page.should have_content('Test buyer')
end
end

View file

@ -6,15 +6,17 @@ feature 'Invoice', type: :feature do
Fabricate(:invoice)
end
it 'should show index of invoices' do
before do
sign_in @user
end
it 'should show index of invoices' do
visit admin_invoices_url
i = Invoice.first
page.should have_link("Invoice no. #{i.id}")
end
it 'should show invoice' do
sign_in @user
visit admin_invoices_url
i = Invoice.first
@ -23,4 +25,21 @@ feature 'Invoice', type: :feature do
page.should have_content("Details")
page.should have_content("Paldiski mnt. 123")
end
it 'should issue an invoice' do
Fabricate(:eis)
r = Fabricate(:registrar)
visit admin_invoices_url
click_link('Add')
page.should have_content('Create new invoice')
select r.name, from: 'Registrar'
fill_in 'Amount', with: '100'
fill_in 'Description', with: 'test issue'
click_button 'Save'
page.should have_content('Record created')
page.should have_content('Invoice no.')
page.should have_content('Prepayment')
page.should have_content('120.0')
page.should have_content(r.name)
end
end

View file

@ -12,8 +12,7 @@ describe BankStatement do
@bank_statement.valid?
@bank_statement.errors.full_messages.should match_array([
"Bank code is missing",
"Iban is missing",
"Queried at is missing"
"Iban is missing"
])
end