CHANGE_CONTROLLER_ARRENGE : AADHAVAN

This commit is contained in:
aadhavan valli 2024-07-04 11:36:35 +05:30
parent f94330d565
commit 9fe35452df
6 changed files with 213 additions and 711 deletions

View File

@ -12,30 +12,27 @@ use CodeIgniter\API\ResponseTrait;
class BranchController extends BaseController class BranchController extends BaseController
{ {
public $session; public $session;
protected $BranchModel; protected $BranchModel;
protected $BusinessModel;
protected $StaffModel; protected $StaffModel;
use ResponseTrait; use ResponseTrait;
public function __construct() public function __construct()
{ {
$this->session = session(); $this->session = session();
$this->BranchModel = new BranchModel(); $this->BranchModel = new BranchModel();
$this->BusinessModel = new BusinessModel();
$this->StaffModel = new StaffModel(); $this->StaffModel = new StaffModel();
} }
public function branch_index() public function branch_index()
{ {
$BranchModel = new BranchModel(); $data['branch'] = $this->BranchModel->select('branches.*, business.business_name')
$BusinessModel = new BusinessModel(); ->join('business', 'branches.business_id = business.business_id', 'left')
$data['branch'] = $BranchModel->select('branches.*, business.business_name') ->findAll();
->join('business', 'branches.business_id = business.business_id', 'left') $data['business_list'] = $this->BusinessModel->findAll();
->findAll();
$data['business_list'] = $BusinessModel->findAll();
$staffdata = $this->StaffModel->where('staff_id',$this->session->get('is_staff_logged_in'))->get()->getRow(); $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', ['Data'=>$staffdata]);
@ -43,57 +40,43 @@ class BranchController extends BaseController
echo view('layout/footer'); echo view('layout/footer');
} }
public function new_business($business_id) public function new_business($business_id)
{ {
if ($business_id === '0') { if ($business_id === '0') {
$data['business'] = []; $data['business'] = [];
$data['page_name']="Add Business"; $data['page_name']="Add Business";
} else if ($business_id !== '0') { } else if ($business_id !== '0') {
$business=$this->BusinessModel->getBusinessById($business_id);
$BusinessModel = new BusinessModel(); $data['business']=$business;
$business=$BusinessModel->getBusinessById($business_id); $data['page_name']="Edit Business" ;
$data['business']=$business;
$data['page_name']="Edit Business" ;
} }
$data['business_id'] = $business_id; $data['business_id'] = $business_id;
return view('business_form',$data); return view('business_form',$data);
} }
public function new_branch() public function new_branch()
{ {
$data = $this->request->getPost(); $data = $this->request->getPost();
$BranchModel = new BranchModel(); $insert=$this->BranchModel->insert($data);
if($insert){
$BranchModel->insert($data);
return json_encode(true); return json_encode(true);
}else{
return ;
}
} }
public function get_branch($branch_id) public function get_branch($branch_id)
{ {
if ($branch_id) { if ($branch_id) {
$BranchModel = new BranchModel(); $branch =$this->BranchModel->where('branch_id',$branch_id)->first();
$branch =$BranchModel->where('branch_id',$branch_id)->first();
return json_encode($branch); return json_encode($branch);
} }
} }
public function edit_branch($branch_id) public function edit_branch($branch_id)
{ {
if ($branch_id) { if ($branch_id) {
$data = $this->request->getPost(); $data = $this->request->getPost();
$BranchModel = new BranchModel(); $this->BranchModel->update($branch_id,$data);
$BranchModel->update($branch_id,$data);
return json_encode(true); return json_encode(true);
} }
} }
@ -103,14 +86,10 @@ class BranchController extends BaseController
$branch_id = $this->request->getPost('branch_id'); $branch_id = $this->request->getPost('branch_id');
if ($branch_id) { if ($branch_id) {
$data = $this->request->getPost(); $data = $this->request->getPost();
$BranchModel = new BranchModel(); $this->BranchModel->update($branch_id,$data);
$BranchModel->update($branch_id,$data);
return json_encode(true); return json_encode(true);
} }
} }
public function status_branch() public function status_branch()
{ {

View File

@ -32,161 +32,106 @@ class BusinessController extends BaseController
{ {
$data['business'] = $this->BusinessModel->findAll(); $data['business'] = $this->BusinessModel->findAll();
$staffdata = $this->StaffModel->where('staff_id',$this->session->get('is_staff_logged_in'))->get()->getRow(); $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', ['Data'=>$staffdata]);
echo view('business_list',$data); echo view('business_list',$data);
echo view('layout/footer'); echo view('layout/footer');
} }
public function new_business($business_id) public function new_business($business_id)
{ {
if ($business_id === '0') { if ($business_id === '0') {
$data['business'] = []; $data['business'] = [];
$data['page_name']="Create Business"; $data['page_name']="Create Business";
} else if ($business_id !== '0') { } else if ($business_id !== '0') {
$business=$this->BusinessModel->getBusinessById($business_id);
$BusinessModel = new BusinessModel();
$business=$BusinessModel->getBusinessById($business_id);
$data['business']=$business; $data['business']=$business;
$data['page_name']="Edit Business" ; $data['page_name']="Edit Business" ;
} }
$data['business_id'] = $business_id; $data['business_id'] = $business_id;
$staffdata = $this->StaffModel->where('staff_id',$this->session->get('is_staff_logged_in'))->get()->getRow(); $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', ['Data'=>$staffdata]);
echo view('business_form',$data); echo view('business_form',$data);
echo view('layout/footer'); echo view('layout/footer');
} }
public function new_branch($business_id) public function new_branch($business_id)
{ {
if ($business_id === '0') {
if ($business_id === '0') {
$data['business'] = []; $data['business'] = [];
$data['page_name']="Add Branch"; $data['page_name']="Add Branch";
} else if ($business_id !== '0') { } else if ($business_id !== '0') {
$business=$this->BusinessModel->getBusinessById($business_id);
$BusinessModel = new BusinessModel(); $data['business']=$business;
$business=$BusinessModel->getBusinessById($business_id); $data['page_name']="Edit Branch" ;
$data['business']=$business;
$data['page_name']="Edit Branch" ;
} }
$data['business_id'] = $business_id; $data['business_id'] = $business_id;
return view('branch_form',$data); return view('branch_form',$data);
} }
public function add_business() public function add_business()
{ {
$BusinessModel = new BusinessModel();
$business_id = $this->request->getPost('business_id'); $business_id = $this->request->getPost('business_id');
$data = $this->request->getPost(); $data = $this->request->getPost();
if ($business_id != '') { if ($business_id != '') {
$this->BusinessModel->update($business_id, $data);
$BusinessModel->update($business_id, $data);
return $this->response->setJSON(['success' => true ]); return $this->response->setJSON(['success' => true ]);
} else { } else {
$this->BusinessModel->insert($data);
$BusinessModel->insert($data);
return $this->response->setJSON(['success' => true ]); return $this->response->setJSON(['success' => true ]);
} }
} }
public function delete_business($business_id) public function delete_business($business_id)
{ {
$model = new BusinessModel();
$where = ['business_id' => $business_id, 'isactive' => 1]; // Assuming 'isactive' is a column in your database $where = ['business_id' => $business_id, 'isactive' => 1]; // Assuming 'isactive' is a column in your database
$existingBusiness = $model->where($where)->first(); $existingBusiness = $this->BusinessModel->where($where)->first();
if ($existingBusiness) { if ($existingBusiness) {
$data['isactive'] = 0; $data['isactive'] = 0;
if ($this->BusinessModel->update($business_id, $data)) {
if ($model->update($business_id, $data)) {
session()->setFlashdata('success', 'Deleted successfully.'); session()->setFlashdata('success', 'Deleted successfully.');
$this->logger->info("Users: has been Inactivated successfully. Inactivated ID = ".$business_id); $this->logger->info("Users: has been Inactivated successfully. Inactivated ID = ".$business_id);
} }
} }
return redirect()->to('business_list'); return redirect()->to('business_list');
} }
public function get_business($business_id) public function get_business($business_id)
{ {
if ($business_id) { if ($business_id) {
$BusinessModel = new BusinessModel(); $business =$this->BusinessModel->where('business_id',$business_id)->first();
$business =$BusinessModel->where('business_id',$business_id)->first();
return json_encode($business); return json_encode($business);
} }
} }
public function business() public function business()
{ {
$branch_id =session()->get("logged_in_staff_branch_id"); $branch_id =session()->get("logged_in_staff_branch_id");
$staffdata = $this->StaffModel->where('staff_id',$this->session->get('is_staff_logged_in'))->get()->getRow(); $staffdata = $this->StaffModel->where('staff_id',$this->session->get('is_staff_logged_in'))->get()->getRow();
if ($branch_id) { if ($branch_id) {
// $BusinessModel = new BusinessModel(); $data['branch'] =$this->BranchModel->select('branches.*, business.*')
$BranchModel = new BranchModel();
$data['branch'] =$BranchModel->select('branches.*, business.*')
->join('business', 'business.business_id = branches.business_id') ->join('business', 'business.business_id = branches.business_id')
->where('branches.branch_id',$branch_id) ->where('branches.branch_id',$branch_id)
->first(); ->first();
echo view('layout/header', ['Data'=>$staffdata]); echo view('layout/header', ['Data'=>$staffdata]);
echo view('business',$data); echo view('business',$data);
echo view('layout/footer'); echo view('layout/footer');
} }
} }
public function business_edit() public function business_edit()
{ {
$uploadFilePath = ROOTPATH . 'public/uploads/'; $uploadFilePath = ROOTPATH . 'public/uploads/';
$file_name = $this->file_Upload($this->request->getFile('business_logo'), $uploadFilePath); $file_name = $this->file_Upload($this->request->getFile('business_logo'), $uploadFilePath);
$data = $this->request->getPost(); $data = $this->request->getPost();
$data['logo'] = $file_name; $data['logo'] = $file_name;
$business_id = $this->request->getPost('business_id'); $business_id = $this->request->getPost('business_id');
if($business_id){ if($business_id){
$update = $this->BusinessModel->update($business_id, $data); $update = $this->BusinessModel->update($business_id, $data);
}else{ }else{
$insert = $this->BusinessModel->insert($data); $insert = $this->BusinessModel->insert($data);
} }
return json_encode(true);
return json_encode(true);
// if($insert){
// $client_data = $this->clientModel->where(['id' => $insert, 'is_active' => 1])->first();
// return $this->respond(['status' => true,'code' => 200,'data' => $client_data], 200);
// }else{
// return $this->respond(['status' => false,'code' => 404,'message' => 'no data found'], 200);
// }
} }
public function file_Upload($fileToUpload, $filepath) public function file_Upload($fileToUpload, $filepath)
{ {
if ($fileToUpload !== null && $fileToUpload->isValid() && !$fileToUpload->hasMoved()) { if ($fileToUpload !== null && $fileToUpload->isValid() && !$fileToUpload->hasMoved()) {
@ -198,14 +143,12 @@ class BusinessController extends BaseController
} }
} }
public function status_business() public function status_business()
{ {
try { try {
$business_id = $this->request->getPost('business_id'); $business_id = $this->request->getPost('business_id');
$isactive = $this->request->getPost('isactive'); $isactive = $this->request->getPost('isactive');
$data = ['isactive' => $isactive]; $data = ['isactive' => $isactive];
$updated = $this->BusinessModel->update($business_id, $data); $updated = $this->BusinessModel->update($business_id, $data);
if ($updated) { if ($updated) {
$BranchList = $this->BranchModel->where('business_id', $business_id)->findAll(); $BranchList = $this->BranchModel->where('business_id', $business_id)->findAll();
@ -221,5 +164,4 @@ class BusinessController extends BaseController
return $this->respond(['status' => 'failed','code' => 500,'data' => $exception],500); return $this->respond(['status' => 'failed','code' => 500,'data' => $exception],500);
} }
} }
} }

View File

@ -45,7 +45,6 @@ class ClientController extends BaseController
} }
public function login() public function login()
{ {
if($this->session->has('is_client_logged_in')){ return redirect()->to(base_url().'client_home'); } if($this->session->has('is_client_logged_in')){ return redirect()->to(base_url().'client_home'); }
@ -53,7 +52,6 @@ class ClientController extends BaseController
{ {
$gst_no = $this->request->getPost('gst_no'); $gst_no = $this->request->getPost('gst_no');
$client_branch_data = $this->ClientBranchModel->where('gst_no', $gst_no)->first(); $client_branch_data = $this->ClientBranchModel->where('gst_no', $gst_no)->first();
if($client_branch_data) if($client_branch_data)
{ {
if($client_branch_data['is_active'] == 0) if($client_branch_data['is_active'] == 0)
@ -61,21 +59,14 @@ class ClientController extends BaseController
$this->session->setTempdata('error','Client Deactivated',3); $this->session->setTempdata('error','Client Deactivated',3);
return redirect()->to(base_url()); return redirect()->to(base_url());
} }
$this->session->set('is_client_logged_in',$client_branch_data['id']);
// $this->session->set('logged_in_client_name',$clientdata['org_name']);
$this->session->set('is_client_logged_in',$client_branch_data['id']); return redirect()->to(base_url().'client_home');
// $this->session->set('logged_in_client_name',$clientdata['org_name']);
return redirect()->to(base_url().'client_home');
}else{ }else{
$this->session->setTempdata('error','Email or Password is invalid',3); $this->session->setTempdata('error','Email or Password is invalid',3);
return redirect()->to(base_url()); return redirect()->to(base_url());
} }
} }
//get method
return view('client_login'); return view('client_login');
} }
@ -86,16 +77,10 @@ class ClientController extends BaseController
return redirect()->to(base_url()); return redirect()->to(base_url());
} }
public function client_home(){ public function client_home(){
$client_id =$this->session->get('is_client_logged_in'); $client_id =$this->session->get('is_client_logged_in');
$data['doc_list'] = $this->ClientDocsModel->getTemplate($client_id); $data['doc_list'] = $this->ClientDocsModel->getTemplate($client_id);
// print_r($client_id);die;
// print_r($data['doc_list']);die;
$clientdata = $this->ClientBranchModel->where('id', $client_id)->get()->getRow(); $clientdata = $this->ClientBranchModel->where('id', $client_id)->get()->getRow();
if($clientdata){ if($clientdata){
echo view('layout/header', ['Data'=>$clientdata]); echo view('layout/header', ['Data'=>$clientdata]);
echo view('client_home',$data); echo view('client_home',$data);
@ -103,7 +88,6 @@ class ClientController extends BaseController
} }
} }
public function client_profile() public function client_profile()
{ {
if(!$this->session->has('is_client_logged_in')){ return redirect()->to(base_url()); } if(!$this->session->has('is_client_logged_in')){ return redirect()->to(base_url()); }
@ -111,17 +95,15 @@ class ClientController extends BaseController
{ {
//update client profile //update client profile
$clientData = $this->request->getVar(); $clientData = $this->request->getVar();
$clientData['updated_by'] = $this->session->get('is_client_logged_in'); $clientData['updated_by'] = $this->session->get('is_client_logged_in');
$client_id = $this->request->getVar('client_id'); $client_id = $this->request->getVar('client_id');
$this->ClientModel->where('client_id', $client_id )->set($clientData)->update(); $this->ClientModel->where('client_id', $client_id )->set($clientData)->update();
echo true; echo true;
}else{ }else{
$clientdata = $this->ClientModel->where('client_id',$this->session->get('is_client_logged_in'))->get()->getRow(); $clientdata = $this->ClientModel->where('client_id',$this->session->get('is_client_logged_in'))->get()->getRow();
echo view('layout/header', ['Data'=>$clientdata]); echo view('layout/header', ['Data'=>$clientdata]);
echo view('client_profile',['client'=>$clientdata]); echo view('client_profile',['client'=>$clientdata]);
echo view('layout/footer'); echo view('layout/footer');
} }
} }
@ -130,11 +112,8 @@ class ClientController extends BaseController
$old_password =$this->request->getVar('old_password'); $old_password =$this->request->getVar('old_password');
$new_password =$this->request->getVar('new_password'); $new_password =$this->request->getVar('new_password');
$confirm_password =$this->request->getVar('confirm_password'); $confirm_password =$this->request->getVar('confirm_password');
$client = $this->ClientModel->where('client_id',$client_id)->first(); $client = $this->ClientModel->where('client_id',$client_id)->first();
$data_old_password = $client['password']; $data_old_password = $client['password'];
if (!password_verify($old_password, $data_old_password)) { if (!password_verify($old_password, $data_old_password)) {
$response = array( $response = array(
'status' => 'error', 'status' => 'error',
@ -142,7 +121,6 @@ class ClientController extends BaseController
); );
return json_encode($response); return json_encode($response);
} }
if($new_password != $confirm_password){ if($new_password != $confirm_password){
$response = array( $response = array(
'status' => 'error', 'status' => 'error',
@ -150,10 +128,7 @@ class ClientController extends BaseController
); );
return json_encode($response); return json_encode($response);
} }
//$hashedPassword = password_hash($new_password, PASSWORD_DEFAULT);
$data['password'] = $new_password; $data['password'] = $new_password;
if ($this->ClientModel->update($client_id, $data)) { if ($this->ClientModel->update($client_id, $data)) {
$response = array( $response = array(
'status' => 'success', 'status' => 'success',
@ -161,38 +136,29 @@ class ClientController extends BaseController
); );
return json_encode($response); return json_encode($response);
} }
} }
public function generate_otp() public function generate_otp()
{ {
try { try {
$gst_no = $this->request->getPost('gst_no'); $gst_no = $this->request->getPost('gst_no');
if (empty($gst_no)) { if (empty($gst_no)) {
throw new \Exception('GST number is required'); throw new \Exception('GST number is required');
} }
$client_branch_data = $this->ClientBranchModel->where('gst_no', $gst_no)->first(); $client_branch_data = $this->ClientBranchModel->where('gst_no', $gst_no)->first();
if (!$client_branch_data) { if (!$client_branch_data) {
throw new \Exception('Client branch not found for GST number: ' . $gst_no); throw new \Exception('Client branch not found for GST number: ' . $gst_no);
} }
$id = $client_branch_data['id']; $id = $client_branch_data['id'];
$otp = mt_rand(100000, 999999); $otp = mt_rand(100000, 999999);
$data = ['otp' => $otp]; $data = ['otp' => $otp];
$update = $this->ClientBranchModel->update($id, $data); $update = $this->ClientBranchModel->update($id, $data);
if (!$update) { if (!$update) {
throw new \Exception('Failed to update OTP in database'); throw new \Exception('Failed to update OTP in database');
} }
$notificationHelper = new NotificationHelper(); $notificationHelper = new NotificationHelper();
$number = '91'. $client_branch_data['mobile_no']; // Replace with dynamic recipient number $number = '91'. $client_branch_data['mobile_no']; // Replace with dynamic recipient number
$message = 'Login OTP is: ' . $otp; $message = 'Login OTP is: ' . $otp;
if($client_branch_data['whatsapp'] == 1){ if($client_branch_data['whatsapp'] == 1){
try { try {
$notificationHelper->sendWhatsAppMessage($number, $message); $notificationHelper->sendWhatsAppMessage($number, $message);
@ -201,7 +167,6 @@ class ClientController extends BaseController
return $this->respond(['Error' => $e->getMessage()]); return $this->respond(['Error' => $e->getMessage()]);
} }
} }
if($client_branch_data['sms'] == 1){ if($client_branch_data['sms'] == 1){
try { try {
$notificationHelper->sendSms('91'. $client_branch_data['mobile_no'], $client_branch_data['name'], $otp, '', 'login_otp',''); $notificationHelper->sendSms('91'. $client_branch_data['mobile_no'], $client_branch_data['name'], $otp, '', 'login_otp','');
@ -210,13 +175,8 @@ class ClientController extends BaseController
return $this->respond(['Error' => $e->getMessage()]); return $this->respond(['Error' => $e->getMessage()]);
} }
} }
return $this->respond(['success' => true, 'otp' => '']);
return $this->respond(['success' => true, 'otp' => $otp]);
// Return success response with OTP // Return success response with OTP
} catch (\Exception $e) { } catch (\Exception $e) {
// Log the exception // Log the exception
error_log('Error generating OTP: ' . $e->getMessage()); error_log('Error generating OTP: ' . $e->getMessage());
@ -226,18 +186,13 @@ class ClientController extends BaseController
} }
} }
public function verify_otp() public function verify_otp()
{ {
try { try {
$gst_no = $this->request->getPost('gst_no'); $gst_no = $this->request->getPost('gst_no');
$otp = $this->request->getPost('otp'); $otp = $this->request->getPost('otp');
$client_branch_data = $this->ClientBranchModel->where('gst_no', $gst_no )->where('otp', $otp)->first(); $client_branch_data = $this->ClientBranchModel->where('gst_no', $gst_no )->where('otp', $otp)->first();
$data = ['otp' =>'']; $data = ['otp' =>''];
if($client_branch_data){ if($client_branch_data){
$id = $client_branch_data['id']; $id = $client_branch_data['id'];
$update = $this->ClientBranchModel->update($id , $data); $update = $this->ClientBranchModel->update($id , $data);
@ -245,19 +200,13 @@ class ClientController extends BaseController
return json_encode(true); return json_encode(true);
} }
} else { } else {
return ; return ;
} }
} catch (\Exception $e) { } catch (\Exception $e) {
// Handle any exceptions that occur during execution
return $this->respond(['status' => 'error', 'code' => 500, 'message' => $e->getMessage()], 500); return $this->respond(['status' => 'error', 'code' => 500, 'message' => $e->getMessage()], 500);
} }
} }
public function status_client() public function status_client()
{ {
try { try {
@ -266,18 +215,12 @@ class ClientController extends BaseController
$data = [ $data = [
'is_active' => $is_active 'is_active' => $is_active
]; ];
$updated = $this->ClientModel->update($client_id, $data); $updated = $this->ClientModel->update($client_id, $data);
if ($updated) { if ($updated) {
$client_branch_list = $this->ClientBranchModel->where('client_id', $client_id)->findAll(); $client_branch_list = $this->ClientBranchModel->where('client_id', $client_id)->findAll();
foreach($client_branch_list as $key=> $value){ foreach($client_branch_list as $key=> $value){
$this->ClientBranchModel->update($value['id'], $data); $this->ClientBranchModel->update($value['id'], $data);
} }
return $this->respond(['status' => 'success','code' => 200,'data' => true],200); return $this->respond(['status' => 'success','code' => 200,'data' => true],200);
} else { } else {
$result = "No Match's"; $result = "No Match's";
@ -288,7 +231,6 @@ class ClientController extends BaseController
} }
} }
public function doc_rejection() public function doc_rejection()
{ {
$id = $this->request->getPost('doc_id'); $id = $this->request->getPost('doc_id');
@ -296,10 +238,8 @@ class ClientController extends BaseController
'rejection_reason' => $this->request->getPost('rejection_reason'), 'rejection_reason' => $this->request->getPost('rejection_reason'),
'is_approved' => $this->request->getPost('is_approved') 'is_approved' => $this->request->getPost('is_approved')
]; ];
if($id){ if($id){
$update =$this->ClientDocsModel->update($id, $data); $update =$this->ClientDocsModel->update($id, $data);
if($this->session->has('is_client_logged_in')){ if($this->session->has('is_client_logged_in')){
$logged_user = $this->session->get('is_client_logged_in'); $logged_user = $this->session->get('is_client_logged_in');
$statusData['is_staff'] = 0; $statusData['is_staff'] = 0;
@ -312,31 +252,22 @@ class ClientController extends BaseController
$statusData['status'] = 'Rejected'; $statusData['status'] = 'Rejected';
$statusData['note'] = $this->request->getPost('rejection_reason'); $statusData['note'] = $this->request->getPost('rejection_reason');
$this->DocsStatusModel->insert($statusData); $this->DocsStatusModel->insert($statusData);
if ($update) { if ($update) {
return json_encode(true); return json_encode(true);
} }
} }
return ; return ;
} }
public function client_branch_list() public function client_branch_list()
{ {
// if(!$this->session->has('is_staff_logged_in')){ return redirect()->to(base_url().'staff'); } // if(!$this->session->has('is_staff_logged_in')){ return redirect()->to(base_url().'staff'); }
// $data['clientBranchList'] = $this->ClientBranchModel->select('client.* , COUNT(client_docs.id) as docs_count')
$data['clientBranchList'] = $this->ClientBranchModel->select('client_branch.*, client.name as client_name') $data['clientBranchList'] = $this->ClientBranchModel->select('client_branch.*, client.name as client_name')
->join('client', 'client.client_id = client_branch.client_id', 'left') ->join('client', 'client.client_id = client_branch.client_id', 'left')
// ->where('client.branch_id',$this->session->get('logged_in_staff_branch_id')) // ->where('client.branch_id',$this->session->get('logged_in_staff_branch_id'))
// ->groupBy('client_branch.client_id') // ->groupBy('client_branch.client_id')
->findAll(); ->findAll();
$data['client_list'] = $this->ClientModel->select('client_id, name')->where('is_active', 1)->findAll(); $data['client_list'] = $this->ClientModel->select('client_id, name')->where('is_active', 1)->findAll();
// echo"<pre>";
// print_r($data);die;
$staffdata = $this->StaffModel->where('staff_id',$this->session->get('is_staff_logged_in'))->get()->getRow(); $staffdata = $this->StaffModel->where('staff_id',$this->session->get('is_staff_logged_in'))->get()->getRow();
foreach (json_decode($staffdata->business_id) as $key => $value) { foreach (json_decode($staffdata->business_id) as $key => $value) {
$business = $this->BusinessModel->where('business_id', $value)->first(); $business = $this->BusinessModel->where('business_id', $value)->first();
@ -345,52 +276,39 @@ class ClientController extends BaseController
} }
} }
echo view('layout/header', ['Data'=>$staffdata]); echo view('layout/header', ['Data'=>$staffdata]);
// echo view('layout/header');
echo view('client_branch_list',$data); echo view('client_branch_list',$data);
echo view('layout/footer'); echo view('layout/footer');
} }
public function add_client_branch() public function add_client_branch()
{ {
$gst = $this->request->getPost('gst_no'); $gst = $this->request->getPost('gst_no');
$client_branch = $this->ClientBranchModel->where('gst_no', $gst)->first(); $client_branch = $this->ClientBranchModel->where('gst_no', $gst)->first();
if($client_branch){ if($client_branch){
return json_encode(false); return json_encode(false);
}else{ }else{
$data = $this->request->getPost(); $data = $this->request->getPost();
// print_r($data);die; $this->ClientBranchModel->insert($data);
$this->ClientBranchModel->insert($data); return json_encode(true);
return json_encode(true); }
}
} }
public function edit_client_branch() public function edit_client_branch()
{ {
$id = $this->request->getPost('id'); $id = $this->request->getPost('id');
$data = $this->request->getPost();
$data = $this->request->getPost(); $this->ClientBranchModel->update($id, $data);
return json_encode('update');
$this->ClientBranchModel->update($id, $data);
return json_encode('update');
} }
public function get_client_branch($branch_id) public function get_client_branch($branch_id)
{ {
if ($branch_id) { if ($branch_id) {
$branch =$this->ClientBranchModel->where('id',$branch_id)->first(); $branch =$this->ClientBranchModel->where('id',$branch_id)->first();
return json_encode($branch); return json_encode($branch);
} }
} }
public function status_client_branch() public function status_client_branch()
{ {
try { try {
@ -399,9 +317,7 @@ class ClientController extends BaseController
$data = [ $data = [
'is_active' => $is_active 'is_active' => $is_active
]; ];
$updated = $this->ClientBranchModel->update($client_branch_id, $data); $updated = $this->ClientBranchModel->update($client_branch_id, $data);
if ($updated) { if ($updated) {
return $this->respond(['status' => 'success','code' => 200,'data' => true],200); return $this->respond(['status' => 'success','code' => 200,'data' => true],200);
} else { } else {
@ -413,41 +329,33 @@ class ClientController extends BaseController
} }
} }
public function client_upload() public function client_upload()
{ {
if ($_FILES['file']['name']) { if ($_FILES['file']['name']) {
$allowed_extension = ['xls', 'xlsx']; $allowed_extension = ['xls', 'xlsx'];
$file_array = explode(".", $_FILES['file']['name']); $file_array = explode(".", $_FILES['file']['name']);
$file_extension = end($file_array); $file_extension = end($file_array);
if (in_array($file_extension, $allowed_extension)) { if (in_array($file_extension, $allowed_extension)) {
$file_name = $_FILES['file']['tmp_name']; $file_name = $_FILES['file']['tmp_name'];
$spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($file_name); $spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($file_name);
$data = $spreadsheet->getActiveSheet()->toArray(); $data = $spreadsheet->getActiveSheet()->toArray();
// Extract headers and data // Extract headers and data
$headers = array_shift($data); $headers = array_shift($data);
$nameIndex = array_search('Name', $headers); $nameIndex = array_search('Name', $headers);
$panNoIndex = array_search('PAN No', $headers); $panNoIndex = array_search('PAN No', $headers);
$emailIndex = array_search('Email', $headers); $emailIndex = array_search('Email', $headers);
$mobileNoIndex = array_search('Mobile No', $headers); $mobileNoIndex = array_search('Mobile No', $headers);
if ($nameIndex === false || $panNoIndex === false || $emailIndex === false || $mobileNoIndex === false) { if ($nameIndex === false || $panNoIndex === false || $emailIndex === false || $mobileNoIndex === false) {
echo "Required columns (Name, PAN No, Email, Mobile No) not found in the spreadsheet."; echo "Required columns (Name, PAN No, Email, Mobile No) not found in the spreadsheet.";
return; return;
} }
$groupedData = []; $groupedData = [];
// Group data by the "Name" field // Group data by the "Name" field
foreach ($data as $row) { foreach ($data as $row) {
$name = $row[$nameIndex]; $name = $row[$nameIndex];
$panNo = $row[$panNoIndex]; $panNo = $row[$panNoIndex];
$email = $row[$emailIndex]; $email = $row[$emailIndex];
$mobileNo = $row[$mobileNoIndex]; $mobileNo = $row[$mobileNoIndex];
if (!isset($groupedData[$name])) { if (!isset($groupedData[$name])) {
$groupedData[$name] = [ $groupedData[$name] = [
'name' => $name, 'name' => $name,
@ -457,7 +365,6 @@ class ClientController extends BaseController
'branches' => [] 'branches' => []
]; ];
} }
$branch = []; $branch = [];
foreach ($headers as $index => $header) { foreach ($headers as $index => $header) {
// print_r($header);die; // print_r($header);die;
@ -491,10 +398,8 @@ class ClientController extends BaseController
break; break;
} }
} }
$groupedData[$name]['branches'][] = $branch; $groupedData[$name]['branches'][] = $branch;
} }
foreach ($groupedData as $key => $value) { foreach ($groupedData as $key => $value) {
// print_r($value); // print_r($value);
$created_by = $this->session->get('is_staff_logged_in'); $created_by = $this->session->get('is_staff_logged_in');
@ -504,7 +409,6 @@ class ClientController extends BaseController
->where('branches.branch_id ',$branch_id) ->where('branches.branch_id ',$branch_id)
->first(); ->first();
$business_id = $business['business_id']; $business_id = $business['business_id'];
$insertData = [ $insertData = [
"name" => $value['name'], "name" => $value['name'],
"pan_no" => $value['pan_no'], "pan_no" => $value['pan_no'],
@ -514,9 +418,7 @@ class ClientController extends BaseController
"branch_id" => $branch_id, "branch_id" => $branch_id,
"business_id" => $business_id "business_id" => $business_id
]; ];
$client = $this->ClientModel->insert($insertData); $client = $this->ClientModel->insert($insertData);
if($client){ if($client){
if($value['branches']){ if($value['branches']){
foreach ($value['branches'] as $key => $branch) { foreach ($value['branches'] as $key => $branch) {
@ -534,10 +436,8 @@ class ClientController extends BaseController
]; ];
$clientBranch = $this->ClientBranchModel->insert($insertBranchData); $clientBranch = $this->ClientBranchModel->insert($insertBranchData);
} }
} }
} }
} }
return json_encode(true); return json_encode(true);
} else { } else {
@ -547,11 +447,6 @@ class ClientController extends BaseController
echo "No file uploaded."; echo "No file uploaded.";
} }
} }
} }

