diff --git a/app/Config/Routes.php b/app/Config/Routes.php index c3c8220..8927442 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -58,6 +58,20 @@ use CodeIgniter\Router\RouteCollection; + $routes->get('business_list','BusinessController::business_list'); + $routes->get('new_business/(:any)','BusinessController::new_business/$1'); + $routes->post('add_business','BusinessController::add_business'); + $routes->get('delete_business/(:any)','BusinessController::delete_business/$1'); + $routes->get('get_business/(:any)','BusinessController::get_business/$1'); + + + $routes->get('branch_index/(:any)','BranchController::branch_index/$1'); + $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'); + \ No newline at end of file diff --git a/app/Controllers/BranchController.php b/app/Controllers/BranchController.php new file mode 100644 index 0000000..a6b9d8d --- /dev/null +++ b/app/Controllers/BranchController.php @@ -0,0 +1,118 @@ +session = session(); + $this->StaffModel = new StaffModel(); + + } + + public function branch_index($business_id) + { + $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']; + + $staffdata = $this->StaffModel->where('staff_id',$this->session->get('is_staff_logged_in'))->get()->getRow(); + + echo view('layout/header', ['Data'=>$staffdata]); + echo view('branch_list',$data); + echo view('layout/footer'); + } + + + public function new_business($business_id) + { + + + if ($business_id === '0') { + + $data['business'] = []; + $data['page_name']="Add Business"; + } else if ($business_id !== '0') { + + $BusinessModel = new BusinessModel(); + $business=$BusinessModel->getBusinessById($business_id); + $data['business']=$business; + $data['page_name']="Edit Business" ; + } + $data['business_id'] = $business_id; + + return view('business_form',$data); + } + public function new_branch($business_id) + { + if ($business_id) { + $data = $this->request->getPost(); + $data['business_id'] = $business_id; + $BranchModel = new BranchModel(); + + $BranchModel->insert($data); + + return; + } + } + + + public function get_branch($branch_id) + { + if ($branch_id) { + $BranchModel = new BranchModel(); + $branch =$BranchModel->where('branch_id',$branch_id)->first(); + + return json_encode($branch); + } + } + + + + public function edit_branch($branch_id) + { + if ($branch_id) { + $data = $this->request->getPost(); + $BranchModel = new BranchModel(); + + $BranchModel->update($branch_id,$data); + return json_encode(true); + } + } + + public function delete_branch($branch_id) + { + $model = new BranchModel(); + $where = ['branch_id' => $branch_id, 'isactive' => 1]; // Assuming 'isactive' is a column in your database + $existingBranch = $model->where($where)->first(); + + if ($existingBranch) { + $data['isactive'] = 0; + + if ($model->update($branch_id, $data)) { + session()->setFlashdata('success', 'Deleted successfully.'); + $this->logger->info("Branch: has been Inactivated successfully. Inactivated ID = ".$branch_id); + } + } + + + return redirect()->to('branch_index/' . $existingBranch['business_id']); + } + +} \ No newline at end of file diff --git a/app/Controllers/BusinessController.php b/app/Controllers/BusinessController.php new file mode 100644 index 0000000..cad16eb --- /dev/null +++ b/app/Controllers/BusinessController.php @@ -0,0 +1,144 @@ +session = session(); + $this->BusinessModel = new BusinessModel(); + $this->StaffModel = new StaffModel(); + + } + + public function business_list() + { + $data['business'] = $this->BusinessModel->findAll(); + $staffdata = $this->StaffModel->where('staff_id',$this->session->get('is_staff_logged_in'))->get()->getRow(); + + echo view('layout/header', ['Data'=>$staffdata]); + echo view('business_list',$data); + echo view('layout/footer'); + + } + + + public function new_business($business_id) + { + + + if ($business_id === '0') { + + $data['business'] = []; + $data['page_name']="Add Business"; + } else if ($business_id !== '0') { + + $BusinessModel = new BusinessModel(); + $business=$BusinessModel->getBusinessById($business_id); + $data['business']=$business; + $data['page_name']="Edit Business" ; + } + $data['business_id'] = $business_id; + + $staffdata = $this->StaffModel->where('staff_id',$this->session->get('is_staff_logged_in'))->get()->getRow(); + + echo view('layout/header', ['Data'=>$staffdata]); + echo view('business_form',$data); + echo view('layout/footer'); + + } + public function new_branch($business_id) + { + + + if ($business_id === '0') { + + $data['business'] = []; + $data['page_name']="Add Branch"; + } else if ($business_id !== '0') { + + $BusinessModel = new BusinessModel(); + $business=$BusinessModel->getBusinessById($business_id); + $data['business']=$business; + $data['page_name']="Edit Branch" ; + } + $data['business_id'] = $business_id; + + return view('branch_form',$data); + } + + + public function add_business() + { + // print_r("hello");die; + $BusinessModel = new BusinessModel(); + + + $data = [ + 'business_name' => $this->request->getPost('businessname'), + 'isactive' => 1 // Assuming this is a default value or handled separately + ]; + + $business_id = $this->request->getPost('business_id'); + + + if (!empty($business_id)) { + + $BusinessModel->update($business_id, $data); + } else { + + $BusinessModel->insert($data); + } + + // echo"
";
+        // print_r(session()->get("logged_user_business_id"));die;
+
+        if (session()->get('logged_user_role') == "Administrator") {
+            return redirect()->to('new_business/'.session()->get("logged_user_business_id"));
+        }else{
+            return redirect()->to('business_list');
+        }
+        
+    }
+    public function delete_business($business_id)
+    {
+        $model = new BusinessModel();
+        $where = ['business_id' => $business_id, 'isactive' => 1]; // Assuming 'isactive' is a column in your database
+        $existingBusiness = $model->where($where)->first();
+    
+        if ($existingBusiness) {
+            $data['isactive'] = 0;
+            
+            if ($model->update($business_id, $data)) {
+                session()->setFlashdata('success', 'Deleted successfully.');
+                $this->logger->info("Users: has been Inactivated successfully. Inactivated ID = ".$business_id); 
+            }
+        }
+    
+       
+        return redirect()->to('business_list');
+    }
+
+    public function get_business($business_id)
+    {
+        if ($business_id) {
+            $BusinessModel = new BusinessModel();
+            $business =$BusinessModel->where('business_id',$business_id)->first();
+
+            return json_encode($business);
+        }   
+    }
+
+
+}
diff --git a/app/Controllers/MasterController.php b/app/Controllers/MasterController.php
index 159cd27..331132d 100644
--- a/app/Controllers/MasterController.php
+++ b/app/Controllers/MasterController.php
@@ -49,6 +49,8 @@ class MasterController extends BaseController
         // $data['serviceList']  = $this->ServiceModel->findAll();
         $data['serviceList'] =  $this->ServiceModel->select('services.* , COUNT(template.template_id) as template_count')
                                                     ->join('template', 'services.service_id = template.service_id', 'left')
