1 | |
2 | type Zoho = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Update a Sales Order |
7 | * Updates a new Sales Order in Zoho Inventory. Description about extra parameter ignore_auto_number_generation - Ignore auto sales order number generation for this sales order. This mandates the Sales Order number to be entered. Allowed Values true and false. |
8 | */ |
9 | export async function main( |
10 | auth: Zoho, |
11 | salesorder_id: string, |
12 | organization_id: string | undefined, |
13 | ignore_auto_number_generation: string | undefined, |
14 | body: { |
15 | salesorder_number: string; |
16 | date?: string; |
17 | shipment_date?: string; |
18 | custom_fields?: { |
19 | custom_field_id?: number; |
20 | index?: number; |
21 | label?: string; |
22 | value?: string; |
23 | }[]; |
24 | reference_number?: string; |
25 | customer_id: number; |
26 | contact_persons?: { contact_person_id?: number }[]; |
27 | discount?: number; |
28 | is_discount_before_tax?: false | true; |
29 | discount_type?: string; |
30 | delivery_method?: string; |
31 | shipping_charge?: number; |
32 | adjustment?: number; |
33 | adjustment_description?: string; |
34 | pricebook_id?: string; |
35 | notes?: string; |
36 | salesperson_name?: string; |
37 | terms?: string; |
38 | exchange_rate?: number; |
39 | line_items: { |
40 | line_item_id?: number; |
41 | item_id?: number; |
42 | name?: string; |
43 | description?: string; |
44 | rate?: number; |
45 | quantity?: number; |
46 | unit?: string; |
47 | tax_id?: number; |
48 | tds_tax_id?: string; |
49 | tax_name?: string; |
50 | tax_type?: string; |
51 | tax_percentage?: number; |
52 | item_total?: number; |
53 | location_id?: string; |
54 | hsn_or_sac?: string; |
55 | sat_item_key_code?: string; |
56 | unitkey_code?: string; |
57 | }[]; |
58 | location_id?: string; |
59 | billing_address_id?: number; |
60 | shipping_address_id?: number; |
61 | place_of_supply?: string; |
62 | gst_treatment?: string; |
63 | gst_no?: string; |
64 | }, |
65 | ) { |
66 | const url = new URL( |
67 | `https://www.zohoapis.com/inventory/v1/salesorders/${salesorder_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 |
|