diff --git a/app/assets/javascripts/controllers/admin/invoices.js.erb b/app/assets/javascripts/controllers/admin/invoices.js.erb index a7f0c62cd..c0adeafbb 100644 --- a/app/assets/javascripts/controllers/admin/invoices.js.erb +++ b/app/assets/javascripts/controllers/admin/invoices.js.erb @@ -614,8 +614,8 @@ 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', 'growl', '_t', - function ($scope, $uibModalInstance, Invoice, growl, _t) { +Application.Controllers.controller('ClosePeriodModalController', ['$scope', '$uibModalInstance', 'Invoice', 'AccountingPeriod', 'growl', '_t', + function ($scope, $uibModalInstance, Invoice, AccountingPeriod, growl, _t) { /* PUBLIC SCOPE */ $scope.period = { start_date: null, @@ -636,10 +636,10 @@ Application.Controllers.controller('ClosePeriodModalController', ['$scope', '$ui /** * Callback to open the datepicker */ - $scope.openDatePicker = function ($event, pickedId) { + $scope.openDatePicker = function ($event, pickerId) { $event.preventDefault(); $event.stopPropagation(); - $scope.datePicker[`${pickedId}Opened`] = true; + $scope.datePicker[`${pickerId}Opened`] = true; }; /** diff --git a/app/controllers/api/accounting_periods_controller.rb b/app/controllers/api/accounting_periods_controller.rb new file mode 100644 index 000000000..2635047d5 --- /dev/null +++ b/app/controllers/api/accounting_periods_controller.rb @@ -0,0 +1,31 @@ +class API::AccountingPeriodsController < API::ApiController + + before_action :authenticate_user!, except: %i[index show] + before_action :set_period, only: %i[show update destroy] + + def index + @accounting_periods = AccountingPeriod.all + end + + def show; end + + def create + authorize AccountingPeriod + @accounting_period = AccountingPeriod.new(tag_params) + if @accounting_period.save + render :show, status: :created, location: @accounting_period + else + render json: @accounting_period.errors, status: :unprocessable_entity + end + end + + private + + def set_period + @tag = AccountingPeriod.find(params[:id]) + end + + def period_params + params.require(:accounting_period).permit(:start_date, :end_date) + end +end