2022-11-16 15:41:08 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2023-03-06 16:35:50 +01:00
|
|
|
require_relative 'concerns/accountings_filters_concern'
|
|
|
|
|
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
|
2023-02-24 17:26:55 +01:00
|
|
|
extend OpenAPI::APIDoc
|
2022-11-16 15:41:08 +01:00
|
|
|
include Rails::Pagination
|
2023-02-24 17:26:55 +01:00
|
|
|
include OpenAPI::V1::Concerns::AccountingsFiltersConcern
|
2022-11-16 15:41:08 +01:00
|
|
|
expose_doc
|
|
|
|
|
|
|
|
def index
|
2022-12-09 12:28:13 +01:00
|
|
|
@codes = {
|
2022-12-12 11:10:06 +01:00
|
|
|
card: Setting.get('accounting_payment_card_code'),
|
|
|
|
wallet: Setting.get('accounting_payment_wallet_code'),
|
|
|
|
other: Setting.get('accounting_payment_other_code')
|
2022-12-09 12:28:13 +01:00
|
|
|
}
|
|
|
|
|
2022-11-23 17:35:39 +01:00
|
|
|
@lines = AccountingLine.order(date: :desc)
|
2022-12-09 12:28:13 +01:00
|
|
|
.includes(:invoicing_profile, invoice: :payment_gateway_object)
|
2022-11-16 15:41:08 +01:00
|
|
|
|
2023-03-06 16:35:50 +01:00
|
|
|
@lines = filter_by_after(@lines, params)
|
|
|
|
@lines = filter_by_before(@lines, params)
|
|
|
|
@lines = filter_by_invoice(@lines, params)
|
|
|
|
@lines = filter_by_line_type(@lines, params)
|
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
|