1 | |
2 | type Xero = { |
3 | token: string |
4 | } |
5 | |
6 | * Updates the tax records for a specific employee |
7 | * |
8 | */ |
9 | export async function main( |
10 | auth: Xero, |
11 | EmployeeID: string, |
12 | Xero_Tenant_Id: string, |
13 | Idempotency_Key: string, |
14 | body: { |
15 | irdNumber?: string |
16 | taxCode?: |
17 | | 'ND' |
18 | | 'M' |
19 | | 'ME' |
20 | | 'MSL' |
21 | | 'MESL' |
22 | | 'SB' |
23 | | 'S' |
24 | | 'SH' |
25 | | 'ST' |
26 | | 'SBSL' |
27 | | 'SSL' |
28 | | 'SHSL' |
29 | | 'STSL' |
30 | | 'WT' |
31 | | 'CAE' |
32 | | 'EDW' |
33 | | 'NSW' |
34 | | 'STC' |
35 | | 'STCSL' |
36 | specialTaxRatePercentage?: number |
37 | hasSpecialStudentLoanRate?: false | true |
38 | specialStudentLoanRatePercentage?: number |
39 | isEligibleForKiwiSaver?: false | true |
40 | esctRatePercentage?: number |
41 | kiwiSaverContributions?: |
42 | | 'MakeContributions' |
43 | | 'OptOut' |
44 | | 'OnAContributionsHoliday' |
45 | | 'OnASavingsSuspension' |
46 | | 'NotCurrentlyAKiwiSaverMember' |
47 | kiwiSaverEmployeeContributionRatePercentage?: number |
48 | kiwiSaverEmployerContributionRatePercentage?: number |
49 | kiwiSaverEmployerSalarySacrificeContributionRatePercentage?: number |
50 | kiwiSaverOptOutDate?: string |
51 | kiwiSaverContributionHolidayEndDate?: string |
52 | hasStudentLoanBalance?: false | true |
53 | studentLoanBalance?: number |
54 | studentLoanAsAt?: string |
55 | } |
56 | ) { |
57 | const url = new URL(`https://api.xero.com/payroll.xro/2.0/Employees/${EmployeeID}/Tax`) |
58 |
|
59 | const response = await fetch(url, { |
60 | method: 'POST', |
61 | headers: { |
62 | Accept: 'application/json', |
63 | 'Xero-Tenant-Id': Xero_Tenant_Id, |
64 | 'Idempotency-Key': Idempotency_Key, |
65 | 'Content-Type': 'application/json', |
66 | Authorization: 'Bearer ' + auth.token |
67 | }, |
68 | body: JSON.stringify(body) |
69 | }) |
70 | if (!response.ok) { |
71 | const text = await response.text() |
72 | throw new Error(`${response.status} ${text}`) |
73 | } |
74 | return await response.json() |
75 | } |
76 |
|