1 | |
2 | type Xero = { |
3 | token: string |
4 | } |
5 | |
6 | * Updates a payslip |
7 | * Update lines on a single payslips |
8 | */ |
9 | export async function main( |
10 | auth: Xero, |
11 | PayslipID: string, |
12 | Xero_Tenant_Id: string, |
13 | Idempotency_Key: string, |
14 | body: { |
15 | EarningsLines?: { |
16 | EarningsRateID: string |
17 | CalculationType?: 'USEEARNINGSRATE' | 'ENTEREARNINGSRATE' | 'ANNUALSALARY' |
18 | AnnualSalary?: number |
19 | NumberOfUnitsPerWeek?: number |
20 | RatePerUnit?: number |
21 | NormalNumberOfUnits?: number |
22 | Amount?: number |
23 | NumberOfUnits?: number |
24 | FixedAmount?: number |
25 | }[] |
26 | LeaveEarningsLines?: { |
27 | EarningsRateID?: string |
28 | RatePerUnit?: number |
29 | NumberOfUnits?: number |
30 | PayOutType?: 'DEFAULT' | 'CASHED_OUT' |
31 | }[] |
32 | TimesheetEarningsLines?: { |
33 | EarningsRateID: string |
34 | CalculationType?: 'USEEARNINGSRATE' | 'ENTEREARNINGSRATE' | 'ANNUALSALARY' |
35 | AnnualSalary?: number |
36 | NumberOfUnitsPerWeek?: number |
37 | RatePerUnit?: number |
38 | NormalNumberOfUnits?: number |
39 | Amount?: number |
40 | NumberOfUnits?: number |
41 | FixedAmount?: number |
42 | }[] |
43 | DeductionLines?: { |
44 | DeductionTypeID: string |
45 | CalculationType?: 'FIXEDAMOUNT' | 'PRETAX' | 'POSTTAX' |
46 | Amount?: number |
47 | Percentage?: number |
48 | NumberOfUnits?: number |
49 | }[] |
50 | LeaveAccrualLines?: { |
51 | LeaveTypeID?: string |
52 | NumberOfUnits?: number |
53 | AutoCalculate?: false | true |
54 | }[] |
55 | ReimbursementLines?: { |
56 | ReimbursementTypeID?: string |
57 | Amount?: number |
58 | Description?: string |
59 | ExpenseAccount?: string |
60 | }[] |
61 | SuperannuationLines?: { |
62 | SuperMembershipID?: string |
63 | ContributionType?: 'SGC' | 'SALARYSACRIFICE' | 'EMPLOYERADDITIONAL' | 'EMPLOYEE' |
64 | CalculationType?: 'FIXEDAMOUNT' | 'PERCENTAGEOFEARNINGS' | 'STATUTORY' |
65 | MinimumMonthlyEarnings?: number |
66 | ExpenseAccountCode?: string |
67 | LiabilityAccountCode?: string |
68 | PaymentDateForThisPeriod?: string |
69 | Percentage?: number |
70 | Amount?: number |
71 | }[] |
72 | TaxLines?: { |
73 | PayslipTaxLineID?: string |
74 | Amount?: number |
75 | TaxTypeName?: string |
76 | Description?: string |
77 | ManualTaxType?: |
78 | | 'PAYGMANUAL' |
79 | | 'ETPOMANUAL' |
80 | | 'ETPRMANUAL' |
81 | | 'SCHEDULE5MANUAL' |
82 | | 'SCHEDULE5STSLMANUAL' |
83 | | 'SCHEDULE4MANUAL' |
84 | LiabilityAccount?: string |
85 | }[] |
86 | }[] |
87 | ) { |
88 | const url = new URL(`https://api.xero.com/payroll.xro/1.0/Payslip/${PayslipID}`) |
89 |
|
90 | const response = await fetch(url, { |
91 | method: 'POST', |
92 | headers: { |
93 | Accept: 'application/json', |
94 | 'Xero-Tenant-Id': Xero_Tenant_Id, |
95 | 'Idempotency-Key': Idempotency_Key, |
96 | 'Content-Type': 'application/json', |
97 | Authorization: 'Bearer ' + auth.token |
98 | }, |
99 | body: JSON.stringify(body) |
100 | }) |
101 | if (!response.ok) { |
102 | const text = await response.text() |
103 | throw new Error(`${response.status} ${text}`) |
104 | } |
105 | return await response.json() |
106 | } |
107 |
|