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