From dee40b166515a62ddb22522bd7eedcac1e20df93 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 11 Jun 2024 14:23:50 +0530 Subject: [PATCH] CHANGE_ADD_CLIENT_BRANCH_CHECK_FULL_UI_AND_CHANGE : AADHAVAN --- app/Config/Routes.php | 14 +- app/Controllers/BranchController.php | 22 ++- app/Controllers/BusinessController.php | 5 + app/Controllers/ClientController.php | 53 ++++++- app/Controllers/StaffController.php | 27 +++- app/Views/branch_list.php | 116 ++++++++------- app/Views/business_list.php | 76 +++++----- app/Views/client_branch_list.php | 194 ++++++++++++++++++++----- app/Views/client_list.php | 153 ++++++++++++++++++- app/Views/layout/header.php | 28 +--- 10 files changed, 503 insertions(+), 185 deletions(-) diff --git a/app/Config/Routes.php b/app/Config/Routes.php index e224d26..9bfb4d5 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -13,7 +13,7 @@ use CodeIgniter\Router\RouteCollection; $routes->match(['get','post'],'/staff_profile','StaffController::staff_profile'); $routes->match(['get','post'],'/staff_create','StaffController::staff_create'); $routes->match(['get','post'],'/client_list','StaffController::client_list'); - $routes->match(['get','post'],'/client_edit','StaffController::client_edit'); + $routes->match(['get','post'],'/client_edit/(:any)','StaffController::client_edit/$1'); $routes->match(['get','post'],'/client_create','StaffController::client_create'); $routes->post("change_staff_password/(:any)", "StaffController::change_staff_password/$1"); $routes->match(['get','post'],'/forgot_password','StaffController::forgot_password'); @@ -34,9 +34,12 @@ use CodeIgniter\Router\RouteCollection; $routes->post('status_client','ClientController::status_client'); $routes->post('doc_rejection','ClientController::doc_rejection'); $routes->match(['get','post'],'/client_branch_list','ClientController::client_branch_list'); + $routes->post('add_client_branch','ClientController::add_client_branch'); + $routes->get('get_client_branch/(:any)','ClientController::get_client_branch/$1'); + $routes->get('delete_client_branch/(:any)','ClientController::delete_client_branch/$1'); - + $routes->match(['get','post'],'/service_group_list','MasterController::service_group_list'); $routes->match(['get','post'],'/service_group_create','MasterController::service_group_create'); $routes->match(['get','post'],'/service_group_edit','MasterController::service_group_edit'); @@ -68,16 +71,15 @@ use CodeIgniter\Router\RouteCollection; $routes->get('delete_business/(:any)','BusinessController::delete_business/$1'); $routes->get('get_business/(:any)','BusinessController::get_business/$1'); $routes->get('business','BusinessController::business'); - $routes->post('business_edit','BusinessController::business_edit'); - + $routes->post('business_edit','BusinessController::business_edit'); - $routes->get('branch_index/(:any)','BranchController::branch_index/$1'); + $routes->get('branch_index','BranchController::branch_index'); $routes->get('new_business/(:any)','BranchController::new_business/$1'); $routes->get('delete_branch/(:any)','BranchController::delete_branch/$1'); $routes->get('get_branch/(:any)','BranchController::get_branch/$1'); $routes->post('edit_branch/(:any)','BranchController::edit_branch/$1'); - $routes->post('add_branch/(:any)','BranchController::new_branch/$1'); + $routes->post('add_branch','BranchController::new_branch'); $routes->post('branch_edit','BranchController::branch_edit'); diff --git a/app/Controllers/BranchController.php b/app/Controllers/BranchController.php index 7a22e00..e81708e 100644 --- a/app/Controllers/BranchController.php +++ b/app/Controllers/BranchController.php @@ -22,16 +22,14 @@ class BranchController extends BaseController } - public function branch_index($business_id) + public function branch_index() { $BranchModel = new BranchModel(); $BusinessModel = new BusinessModel(); - $business=$BusinessModel->where('business_id',$business_id)->first(); - $branch=$BranchModel->where('business_id',$business_id)->findAll(); - $data['branch']=$branch; - $data['business_name']=$business['business_name']; - $data['business_id']=$business['business_id']; - + $data['branch'] = $BranchModel->select('branches.*, business.business_name') + ->join('business', 'branches.business_id = business.business_id', 'left') + ->findAll(); + $data['business_list'] = $BusinessModel->findAll(); $staffdata = $this->StaffModel->where('staff_id',$this->session->get('is_staff_logged_in'))->get()->getRow(); echo view('layout/header', ['Data'=>$staffdata]); @@ -59,17 +57,15 @@ class BranchController extends BaseController return view('business_form',$data); } - public function new_branch($business_id) + public function new_branch() { - if ($business_id) { $data = $this->request->getPost(); - $data['business_id'] = $business_id; $BranchModel = new BranchModel(); $BranchModel->insert($data); return; - } + } @@ -114,7 +110,7 @@ class BranchController extends BaseController public function delete_branch($branch_id) { $model = new BranchModel(); - $where = ['branch_id' => $branch_id, 'isactive' => 1]; // Assuming 'isactive' is a column in your database + $where = ['branch_id' => $branch_id]; // Assuming 'isactive' is a column in your database $existingBranch = $model->where($where)->first(); if ($existingBranch) { @@ -127,7 +123,7 @@ class BranchController extends BaseController } - return redirect()->to('branch_index/' . $existingBranch['business_id']); + return redirect()->to('branch_index'); } } \ No newline at end of file diff --git a/app/Controllers/BusinessController.php b/app/Controllers/BusinessController.php index 4647061..30b46c4 100644 --- a/app/Controllers/BusinessController.php +++ b/app/Controllers/BusinessController.php @@ -206,4 +206,9 @@ class BusinessController extends BaseController } + public function business_branch_list() + { + + } + } diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index a3bebd0..e525393 100644 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -257,12 +257,14 @@ class ClientController extends BaseController // $data['clientBranchList'] = $this->ClientBranchModel->select('client.* , COUNT(client_docs.id) as docs_count') - $data['clientBranchList'] = $this->ClientBranchModel->select('*') - // ->join('client_docs', 'client.client_id = client_docs.client_id', 'left') + $data['clientBranchList'] = $this->ClientBranchModel->select('client_branch.*, client.name as client_name') + ->join('client', 'client.client_id = client_branch.client_id', 'left') // ->where('client.branch_id',$this->session->get('logged_in_staff_branch_id')) - // ->groupBy('client.client_id') + // ->groupBy('client_branch.client_id') ->findAll(); - + $data['client_list'] = $this->ClientModel->select('client_id, name')->where('is_active', 1)->findAll(); + // echo"
";
+        // print_r($data);die;
         $staffdata = $this->StaffModel->where('staff_id',$this->session->get('is_staff_logged_in'))->get()->getRow();
         echo view('layout/header', ['Data'=>$staffdata]);
         // echo view('layout/header');
@@ -270,4 +272,47 @@ class ClientController extends BaseController
         echo view('layout/footer');
 	}
 
