FIX_User UI and Manager deletion changes

This commit is contained in:
venba-Inspriron-3558 2025-10-06 17:50:09 +05:30
parent 915c2861f2
commit b52cad8026
3 changed files with 90 additions and 15 deletions

View File

@ -627,17 +627,24 @@ class UserController extends AdminController
if (!$staff) { if (!$staff) {
return $this->response->setJSON(['status' => 'error','message' => 'Staff not found'])->setStatusCode(404); return $this->response->setJSON(['status' => 'error','message' => 'Staff not found'])->setStatusCode(404);
} }
$role = $staff['role_id'];
$text = $role == 1 ? "Manager" : "Staff";
if ($staff['is_active'] == 1) { if ($staff['is_active'] == 1) {
if($role == 1){ // manager
$result = $this->partnerStaffModel->updateByKey($id);
$message = $result;
}else{ // staff
$result = $this->partnerStaffModel->update($id, ['is_active' => 0]); $result = $this->partnerStaffModel->update($id, ['is_active' => 0]);
$message = "Staff deleted successfully"; $message = $text." deleted successfully";
}
} else { } else {
return $this->response->setJSON(['status' => 'error','message' => 'Staff already deleted'])->setStatusCode(400); return $this->response->setJSON(['status' => 'error','message' => $text.' already deleted'])->setStatusCode(400);
} }
return $this->response->setJSON([ return $this->response->setJSON([
'status' => $result ? 'success' : 'error', 'status' => $result ? 'success' : 'error',
'message' => $result ? $message : "Unable to delete staff. Please try again.", 'message' => $result ? $message : "Unable to delete ".$text.". Please try again.",
'id' => $id 'id' => $id
])->setStatusCode($result ? 200 : 400); ])->setStatusCode($result ? 200 : 400);
} }

View File

@ -47,4 +47,55 @@ class PartnerStaffModel extends Model
// ]; // ];
// protected $skipValidation = false; // protected $skipValidation = false;
public function updateByKey($key)
{
$db = \Config\Database::connect();
$message = "";
// Start transaction
$db->transStart();
try {
// 1. Update manager
$db->table('partner_staff')
->where('id', $key)
->set('is_active', 0)
->update();
$managerRows = $db->affectedRows();
$message = "{$managerRows} manager(s), ";
// 2. Update agents under manager
$db->table('partner_agent')
->where('manager_id', $key)
->set('is_active', 0)
->update();
$agentRows = $db->affectedRows();
$message .= "{$agentRows} agent(s), ";
// 3. Update staff under manager
$db->table('partner_staff')
->where('manager_id', $key)
->set('is_active', 0)
->update();
$staffRows = $db->affectedRows();
$message .= "{$staffRows} staff(s)";
// Complete transaction
$db->transComplete();
// Check transaction status
if ($db->transStatus() === false) {
return "Transaction failed. No updates were applied.";
}
return $message . " are deleted successfully";
} catch (\Exception $e) {
// Rollback in case of exception
$db->transRollback();
return "Error: " . $e->getMessage();
}
}
} }

View File

