1 | |
2 | type Xero = { |
3 | token: string |
4 | } |
5 | |
6 | * Creates an employee salary and wage record |
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 | salaryAndWagesID?: string |
16 | earningsRateID: string |
17 | numberOfUnitsPerWeek: number |
18 | ratePerUnit?: number |
19 | numberOfUnitsPerDay: number |
20 | daysPerWeek?: number |
21 | effectiveFrom: string |
22 | annualSalary: number |
23 | status: 'Active' | 'Pending' | 'History' |
24 | paymentType: 'Salary' | 'Hourly' |
25 | workPatternType?: 'DaysAndHours' | 'RegularWeek' |
26 | } |
27 | ) { |
28 | const url = new URL(`https://api.xero.com/payroll.xro/2.0/Employees/${EmployeeID}/SalaryAndWages`) |
29 |
|
30 | const response = await fetch(url, { |
31 | method: 'POST', |
32 | headers: { |
33 | Accept: 'application/json', |
34 | 'Xero-Tenant-Id': Xero_Tenant_Id, |
35 | 'Idempotency-Key': Idempotency_Key, |
36 | 'Content-Type': 'application/json', |
37 | Authorization: 'Bearer ' + auth.token |
38 | }, |
39 | body: JSON.stringify(body) |
40 | }) |
41 | if (!response.ok) { |
42 | const text = await response.text() |
43 | throw new Error(`${response.status} ${text}`) |
44 | } |
45 | return await response.json() |
46 | } |
47 |
|