+
+
+    public function add_client_branch()
+    {
+            $data = $this->request->getPost();
+
+            $this->ClientBranchModel->insert($data);
+
+            return;
+    }
+
+    public function get_client_branch($branch_id)
+    {
+        if ($branch_id) {
+            $branch =$this->ClientBranchModel->where('id',$branch_id)->first();
+
+            return json_encode($branch);
+        }   
+    }
+
+
+    
+    public function delete_client_branch($branch_id)
+    {
+        $where = ['id' => $branch_id]; // Assuming 'isactive' is a column in your database
+        $existingBranch = $this->ClientBranchModel->where($where)->first();
+    
+        if ($existingBranch) {
+            $data['is_active'] = 0;
+            
+            if ($this->ClientBranchModel->update($branch_id, $data)) {
+                session()->setFlashdata('success', 'Deleted successfully.');
+                $this->logger->info("Branch: has been Inactivated successfully. Inactivated ID = ".$branch_id); 
+            }
+        }
+    
+       
+        return redirect()->to('client_branch_list');
+    }
+
 }
+
+
+
diff --git a/app/Controllers/StaffController.php b/app/Controllers/StaffController.php
index ab52fd9..bae1483 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\BranchModel;
 use App\Models\TemplateModel;
 
 use CodeIgniter\API\ResponseTrait;
