/* * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. */ import * as z from "zod/v3"; import { remap as remap$ } from "../../lib/primitives.js"; import { lazySchema as lazySchema$, safeParse } from "../../lib/schemas.js"; import * as openEnums from "../../types/enums.js"; import { OpenEnum } from "../../types/enums.js"; import { Result as SafeParseResult } from "../../types/fp.js"; import * as types from "../../types/primitives.js"; import { SDKValidationError } from "../errors/sdkvalidationerror.js"; import { BankAccount, BankAccount$inboundSchema, BankAccount$Outbound, BankAccount$outboundSchema, } from "./bankaccount.js"; import { BillLineItem, BillLineItem$inboundSchema } from "./billlineitem.js"; import { BillLineItemInput, BillLineItemInput$Outbound, BillLineItemInput$outboundSchema, } from "./billlineiteminput.js"; import { Currency, Currency$inboundSchema, Currency$outboundSchema, } from "./currency.js"; import { CustomField, CustomField$inboundSchema, CustomField$Outbound, CustomField$outboundSchema, } from "./customfield.js"; import { LinkedAttachment, LinkedAttachment$inboundSchema, LinkedAttachment$Outbound, LinkedAttachment$outboundSchema, } from "./linkedattachment.js"; import { LinkedLedgerAccount, LinkedLedgerAccount$inboundSchema, LinkedLedgerAccount$Outbound, LinkedLedgerAccount$outboundSchema, } from "./linkedledgeraccount.js"; import { LinkedPaymentAllocations, LinkedPaymentAllocations$inboundSchema, LinkedPaymentAllocations$Outbound, LinkedPaymentAllocations$outboundSchema, } from "./linkedpaymentallocations.js"; import { LinkedSubsidiary, LinkedSubsidiary$inboundSchema, } from "./linkedsubsidiary.js"; import { LinkedSubsidiaryInput, LinkedSubsidiaryInput$Outbound, LinkedSubsidiaryInput$outboundSchema, } from "./linkedsubsidiaryinput.js"; import { LinkedSupplier, LinkedSupplier$inboundSchema, } from "./linkedsupplier.js"; import { LinkedSupplierInput, LinkedSupplierInput$Outbound, LinkedSupplierInput$outboundSchema, } from "./linkedsupplierinput.js"; import { LinkedTrackingCategory, LinkedTrackingCategory$inboundSchema, LinkedTrackingCategory$Outbound, LinkedTrackingCategory$outboundSchema, } from "./linkedtrackingcategory.js"; import { PassThroughBody, PassThroughBody$inboundSchema, PassThroughBody$Outbound, PassThroughBody$outboundSchema, } from "./passthroughbody.js"; /** * Invoice status */ export const BillStatus = { Draft: "draft", Submitted: "submitted", Authorised: "authorised", PartiallyPaid: "partially_paid", Paid: "paid", Void: "void", Credit: "credit", Deleted: "deleted", Posted: "posted", } as const; /** * Invoice status */ export type BillStatus = OpenEnum; /** * Type of amortization */ export const AmortizationType = { Manual: "manual", Receipt: "receipt", Schedule: "schedule", Other: "other", } as const; /** * Type of amortization */ export type AmortizationType = OpenEnum; export type Bill = { /** * A unique identifier for an object. */ id?: string | undefined; /** * The third-party API ID of original entity */ downstreamId?: string | null | undefined; /** * Id to be displayed. */ displayId?: string | null | undefined; /** * Reference to supplier bill number */ billNumber?: string | null | undefined; /** * The supplier this entity is linked to. */ supplier?: LinkedSupplier | null | undefined; /** * The company ID the transaction belongs to */ companyId?: string | null | undefined; subsidiary?: LinkedSubsidiary | null | undefined; /** * The ID of the location */ locationId?: string | null | undefined; /** * The ID of the department */ departmentId?: string | null | undefined; /** * Indicates the associated currency for an amount of money. Values correspond to [ISO 4217](https://en.wikipedia.org/wiki/ISO_4217). */ currency?: Currency | null | undefined; /** * Currency Exchange Rate at the time entity was recorded/generated. */ currencyRate?: number | null | undefined; /** * Amounts are including tax */ taxInclusive?: boolean | null | undefined; /** * Date bill was issued - YYYY-MM-DD. */ billDate?: Date | null | undefined; /** * The due date is the date on which a payment is scheduled to be received - YYYY-MM-DD. */ dueDate?: Date | null | undefined; /** * The paid date is the date on which a payment was sent to the supplier - YYYY-MM-DD. */ paidDate?: Date | null | undefined; /** * A PO Number uniquely identifies a purchase order and is generally defined by the buyer. The buyer will match the PO number in the invoice to the Purchase Order. */ poNumber?: string | null | undefined; /** * Optional reference identifier for the transaction. */ reference?: string | null | undefined; lineItems?: Array | undefined; /** * Terms of payment. */ terms?: string | null | undefined; /** * The ID of the payment terms */ termsId?: string | null | undefined; /** * Balance of bill due. */ balance?: number | null | undefined; /** * Amount of deposit made to this bill. */ deposit?: number | null | undefined; /** * Subtotal amount, normally before tax. */ subTotal?: number | null | undefined; /** * Total tax amount applied to this transaction. */ totalTax?: number | null | undefined; /** * Total amount of bill, including tax. */ total?: number | null | undefined; /** * Applicable tax id/code override if tax is not supplied on a line item basis. */ taxCode?: string | null | undefined; notes?: string | null | undefined; /** * Invoice status */ status?: BillStatus | null | undefined; /** * Whether the bill is on payment hold. A bill on hold is not ready to pay, whatever its status. Not returned by connectors that do not report a payment hold. */ paymentHold?: boolean | null | undefined; ledgerAccount?: LinkedLedgerAccount | null | undefined; /** * Payment method used for the transaction, such as cash, credit card, bank transfer, or check */ paymentMethod?: string | null | undefined; /** * The channel through which the transaction is processed. */ channel?: string | null | undefined; /** * language code according to ISO 639-1. For the United States - EN */ language?: string | null | undefined; /** * Indicates if accounting by row is used (true) or not (false). Accounting by row means that a separate ledger transaction is created for each row. */ accountingByRow?: boolean | null | undefined; bankAccount?: BankAccount | undefined; /** * Discount percentage applied to this transaction. */ discountPercentage?: number | null | undefined; /** * Optional bill template */ templateId?: string | null | undefined; /** * The user who approved the bill */ approvedBy?: string | null | undefined; /** * Type of amortization */ amortizationType?: AmortizationType | null | undefined; /** * Method of tax calculation */ taxMethod?: string | null | undefined; /** * Whether the document has been received */ documentReceived?: boolean | null | undefined; /** * URL link to a source document - shown as 'Go to [appName]' in the downstream app. Currently only supported for Xero. */ sourceDocumentUrl?: string | null | undefined; /** * A list of linked payment allocations. */ paymentAllocations?: | Array | null | undefined; /** * A list of linked tracking categories. */ trackingCategories?: Array | null | undefined; /** * The user who last updated the object. */ updatedBy?: string | null | undefined; /** * The user who created the object. */ createdBy?: string | null | undefined; /** * The date and time when the object was last updated. */ updatedAt?: Date | null | undefined; /** * The date and time when the object was created. */ createdAt?: Date | null | undefined; /** * A binary value used to detect updates to a object and prevent data conflicts. It is incremented each time an update is made to the object. */ rowVersion?: string | null | undefined; customFields?: Array | undefined; /** * When custom mappings are configured on the resource, the result is included here. */ customMappings?: { [k: string]: any } | null | undefined; /** * The pass_through property allows passing service-specific, custom data or structured modifications in request body when creating or updating resources. */ passThrough?: Array | undefined; /** * Accounting period */ accountingPeriod?: string | null | undefined; attachments?: Array | undefined; }; export type BillInput = { /** * Id to be displayed. */ displayId?: string | null | undefined; /** * Reference to supplier bill number */ billNumber?: string | null | undefined; /** * The supplier this entity is linked to. */ supplier?: LinkedSupplierInput | null | undefined; /** * The company ID the transaction belongs to */ companyId?: string | null | undefined; subsidiary?: LinkedSubsidiaryInput | null | undefined; /** * The ID of the location */ locationId?: string | null | undefined; /** * The ID of the department */ departmentId?: string | null | undefined; /** * Indicates the associated currency for an amount of money. Values correspond to [ISO 4217](https://en.wikipedia.org/wiki/ISO_4217). */ currency?: Currency | null | undefined; /** * Currency Exchange Rate at the time entity was recorded/generated. */ currencyRate?: number | null | undefined; /** * Amounts are including tax */ taxInclusive?: boolean | null | undefined; /** * Date bill was issued - YYYY-MM-DD. */ billDate?: Date | null | undefined; /** * The due date is the date on which a payment is scheduled to be received - YYYY-MM-DD. */ dueDate?: Date | null | undefined; /** * The paid date is the date on which a payment was sent to the supplier - YYYY-MM-DD. */ paidDate?: Date | null | undefined; /** * A PO Number uniquely identifies a purchase order and is generally defined by the buyer. The buyer will match the PO number in the invoice to the Purchase Order. */ poNumber?: string | null | undefined; /** * Optional reference identifier for the transaction. */ reference?: string | null | undefined; lineItems?: Array | undefined; /** * Terms of payment. */ terms?: string | null | undefined; /** * The ID of the payment terms */ termsId?: string | null | undefined; /** * Balance of bill due. */ balance?: number | null | undefined; /** * Amount of deposit made to this bill. */ deposit?: number | null | undefined; /** * Subtotal amount, normally before tax. */ subTotal?: number | null | undefined; /** * Total tax amount applied to this transaction. */ totalTax?: number | null | undefined; /** * Total amount of bill, including tax. */ total?: number | null | undefined; /** * Applicable tax id/code override if tax is not supplied on a line item basis. */ taxCode?: string | null | undefined; notes?: string | null | undefined; /** * Invoice status */ status?: BillStatus | null | undefined; ledgerAccount?: LinkedLedgerAccount | null | undefined; /** * Payment method used for the transaction, such as cash, credit card, bank transfer, or check */ paymentMethod?: string | null | undefined; /** * The channel through which the transaction is processed. */ channel?: string | null | undefined; /** * language code according to ISO 639-1. For the United States - EN */ language?: string | null | undefined; /** * Indicates if accounting by row is used (true) or not (false). Accounting by row means that a separate ledger transaction is created for each row. */ accountingByRow?: boolean | null | undefined; bankAccount?: BankAccount | undefined; /** * Discount percentage applied to this transaction. */ discountPercentage?: number | null | undefined; /** * Optional bill template */ templateId?: string | null | undefined; /** * The user who approved the bill */ approvedBy?: string | null | undefined; /** * Type of amortization */ amortizationType?: AmortizationType | null | undefined; /** * Method of tax calculation */ taxMethod?: string | null | undefined; /** * Whether the document has been received */ documentReceived?: boolean | null | undefined; /** * URL link to a source document - shown as 'Go to [appName]' in the downstream app. Currently only supported for Xero. */ sourceDocumentUrl?: string | null | undefined; /** * A list of linked payment allocations. */ paymentAllocations?: | Array | null | undefined; /** * A list of linked tracking categories. */ trackingCategories?: Array | null | undefined; /** * A binary value used to detect updates to a object and prevent data conflicts. It is incremented each time an update is made to the object. */ rowVersion?: string | null | undefined; customFields?: Array | undefined; /** * The pass_through property allows passing service-specific, custom data or structured modifications in request body when creating or updating resources. */ passThrough?: Array | undefined; /** * Accounting period */ accountingPeriod?: string | null | undefined; attachments?: Array | undefined; }; /** @internal */ export const BillStatus$inboundSchema: z.ZodType< BillStatus, z.ZodTypeDef, unknown > = /* @__PURE__ */ lazySchema$(() => openEnums.inboundSchema(BillStatus)); /** @internal */ export const BillStatus$outboundSchema: z.ZodType< string, z.ZodTypeDef, BillStatus > = /* @__PURE__ */ lazySchema$(() => openEnums.outboundSchema(BillStatus)); /** @internal */ export const AmortizationType$inboundSchema: z.ZodType< AmortizationType, z.ZodTypeDef, unknown > = /* @__PURE__ */ lazySchema$(() => openEnums.inboundSchema(AmortizationType) ); /** @internal */ export const AmortizationType$outboundSchema: z.ZodType< string, z.ZodTypeDef, AmortizationType > = /* @__PURE__ */ lazySchema$(() => openEnums.outboundSchema(AmortizationType) ); /** @internal */ export const Bill$inboundSchema: z.ZodType = /* @__PURE__ */ lazySchema$(() => z.object({ id: types.optional(types.string()), downstream_id: z.nullable(types.string()).optional(), display_id: z.nullable(types.string()).optional(), bill_number: z.nullable(types.string()).optional(), supplier: z.nullable(LinkedSupplier$inboundSchema).optional(), company_id: z.nullable(types.string()).optional(), subsidiary: z.nullable(LinkedSubsidiary$inboundSchema).optional(), location_id: z.nullable(types.string()).optional(), department_id: z.nullable(types.string()).optional(), currency: z.nullable(Currency$inboundSchema).optional(), currency_rate: z.nullable(types.number()).optional(), tax_inclusive: z.nullable(types.boolean()).optional(), bill_date: z.nullable(types.date()).optional(), due_date: z.nullable(types.date()).optional(), paid_date: z.nullable(types.date()).optional(), po_number: z.nullable(types.string()).optional(), reference: z.nullable(types.string()).optional(), line_items: types.optional(z.array(BillLineItem$inboundSchema)), terms: z.nullable(types.string()).optional(), terms_id: z.nullable(types.string()).optional(), balance: z.nullable(types.number()).optional(), deposit: z.nullable(types.number()).optional(), sub_total: z.nullable(types.number()).optional(), total_tax: z.nullable(types.number()).optional(), total: z.nullable(types.number()).optional(), tax_code: z.nullable(types.string()).optional(), notes: z.nullable(types.string()).optional(), status: z.nullable(BillStatus$inboundSchema).optional(), payment_hold: z.nullable(types.boolean()).optional(), ledger_account: z.nullable(LinkedLedgerAccount$inboundSchema).optional(), payment_method: z.nullable(types.string()).optional(), channel: z.nullable(types.string()).optional(), language: z.nullable(types.string()).optional(), accounting_by_row: z.nullable(types.boolean()).optional(), bank_account: types.optional(BankAccount$inboundSchema), discount_percentage: z.nullable(types.number()).optional(), template_id: z.nullable(types.string()).optional(), approved_by: z.nullable(types.string()).optional(), amortization_type: z.nullable(AmortizationType$inboundSchema).optional(), tax_method: z.nullable(types.string()).optional(), document_received: z.nullable(types.boolean()).optional(), source_document_url: z.nullable(types.string()).optional(), payment_allocations: z.nullable( z.array(types.nullable(LinkedPaymentAllocations$inboundSchema)), ).optional(), tracking_categories: z.nullable( z.array(types.nullable(LinkedTrackingCategory$inboundSchema)), ).optional(), updated_by: z.nullable(types.string()).optional(), created_by: z.nullable(types.string()).optional(), updated_at: z.nullable(types.date()).optional(), created_at: z.nullable(types.date()).optional(), row_version: z.nullable(types.string()).optional(), custom_fields: types.optional(z.array(CustomField$inboundSchema)), custom_mappings: z.nullable(z.record(z.any())).optional(), pass_through: types.optional(z.array(PassThroughBody$inboundSchema)), accounting_period: z.nullable(types.string()).optional(), attachments: types.optional( z.array(types.nullable(LinkedAttachment$inboundSchema)), ), }).transform((v) => { return remap$(v, { "downstream_id": "downstreamId", "display_id": "displayId", "bill_number": "billNumber", "company_id": "companyId", "location_id": "locationId", "department_id": "departmentId", "currency_rate": "currencyRate", "tax_inclusive": "taxInclusive", "bill_date": "billDate", "due_date": "dueDate", "paid_date": "paidDate", "po_number": "poNumber", "line_items": "lineItems", "terms_id": "termsId", "sub_total": "subTotal", "total_tax": "totalTax", "tax_code": "taxCode", "payment_hold": "paymentHold", "ledger_account": "ledgerAccount", "payment_method": "paymentMethod", "accounting_by_row": "accountingByRow", "bank_account": "bankAccount", "discount_percentage": "discountPercentage", "template_id": "templateId", "approved_by": "approvedBy", "amortization_type": "amortizationType", "tax_method": "taxMethod", "document_received": "documentReceived", "source_document_url": "sourceDocumentUrl", "payment_allocations": "paymentAllocations", "tracking_categories": "trackingCategories", "updated_by": "updatedBy", "created_by": "createdBy", "updated_at": "updatedAt", "created_at": "createdAt", "row_version": "rowVersion", "custom_fields": "customFields", "custom_mappings": "customMappings", "pass_through": "passThrough", "accounting_period": "accountingPeriod", }); }) ); export function billFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => Bill$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Bill' from JSON`, ); } /** @internal */ export type BillInput$Outbound = { display_id?: string | null | undefined; bill_number?: string | null | undefined; supplier?: LinkedSupplierInput$Outbound | null | undefined; company_id?: string | null | undefined; subsidiary?: LinkedSubsidiaryInput$Outbound | null | undefined; location_id?: string | null | undefined; department_id?: string | null | undefined; currency?: string | null | undefined; currency_rate?: number | null | undefined; tax_inclusive?: boolean | null | undefined; bill_date?: string | null | undefined; due_date?: string | null | undefined; paid_date?: string | null | undefined; po_number?: string | null | undefined; reference?: string | null | undefined; line_items?: Array | undefined; terms?: string | null | undefined; terms_id?: string | null | undefined; balance?: number | null | undefined; deposit?: number | null | undefined; sub_total?: number | null | undefined; total_tax?: number | null | undefined; total?: number | null | undefined; tax_code?: string | null | undefined; notes?: string | null | undefined; status?: string | null | undefined; ledger_account?: LinkedLedgerAccount$Outbound | null | undefined; payment_method?: string | null | undefined; channel?: string | null | undefined; language?: string | null | undefined; accounting_by_row?: boolean | null | undefined; bank_account?: BankAccount$Outbound | undefined; discount_percentage?: number | null | undefined; template_id?: string | null | undefined; approved_by?: string | null | undefined; amortization_type?: string | null | undefined; tax_method?: string | null | undefined; document_received?: boolean | null | undefined; source_document_url?: string | null | undefined; payment_allocations?: | Array | null | undefined; tracking_categories?: | Array | null | undefined; row_version?: string | null | undefined; custom_fields?: Array | undefined; pass_through?: Array | undefined; accounting_period?: string | null | undefined; attachments?: Array | undefined; }; /** @internal */ export const BillInput$outboundSchema: z.ZodType< BillInput$Outbound, z.ZodTypeDef, BillInput > = /* @__PURE__ */ lazySchema$(() => z.object({ displayId: z.nullable(z.string()).optional(), billNumber: z.nullable(z.string()).optional(), supplier: z.nullable(LinkedSupplierInput$outboundSchema).optional(), companyId: z.nullable(z.string()).optional(), subsidiary: z.nullable(LinkedSubsidiaryInput$outboundSchema).optional(), locationId: z.nullable(z.string()).optional(), departmentId: z.nullable(z.string()).optional(), currency: z.nullable(Currency$outboundSchema).optional(), currencyRate: z.nullable(z.number()).optional(), taxInclusive: z.nullable(z.boolean()).optional(), billDate: z.nullable( z.date().transform(v => v.toISOString().slice(0, "YYYY-MM-DD".length)), ).optional(), dueDate: z.nullable( z.date().transform(v => v.toISOString().slice(0, "YYYY-MM-DD".length)), ).optional(), paidDate: z.nullable( z.date().transform(v => v.toISOString().slice(0, "YYYY-MM-DD".length)), ).optional(), poNumber: z.nullable(z.string()).optional(), reference: z.nullable(z.string()).optional(), lineItems: z.array(BillLineItemInput$outboundSchema).optional(), terms: z.nullable(z.string()).optional(), termsId: z.nullable(z.string()).optional(), balance: z.nullable(z.number()).optional(), deposit: z.nullable(z.number()).optional(), subTotal: z.nullable(z.number()).optional(), totalTax: z.nullable(z.number()).optional(), total: z.nullable(z.number()).optional(), taxCode: z.nullable(z.string()).optional(), notes: z.nullable(z.string()).optional(), status: z.nullable(BillStatus$outboundSchema).optional(), ledgerAccount: z.nullable(LinkedLedgerAccount$outboundSchema).optional(), paymentMethod: z.nullable(z.string()).optional(), channel: z.nullable(z.string()).optional(), language: z.nullable(z.string()).optional(), accountingByRow: z.nullable(z.boolean()).optional(), bankAccount: BankAccount$outboundSchema.optional(), discountPercentage: z.nullable(z.number()).optional(), templateId: z.nullable(z.string()).optional(), approvedBy: z.nullable(z.string()).optional(), amortizationType: z.nullable(AmortizationType$outboundSchema).optional(), taxMethod: z.nullable(z.string()).optional(), documentReceived: z.nullable(z.boolean()).optional(), sourceDocumentUrl: z.nullable(z.string()).optional(), paymentAllocations: z.nullable( z.array(z.nullable(LinkedPaymentAllocations$outboundSchema)), ).optional(), trackingCategories: z.nullable( z.array(z.nullable(LinkedTrackingCategory$outboundSchema)), ).optional(), rowVersion: z.nullable(z.string()).optional(), customFields: z.array(CustomField$outboundSchema).optional(), passThrough: z.array(PassThroughBody$outboundSchema).optional(), accountingPeriod: z.nullable(z.string()).optional(), attachments: z.array(z.nullable(LinkedAttachment$outboundSchema)) .optional(), }).transform((v) => { return remap$(v, { displayId: "display_id", billNumber: "bill_number", companyId: "company_id", locationId: "location_id", departmentId: "department_id", currencyRate: "currency_rate", taxInclusive: "tax_inclusive", billDate: "bill_date", dueDate: "due_date", paidDate: "paid_date", poNumber: "po_number", lineItems: "line_items", termsId: "terms_id", subTotal: "sub_total", totalTax: "total_tax", taxCode: "tax_code", ledgerAccount: "ledger_account", paymentMethod: "payment_method", accountingByRow: "accounting_by_row", bankAccount: "bank_account", discountPercentage: "discount_percentage", templateId: "template_id", approvedBy: "approved_by", amortizationType: "amortization_type", taxMethod: "tax_method", documentReceived: "document_received", sourceDocumentUrl: "source_document_url", paymentAllocations: "payment_allocations", trackingCategories: "tracking_categories", rowVersion: "row_version", customFields: "custom_fields", passThrough: "pass_through", accountingPeriod: "accounting_period", }); }) ); export function billInputToJSON(billInput: BillInput): string { return JSON.stringify(BillInput$outboundSchema.parse(billInput)); }