diff --git a/app/controllers/admin/bank_statements_controller.rb b/app/controllers/admin/bank_statements_controller.rb index 1e69aa1af..238b819da 100644 --- a/app/controllers/admin/bank_statements_controller.rb +++ b/app/controllers/admin/bank_statements_controller.rb @@ -17,6 +17,14 @@ class Admin::BankStatementsController < AdminController def new @bank_statement = BankStatement.new + @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 def create @@ -69,6 +77,8 @@ class Admin::BankStatementsController < AdminController end 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, :reference_no, :paid_at + ]) end end diff --git a/app/models/bank_statement.rb b/app/models/bank_statement.rb index 7267b4773..89a5c7d69 100644 --- a/app/models/bank_statement.rb +++ b/app/models/bank_statement.rb @@ -2,6 +2,8 @@ class BankStatement < ActiveRecord::Base include Versions has_many :bank_transactions + accepts_nested_attributes_for :bank_transactions + attr_accessor :th6_file validates :bank_code, :iban, presence: true diff --git a/app/views/admin/bank_statements/_form.haml b/app/views/admin/bank_statements/_form.haml index 158d69e89..848fde486 100644 --- a/app/views/admin/bank_statements/_form.haml +++ b/app/views/admin/bank_statements/_form.haml @@ -13,6 +13,31 @@ = f.label :iban .col-md-8 = 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 :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 .row .col-md-8.text-right diff --git a/app/views/admin/bank_transactions/new.haml b/app/views/admin/bank_transactions/new.haml index 403eb415e..c2acb0c79 100644 --- a/app/views/admin/bank_transactions/new.haml +++ b/app/views/admin/bank_transactions/new.haml @@ -1,5 +1,6 @@ - content_for :actions do - = link_to(t(:back), admin_bank_statement_path(@bank_statement), class: 'btn btn-default') + - if @bank_statement.persisted? + = link_to(t(:back), admin_bank_statement_path(@bank_statement), class: 'btn btn-default') = render 'shared/title', name: t(:create_bank_transaction) diff --git a/app/views/admin/invoices/show.haml b/app/views/admin/invoices/show.haml index 1d8480da4..33fc5a5d1 100644 --- a/app/views/admin/invoices/show.haml +++ b/app/views/admin/invoices/show.haml @@ -1,9 +1,11 @@ .row - .col-sm-6 + .col-sm-4 %h1.text-center-xs = @invoice - .col-sm-6 + .col-sm-8 %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(:forward), admin_invoice_forward_path(@invoice), class: 'btn btn-default') - if !@invoice.cancelled? && !@invoice.binded? diff --git a/config/locales/en.yml b/config/locales/en.yml index 23f97b5e2..863a00790 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -869,3 +869,4 @@ en: reserved_pw: 'Reserved pw' no_transfers_found: 'No transfers found' parameter_value_range_error: 'Parameter value range error: %{key}' + payment_received: 'Payment received'