mirror of
https://github.com/internetee/registry.git
synced 2025-07-21 02:05:57 +02:00
Issue invoices via admin #2566
This commit is contained in:
parent
4569cc11cd
commit
935c547016
8 changed files with 86 additions and 9 deletions
|
@ -1,6 +1,24 @@
|
||||||
class Admin::InvoicesController < AdminController
|
class Admin::InvoicesController < AdminController
|
||||||
load_and_authorize_resource
|
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
|
def index
|
||||||
@q = Invoice.includes(:account_activity).search(params[:q])
|
@q = Invoice.includes(:account_activity).search(params[:q])
|
||||||
@q.sorts = 'id desc' if @q.sorts.empty?
|
@q.sorts = 'id desc' if @q.sorts.empty?
|
||||||
|
@ -20,4 +38,10 @@ class Admin::InvoicesController < AdminController
|
||||||
render :show
|
render :show
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def deposit_params
|
||||||
|
params.require(:deposit).permit(:amount, :description, :registrar_id)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,7 +4,7 @@ class Deposit
|
||||||
extend ActiveModel::Naming
|
extend ActiveModel::Naming
|
||||||
include DisableHtml5Validation
|
include DisableHtml5Validation
|
||||||
|
|
||||||
attr_accessor :amount, :description, :registrar
|
attr_accessor :amount, :description, :registrar, :registrar_id
|
||||||
|
|
||||||
validates :amount, :registrar, presence: true
|
validates :amount, :registrar, presence: true
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ class Invoice < ActiveRecord::Base
|
||||||
validates :invoice_type, :due_date, :currency, :seller_name,
|
validates :invoice_type, :due_date, :currency, :seller_name,
|
||||||
:seller_iban, :buyer_name, :invoice_items, :vat_prc, presence: true
|
:seller_iban, :buyer_name, :invoice_items, :vat_prc, presence: true
|
||||||
|
|
||||||
before_save :set_invoice_number
|
before_create :set_invoice_number
|
||||||
def set_invoice_number
|
def set_invoice_number
|
||||||
last_no = Invoice.order(number: :desc).where('number IS NOT NULL').limit(1).pluck(:number).first
|
last_no = Invoice.order(number: :desc).where('number IS NOT NULL').limit(1).pluck(:number).first
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
.row
|
- content_for :actions do
|
||||||
.col-sm-12
|
= link_to(t(:add), new_admin_invoice_path, class: 'btn btn-primary')
|
||||||
%h2.text-center-xs= t(:invoices)
|
= render 'shared/title', name: t(:invoices)
|
||||||
%hr
|
|
||||||
.row
|
.row
|
||||||
.col-md-12
|
.col-md-12
|
||||||
.table-responsive
|
.table-responsive
|
||||||
|
|
33
app/views/admin/invoices/new.haml
Normal file
33
app/views/admin/invoices/new.haml
Normal 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(:add), class: 'btn btn-warning')
|
|
@ -5,7 +5,7 @@
|
||||||
.col-sm-6
|
.col-sm-6
|
||||||
%h1.text-right.text-center-xs
|
%h1.text-right.text-center-xs
|
||||||
- if !@invoice.cancelled? && !@invoice.binded?
|
- 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')
|
= link_to(t(:back), admin_invoices_path, class: 'btn btn-default')
|
||||||
%hr
|
%hr
|
||||||
= render 'shared/full_errors', object: @invoice
|
= render 'shared/full_errors', object: @invoice
|
||||||
|
|
|
@ -833,3 +833,4 @@ en:
|
||||||
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'
|
create_bank_statement: 'Create bank statement'
|
||||||
create_bank_transaction: 'Create bank transaction'
|
create_bank_transaction: 'Create bank transaction'
|
||||||
|
create_new_invoice: 'Create new invoice'
|
||||||
|
|
|
@ -6,15 +6,17 @@ feature 'Invoice', type: :feature do
|
||||||
Fabricate(:invoice)
|
Fabricate(:invoice)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should show index of invoices' do
|
before do
|
||||||
sign_in @user
|
sign_in @user
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should show index of invoices' do
|
||||||
visit admin_invoices_url
|
visit admin_invoices_url
|
||||||
i = Invoice.first
|
i = Invoice.first
|
||||||
page.should have_link("Invoice no. #{i.id}")
|
page.should have_link("Invoice no. #{i.id}")
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should show invoice' do
|
it 'should show invoice' do
|
||||||
sign_in @user
|
|
||||||
visit admin_invoices_url
|
visit admin_invoices_url
|
||||||
i = Invoice.first
|
i = Invoice.first
|
||||||
|
|
||||||
|
@ -23,4 +25,21 @@ feature 'Invoice', type: :feature do
|
||||||
page.should have_content("Details")
|
page.should have_content("Details")
|
||||||
page.should have_content("Paldiski mnt. 123")
|
page.should have_content("Paldiski mnt. 123")
|
||||||
end
|
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
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue