2019-01-07 15:33:09 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# API Controller for resources of AccountingPeriod
|
2019-01-07 12:47:23 +01:00
|
|
|
class API::AccountingPeriodsController < API::ApiController
|
|
|
|
|
2019-01-07 15:33:09 +01:00
|
|
|
before_action :authenticate_user!
|
|
|
|
before_action :set_period, only: %i[show]
|
2019-01-07 12:47:23 +01:00
|
|
|
|
|
|
|
def index
|
|
|
|
@accounting_periods = AccountingPeriod.all
|
|
|
|
end
|
|
|
|
|
|
|
|
def show; end
|
|
|
|
|
|
|
|
def create
|
|
|
|
authorize AccountingPeriod
|
2019-01-07 15:33:09 +01:00
|
|
|
@accounting_period = AccountingPeriod.new(period_params)
|
2019-01-07 12:47:23 +01:00
|
|
|
if @accounting_period.save
|
|
|
|
render :show, status: :created, location: @accounting_period
|
|
|
|
else
|
|
|
|
render json: @accounting_period.errors, status: :unprocessable_entity
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-01-07 15:33:09 +01:00
|
|
|
def last_closing_end
|
|
|
|
authorize AccountingPeriod
|
|
|
|
@last_period = AccountingPeriodService.find_last_period
|
|
|
|
end
|
|
|
|
|
2019-01-07 12:47:23 +01:00
|
|
|
private
|
|
|
|
|
|
|
|
def set_period
|
|
|
|
@tag = AccountingPeriod.find(params[:id])
|
|
|
|
end
|
|
|
|
|
|
|
|
def period_params
|
2019-01-07 15:33:09 +01:00
|
|
|
params.require(:accounting_period).permit(:start_at, :end_at)
|
2019-01-07 12:47:23 +01:00
|
|
|
end
|
|
|
|
end
|