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