diff --git a/app/assets/javascripts/controllers/admin/invoices.js.erb b/app/assets/javascripts/controllers/admin/invoices.js.erb index c0adeafbb..0cbecd94a 100644 --- a/app/assets/javascripts/controllers/admin/invoices.js.erb +++ b/app/assets/javascripts/controllers/admin/invoices.js.erb @@ -392,7 +392,10 @@ Application.Controllers.controller('InvoicesController', ['$scope', '$state', 'I $uibModal.open({ templateUrl: '<%= asset_path "admin/invoices/closePeriodModal.html" %>', 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 */ -Application.Controllers.controller('ClosePeriodModalController', ['$scope', '$uibModalInstance', 'Invoice', 'AccountingPeriod', 'growl', '_t', - function ($scope, $uibModalInstance, Invoice, AccountingPeriod, growl, _t) { +Application.Controllers.controller('ClosePeriodModalController', ['$scope', '$uibModalInstance', 'Invoice', 'AccountingPeriod', 'dialogs', 'growl', '_t', + function ($scope, $uibModalInstance, Invoice, AccountingPeriod, dialogs, growl, _t) { /* PUBLIC SCOPE */ $scope.period = { - start_date: null, - end_date: null + start_at: null, + end_at: null }; // 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 () { - $uibModalInstance.close({ period: $scope.period }); - growl.info(_t('not_implemented_yet')); + dialogs.confirm( + { + 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); + }); + } + ); + }; /** diff --git a/app/assets/javascripts/services/accounting_period.js b/app/assets/javascripts/services/accounting_period.js index b5a92433b..9ffb9e03a 100644 --- a/app/assets/javascripts/services/accounting_period.js +++ b/app/assets/javascripts/services/accounting_period.js @@ -1,11 +1,11 @@ 'use strict'; Application.Services.factory('AccountingPeriod', ['$resource', function ($resource) { - return $resource('/api/accounting_period/:id', + return $resource('/api/accounting_periods/:id', { id: '@id' }, { lastClosingEnd: { method: 'GET', - url: '/api/accounting_period/last_closing_end' + url: '/api/accounting_periods/last_closing_end' } } ); diff --git a/app/assets/templates/admin/invoices/closePeriodModal.html.erb b/app/assets/templates/admin/invoices/closePeriodModal.html.erb index 186a6dbca..7a48adbbc 100644 --- a/app/assets/templates/admin/invoices/closePeriodModal.html.erb +++ b/app/assets/templates/admin/invoices/closePeriodModal.html.erb @@ -3,14 +3,14 @@