1
0
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:
Sylvain 2019-02-11 13:57:07 +01:00
parent abf80e0a38
commit cc124a0dee
3 changed files with 22 additions and 1 deletions

View File

@ -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

View File

@ -0,0 +1,5 @@
class AddFootprintToInvoice < ActiveRecord::Migration
def change
add_column :invoices, :footprint, :string
end
end

View File

@ -0,0 +1,5 @@
class AddFootprintToInvoiceItem < ActiveRecord::Migration
def change
add_column :invoice_items, :footprint, :string
end
end