Add invoice numbers

This commit is contained in:
Martin Lensment 2015-04-23 17:49:22 +03:00
parent 109ce6c912
commit 1e47f3e41c
10 changed files with 35 additions and 14 deletions

View file

@ -9,7 +9,7 @@ class Registrar::DepositsController < RegistrarController
@deposit = Deposit.new(deposit_params.merge(registrar: current_user.registrar)) @deposit = Deposit.new(deposit_params.merge(registrar: current_user.registrar))
@invoice = @deposit.issue_prepayment_invoice @invoice = @deposit.issue_prepayment_invoice
if @invoice if @invoice.persisted?
flash[:notice] = t('please_pay_the_following_invoice') flash[:notice] = t('please_pay_the_following_invoice')
redirect_to [:registrar, @invoice] redirect_to [:registrar, @invoice]
else else

View file

@ -13,6 +13,23 @@ 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
def set_invoice_number
last_no = Invoice.order(number: :desc).where('number IS NOT NULL').limit(1).pluck(:number).first
if last_no
self.number = last_no + 1
else
self.number = Setting.invoice_number_min.to_i
end
return if number <= Setting.invoice_number_max.to_i
errors.add(:base, I18n.t('failed_to_generate_invoice'))
logger.error('INVOICE NUMBER LIMIT REACHED, COULD NOT GENERATE INVOICE')
false
end
def binded? def binded?
account_activity.present? account_activity.present?
end end
@ -25,11 +42,6 @@ class Invoice < ActiveRecord::Base
I18n.t('invoice_no', no: number) I18n.t('invoice_no', no: number)
end end
def number
# TODO: Real invoice numbers here
id
end
def seller_address def seller_address
[seller_street, seller_city, seller_state, seller_zip].reject(&:blank?).compact.join(', ') [seller_street, seller_city, seller_state, seller_zip].reject(&:blank?).compact.join(', ')
end end

View file

@ -19,7 +19,7 @@
%tbody %tbody
- @invoices.each do |x| - @invoices.each do |x|
%tr %tr
%td= link_to(t('invoice_no', no: x.id), [:admin, x]) %td= link_to(x, [:admin, x])
%td= link_to(x.buyer_name, admin_registrar_path(x.buyer_id)) %td= link_to(x.buyer_name, admin_registrar_path(x.buyer_id))
%td= l(x.due_date) %td= l(x.due_date)
- if x.binded? - if x.binded?

View file

@ -1,7 +1,7 @@
.row .row
.col-sm-6 .col-sm-6
%h1.text-center-xs %h1.text-center-xs
= t('invoice_no', no: @invoice.id) = @invoice
.col-sm-6 .col-sm-6
%h1.text-right.text-center-xs %h1.text-right.text-center-xs
= link_to(t('back'), :back, class: 'btn btn-default') = link_to(t('back'), :back, class: 'btn btn-default')

View file

@ -3,8 +3,8 @@
= link_to(t(:account_activity), registrar_account_activities_path, class: 'btn btn-default') = link_to(t(:account_activity), registrar_account_activities_path, class: 'btn btn-default')
= render 'shared/title', name: t(:your_account) = render 'shared/title', name: t(:your_account)
= t(:your_current_account_balance_is, = t(:your_current_account_balance_is,
balance: current_user.registrar.cash_account.balance, balance: current_user.registrar.cash_account.balance,
currency: current_user.registrar.cash_account.currency) currency: current_user.registrar.cash_account.currency)
%h1= t(:invoices) %h1= t(:invoices)
@ -22,7 +22,7 @@
%tbody %tbody
- @invoices.each do |x| - @invoices.each do |x|
%tr %tr
%td= link_to(t(:invoice_no, no: x.id), [:registrar, x]) %td= link_to(x, [:registrar, x])
- if x.receipt_date - if x.receipt_date
%td= l(x.receipt_date) %td= l(x.receipt_date)
- else - else

View file

@ -137,7 +137,7 @@
.col-sm-6.left .col-sm-6.left
#header-content #header-content
%h1 %h1
= t(:invoice_no, no: @invoice.id) = @invoice
.col-sm-6.right .col-sm-6.right
%img{src: "#{Rails.root}/public/eis-logo-black-et.png"} %img{src: "#{Rails.root}/public/eis-logo-black-et.png"}
.clear .clear

View file

@ -2,7 +2,7 @@
= link_to(t(:download), download_pdf_registrar_invoice_path(@invoice), class: 'btn btn-default') = link_to(t(:download), download_pdf_registrar_invoice_path(@invoice), class: 'btn btn-default')
= link_to(t(:forward_invoice), forward_registrar_invoice_path(@invoice), class: 'btn btn-default') = link_to(t(:forward_invoice), forward_registrar_invoice_path(@invoice), class: 'btn btn-default')
= link_to(t(:back), :back, class: 'btn btn-default') = link_to(t(:back), :back, class: 'btn btn-default')
= render 'shared/title', name: t(:invoice_no, no: @invoice.id) = render 'shared/title', name: @invoice.to_s
.row .row
.col-md-6= render 'registrar/invoices/partials/details' .col-md-6= render 'registrar/invoices/partials/details'

View file

@ -28,6 +28,8 @@ if con.present? && con.table_exists?('settings')
Setting.save_default(:eis_bank, 'LHV Pank') Setting.save_default(:eis_bank, 'LHV Pank')
Setting.save_default(:eis_swift, 'LHVBEE22') Setting.save_default(:eis_swift, 'LHVBEE22')
Setting.save_default(:eis_invoice_contact, 'Martti Õigus') Setting.save_default(:eis_invoice_contact, 'Martti Õigus')
Setting.save_default(:invoice_number_min, '131050')
Setting.save_default(:invoice_number_max, '149999')
end end
# dev only setting # dev only setting

View file

@ -0,0 +1,6 @@
class AddNumberToInvoices < ActiveRecord::Migration
def change
add_column :invoices, :number, :integer
Invoice.all.each(&:save)
end
end

View file

@ -11,7 +11,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20150422132631) do ActiveRecord::Schema.define(version: 20150423083308) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@ -367,6 +367,7 @@ ActiveRecord::Schema.define(version: 20150422132631) do
t.string "buyer_email" t.string "buyer_email"
t.string "creator_str" t.string "creator_str"
t.string "updator_str" t.string "updator_str"
t.integer "number"
end end
add_index "invoices", ["buyer_id"], name: "index_invoices_on_buyer_id", using: :btree add_index "invoices", ["buyer_id"], name: "index_invoices_on_buyer_id", using: :btree