import {z} from 'zod' export type ApiSharedEnum6a9369bfa4 = '19' | '21' | '25' | '30' | '31' | '32' | '35' | '43' | '51' | '53' | '55' | '69' | '70' | '71' | '78' | '86' | '94' | '95' | '110' | '111' | '116' | '119' | '124'; export type ApiSharedObjectf91176efb5 = {purchase_id: string, applied_amount: number}; export type ApiSharedObjectdaa374f786 = {journal_line_id: string, applied_amount: number}; export type ApiGananciasPreviewRequest = {regimen: ApiSharedEnum6a9369bfa4, calculation_base?: number | undefined, is_inscripto?: boolean | undefined, supplier_id: string, payment_date: string, exclude_payment_id?: string | undefined, currency?: ('ARS' | 'USD') | undefined, exchange_rate?: number | undefined, applications?: Array | undefined, journal_line_applications?: Array | undefined}; export type CreateApiApiV1SupplierPaymentsPreviewGananciasArgs = {body: ApiGananciasPreviewRequest}; export type CreateApiApiV1SupplierPaymentsPreviewGananciasOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const apiGananciasPreviewResponse = z.object({request_id: z.string(), data: z.object({object: z.literal("supplier_payment_ganancias_preview"), should_withhold: z.boolean(), exempt_reason: z.string().optional(), calculation_base: z.number().int(), accumulated_base_total: z.number().int(), minimum_non_taxable: z.number().int(), taxable_amount: z.number().int(), rate: z.number(), gross_withholding: z.number().int(), previous_withholdings: z.number().int(), net_withholding: z.number().int(), minimum_threshold: z.number().int(), final_withholding: z.number().int(), supplier_name: z.string(), is_inscripto_en_ganancias: z.boolean(), person_type: z.enum(["FISICA", "JURIDICA"]), breakdown: z.array(z.object({label: z.string(), value: z.number(), formatted_value: z.string().optional()})), progressive_scale_details: z.object({bracket: z.string(), fixed_amount: z.number(), rate: z.number(), excess_over: z.number()}).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 }; /** * Calcular retención de Ganancias sin registrar un pago * * POST /api/v1/supplier-payments/preview-ganancias */ export const createApiApiV1SupplierPaymentsPreviewGanancias = async (args: CreateApiApiV1SupplierPaymentsPreviewGananciasArgs, options?: CreateApiApiV1SupplierPaymentsPreviewGananciasOptions) => { const {baseUrl = "https://api.lapyme.com.ar", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/supplier-payments/preview-ganancias${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(apiGananciasPreviewResponse, await res.json()) };