1 | |
2 | type Zoho = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Update a journal |
7 | * Updates the journal with given information. |
8 | */ |
9 | export async function main( |
10 | auth: Zoho, |
11 | journal_id: string, |
12 | organization_id: string | undefined, |
13 | body: { |
14 | journal_date: string; |
15 | reference_number?: string; |
16 | notes?: string; |
17 | journal_type?: string; |
18 | vat_treatment?: string; |
19 | include_in_vat_return?: false | true; |
20 | product_type?: string; |
21 | is_bas_adjustment?: false | true; |
22 | currency_id?: string; |
23 | exchange_rate?: number; |
24 | location_id?: string; |
25 | line_items?: { |
26 | account_id?: string; |
27 | customer_id?: string; |
28 | line_id?: string; |
29 | description?: string; |
30 | tax_exemption_id?: string; |
31 | tax_authority_id?: string; |
32 | tax_exemption_type?: string; |
33 | tax_exemption_code?: string; |
34 | tax_authority_name?: string; |
35 | tax_id?: string; |
36 | amount: number; |
37 | debit_or_credit: string; |
38 | acquisition_vat_id?: string; |
39 | reverse_charge_vat_id?: string; |
40 | tags?: { tag_id?: number; tag_option_id?: number }[]; |
41 | location_id?: string; |
42 | project_id?: string; |
43 | }[]; |
44 | tax_exemption_code?: string; |
45 | tax_exemption_type?: string; |
46 | custom_fields?: { customfield_id?: string; value?: string }[]; |
47 | }, |
48 | ) { |
49 | const url = new URL( |
50 | `https://www.zohoapis.com/books/v3/journals/${journal_id}`, |
51 | ); |
52 | for (const [k, v] of [["organization_id", organization_id]]) { |
53 | if (v !== undefined && v !== "" && k !== undefined) { |
54 | url.searchParams.append(k, v); |
55 | } |
56 | } |
57 | const response = await fetch(url, { |
58 | method: "PUT", |
59 | headers: { |
60 | "Content-Type": "application/json", |
61 | Authorization: "Zoho-oauthtoken " + auth.token, |
62 | }, |
63 | body: JSON.stringify(body), |
64 | }); |
65 | if (!response.ok) { |
66 | const text = await response.text(); |
67 | throw new Error(`${response.status} ${text}`); |
68 | } |
69 | return await response.json(); |
70 | } |
71 |
|