2022-11-16 15:41:08 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-11-23 17:35:39 +01:00
|
|
|
# authorized 3rd party softwares can fetch the accounting lines through the OpenAPI
|
2022-11-16 15:41:08 +01:00
|
|
|
class OpenAPI::V1::AccountingController < OpenAPI::V1::BaseController
|
|
|
|
extend OpenAPI::ApiDoc
|
|
|
|
include Rails::Pagination
|
|
|
|
expose_doc
|
|
|
|
|
|
|
|
def index
|
2022-11-23 17:35:39 +01:00
|
|
|
@lines = AccountingLine.order(date: :desc)
|
|
|
|
.includes(:invoice)
|
2022-11-16 15:41:08 +01:00
|
|
|
|
2022-11-23 17:35:39 +01:00
|
|
|
@lines = @lines.where('date >= ?', DateTime.parse(params[:after])) if params[:after].present?
|
|
|
|
@lines = @lines.where('date <= ?', DateTime.parse(params[:before])) if params[:before].present?
|
|
|
|
@lines = @lines.where(invoice_id: may_array(params[:invoice_id])) if params[:invoice_id].present?
|
2022-12-08 16:24:40 +01:00
|
|
|
@lines = @lines.where(line_type: may_array(params[:type])) if params[:type].present?
|
2022-11-16 15:41:08 +01:00
|
|
|
|
2022-11-23 17:35:39 +01:00
|
|
|
@lines = @lines.page(page).per(per_page)
|
|
|
|
paginate @lines, per_page: per_page
|
2022-11-16 15:41:08 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2022-11-23 17:35:39 +01:00
|
|
|
def page
|
|
|
|
params[:page] || 1
|
|
|
|
end
|
|
|
|
|
2022-11-16 15:41:08 +01:00
|
|
|
def per_page
|
|
|
|
params[:per_page] || 20
|
|
|
|
end
|
|
|
|
end
|