From 105bcf623615e4eb168654936299fbf1b611d61f Mon Sep 17 00:00:00 2001 From: Sylvain Date: Thu, 3 Jan 2019 16:48:52 +0100 Subject: [PATCH] [ongoing] interface to close an accounting period --- .../controllers/admin/invoices.js.erb | 61 ++++++++++++++++++- .../admin/invoices/closePeriodModal.html.erb | 45 ++++++++++++++ .../templates/admin/invoices/index.html.erb | 6 +- 3 files changed, 108 insertions(+), 4 deletions(-) create mode 100644 app/assets/templates/admin/invoices/closePeriodModal.html.erb diff --git a/app/assets/javascripts/controllers/admin/invoices.js.erb b/app/assets/javascripts/controllers/admin/invoices.js.erb index bbef9d26a..8724466d4 100644 --- a/app/assets/javascripts/controllers/admin/invoices.js.erb +++ b/app/assets/javascripts/controllers/admin/invoices.js.erb @@ -105,7 +105,7 @@ Application.Controllers.controller('InvoicesController', ['$scope', '$state', 'I * @param invoice {Object} invoice inherited from angular's $resource */ $scope.generateAvoirForInvoice = function (invoice) { - // open modal + // open modal const modalInstance = $uibModal.open({ templateUrl: '<%= asset_path "admin/invoices/avoirModal.html" %>', controller: 'AvoirModalController', @@ -387,6 +387,14 @@ Application.Controllers.controller('InvoicesController', ['$scope', '$state', 'I return invoiceSearch(true); }; + $scope.closeAnAccountingPeriod = function() { + // open modal + $uibModal.open({ + templateUrl: '<%= asset_path "admin/invoices/closePeriodModal.html" %>', + controller: 'ClosePeriodModalController' + }); + } + /* PRIVATE SCOPE */ /** @@ -542,7 +550,7 @@ Application.Controllers.controller('AvoirModalController', ['$scope', '$uibModal $scope.openDatePicker = function ($event) { $event.preventDefault(); $event.stopPropagation(); - return $scope.datePicker.opened = true; + $scope.datePicker.opened = true; }; /** @@ -571,7 +579,7 @@ Application.Controllers.controller('AvoirModalController', ['$scope', '$uibModal } }; - /**q + /** * Cancel the refund, dismiss the modal window */ $scope.cancel = function () { $uibModalInstance.dismiss('cancel'); }; @@ -600,3 +608,50 @@ Application.Controllers.controller('AvoirModalController', ['$scope', '$uibModal return initialize(); } ]); + + +/** + * Controller used in the modal window allowing an admin to close an accounting period + */ +Application.Controllers.controller('ClosePeriodModalController', ['$scope', '$uibModalInstance', 'Invoice', 'growl', '_t', + function ($scope, $uibModalInstance, Invoice, growl, _t) { + /* PUBLIC SCOPE */ + $scope.period = { + start_date: null, + end_date: null + }; + + // AngularUI-Bootstrap datepickers parameters to define the period to close + $scope.datePicker = { + format: Fablab.uibDateFormat, + // default: datePicker are not shown + startOpened: false, + endOpened: false, + options: { + startingDay: Fablab.weekStartingDay + } + }; + + /** + * Callback to open the datepicker + */ + $scope.openDatePicker = function ($event, pickedId) { + $event.preventDefault(); + $event.stopPropagation(); + $scope.datePicker[`${pickedId}Opened`] = true; + }; + + /** + * Validate the refunding and generate a refund invoice + */ + $scope.ok = function () { + $uibModalInstance.close({ period: $scope.period }); + growl.info(_t('not_implemented_yet')); + }; + + /** + * Cancel the refund, dismiss the modal window + */ + $scope.cancel = function () { $uibModalInstance.dismiss('cancel'); }; + } +]); diff --git a/app/assets/templates/admin/invoices/closePeriodModal.html.erb b/app/assets/templates/admin/invoices/closePeriodModal.html.erb new file mode 100644 index 000000000..8b36a29ad --- /dev/null +++ b/app/assets/templates/admin/invoices/closePeriodModal.html.erb @@ -0,0 +1,45 @@ + + + diff --git a/app/assets/templates/admin/invoices/index.html.erb b/app/assets/templates/admin/invoices/index.html.erb index a421d2286..f4b4984b6 100644 --- a/app/assets/templates/admin/invoices/index.html.erb +++ b/app/assets/templates/admin/invoices/index.html.erb @@ -10,7 +10,11 @@

{{ 'invoices' }}

- +
+
+ +
+