export type GetApiInvoicesArgs = {account_id?: number | undefined, account_name?: string | undefined, account_number?: number | undefined, balance_due: unknown, invoice_date?: string | undefined, due_on?: string | undefined, invoice_number?: string | undefined, non_taxable: unknown, organization_id?: string | undefined, payment_made: unknown, status?: string | undefined, sub_total: unknown, sub_total_after_discount: unknown, total: unknown, total_discount: unknown, total_tax: unknown, voucher_header_id?: number | undefined, modified_on?: string | undefined, filters?: Record | undefined, 'sort[asc]'?: ('balance_due' | 'invoice_date' | 'invoice_number' | 'payment_made' | 'total') | undefined, 'sort[desc]'?: ('balance_due' | 'invoice_date' | 'invoice_number' | 'payment_made' | 'total') | undefined, page?: number | undefined, per_page?: number | undefined}; export type GetApiInvoicesOptions = {baseUrl?: string | undefined, passport?: string | undefined, fetch?: typeof fetch | undefined}; /** * List invoices * * GET /invoices */ export const getApiInvoices = async (args: GetApiInvoicesArgs, options?: GetApiInvoicesOptions) => { const {baseUrl = "http://localhost/app4legal/api/v2/money", fetch: fetchFn = fetch, passport} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.account_id != null) query.append("account_id", String(args.account_id)) if (args.account_name != null) query.append("account_name", String(args.account_name)) if (args.account_number != null) query.append("account_number", String(args.account_number)) if (args.balance_due != null) query.append("balance_due", String(args.balance_due)) if (args.invoice_date != null) query.append("invoice_date", String(args.invoice_date)) if (args.due_on != null) query.append("due_on", String(args.due_on)) if (args.invoice_number != null) query.append("invoice_number", String(args.invoice_number)) if (args.non_taxable != null) query.append("non_taxable", String(args.non_taxable)) if (args.organization_id != null) query.append("organization_id", String(args.organization_id)) if (args.payment_made != null) query.append("payment_made", String(args.payment_made)) if (args.status != null) query.append("status", String(args.status)) if (args.sub_total != null) query.append("sub_total", String(args.sub_total)) if (args.sub_total_after_discount != null) query.append("sub_total_after_discount", String(args.sub_total_after_discount)) if (args.total != null) query.append("total", String(args.total)) if (args.total_discount != null) query.append("total_discount", String(args.total_discount)) if (args.total_tax != null) query.append("total_tax", String(args.total_tax)) if (args.voucher_header_id != null) query.append("voucher_header_id", String(args.voucher_header_id)) if (args.modified_on != null) query.append("modified_on", String(args.modified_on)) if (args.filters != null) query.append("filters", JSON.stringify(args.filters)) if (args['sort[asc]'] != null) query.append("sort[asc]", String(args['sort[asc]'])) if (args['sort[desc]'] != null) query.append("sort[desc]", String(args['sort[desc]'])) if (args.page != null) query.append("page", String(args.page)) if (args.per_page != null) query.append("per_page", String(args.per_page)) if (passport !== undefined) headers.set('authorization', `Bearer ${passport}`) const url = `${baseUrl.replace(/\/+$/, '')}/invoices${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };