CHANGE_USER_CURD

This commit is contained in:
aadhavan valli 2024-09-02 17:07:58 +05:30
parent 9f1c0ab40e
commit 0c0170a7cc
5 changed files with 30 additions and 52 deletions

View File

@ -7,6 +7,7 @@ use App\Controllers\BaseController;
use CodeIgniter\Validation\Exceptions\ValidationException; use CodeIgniter\Validation\Exceptions\ValidationException;
use App\Models\Costcenter_model; use App\Models\Costcenter_model;
use App\Models\Department_model;
use App\Models\Dashboard_model; use App\Models\Dashboard_model;
use App\Models\Employeedetails_model; use App\Models\Employeedetails_model;
use App\Models\User_model; use App\Models\User_model;
@ -26,6 +27,7 @@ require_once 'vendor/autoload.php';
class User extends BaseController class User extends BaseController
{ {
protected $costcenter_model; protected $costcenter_model;
protected $department_model;
protected $dahsboard_Model; protected $dahsboard_Model;
protected $employeedetails_model; protected $employeedetails_model;
protected $user_model; protected $user_model;
@ -42,6 +44,7 @@ class User extends BaseController
$this->dahsboard_Model = new Dashboard_model(); $this->dahsboard_Model = new Dashboard_model();
$this->costcenter_model = new Costcenter_model(); $this->costcenter_model = new Costcenter_model();
$this->department_model = new Department_model();
$this->employeedetails_model = new employeedetails_model(); $this->employeedetails_model = new employeedetails_model();
$this->user_model = new User_model(); $this->user_model = new User_model();
$this->ipinvoice_model = new Ipinvoice_model(); $this->ipinvoice_model = new Ipinvoice_model();
@ -918,8 +921,14 @@ class User extends BaseController
// { // {
$data['EmpList'] = $this->user_model->getAllEmployees(); $data['EmpList'] = $this->user_model->getAllEmployees();
$data['roles'] = $this->user_model->getUserRoles(); $data['roles'] = $this->user_model->getUserRoles();
// $data['Department'] = $this->costcenter_model->getDepartment(); $data['Department'] = json_decode(json_encode($this->department_model->departmentListing()), true);
// echo "<pre>";
// print_r($data['Department']);
// die;
// echo "<pre>";
// print_r($data['Department']);die;
$this->global['pageTitle'] = 'Add New User'; $this->global['pageTitle'] = 'Add New User';
$this->loadViews("addUser", $this->global, $data, NULL); $this->loadViews("addUser", $this->global, $data, NULL);
// } // }

View File

@ -134,16 +134,19 @@ class User_model extends Model
* @param number $userId : This is user id * @param number $userId : This is user id
* @return boolean $result : TRUE / FALSE * @return boolean $result : TRUE / FALSE
*/ */
function deleteUser($userId, $userInfo) function deleteUser($userId)
{ {
// Delete the user record
$this->db->table('tbl_users') $this->db->table('tbl_users')
->where('userId', $userId) ->where('userId', $userId)
->update($userInfo); ->delete();
// Return the number of affected rows to confirm the deletion
return $this->db->affectedRows(); return $this->db->affectedRows();
} }
/** /**
* This function is used to match users password for change password * This function is used to match users password for change password
* @param number $userId : This is user id * @param number $userId : This is user id
@ -215,7 +218,9 @@ class User_model extends Model
$builder = $this->db->table('t_employee_details EMP') $builder = $this->db->table('t_employee_details EMP')
->select('EMP.EmpID,EMP.FirstName,EMP.LastName,EMP.Designation,EMP.EmailId,EMP.ContactNumber,DEPT.DEPCode,DEPT.DepartmentName') ->select('EMP.EmpID,EMP.FirstName,EMP.LastName,EMP.Designation,EMP.EmailId,EMP.ContactNumber,DEPT.DEPCode,DEPT.DepartmentName')
->join('t_departmentdetails DEPT', 'EMP.Departmentcode = DEPT.DEPCode') ->join('t_departmentdetails DEPT', 'EMP.Departmentcode = DEPT.DEPCode')
->where('EMP.IsActive ', 1); ->join('tbl_users U', 'EMP.EmpID = U.EmpID', 'left')
->where('EMP.IsActive ', 1)
->where('U.EmpID IS NULL');
$query = $builder->get(); $query = $builder->get();
return $query->getResult(); return $query->getResult();
} }
@ -311,10 +316,9 @@ GROUP BY financial_year ";
function findEmp($EmpId) function findEmp($EmpId)
{ {
$builder = $this->db->table('tbl_users') $builder = $this->db->table('t_employee_details')
->select('tbl_users.*, t_employee_details.*') ->select('t_employee_details.*')
->join('t_employee_details', 'tbl_users.EmpID = t_employee_details.EmpID' ,'left') ->where('t_employee_details.EmpID', $EmpId);
->where('tbl_users.EmpID', $EmpId);
$query = $builder->get(); $query = $builder->get();
return $query->getResult(); return $query->getResult();

View File

@ -81,22 +81,6 @@
?> ?>
</select> </select>
</div> </div>
<div class="col-md-3">
<label for="Department">Department</label>
<select class="form-control required" id="Department" name="Department">
<option value="0">Select Department</option>
<?php
if (!empty($departments)) {
foreach ($departments as $dt) {
?>
<option value="<?php echo $dt->departmentId ?>"><?php echo $dt->departments ?></option>
<?php
}
}
?>
</select>
</div>
</div> </div>
<div class="form-row" style="margin-top:20px"> <div class="form-row" style="margin-top:20px">
@ -194,7 +178,6 @@
$("#Designation").val(data.userInfo[0].Designation); $("#Designation").val(data.userInfo[0].Designation);
$("#MailID").val(data.userInfo[0].EmailId); $("#MailID").val(data.userInfo[0].EmailId);
$("#ContactNo").val(data.userInfo[0].ContactNumber); $("#ContactNo").val(data.userInfo[0].ContactNumber);
$("#Department").val(data.userInfo[0].DepartmentName);
} else { } else {
alert('Employee not found'); alert('Employee not found');
} }
@ -210,7 +193,6 @@
$("#Designation").val(''); $("#Designation").val('');
$("#MailID").val(''); $("#MailID").val('');
$("#ContactNo").val(''); $("#ContactNo").val('');
$("#Department").val('');
} }
}); });
}); });
@ -218,20 +200,17 @@
$('#addPop').click(function() { $('#addPop').click(function() {
if ($('#distriList option:selected').val() != null) { if ($('#distriList option:selected').val() != null) {
if ($('#distriList option:selected').val() == 0) { if ($('#distriList option:selected').val() == 0) {
alert('please select Department');
} else { } else {
var tempSelect = $('#distriList option:selected').val(); var tempSelect = $('#distriList option:selected').val();
var tempText = $('#distriList option:selected').text(); var tempText = $('#distriList option:selected').text();
var o = new Option(tempText, tempSelect); var o = new Option(tempText, tempSelect);
var hidval = tempSelect; var hidval = tempSelect;
var orgVal = $('#txtSelectedDepartment').val();
var Selectedval = '' var Selectedval = ''
if (orgVal != '') { if (orgVal != '') {
Selectedval = orgVal + ':' + hidval; Selectedval = orgVal + ':' + hidval;
} else { } else {
Selectedval = hidval Selectedval = hidval
} }
$('#txtSelectedDepartment').val(Selectedval);
$(o).html(tempText); $(o).html(tempText);
$("#selectDistriList").append(o); $("#selectDistriList").append(o);
$('#distriList option:selected').remove(); $('#distriList option:selected').remove();

View File

@ -8,7 +8,6 @@ $LastName = '';
$ContactNo = ''; $ContactNo = '';
$EmailId = ''; $EmailId = '';
$Role = ''; $Role = '';
$Department = '';
$Designation = ''; $Designation = '';
$RoleName = ''; $RoleName = '';
if(!empty($EmpRole)) if(!empty($EmpRole))
@ -30,7 +29,6 @@ if(!empty($EmpList))
$ContactNo = $Emp->ContactNumber; $ContactNo = $Emp->ContactNumber;
$EmailId = $Emp->EmailId; $EmailId = $Emp->EmailId;
$Department = $Emp->DepartmentName;
$Designation = $Emp->Designation; $Designation = $Emp->Designation;
} }
@ -79,10 +77,7 @@ if(!empty($EmpList))
</div> </div>
</div> </div>
<div class="form-row"> <div class="form-row">
<div class="col-md-3">
<label class="col-form-label" for="Department">Department</label>
<input type="text" class="form-control required" value="<?php echo $Department ?>" readonly id="Department" name="Department" minlength="10" maxlength="10">
</div>
<div class="col-md-3"> <div class="col-md-3">
<label for="MailID">Email address</label> <label for="MailID">Email address</label>
<input type="text" class="form-control required email" value="<?php echo $EmailId ?>" readonly id="MailID" name="MailID" maxlength="128"> <input type="text" class="form-control required email" value="<?php echo $EmailId ?>" readonly id="MailID" name="MailID" maxlength="128">
@ -91,12 +86,12 @@ if(!empty($EmpList))
<label for="ContactNo">Contact Number</label> <label for="ContactNo">Contact Number</label>
<input type="text" class="form-control required digits" value="<?php echo $ContactNo ?>" readonly id="ContactNo" name="ContactNo" minlength="10" maxlength="10"> <input type="text" class="form-control required digits" value="<?php echo $ContactNo ?>" readonly id="ContactNo" name="ContactNo" minlength="10" maxlength="10">
</div> </div>
<div class="col-md-3"> </div>
<div class="form-row">
<div class="col-md-3">
<label for="password">Password</label> <label for="password">Password</label>
<input type="password" class="form-control" id="password" required name="password" maxlength="10"> <input type="password" class="form-control" id="password" required name="password" maxlength="10">
</div> </div>
</div>
<div class="form-row">
<div class="col-md-3"> <div class="col-md-3">
<label for="cpassword">Confirm Password</label> <label for="cpassword">Confirm Password</label>
<input type="password" class="form-control equalTo" id="cpassword" name="cpassword" maxlength="10"> <input type="password" class="form-control equalTo" id="cpassword" name="cpassword" maxlength="10">
@ -105,7 +100,6 @@ if(!empty($EmpList))
</div> </div>
<div class="form-group text-right mt-3"> <div class="form-group text-right mt-3">
<input type="hidden" name="txtSelectedDepartment" id="txtSelectedDepartment">
<input type="hidden" name="txtEmpid" id="txtEmpid" value="<?php echo $EmpId ?>"> <input type="hidden" name="txtEmpid" id="txtEmpid" value="<?php echo $EmpId ?>">
<input type="reset" id="reset" class="btn btn-reset" style="background-color: red;color: white;margin-right: 15px;" value="Reset"> <input type="reset" id="reset" class="btn btn-reset" style="background-color: red;color: white;margin-right: 15px;" value="Reset">
<input type="submit" class="btn btn-success" value="Submit"> <input type="submit" class="btn btn-success" value="Submit">
@ -158,7 +152,6 @@ if(!empty($EmpList))
$('#addPop').click(function () { $('#addPop').click(function () {
if ($('#distriList option:selected').val() != null) { if ($('#distriList option:selected').val() != null) {
if($('#distriList option:selected').val()==0 ){ if($('#distriList option:selected').val()==0 ){
alert('please select Department');
} }
else{ else{
var tempSelect = $('#distriList option:selected').val(); var tempSelect = $('#distriList option:selected').val();
@ -167,7 +160,6 @@ if(!empty($EmpList))
var o = new Option(tempText,tempSelect); var o = new Option(tempText,tempSelect);
var hidval = tempSelect; var hidval = tempSelect;
var orgVal = $('#txtSelectedDepartment').val();
//salert(orgVal); //salert(orgVal);
var Selectedval = '' var Selectedval = ''
@ -179,9 +171,7 @@ if(!empty($EmpList))
{ {
Selectedval = hidval Selectedval = hidval
} }
$('#txtSelectedDepartment').val(Selectedval);
var Department= $('#txtSelectedDepartment').val();
$(o).html(tempText); $(o).html(tempText);
@ -196,7 +186,7 @@ if(!empty($EmpList))
$('#content').loader('show'); $('#content').loader('show');
$.ajax({ $.ajax({
data:{Eid:Eid,Department:Department}, data:{Eid:Eid},
type:"POST", type:"POST",
url:"<?php echo base_url() ?>user/Adduserdepartment", url:"<?php echo base_url() ?>user/Adduserdepartment",
@ -205,7 +195,6 @@ if(!empty($EmpList))
{ {
$('#content').loader('hide'); $('#content').loader('hide');
alert(data); alert(data);
$('#txtSelectedDepartment').val('');
$('#txtRowCount').val(''); $('#txtRowCount').val('');
//window.location = baseurl + 'CostCenter/CostListing'; //window.location = baseurl + 'CostCenter/CostListing';
@ -251,15 +240,13 @@ if(!empty($EmpList))
$("#distriList").attr('selectedIndex', '-1').find("option:selected").removeAttr("selected"); $("#distriList").attr('selectedIndex', '-1').find("option:selected").removeAttr("selected");
$("#distriList").val(tempSelect); $("#distriList").val(tempSelect);
$('#txtSelectedDepartment').val(tempSelect);
tempSelect = ''; tempSelect = '';
var Department= $('#txtSelectedDepartment').val();
$('#content').loader('show'); $('#content').loader('show');
$.ajax({ $.ajax({
data:{Eid:Eid,Department:Department}, data:{Eid:Eid},
type:"POST", type:"POST",
url:"<?php echo base_url() ?>user/Deleteuserdepartment", url:"<?php echo base_url() ?>user/Deleteuserdepartment",
success:function(data) { success:function(data) {
@ -267,7 +254,6 @@ if(!empty($EmpList))
{ {
$('#content').loader('hide'); $('#content').loader('hide');
alert(data); alert(data);
$('#txtSelectedDepartment').val('');
$('#txtRowCount').val(''); $('#txtRowCount').val('');
//window.location = baseurl + 'CostCenter/CostListing'; //window.location = baseurl + 'CostCenter/CostListing';

View File

@ -165,8 +165,8 @@
url: "<?php echo base_url() ?>user/deleteUser", url: "<?php echo base_url() ?>user/deleteUser",
success: function(data) { success: function(data) {
if (data) { if (data) {
$('#content').loader('hide'); // $('#content').loader('hide');
alert(data); // alert(data);
location.reload(); location.reload();