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

This commit is contained in:
Priit Tark 2015-07-15 12:53:09 +03:00
commit 8a12abf88a
9 changed files with 103 additions and 5 deletions

View file

@ -16,7 +16,18 @@ class Admin::BankStatementsController < AdminController
end end
def new def new
@bank_statement = BankStatement.new @bank_statement = BankStatement.new(
bank_code: Setting.registry_bank_code,
iban: Setting.registry_iban
)
@invoice = Invoice.find_by(id: params[:invoice_id])
@bank_transaction = @bank_statement.bank_transactions.build(
description: @invoice.to_s,
sum: @invoice.sum,
reference_no: @invoice.reference_no,
paid_at: Time.zone.now.to_date,
currency: 'EUR'
) if @invoice
end end
def create def create
@ -69,6 +80,8 @@ class Admin::BankStatementsController < AdminController
end end
def bank_statement_params def bank_statement_params
params.require(:bank_statement).permit(:th6_file, :bank_code, :iban) params.require(:bank_statement).permit(:th6_file, :bank_code, :iban, bank_transactions_attributes: [
:description, :sum, :currency, :reference_no, :paid_at
])
end end
end end

View file

@ -2,6 +2,8 @@ class BankStatement < ActiveRecord::Base
include Versions include Versions
has_many :bank_transactions has_many :bank_transactions
accepts_nested_attributes_for :bank_transactions
attr_accessor :th6_file attr_accessor :th6_file
validates :bank_code, :iban, presence: true validates :bank_code, :iban, presence: true

View file

@ -13,6 +13,35 @@
= f.label :iban = f.label :iban
.col-md-8 .col-md-8
= f.text_field(:iban, class: 'form-control') = f.text_field(:iban, class: 'form-control')
- if @invoice
%hr
%h4= t('bank_transaction')
%hr
= f.fields_for :bank_transactions, [@bank_transaction] do |x|
.row
.col-md-8
.form-group
= x.label :description, class: 'col-md-4 control-label required'
.col-md-8
= x.text_field(:description, class: 'form-control', required: true)
.form-group
= x.label :sum, class: 'col-md-4 control-label required'
.col-md-8
= x.text_field(:sum, class: 'form-control', required: true)
.form-group
= x.label :currency, class: 'col-md-4 control-label required'
.col-md-8
= x.text_field(:currency, class: 'form-control', required: true, readonly: true)
.form-group
= x.label :reference_no, class: 'col-md-4 control-label required'
.col-md-8
= x.text_field(:reference_no, class: 'form-control', required: true)
.form-group
= x.label :paid_at, class: 'col-md-4 control-label required'
.col-md-8
= x.text_field(:paid_at, class: 'form-control datepicker', required: true)
%hr %hr
.row .row
.col-md-8.text-right .col-md-8.text-right

View file

@ -1,4 +1,5 @@
- content_for :actions do - content_for :actions do
- if @bank_statement.persisted?
= link_to(t(:back), admin_bank_statement_path(@bank_statement), class: 'btn btn-default') = link_to(t(:back), admin_bank_statement_path(@bank_statement), class: 'btn btn-default')
= render 'shared/title', name: t(:create_bank_transaction) = render 'shared/title', name: t(:create_bank_transaction)

View file

@ -1,9 +1,11 @@
.row .row
.col-sm-6 .col-sm-4
%h1.text-center-xs %h1.text-center-xs
= @invoice = @invoice
.col-sm-6 .col-sm-8
%h1.text-right.text-center-xs %h1.text-right.text-center-xs
- unless @invoice.binded?
= link_to(t(:payment_received), new_admin_bank_statement_path(invoice_id: @invoice.id), class: 'btn btn-default')
= link_to(t(:download), admin_invoice_download_pdf_path(@invoice), class: 'btn btn-default') = link_to(t(:download), admin_invoice_download_pdf_path(@invoice), class: 'btn btn-default')
= link_to(t(:forward), admin_invoice_forward_path(@invoice), class: 'btn btn-default') = link_to(t(:forward), admin_invoice_forward_path(@invoice), class: 'btn btn-default')
- if !@invoice.cancelled? && !@invoice.binded? - if !@invoice.cancelled? && !@invoice.binded?

View file

@ -71,6 +71,7 @@
= render 'setting_row', var: :registry_vat_no = render 'setting_row', var: :registry_vat_no
= render 'setting_row', var: :registry_vat_prc = render 'setting_row', var: :registry_vat_prc
= render 'setting_row', var: :registry_bank = render 'setting_row', var: :registry_bank
= render 'setting_row', var: :registry_bank_code
= render 'setting_row', var: :registry_iban = render 'setting_row', var: :registry_iban
= render 'setting_row', var: :registry_swift = render 'setting_row', var: :registry_swift

View file

@ -50,6 +50,7 @@ if con.present? && con.table_exists?('settings')
Setting.save_default(:registry_vat_prc, 0.2) Setting.save_default(:registry_vat_prc, 0.2)
Setting.save_default(:registry_iban, 'EE557700771000598731') Setting.save_default(:registry_iban, 'EE557700771000598731')
Setting.save_default(:registry_bank, 'LHV Pank') Setting.save_default(:registry_bank, 'LHV Pank')
Setting.save_default(:registry_bank_code, '689')
Setting.save_default(:registry_swift, 'LHVBEE22') Setting.save_default(:registry_swift, 'LHVBEE22')
Setting.save_default(:registry_invoice_contact, 'Martti Õigus') Setting.save_default(:registry_invoice_contact, 'Martti Õigus')
end end

View file

@ -869,4 +869,5 @@ en:
reserved_pw: 'Reserved pw' reserved_pw: 'Reserved pw'
no_transfers_found: 'No transfers found' no_transfers_found: 'No transfers found'
parameter_value_range_error: 'Parameter value range error: %{key}' parameter_value_range_error: 'Parameter value range error: %{key}'
payment_received: 'Payment received'
domain_registrant_updated: 'Domeeni %{name} registreerija vahetus teostatud / Registrant change of %{name} has been finished.' domain_registrant_updated: 'Domeeni %{name} registreerija vahetus teostatud / Registrant change of %{name} has been finished.'

View file

@ -59,4 +59,52 @@ feature 'Invoice', type: :feature do
response_headers['Content-Type'].should == 'application/pdf' response_headers['Content-Type'].should == 'application/pdf'
response_headers['Content-Disposition'].should == "attachment; filename=\"#{@invoice.pdf_name}\"" response_headers['Content-Disposition'].should == "attachment; filename=\"#{@invoice.pdf_name}\""
end end
it 'should create bank statement and transaction for invoice' do
r = Fabricate(:registrar, reference_no: 'RF7086666663')
invoice = r.issue_prepayment_invoice(200, 'add some money')
visit '/admin/invoices'
click_link invoice.to_s
page.should have_content('Unpaid')
click_link 'Payment received'
paid_at = Time.zone.now
find_field('Bank code').value.should == '689'
find_field('Iban').value.should == 'EE557700771000598731'
find_field('Description').value.should == invoice.to_s
find_field('Sum').value.should == invoice.sum.to_s
find_field('Currency').value.should == 'EUR'
find_field('Reference no').value.should == invoice.reference_no
find_field('Paid at').value.should == paid_at.to_date.to_s
click_button 'Save'
page.should have_content('Record created')
page.should have_content('689')
page.should have_content('EE557700771000598731')
page.should have_content('Not binded', count: 2)
page.should have_content(invoice.sum.to_s)
page.should have_content('EUR')
click_link 'Bind invoices'
page.should have_content('Invoices were fully binded')
page.should have_content('Fully binded')
page.should have_content('Binded')
click_link I18n.l(paid_at, format: :date_long)
page.should have_content('Binded')
page.should have_content(invoice.to_s)
page.should have_content(invoice.sum.to_s)
page.should have_content(invoice.reference_no)
page.should have_content(I18n.l(paid_at, format: :date_long))
click_link(invoice.to_s)
page.should_not have_content('Unpaid')
page.should_not have_content('Payment received')
end
end end