From de082bb637520293c9db4f022b711b400fdf2536 Mon Sep 17 00:00:00 2001 From: Martin Lensment Date: Fri, 26 Jun 2015 14:53:49 +0300 Subject: [PATCH 1/8] Add form for bank statements #2733 --- .../admin/bank_statements_controller.rb | 18 ++++++++++++++++- app/models/bank_statement.rb | 2 +- app/views/admin/bank_statements/_form.haml | 19 ++++++++++++++++++ app/views/admin/bank_statements/import.haml | 20 +++++++++++++++++++ app/views/admin/bank_statements/index.haml | 3 ++- app/views/admin/bank_statements/new.haml | 20 +++---------------- app/views/admin/bank_statements/show.haml | 9 +++++---- config/locales/en.yml | 1 + config/routes.rb | 5 +++++ 9 files changed, 73 insertions(+), 24 deletions(-) create mode 100644 app/views/admin/bank_statements/_form.haml create mode 100644 app/views/admin/bank_statements/import.haml diff --git a/app/controllers/admin/bank_statements_controller.rb b/app/controllers/admin/bank_statements_controller.rb index b667d0fb6..1e69aa1af 100644 --- a/app/controllers/admin/bank_statements_controller.rb +++ b/app/controllers/admin/bank_statements_controller.rb @@ -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 diff --git a/app/models/bank_statement.rb b/app/models/bank_statement.rb index bb670d227..a5102ce78 100644 --- a/app/models/bank_statement.rb +++ b/app/models/bank_statement.rb @@ -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' diff --git a/app/views/admin/bank_statements/_form.haml b/app/views/admin/bank_statements/_form.haml new file mode 100644 index 000000000..158d69e89 --- /dev/null +++ b/app/views/admin/bank_statements/_form.haml @@ -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') diff --git a/app/views/admin/bank_statements/import.haml b/app/views/admin/bank_statements/import.haml new file mode 100644 index 000000000..e432abdf1 --- /dev/null +++ b/app/views/admin/bank_statements/import.haml @@ -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') diff --git a/app/views/admin/bank_statements/index.haml b/app/views/admin/bank_statements/index.haml index afb3a7be1..0810c15fe 100644 --- a/app/views/admin/bank_statements/index.haml +++ b/app/views/admin/bank_statements/index.haml @@ -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 diff --git a/app/views/admin/bank_statements/new.haml b/app/views/admin/bank_statements/new.haml index 452ffd264..4e5ff09d3 100644 --- a/app/views/admin/bank_statements/new.haml +++ b/app/views/admin/bank_statements/new.haml @@ -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' diff --git a/app/views/admin/bank_statements/show.haml b/app/views/admin/bank_statements/show.haml index 6eb808515..c0051d447 100644 --- a/app/views/admin/bank_statements/show.haml +++ b/app/views/admin/bank_statements/show.haml @@ -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,10 +23,11 @@ - 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 diff --git a/config/locales/en.yml b/config/locales/en.yml index 2275b13b1..d46aa048e 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -831,3 +831,4 @@ en: domain_expiring: 'Domain expiring' domain_validation_rules: 'Domain validation rules' bank_statement_desc: 'Import file row will match only when matching following attributes:
ref number
payment amount
invoice number (the very first number in comment field)
.' + create_bank_statement: 'Create bank statement' diff --git a/config/routes.rb b/config/routes.rb index 5986f213f..7b7025179 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -161,6 +161,11 @@ Rails.application.routes.draw do resources :pricelists resources :bank_statements do + collection do + get 'import' + post 'create_from_import' + end + post 'bind_invoices', on: :member get 'download_import_file', on: :member end From 55ecae3e288c4b80e6dc5145bc74bc7432b195e2 Mon Sep 17 00:00:00 2001 From: Martin Lensment Date: Fri, 26 Jun 2015 15:48:12 +0300 Subject: [PATCH 2/8] Add forms for adding bank transactions #2733 --- .../admin/bank_transactions_controller.rb | 25 ++++++- app/views/admin/bank_statements/show.haml | 8 ++- app/views/admin/bank_transactions/_form.haml | 71 +++++++++++++++++++ app/views/admin/bank_transactions/edit.haml | 71 +------------------ app/views/admin/bank_transactions/new.haml | 6 ++ config/locales/en.yml | 1 + config/routes.rb | 1 + 7 files changed, 111 insertions(+), 72 deletions(-) create mode 100644 app/views/admin/bank_transactions/_form.haml create mode 100644 app/views/admin/bank_transactions/new.haml diff --git a/app/controllers/admin/bank_transactions_controller.rb b/app/controllers/admin/bank_transactions_controller.rb index ca1da48a8..1aaf452a8 100644 --- a/app/controllers/admin/bank_transactions_controller.rb +++ b/app/controllers/admin/bank_transactions_controller.rb @@ -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 diff --git a/app/views/admin/bank_statements/show.haml b/app/views/admin/bank_statements/show.haml index c0051d447..db8d64004 100644 --- a/app/views/admin/bank_statements/show.haml +++ b/app/views/admin/bank_statements/show.haml @@ -34,7 +34,13 @@ %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 diff --git a/app/views/admin/bank_transactions/_form.haml b/app/views/admin/bank_transactions/_form.haml new file mode 100644 index 000000000..c3a3c011f --- /dev/null +++ b/app/views/admin/bank_transactions/_form.haml @@ -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' + .col-md-8 + = f.text_field(:description, class: 'form-control') + + .form-group + = f.label :sum, class: 'col-md-4 control-label' + .col-md-8 + = f.text_field(:sum, class: 'form-control') + + .form-group + = f.label :reference_no, class: 'col-md-4 control-label' + .col-md-8 + = f.text_field(:reference_no, class: 'form-control') + + .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' + .col-md-8 + = f.text_field(:paid_at, class: 'form-control datepicker') + + %hr + .row + .col-md-8.text-right + = button_tag(t(:save), class: 'btn btn-warning') diff --git a/app/views/admin/bank_transactions/edit.haml b/app/views/admin/bank_transactions/edit.haml index 5c38ea6e0..8bb5a2666 100644 --- a/app/views/admin/bank_transactions/edit.haml +++ b/app/views/admin/bank_transactions/edit.haml @@ -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' diff --git a/app/views/admin/bank_transactions/new.haml b/app/views/admin/bank_transactions/new.haml new file mode 100644 index 000000000..403eb415e --- /dev/null +++ b/app/views/admin/bank_transactions/new.haml @@ -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' diff --git a/config/locales/en.yml b/config/locales/en.yml index d46aa048e..04b370c61 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -832,3 +832,4 @@ en: domain_validation_rules: 'Domain validation rules' bank_statement_desc: 'Import file row will match only when matching following attributes:
ref number
payment amount
invoice number (the very first number in comment field)
.' create_bank_statement: 'Create bank statement' + create_bank_transaction: 'Create bank transaction' diff --git a/config/routes.rb b/config/routes.rb index 7b7025179..632e55e54 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -161,6 +161,7 @@ Rails.application.routes.draw do resources :pricelists resources :bank_statements do + resources :bank_transactions collection do get 'import' post 'create_from_import' From ca8d780c9c86816aa1958407d026f1a4ccf41718 Mon Sep 17 00:00:00 2001 From: Martin Lensment Date: Fri, 26 Jun 2015 15:50:42 +0300 Subject: [PATCH 3/8] Test fix #2733 --- spec/models/bank_statement_spec.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/spec/models/bank_statement_spec.rb b/spec/models/bank_statement_spec.rb index ed9a0218e..d5812fbeb 100644 --- a/spec/models/bank_statement_spec.rb +++ b/spec/models/bank_statement_spec.rb @@ -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 From cf7469358c53cfc6e03691ef5f30d12f5e4c33aa Mon Sep 17 00:00:00 2001 From: Priit Tark Date: Fri, 26 Jun 2015 15:56:01 +0300 Subject: [PATCH 4/8] Updaded newrelic and added license key to application-example #2711 --- CHANGELOG.md | 4 ++++ Gemfile | 2 +- Gemfile.lock | 4 ++-- config/application-example.yml | 1 + config/initializers/new_relic_app_name.rb | 4 ---- config/newrelic.yml | 7 ++----- 6 files changed, 10 insertions(+), 12 deletions(-) delete mode 100644 config/initializers/new_relic_app_name.rb diff --git a/CHANGELOG.md b/CHANGELOG.md index f700d1b1f..150782125 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +26.06.2015 + +* Added new relic license key ta application-example.yml, please update application.yml + 22.06.2015 * Update zonefile diff --git a/Gemfile b/Gemfile index 4e1c757c1..fc91ac71e 100644 --- a/Gemfile +++ b/Gemfile @@ -67,7 +67,7 @@ gem 'data_migrate', ref: '35d22b09ff37a4e9d61ab326ad5d8eb0edf1fc81' # monitors -gem 'newrelic_rpm', '~> 3.9.9.275' +gem 'newrelic_rpm', '~> 3.12.0.288' # country listing gem 'countries', '~> 0.10.0' diff --git a/Gemfile.lock b/Gemfile.lock index 259c87e03..322135254 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -295,7 +295,7 @@ GEM railties (>= 3.0) multi_json (1.11.1) multi_xml (0.5.5) - newrelic_rpm (3.9.9.275) + newrelic_rpm (3.12.0.288) nokogiri (1.6.6.2) mini_portile (~> 0.6.0) nori (2.6.0) @@ -563,7 +563,7 @@ DEPENDENCIES launchy (~> 2.4.3) mina (~> 0.3.1) money-rails (~> 1.4.1) - newrelic_rpm (~> 3.9.9.275) + newrelic_rpm (~> 3.12.0.288) nokogiri (~> 1.6.6.2) nprogress-rails (~> 0.1.6.7) paper_trail! diff --git a/config/application-example.yml b/config/application-example.yml index 24a551769..c01412138 100644 --- a/config/application-example.yml +++ b/config/application-example.yml @@ -9,6 +9,7 @@ time_zone: 'Tallinn' # more zones by rake time:zones:all # New Relic app name, keep only current mode, remove other names. # Example: 'Admin, EPP, REPP' will have name 'Admin, EPP, REPP - production' at New Relic. new_relic_app_name: 'Admin, EPP, REPP, Registrar, Registrant' +new_relic_license_key: '42d1c2ba4ed17a9cf6297c59d80e563a3dd3c4fa' # You can use `rake secret` to generate a secure secret key. # Your secret key is used for verifying the integrity of signed cookies. diff --git a/config/initializers/new_relic_app_name.rb b/config/initializers/new_relic_app_name.rb deleted file mode 100644 index 662fdf6b1..000000000 --- a/config/initializers/new_relic_app_name.rb +++ /dev/null @@ -1,4 +0,0 @@ -if !Rails.env.test? && ENV['new_relic_app_name'].present? - require 'newrelic' - NewRelic::Agent.config[:app_name] = "#{ENV['new_relic_app_name']} - #{Rails.env}" -end diff --git a/config/newrelic.yml b/config/newrelic.yml index 6dc617a9d..fb3867854 100644 --- a/config/newrelic.yml +++ b/config/newrelic.yml @@ -15,7 +15,7 @@ common: &default_settings # You must specify the license key associated with your New Relic # account. This key binds your Agent's data to your account in the # New Relic service. - license_key: '42d1c2ba4ed17a9cf6297c59d80e563a3dd3c4fa' + license_key: <%= ENV['new_relic_license_key'] %> # Agent Enabled (Ruby/Rails Only) # Use this setting to force the agent to run or not run. @@ -49,7 +49,7 @@ common: &default_settings # See https://newrelic.com/docs/site/renaming-applications for more details # on renaming your New Relic applications. # - app_name: Registry + app_name: <%= "#{ENV['new_relic_app_name']} - #{Rails.env}" %> # When "true", the agent collects performance data about your # application and reports this data to the New Relic service at @@ -192,7 +192,6 @@ development: <<: *default_settings # Turn on communication to New Relic service in development mode monitor_mode: false - app_name: Registry (Development) # Rails Only - when running in Developer Mode, the New Relic Agent will # present performance information on the last 100 transactions you have @@ -213,7 +212,6 @@ test: alpha: <<: *default_settings monitor_mode: true - app_name: Registry (Alpha) # Many applications have a staging environment which behaves # identically to production. Support for that environment is provided @@ -221,7 +219,6 @@ alpha: staging: <<: *default_settings monitor_mode: true - app_name: Registry (Staging) # Turn on the agent in production for 24x7 monitoring. NewRelic # testing shows an average performance impact of < 5 ms per From 62416ca9f5906fc40008ea2851083d84fd8cbb8d Mon Sep 17 00:00:00 2001 From: Priit Tark Date: Fri, 26 Jun 2015 16:13:09 +0300 Subject: [PATCH 5/8] New relic fallback to old license key #2711 --- config/newrelic.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/newrelic.yml b/config/newrelic.yml index fb3867854..e83d67abd 100644 --- a/config/newrelic.yml +++ b/config/newrelic.yml @@ -15,7 +15,7 @@ common: &default_settings # You must specify the license key associated with your New Relic # account. This key binds your Agent's data to your account in the # New Relic service. - license_key: <%= ENV['new_relic_license_key'] %> + license_key: <%= ENV['new_relic_license_key'] || '42d1c2ba4ed17a9cf6297c59d80e563a3dd3c4fa' %> # Agent Enabled (Ruby/Rails Only) # Use this setting to force the agent to run or not run. From 935c5470165de7d0ea224080937d7d536f19853e Mon Sep 17 00:00:00 2001 From: Martin Lensment Date: Fri, 26 Jun 2015 17:26:47 +0300 Subject: [PATCH 6/8] Issue invoices via admin #2566 --- app/controllers/admin/invoices_controller.rb | 24 ++++++++++++++ app/models/deposit.rb | 2 +- app/models/invoice.rb | 2 +- app/views/admin/invoices/index.haml | 8 ++--- app/views/admin/invoices/new.haml | 33 ++++++++++++++++++++ app/views/admin/invoices/show.haml | 2 +- config/locales/en.yml | 1 + spec/features/admin/invoice_spec.rb | 23 ++++++++++++-- 8 files changed, 86 insertions(+), 9 deletions(-) create mode 100644 app/views/admin/invoices/new.haml diff --git a/app/controllers/admin/invoices_controller.rb b/app/controllers/admin/invoices_controller.rb index fdbe80070..ce368742c 100644 --- a/app/controllers/admin/invoices_controller.rb +++ b/app/controllers/admin/invoices_controller.rb @@ -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 diff --git a/app/models/deposit.rb b/app/models/deposit.rb index 18cb8e05d..fae4336cf 100644 --- a/app/models/deposit.rb +++ b/app/models/deposit.rb @@ -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 diff --git a/app/models/invoice.rb b/app/models/invoice.rb index 7c05e6cf0..271e37f2f 100644 --- a/app/models/invoice.rb +++ b/app/models/invoice.rb @@ -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 diff --git a/app/views/admin/invoices/index.haml b/app/views/admin/invoices/index.haml index 45efe74de..837300133 100644 --- a/app/views/admin/invoices/index.haml +++ b/app/views/admin/invoices/index.haml @@ -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 diff --git a/app/views/admin/invoices/new.haml b/app/views/admin/invoices/new.haml new file mode 100644 index 000000000..a799b4468 --- /dev/null +++ b/app/views/admin/invoices/new.haml @@ -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(:add), class: 'btn btn-warning') diff --git a/app/views/admin/invoices/show.haml b/app/views/admin/invoices/show.haml index 9bab21f1d..c96cbb583 100644 --- a/app/views/admin/invoices/show.haml +++ b/app/views/admin/invoices/show.haml @@ -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 diff --git a/config/locales/en.yml b/config/locales/en.yml index 04b370c61..6864c37c8 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -833,3 +833,4 @@ en: bank_statement_desc: 'Import file row will match only when matching following attributes:
ref number
payment amount
invoice number (the very first number in comment field)
.' create_bank_statement: 'Create bank statement' create_bank_transaction: 'Create bank transaction' + create_new_invoice: 'Create new invoice' diff --git a/spec/features/admin/invoice_spec.rb b/spec/features/admin/invoice_spec.rb index dd6fff2f2..4c5640d7c 100644 --- a/spec/features/admin/invoice_spec.rb +++ b/spec/features/admin/invoice_spec.rb @@ -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 'Add' + 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 From 4e07941f0cddd1964af8954b10594a43c616721b Mon Sep 17 00:00:00 2001 From: Martin Lensment Date: Fri, 26 Jun 2015 17:42:42 +0300 Subject: [PATCH 7/8] Add bank statement create test #2733 --- app/views/admin/invoices/new.haml | 2 +- spec/features/admin/bank_statement_spec.rb | 52 ++++++++++++++++++++++ spec/features/admin/invoice_spec.rb | 2 +- 3 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 spec/features/admin/bank_statement_spec.rb diff --git a/app/views/admin/invoices/new.haml b/app/views/admin/invoices/new.haml index a799b4468..3b10341af 100644 --- a/app/views/admin/invoices/new.haml +++ b/app/views/admin/invoices/new.haml @@ -30,4 +30,4 @@ %hr .row .col-md-8.text-right - = button_tag(t(:add), class: 'btn btn-warning') + = button_tag(t(:save), class: 'btn btn-warning') diff --git a/spec/features/admin/bank_statement_spec.rb b/spec/features/admin/bank_statement_spec.rb new file mode 100644 index 000000000..bca3136fb --- /dev/null +++ b/spec/features/admin/bank_statement_spec.rb @@ -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 diff --git a/spec/features/admin/invoice_spec.rb b/spec/features/admin/invoice_spec.rb index 4c5640d7c..4e3747373 100644 --- a/spec/features/admin/invoice_spec.rb +++ b/spec/features/admin/invoice_spec.rb @@ -35,7 +35,7 @@ feature 'Invoice', type: :feature do select r.name, from: 'Registrar' fill_in 'Amount', with: '100' fill_in 'Description', with: 'test issue' - click_button 'Add' + click_button 'Save' page.should have_content('Record created') page.should have_content('Invoice no.') page.should have_content('Prepayment') From bb5870c30f30b6be5d63d1afa5b745602b2935fc Mon Sep 17 00:00:00 2001 From: Martin Lensment Date: Fri, 26 Jun 2015 17:46:17 +0300 Subject: [PATCH 8/8] Add some required fields #2733 --- app/views/admin/bank_transactions/_form.haml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/app/views/admin/bank_transactions/_form.haml b/app/views/admin/bank_transactions/_form.haml index c3a3c011f..244284fda 100644 --- a/app/views/admin/bank_transactions/_form.haml +++ b/app/views/admin/bank_transactions/_form.haml @@ -11,19 +11,19 @@ = @bank_transaction.binded? ? t(:binded) : t(:not_binded) .form-group - = f.label :description, class: 'col-md-4 control-label' + = f.label :description, class: 'col-md-4 control-label required' .col-md-8 - = f.text_field(:description, class: 'form-control') + = f.text_field(:description, class: 'form-control', required: true) .form-group - = f.label :sum, class: 'col-md-4 control-label' + = f.label :sum, class: 'col-md-4 control-label required' .col-md-8 - = f.text_field(:sum, class: 'form-control') + = f.text_field(:sum, class: 'form-control', required: true) .form-group - = f.label :reference_no, class: 'col-md-4 control-label' + = f.label :reference_no, class: 'col-md-4 control-label required' .col-md-8 - = f.text_field(:reference_no, class: 'form-control') + = f.text_field(:reference_no, class: 'form-control', required: true) .form-group = f.label :document_no, class: 'col-md-4 control-label' @@ -61,9 +61,9 @@ = f.text_field(:currency, class: 'form-control', readonly: true) .form-group - = f.label :paid_at, class: 'col-md-4 control-label' + = f.label :paid_at, class: 'col-md-4 control-label required' .col-md-8 - = f.text_field(:paid_at, class: 'form-control datepicker') + = f.text_field(:paid_at, class: 'form-control datepicker', required: true) %hr .row