1 | |
2 | type Zoho = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Update a Purchase Order |
7 | * Updates a new Purchase Order in Zoho Inventory. Description about extra parameter ignore_auto_number_generation - Ignore auto Purchase order number generation for this Purchase Order. This mandates the Purchase Order number to be entered. Allowed Values true and false. |
8 | */ |
9 | export async function main( |
10 | auth: Zoho, |
11 | purchaseorder_id: string, |
12 | organization_id: string | undefined, |
13 | ignore_auto_number_generation: string | undefined, |
14 | body: { |
15 | purchaseorder_number: string; |
16 | date?: string; |
17 | expected_delivery_date?: string; |
18 | reference_number?: string; |
19 | ship_via?: string; |
20 | vendor_id: number; |
21 | salesorder_id?: number; |
22 | is_drop_shipment?: false | true; |
23 | contact_persons?: { contact_person_id?: number }[]; |
24 | attention?: string; |
25 | delivery_org_address_id?: number; |
26 | delivery_customer_id?: number; |
27 | notes?: string; |
28 | terms?: string; |
29 | exchange_rate?: number; |
30 | custom_fields?: { customfield_id?: number; value?: string }[]; |
31 | line_items: { |
32 | item_id?: number; |
33 | line_item_id?: number; |
34 | account_id?: number; |
35 | name?: string; |
36 | description?: string; |
37 | item_order?: number; |
38 | bcy_rate?: number; |
39 | purchase_rate?: number; |
40 | quantity?: number; |
41 | quantity_received?: number; |
42 | unit?: string; |
43 | item_total?: number; |
44 | tax_id?: number; |
45 | tax_name?: string; |
46 | tax_type?: string; |
47 | tax_percentage?: number; |
48 | image_id?: number; |
49 | image_name?: string; |
50 | image_type?: string; |
51 | reverse_charge_tax_id?: string; |
52 | hsn_or_sac?: string; |
53 | tax_exemption_code?: string; |
54 | location_id?: string; |
55 | tax_exemption_id?: string; |
56 | salesorder_item_id?: number; |
57 | }[]; |
58 | location_id?: string; |
59 | gst_treatment?: string; |
60 | tax_treatment?: {}; |
61 | gst_no?: string; |
62 | source_of_supply?: string; |
63 | destination_of_supply?: string; |
64 | }, |
65 | ) { |
66 | const url = new URL( |
67 | `https://www.zohoapis.com/inventory/v1/purchaseorders/${purchaseorder_id}`, |
68 | ); |
69 | for (const [k, v] of [ |
70 | ["organization_id", organization_id], |
71 | ["ignore_auto_number_generation", ignore_auto_number_generation], |
72 | ]) { |
73 | if (v !== undefined && v !== "" && k !== undefined) { |
74 | url.searchParams.append(k, v); |
75 | } |
76 | } |
77 | const response = await fetch(url, { |
78 | method: "PUT", |
79 | headers: { |
80 | "Content-Type": "application/json", |
81 | Authorization: "Zoho-oauthtoken " + auth.token, |
82 | }, |
83 | body: JSON.stringify(body), |
84 | }); |
85 | if (!response.ok) { |
86 | const text = await response.text(); |
87 | throw new Error(`${response.status} ${text}`); |
88 | } |
89 | return await response.json(); |
90 | } |
91 |
|