export type OrderLine = {lineId?: number | undefined, description: string, netPrice?: number | undefined, vat?: number | undefined, account?: string | undefined, vatType: string, netPriceInCurrency?: number | undefined, vatInCurrency?: number | undefined, projectId?: number | undefined}; export type PurchaseRequest = {transactionId?: number | undefined, identifier?: string | undefined, date: string, dueDate?: string | undefined, kind: 'cash_purchase' | 'supplier', lines: Array, supplierId?: number | undefined, currency: string, paymentAccount?: string | undefined, paymentDate?: string | undefined, paymentAmountInNok?: number | undefined, kid?: string | undefined, projectId?: number | undefined}; export type CreateApiCompaniesCompanySlugPurchasesArgs = {body: PurchaseRequest}; export type CreateApiCompaniesCompanySlugPurchasesOptions = {baseUrl?: string | undefined, fikenApiOauth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Creates a new purchase. * * POST /companies/{companySlug}/purchases */ export const createApiCompaniesCompanySlugPurchases = async (args: CreateApiCompaniesCompanySlugPurchasesArgs, options?: CreateApiCompaniesCompanySlugPurchasesOptions) => { const {baseUrl = "https://api.fiken.no/api/v2", fetch: fetchFn = fetch, fikenApiOauth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (fikenApiOauth !== undefined) headers.set('authorization', `Bearer ${fikenApiOauth}`) const url = `${baseUrl.replace(/\/+$/, '')}/companies/${encodeURIComponent(String(args.companySlug))}/purchases${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 };