mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-02-19 13:54:25 +01:00
prevent closing an accounting period if any checksum error in period
This commit is contained in:
parent
9f4d026f30
commit
ffe5516d10
@ -671,6 +671,9 @@ Application.Controllers.controller('ClosePeriodModalController', ['$scope', '$ui
|
||||
// any form errors will come here
|
||||
$scope.errors = {};
|
||||
|
||||
// will match any error about invoices
|
||||
$scope.invoiceErrorRE = /^invoice_(.+)$/;
|
||||
|
||||
// existing closed periods, provided by the API
|
||||
$scope.accountingPeriods = periods;
|
||||
|
||||
|
@ -46,6 +46,9 @@
|
||||
<span class="help-block error" ng-show="errors.end_at">{{ errors.end_at[0] }}</span>
|
||||
</div>
|
||||
</form>
|
||||
<div ng-repeat="(key, value) in errors" ng-if="invoiceErrorRE.test(key)" class="row col-md-12">
|
||||
<span class="help-block error">{{ $parent.invoiceErrorRE.exec(key)[1] }} : {{ value[0] }}</span>
|
||||
</div>
|
||||
<div>
|
||||
<h4 translate>{{ 'invoices.previous_closings' }}</h4>
|
||||
<table class="table closings-table" ng-show="accountingPeriods.length > 0">
|
||||
|
@ -13,6 +13,7 @@ class AccountingPeriod < ActiveRecord::Base
|
||||
validates :start_at, :end_at, :closed_at, :closed_by, presence: true
|
||||
validates_with DateRangeValidator
|
||||
validates_with PeriodOverlapValidator
|
||||
validates_with PeriodIntegrityValidator
|
||||
|
||||
def delete
|
||||
false
|
||||
|
17
app/validators/period_integrity_validator.rb
Normal file
17
app/validators/period_integrity_validator.rb
Normal file
@ -0,0 +1,17 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# Validates that all invoices in the current accounting period are chained with footprints which ensure their integrity
|
||||
class PeriodIntegrityValidator < ActiveModel::Validator
|
||||
def validate(record)
|
||||
the_end = record.end_at
|
||||
the_start = record.start_at
|
||||
|
||||
invoices = Invoice.where('created_at >= :start_date AND created_at < :end_date', start_date: the_start, end_date: the_end)
|
||||
.includes(:invoice_items)
|
||||
|
||||
|
||||
invoices.each do |i|
|
||||
record.errors["invoice_#{i.reference}".to_sym] << I18n.t('errors.messages.invalid_footprint') unless i.check_footprint
|
||||
end
|
||||
end
|
||||
end
|
@ -417,7 +417,7 @@ en:
|
||||
closed_at: "Closed at"
|
||||
closed_by: "By"
|
||||
confirmation_required: "Confirmation required"
|
||||
confirm_close_START_END: "Do you really want to close the accounting period between {{START}} and {{END}}? Any subsequent changes will be impossible."
|
||||
confirm_close_START_END: "Do you really want to close the accounting period between {{START}} and {{END}}? Any subsequent changes will be impossible. This operation will take some time to complete"
|
||||
period_START_END_closed_success: "The accounting period from {{START}} to {{END}} has been successfully closed"
|
||||
failed_to_close_period: "An error occurred, unable to close the accounting period"
|
||||
no_periods: "No closings for now"
|
||||
|
@ -417,7 +417,7 @@ es:
|
||||
closed_at: "Closed at" # translation_missing
|
||||
closed_by: "By" # translation_missing
|
||||
confirmation_required: "Confirmation required" # translation_missing
|
||||
confirm_close_START_END: "Do you really want to close the accounting period between {{START}} and {{END}}? Any subsequent changes will be impossible." # translation_missing
|
||||
confirm_close_START_END: "Do you really want to close the accounting period between {{START}} and {{END}}? Any subsequent changes will be impossible. This operation will take some time to complete" # translation_missing
|
||||
period_START_END_closed_success: "The accounting period from {{START}} to {{END}} has been successfully closed" # translation_missing
|
||||
failed_to_close_period: "An error occurred, unable to close the accounting period" # translation_missing
|
||||
no_periods: "No closings for now" # translation_missing
|
||||
|
@ -417,7 +417,7 @@ fr:
|
||||
closed_at: "Clôturé le"
|
||||
closed_by: "Par"
|
||||
confirmation_required: "Confirmation requise"
|
||||
confirm_close_START_END: "Êtes-vous sur de vouloir clôturer la période comptable du {{START}} au {{END}} ? Toute modification ultérieure sera impossible."
|
||||
confirm_close_START_END: "Êtes-vous sur de vouloir clôturer la période comptable du {{START}} au {{END}} ? Toute modification ultérieure sera impossible. Cette opération va prendre un certain temps."
|
||||
period_START_END_closed_success: "La période comptable du {{START}} au {{END}} a bien été clôturée"
|
||||
failed_to_close_period: "Une erreur est survenue, impossible de clôturer la période comptable"
|
||||
no_periods: "Aucune clôture pour le moment"
|
||||
|
@ -417,7 +417,7 @@ pt:
|
||||
closed_at: "Closed at" # translation_missing
|
||||
closed_by: "By" # translation_missing
|
||||
confirmation_required: "Confirmation required" # translation_missing
|
||||
confirm_close_START_END: "Do you really want to close the accounting period between {{START}} and {{END}}? Any subsequent changes will be impossible." # translation_missing
|
||||
confirm_close_START_END: "Do you really want to close the accounting period between {{START}} and {{END}}? Any subsequent changes will be impossible. This operation will take some time to complete." # translation_missing
|
||||
period_START_END_closed_success: "The accounting period from {{START}} to {{END}} has been successfully closed" # translation_missing
|
||||
failed_to_close_period: "An error occurred, unable to close the accounting period" # translation_missing
|
||||
no_periods: "No closings for now" # translation_missing
|
||||
|
@ -39,6 +39,7 @@ en:
|
||||
cannot_overlap: "can't overlap an existing accounting period"
|
||||
cannot_encompass: "can't encompass an existing accounting period"
|
||||
in_closed_period: "can't be within a closed accounting period"
|
||||
invalid_footprint: "invoice's checksum is invalid"
|
||||
|
||||
activemodel:
|
||||
errors:
|
||||
|
@ -39,6 +39,7 @@ es:
|
||||
cannot_overlap: "can't overlap an existing accounting period" # missing translation
|
||||
cannot_encompass: "can't encompass an existing accounting period" # missing translation
|
||||
in_closed_period: "can't be within a closed accounting period" # missing translation
|
||||
invalid_footprint: "invoice's checksum is invalid" # missing translation
|
||||
|
||||
activemodel:
|
||||
errors:
|
||||
|
@ -39,6 +39,7 @@ fr:
|
||||
cannot_overlap: "ne peut pas chevaucher une période comptable existante"
|
||||
cannot_encompass: "ne peut pas englober une période comptable existante"
|
||||
in_closed_period: "ne peut pas être dans une période comptable fermée"
|
||||
invalid_footprint: "la somme de contrôle de la facture est invalide"
|
||||
|
||||
activemodel:
|
||||
errors:
|
||||
|
@ -39,6 +39,7 @@ pt:
|
||||
cannot_overlap: "can't overlap an existing accounting period" # missing translation
|
||||
cannot_encompass: "can't encompass an existing accounting period" # missing translation
|
||||
in_closed_period: "can't be within a closed accounting period" # missing translation
|
||||
invalid_footprint: "invoice's checksum is invalid" # missing translation
|
||||
|
||||
activemodel:
|
||||
errors:
|
||||
|
Loading…
x
Reference in New Issue
Block a user