@ -37,10 +37,10 @@ table.dataTable tbody td {
</style> --> </style> -->
<style> <style>
body { /* body {
font-family: Arial, sans-serif; font-family: Arial, sans-serif;
padding: 20px; padding: 20px;
} } */
#mobile::placeholder, #mobile::placeholder,
#mobile_no::placeholder { #mobile_no::placeholder {
@ -353,8 +353,7 @@ table.dataTable tbody td {
<h4 style="position: relative;">Users</h4> <h4 style="position: relative;">Users</h4>
</div> </div>
</div> --> </div> -->
<table data-custom-table-css="table" class="table table-sm table-hover m-0 table-centered dt-responsive nowrap w-100" cellspacing="1" id="user-table"> <table data-custom-table-css="table" class="table table-sm m-0 table-centered dt-responsive nowrap w-100" cellspacing="a" id="user-table">
<thead class="bg-light"> <thead class="bg-light">
<tr> <tr>
<th class="font-weight-medium">Name</th> <th class="font-weight-medium">Name</th>
@ -874,13 +873,19 @@ table.dataTable tbody td {
{ {
extend: 'csv', extend: 'csv',
text: '<i class="mdi mdi-file-delimited"></i><span class="btn-custom"> CSV </span>', text: '<i class="mdi mdi-file-delimited"></i><span class="btn-custom"> CSV </span>',
className: 'app-btn-primary' className: 'app-btn-primary',
exportOptions: {
columns: ':not(:last-child)'
}
}, },
{ {
extend: 'excel', extend: 'excel',
text: '<i class="mdi mdi-file-excel"></i><span class="btn-custom"> EXCEL </span>', text: '<i class="mdi mdi-file-excel"></i><span class="btn-custom"> EXCEL </span>',
exportOptions: { orthogonal: 'sort' }, exportOptions: { orthogonal: 'sort' },
className: 'app-btn-primary' className: 'app-btn-primary',
exportOptions: {
columns: ':not(:last-child)'
}
} }
] ]
} }
@ -1027,9 +1032,17 @@ table.dataTable tbody td {
}); });
$('body').on('click', '.btnPartnerDelete', function () { $('body').on('click', '.btnPartnerDelete', function () {
var partner_role = $(this).attr('data-role');
var alertText = "You need to remove this user";
if (partner_role == 2) {
alertText = "You need to remove this Staff";
} else if (partner_role == 1) {
alertText = "You need to remove this Manager and related agent and staff are also delete";
}
Swal.fire({ Swal.fire({
title: "Are you sure?", title: "Are you sure?",
text: "You need to remove this user", text: alertText,
icon: "info", icon: "info",
showCancelButton: true, showCancelButton: true,
confirmButtonColor: "#3085d6", confirmButtonColor: "#3085d6",
@ -1165,6 +1178,9 @@ table.dataTable tbody td {
complete: function() { complete: function() {
btn.disabled = false; btn.disabled = false;
btn.innerText = "Submit"; btn.innerText = "Submit";
$('#nhance-partner-modal').removeClass('show').hide();
$('.modal-backdrop').remove();
loadPartner();
} }
}); });
} }
@ -1263,7 +1279,7 @@ table.dataTable tbody td {
row.name, row.name,
row.email, row.email,
row.mobile, row.mobile,
'Staff', row.role_id == 1 ? "Manager" : "Staff",
`<span class="badge ${statusClass}">${statusText}</span>`, `<span class="badge ${statusClass}">${statusText}</span>`,
`<div class="btn-group dropdown"> `<div class="btn-group dropdown">
<a href="javascript:void(0);" class="dropdown-toggle arrow-none btn btn-light btn-sm" data-toggle="dropdown"> <a href="javascript:void(0);" class="dropdown-toggle arrow-none btn btn-light btn-sm" data-toggle="dropdown">
@ -1273,8 +1289,8 @@ table.dataTable tbody td {
<a data-toggle="modal" data-target="#nhance-partner-modal" class="dropdown-item btnPartnerEdit" data-obj='${JSON.stringify(row)}'> <a data-toggle="modal" data-target="#nhance-partner-modal" class="dropdown-item btnPartnerEdit" data-obj='${JSON.stringify(row)}'>
<i data-obj='${JSON.stringify(row)}' class="mdi mdi-pencil mr-2 text-muted font-18 vertical-middle btnPartnerEdit"></i>Edit <i data-obj='${JSON.stringify(row)}' class="mdi mdi-pencil mr-2 text-muted font-18 vertical-middle btnPartnerEdit"></i>Edit
</a> </a>
<a class="dropdown-item btnPartnerDelete" data-id="${row.id}"> <a class="dropdown-item btnPartnerDelete" data-id="${row.id}" data-role="${row.role_id}">
<i data-id="${row.id}" class="mdi mdi-delete mr-2 text-muted font-18 vertical-middle btnPartnerDelete"></i>Delete <i data-id="${row.id}" data-role="${row.role_id}" class="mdi mdi-delete mr-2 text-muted font-18 vertical-middle btnPartnerDelete"></i>Delete
</a> </a>
<a class="dropdown-item btnPartnerPerformance" data-id="${row.id}"> <a class="dropdown-item btnPartnerPerformance" data-id="${row.id}">
<i data-id="${row.id}" class="mdi mdi-speedometer mr-2 text-muted font-18 vertical-middle btnPartnerPerformance"></i>View Performance <i data-id="${row.id}" class="mdi mdi-speedometer mr-2 text-muted font-18 vertical-middle btnPartnerPerformance"></i>View Performance
@ -1699,10 +1715,11 @@ table.dataTable tbody td {
}); });
$(document).on('click', '#btnNhancePartnerAdd', function(){ $(document).on('click', '#btnNhancePartnerAdd', function(){
$('#partner_name').val(''); $('#partner_name').val('');
$('#email').val(''); $('#email_addr').val('');
$('#partner_id').val(''); $('#partner_id').val('');
$('#mobile_no').val(''); $('#mobile_no').val('');
$('#locn').val(''); $('#locn').val('');
$('.modal-title').html('Add Nhance Partner');
$('#PartnerForm').attr('action', '<?php echo base_url('/user/partner');?>'); $('#PartnerForm').attr('action', '<?php echo base_url('/user/partner');?>');
let myModal = new bootstrap.Modal(document.getElementById('nhance-partner-modal')); let myModal = new bootstrap.Modal(document.getElementById('nhance-partner-modal'));
myModal.show(); // open modal myModal.show(); // open modal