Updates an employee's salary and wages record

Script xero Verified

by hugo697 ยท 12/20/2024

The script

Submitted by hugo697 Bun
Verified 515 days ago
1
//native
2
type Xero = {
3
	token: string
4
}
5
/**
6
 * Updates an employee's salary and wages record
7
 *
8
 */
9
export async function main(
10
	auth: Xero,
11
	EmployeeID: string,
12
	SalaryAndWagesID: string,
13
	Xero_Tenant_Id: string,
14
	Idempotency_Key: string,
15
	body: {
16
		salaryAndWagesID?: string
17
		earningsRateID: string
18
		numberOfUnitsPerWeek: number
19
		ratePerUnit?: number
20
		numberOfUnitsPerDay: number
21
		daysPerWeek?: number
22
		effectiveFrom: string
23
		annualSalary: number
24
		status: 'Active' | 'Pending' | 'History'
25
		paymentType: 'Salary' | 'Hourly'
26
		workPatternType?: 'DaysAndHours' | 'RegularWeek'
27
	}
28
) {
29
	const url = new URL(
30
		`https://api.xero.com/payroll.xro/2.0/Employees/${EmployeeID}/SalaryAndWages/${SalaryAndWagesID}`
31
	)
32

33
	const response = await fetch(url, {
34
		method: 'PUT',
35
		headers: {
36
			Accept: 'application/json',
37
			'Xero-Tenant-Id': Xero_Tenant_Id,
38
			'Idempotency-Key': Idempotency_Key,
39
			'Content-Type': 'application/json',
40
			Authorization: 'Bearer ' + auth.token
41
		},
42
		body: JSON.stringify(body)
43
	})
44
	if (!response.ok) {
45
		const text = await response.text()
46
		throw new Error(`${response.status} ${text}`)
47
	}
48
	return await response.json()
49
}
50