update user company
This commit is contained in:
@@ -154,9 +154,41 @@ class Users extends MY_Admin_Controller {
|
||||
'employee_id' => $this->validatedEmployeeId($this->input->post('employee_id'))
|
||||
];
|
||||
|
||||
$this->dm->setTable('users')->insert($data);
|
||||
|
||||
log_activity(
|
||||
$companyId = (int) $this->companycontext->id();
|
||||
$this->db->trans_begin();
|
||||
|
||||
try {
|
||||
$userId = (int) $this->dm->setTable('users')->insert($data);
|
||||
if ($userId < 1) {
|
||||
throw new RuntimeException('Data pengguna gagal disimpan.');
|
||||
}
|
||||
|
||||
$role = $this->db->select('is_super_admin')->get_where('roles', array(
|
||||
'id' => (int) $data['role_id'],
|
||||
))->row();
|
||||
|
||||
$this->db->insert('user_companies', array(
|
||||
'user_id' => $userId,
|
||||
'company_id' => $companyId,
|
||||
'is_default' => 1,
|
||||
'can_consolidate' => $role && (int) $role->is_super_admin === 1 ? 1 : 0,
|
||||
));
|
||||
|
||||
if (!$this->db->trans_status()) {
|
||||
throw new RuntimeException('Pengguna gagal dihubungkan ke perusahaan aktif.');
|
||||
}
|
||||
|
||||
$this->db->trans_commit();
|
||||
} catch (Throwable $exception) {
|
||||
$this->db->trans_rollback();
|
||||
echo json_encode(array(
|
||||
'status' => false,
|
||||
'message' => $exception->getMessage(),
|
||||
));
|
||||
return;
|
||||
}
|
||||
|
||||
log_activity(
|
||||
'users',
|
||||
'create',
|
||||
'Menambahkan user: ' . $data['username'],
|
||||
|
||||
Reference in New Issue
Block a user