From 6d00930f9c70bde3040161c8d6b5a68a1485e756 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 13 Jun 2024 17:34:33 +0530 Subject: [PATCH] CHANGE_STAFF_ADD_BUSINESS_BRANCH : AADHAVAN --- app/Controllers/StaffController.php | 23 ++++++--- app/Models/StaffModel.php | 16 ++++++ app/Views/client_branch_list.php | 8 ++- app/Views/staff_form.php | 80 ++++++++++++++++++++++++++++- app/Views/staff_list.php | 2 + 5 files changed, 119 insertions(+), 10 deletions(-) diff --git a/app/Controllers/StaffController.php b/app/Controllers/StaffController.php index 6c495f7..c01656c 100644 --- a/app/Controllers/StaffController.php +++ b/app/Controllers/StaffController.php @@ -5,6 +5,7 @@ use App\Helpers\MailHelper; use App\Models\StaffModel; use App\Models\ClientModel; use App\Models\ServiceModel; +use App\Models\BusinessModel; use App\Models\BranchModel; use App\Models\TemplateModel; @@ -17,6 +18,8 @@ class StaffController extends BaseController protected $StaffModel; protected $ClientModel; protected $ServiceModel; + + protected $BusinessModel; protected $BranchModel; protected $TemplateModel; @@ -28,6 +31,7 @@ class StaffController extends BaseController $this->StaffModel = new StaffModel(); $this->ClientModel = new ClientModel(); $this->ServiceModel = new ServiceModel(); + $this->BusinessModel = new BusinessModel(); $this->BranchModel = new BranchModel(); $this->TemplateModel = new TemplateModel(); } @@ -100,8 +104,9 @@ class StaffController extends BaseController if(!$this->session->has('is_staff_logged_in')){ return redirect()->to(base_url().'staff'); } - $data['staffList'] = $this->StaffModel->where('staff.staff_id != ',session()->get('is_staff_logged_in') )->where('branch_id',$this->session->get('logged_in_staff_branch_id'))->findAll(); - + $data['staffList'] = $this->StaffModel->getStaffWithBusinessAndBranch(session()->get('is_staff_logged_in'), $this->session->get('logged_in_staff_branch_id')); + + $staffdata = $this->StaffModel->where('staff_id',$this->session->get('is_staff_logged_in'))->get()->getRow(); echo view('layout/header', ['Data'=>$staffdata]); echo view('staff_list',$data); @@ -114,8 +119,9 @@ class StaffController extends BaseController if($this->request->getmethod() == 'POST') { $staffData = $this->request->getVar(); + // print_r($staffData);die; $staffData['created_by'] = $this->session->get('is_staff_logged_in'); - $staffData['branch_id'] = $this->session->get('logged_in_staff_branch_id'); + // $staffData['branch_id'] = $this->session->get('logged_in_staff_branch_id'); $insert = $this->StaffModel->save($staffData); if($insert) { @@ -125,8 +131,11 @@ class StaffController extends BaseController }else{ $staffdata = $this->StaffModel->where('staff_id',$this->session->get('is_staff_logged_in'))->get()->getRow(); + $data['business'] = $this->BusinessModel->where('isactive', 1)->findAll(); + $data['branch'] = $this->BranchModel->where('isactive', 1)->findAll(); + $data['page_heading'] = "Create Staff"; echo view('layout/header', ['Data'=>$staffdata]); - echo view('staff_form'); + echo view('staff_form', $data); echo view('layout/footer'); } } @@ -146,8 +155,10 @@ class StaffController extends BaseController $data['staffData'] = $this->StaffModel->where('md5(staff.staff_id)', $this->request->getVar('staff_id') )->get()->getRow(); $staffdata = $this->StaffModel->where('staff_id',$this->session->get('is_staff_logged_in'))->get()->getRow(); - - echo view('layout/header', ['Data'=>$staffdata]); + $data['business'] = $this->BusinessModel->where('isactive', 1)->findAll(); + $data['branch'] = $this->BranchModel->where('isactive', 1)->findAll(); + $data['page_heading'] = "Edit Staff"; + echo view('layout/header', ['Data'=>$staffdata]); echo view('staff_form',$data); echo view('layout/footer'); diff --git a/app/Models/StaffModel.php b/app/Models/StaffModel.php index d3b2d2c..e6a5428 100644 --- a/app/Models/StaffModel.php +++ b/app/Models/StaffModel.php @@ -43,5 +43,21 @@ class StaffModel extends Model } } + + public function getStaffWithBusinessAndBranch($is_staff_logged_in, $logged_in_staff_branch_id) { + $query = $this->db->table('staff') + ->select('staff.*, business.business_name AS business_name, branches.branch_name AS branch_name') + ->join('business', 'business.business_id = staff.business_id') + ->join('branches', 'branches.branch_id = staff.branch_id') + ->where('staff.staff_id != ', $is_staff_logged_in) + ->where('staff.branch_id', $logged_in_staff_branch_id); + + // Execute the query and fetch results as an array + $result = $query->get()->getResultArray(); + + return $result; + } + + } \ No newline at end of file diff --git a/app/Views/client_branch_list.php b/app/Views/client_branch_list.php index 003dab8..f989392 100644 --- a/app/Views/client_branch_list.php +++ b/app/Views/client_branch_list.php @@ -97,7 +97,8 @@