mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-02-20 14:54:15 +01:00
display records integrity status
This commit is contained in:
parent
f9364b3872
commit
2ba3890325
@ -1,6 +1,14 @@
|
||||
|
||||
// admin invoices
|
||||
|
||||
.chained {
|
||||
color: green;
|
||||
}
|
||||
|
||||
.broken {
|
||||
color: red;
|
||||
}
|
||||
|
||||
.invoice-placeholder {
|
||||
width: 80%;
|
||||
max-width: 800px;
|
||||
|
@ -61,6 +61,7 @@
|
||||
<table class="table" ng-if="invoices.length > 0">
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="width:5%"></th>
|
||||
<th style="width:15%"><a href="" ng-click="setOrderInvoice('reference')">{{ 'invoices.invoice_#' | translate }} <i class="fa fa-arrows-v" ng-class="{'fa fa-sort-numeric-asc': orderInvoice=='reference', 'fa fa-sort-numeric-desc': orderInvoice=='-reference', 'fa fa-arrows-v': orderInvoice }"></i></a></th>
|
||||
|
||||
<th style="width:20%"><a href="" ng-click="setOrderInvoice('date')">{{ 'invoices.date' | translate }} <i class="fa fa-arrows-v" ng-class="{'fa fa-sort-numeric-asc': orderInvoice=='date', 'fa fa-sort-numeric-desc': orderInvoice=='-date', 'fa fa-arrows-v': orderInvoice }"></i></a></th>
|
||||
@ -74,6 +75,10 @@
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr ng-repeat="invoice in invoices">
|
||||
<td>
|
||||
<i class="fa fa-link chained" ng-show="invoice.chained_footprint"/>
|
||||
<i class="fa fa-chain-broken broken" ng-hide="invoice.chained_footprint"/>
|
||||
</td>
|
||||
<td>{{ invoice.reference }}</td>
|
||||
<td ng-if="!invoice.is_avoir">{{ invoice.date | amDateFormat:'L LTS' }}</td>
|
||||
<td ng-if="invoice.is_avoir">{{ invoice.date | amDateFormat:'L' }}</td>
|
||||
|
@ -212,16 +212,11 @@ class Invoice < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def chain_record
|
||||
max_date = created_at || DateTime.now
|
||||
previous = Invoice.where('created_at < ?', max_date)
|
||||
.order('created_at DESC')
|
||||
.limit(1)
|
||||
self.footprint = compute_footprint
|
||||
end
|
||||
|
||||
columns = Invoice.columns.map(&:name)
|
||||
.delete_if { |c| c == 'footprint' }
|
||||
|
||||
sha256 = Digest::SHA256.new
|
||||
self.footprint = sha256.hexdigest "#{columns.map { |c| self[c] }.join}#{previous.first ? previous.first.footprint : ''}"
|
||||
def check_footprint
|
||||
invoice_items.map(&:check_footprint).all? && footprint == compute_footprint
|
||||
end
|
||||
|
||||
private
|
||||
@ -269,4 +264,17 @@ class Invoice < ActiveRecord::Base
|
||||
Invoice.where('created_at >= :start_date AND created_at < :end_date', start_date: start, end_date: ending).length
|
||||
end
|
||||
|
||||
def compute_footprint
|
||||
max_date = created_at || DateTime.now
|
||||
previous = Invoice.where('created_at < ?', max_date)
|
||||
.order('created_at DESC')
|
||||
.limit(1)
|
||||
|
||||
columns = Invoice.columns.map(&:name)
|
||||
.delete_if { |c| %w[footprint updated_at].include? c }
|
||||
|
||||
sha256 = Digest::SHA256.new
|
||||
sha256.hexdigest "#{columns.map { |c| self[c] }.join}#{previous.first ? previous.first.footprint : ''}"
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -7,13 +7,23 @@ class InvoiceItem < ActiveRecord::Base
|
||||
after_create :chain_record
|
||||
|
||||
def chain_record
|
||||
self.footprint = compute_footprint
|
||||
end
|
||||
|
||||
def check_footprint
|
||||
footprint == compute_footprint
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def compute_footprint
|
||||
max_date = created_at || Time.current
|
||||
previous = InvoiceItem.where('created_at < ?', max_date)
|
||||
.order('created_at DESC')
|
||||
.limit(1)
|
||||
|
||||
columns = InvoiceItem.columns.map(&:name)
|
||||
.delete_if { |c| c == 'footprint' }
|
||||
.delete_if { |c| %w[footprint updated_at].include? c }
|
||||
|
||||
sha256 = Digest::SHA256.new
|
||||
self.footprint = sha256.hexdigest "#{columns.map { |c| self[c] }.join}#{previous.first ? previous.first.footprint : ''}"
|
||||
|
@ -12,4 +12,5 @@ json.array!(@invoices) do |invoice|
|
||||
json.stripe invoice.stp_invoice_id?
|
||||
json.date invoice.is_a?(Avoir) ? invoice.avoir_date : invoice.created_at
|
||||
json.prevent_refund invoice.prevent_refund?
|
||||
json.chained_footprint invoice.check_footprint
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user