1 | |
2 | type Zoho = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Create a Purchase Order |
7 | * Creates 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 | organization_id: string | undefined, |
12 | ignore_auto_number_generation: string | undefined, |
13 | body: { |
14 | purchaseorder_number: string; |
15 | date?: string; |
16 | delivery_date?: string; |
17 | reference_number?: string; |
18 | ship_via?: string; |
19 | vendor_id: number; |
20 | salesorder_id?: number; |
21 | is_drop_shipment?: false | true; |
22 | is_inclusive_tax?: false | true; |
23 | is_backorder?: false | true; |
24 | template_id?: number; |
25 | contact_persons?: { contact_person_id?: number }[]; |
26 | attention?: string; |
27 | delivery_org_address_id?: number; |
28 | delivery_customer_id?: number; |
29 | notes?: string; |
30 | terms?: string; |
31 | exchange_rate?: number; |
32 | custom_fields?: { customfield_id?: number; value?: string }[]; |
33 | line_items: { |
34 | item_id?: number; |
35 | account_id?: number; |
36 | name?: string; |
37 | description?: string; |
38 | item_order?: number; |
39 | bcy_rate?: number; |
40 | purchase_rate?: number; |
41 | quantity?: number; |
42 | quantity_received?: number; |
43 | unit?: string; |
44 | item_total?: number; |
45 | tax_id?: number; |
46 | tds_tax_id?: string; |
47 | tax_name?: string; |
48 | tax_type?: string; |
49 | tax_percentage?: number; |
50 | image_id?: number; |
51 | image_name?: string; |
52 | image_type?: string; |
53 | reverse_charge_tax_id?: string; |
54 | hsn_or_sac?: string; |
55 | tax_exemption_code?: string; |
56 | location_id?: string; |
57 | tax_exemption_id?: string; |
58 | salesorder_item_id?: number; |
59 | }[]; |
60 | location_id?: string; |
61 | documents?: { |
62 | can_send_in_mail?: false | true; |
63 | file_name?: string; |
64 | file_type?: string; |
65 | file_size_formatted?: string; |
66 | attachment_order?: number; |
67 | document_id?: number; |
68 | file_size?: number; |
69 | }[]; |
70 | gst_treatment?: string; |
71 | tax_treatment?: {}; |
72 | gst_no?: string; |
73 | source_of_supply?: string; |
74 | destination_of_supply?: string; |
75 | }, |
76 | ) { |
77 | const url = new URL(`https://www.zohoapis.com/inventory/v1/purchaseorders`); |
78 | for (const [k, v] of [ |
79 | ["organization_id", organization_id], |
80 | ["ignore_auto_number_generation", ignore_auto_number_generation], |
81 | ]) { |
82 | if (v !== undefined && v !== "" && k !== undefined) { |
83 | url.searchParams.append(k, v); |
84 | } |
85 | } |
86 | const response = await fetch(url, { |
87 | method: "POST", |
88 | headers: { |
89 | "Content-Type": "application/json", |
90 | Authorization: "Zoho-oauthtoken " + auth.token, |
91 | }, |
92 | body: JSON.stringify(body), |
93 | }); |
94 | if (!response.ok) { |
95 | const text = await response.text(); |
96 | throw new Error(`${response.status} ${text}`); |
97 | } |
98 | return await response.json(); |
99 | } |
100 |
|