1 | |
2 | type Xero = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Creates a payroll employee |
7 | * |
8 | */ |
9 | export async function main( |
10 | auth: Xero, |
11 | Xero_Tenant_Id: string, |
12 | Idempotency_Key: string, |
13 | body: { |
14 | FirstName: string; |
15 | LastName: string; |
16 | DateOfBirth: string; |
17 | HomeAddress?: { |
18 | AddressLine1: string; |
19 | AddressLine2?: string; |
20 | City?: string; |
21 | Region?: "ACT" | "NSW" | "NT" | "QLD" | "SA" | "TAS" | "VIC" | "WA"; |
22 | PostalCode?: string; |
23 | Country?: string; |
24 | }; |
25 | StartDate?: string; |
26 | Title?: string; |
27 | MiddleNames?: string; |
28 | Email?: string; |
29 | Gender?: "N" | "M" | "F" | "I"; |
30 | Phone?: string; |
31 | Mobile?: string; |
32 | TwitterUserName?: string; |
33 | IsAuthorisedToApproveLeave?: false | true; |
34 | IsAuthorisedToApproveTimesheets?: false | true; |
35 | JobTitle?: string; |
36 | Classification?: string; |
37 | OrdinaryEarningsRateID?: string; |
38 | PayrollCalendarID?: string; |
39 | EmployeeGroupName?: string; |
40 | EmployeeID?: string; |
41 | TerminationDate?: string; |
42 | TerminationReason?: "F" | "I" | "V" | "D" | "R" | "C" | "T"; |
43 | BankAccounts?: { |
44 | StatementText?: string; |
45 | AccountName?: string; |
46 | BSB?: string; |
47 | AccountNumber?: string; |
48 | Remainder?: false | true; |
49 | Amount?: number; |
50 | }[]; |
51 | PayTemplate?: { |
52 | EarningsLines?: { |
53 | EarningsRateID: string; |
54 | CalculationType?: |
55 | | "USEEARNINGSRATE" |
56 | | "ENTEREARNINGSRATE" |
57 | | "ANNUALSALARY"; |
58 | AnnualSalary?: number; |
59 | NumberOfUnitsPerWeek?: number; |
60 | RatePerUnit?: number; |
61 | NormalNumberOfUnits?: number; |
62 | Amount?: number; |
63 | NumberOfUnits?: number; |
64 | FixedAmount?: number; |
65 | }[]; |
66 | DeductionLines?: { |
67 | DeductionTypeID: string; |
68 | CalculationType?: "FIXEDAMOUNT" | "PRETAX" | "POSTTAX"; |
69 | Amount?: number; |
70 | Percentage?: number; |
71 | NumberOfUnits?: number; |
72 | }[]; |
73 | SuperLines?: { |
74 | SuperMembershipID?: string; |
75 | ContributionType?: |
76 | | "SGC" |
77 | | "SALARYSACRIFICE" |
78 | | "EMPLOYERADDITIONAL" |
79 | | "EMPLOYEE"; |
80 | CalculationType?: "FIXEDAMOUNT" | "PERCENTAGEOFEARNINGS" | "STATUTORY"; |
81 | MinimumMonthlyEarnings?: number; |
82 | ExpenseAccountCode?: string; |
83 | LiabilityAccountCode?: string; |
84 | Percentage?: number; |
85 | Amount?: number; |
86 | }[]; |
87 | ReimbursementLines?: { |
88 | ReimbursementTypeID?: string; |
89 | Amount?: number; |
90 | Description?: string; |
91 | ExpenseAccount?: string; |
92 | }[]; |
93 | LeaveLines?: { |
94 | LeaveTypeID?: string; |
95 | CalculationType?: |
96 | | "NOCALCULATIONREQUIRED" |
97 | | "FIXEDAMOUNTEACHPERIOD" |
98 | | "ENTERRATEINPAYTEMPLATE" |
99 | | "BASEDONORDINARYEARNINGS"; |
100 | EntitlementFinalPayPayoutType?: "NOTPAIDOUT" | "PAIDOUT"; |
101 | EmploymentTerminationPaymentType?: "R" | "O"; |
102 | IncludeSuperannuationGuaranteeContribution?: false | true; |
103 | NumberOfUnits?: number; |
104 | AnnualNumberOfUnits?: number; |
105 | FullTimeNumberOfUnitsPerPeriod?: number; |
106 | }[]; |
107 | }; |
108 | OpeningBalances?: { |
109 | OpeningBalanceDate?: string; |
110 | Tax?: string; |
111 | EarningsLines?: { |
112 | EarningsRateID: string; |
113 | CalculationType?: |
114 | | "USEEARNINGSRATE" |
115 | | "ENTEREARNINGSRATE" |
116 | | "ANNUALSALARY"; |
117 | AnnualSalary?: number; |
118 | NumberOfUnitsPerWeek?: number; |
119 | RatePerUnit?: number; |
120 | NormalNumberOfUnits?: number; |
121 | Amount?: number; |
122 | NumberOfUnits?: number; |
123 | FixedAmount?: number; |
124 | }[]; |
125 | DeductionLines?: { |
126 | DeductionTypeID: string; |
127 | CalculationType?: "FIXEDAMOUNT" | "PRETAX" | "POSTTAX"; |
128 | Amount?: number; |
129 | Percentage?: number; |
130 | NumberOfUnits?: number; |
131 | }[]; |
132 | SuperLines?: { |
133 | SuperMembershipID?: string; |
134 | ContributionType?: |
135 | | "SGC" |
136 | | "SALARYSACRIFICE" |
137 | | "EMPLOYERADDITIONAL" |
138 | | "EMPLOYEE"; |
139 | CalculationType?: "FIXEDAMOUNT" | "PERCENTAGEOFEARNINGS" | "STATUTORY"; |
140 | MinimumMonthlyEarnings?: number; |
141 | ExpenseAccountCode?: string; |
142 | LiabilityAccountCode?: string; |
143 | Percentage?: number; |
144 | Amount?: number; |
145 | }[]; |
146 | ReimbursementLines?: { |
147 | ReimbursementTypeID?: string; |
148 | Amount?: number; |
149 | Description?: string; |
150 | ExpenseAccount?: string; |
151 | }[]; |
152 | LeaveLines?: { |
153 | LeaveTypeID?: string; |
154 | CalculationType?: |
155 | | "NOCALCULATIONREQUIRED" |
156 | | "FIXEDAMOUNTEACHPERIOD" |
157 | | "ENTERRATEINPAYTEMPLATE" |
158 | | "BASEDONORDINARYEARNINGS"; |
159 | EntitlementFinalPayPayoutType?: "NOTPAIDOUT" | "PAIDOUT"; |
160 | EmploymentTerminationPaymentType?: "R" | "O"; |
161 | IncludeSuperannuationGuaranteeContribution?: false | true; |
162 | NumberOfUnits?: number; |
163 | AnnualNumberOfUnits?: number; |
164 | FullTimeNumberOfUnitsPerPeriod?: number; |
165 | }[]; |
166 | PaidLeaveEarningsLines?: { |
167 | LeaveTypeID: string; |
168 | Amount: number; |
169 | SGCAppliedLeaveLoadingAmount?: number; |
170 | SGCExemptedLeaveLoadingAmount?: number; |
171 | ResetSTPCategorisation?: false | true; |
172 | }[]; |
173 | }; |
174 | TaxDeclaration?: { |
175 | EmployeeID?: string; |
176 | EmploymentBasis?: |
177 | | "FULLTIME" |
178 | | "PARTTIME" |
179 | | "CASUAL" |
180 | | "LABOURHIRE" |
181 | | "SUPERINCOMESTREAM" |
182 | | "NONEMPLOYEE"; |
183 | TFNExemptionType?: "NOTQUOTED" | "PENDING" | "PENSIONER" | "UNDER18"; |
184 | TaxFileNumber?: string; |
185 | ABN?: string; |
186 | AustralianResidentForTaxPurposes?: false | true; |
187 | ResidencyStatus?: |
188 | | "AUSTRALIANRESIDENT" |
189 | | "FOREIGNRESIDENT" |
190 | | "WORKINGHOLIDAYMAKER"; |
191 | TaxScaleType?: |
192 | | "WORKINGHOLIDAYMAKER" |
193 | | "REGULAR" |
194 | | "ACTORSARTISTSENTERTAINERS" |
195 | | "HORTICULTURISTORSHEARER" |
196 | | "SENIORORPENSIONER" |
197 | | "FOREIGN"; |
198 | WorkCondition?: "PROMOTIONAL" | "THREELESSPERFORMANCESPERWEEK" | "NONE"; |
199 | SeniorMaritalStatus?: |
200 | | "MEMBEROFCOUPLE" |
201 | | "MEMBEROFILLNESSSEPARATEDCOUPLE" |
202 | | "SINGLE"; |
203 | TaxFreeThresholdClaimed?: false | true; |
204 | TaxOffsetEstimatedAmount?: number; |
205 | HasHELPDebt?: false | true; |
206 | HasSFSSDebt?: false | true; |
207 | HasTradeSupportLoanDebt?: false | true; |
208 | UpwardVariationTaxWithholdingAmount?: number; |
209 | EligibleToReceiveLeaveLoading?: false | true; |
210 | ApprovedWithholdingVariationPercentage?: number; |
211 | HasStudentStartupLoan?: false | true; |
212 | HasLoanOrStudentDebt?: false | true; |
213 | UpdatedDateUTC?: string; |
214 | }; |
215 | IncomeType?: |
216 | | "LABOURHIRE" |
217 | | "NONEMPLOYEE" |
218 | | "WORKINGHOLIDAYMAKER" |
219 | | "SALARYANDWAGES" |
220 | | "CLOSELYHELDPAYEES"; |
221 | EmploymentType?: "EMPLOYEE" | "CONTRACTOR"; |
222 | CountryOfResidence?: |
223 | | "SA" |
224 | | "AF" |
225 | | "AX" |
226 | | "AL" |
227 | | "DZ" |
228 | | "AS" |
229 | | "AD" |
230 | | "AO" |
231 | | "AI" |
232 | | "AQ" |
233 | | "AG" |
234 | | "AR" |
235 | | "AM" |
236 | | "AW" |
237 | | "AU" |
238 | | "AT" |
239 | | "AZ" |
240 | | "BS" |
241 | | "BH" |
242 | | "BD" |
243 | | "BB" |
244 | | "BY" |
245 | | "BE" |
246 | | "BZ" |
247 | | "BJ" |
248 | | "BM" |
249 | | "BT" |
250 | | "BO" |
251 | | "BA" |
252 | | "BW" |
253 | | "BV" |
254 | | "BR" |
255 | | "IO" |
256 | | "BN" |
257 | | "BG" |
258 | | "BF" |
259 | | "BI" |
260 | | "KH" |
261 | | "CM" |
262 | | "CA" |
263 | | "CV" |
264 | | "KY" |
265 | | "CF" |
266 | | "TD" |
267 | | "CL" |
268 | | "CN" |
269 | | "CX" |
270 | | "CC" |
271 | | "CO" |
272 | | "KM" |
273 | | "CG" |
274 | | "CD" |
275 | | "CK" |
276 | | "CR" |
277 | | "CI" |
278 | | "HR" |
279 | | "CU" |
280 | | "CY" |
281 | | "CZ" |
282 | | "DK" |
283 | | "DJ" |
284 | | "DM" |
285 | | "DO" |
286 | | "EC" |
287 | | "EG" |
288 | | "SV" |
289 | | "GQ" |
290 | | "ER" |
291 | | "EE" |
292 | | "ET" |
293 | | "FK" |
294 | | "FO" |
295 | | "FJ" |
296 | | "FI" |
297 | | "FR" |
298 | | "GF" |
299 | | "PF" |
300 | | "TF" |
301 | | "GA" |
302 | | "GM" |
303 | | "GE" |
304 | | "DE" |
305 | | "GH" |
306 | | "GI" |
307 | | "GR" |
308 | | "GL" |
309 | | "GD" |
310 | | "GP" |
311 | | "GU" |
312 | | "GT" |
313 | | "GG" |
314 | | "GN" |
315 | | "GW" |
316 | | "GY" |
317 | | "HT" |
318 | | "HM" |
319 | | "VA" |
320 | | "HN" |
321 | | "HK" |
322 | | "HU" |
323 | | "IS" |
324 | | "IN" |
325 | | "ID" |
326 | | "IR" |
327 | | "IQ" |
328 | | "IE" |
329 | | "IM" |
330 | | "IL" |
331 | | "IT" |
332 | | "JM" |
333 | | "JP" |
334 | | "JE" |
335 | | "JO" |
336 | | "KZ" |
337 | | "KE" |
338 | | "KI" |
339 | | "KP" |
340 | | "KR" |
341 | | "KW" |
342 | | "KG" |
343 | | "LA" |
344 | | "LV" |
345 | | "LB" |
346 | | "LS" |
347 | | "LR" |
348 | | "LY" |
349 | | "LI" |
350 | | "LT" |
351 | | "LU" |
352 | | "MO" |
353 | | "MK" |
354 | | "MG" |
355 | | "MW" |
356 | | "MY" |
357 | | "MV" |
358 | | "ML" |
359 | | "MT" |
360 | | "MH" |
361 | | "MQ" |
362 | | "MR" |
363 | | "MU" |
364 | | "YT" |
365 | | "MX" |
366 | | "FM" |
367 | | "MD" |
368 | | "MC" |
369 | | "MN" |
370 | | "ME" |
371 | | "MS" |
372 | | "MA" |
373 | | "MZ" |
374 | | "MM" |
375 | | "NA" |
376 | | "NR" |
377 | | "NP" |
378 | | "NL" |
379 | | "AN" |
380 | | "NC" |
381 | | "NZ" |
382 | | "NI" |
383 | | "NE" |
384 | | "NG" |
385 | | "NU" |
386 | | "NF" |
387 | | "MP" |
388 | | "NO" |
389 | | "OM" |
390 | | "PK" |
391 | | "PW" |
392 | | "PS" |
393 | | "PA" |
394 | | "PG" |
395 | | "PY" |
396 | | "PE" |
397 | | "PH" |
398 | | "PN" |
399 | | "PL" |
400 | | "PT" |
401 | | "PR" |
402 | | "QA" |
403 | | "RE" |
404 | | "RO" |
405 | | "RU" |
406 | | "RW" |
407 | | "BL" |
408 | | "SH" |
409 | | "KN" |
410 | | "LC" |
411 | | "MF" |
412 | | "PM" |
413 | | "VC" |
414 | | "WS" |
415 | | "SM" |
416 | | "ST" |
417 | | "SN" |
418 | | "RS" |
419 | | "SC" |
420 | | "SL" |
421 | | "SG" |
422 | | "SK" |
423 | | "SI" |
424 | | "SB" |
425 | | "SO" |
426 | | "ZA" |
427 | | "GS" |
428 | | "ES" |
429 | | "LK" |
430 | | "SD" |
431 | | "SR" |
432 | | "SJ" |
433 | | "SZ" |
434 | | "SE" |
435 | | "CH" |
436 | | "SY" |
437 | | "TW" |
438 | | "TJ" |
439 | | "TZ" |
440 | | "TH" |
441 | | "TL" |
442 | | "TG" |
443 | | "TK" |
444 | | "TO" |
445 | | "TT" |
446 | | "TN" |
447 | | "TR" |
448 | | "TM" |
449 | | "TC" |
450 | | "TV" |
451 | | "UG" |
452 | | "UA" |
453 | | "AE" |
454 | | "GB" |
455 | | "US" |
456 | | "UM" |
457 | | "UY" |
458 | | "UZ" |
459 | | "VU" |
460 | | "VE" |
461 | | "VN" |
462 | | "VG" |
463 | | "VI" |
464 | | "WF" |
465 | | "EH" |
466 | | "YE" |
467 | | "ZM" |
468 | | "ZW" |
469 | | "BQ" |
470 | | "CW" |
471 | | "SX" |
472 | | "SS"; |
473 | IsSTP2Qualified?: false | true; |
474 | LeaveBalances?: { |
475 | LeaveName?: string; |
476 | LeaveTypeID?: string; |
477 | NumberOfUnits?: number; |
478 | TypeOfUnits?: string; |
479 | }[]; |
480 | LeaveLines?: { |
481 | LeaveTypeID?: string; |
482 | CalculationType?: |
483 | | "NOCALCULATIONREQUIRED" |
484 | | "FIXEDAMOUNTEACHPERIOD" |
485 | | "ENTERRATEINPAYTEMPLATE" |
486 | | "BASEDONORDINARYEARNINGS"; |
487 | EntitlementFinalPayPayoutType?: "NOTPAIDOUT" | "PAIDOUT"; |
488 | EmploymentTerminationPaymentType?: "R" | "O"; |
489 | IncludeSuperannuationGuaranteeContribution?: false | true; |
490 | NumberOfUnits?: number; |
491 | AnnualNumberOfUnits?: number; |
492 | FullTimeNumberOfUnitsPerPeriod?: number; |
493 | }[]; |
494 | SuperMemberships?: { |
495 | SuperMembershipID?: string; |
496 | SuperFundID: string; |
497 | EmployeeNumber: string; |
498 | }[]; |
499 | Status?: "ACTIVE" | "TERMINATED"; |
500 | UpdatedDateUTC?: string; |
501 | ValidationErrors?: { Message?: string }[]; |
502 | }[], |
503 | ) { |
504 | const url = new URL(`https://api.xero.com/payroll.xro/1.0/Employees`); |
505 |
|
506 | const response = await fetch(url, { |
507 | method: "POST", |
508 | headers: { |
509 | Accept: 'application/json', |
510 | "Xero-Tenant-Id": Xero_Tenant_Id, |
511 | "Idempotency-Key": Idempotency_Key, |
512 | "Content-Type": "application/json", |
513 | Authorization: "Bearer " + auth.token, |
514 | }, |
515 | body: JSON.stringify(body), |
516 | }); |
517 | if (!response.ok) { |
518 | const text = await response.text(); |
519 | throw new Error(`${response.status} ${text}`); |
520 | } |
521 | return await response.json(); |
522 | } |
523 |
|