1 | |
2 | type Zoho = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Create a Sales Order |
7 | * Creates 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 | organization_id: string | undefined, |
12 | ignore_auto_number_generation: string | undefined, |
13 | body: { |
14 | customer_id: number; |
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 | location_id?: string; |
26 | line_items: { |
27 | item_id?: number; |
28 | name?: string; |
29 | description?: string; |
30 | rate?: number; |
31 | quantity?: number; |
32 | unit?: string; |
33 | tax_id?: number; |
34 | tds_tax_id?: string; |
35 | tax_name?: string; |
36 | tax_type?: string; |
37 | tax_percentage?: number; |
38 | item_total?: number; |
39 | location_id?: string; |
40 | hsn_or_sac?: string; |
41 | sat_item_key_code?: string; |
42 | unitkey_code?: string; |
43 | }[]; |
44 | notes?: string; |
45 | terms?: string; |
46 | discount?: number; |
47 | is_discount_before_tax?: false | true; |
48 | discount_type?: string; |
49 | shipping_charge?: number; |
50 | delivery_method?: string; |
51 | adjustment?: number; |
52 | pricebook_id?: string; |
53 | salesperson_id?: string; |
54 | adjustment_description?: string; |
55 | is_inclusive_tax?: false | true; |
56 | exchange_rate?: number; |
57 | template_id?: number; |
58 | documents?: { |
59 | can_send_in_mail?: false | true; |
60 | file_name?: string; |
61 | file_type?: string; |
62 | file_size_formatted?: string; |
63 | attachment_order?: number; |
64 | document_id?: number; |
65 | file_size?: number; |
66 | }[]; |
67 | billing_address_id?: number; |
68 | shipping_address_id?: number; |
69 | place_of_supply?: string; |
70 | gst_treatment?: string; |
71 | gst_no?: string; |
72 | }, |
73 | ) { |
74 | const url = new URL(`https://www.zohoapis.com/inventory/v1/salesorders`); |
75 | for (const [k, v] of [ |
76 | ["organization_id", organization_id], |
77 | ["ignore_auto_number_generation", ignore_auto_number_generation], |
78 | ]) { |
79 | if (v !== undefined && v !== "" && k !== undefined) { |
80 | url.searchParams.append(k, v); |
81 | } |
82 | } |
83 | const response = await fetch(url, { |
84 | method: "POST", |
85 | headers: { |
86 | "Content-Type": "application/json", |
87 | Authorization: "Zoho-oauthtoken " + auth.token, |
88 | }, |
89 | body: JSON.stringify(body), |
90 | }); |
91 | if (!response.ok) { |
92 | const text = await response.text(); |
93 | throw new Error(`${response.status} ${text}`); |
94 | } |
95 | return await response.json(); |
96 | } |
97 |
|