import {z} from 'zod' export type PeakAPIsLibraryModelRequestContactsContactBankAccount = {bankId?: (0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37) | undefined, bankBranch?: string | undefined, bankAccountNo?: string | undefined, bankAccountName?: string | undefined}; export type PeakAPIsLibraryModelEcoSystemResponseProductAPIUnitModel = {id?: string | undefined, code?: string | undefined, nameTh?: string | undefined, nameEn?: string | undefined}; export type PeakAPIsLibraryModelRequestPaymentMethodsPaymentMethods = {id?: string | undefined, code?: string | undefined, name?: string | undefined, type?: (0 | 1 | 2 | 3 | 4) | undefined, memo?: string | undefined, carringBalanceValue?: number | undefined, bankId?: (0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37) | undefined, eWalletId?: (0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37) | undefined, bankName?: string | undefined, accountType?: (0 | 1 | 2 | 3) | undefined, accountNumber?: string | undefined, isHaveCheque?: (0 | 1) | undefined, accountCode?: string | undefined}; export type PeakAPIsLibraryModelRequestTransactionSharedNormalReceivedTaxInvoiceTransaction = {taxInvoiceNumber?: string | undefined, taxInvoiceDate?: string | undefined, journalDate?: string | undefined, periodDate?: string | undefined}; export type CreateApiApiV1ExpensesAllinoneArgs = {getResult?: (0 | 1) | undefined, 'Time-Stamp': string, 'Time-Signature': string, 'User-Token': string, 'Client-Token': string, body: {peakExpenses: {expenses: Array<{code?: string | undefined, issuedDate: string, dueDate: string, contact: {name: string, type: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11, prefixNameType?: (0 | 1 | 2 | 3 | 4 | 5) | undefined, prefixNameOther?: string | undefined, taxNumber?: string | undefined, branchCode?: string | undefined, address?: string | undefined, subDistrict?: string | undefined, district?: string | undefined, province?: string | undefined, country?: string | undefined, postCode?: string | undefined, callCenterNumber?: string | undefined, faxNumber?: string | undefined, email?: string | undefined, website?: string | undefined, contactFirstName?: string | undefined, contactLastName?: string | undefined, contactNickName?: string | undefined, contactPosition?: string | undefined, contactPhoneNumber?: string | undefined, contactEmail?: string | undefined, purchaseAccount?: string | undefined, sellAccount?: string | undefined, bankAccount?: PeakAPIsLibraryModelRequestContactsContactBankAccount | undefined, id?: string | undefined, code: string, contactFinanceType?: (0 | 1 | 2) | undefined}, reference?: string | undefined, remark?: string | undefined, taxStatus?: (0 | 1 | 2) | undefined, discountTotal?: string | undefined, isTaxInvoice?: (0 | 1) | undefined, tags?: Array | undefined, status?: ('Draft' | 'Approve') | undefined, products: Array<{id?: string | undefined, productTemplate?: ({id?: string | undefined, name: string, type: 0 | 1 | 2, code: string, purchaseValue?: number | undefined, purchaseVatType?: (1 | 2 | 3) | undefined, purchaseAccount?: string | undefined, sellValue?: number | undefined, sellVatType?: (1 | 2 | 3) | undefined, sellAccount?: string | undefined, description?: string | undefined, carryingBalanceValue?: number | undefined, carryingBalanceAmount?: number | undefined, unit?: PeakAPIsLibraryModelEcoSystemResponseProductAPIUnitModel | undefined}) | undefined, description?: string | undefined, accountCode?: string | undefined, accountSubId?: string | undefined, accountSubCode?: string | undefined, quantity: number, price: number, discount?: string | undefined, vatType: 1 | 2 | 3, isDescription?: (0 | 1) | undefined, withHoldingTaxAmount?: string | undefined}>, paidPayments?: ({payments?: (Array<{cheque?: ({accountNo: string, branchNo?: string | undefined, chequeNo: string, amount: number, chequeDate: string, bankId?: (0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37) | undefined, paymentMethodId?: string | undefined, paymentMethodCode?: string | undefined}) | undefined, note?: string | undefined, isCheque?: (0 | 1) | undefined, amount: number, paymentMethod?: PeakAPIsLibraryModelRequestPaymentMethodsPaymentMethods | undefined, accountCode?: string | undefined, accountSubId?: string | undefined, accountSubCode?: string | undefined}>) | undefined, paymentDate?: string | undefined, withHoldingTaxAmount?: string | undefined, transactionId?: string | undefined}) | undefined, preTaxAmount?: number | undefined, vatAmount?: number | undefined, netAmount?: number | undefined, currency?: ({currencyId: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48, exchangeRate: number}) | undefined, receivedTaxInvoice?: PeakAPIsLibraryModelRequestTransactionSharedNormalReceivedTaxInvoiceTransaction | undefined}>, getResult?: (0 | 1) | undefined}}}; export type CreateApiApiV1ExpensesAllinoneOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const peakWCFModelsAPIAPITransactionsAPITransactionProducts = z.object({id: z.string().optional(), productId: z.string().optional(), productCode: z.string().optional(), accountCode: z.string().optional(), accountSubId: z.string().optional(), accountSubCode: z.string().optional(), description: z.string().optional(), quantity: z.number().optional(), price: z.number().optional(), discount: z.string().optional(), vatType: z.number().int().optional(), isDescription: z.number().int().optional(), withHoldingTaxAmount: z.string().optional()}); export const peakWCFModelsAPIAPITransactionsAPITransactionChequePayment = z.object({chequeDate: z.string().optional(), paymentMethodId: z.string().optional(), paymentMethodCode: z.string().optional(), bankId: z.number().int().optional(), bankName: z.string().optional(), amount: z.number().optional(), chequeNo: z.string().optional(), branchNo: z.string().optional(), accountNo: z.string().optional(), isDeposited: z.number().int().optional()}); export const peakWCFModelsAPIAPITransactionsAPITransactionPaymentLists = z.object({paymentMethodId: z.string().optional(), paymentMethodCode: z.string().optional(), accountCode: z.string().optional(), accountSubId: z.string().optional(), accountSubCode: z.string().optional(), amount: z.number().optional(), note: z.string().optional(), isCheque: z.number().int().optional(), cheque: peakWCFModelsAPIAPITransactionsAPITransactionChequePayment.optional()}); export const peakWCFModelsAPIAPITransactionsAPITransactionJournals = z.object({id: z.string().optional(), code: z.string().optional()}); export const peakWCFModelsAPIAPITransactionsAPITransactionPayments = z.object({id: z.string().optional(), paymentDate: z.string().optional(), withHoldingTaxAmount: z.string().optional(), paymentGroupId: z.number().int().optional(), paymentTotal: z.number().optional(), payments: z.array(peakWCFModelsAPIAPITransactionsAPITransactionPaymentLists).optional(), journals: z.array(peakWCFModelsAPIAPITransactionsAPITransactionJournals).optional(), referenceCode: z.string().optional(), referenceId: z.string().optional(), referenceType: z.string().optional()}); export const peakWCFModelsAPIAPITransactionsAPITransactionBillingNotes = z.object({id: z.string().optional(), code: z.string().optional(), amount: z.number().optional(), isPaid: z.number().int().optional()}); export const peakWCFModelsAPIAPITransactionsAPITransactionCreditNotes = z.object({id: z.string().optional(), code: z.string().optional(), creditAmount: z.number().optional(), deductedAmount: z.number().optional(), refundedAmount: z.number().optional()}); export const peakWCFModelsAPIAPITransactionsAPITransactionCurrency = z.object({currencyId: z.number().int().optional(), exchangeRate: z.number().optional()}); export const peakWCFModelsAPIAPITransactionsAPITransactionReceivedTaxInvoice = z.object({taxInvoiceNumber: z.string().optional(), taxInvoiceDate: z.string().optional(), journalDate: z.string().optional(), periodDate: z.string().optional()}); export const peakWCFModelsAPIAPITransactionsAPITransactionsModel = z.object({resCode: z.string().optional(), resDesc: z.string().optional(), id: z.string().optional(), code: z.string().optional(), issuedDate: z.string().optional(), dueDate: z.string().optional(), contactId: z.string().optional(), contactCode: z.string().optional(), reference: z.string().optional(), status: z.string().optional(), isTaxInvoice: z.number().int().optional(), isVoid: z.number().int().optional(), preTaxAmount: z.number().optional(), vatAmount: z.number().optional(), netAmount: z.number().optional(), whtAmount: z.number().optional(), paymentAmount: z.number().optional(), remainAmount: z.number().optional(), remainWhtAmount: z.number().optional(), documentLink: z.string().optional(), onlineViewLink: z.string().optional(), isPartialReceipt: z.number().int().optional(), remark: z.string().optional(), taxStatus: z.number().int().optional(), discountTotal: z.string().optional(), tags: z.array(z.string()).optional(), products: z.array(peakWCFModelsAPIAPITransactionsAPITransactionProducts).optional(), paidPayments: z.array(peakWCFModelsAPIAPITransactionsAPITransactionPayments).optional(), billingNotes: z.array(peakWCFModelsAPIAPITransactionsAPITransactionBillingNotes).optional(), creditNotes: z.array(peakWCFModelsAPIAPITransactionsAPITransactionCreditNotes).optional(), journals: z.array(peakWCFModelsAPIAPITransactionsAPITransactionJournals).optional(), referenceCode: z.string().optional(), referenceId: z.string().optional(), referenceType: z.string().optional(), statusId: z.number().int().optional(), currency: peakWCFModelsAPIAPITransactionsAPITransactionCurrency.optional(), receivedTaxInvoice: peakWCFModelsAPIAPITransactionsAPITransactionReceivedTaxInvoice.optional(), isETaxInvoiceSent: z.number().int().optional()}); export const peakWCFModelsAPIBodyAPIBodyExpense = z.object({expenses: z.array(peakWCFModelsAPIAPITransactionsAPITransactionsModel).optional(), totalExpenses: z.number().int().optional(), resDesc: z.string().optional(), resCode: z.string().optional()}); export const peakWCFModelsAPIResponseResponseExpenseModel = z.object({peakExpenses: peakWCFModelsAPIBodyAPIBodyExpense.optional(), eventType: z.string().optional(), apiType: z.string().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 }; /** * Create Expense All In One * * POST /api/v1/Expenses/allinone */ export const createApiApiV1ExpensesAllinone = async (args: CreateApiApiV1ExpensesAllinoneArgs, options?: CreateApiApiV1ExpensesAllinoneOptions) => { const {baseUrl = "https://api.peakaccount.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.getResult != null) query.append("getResult", String(args.getResult)) if (args['Time-Stamp'] != null) headers.set("Time-Stamp", String(args['Time-Stamp'])) if (args['Time-Signature'] != null) headers.set("Time-Signature", String(args['Time-Signature'])) if (args['User-Token'] != null) headers.set("User-Token", String(args['User-Token'])) if (args['Client-Token'] != null) headers.set("Client-Token", String(args['Client-Token'])) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/Expenses/allinone${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 validateResponse(peakWCFModelsAPIResponseResponseExpenseModel, await res.json()) };