1 | |
2 | type Zoho = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Update a credit note |
7 | * To update the details of an existing creditnote. |
8 | */ |
9 | export async function main( |
10 | auth: Zoho, |
11 | creditnote_id: string, |
12 | organization_id: string | undefined, |
13 | ignore_auto_number_generation: string | undefined, |
14 | body: { |
15 | customer_id: string; |
16 | contact_persons?: string[]; |
17 | date: string; |
18 | is_draft?: false | true; |
19 | exchange_rate?: string; |
20 | line_items: { |
21 | item_id?: string; |
22 | line_item_id?: string; |
23 | account_id?: string; |
24 | name?: string; |
25 | description?: string; |
26 | item_order?: number; |
27 | rate?: number; |
28 | quantity?: number; |
29 | unit?: string; |
30 | discount?: number; |
31 | tax_id?: string; |
32 | tds_tax_id?: string; |
33 | tax_exemption_id?: string; |
34 | tax_exemption_code?: string; |
35 | avatax_use_code?: string; |
36 | avatax_tax_code?: string; |
37 | product_type?: string; |
38 | hsn_or_sac?: string; |
39 | sat_item_key_code?: string; |
40 | unitkey_code?: string; |
41 | item_custom_fields?: { value?: string; index?: number; label?: string }[]; |
42 | location_id?: string; |
43 | location_name?: string; |
44 | serial_numbers?: string; |
45 | invoice_id?: string; |
46 | invoice_item_id?: string; |
47 | is_item_shipped?: false | true; |
48 | is_returned_to_stock?: false | true; |
49 | salesreturn_item_id?: string; |
50 | }[]; |
51 | location_id?: string; |
52 | creditnote_number: string; |
53 | gst_treatment?: string; |
54 | tax_treatment?: string; |
55 | gst_no?: string; |
56 | cfdi_usage?: string; |
57 | cfdi_reference_type?: string; |
58 | place_of_supply?: string; |
59 | ignore_auto_number_generation?: false | true; |
60 | reference_number?: string; |
61 | custom_fields?: { value?: string; index?: number; label?: string }[]; |
62 | notes?: string; |
63 | terms?: string; |
64 | template_id?: string; |
65 | tax_id?: string; |
66 | tax_authority_id?: string; |
67 | tax_exemption_id?: string; |
68 | avatax_use_code?: string; |
69 | avatax_exempt_no?: string; |
70 | vat_treatment?: string; |
71 | is_inclusive_tax?: false | true; |
72 | item_id?: string; |
73 | account_id?: string; |
74 | name?: string; |
75 | avatax_tax_code?: string; |
76 | description?: string; |
77 | unit?: string; |
78 | rate?: number; |
79 | quantity?: number; |
80 | }, |
81 | ) { |
82 | const url = new URL( |
83 | `https://www.zohoapis.com/inventory/v1/creditnotes/${creditnote_id}`, |
84 | ); |
85 | for (const [k, v] of [ |
86 | ["organization_id", organization_id], |
87 | ["ignore_auto_number_generation", ignore_auto_number_generation], |
88 | ]) { |
89 | if (v !== undefined && v !== "" && k !== undefined) { |
90 | url.searchParams.append(k, v); |
91 | } |
92 | } |
93 | const response = await fetch(url, { |
94 | method: "PUT", |
95 | headers: { |
96 | "Content-Type": "application/json", |
97 | Authorization: "Zoho-oauthtoken " + auth.token, |
98 | }, |
99 | body: JSON.stringify(body), |
100 | }); |
101 | if (!response.ok) { |
102 | const text = await response.text(); |
103 | throw new Error(`${response.status} ${text}`); |
104 | } |
105 | return await response.json(); |
106 | } |
107 |
|