diff --git a/app/Config/Routes.php b/app/Config/Routes.php
index 68797ea..b61b6a8 100644
--- a/app/Config/Routes.php
+++ b/app/Config/Routes.php
@@ -6,6 +6,8 @@ use CodeIgniter\Router\RouteCollection;
* @var RouteCollection $routes
*/
+ $routes->get('/set_business_in_session/(:any)','StaffController::set_business_in_session/$1');
+
// $routes->get('/home','Home::index');
// $routes->post('/upload_1','Home::upload_1');
@@ -25,6 +27,7 @@ use CodeIgniter\Router\RouteCollection;
$routes->match(['get','post'],'/change_password','StaffController::change_password');
$routes->post('status_staff','StaffController::status_staff');
$routes->post('staff_password_update','StaffController::staff_password_update');
+ $routes->get('business_view/(:any)','StaffController::business_view/$1');
diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php
index 4924a84..3162472 100644
--- a/app/Controllers/ClientController.php
+++ b/app/Controllers/ClientController.php
@@ -4,6 +4,7 @@ namespace App\Controllers;
use App\Models\ClientModel;
use App\Models\ClientBranchModel;
use App\Models\BranchModel;
+use App\Models\BusinessModel;
use App\Models\StaffModel;
use App\Models\ClientDocsModel;
@@ -24,6 +25,7 @@ class ClientController extends BaseController
protected $ClientModel;
protected $ClientBranchModel;
protected $BranchModel;
+ protected $BusinessModel;
protected $StaffModel;
protected $ClientDocsModel;
protected $DocsStatusModel;
@@ -36,6 +38,7 @@ class ClientController extends BaseController
$this->ClientModel = new ClientModel();
$this->ClientBranchModel = new ClientBranchModel();
$this->BranchModel = new BranchModel();
+ $this->BusinessModel = new BusinessModel();
$this->StaffModel = new StaffModel();
$this->ClientDocsModel = new ClientDocsModel();
$this->DocsStatusModel = new DocsStatusModel();
@@ -318,6 +321,12 @@ class ClientController extends BaseController
// echo"
";
// print_r($data);die;
$staffdata = $this->StaffModel->where('staff_id',$this->session->get('is_staff_logged_in'))->get()->getRow();
+ foreach (json_decode($staffdata->business_id) as $key => $value) {
+ $business = $this->BusinessModel->where('business_id', $value)->first();
+ if ($business) {
+ $data['business_list'][] = $business;
+ }
+ }
echo view('layout/header', ['Data'=>$staffdata]);
// echo view('layout/header');
echo view('client_branch_list',$data);
@@ -334,7 +343,7 @@ class ClientController extends BaseController
return json_encode(false);
}else{
$data = $this->request->getPost();
-
+ // print_r($data);die;
$this->ClientBranchModel->insert($data);
return json_encode(true);
}
diff --git a/app/Controllers/MasterController.php b/app/Controllers/MasterController.php
index 2805ff2..3e66405 100644
--- a/app/Controllers/MasterController.php
+++ b/app/Controllers/MasterController.php
@@ -22,6 +22,8 @@ use CodeIgniter\API\ResponseTrait;
class MasterController extends BaseController
{
+ protected $db;
+
public $session;
protected $ServiceModel;
protected $TemplateModel;
@@ -52,6 +54,8 @@ class MasterController extends BaseController
$this->ClientBranchModel = new ClientBranchModel();
$this->DocsStatusModel = new DocsStatusModel();
+ $this->db = \Config\Database::connect();
+
}
@@ -63,10 +67,10 @@ class MasterController extends BaseController
$data['serviceGroupList'] = $this->ServiceGroupModel->select('service_group.* , COUNT(services.service_id) as service_count')
->join('services', 'service_group.service_group_id = services.service_group_id', 'left')
- ->where('service_group.business_id',$this->session->get('logged_in_staff_business_id'))
+ // ->where('service_group.business_id',$this->session->get('logged_in_staff_business_id'))
->groupBy('service_group.service_group_id')
->findAll();
-
+ $data['business_list'] = $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('service_group_list',$data);
@@ -75,19 +79,22 @@ class MasterController extends BaseController
}
public function service_group_create()
+
{
if(!$this->session->has('is_staff_logged_in')){ return redirect()->to(base_url().'staff'); }
if($this->request->getmethod() == 'POST')
{
+
$serviceGroupData = $this->request->getVar();
if( isset($serviceGroupData['service_group_id']) ){
-
+ $serviceGroupData['business_id'] = json_encode($serviceGroupData['business']);
$this->ServiceGroupModel->where('service_group_id', $this->request->getVar('service_group_id') )->set($serviceGroupData)->update();
}else{
$serviceGroupData = $this->request->getVar();
- $serviceGroupData['business_id'] = $this->session->get('logged_in_staff_business_id');
+ $serviceGroupData['business_id'] = json_encode($this->request->getPost('business'));
+ // $serviceGroupData['business_id'] = $this->session->get('logged_in_staff_business_id');
$serviceGroupData['branch_id'] = $this->session->get('logged_in_staff_branch_id');
$this->ServiceGroupModel->insert($serviceGroupData);
@@ -120,12 +127,18 @@ class MasterController extends BaseController
$data['serviceList'] = $this->ServiceModel->select('services.* , service_group.group_name ,COUNT(template.template_id) as template_count')
->join('template', 'services.service_id = template.service_id', 'left')
->join('service_group', 'services.service_group_id = service_group.service_group_id', 'left')
- ->where('services.branch_id',$this->session->get('logged_in_staff_branch_id'))
+ // ->where('services.branch_id',$this->session->get('logged_in_staff_branch_id'))
->groupBy('services.service_id')
->orderBy('services.service_group_id')
->findAll();
$data['serviceGroupData'] = $this->ServiceGroupModel->where('is_active',1)->findall();
$staffdata = $this->StaffModel->where('staff_id',$this->session->get('is_staff_logged_in'))->get()->getRow();
+ foreach (json_decode($staffdata->business_id) as $key => $value) {
+ $business = $this->BusinessModel->where('business_id', $value)->first();
+ if ($business) {
+ $data['business_list'][] = $business;
+ }
+ }
echo view('layout/header', ['Data'=>$staffdata]);
echo view('service_list',$data);
echo view('layout/footer');
@@ -191,6 +204,12 @@ class MasterController extends BaseController
$staffdata = $this->StaffModel->where('staff_id',$this->session->get('is_staff_logged_in'))->get()->getRow();
+ foreach (json_decode($staffdata->business_id) as $key => $value) {
+ $business = $this->BusinessModel->where('business_id', $value)->first();
+ if ($business) {
+ $data['business_list'][] = $business;
+ }
+ }
echo view('layout/header', ['Data'=>$staffdata]);
echo view('template_list',$data);
echo view('layout/footer');
@@ -225,6 +244,12 @@ class MasterController extends BaseController
$data['AllBusinessData'] = $this->BusinessModel->where('isactive',1)->findAll();
$staffdata = $this->StaffModel->where('staff_id',$this->session->get('is_staff_logged_in'))->get()->getRow();
+ foreach (json_decode($staffdata->business_id) as $key => $value) {
+ $business = $this->BusinessModel->where('business_id', $value)->first();
+ if ($business) {
+ $data['business_list'][] = $business;
+ }
+ }
echo view('layout/header', ['Data'=>$staffdata]);
echo view('template_form',$data);
echo view('layout/footer');
@@ -273,30 +298,109 @@ class MasterController extends BaseController
}
+
public function shared_docs_list()
{
+
if(!$this->session->has('is_staff_logged_in')){ return redirect()->to(base_url().'staff'); }
+ $staffdata = $this->StaffModel->where('staff_id',$this->session->get('is_staff_logged_in'))->get()->getRow();
+ if($this->session->get('logged_in_staff_role') == 'Admin'){
+ $data['doc_list'] = $this->ClientDocsModel->select('client_docs.* , services.service_name , service_group.group_name , client_branch.name as client_branch_name , client.name as client_name')
+ ->join('template', 'template.template_id = client_docs.template_id', 'left')
+ ->join('services', 'services.service_id = template.service_id', 'left')
+ ->join('service_group', 'service_group.service_group_id = template.service_group_id', 'left')
+ ->join('client_branch', 'client_branch.id = client_docs.client_branch_id', 'left')
+ ->join('client', 'client.client_id = client_branch.client_id', 'left')
+ ->orderBy('client_docs.id','DESC')
+ ->findAll();
-
- $data['doc_list'] = $this->ClientDocsModel->select('client_docs.* , services.service_name , service_group.group_name , client_branch.name as client_branch_name , client.name as client_name')
+
+ // print_r($data['doc_list']);die;
+ $data['clientdata'] = $this->ClientBranchModel->select('client.name as client_name , client_branch.name as client_branch_name , client_branch.id as client_branch_id')
+ ->join('client', 'client_branch.client_id = client.client_id', 'left')
+ // ->where('client.business_id',$this->session->get('logged_in_staff_business_id'))
+ ->findAll();
+ $data['serviceGroupData'] = $this->ServiceGroupModel->findAll();
+
+ }else{
+ $business_id = $this->session->get('logged_in_staff_business_id');
+ // print_r($business_id);die;
+ $data['doc_list'] = $this->ClientDocsModel->select('client_docs.*,
+ services.service_name,
+ service_group.group_name,
+ client_branch.name as client_branch_name,
+ client.name as client_name, service_group.business_id')
->join('template', 'template.template_id = client_docs.template_id', 'left')
->join('services', 'services.service_id = template.service_id', 'left')
->join('service_group', 'service_group.service_group_id = template.service_group_id', 'left')
->join('client_branch', 'client_branch.id = client_docs.client_branch_id', 'left')
- ->join('client', 'client.client_id = client_branch.client_id', 'left')
- ->orderBy('client_docs.id','DESC')
- ->findAll();
-
- $data['clientdata'] = $this->ClientBranchModel->select('client.name as client_name , client_branch.name as client_branch_name , client_branch.id as client_branch_id')
- ->join('client', 'client_branch.client_id = client.client_id', 'left')
- // ->where('client.business_id',$this->session->get('logged_in_staff_business_id'))
- ->findAll();
- $data['serviceGroupData'] = $this->ServiceGroupModel->findAll();
-
- $staffdata = $this->StaffModel->where('staff_id',$this->session->get('is_staff_logged_in'))->get()->getRow();
- // echo "";
- // print_r($data['doc_list']);die;
+ ->join('client', 'client.client_id = client_branch.client_id ' , 'left')
+ // ->where('client.business_id', $business_id)
+ // ->where('service_group.business_id', $business_id )
+ // ->where("JSON_CONTAINS(service_group.business_id, '" . $business_id . "')")
+ ->orderBy('client_docs.id', 'DESC')
+ ->get()
+ ->getResultArray();
+ $business_id_check = 0;
+ // echo "";
+ // print_r($data['doc_list']);die;
+
+ foreach ($data['doc_list'] as $index => $value) {
+ foreach (json_decode($value['business_id']) as $key => $values) {
+ if($values == $business_id){
+ $business_id_check = $business_id;
+ }
+ }
+ if($business_id_check != 0){
+ // print_r($value);die;
+ $data['doc_list'][$index] =$value;
+ }else{
+ unset($data['doc_list'][$index]); // Remove the element completely
+ }
+ $business_id_check = 0;
+
+ }
+
+ // echo "";
+ // print_r($data['doc_list']);die;
+ $docStatusByClientId = [];
+
+
+ // Fetch all doc_status entries and group them by client_docs_id
+ foreach ($data['doc_list'] as $doc) {
+ // print_r($doc['id']);die;
+ $doc_id_temp = $doc['id'];
+ $docStatusByClientId[$doc_id_temp] = $this->db->table('docs_status')
+ ->where('client_docs_id', $doc_id_temp)
+ ->where('status', "Approved")
+ ->get()
+ ->getResultArray();
+ }
+ // Assign doc_status arrays to each document in doc_list
+ foreach ($data['doc_list'] as &$doc) {
+ $doc['doc_status'] = isset($docStatusByClientId[$doc['id']]) ? $docStatusByClientId[$doc['id']] : [];
+ }
+
+
+
+ $data['clientdata'] = $this->ClientBranchModel->select('client.name as client_name , client_branch.name as client_branch_name , client_branch.id as client_branch_id')
+ ->join('client', 'client_branch.client_id = client.client_id', 'left')
+ // ->where('client.business_id',$this->session->get('logged_in_staff_business_id'))
+ ->findAll();
+ $data['serviceGroupData'] = $this->ServiceGroupModel->findAll();
+
+
+ }
+ $data['business_list'] = [];
+ foreach (json_decode($staffdata->business_id) as $key => $value) {
+ $business = $this->BusinessModel->where('business_id', $value)->first();
+ if ($business) {
+ $data['business_list'][] = $business;
+ }
+ }
+ // echo"";
+ // print_r($data);die;
echo view('layout/header', ['Data'=>$staffdata]);
echo view('share_docs',$data);
echo view('layout/footer');
@@ -352,6 +456,7 @@ class MasterController extends BaseController
{
$docData = $this->request->getVar();
+ $docData['is_active'] = 1;
$docData['created_by'] = $this->session->has('is_staff_logged_in');
$docData['body_html'] = $this->TemplateModel->where('template_id',$this->request->getVar('template_id'))->get()->getRow()->body_html;
$insert = $this->ClientDocsModel->insert($docData);
diff --git a/app/Controllers/StaffController.php b/app/Controllers/StaffController.php
index 11045f3..38b2f35 100644
--- a/app/Controllers/StaffController.php
+++ b/app/Controllers/StaffController.php
@@ -4,6 +4,7 @@ namespace App\Controllers;
use App\Helpers\MailHelper;
use App\Models\StaffModel;
use App\Models\ClientModel;
+use App\Models\ClientBranchModel;
use App\Models\ServiceModel;
use App\Models\BusinessModel;
use App\Models\BranchModel;
@@ -17,6 +18,7 @@ class StaffController extends BaseController
public $session;
protected $StaffModel;
protected $ClientModel;
+ protected $ClientBranchModel;
protected $ServiceModel;
protected $BusinessModel;
@@ -30,6 +32,7 @@ class StaffController extends BaseController
$this->session = session();
$this->StaffModel = new StaffModel();
$this->ClientModel = new ClientModel();
+ $this->ClientBranchModel = new ClientBranchModel();
$this->ServiceModel = new ServiceModel();
$this->BusinessModel = new BusinessModel();
$this->BranchModel = new BranchModel();
@@ -37,7 +40,11 @@ class StaffController extends BaseController
}
+ public function set_business_in_session($business_id){
+ $this->session->set('logged_in_staff_business_id', $business_id);
+ return json_encode(true);
+ }
public function login()
{
@@ -49,7 +56,6 @@ class StaffController extends BaseController
$email = $this->request->getVar('email');
$password = $this->request->getVar('password');
$staffdata = $this->StaffModel->verifyEmail($email);
-
if($staffdata)
{
if($staffdata['is_active'] == 0)
@@ -63,8 +69,14 @@ 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']);
- $this->session->set('logged_in_staff_business_id',$staffdata['business_id']);
+ // $this->session->set('logged_in_staff_branch_id',$staffdata['branch_id']);
+
+
+ if($staffdata['role'] == 'Admin'){
+ $this->session->set('logged_in_staff_business_id', 0);
+ }else{
+ $this->session->set('logged_in_staff_business_id',json_decode($staffdata['business_id'])[0]);
+ }
return redirect()->to(base_url().'shared_docs_list');
}
@@ -72,7 +84,6 @@ class StaffController extends BaseController
$this->session->setTempdata('error','Email or Password is invalid',3);
return redirect()->to(base_url()."staff");
}
-
}else{
$this->session->setTempdata('error','Email or Password is invalid',3);
return redirect()->to(base_url()."staff");
@@ -112,6 +123,7 @@ class StaffController extends BaseController
}
public function staff_create()
{
+
if(!$this->session->has('is_staff_logged_in')){ return redirect()->to(base_url().'staff'); }
if($this->request->getmethod() == 'POST')
@@ -123,9 +135,11 @@ class StaffController extends BaseController
return json_encode('mail_exists');
}else{
$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['business_id'] = json_encode($this->request->getVar('business_id'));
+
$insert = $this->StaffModel->save($staffData);
if($insert)
{
@@ -138,7 +152,7 @@ class StaffController extends BaseController
$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['branch'] = $this->BranchModel->where('isactive', 1)->findAll();
$data['page_heading'] = "Create Staff";
echo view('layout/header', ['Data'=>$staffdata]);
echo view('staff_form', $data);
@@ -153,7 +167,10 @@ class StaffController extends BaseController
//update staff details
$staffData = $this->request->getVar();
$staffData['updated_by'] = $this->session->get('is_staff_logged_in');
+
$staff_id = $this->request->getVar('id');
+ $staffData['business_id'] = json_encode($this->request->getVar('business_id'));
+
$this->StaffModel->where('staff_id', $staff_id )->set($staffData)->update();
return json_encode('edit_success');
@@ -163,7 +180,8 @@ 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();
$data['business'] = $this->BusinessModel->where('isactive', 1)->findAll();
- $data['branch'] = $this->BranchModel->where('isactive', 1)->findAll();
+ // $data['branch'] = $this->BranchModel->where('isactive', 1)->findAll();
+ // print_r($data['staffData']->business_id);die;
$data['page_heading'] = "Edit Staff";
echo view('layout/header', ['Data'=>$staffdata]);
echo view('staff_form',$data);
@@ -174,6 +192,24 @@ class StaffController extends BaseController
}
+ public function business_view($staff_id){
+
+ $staffdata = $this->StaffModel->where('staff_id',$staff_id)->first();
+ $businessData =[];
+ $businessIds = json_decode($staffdata['business_id']);
+
+ if (isset($businessIds) && is_array($businessIds)) {
+ foreach ($businessIds as $key => $value) {
+ $businessData[] = $this->BusinessModel->where('business_id', $value)->first();
+ }
+ }else{
+ $businessData[] = $this->BusinessModel->where('business_id', $businessIds)->first();
+ }
+
+ return json_encode($businessData);
+
+ }
+
// client crud
public function client_list()
@@ -188,22 +224,28 @@ class StaffController extends BaseController
echo view('client_list',$data);
echo view('layout/footer');
}
- public function client_edit($client_id)
+ public function client_edit($client_idd)
{
if(!$this->session->has('is_staff_logged_in')){ return redirect()->to(base_url().'staff'); }
if($this->request->getmethod() == 'POST')
{
//update staff details
$clientData = $this->request->getVar();
+
$clientData['updated_by'] = $this->session->get('is_staff_logged_in');
$client_id = $this->request->getVar('client_id');
- $this->ClientModel->where('client_id', $client_id )->set($clientData)->update();
+ $client_update =$this->ClientModel->where('client_id', $client_id )->set($clientData)->update();
+
+ if($client_update){
+ return json_encode(true);
+ }else{
+ return ;
+ }
- 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('client_id', $client_id )->get()->getRow();
+ $data['clientData'] = $this->ClientModel->where('client_id', $client_idd )->get()->getRow();
// print_r($data);die;
$staffdata = $this->StaffModel->where('staff_id',$this->session->get('is_staff_logged_in'))->get()->getRow();
@@ -229,10 +271,28 @@ class StaffController extends BaseController
->where('branches.branch_id ',$clientData['branch_id'])
->first();
$clientData['business_id'] = $business['business_id'];
- $insert = $this->ClientModel->save($clientData);
+ // $insert = $this->ClientModel->save($clientData);
+ $insert = $this->ClientModel->insert($clientData);
if($insert)
- {
- return redirect()->to(base_url()."client_list");
+ {
+ $data['client_id'] = $insert;
+ $data['email'] = $clientData['branch_email'];
+ $data['country'] = $clientData['country'];
+ $data['name'] = $clientData['branch_name'];
+ $data['address'] = $clientData['address'];
+ $data['city'] = $clientData['city'];
+ $data['state'] = $clientData['state'];
+ $data['pin_code'] = $clientData['pin_code'];
+ $data['mobile_no'] = $clientData['branch_mobile_no'];
+ $data['gst_no'] = $clientData['gst_no'];
+
+ $branch_insert = $this->ClientBranchModel->insert($data);
+
+ if($branch_insert){
+ return json_encode(true);
+ }else{
+ return ;
+ }
}
}else{
diff --git a/app/Models/ClientBranchModel.php b/app/Models/ClientBranchModel.php
index 30474c5..0282f5e 100644
--- a/app/Models/ClientBranchModel.php
+++ b/app/Models/ClientBranchModel.php
@@ -12,7 +12,7 @@ class ClientBranchModel extends Model
'email' , 'address',
'country', 'state',
'city', 'pin_code',
- 'otp', 'is_active',
+ 'otp', 'sms', 'whatsapp', 'is_active',
'created_by', 'updated_by'];
diff --git a/app/Models/StaffModel.php b/app/Models/StaffModel.php
index b20869e..36de388 100644
--- a/app/Models/StaffModel.php
+++ b/app/Models/StaffModel.php
@@ -32,7 +32,8 @@ class StaffModel extends Model
{
$builder = $this->db->table('staff');
- $builder -> select("staff_id,name,email,password,is_active,role,branch_id,business_id");
+ // $builder -> select("staff_id,name,email,password,is_active,role,branch_id,business_id");
+ $builder -> select("staff_id,name,email,password,is_active,role,business_id");
$builder -> where('email',$email);
$result = $builder->get();
if(count($result->getResultArray()) ==1)
@@ -46,9 +47,8 @@ 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')
+ ->select('staff.*')
+ // ->join('business', 'business.business_id = staff.business_id')
->where('staff.staff_id != ', $is_staff_logged_in);
// Execute the query and fetch results as an array
diff --git a/app/Views/branch_list.php b/app/Views/branch_list.php
index e275c26..6b865f6 100644
--- a/app/Views/branch_list.php
+++ b/app/Views/branch_list.php
@@ -30,7 +30,7 @@