1 | |
2 | type Xero = { |
3 | token: string |
4 | } |
5 | |
6 | * Updates a pay run |
7 | * |
8 | */ |
9 | export async function main( |
10 | auth: Xero, |
11 | PayRunID: string, |
12 | Xero_Tenant_Id: string, |
13 | Idempotency_Key: string, |
14 | body: { |
15 | payRunID?: string |
16 | payrollCalendarID?: string |
17 | periodStartDate?: string |
18 | periodEndDate?: string |
19 | paymentDate?: string |
20 | totalCost?: number |
21 | totalPay?: number |
22 | payRunStatus?: 'Draft' | 'Posted' |
23 | payRunType?: 'Scheduled' | 'Unscheduled' | 'EarlierYearUpdate' |
24 | calendarType?: |
25 | | 'Weekly' |
26 | | 'Fortnightly' |
27 | | 'FourWeekly' |
28 | | 'Monthly' |
29 | | 'Annual' |
30 | | 'Quarterly' |
31 | | 'TwiceMonthly' |
32 | postedDateTime?: string |
33 | paySlips?: { |
34 | paySlipID?: string |
35 | employeeID?: string |
36 | payRunID?: string |
37 | lastEdited?: string |
38 | firstName?: string |
39 | lastName?: string |
40 | totalEarnings?: number |
41 | grossEarnings?: number |
42 | totalPay?: number |
43 | totalEmployerTaxes?: number |
44 | totalEmployeeTaxes?: number |
45 | totalDeductions?: number |
46 | totalReimbursements?: number |
47 | totalStatutoryDeductions?: number |
48 | totalSuperannuation?: number |
49 | bacsHash?: string |
50 | paymentMethod?: 'Cheque' | 'Electronically' | 'Manual' |
51 | earningsLines?: { |
52 | earningsLineID?: string |
53 | earningsRateID?: string |
54 | displayName?: string |
55 | ratePerUnit?: number |
56 | numberOfUnits?: number |
57 | fixedAmount?: number |
58 | amount?: number |
59 | isLinkedToTimesheet?: false | true |
60 | isAverageDailyPayRate?: false | true |
61 | isSystemGenerated?: false | true |
62 | }[] |
63 | leaveEarningsLines?: { |
64 | earningsLineID?: string |
65 | earningsRateID?: string |
66 | displayName?: string |
67 | ratePerUnit?: number |
68 | numberOfUnits?: number |
69 | fixedAmount?: number |
70 | amount?: number |
71 | isLinkedToTimesheet?: false | true |
72 | isAverageDailyPayRate?: false | true |
73 | isSystemGenerated?: false | true |
74 | }[] |
75 | timesheetEarningsLines?: { |
76 | earningsLineID?: string |
77 | earningsRateID?: string |
78 | displayName?: string |
79 | ratePerUnit?: number |
80 | numberOfUnits?: number |
81 | fixedAmount?: number |
82 | amount?: number |
83 | isLinkedToTimesheet?: false | true |
84 | isAverageDailyPayRate?: false | true |
85 | isSystemGenerated?: false | true |
86 | }[] |
87 | deductionLines?: { |
88 | deductionTypeID?: string |
89 | displayName?: string |
90 | amount?: number |
91 | subjectToTax?: false | true |
92 | percentage?: number |
93 | }[] |
94 | reimbursementLines?: { |
95 | reimbursementTypeID?: string |
96 | description?: string |
97 | amount?: number |
98 | ratePerUnit?: number |
99 | numberOfUnits?: number |
100 | }[] |
101 | leaveAccrualLines?: { leaveTypeID?: string; numberOfUnits?: number }[] |
102 | superannuationLines?: { |
103 | superannuationTypeID?: string |
104 | displayName?: string |
105 | amount?: number |
106 | fixedAmount?: number |
107 | percentage?: number |
108 | manualAdjustment?: false | true |
109 | }[] |
110 | paymentLines?: { |
111 | paymentLineID?: string |
112 | amount?: number |
113 | accountNumber?: string |
114 | sortCode?: string |
115 | accountName?: string |
116 | }[] |
117 | employeeTaxLines?: { |
118 | taxLineID?: string |
119 | description?: string |
120 | amount?: number |
121 | globalTaxTypeID?: string |
122 | manualAdjustment?: false | true |
123 | }[] |
124 | employerTaxLines?: { |
125 | taxLineID?: string |
126 | description?: string |
127 | amount?: number |
128 | globalTaxTypeID?: string |
129 | manualAdjustment?: false | true |
130 | }[] |
131 | statutoryDeductionLines?: { |
132 | statutoryDeductionTypeID?: string |
133 | amount?: number |
134 | fixedAmount?: number |
135 | manualAdjustment?: false | true |
136 | }[] |
137 | taxSettings?: { |
138 | periodUnits?: number |
139 | periodType?: 'weeks' | 'months' |
140 | taxCode?: |
141 | | 'ND' |
142 | | 'M' |
143 | | 'ME' |
144 | | 'MSL' |
145 | | 'MESL' |
146 | | 'SB' |
147 | | 'S' |
148 | | 'SH' |
149 | | 'ST' |
150 | | 'SBSL' |
151 | | 'SSL' |
152 | | 'SHSL' |
153 | | 'STSL' |
154 | | 'WT' |
155 | | 'CAE' |
156 | | 'EDW' |
157 | | 'NSW' |
158 | | 'STC' |
159 | | 'STCSL' |
160 | specialTaxRate?: string |
161 | lumpSumTaxCode?: string |
162 | lumpSumAmount?: string |
163 | } |
164 | grossEarningsHistory?: { daysPaid?: number; unpaidWeeks?: number } |
165 | }[] |
166 | } |
167 | ) { |
168 | const url = new URL(`https://api.xero.com/payroll.xro/2.0/PayRuns/${PayRunID}`) |
169 |
|
170 | const response = await fetch(url, { |
171 | method: 'PUT', |
172 | headers: { |
173 | Accept: 'application/json', |
174 | 'Xero-Tenant-Id': Xero_Tenant_Id, |
175 | 'Idempotency-Key': Idempotency_Key, |
176 | 'Content-Type': 'application/json', |
177 | Authorization: 'Bearer ' + auth.token |
178 | }, |
179 | body: JSON.stringify(body) |
180 | }) |
181 | if (!response.ok) { |
182 | const text = await response.text() |
183 | throw new Error(`${response.status} ${text}`) |
184 | } |
185 | return await response.json() |
186 | } |
187 |
|