1 | |
2 | type Zoho = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Update an Expense |
7 | * Update an existing Expense. |
8 | */ |
9 | export async function main( |
10 | auth: Zoho, |
11 | expense_id: string, |
12 | organization_id: string | undefined, |
13 | receipt: string | undefined, |
14 | delete_receipt: string | undefined, |
15 | body: { |
16 | account_id: string; |
17 | date: string; |
18 | amount: number; |
19 | tax_id?: string; |
20 | source_of_supply?: string; |
21 | destination_of_supply?: string; |
22 | place_of_supply?: string; |
23 | hsn_or_sac?: string; |
24 | gst_no?: string; |
25 | reverse_charge_tax_id?: string; |
26 | line_items?: { |
27 | line_item_id?: string; |
28 | account_id?: string; |
29 | description?: string; |
30 | amount?: number; |
31 | tax_id?: string; |
32 | item_order?: string; |
33 | product_type?: string; |
34 | acquisition_vat_id?: string; |
35 | reverse_charge_vat_id?: string; |
36 | reverse_charge_tax_id?: string; |
37 | tax_exemption_code?: string; |
38 | tax_exemption_id?: string; |
39 | location_id?: string; |
40 | }[]; |
41 | location_id?: string; |
42 | taxes?: { tax_id?: string; tax_amount?: number }[]; |
43 | is_inclusive_tax?: false | true; |
44 | is_billable?: false | true; |
45 | reference_number?: string; |
46 | description?: string; |
47 | customer_id?: string; |
48 | currency_id?: string; |
49 | exchange_rate?: number; |
50 | project_id?: string; |
51 | mileage_type?: string; |
52 | vat_treatment?: string; |
53 | tax_treatment?: string; |
54 | product_type?: string; |
55 | acquisition_vat_id?: string; |
56 | reverse_charge_vat_id?: string; |
57 | start_reading?: number; |
58 | end_reading?: number; |
59 | distance?: string; |
60 | mileage_unit?: string; |
61 | mileage_rate?: number; |
62 | employee_id?: string; |
63 | vehicle_type?: string; |
64 | can_reclaim_vat_on_mileage?: string; |
65 | fuel_type?: string; |
66 | engine_capacity_range?: string; |
67 | paid_through_account_id: string; |
68 | vendor_id?: string; |
69 | custom_fields?: string[]; |
70 | }, |
71 | ) { |
72 | const url = new URL( |
73 | `https://www.zohoapis.com/books/v3/expenses/${expense_id}`, |
74 | ); |
75 | for (const [k, v] of [ |
76 | ["organization_id", organization_id], |
77 | ["receipt", receipt], |
78 | ["delete_receipt", delete_receipt], |
79 | ]) { |
80 | if (v !== undefined && v !== "" && k !== undefined) { |
81 | url.searchParams.append(k, v); |
82 | } |
83 | } |
84 | const response = await fetch(url, { |
85 | method: "PUT", |
86 | headers: { |
87 | "Content-Type": "application/json", |
88 | Authorization: "Zoho-oauthtoken " + auth.token, |
89 | }, |
90 | body: JSON.stringify(body), |
91 | }); |
92 | if (!response.ok) { |
93 | const text = await response.text(); |
94 | throw new Error(`${response.status} ${text}`); |
95 | } |
96 | return await response.json(); |
97 | } |
98 |
|