@@ -16,6 +17,7 @@ class StaffController extends BaseController
     protected $StaffModel;
 	protected $ClientModel;
 	protected $ServiceModel;
+	protected $BranchModel;
 	protected $TemplateModel;
 
 	use ResponseTrait;
@@ -26,6 +28,7 @@ class StaffController extends BaseController
         $this->StaffModel = new StaffModel();
 		$this->ClientModel = new ClientModel();
 		$this->ServiceModel = new ServiceModel();
+		$this->BranchModel = new BranchModel();
 		$this->TemplateModel = new TemplateModel();
     }
 
@@ -161,7 +164,7 @@ class StaffController extends BaseController
 
        
 		$data['clientList'] =  $this->ClientModel->select('client.* , COUNT(client_docs.id) as docs_count')
-									->join('client_docs', 'client.client_id = client_docs.client_id', 'left')
+									->join('client_docs', 'client.client_id = client_docs.client_branch_id', 'left')
 									->where('client.branch_id',$this->session->get('logged_in_staff_branch_id'))
 									->groupBy('client.client_id')
 									->findAll();
@@ -171,7 +174,7 @@ class StaffController extends BaseController
         echo view('client_list',$data);
         echo view('layout/footer');
 	}
-	public function client_edit()
+	public function client_edit($client_id)
 	{
 		if(!$this->session->has('is_staff_logged_in')){ return redirect()->to(base_url().'staff'); }
 		if($this->request->getmethod() == 'POST')
@@ -179,18 +182,21 @@ class StaffController extends BaseController
 				//update staff details
 				$clientData = $this->request->getVar();
                 $clientData['updated_by'] = $this->session->get('is_staff_logged_in');
-				$client_id =  $this->request->getVar('id');
+				$client_id =  $this->request->getVar('client_id');
 				$this->ClientModel->where('client_id', $client_id )->set($clientData)->update();
 
 				return redirect()->to(base_url()."client_list");
 		}else{
 
-            $data['clientData'] =  $this->ClientModel->where('md5(client.client_id)', $this->request->getVar('client_id') )->get()->getRow();
+            // $data['clientData'] =  $this->ClientModel->where('md5(client.client_id)', $this->request->getVar('client_id') )->get()->getRow();
+            $data['clientData'] =  $this->ClientModel->where('client_id', $client_id )->get()->getRow();
+			// print_r($data);die;
             $staffdata = $this->StaffModel->where('staff_id',$this->session->get('is_staff_logged_in'))->get()->getRow();
           
-            echo view('layout/header', ['Data'=>$staffdata]);
-            echo view('client_form',$data);
-            echo view('layout/footer');
+			return json_encode($data['clientData']);
+            // echo view('layout/header', ['Data'=>$staffdata]);
+            // echo view('client_form',$data);
+            // echo view('layout/footer');
 
         }
 
@@ -200,10 +206,15 @@ class StaffController extends BaseController
 		if(!$this->session->has('is_staff_logged_in')){ return redirect()->to(base_url().'staff'); }
 
 		if($this->request->getmethod() == 'POST')
-		{
+		{		
 				$clientData = $this->request->getVar();
                 $clientData['created_by'] = $this->session->get('is_staff_logged_in');
 				$clientData['branch_id'] = $this->session->get('logged_in_staff_branch_id');
+				$business= $this->BranchModel->select('*')
+											 ->join('business' , 'branches.business_id = business.business_id', 'left')
+											 ->where('branches.branch_id ',$clientData['branch_id'])
+											 ->first();
+				$clientData['business_id'] = $business['business_id'];
 				$insert = $this->ClientModel->save($clientData);
 				if($insert) 
 				{
diff --git a/app/Views/branch_list.php b/app/Views/branch_list.php
index 15e9661..aa791fd 100644
--- a/app/Views/branch_list.php
+++ b/app/Views/branch_list.php
@@ -10,7 +10,7 @@
             
-

Branch List -

+

Branch List