mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-02-20 14:54:15 +01:00
[ongoing] chain invoice records
This commit is contained in:
parent
abf80e0a38
commit
cc124a0dee
@ -14,7 +14,7 @@ class Invoice < ActiveRecord::Base
|
||||
|
||||
has_one :avoir, class_name: 'Invoice', foreign_key: :invoice_id, dependent: :destroy
|
||||
|
||||
after_create :update_reference
|
||||
after_create :update_reference, :chain_record
|
||||
after_commit :generate_and_send_invoice, on: [:create], if: :persisted?
|
||||
|
||||
validates_with ClosedPeriodValidator
|
||||
@ -211,6 +211,17 @@ class Invoice < ActiveRecord::Base
|
||||
total - (wallet_amount || 0)
|
||||
end
|
||||
|
||||
def chain_record
|
||||
sha256 = Digest::SHA256.new
|
||||
|
||||
previous = Invoice.where(created_at: Invoice.select('MAX(created_at)')).limit(1).first
|
||||
|
||||
self.footprint = sha256.hexdigest "#{id}#{invoice_id}#{invoiced_type}#{stp_invoice_id}#{total}#{created_at}#{updated_at}" \
|
||||
"#{user_id}#{reference}#{avoir_mode}#{avoir_date}#{invoice_id}#{type}" \
|
||||
"#{subscription_to_expire}#{description}#{wallet_amount}#{wallet_transaction_id}" \
|
||||
"#{coupon_id}#{previous ? previous.footprint : ''}"
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def generate_and_send_invoice
|
||||
|
5
db/migrate/20190211124135_add_footprint_to_invoice.rb
Normal file
5
db/migrate/20190211124135_add_footprint_to_invoice.rb
Normal file
@ -0,0 +1,5 @@
|
||||
class AddFootprintToInvoice < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :invoices, :footprint, :string
|
||||
end
|
||||
end
|
@ -0,0 +1,5 @@
|
||||
class AddFootprintToInvoiceItem < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :invoice_items, :footprint, :string
|
||||
end
|
||||
end
|
Loading…
x
Reference in New Issue
Block a user