+                                                    ->where('services.branch_id',$this->session->get('logged_in_staff_branch_id'))
+									                ->groupBy('services.service_id')
                                                     ->findAll();
 
         $staffdata = $this->StaffModel->where('staff_id',$this->session->get('is_staff_logged_in'))->get()->getRow();
@@ -65,6 +67,8 @@ class MasterController extends BaseController
 		if($this->request->getmethod() == 'POST')
 		{
 				$serviceData = $this->request->getVar();
+                $serviceData['branch_id'] = $this->session->get('logged_in_staff_branch_id');
+
 				$this->ServiceModel->insert($serviceData);
                 return redirect()->to(base_url()."service_list"); 
 			
diff --git a/app/Controllers/StaffController.php b/app/Controllers/StaffController.php
index f82f479..08c94a8 100644
--- a/app/Controllers/StaffController.php
+++ b/app/Controllers/StaffController.php
@@ -56,6 +56,7 @@ class StaffController extends BaseController
 					$this->session->set('is_staff_logged_in',$staffdata['staff_id']);
 					$this->session->set('logged_in_staff_role',$staffdata['role']);
                     $this->session->set('logged_in_staff_name',$staffdata['name']);
+                    $this->session->set('logged_in_staff_branch_id',$staffdata['branch_id']);
 
                     return redirect()->to(base_url().'staff_list');
 				}
@@ -78,6 +79,7 @@ class StaffController extends BaseController
     public function staff_logout()
 	{
 		session()->remove('is_staff_logged_in');
+		session()->remove('logged_in_staff_branch_id');
 		session()->destroy();
 		return redirect()->to(base_url()."staff");
 	}
@@ -94,7 +96,7 @@ 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') )->findAll();
+        $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();
         
         $staffdata = $this->StaffModel->where('staff_id',$this->session->get('is_staff_logged_in'))->get()->getRow();
         echo view('layout/header', ['Data'=>$staffdata]);
@@ -109,6 +111,7 @@ class StaffController extends BaseController
 		{
 				$staffData = $this->request->getVar();
                 $staffData['created_by'] = $this->session->get('is_staff_logged_in');
+                $staffData['branch_id'] = $this->session->get('logged_in_staff_branch_id');
 				$insert = $this->StaffModel->save($staffData);
 				if($insert) 
 				{
@@ -158,6 +161,8 @@ 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')
+									->where('client.branch_id',$this->session->get('logged_in_staff_branch_id'))
+									->groupBy('client.client_id')
 									->findAll();
 
         $staffdata = $this->StaffModel->where('staff_id',$this->session->get('is_staff_logged_in'))->get()->getRow();
@@ -197,6 +202,7 @@ class StaffController extends BaseController
 		{
 				$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');
 				$insert = $this->ClientModel->save($clientData);
 				if($insert) 
 				{
diff --git a/app/Models/BranchModel.php b/app/Models/BranchModel.php
new file mode 100644
index 0000000..1b364aa
--- /dev/null
+++ b/app/Models/BranchModel.php
@@ -0,0 +1,15 @@
+where('business_id', $business_id)->findAll();
+    }
+}
\ No newline at end of file
diff --git a/app/Models/BusinessModel.php b/app/Models/BusinessModel.php
new file mode 100644
index 0000000..9f8b865
--- /dev/null
+++ b/app/Models/BusinessModel.php
@@ -0,0 +1,13 @@
+db->table('business')->where('business_id', $business_id)->get()->getRowArray();
+    }
+}
\ No newline at end of file
diff --git a/app/Models/ClientModel.php b/app/Models/ClientModel.php
index fc9b97a..dc7d296 100644
--- a/app/Models/ClientModel.php
+++ b/app/Models/ClientModel.php
@@ -7,7 +7,7 @@ class ClientModel extends Model
     protected $table      = 'client';
     protected $primaryKey = 'client_id';
 	
