export type CreateApiInvoicesArgs = {body: {issue_date?: string | undefined, due_date?: string | undefined, client_id: number, payer_id?: number | undefined, payment_method: 'cash' | 'cashless' | 'credit_card', legal_entity_id?: number | undefined, manager_id?: number | undefined, comment?: string | undefined, items?: (Array<{entity_id: number, quantity: number, price: number, discount?: ({type: 'percentage' | 'value', percentage: number, amount: number, sponsor: 'staff' | 'company'}) | undefined, warranty?: ({period: number, unit: 'days' | 'months'}) | undefined, tax_ids?: Array | undefined, comment?: string | undefined, comment_visibility?: ('public' | 'private') | undefined}>) | undefined, items_custom?: (Array<{entity: {type: 'product' | 'service', title: string, description?: string | undefined, uom_id: number}, quantity: number, price: number, comment?: string | undefined, comment_visibility?: ('private' | 'public') | undefined, discount?: ({type: 'percentage' | 'value', percentage: number, amount: number, sponsor: 'staff' | 'company'}) | undefined, warranty?: ({period: number, unit: 'days' | 'months'}) | undefined, tax_ids?: Array | undefined}>) | undefined}}; export type CreateApiInvoicesOptions = {baseUrl?: string | undefined, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; /** * Create Invoice * * POST /invoices */ export const createApiInvoices = async (args: CreateApiInvoicesArgs, options?: CreateApiInvoicesOptions) => { const {baseUrl = "https://api.roapp.io/v2", fetch: fetchFn = fetch, apiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (apiKey !== undefined) headers.set('authorization', `Bearer ${apiKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/invoices${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };