1 | |
2 | type Zoho = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Create a credit note |
7 | * To create a credit note for a customer. |
8 | */ |
9 | export async function main( |
10 | auth: Zoho, |
11 | organization_id: string | undefined, |
12 | invoice_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 | description?: string; |
23 | code?: string; |
24 | name?: string; |
25 | type?: number; |
26 | account_id?: string; |
27 | account_name?: string; |
28 | quantity?: number; |
29 | tax_id?: string; |
30 | tds_tax_id?: string; |
31 | product_type?: string; |
32 | sat_item_key_code?: string; |
33 | unitkey_code?: string; |
34 | serial_numbers?: string; |
35 | location_id?: string; |
36 | invoice_id?: string; |
37 | invoice_item_id?: string; |
38 | is_item_shipped?: false | true; |
39 | is_returned_to_stock?: false | true; |
40 | salesreturn_item_id?: string; |
41 | }[]; |
42 | location_id?: string; |
43 | creditnote_number: string; |
44 | gst_treatment?: string; |
45 | tax_treatment?: string; |
46 | gst_no?: string; |
47 | cfdi_usage?: string; |
48 | cfdi_reference_type?: string; |
49 | place_of_supply?: string; |
50 | ignore_auto_number_generation?: false | true; |
51 | reference_number?: string; |
52 | custom_fields?: { value?: string; index?: number; label?: string }[]; |
53 | notes?: string; |
54 | terms?: string; |
55 | template_id?: string; |
56 | tax_id?: string; |
57 | tax_authority_id?: string; |
58 | tax_exemption_id?: string; |
59 | avatax_use_code?: string; |
60 | avatax_exempt_no?: string; |
61 | vat_treatment?: string; |
62 | is_inclusive_tax?: false | true; |
63 | avatax_tax_code?: string; |
64 | }, |
65 | ) { |
66 | const url = new URL(`https://www.zohoapis.com/inventory/v1/creditnotes`); |
67 | for (const [k, v] of [ |
68 | ["organization_id", organization_id], |
69 | ["invoice_id", invoice_id], |
70 | ["ignore_auto_number_generation", ignore_auto_number_generation], |
71 | ]) { |
72 | if (v !== undefined && v !== "" && k !== undefined) { |
73 | url.searchParams.append(k, v); |
74 | } |
75 | } |
76 | const response = await fetch(url, { |
77 | method: "POST", |
78 | headers: { |
79 | "Content-Type": "application/json", |
80 | Authorization: "Zoho-oauthtoken " + auth.token, |
81 | }, |
82 | body: JSON.stringify(body), |
83 | }); |
84 | if (!response.ok) { |
85 | const text = await response.text(); |
86 | throw new Error(`${response.status} ${text}`); |
87 | } |
88 | return await response.json(); |
89 | } |
90 |
|