mirror of
https://github.com/internetee/registry.git
synced 2025-07-24 11:38:30 +02:00
Add invoice numbers
This commit is contained in:
parent
109ce6c912
commit
1e47f3e41c
10 changed files with 35 additions and 14 deletions
|
@ -9,7 +9,7 @@ class Registrar::DepositsController < RegistrarController
|
|||
@deposit = Deposit.new(deposit_params.merge(registrar: current_user.registrar))
|
||||
@invoice = @deposit.issue_prepayment_invoice
|
||||
|
||||
if @invoice
|
||||
if @invoice.persisted?
|
||||
flash[:notice] = t('please_pay_the_following_invoice')
|
||||
redirect_to [:registrar, @invoice]
|
||||
else
|
||||
|
|
|
@ -13,6 +13,23 @@ 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
|
||||
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?
|
||||
account_activity.present?
|
||||
end
|
||||
|
@ -25,11 +42,6 @@ class Invoice < ActiveRecord::Base
|
|||
I18n.t('invoice_no', no: number)
|
||||
end
|
||||
|
||||
def number
|
||||
# TODO: Real invoice numbers here
|
||||
id
|
||||
end
|
||||
|
||||
def seller_address
|
||||
[seller_street, seller_city, seller_state, seller_zip].reject(&:blank?).compact.join(', ')
|
||||
end
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
%tbody
|
||||
- @invoices.each do |x|
|
||||
%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= l(x.due_date)
|
||||
- if x.binded?
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
.row
|
||||
.col-sm-6
|
||||
%h1.text-center-xs
|
||||
= t('invoice_no', no: @invoice.id)
|
||||
= @invoice
|
||||
.col-sm-6
|
||||
%h1.text-right.text-center-xs
|
||||
= link_to(t('back'), :back, class: 'btn btn-default')
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
= link_to(t(:account_activity), registrar_account_activities_path, class: 'btn btn-default')
|
||||
= render 'shared/title', name: t(:your_account)
|
||||
|
||||
= t(:your_current_account_balance_is,
|
||||
balance: current_user.registrar.cash_account.balance,
|
||||
= t(:your_current_account_balance_is,
|
||||
balance: current_user.registrar.cash_account.balance,
|
||||
currency: current_user.registrar.cash_account.currency)
|
||||
|
||||
%h1= t(:invoices)
|
||||
|
@ -22,7 +22,7 @@
|
|||
%tbody
|
||||
- @invoices.each do |x|
|
||||
%tr
|
||||
%td= link_to(t(:invoice_no, no: x.id), [:registrar, x])
|
||||
%td= link_to(x, [:registrar, x])
|
||||
- if x.receipt_date
|
||||
%td= l(x.receipt_date)
|
||||
- else
|
||||
|
|
|
@ -137,7 +137,7 @@
|
|||
.col-sm-6.left
|
||||
#header-content
|
||||
%h1
|
||||
= t(:invoice_no, no: @invoice.id)
|
||||
= @invoice
|
||||
.col-sm-6.right
|
||||
%img{src: "#{Rails.root}/public/eis-logo-black-et.png"}
|
||||
.clear
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
= 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(:back), :back, class: 'btn btn-default')
|
||||
= render 'shared/title', name: t(:invoice_no, no: @invoice.id)
|
||||
= render 'shared/title', name: @invoice.to_s
|
||||
|
||||
.row
|
||||
.col-md-6= render 'registrar/invoices/partials/details'
|
||||
|
|
|
@ -28,6 +28,8 @@ if con.present? && con.table_exists?('settings')
|
|||
Setting.save_default(:eis_bank, 'LHV Pank')
|
||||
Setting.save_default(:eis_swift, 'LHVBEE22')
|
||||
Setting.save_default(:eis_invoice_contact, 'Martti Õigus')
|
||||
Setting.save_default(:invoice_number_min, '131050')
|
||||
Setting.save_default(:invoice_number_max, '149999')
|
||||
end
|
||||
|
||||
# dev only setting
|
||||
|
|
6
db/migrate/20150423083308_add_number_to_invoices.rb
Normal file
6
db/migrate/20150423083308_add_number_to_invoices.rb
Normal file
|
@ -0,0 +1,6 @@
|
|||
class AddNumberToInvoices < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :invoices, :number, :integer
|
||||
Invoice.all.each(&:save)
|
||||
end
|
||||
end
|
|
@ -11,7 +11,7 @@
|
|||
#
|
||||
# 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
|
||||
enable_extension "plpgsql"
|
||||
|
@ -367,6 +367,7 @@ ActiveRecord::Schema.define(version: 20150422132631) do
|
|||
t.string "buyer_email"
|
||||
t.string "creator_str"
|
||||
t.string "updator_str"
|
||||
t.integer "number"
|
||||
end
|
||||
|
||||
add_index "invoices", ["buyer_id"], name: "index_invoices_on_buyer_id", using: :btree
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue