/* * 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 { Address, Address$inboundSchema, Address$Outbound, Address$outboundSchema, } from "./address.js"; import { BankAccount, BankAccount$inboundSchema, BankAccount$Outbound, BankAccount$outboundSchema, } from "./bankaccount.js"; import { Currency, Currency$inboundSchema, Currency$outboundSchema, } from "./currency.js"; import { CustomField, CustomField$inboundSchema, CustomField$Outbound, CustomField$outboundSchema, } from "./customfield.js"; import { InvoiceLineItem, InvoiceLineItem$inboundSchema, InvoiceLineItemInput, InvoiceLineItemInput$Outbound, InvoiceLineItemInput$outboundSchema, } from "./invoicelineitem.js"; import { LinkedLedgerAccount, LinkedLedgerAccount$inboundSchema, LinkedLedgerAccount$Outbound, LinkedLedgerAccount$outboundSchema, } from "./linkedledgeraccount.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"; export const PurchaseOrderStatus = { Draft: "draft", Open: "open", Closed: "closed", Deleted: "deleted", Billed: "billed", Other: "other", } as const; export type PurchaseOrderStatus = OpenEnum; /** * Type of amortization */ export const PurchaseOrderAmortizationType = { Manual: "manual", Receipt: "receipt", Schedule: "schedule", Other: "other", } as const; /** * Type of amortization */ export type PurchaseOrderAmortizationType = OpenEnum< typeof PurchaseOrderAmortizationType >; export type PurchaseOrder = { /** * A unique identifier for an object. */ id?: string | undefined; /** * The third-party API ID of original entity */ downstreamId?: string | null | undefined; /** * Display ID of the purchase order */ displayId?: string | null | undefined; /** * A PO Number uniquely identifies a purchase order and is generally defined by the buyer. */ poNumber?: string | null | undefined; /** * Optional purchase order reference. */ reference?: string | null | undefined; /** * The supplier this entity is linked to. */ supplier?: LinkedSupplier | null | undefined; /** * The ID of the subsidiary */ subsidiaryId?: string | null | undefined; /** * The company ID the transaction belongs to */ companyId?: string | null | undefined; /** * The ID of the location */ locationId?: string | null | undefined; /** * The ID of the department */ departmentId?: string | null | undefined; status?: PurchaseOrderStatus | null | undefined; /** * Date purchase order was issued - YYYY-MM-DD. */ issuedDate?: Date | null | undefined; /** * The date on which the purchase order is to be delivered - YYYY-MM-DD. */ deliveryDate?: Date | null | undefined; /** * The date on which the order is expected to arrive - YYYY-MM-DD. */ expectedArrivalDate?: Date | 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; /** * Sub-total amount, normally before tax. */ subTotal?: number | null | undefined; /** * Total tax amount applied to this invoice. */ totalTax?: number | null | undefined; /** * Total amount of invoice, including tax. */ total?: number | null | undefined; /** * Amounts are including tax */ taxInclusive?: boolean | null | undefined; lineItems?: Array | undefined; billingAddress?: Address | undefined; shippingAddress?: Address | undefined; ledgerAccount?: LinkedLedgerAccount | null | undefined; /** * Optional purchase order template */ templateId?: string | null | undefined; /** * Discount percentage applied to this transaction. */ discountPercentage?: number | null | undefined; bankAccount?: BankAccount | 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; /** * The due date is the date on which a payment is scheduled to be received - YYYY-MM-DD. */ dueDate?: Date | null | undefined; /** * Payment method used for the transaction, such as cash, credit card, bank transfer, or check */ paymentMethod?: string | null | undefined; /** * Terms of payment. */ terms?: string | null | undefined; /** * The ID of the payment terms */ termsId?: string | null | undefined; /** * Type of amortization */ amortizationType?: PurchaseOrderAmortizationType | null | undefined; /** * Applicable tax id/code override if tax is not supplied on a line item basis. */ taxCode?: string | null | undefined; /** * Method of tax calculation */ taxMethod?: string | null | undefined; /** * Method of issuance of the purchase order */ issuedMethod?: string | null | undefined; /** * Email address of the person who issued the purchase order */ issuedEmail?: string | null | undefined; /** * The channel through which the transaction is processed. */ channel?: string | null | undefined; /** * Message for the supplier. This text appears on the Purchase Order. */ memo?: string | null | undefined; /** * Internal notes for the purchase order. */ notes?: string | null | undefined; /** * A list of linked tracking categories. */ trackingCategories?: Array | null | undefined; /** * When custom mappings are configured on the resource, the result is included here. */ customMappings?: { [k: string]: any } | null | undefined; customFields?: Array | 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; /** * 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; /** * The pass_through property allows passing service-specific, custom data or structured modifications in request body when creating or updating resources. */ passThrough?: Array | undefined; }; export type PurchaseOrderInput = { /** * Display ID of the purchase order */ displayId?: string | null | undefined; /** * A PO Number uniquely identifies a purchase order and is generally defined by the buyer. */ poNumber?: string | null | undefined; /** * Optional purchase order reference. */ reference?: string | null | undefined; /** * The supplier this entity is linked to. */ supplier?: LinkedSupplierInput | null | undefined; /** * The ID of the subsidiary */ subsidiaryId?: string | null | undefined; /** * The company ID the transaction belongs to */ companyId?: string | null | undefined; /** * The ID of the location */ locationId?: string | null | undefined; /** * The ID of the department */ departmentId?: string | null | undefined; status?: PurchaseOrderStatus | null | undefined; /** * Date purchase order was issued - YYYY-MM-DD. */ issuedDate?: Date | null | undefined; /** * The date on which the purchase order is to be delivered - YYYY-MM-DD. */ deliveryDate?: Date | null | undefined; /** * The date on which the order is expected to arrive - YYYY-MM-DD. */ expectedArrivalDate?: Date | 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; /** * Sub-total amount, normally before tax. */ subTotal?: number | null | undefined; /** * Total tax amount applied to this invoice. */ totalTax?: number | null | undefined; /** * Total amount of invoice, including tax. */ total?: number | null | undefined; /** * Amounts are including tax */ taxInclusive?: boolean | null | undefined; lineItems?: Array | undefined; billingAddress?: Address | undefined; shippingAddress?: Address | undefined; ledgerAccount?: LinkedLedgerAccount | null | undefined; /** * Optional purchase order template */ templateId?: string | null | undefined; /** * Discount percentage applied to this transaction. */ discountPercentage?: number | null | undefined; bankAccount?: BankAccount | 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; /** * The due date is the date on which a payment is scheduled to be received - YYYY-MM-DD. */ dueDate?: Date | null | undefined; /** * Payment method used for the transaction, such as cash, credit card, bank transfer, or check */ paymentMethod?: string | null | undefined; /** * Terms of payment. */ terms?: string | null | undefined; /** * The ID of the payment terms */ termsId?: string | null | undefined; /** * Type of amortization */ amortizationType?: PurchaseOrderAmortizationType | null | undefined; /** * Applicable tax id/code override if tax is not supplied on a line item basis. */ taxCode?: string | null | undefined; /** * Method of tax calculation */ taxMethod?: string | null | undefined; /** * Method of issuance of the purchase order */ issuedMethod?: string | null | undefined; /** * Email address of the person who issued the purchase order */ issuedEmail?: string | null | undefined; /** * The channel through which the transaction is processed. */ channel?: string | null | undefined; /** * Message for the supplier. This text appears on the Purchase Order. */ memo?: string | null | undefined; /** * Internal notes for the purchase order. */ notes?: string | null | undefined; /** * A list of linked tracking categories. */ trackingCategories?: Array | null | undefined; customFields?: Array | 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; /** * The pass_through property allows passing service-specific, custom data or structured modifications in request body when creating or updating resources. */ passThrough?: Array | undefined; }; /** @internal */ export const PurchaseOrderStatus$inboundSchema: z.ZodType< PurchaseOrderStatus, z.ZodTypeDef, unknown > = /* @__PURE__ */ lazySchema$(() => openEnums.inboundSchema(PurchaseOrderStatus) ); /** @internal */ export const PurchaseOrderStatus$outboundSchema: z.ZodType< string, z.ZodTypeDef, PurchaseOrderStatus > = /* @__PURE__ */ lazySchema$(() => openEnums.outboundSchema(PurchaseOrderStatus) ); /** @internal */ export const PurchaseOrderAmortizationType$inboundSchema: z.ZodType< PurchaseOrderAmortizationType, z.ZodTypeDef, unknown > = /* @__PURE__ */ lazySchema$(() => openEnums.inboundSchema(PurchaseOrderAmortizationType) ); /** @internal */ export const PurchaseOrderAmortizationType$outboundSchema: z.ZodType< string, z.ZodTypeDef, PurchaseOrderAmortizationType > = /* @__PURE__ */ lazySchema$(() => openEnums.outboundSchema(PurchaseOrderAmortizationType) ); /** @internal */ export const PurchaseOrder$inboundSchema: z.ZodType< PurchaseOrder, z.ZodTypeDef, unknown > = /* @__PURE__ */ lazySchema$(() => z.object({ id: types.optional(types.string()), downstream_id: z.nullable(types.string()).optional(), display_id: z.nullable(types.string()).optional(), po_number: z.nullable(types.string()).optional(), reference: z.nullable(types.string()).optional(), supplier: z.nullable(LinkedSupplier$inboundSchema).optional(), subsidiary_id: z.nullable(types.string()).optional(), company_id: z.nullable(types.string()).optional(), location_id: z.nullable(types.string()).optional(), department_id: z.nullable(types.string()).optional(), status: z.nullable(PurchaseOrderStatus$inboundSchema).optional(), issued_date: z.nullable(types.date()).optional(), delivery_date: z.nullable(types.date()).optional(), expected_arrival_date: z.nullable(types.date()).optional(), currency: z.nullable(Currency$inboundSchema).optional(), currency_rate: 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_inclusive: z.nullable(types.boolean()).optional(), line_items: types.optional(z.array(InvoiceLineItem$inboundSchema)), billing_address: types.optional(Address$inboundSchema), shipping_address: types.optional(Address$inboundSchema), ledger_account: z.nullable(LinkedLedgerAccount$inboundSchema).optional(), template_id: z.nullable(types.string()).optional(), discount_percentage: z.nullable(types.number()).optional(), bank_account: types.optional(BankAccount$inboundSchema), accounting_by_row: z.nullable(types.boolean()).optional(), due_date: z.nullable(types.date()).optional(), payment_method: z.nullable(types.string()).optional(), terms: z.nullable(types.string()).optional(), terms_id: z.nullable(types.string()).optional(), amortization_type: z.nullable(PurchaseOrderAmortizationType$inboundSchema) .optional(), tax_code: z.nullable(types.string()).optional(), tax_method: z.nullable(types.string()).optional(), issued_method: z.nullable(types.string()).optional(), issued_email: z.nullable(types.string()).optional(), channel: z.nullable(types.string()).optional(), memo: z.nullable(types.string()).optional(), notes: z.nullable(types.string()).optional(), tracking_categories: z.nullable( z.array(types.nullable(LinkedTrackingCategory$inboundSchema)), ).optional(), custom_mappings: z.nullable(z.record(z.any())).optional(), custom_fields: types.optional(z.array(CustomField$inboundSchema)), row_version: z.nullable(types.string()).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(), pass_through: types.optional(z.array(PassThroughBody$inboundSchema)), }).transform((v) => { return remap$(v, { "downstream_id": "downstreamId", "display_id": "displayId", "po_number": "poNumber", "subsidiary_id": "subsidiaryId", "company_id": "companyId", "location_id": "locationId", "department_id": "departmentId", "issued_date": "issuedDate", "delivery_date": "deliveryDate", "expected_arrival_date": "expectedArrivalDate", "currency_rate": "currencyRate", "sub_total": "subTotal", "total_tax": "totalTax", "tax_inclusive": "taxInclusive", "line_items": "lineItems", "billing_address": "billingAddress", "shipping_address": "shippingAddress", "ledger_account": "ledgerAccount", "template_id": "templateId", "discount_percentage": "discountPercentage", "bank_account": "bankAccount", "accounting_by_row": "accountingByRow", "due_date": "dueDate", "payment_method": "paymentMethod", "terms_id": "termsId", "amortization_type": "amortizationType", "tax_code": "taxCode", "tax_method": "taxMethod", "issued_method": "issuedMethod", "issued_email": "issuedEmail", "tracking_categories": "trackingCategories", "custom_mappings": "customMappings", "custom_fields": "customFields", "row_version": "rowVersion", "updated_by": "updatedBy", "created_by": "createdBy", "updated_at": "updatedAt", "created_at": "createdAt", "pass_through": "passThrough", }); }) ); export function purchaseOrderFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => PurchaseOrder$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'PurchaseOrder' from JSON`, ); } /** @internal */ export type PurchaseOrderInput$Outbound = { display_id?: string | null | undefined; po_number?: string | null | undefined; reference?: string | null | undefined; supplier?: LinkedSupplierInput$Outbound | null | undefined; subsidiary_id?: string | null | undefined; company_id?: string | null | undefined; location_id?: string | null | undefined; department_id?: string | null | undefined; status?: string | null | undefined; issued_date?: string | null | undefined; delivery_date?: string | null | undefined; expected_arrival_date?: string | null | undefined; currency?: string | null | undefined; currency_rate?: number | null | undefined; sub_total?: number | null | undefined; total_tax?: number | null | undefined; total?: number | null | undefined; tax_inclusive?: boolean | null | undefined; line_items?: Array | undefined; billing_address?: Address$Outbound | undefined; shipping_address?: Address$Outbound | undefined; ledger_account?: LinkedLedgerAccount$Outbound | null | undefined; template_id?: string | null | undefined; discount_percentage?: number | null | undefined; bank_account?: BankAccount$Outbound | undefined; accounting_by_row?: boolean | null | undefined; due_date?: string | null | undefined; payment_method?: string | null | undefined; terms?: string | null | undefined; terms_id?: string | null | undefined; amortization_type?: string | null | undefined; tax_code?: string | null | undefined; tax_method?: string | null | undefined; issued_method?: string | null | undefined; issued_email?: string | null | undefined; channel?: string | null | undefined; memo?: string | null | undefined; notes?: string | null | undefined; tracking_categories?: | Array | null | undefined; custom_fields?: Array | undefined; row_version?: string | null | undefined; pass_through?: Array | undefined; }; /** @internal */ export const PurchaseOrderInput$outboundSchema: z.ZodType< PurchaseOrderInput$Outbound, z.ZodTypeDef, PurchaseOrderInput > = /* @__PURE__ */ lazySchema$(() => z.object({ displayId: z.nullable(z.string()).optional(), poNumber: z.nullable(z.string()).optional(), reference: z.nullable(z.string()).optional(), supplier: z.nullable(LinkedSupplierInput$outboundSchema).optional(), subsidiaryId: z.nullable(z.string()).optional(), companyId: z.nullable(z.string()).optional(), locationId: z.nullable(z.string()).optional(), departmentId: z.nullable(z.string()).optional(), status: z.nullable(PurchaseOrderStatus$outboundSchema).optional(), issuedDate: z.nullable( z.date().transform(v => v.toISOString().slice(0, "YYYY-MM-DD".length)), ).optional(), deliveryDate: z.nullable( z.date().transform(v => v.toISOString().slice(0, "YYYY-MM-DD".length)), ).optional(), expectedArrivalDate: z.nullable( z.date().transform(v => v.toISOString().slice(0, "YYYY-MM-DD".length)), ).optional(), currency: z.nullable(Currency$outboundSchema).optional(), currencyRate: z.nullable(z.number()).optional(), subTotal: z.nullable(z.number()).optional(), totalTax: z.nullable(z.number()).optional(), total: z.nullable(z.number()).optional(), taxInclusive: z.nullable(z.boolean()).optional(), lineItems: z.array(InvoiceLineItemInput$outboundSchema).optional(), billingAddress: Address$outboundSchema.optional(), shippingAddress: Address$outboundSchema.optional(), ledgerAccount: z.nullable(LinkedLedgerAccount$outboundSchema).optional(), templateId: z.nullable(z.string()).optional(), discountPercentage: z.nullable(z.number()).optional(), bankAccount: BankAccount$outboundSchema.optional(), accountingByRow: z.nullable(z.boolean()).optional(), dueDate: z.nullable( z.date().transform(v => v.toISOString().slice(0, "YYYY-MM-DD".length)), ).optional(), paymentMethod: z.nullable(z.string()).optional(), terms: z.nullable(z.string()).optional(), termsId: z.nullable(z.string()).optional(), amortizationType: z.nullable(PurchaseOrderAmortizationType$outboundSchema) .optional(), taxCode: z.nullable(z.string()).optional(), taxMethod: z.nullable(z.string()).optional(), issuedMethod: z.nullable(z.string()).optional(), issuedEmail: z.nullable(z.string()).optional(), channel: z.nullable(z.string()).optional(), memo: z.nullable(z.string()).optional(), notes: z.nullable(z.string()).optional(), trackingCategories: z.nullable( z.array(z.nullable(LinkedTrackingCategory$outboundSchema)), ).optional(), customFields: z.array(CustomField$outboundSchema).optional(), rowVersion: z.nullable(z.string()).optional(), passThrough: z.array(PassThroughBody$outboundSchema).optional(), }).transform((v) => { return remap$(v, { displayId: "display_id", poNumber: "po_number", subsidiaryId: "subsidiary_id", companyId: "company_id", locationId: "location_id", departmentId: "department_id", issuedDate: "issued_date", deliveryDate: "delivery_date", expectedArrivalDate: "expected_arrival_date", currencyRate: "currency_rate", subTotal: "sub_total", totalTax: "total_tax", taxInclusive: "tax_inclusive", lineItems: "line_items", billingAddress: "billing_address", shippingAddress: "shipping_address", ledgerAccount: "ledger_account", templateId: "template_id", discountPercentage: "discount_percentage", bankAccount: "bank_account", accountingByRow: "accounting_by_row", dueDate: "due_date", paymentMethod: "payment_method", termsId: "terms_id", amortizationType: "amortization_type", taxCode: "tax_code", taxMethod: "tax_method", issuedMethod: "issued_method", issuedEmail: "issued_email", trackingCategories: "tracking_categories", customFields: "custom_fields", rowVersion: "row_version", passThrough: "pass_through", }); }) ); export function purchaseOrderInputToJSON( purchaseOrderInput: PurchaseOrderInput, ): string { return JSON.stringify( PurchaseOrderInput$outboundSchema.parse(purchaseOrderInput), ); }