File diff suppressed because it is too large Load Diff

View File

@ -12,7 +12,6 @@ use App\Models\TemplateModel;
use CodeIgniter\API\ResponseTrait; use CodeIgniter\API\ResponseTrait;
class StaffController extends BaseController class StaffController extends BaseController
{ {
public $session; public $session;
@ -38,18 +37,14 @@ class StaffController extends BaseController
$this->BranchModel = new BranchModel(); $this->BranchModel = new BranchModel();
$this->TemplateModel = new TemplateModel(); $this->TemplateModel = new TemplateModel();
} }
public function set_business_in_session($business_id){ public function set_business_in_session($business_id){
$this->session->set('logged_in_staff_business_id', $business_id); $this->session->set('logged_in_staff_business_id', $business_id);
return json_encode(true); return json_encode(true);
} }
public function login() public function login()
{ {
// if($this->session->has('is_staff_logged_in')){ return redirect()->to(base_url().'staff_home'); }
if($this->session->has('is_staff_logged_in')){ return redirect()->to(base_url().'staff_list'); } if($this->session->has('is_staff_logged_in')){ return redirect()->to(base_url().'staff_list'); }
if($this->request->getmethod() == 'POST') if($this->request->getmethod() == 'POST')
{ {
@ -63,21 +58,17 @@ class StaffController extends BaseController
$this->session->setTempdata('error','Staff Deactivated',3); $this->session->setTempdata('error','Staff Deactivated',3);
return redirect()->to(base_url()."staff"); return redirect()->to(base_url()."staff");
} }
if (password_verify($password, $staffdata['password'])) if (password_verify($password, $staffdata['password']))
{ {
$this->session->set('is_staff_logged_in',$staffdata['staff_id']); $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_role',$staffdata['role']);
$this->session->set('logged_in_staff_name',$staffdata['name']); $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_branch_id',$staffdata['branch_id']);
if($staffdata['role'] == 'Admin'){ if($staffdata['role'] == 'Admin'){
$this->session->set('logged_in_staff_business_id', 0); $this->session->set('logged_in_staff_business_id', 0);
}else{ }else{
$this->session->set('logged_in_staff_business_id',json_decode($staffdata['business_id'])[0]); $this->session->set('logged_in_staff_business_id',json_decode($staffdata['business_id'])[0]);
} }
return redirect()->to(base_url().'shared_docs_list'); return redirect()->to(base_url().'shared_docs_list');
} }
else{ else{
@ -88,10 +79,7 @@ class StaffController extends BaseController
$this->session->setTempdata('error','Email or Password is invalid',3); $this->session->setTempdata('error','Email or Password is invalid',3);
return redirect()->to(base_url()."staff"); return redirect()->to(base_url()."staff");
} }
} }
//get method //get method
return view('staff_login'); return view('staff_login');
} }
@ -103,18 +91,10 @@ class StaffController extends BaseController
return redirect()->to(base_url()."staff"); return redirect()->to(base_url()."staff");
} }
// staff crud // staff crud
public function staff_list() public function staff_list()
{ {
if(!$this->session->has('is_staff_logged_in')){ return redirect()->to(base_url().'staff'); } if(!$this->session->has('is_staff_logged_in')){ return redirect()->to(base_url().'staff'); }
$data['staffList'] = $this->StaffModel->getStaffWithBusinessAndBranch(session()->get('is_staff_logged_in'), $this->session->get('logged_in_staff_branch_id')); $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(); $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', ['Data'=>$staffdata]);
@ -123,81 +103,60 @@ class StaffController extends BaseController
} }
public function staff_create() public function staff_create()
{ {
if(!$this->session->has('is_staff_logged_in')){ return redirect()->to(base_url().'staff'); } if(!$this->session->has('is_staff_logged_in')){ return redirect()->to(base_url().'staff'); }
if($this->request->getmethod() == 'POST') if($this->request->getmethod() == 'POST')
{ {
$email = $this->request->getVar('email'); $email = $this->request->getVar('email');
$staff = $this->StaffModel->where('email', $email)->first(); $staff = $this->StaffModel->where('email', $email)->first();
if($staff){ if($staff){
return json_encode('mail_exists'); return json_encode('mail_exists');
}else{ }else{
$staffData = $this->request->getVar(); $staffData = $this->request->getVar();
$staffData['created_by'] = $this->session->get('is_staff_logged_in'); $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')); $staffData['business_id'] = json_encode($this->request->getVar('business_id'));
$insert = $this->StaffModel->save($staffData); $insert = $this->StaffModel->save($staffData);
if($insert) if($insert)
{ {
return json_encode('staff_created'); return json_encode('staff_created');
// return redirect()->to(base_url()."staff_list");
} }
} }
}else{ }else{
$staffdata = $this->StaffModel->where('staff_id',$this->session->get('is_staff_logged_in'))->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['business'] = $this->BusinessModel->where('isactive', 1)->findAll();
// $data['branch'] = $this->BranchModel->where('isactive', 1)->findAll();
$data['page_heading'] = "Create Staff"; $data['page_heading'] = "Create Staff";
echo view('layout/header', ['Data'=>$staffdata]); echo view('layout/header', ['Data'=>$staffdata]);
echo view('staff_form', $data); echo view('staff_form', $data);
echo view('layout/footer'); echo view('layout/footer');
} }
} }
public function staff_edit($staff_id = null) public function staff_edit($staff_id = null)
{ {
if(!$this->session->has('is_staff_logged_in')){ return redirect()->to(base_url().'staff'); } if(!$this->session->has('is_staff_logged_in')){ return redirect()->to(base_url().'staff'); }
if($this->request->getmethod() == 'POST') if($this->request->getmethod() == 'POST')
{ {
//update staff details $staffData = $this->request->getVar();
$staffData = $this->request->getVar(); $staffData['updated_by'] = $this->session->get('is_staff_logged_in');
$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'));
$staff_id = $this->request->getVar('id'); $this->StaffModel->where('staff_id', $staff_id )->set($staffData)->update();
$staffData['business_id'] = json_encode($this->request->getVar('business_id')); return json_encode('edit_success');
$this->StaffModel->where('staff_id', $staff_id )->set($staffData)->update();
return json_encode('edit_success');
// return redirect()->to(base_url()."staff_list");
}else{ }else{
$data['staffData'] = $this->StaffModel->where('md5(staff.staff_id)', $this->request->getVar('staff_id') )->get()->getRow(); $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(); $staffdata = $this->StaffModel->where('staff_id',$this->session->get('is_staff_logged_in'))->get()->getRow();
$data['business'] = $this->BusinessModel->where('isactive', 1)->findAll(); $data['business'] = $this->BusinessModel->where('isactive', 1)->findAll();
// $data['branch'] = $this->BranchModel->where('isactive', 1)->findAll();
// print_r($data['staffData']->business_id);die;
$data['page_heading'] = "Edit Staff"; $data['page_heading'] = "Edit Staff";
echo view('layout/header', ['Data'=>$staffdata]); echo view('layout/header', ['Data'=>$staffdata]);
echo view('staff_form',$data); echo view('staff_form',$data);
echo view('layout/footer'); echo view('layout/footer');
} }
} }
public function business_view($staff_id){
public function business_view($staff_id)
{
$staffdata = $this->StaffModel->where('staff_id',$staff_id)->first(); $staffdata = $this->StaffModel->where('staff_id',$staff_id)->first();
$businessData =[]; $businessData =[];
$businessIds = json_decode($staffdata['business_id']); $businessIds = json_decode($staffdata['business_id']);
if (isset($businessIds) && is_array($businessIds)) { if (isset($businessIds) && is_array($businessIds)) {
foreach ($businessIds as $key => $value) { foreach ($businessIds as $key => $value) {
$businessData[] = $this->BusinessModel->where('business_id', $value)->first(); $businessData[] = $this->BusinessModel->where('business_id', $value)->first();
@ -205,21 +164,17 @@ class StaffController extends BaseController
}else{ }else{
$businessData[] = $this->BusinessModel->where('business_id', $businessIds)->first(); $businessData[] = $this->BusinessModel->where('business_id', $businessIds)->first();
} }
return json_encode($businessData); return json_encode($businessData);
} }
// client crud // client crud
public function client_list() public function client_list()
{ {
if(!$this->session->has('is_staff_logged_in')){ return redirect()->to(base_url().'staff'); } if(!$this->session->has('is_staff_logged_in')){ return redirect()->to(base_url().'staff'); }
$data['clientList'] = $this->ClientModel->findAll(); $data['clientList'] = $this->ClientModel->findAll();
$staffdata = $this->StaffModel->where('staff_id',$this->session->get('is_staff_logged_in'))
$staffdata = $this->StaffModel->where('staff_id',$this->session->get('is_staff_logged_in'))->get()->getRow(); ->get()
->getRow();
foreach (json_decode($staffdata->business_id) as $key => $value) { foreach (json_decode($staffdata->business_id) as $key => $value) {
$business = $this->BusinessModel->where('business_id', $value)->first(); $business = $this->BusinessModel->where('business_id', $value)->first();
if ($business) { if ($business) {

View File

@ -180,7 +180,6 @@
<ul class="list-unstyled topnav-menu float-right mb-0"> <ul class="list-unstyled topnav-menu float-right mb-0">
<li class="nav-item dropdown" > <li class="nav-item dropdown" >
<?php if(isset($_SESSION['logged_in_staff_business_id']) && $_SESSION['logged_in_staff_business_id']) { ?>
<a class="nav-link dropdown-toggle arrow-none" href="#" id="topnav-Service" role="button" <a class="nav-link dropdown-toggle arrow-none" href="#" id="topnav-Service" role="button"
data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
@ -189,7 +188,6 @@
<div class="dropdown-menu busines_menu_header_staff_view" aria-labelledby="topnav-Service"> <div class="dropdown-menu busines_menu_header_staff_view" aria-labelledby="topnav-Service">
</div> </div>
<?php } ?>
</li> </li>
<li> <li>
<?php if(isset($_SESSION['logged_in_staff_business_id']) && $_SESSION['logged_in_staff_business_id']) { ?> <?php if(isset($_SESSION['logged_in_staff_business_id']) && $_SESSION['logged_in_staff_business_id']) { ?>