import {z} from 'zod' export type AmortizationSchedule = {id?: number | undefined, amortization?: number | undefined, accounting_amortization?: number | undefined, journal_entry_order: string, date: string, amount: number, posted?: boolean | undefined, customer: number, transaction?: (number | null) | undefined, bill_line?: (number | null) | undefined, debit_memo_line?: (number | null) | undefined, journal_entry?: (number | null) | undefined}; export type AccountingBillLine = {id: number, bill?: number | undefined, account_number: string, account_name: string | null, department_name: string, department_code: string, bill_customer_name: string, tags: Array<{[key: string]: unknown}>, amortization_schedule: Array, tax_rate_name: string, tax_rate_value: number, description?: (string | null) | undefined, amount?: number | undefined, tax?: number | undefined, tax_description?: (string | null) | undefined, tag_ids?: Array | undefined, tag_group_ids?: Array | undefined, source?: (string | null) | undefined, source_id?: (string | null) | undefined, currency?: string | undefined, created_at: string, last_modified_at: string, customer: number, account: number, tax_rate?: (number | null) | undefined, bill_customer?: (number | null) | undefined, department?: (number | null) | undefined}; export type AccountingBillPayment = {id: number, payment_transaction_bank_description: string, payment_journal_entry_order: string, voided_journal_entry_order: string, withheld_amount: number | null, currency?: string | undefined, amount?: number | undefined, payment_date?: (string | null) | undefined, source?: (string | null) | undefined, source_id?: (string | null) | undefined, created_at: string, voided_date?: (string | null) | undefined, last_modified_at: string, customer: number, bill: number, payment_journal_entry: number, payment_transaction?: (number | null) | undefined, voided_journal_entry?: (number | null) | undefined}; export type File = {id: number, customer: number, created_at: string, created_by: number | null, created_by_name: string, created_by_email: string, last_modified_at: string, name: string, url: string, s3_content_type?: (string | null) | undefined, s3_content_length?: (number | null) | undefined, s3_path: string, object_id?: (number | null) | undefined, app: string, model: string, is_deleted: boolean, deleted_at: string | null}; export type TermsEnum = 'custom' | 'net_5' | 'net_7' | 'net_10' | 'net_15' | 'net_20' | 'net_30' | 'net_40' | 'net_45' | 'net_60' | 'net_90' | 'net_105' | 'net_120' | 'due_on_receipt'; export type BlankEnum = ''; export type NullEnum = unknown; export type ItaBillTypeEnum = 'other' | 'equipment'; export type AccountingBillPaymentStatusEnum = 'partial' | 'open' | 'paid' | 'payment_not_found' | 'payment_pending' | 'voided'; export type TaxBehaviorEnum = 'inclusive' | 'exclusive'; export type BillTypeEnum = 'BILL' | 'PAYROLL' | 'REIMBURSEMENT'; export type PatchedAccountingBill = {id?: number | undefined, lines?: Array | undefined, payments?: Array | undefined, payment_journal_entries?: Array | undefined, status?: string | undefined, past_due_days?: (number | null) | undefined, entity_name?: string | undefined, entity_currency?: string | undefined, vendor_name?: string | undefined, ap_account_name?: (string | null) | undefined, attachments?: Array | undefined, total_amount?: number | undefined, amount_due?: number | undefined, amount_paid?: number | undefined, item_date?: (string | null) | undefined, migrated_journal_id?: (number | null) | undefined, voided_date?: string | undefined, voided_journal_entry_order?: string | undefined, amortizations?: string | undefined, last_modified_at?: string | undefined, ramp_use_sandbox?: string | undefined, navan_region?: (string | null) | undefined, zip_metadata?: string | undefined, is_deleted?: boolean | undefined, deleted_at?: (string | null) | undefined, payment_term_name?: string | undefined, chat_uuid?: string | undefined, withholding_info?: ({[key: string]: unknown} | null) | undefined, search_vector?: (string | null) | undefined, search_text?: (string | null) | undefined, mailing_address?: (string | null) | undefined, terms?: (TermsEnum | BlankEnum | NullEnum | null) | undefined, bill_number?: string | undefined, bill_date?: string | undefined, due_date?: string | undefined, paid_date?: (string | null) | undefined, message_on_bill?: (string | null) | undefined, ita_allocation_number?: (string | null) | undefined, ita_bill_type?: (ItaBillTypeEnum | BlankEnum | NullEnum | null) | undefined, source_id?: (string | null) | undefined, source?: (string | null) | undefined, source_bill_data: unknown, external_ramp_id?: (string | null) | undefined, payment_status?: (AccountingBillPaymentStatusEnum | BlankEnum | NullEnum | null) | undefined, currency?: string | undefined, exchange_rate?: (number | null) | undefined, exchange_rate_book?: (number | null) | undefined, created_at?: string | undefined, tax_behavior?: (TaxBehaviorEnum | BlankEnum | NullEnum | null) | undefined, bill_type?: BillTypeEnum | undefined, chat_id?: (number | null) | undefined, customer?: number | undefined, entity?: number | undefined, vendor?: (number | null) | undefined, payment_term?: (number | null) | undefined, journal_entry?: (number | null) | undefined, source_file?: (number | null) | undefined, tax_rate?: (number | null) | undefined, ap_account?: (number | null) | undefined, voided_journal_entry?: (number | null) | undefined}; export type PatchApiCoaApiV1BillIdArgs = {id: string, body: PatchedAccountingBill}; export type PatchApiCoaApiV1BillIdOptions = {baseUrl?: string | undefined, knoxApiToken?: string | undefined, fetch?: typeof fetch | undefined}; export const amortizationSchedule = z.object({id: z.number().int().optional(), amortization: z.number().int().optional(), accounting_amortization: z.number().int().optional(), journal_entry_order: z.string(), date: z.string(), amount: z.number().gt(-1000000000000000000).lt(1000000000000000000), posted: z.boolean().optional(), customer: z.number().int(), transaction: z.number().int().nullable().optional(), bill_line: z.number().int().nullable().optional(), debit_memo_line: z.number().int().nullable().optional(), journal_entry: z.number().int().nullable().optional()}); export const accountingBillLine = z.object({id: z.number().int(), bill: z.number().int().optional(), account_number: z.string(), account_name: z.string().nullable(), department_name: z.string(), department_code: z.string(), bill_customer_name: z.string(), tags: z.array(z.record(z.string(), z.unknown())), amortization_schedule: z.array(amortizationSchedule), tax_rate_name: z.string(), tax_rate_value: z.number().gt(-1000000).lt(1000000), description: z.string().nullable().optional(), amount: z.number().gt(-1000000000000000000).lt(1000000000000000000).optional(), tax: z.number().gt(-1000000000000000000).lt(1000000000000000000).optional(), tax_description: z.string().max(250).nullable().optional(), tag_ids: z.array(z.number().int().gte(-9223372036854776000).lte(9223372036854776000)).optional(), tag_group_ids: z.array(z.number().int().gte(-9223372036854776000).lte(9223372036854776000)).optional(), source: z.string().max(250).nullable().optional(), source_id: z.string().nullable().optional(), currency: z.string().max(3).optional(), created_at: z.string(), last_modified_at: z.string(), customer: z.number().int(), account: z.number().int(), tax_rate: z.number().int().nullable().optional(), bill_customer: z.number().int().nullable().optional(), department: z.number().int().nullable().optional()}); export const accountingBillPayment = z.object({id: z.number().int(), payment_transaction_bank_description: z.string(), payment_journal_entry_order: z.string(), voided_journal_entry_order: z.string(), withheld_amount: z.number().nullable(), currency: z.string().max(3).optional(), amount: z.number().gt(-1000000000000000000).lt(1000000000000000000).optional(), payment_date: z.string().nullable().optional(), source: z.string().max(250).nullable().optional(), source_id: z.string().nullable().optional(), created_at: z.string(), voided_date: z.string().nullable().optional(), last_modified_at: z.string(), customer: z.number().int(), bill: z.number().int(), payment_journal_entry: z.number().int(), payment_transaction: z.number().int().nullable().optional(), voided_journal_entry: z.number().int().nullable().optional()}); export const file = z.object({id: z.number().int(), customer: z.number().int(), created_at: z.string(), created_by: z.number().int().nullable(), created_by_name: z.string(), created_by_email: z.string(), last_modified_at: z.string(), name: z.string(), url: z.string(), s3_content_type: z.string().nullable().optional(), s3_content_length: z.number().int().gte(0).lte(2147483647).nullable().optional(), s3_path: z.string(), object_id: z.number().int().gte(0).lte(2147483647).nullable().optional(), app: z.string(), model: z.string(), is_deleted: z.boolean(), deleted_at: z.string().nullable()}); export const termsEnum = z.enum(["custom", "net_5", "net_7", "net_10", "net_15", "net_20", "net_30", "net_40", "net_45", "net_60", "net_90", "net_105", "net_120", "due_on_receipt"]); export const blankEnum = z.literal(""); export const nullEnum = z.unknown(); export const itaBillTypeEnum = z.enum(["other", "equipment"]); export const accountingBillPaymentStatusEnum = z.enum(["partial", "open", "paid", "payment_not_found", "payment_pending", "voided"]); export const taxBehaviorEnum = z.enum(["inclusive", "exclusive"]); export const billTypeEnum = z.enum(["BILL", "PAYROLL", "REIMBURSEMENT"]); export const accountingBill = z.object({id: z.number().int(), lines: z.array(accountingBillLine), payments: z.array(accountingBillPayment), payment_journal_entries: z.array(z.number().int()), status: z.string(), past_due_days: z.number().int().nullable(), entity_name: z.string(), entity_currency: z.string(), vendor_name: z.string(), ap_account_name: z.string().nullable(), attachments: z.array(file), total_amount: z.number().gt(-1000000000000000000).lt(1000000000000000000), amount_due: z.number(), amount_paid: z.number().gt(-1000000000000000000).lt(1000000000000000000), item_date: z.string().nullable().optional(), migrated_journal_id: z.number().int().nullable().optional(), voided_date: z.string(), voided_journal_entry_order: z.string(), amortizations: z.string(), last_modified_at: z.string(), ramp_use_sandbox: z.string(), navan_region: z.string().nullable(), zip_metadata: z.string(), is_deleted: z.boolean(), deleted_at: z.string().nullable(), payment_term_name: z.string(), chat_uuid: z.string().optional(), withholding_info: z.record(z.string(), z.unknown()).nullable(), search_vector: z.string().nullable(), search_text: z.string().nullable(), mailing_address: z.string().nullable().optional(), terms: z.union([termsEnum, blankEnum, nullEnum]).nullable().optional(), bill_number: z.string().max(120), bill_date: z.string(), due_date: z.string(), paid_date: z.string().nullable().optional(), message_on_bill: z.string().nullable().optional(), ita_allocation_number: z.string().max(9).nullable().optional(), ita_bill_type: z.union([itaBillTypeEnum, blankEnum, nullEnum]).nullable().optional(), source_id: z.string().nullable().optional(), source: z.string().max(250).nullable().optional(), source_bill_data: z.unknown(), external_ramp_id: z.string().nullable().optional(), payment_status: z.union([accountingBillPaymentStatusEnum, blankEnum, nullEnum]).nullable().optional(), currency: z.string().max(3).optional(), exchange_rate: z.number().gt(-100000000000000).lt(100000000000000).nullable().optional(), exchange_rate_book: z.number().gt(-100000000000000).lt(100000000000000).nullable().optional(), created_at: z.string(), tax_behavior: z.union([taxBehaviorEnum, blankEnum, nullEnum]).nullable().optional(), bill_type: billTypeEnum.optional(), chat_id: z.number().int().gte(-2147483648).lte(2147483647).nullable().optional(), customer: z.number().int(), entity: z.number().int(), vendor: z.number().int().nullable(), payment_term: z.number().int().nullable().optional(), journal_entry: z.number().int().nullable().optional(), source_file: z.number().int().nullable().optional(), tax_rate: z.number().int().nullable().optional(), ap_account: z.number().int().nullable().optional(), voided_journal_entry: z.number().int().nullable().optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Partial Update Accounting Bill * * PATCH /coa/api/v1/bill/{id}/ */ export const patchApiCoaApiV1BillId = async (args: PatchApiCoaApiV1BillIdArgs, options?: PatchApiCoaApiV1BillIdOptions) => { const {baseUrl = "https://api.meetcampfire.com", fetch: fetchFn = fetch, knoxApiToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (knoxApiToken !== undefined) headers.set("Authorization", knoxApiToken) const url = `${baseUrl.replace(/\/+$/, '')}/coa/api/v1/bill/${encodeURIComponent(String(args.id))}/${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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 validateResponse(accountingBill, await res.json()) };