@@ -111,173 +111,4 @@ UPDATE companies SET
111
111
legal_entity_type = COALESCE(@legal_entity_type, legal_entity_type),
112
112
updated_at = NOW()
113
113
WHERE id = @id
114
- RETURNING * ;
115
-
116
- -- name: CreateCompanyUser :one
117
- INSERT INTO company_users (
118
- id,
119
- company_id,
120
- user_id,
121
- role,
122
- department,
123
- job_title,
124
- is_administrator,
125
- can_manage_payroll,
126
- can_manage_invoices,
127
- can_manage_employees,
128
- can_manage_company_settings,
129
- can_manage_bank_accounts,
130
- can_manage_wallets,
131
- permissions,
132
- is_active,
133
- added_by,
134
- created_at,
135
- updated_at
136
- ) VALUES (
137
- COALESCE(@id, uuid_generate_v4()),
138
- @company_id,
139
- @user_id,
140
- @role,
141
- @department,
142
- @job_title,
143
- COALESCE(@is_administrator, FALSE),
144
- COALESCE(@can_manage_payroll, FALSE),
145
- COALESCE(@can_manage_invoices, FALSE),
146
- COALESCE(@can_manage_employees, FALSE),
147
- COALESCE(@can_manage_company_settings, FALSE),
148
- COALESCE(@can_manage_bank_accounts, FALSE),
149
- COALESCE(@can_manage_wallets, FALSE),
150
- @permissions,
151
- COALESCE(@is_active, TRUE),
152
- @added_by,
153
- COALESCE(@created_at, NOW()),
154
- COALESCE(@updated_at, NOW())
155
- ) RETURNING * ;
156
-
157
- -- name: GetCompanyUser :one
158
- SELECT cu.* , u .email , u .account_status ,
159
- COALESCE(csp .first_name , pu .first_name ) as first_name,
160
- COALESCE(csp .last_name , pu .last_name ) as last_name
161
- FROM company_users cu
162
- JOIN users u ON cu .user_id = u .id
163
- LEFT JOIN company_staff_profiles csp ON cu .id = csp .id
164
- LEFT JOIN personal_users pu ON u .id = pu .id
165
- WHERE cu .company_id = @company_id AND cu .user_id = @user_id;
166
-
167
- -- name: GetCompanyUsersByCompany :many
168
- SELECT cu.* , u .email , u .account_status ,
169
- COALESCE(csp .first_name , pu .first_name ) as first_name,
170
- COALESCE(csp .last_name , pu .last_name ) as last_name
171
- FROM company_users cu
172
- JOIN users u ON cu .user_id = u .id
173
- LEFT JOIN company_staff_profiles csp ON cu .id = csp .id
174
- LEFT JOIN personal_users pu ON u .id = pu .id
175
- WHERE cu .company_id = @company_id AND cu .is_active = TRUE
176
- ORDER BY cu .created_at DESC ;
177
-
178
- -- name: UpdateCompanyUser :one
179
- UPDATE company_users SET
180
- role = COALESCE(@role, role),
181
- department = COALESCE(@department, department),
182
- job_title = COALESCE(@job_title, job_title),
183
- is_administrator = COALESCE(@is_administrator, is_administrator),
184
- can_manage_payroll = COALESCE(@can_manage_payroll, can_manage_payroll),
185
- can_manage_invoices = COALESCE(@can_manage_invoices, can_manage_invoices),
186
- can_manage_employees = COALESCE(@can_manage_employees, can_manage_employees),
187
- can_manage_company_settings = COALESCE(@can_manage_company_settings, can_manage_company_settings),
188
- can_manage_bank_accounts = COALESCE(@can_manage_bank_accounts, can_manage_bank_accounts),
189
- can_manage_wallets = COALESCE(@can_manage_wallets, can_manage_wallets),
190
- permissions = COALESCE(@permissions, permissions),
191
- is_active = COALESCE(@is_active, is_active),
192
- updated_at = NOW()
193
- WHERE company_id = @company_id AND user_id = @user_id
194
- RETURNING * ;
195
-
196
- -- name: CreateCompanyEmployee :one
197
- INSERT INTO company_employees (
198
- id,
199
- company_id,
200
- user_id,
201
- employee_id,
202
- department,
203
- position,
204
- employment_status,
205
- employment_type,
206
- start_date,
207
- end_date,
208
- manager_id,
209
- salary_amount,
210
- salary_currency,
211
- salary_frequency,
212
- hourly_rate,
213
- payment_method,
214
- payment_split,
215
- tax_information,
216
- created_at,
217
- updated_at
218
- ) VALUES (
219
- COALESCE(@id, uuid_generate_v4()),
220
- @company_id,
221
- @user_id,
222
- @employee_id,
223
- @department,
224
- @position,
225
- COALESCE(@employment_status, ' active' ),
226
- @employment_type,
227
- @start_date,
228
- @end_date,
229
- @manager_id,
230
- @salary_amount,
231
- @salary_currency,
232
- @salary_frequency,
233
- @hourly_rate,
234
- @payment_method,
235
- @payment_split,
236
- @tax_information,
237
- COALESCE(@created_at, NOW()),
238
- COALESCE(@updated_at, NOW())
239
- ) RETURNING * ;
240
-
241
- -- name: GetCompanyEmployeeByID :one
242
- SELECT ce.* ,
243
- u .email ,
244
- COALESCE(csp .first_name , pu .first_name ) as first_name,
245
- COALESCE(csp .last_name , pu .last_name ) as last_name
246
- FROM company_employees ce
247
- LEFT JOIN users u ON ce .user_id = u .id
248
- LEFT JOIN company_staff_profiles csp ON ce .user_id = csp .id
249
- LEFT JOIN personal_users pu ON u .id = pu .id
250
- WHERE ce .id = @id;
251
-
252
- -- name: GetCompanyEmployeesByCompany :many
253
- SELECT ce.* ,
254
- u .email ,
255
- COALESCE(csp .first_name , pu .first_name ) as first_name,
256
- COALESCE(csp .last_name , pu .last_name ) as last_name
257
- FROM company_employees ce
258
- LEFT JOIN users u ON ce .user_id = u .id
259
- LEFT JOIN company_staff_profiles csp ON ce .user_id = csp .id
260
- LEFT JOIN personal_users pu ON u .id = pu .id
261
- WHERE ce .company_id = @company_id
262
- ORDER BY ce .created_at DESC ;
263
-
264
- -- name: UpdateCompanyEmployee :one
265
- UPDATE company_employees SET
266
- employee_id = COALESCE(@employee_id, employee_id),
267
- department = COALESCE(@department, department),
268
- position = COALESCE(@position, position),
269
- employment_status = COALESCE(@employment_status, employment_status),
270
- employment_type = COALESCE(@employment_type, employment_type),
271
- start_date = COALESCE(@start_date, start_date),
272
- end_date = COALESCE(@end_date, end_date),
273
- manager_id = COALESCE(@manager_id, manager_id),
274
- salary_amount = COALESCE(@salary_amount, salary_amount),
275
- salary_currency = COALESCE(@salary_currency, salary_currency),
276
- salary_frequency = COALESCE(@salary_frequency, salary_frequency),
277
- hourly_rate = COALESCE(@hourly_rate, hourly_rate),
278
- payment_method = COALESCE(@payment_method, payment_method),
279
- payment_split = COALESCE(@payment_split, payment_split),
280
- tax_information = COALESCE(@tax_information, tax_information),
281
- updated_at = NOW()
282
- WHERE id = @id
283
114
RETURNING * ;
0 commit comments