2021-06-24 12:36:16 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2021-02-01 17:43:15 +01:00
|
|
|
# OpenAPI controller for the invoices
|
2016-05-04 18:17:50 +02:00
|
|
|
class OpenAPI::V1::InvoicesController < OpenAPI::V1::BaseController
|
2023-02-24 17:26:55 +01:00
|
|
|
extend OpenAPI::APIDoc
|
2021-06-24 12:36:16 +02:00
|
|
|
include Rails::Pagination
|
2016-05-05 15:02:02 +02:00
|
|
|
expose_doc
|
|
|
|
|
2016-05-04 18:17:50 +02:00
|
|
|
def index
|
|
|
|
@invoices = Invoice.order(created_at: :desc)
|
2023-03-03 10:09:07 +01:00
|
|
|
.includes(:payment_gateway_object, :invoicing_profile)
|
2021-06-24 12:36:16 +02:00
|
|
|
.references(:invoicing_profiles)
|
2016-05-04 18:17:50 +02:00
|
|
|
|
2022-11-23 17:35:39 +01:00
|
|
|
@invoices = @invoices.where(invoicing_profiles: { user_id: may_array(params[:user_id]) }) if params[:user_id].present?
|
2016-05-04 18:17:50 +02:00
|
|
|
|
2021-02-01 17:43:15 +01:00
|
|
|
@invoices = @invoices.page(params[:page]).per(per_page)
|
|
|
|
paginate @invoices, per_page: per_page
|
2016-05-04 18:17:50 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def download
|
|
|
|
@invoice = Invoice.find(params[:id])
|
2022-11-23 17:35:39 +01:00
|
|
|
send_file Rails.root.join(@invoice.file), type: 'application/pdf', disposition: 'inline', filename: @invoice.filename
|
2016-05-04 18:17:50 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
2021-02-01 17:43:15 +01:00
|
|
|
|
|
|
|
def per_page
|
|
|
|
params[:per_page] || 20
|
|
|
|
end
|
2016-05-04 18:17:50 +02:00
|
|
|
end
|