-	protected $allowedFields = [ 'name','pan_no', 'mobile_no' , 'email' , 'otp', 'address' , 'city' , 'state' , 'country' , 'pin_code'  , 'is_active' ,'created_by','updated_by'];
+	protected $allowedFields = [ 'branch_id', 'name','pan_no', 'mobile_no' , 'email' , 'otp', 'address' , 'city' , 'state' , 'country' , 'pin_code'  , 'is_active' ,'created_by','updated_by'];
 	
 	protected $beforeInsert = ['beforeInsert'];
 	protected $beforeUpdate = ['beforeUpdate'];
diff --git a/app/Models/ServiceModel.php b/app/Models/ServiceModel.php
index ce78f2f..b87b93b 100644
--- a/app/Models/ServiceModel.php
+++ b/app/Models/ServiceModel.php
@@ -7,7 +7,7 @@ class ServiceModel extends Model
     protected $table      = 'services';
     protected $primaryKey = 'service_id';
 	
-	protected $allowedFields = ['service_name', 'notes' ,'is_active' ,'created_by','updated_by'];
+	protected $allowedFields = ['branch_id','service_name', 'notes' ,'is_active' ,'created_by','updated_by'];
 	
 
 
diff --git a/app/Models/StaffModel.php b/app/Models/StaffModel.php
index dc70e13..df84781 100644
--- a/app/Models/StaffModel.php
+++ b/app/Models/StaffModel.php
@@ -7,7 +7,7 @@ class StaffModel extends Model
     protected $table      = 'staff';
     protected $primaryKey = 'staff_id';
 	
-	protected $allowedFields = [ 'role' , 'name',  'mobile_no' , 'email', 'password' , 'address' , 'city' , 'state' , 'country' , 'pin_code'  , 'is_active' ,'created_by','updated_by'];
+	protected $allowedFields = [ 'branch_id','role' , 'name',  'mobile_no' , 'email', 'password' , 'address' , 'city' , 'state' , 'country' , 'pin_code'  , 'is_active' ,'created_by','updated_by'];
 	
 	protected $beforeInsert = ['beforeInsert'];
 	protected $beforeUpdate = ['beforeUpdate'];
@@ -32,7 +32,7 @@ class StaffModel extends Model
 	{
 		
 		$builder = $this->db->table('staff');
-		$builder -> select("staff_id,name,email,password,is_active,role");
+		$builder -> select("staff_id,name,email,password,is_active,role,branch_id");
 		$builder -> where('email',$email);
 		$result = $builder->get();
 		if(count($result->getResultArray()) ==1)
diff --git a/app/Views/branch_list.php b/app/Views/branch_list.php
new file mode 100644
index 0000000..15e9661
--- /dev/null
+++ b/app/Views/branch_list.php
@@ -0,0 +1,289 @@
+
+
+
+
+
+ +
+ + +
+
+
+

Branch List -

+ +
+
+
+ + + +
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Branch NameGSTAddressCityStatePostal CodeContactActiveAction
+ + Inactive + + Active + + + + + + " + class="delete-button"> +
+ +
+
+
+
+ + + +
+ +
+ + + + + + + + + + + + diff --git a/app/Views/business_form.php b/app/Views/business_form.php new file mode 100644 index 0000000..04ab28a --- /dev/null +++ b/app/Views/business_form.php @@ -0,0 +1,115 @@ + + + + +
+ +
+ + +
+
+
+

Create Business

+
+ +
+
+
+
+ + + +
+
+ +
+
+ + +
" method="post"> +
+
+ + +
+
+ + +
+ +
+
+
+ + +
+ + +
+ +
+ + + + + + + + \ No newline at end of file diff --git a/app/Views/business_list.php b/app/Views/business_list.php new file mode 100644 index 0000000..0b6f012 --- /dev/null +++ b/app/Views/business_list.php @@ -0,0 +1,197 @@ + + + + +
+ +
+ + +
+
+
+

Business List

+ +
+
+
+ + + +
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#Business NameBranch ListAction
" style="margin-left: 20px;">View + + + + + " + class="delete-button"> +
+ +
+
+
+
+ + + +
+ +
+ + + + + + + + + + + + + \ No newline at end of file diff --git a/app/Views/client_list.php b/app/Views/client_list.php index 94952b4..56e27f8 100644 --- a/app/Views/client_list.php +++ b/app/Views/client_list.php @@ -28,7 +28,7 @@
- +
@@ -107,7 +107,7 @@
Name