1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-02-06 01:08:21 +01:00

close an accounting period from interface to db through api

This commit is contained in:
Sylvain 2019-01-07 15:33:09 +01:00
parent b1b5edbfb4
commit d89f9e9301
11 changed files with 90 additions and 22 deletions

View File

@ -392,7 +392,10 @@ Application.Controllers.controller('InvoicesController', ['$scope', '$state', 'I
$uibModal.open({ $uibModal.open({
templateUrl: '<%= asset_path "admin/invoices/closePeriodModal.html" %>', templateUrl: '<%= asset_path "admin/invoices/closePeriodModal.html" %>',
controller: 'ClosePeriodModalController', controller: 'ClosePeriodModalController',
size: 'lg' size: 'lg',
resolve: {
}
}); });
} }
@ -614,12 +617,12 @@ Application.Controllers.controller('AvoirModalController', ['$scope', '$uibModal
/** /**
* Controller used in the modal window allowing an admin to close an accounting period * Controller used in the modal window allowing an admin to close an accounting period
*/ */
Application.Controllers.controller('ClosePeriodModalController', ['$scope', '$uibModalInstance', 'Invoice', 'AccountingPeriod', 'growl', '_t', Application.Controllers.controller('ClosePeriodModalController', ['$scope', '$uibModalInstance', 'Invoice', 'AccountingPeriod', 'dialogs', 'growl', '_t',
function ($scope, $uibModalInstance, Invoice, AccountingPeriod, growl, _t) { function ($scope, $uibModalInstance, Invoice, AccountingPeriod, dialogs, growl, _t) {
/* PUBLIC SCOPE */ /* PUBLIC SCOPE */
$scope.period = { $scope.period = {
start_date: null, start_at: null,
end_date: null end_at: null
}; };
// AngularUI-Bootstrap datepickers parameters to define the period to close // AngularUI-Bootstrap datepickers parameters to define the period to close
@ -643,11 +646,35 @@ Application.Controllers.controller('ClosePeriodModalController', ['$scope', '$ui
}; };
/** /**
* Validate the refunding and generate a refund invoice * Validate the close period creation
*/ */
$scope.ok = function () { $scope.ok = function () {
$uibModalInstance.close({ period: $scope.period }); dialogs.confirm(
growl.info(_t('not_implemented_yet')); {
resolve: {
object () {
return {
title: _t('invoices.confirmation_required'),
msg: _t('invoices.confirm_close')
};
}
}
},
function () { // creation confirmed
AccountingPeriod.save({ accounting_period: $scope.period }, function (resp) {
growl.success(_t(
'invoices.period_START_END_closed_success',
{ START: moment(resp.start_at).format('LL'), END: moment(resp.end_at).format('LL') }
));
$uibModalInstance.close(resp);
}
, function(error) {
growl.error(_t('invoices.failed_to_close_period'));
console.error(error);
});
}
);
}; };
/** /**

View File

@ -1,11 +1,11 @@
'use strict'; 'use strict';
Application.Services.factory('AccountingPeriod', ['$resource', function ($resource) { Application.Services.factory('AccountingPeriod', ['$resource', function ($resource) {
return $resource('/api/accounting_period/:id', return $resource('/api/accounting_periods/:id',
{ id: '@id' }, { { id: '@id' }, {
lastClosingEnd: { lastClosingEnd: {
method: 'GET', method: 'GET',
url: '/api/accounting_period/last_closing_end' url: '/api/accounting_periods/last_closing_end'
} }
} }
); );

View File

@ -3,14 +3,14 @@
</div> </div>
<div class="modal-body"> <div class="modal-body">
<form name="closePeriodForm" novalidate="novalidate" class="row"> <form name="closePeriodForm" novalidate="novalidate" class="row">
<div class="form-group col-md-6" ng-class="{'has-error': closePeriodForm.start_date.$dirty && closePeriodForm.start_date.$invalid }"> <div class="form-group col-md-6" ng-class="{'has-error': closePeriodForm.start_at.$dirty && closePeriodForm.start_at.$invalid }">
<label translate>{{ 'invoices.close_from_date' }}</label> <label translate>{{ 'invoices.close_from_date' }}</label>
<div class="input-group"> <div class="input-group">
<span class="input-group-addon"><i class="fa fa-calendar"></i></span> <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
<input type="text" <input type="text"
class="form-control" class="form-control"
name="start_date" name="start_at"
ng-model="period.start_date" ng-model="period.start_at"
uib-datepicker-popup="{{datePicker.format}}" uib-datepicker-popup="{{datePicker.format}}"
datepicker-options="datePicker.options" datepicker-options="datePicker.options"
is-open="datePicker.startOpened" is-open="datePicker.startOpened"
@ -18,16 +18,16 @@
ng-click="openDatePicker($event, 'start')" ng-click="openDatePicker($event, 'start')"
required/> required/>
</div> </div>
<span class="help-block" ng-show="closePeriodForm.start_date.$dirty && closePeriodForm.start_date.$error.required" translate>{{ 'invoices.start_date_is_required' }}</span> <span class="help-block" ng-show="closePeriodForm.start_at.$dirty && closePeriodForm.start_at.$error.required" translate>{{ 'invoices.start_date_is_required' }}</span>
</div> </div>
<div class="form-group col-md-6" ng-class="{'has-error': closePeriodForm.end_date.$dirty && closePeriodForm.end_date.$invalid }"> <div class="form-group col-md-6" ng-class="{'has-error': closePeriodForm.end_at.$dirty && closePeriodForm.end_at.$invalid }">
<label translate>{{ 'invoices.close_until_date' }}</label> <label translate>{{ 'invoices.close_until_date' }}</label>
<div class="input-group"> <div class="input-group">
<span class="input-group-addon"><i class="fa fa-calendar"></i></span> <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
<input type="text" <input type="text"
class="form-control" class="form-control"
name="end_date" name="end_at"
ng-model="period.end_date" ng-model="period.end_at"
uib-datepicker-popup="{{datePicker.format}}" uib-datepicker-popup="{{datePicker.format}}"
datepicker-options="datePicker.options" datepicker-options="datePicker.options"
is-open="datePicker.endOpened" is-open="datePicker.endOpened"
@ -35,7 +35,7 @@
ng-click="openDatePicker($event, 'end')" ng-click="openDatePicker($event, 'end')"
required/> required/>
</div> </div>
<span class="help-block" ng-show="closePeriodForm.end_date.$dirty && closePeriodForm.end_date.$error.required" translate>{{ 'invoices.end_date_is_required' }}</span> <span class="help-block" ng-show="closePeriodForm.end_at.$dirty && closePeriodForm.end_at.$error.required" translate>{{ 'invoices.end_date_is_required' }}</span>
</div> </div>
</form> </form>
<div> <div>

View File

@ -1,7 +1,10 @@
# frozen_string_literal: true
# API Controller for resources of AccountingPeriod
class API::AccountingPeriodsController < API::ApiController class API::AccountingPeriodsController < API::ApiController
before_action :authenticate_user!, except: %i[index show] before_action :authenticate_user!
before_action :set_period, only: %i[show update destroy] before_action :set_period, only: %i[show]
def index def index
@accounting_periods = AccountingPeriod.all @accounting_periods = AccountingPeriod.all
@ -11,7 +14,7 @@ class API::AccountingPeriodsController < API::ApiController
def create def create
authorize AccountingPeriod authorize AccountingPeriod
@accounting_period = AccountingPeriod.new(tag_params) @accounting_period = AccountingPeriod.new(period_params)
if @accounting_period.save if @accounting_period.save
render :show, status: :created, location: @accounting_period render :show, status: :created, location: @accounting_period
else else
@ -19,6 +22,11 @@ class API::AccountingPeriodsController < API::ApiController
end end
end end
def last_closing_end
authorize AccountingPeriod
@last_period = AccountingPeriodService.find_last_period
end
private private
def set_period def set_period
@ -26,6 +34,6 @@ class API::AccountingPeriodsController < API::ApiController
end end
def period_params def period_params
params.require(:accounting_period).permit(:start_date, :end_date) params.require(:accounting_period).permit(:start_at, :end_at)
end end
end end

View File

@ -0,0 +1,10 @@
# frozen_string_literal: true
# Check the access policies for API::AccountingPeriodsController
class AccountingPeriodPolicy < ApplicationPolicy
%w[index show create last_closing_end].each do |action|
define_method "#{action}?" do
user.is_admin?
end
end
end

View File

@ -0,0 +1,9 @@
# frozen_string_literal: true
# Provides methods for accessing AccountingPeriods properties
class AccountingPeriodService
def find_last_period
AccountingPeriod.where(end_at: AccountingPeriod.select('max(end_at)')).first
end
end

View File

@ -0,0 +1,3 @@
# frozen_string_literal: true
json.extract! @last_period, :id, :end_at

View File

@ -0,0 +1,3 @@
# frozen_string_literal: true
json.extract! @accounting_period, :id, :start_at, :end_at, :closed_at, :closed_by, :created_at

View File

@ -412,6 +412,7 @@ en:
end_date: "To" end_date: "To"
closed_at: "Closed at" closed_at: "Closed at"
closed_by: "By" closed_by: "By"
confirmation_required: "Confirmation required"
members: members:
# management of users, labels, groups, and so on # management of users, labels, groups, and so on

View File

@ -412,6 +412,10 @@ fr:
end_date: "Au" end_date: "Au"
closed_at: "Clôturé le" closed_at: "Clôturé le"
closed_by: "Par" closed_by: "Par"
confirmation_required: "Confirmation requise"
confirm_close: "Êtes-vous sur de vouloir clôturer cette période comptable ? Toute modification ultérieure sera impossible."
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"
members: members:
# gestion des utilisateurs, des groupes, des étiquettes, etc. # gestion des utilisateurs, des groupes, des étiquettes, etc.

View File

@ -127,6 +127,9 @@ Rails.application.routes.draw do
end end
resources :price_categories resources :price_categories
resources :spaces resources :spaces
resources :accounting_periods do
get 'last_closing_end'
end
# i18n # i18n
# regex allows using dots in URL for 'state' # regex allows using dots in URL for 'state'