CHANGE_CONTROLLER_ARRENGE : AADHAVAN
This commit is contained in:
parent
f94330d565
commit
9fe35452df
@ -12,30 +12,27 @@ use CodeIgniter\API\ResponseTrait;
|
||||
|
||||
class BranchController extends BaseController
|
||||
{
|
||||
|
||||
public $session;
|
||||
protected $BranchModel;
|
||||
protected $BusinessModel;
|
||||
protected $StaffModel;
|
||||
|
||||
use ResponseTrait;
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->session = session();
|
||||
$this->BranchModel = new BranchModel();
|
||||
$this->BusinessModel = new BusinessModel();
|
||||
$this->StaffModel = new StaffModel();
|
||||
|
||||
}
|
||||
|
||||
public function branch_index()
|
||||
{
|
||||
$BranchModel = new BranchModel();
|
||||
$BusinessModel = new BusinessModel();
|
||||
$data['branch'] = $BranchModel->select('branches.*, business.business_name')
|
||||
->join('business', 'branches.business_id = business.business_id', 'left')
|
||||
->findAll();
|
||||
$data['business_list'] = $BusinessModel->findAll();
|
||||
$data['branch'] = $this->BranchModel->select('branches.*, business.business_name')
|
||||
->join('business', 'branches.business_id = business.business_id', 'left')
|
||||
->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]);
|
||||
@ -43,57 +40,43 @@ class BranchController extends BaseController
|
||||
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" ;
|
||||
$business=$this->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()
|
||||
{
|
||||
$data = $this->request->getPost();
|
||||
$BranchModel = new BranchModel();
|
||||
|
||||
$BranchModel->insert($data);
|
||||
|
||||
$data = $this->request->getPost();
|
||||
$insert=$this->BranchModel->insert($data);
|
||||
if($insert){
|
||||
return json_encode(true);
|
||||
|
||||
}else{
|
||||
return ;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function get_branch($branch_id)
|
||||
{
|
||||
if ($branch_id) {
|
||||
$BranchModel = new BranchModel();
|
||||
$branch =$BranchModel->where('branch_id',$branch_id)->first();
|
||||
|
||||
$branch =$this->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);
|
||||
$this->BranchModel->update($branch_id,$data);
|
||||
return json_encode(true);
|
||||
}
|
||||
}
|
||||
@ -103,14 +86,10 @@ class BranchController extends BaseController
|
||||
$branch_id = $this->request->getPost('branch_id');
|
||||
if ($branch_id) {
|
||||
$data = $this->request->getPost();
|
||||
$BranchModel = new BranchModel();
|
||||
|
||||
$BranchModel->update($branch_id,$data);
|
||||
$this->BranchModel->update($branch_id,$data);
|
||||
return json_encode(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function status_branch()
|
||||
{
|
||||
|
||||
@ -32,161 +32,106 @@ class BusinessController extends BaseController
|
||||
{
|
||||
$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']="Create Business";
|
||||
} else if ($business_id !== '0') {
|
||||
|
||||
$BusinessModel = new BusinessModel();
|
||||
$business=$BusinessModel->getBusinessById($business_id);
|
||||
} else if ($business_id !== '0') {
|
||||
$business=$this->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') {
|
||||
|
||||
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" ;
|
||||
} else if ($business_id !== '0') {
|
||||
$business=$this->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()
|
||||
{
|
||||
$BusinessModel = new BusinessModel();
|
||||
|
||||
|
||||
{
|
||||
$business_id = $this->request->getPost('business_id');
|
||||
$data = $this->request->getPost();
|
||||
|
||||
|
||||
$data = $this->request->getPost();
|
||||
if ($business_id != '') {
|
||||
|
||||
$BusinessModel->update($business_id, $data);
|
||||
$this->BusinessModel->update($business_id, $data);
|
||||
return $this->response->setJSON(['success' => true ]);
|
||||
|
||||
} else {
|
||||
|
||||
$BusinessModel->insert($data);
|
||||
$this->BusinessModel->insert($data);
|
||||
return $this->response->setJSON(['success' => true ]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
$existingBusiness = $this->BusinessModel->where($where)->first();
|
||||
if ($existingBusiness) {
|
||||
$data['isactive'] = 0;
|
||||
|
||||
if ($model->update($business_id, $data)) {
|
||||
if ($this->BusinessModel->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();
|
||||
|
||||
$business =$this->BusinessModel->where('business_id',$business_id)->first();
|
||||
return json_encode($business);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function business()
|
||||
{
|
||||
$branch_id =session()->get("logged_in_staff_branch_id");
|
||||
$staffdata = $this->StaffModel->where('staff_id',$this->session->get('is_staff_logged_in'))->get()->getRow();
|
||||
if ($branch_id) {
|
||||
// $BusinessModel = new BusinessModel();
|
||||
$BranchModel = new BranchModel();
|
||||
$data['branch'] =$BranchModel->select('branches.*, business.*')
|
||||
$data['branch'] =$this->BranchModel->select('branches.*, business.*')
|
||||
->join('business', 'business.business_id = branches.business_id')
|
||||
->where('branches.branch_id',$branch_id)
|
||||
->first();
|
||||
|
||||
echo view('layout/header', ['Data'=>$staffdata]);
|
||||
echo view('business',$data);
|
||||
echo view('layout/footer');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function business_edit()
|
||||
{
|
||||
$uploadFilePath = ROOTPATH . 'public/uploads/';
|
||||
$file_name = $this->file_Upload($this->request->getFile('business_logo'), $uploadFilePath);
|
||||
$data = $this->request->getPost();
|
||||
$data['logo'] = $file_name;
|
||||
|
||||
$business_id = $this->request->getPost('business_id');
|
||||
|
||||
if($business_id){
|
||||
$update = $this->BusinessModel->update($business_id, $data);
|
||||
}else{
|
||||
$insert = $this->BusinessModel->insert($data);
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
// }
|
||||
|
||||
return json_encode(true);
|
||||
}
|
||||
|
||||
|
||||
public function file_Upload($fileToUpload, $filepath)
|
||||
{
|
||||
if ($fileToUpload !== null && $fileToUpload->isValid() && !$fileToUpload->hasMoved()) {
|
||||
@ -198,14 +143,12 @@ class BusinessController extends BaseController
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function status_business()
|
||||
{
|
||||
try {
|
||||
$business_id = $this->request->getPost('business_id');
|
||||
$isactive = $this->request->getPost('isactive');
|
||||
$data = ['isactive' => $isactive];
|
||||
|
||||
$updated = $this->BusinessModel->update($business_id, $data);
|
||||
if ($updated) {
|
||||
$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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -45,7 +45,6 @@ class ClientController extends BaseController
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function login()
|
||||
{
|
||||
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');
|
||||
$client_branch_data = $this->ClientBranchModel->where('gst_no', $gst_no)->first();
|
||||
|
||||
if($client_branch_data)
|
||||
{
|
||||
if($client_branch_data['is_active'] == 0)
|
||||
@ -61,21 +59,14 @@ class ClientController extends BaseController
|
||||
$this->session->setTempdata('error','Client Deactivated',3);
|
||||
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']);
|
||||
|
||||
return redirect()->to(base_url().'client_home');
|
||||
|
||||
|
||||
$this->session->set('is_client_logged_in',$client_branch_data['id']);
|
||||
// $this->session->set('logged_in_client_name',$clientdata['org_name']);
|
||||
return redirect()->to(base_url().'client_home');
|
||||
}else{
|
||||
$this->session->setTempdata('error','Email or Password is invalid',3);
|
||||
return redirect()->to(base_url());
|
||||
}
|
||||
|
||||
}
|
||||
//get method
|
||||
return view('client_login');
|
||||
}
|
||||
|
||||
@ -86,16 +77,10 @@ class ClientController extends BaseController
|
||||
return redirect()->to(base_url());
|
||||
}
|
||||
|
||||
|
||||
public function client_home(){
|
||||
$client_id =$this->session->get('is_client_logged_in');
|
||||
|
||||
$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();
|
||||
|
||||
if($clientdata){
|
||||
echo view('layout/header', ['Data'=>$clientdata]);
|
||||
echo view('client_home',$data);
|
||||
@ -103,7 +88,6 @@ class ClientController extends BaseController
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function client_profile()
|
||||
{
|
||||
if(!$this->session->has('is_client_logged_in')){ return redirect()->to(base_url()); }
|
||||
@ -111,17 +95,15 @@ class ClientController extends BaseController
|
||||
{
|
||||
//update client profile
|
||||
$clientData = $this->request->getVar();
|
||||
|
||||
$clientData['updated_by'] = $this->session->get('is_client_logged_in');
|
||||
$client_id = $this->request->getVar('client_id');
|
||||
$this->ClientModel->where('client_id', $client_id )->set($clientData)->update();
|
||||
|
||||
echo true;
|
||||
}else{
|
||||
$clientdata = $this->ClientModel->where('client_id',$this->session->get('is_client_logged_in'))->get()->getRow();
|
||||
echo view('layout/header', ['Data'=>$clientdata]);
|
||||
echo view('client_profile',['client'=>$clientdata]);
|
||||
echo view('layout/footer');
|
||||
$clientdata = $this->ClientModel->where('client_id',$this->session->get('is_client_logged_in'))->get()->getRow();
|
||||
echo view('layout/header', ['Data'=>$clientdata]);
|
||||
echo view('client_profile',['client'=>$clientdata]);
|
||||
echo view('layout/footer');
|
||||
}
|
||||
}
|
||||
|
||||
@ -130,11 +112,8 @@ class ClientController extends BaseController
|
||||
$old_password =$this->request->getVar('old_password');
|
||||
$new_password =$this->request->getVar('new_password');
|
||||
$confirm_password =$this->request->getVar('confirm_password');
|
||||
|
||||
|
||||
$client = $this->ClientModel->where('client_id',$client_id)->first();
|
||||
$data_old_password = $client['password'];
|
||||
|
||||
if (!password_verify($old_password, $data_old_password)) {
|
||||
$response = array(
|
||||
'status' => 'error',
|
||||
@ -142,7 +121,6 @@ class ClientController extends BaseController
|
||||
);
|
||||
return json_encode($response);
|
||||
}
|
||||
|
||||
if($new_password != $confirm_password){
|
||||
$response = array(
|
||||
'status' => 'error',
|
||||
@ -150,10 +128,7 @@ class ClientController extends BaseController
|
||||
);
|
||||
return json_encode($response);
|
||||
}
|
||||
|
||||
//$hashedPassword = password_hash($new_password, PASSWORD_DEFAULT);
|
||||
$data['password'] = $new_password;
|
||||
|
||||
if ($this->ClientModel->update($client_id, $data)) {
|
||||
$response = array(
|
||||
'status' => 'success',
|
||||
@ -161,38 +136,29 @@ class ClientController extends BaseController
|
||||
);
|
||||
return json_encode($response);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function generate_otp()
|
||||
{
|
||||
try {
|
||||
$gst_no = $this->request->getPost('gst_no');
|
||||
|
||||
if (empty($gst_no)) {
|
||||
throw new \Exception('GST number is required');
|
||||
}
|
||||
|
||||
$client_branch_data = $this->ClientBranchModel->where('gst_no', $gst_no)->first();
|
||||
|
||||
if (!$client_branch_data) {
|
||||
throw new \Exception('Client branch not found for GST number: ' . $gst_no);
|
||||
}
|
||||
|
||||
$id = $client_branch_data['id'];
|
||||
|
||||
$otp = mt_rand(100000, 999999);
|
||||
$data = ['otp' => $otp];
|
||||
$update = $this->ClientBranchModel->update($id, $data);
|
||||
|
||||
if (!$update) {
|
||||
throw new \Exception('Failed to update OTP in database');
|
||||
}
|
||||
$notificationHelper = new NotificationHelper();
|
||||
$number = '91'. $client_branch_data['mobile_no']; // Replace with dynamic recipient number
|
||||
$message = 'Login OTP is: ' . $otp;
|
||||
|
||||
if($client_branch_data['whatsapp'] == 1){
|
||||
try {
|
||||
$notificationHelper->sendWhatsAppMessage($number, $message);
|
||||
@ -201,7 +167,6 @@ class ClientController extends BaseController
|
||||
return $this->respond(['Error' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
if($client_branch_data['sms'] == 1){
|
||||
try {
|
||||
$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(['success' => true, 'otp' => $otp]);
|
||||
|
||||
|
||||
return $this->respond(['success' => true, 'otp' => '']);
|
||||
// Return success response with OTP
|
||||
|
||||
} catch (\Exception $e) {
|
||||
// Log the exception
|
||||
error_log('Error generating OTP: ' . $e->getMessage());
|
||||
@ -226,18 +186,13 @@ class ClientController extends BaseController
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public function verify_otp()
|
||||
{
|
||||
try {
|
||||
$gst_no = $this->request->getPost('gst_no');
|
||||
$otp = $this->request->getPost('otp');
|
||||
|
||||
$client_branch_data = $this->ClientBranchModel->where('gst_no', $gst_no )->where('otp', $otp)->first();
|
||||
$data = ['otp' =>''];
|
||||
|
||||
if($client_branch_data){
|
||||
$id = $client_branch_data['id'];
|
||||
$update = $this->ClientBranchModel->update($id , $data);
|
||||
@ -245,19 +200,13 @@ class ClientController extends BaseController
|
||||
return json_encode(true);
|
||||
}
|
||||
} else {
|
||||
|
||||
|
||||
return ;
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
// Handle any exceptions that occur during execution
|
||||
return $this->respond(['status' => 'error', 'code' => 500, 'message' => $e->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public function status_client()
|
||||
{
|
||||
try {
|
||||
@ -266,18 +215,12 @@ class ClientController extends BaseController
|
||||
$data = [
|
||||
'is_active' => $is_active
|
||||
];
|
||||
|
||||
$updated = $this->ClientModel->update($client_id, $data);
|
||||
|
||||
if ($updated) {
|
||||
|
||||
$client_branch_list = $this->ClientBranchModel->where('client_id', $client_id)->findAll();
|
||||
|
||||
foreach($client_branch_list as $key=> $value){
|
||||
$this->ClientBranchModel->update($value['id'], $data);
|
||||
}
|
||||
|
||||
|
||||
return $this->respond(['status' => 'success','code' => 200,'data' => true],200);
|
||||
} else {
|
||||
$result = "No Match's";
|
||||
@ -288,7 +231,6 @@ class ClientController extends BaseController
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function doc_rejection()
|
||||
{
|
||||
$id = $this->request->getPost('doc_id');
|
||||
@ -296,10 +238,8 @@ class ClientController extends BaseController
|
||||
'rejection_reason' => $this->request->getPost('rejection_reason'),
|
||||
'is_approved' => $this->request->getPost('is_approved')
|
||||
];
|
||||
|
||||
if($id){
|
||||
$update =$this->ClientDocsModel->update($id, $data);
|
||||
|
||||
if($this->session->has('is_client_logged_in')){
|
||||
$logged_user = $this->session->get('is_client_logged_in');
|
||||
$statusData['is_staff'] = 0;
|
||||
@ -312,31 +252,22 @@ class ClientController extends BaseController
|
||||
$statusData['status'] = 'Rejected';
|
||||
$statusData['note'] = $this->request->getPost('rejection_reason');
|
||||
$this->DocsStatusModel->insert($statusData);
|
||||
|
||||
if ($update) {
|
||||
return json_encode(true);
|
||||
}
|
||||
}
|
||||
|
||||
return ;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function client_branch_list()
|
||||
{
|
||||
// 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')
|
||||
->join('client', 'client.client_id = client_branch.client_id', 'left')
|
||||
// ->where('client.branch_id',$this->session->get('logged_in_staff_branch_id'))
|
||||
// ->groupBy('client_branch.client_id')
|
||||
->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();
|
||||
foreach (json_decode($staffdata->business_id) as $key => $value) {
|
||||
$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');
|
||||
echo view('client_branch_list',$data);
|
||||
echo view('layout/footer');
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function add_client_branch()
|
||||
{
|
||||
$gst = $this->request->getPost('gst_no');
|
||||
$client_branch = $this->ClientBranchModel->where('gst_no', $gst)->first();
|
||||
if($client_branch){
|
||||
return json_encode(false);
|
||||
}else{
|
||||
$data = $this->request->getPost();
|
||||
// print_r($data);die;
|
||||
$this->ClientBranchModel->insert($data);
|
||||
return json_encode(true);
|
||||
}
|
||||
$gst = $this->request->getPost('gst_no');
|
||||
$client_branch = $this->ClientBranchModel->where('gst_no', $gst)->first();
|
||||
if($client_branch){
|
||||
return json_encode(false);
|
||||
}else{
|
||||
$data = $this->request->getPost();
|
||||
$this->ClientBranchModel->insert($data);
|
||||
return json_encode(true);
|
||||
}
|
||||
}
|
||||
|
||||
public function edit_client_branch()
|
||||
{
|
||||
$id = $this->request->getPost('id');
|
||||
|
||||
$data = $this->request->getPost();
|
||||
|
||||
$this->ClientBranchModel->update($id, $data);
|
||||
|
||||
return json_encode('update');
|
||||
|
||||
$id = $this->request->getPost('id');
|
||||
$data = $this->request->getPost();
|
||||
$this->ClientBranchModel->update($id, $data);
|
||||
return json_encode('update');
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function get_client_branch($branch_id)
|
||||
{
|
||||
if ($branch_id) {
|
||||
$branch =$this->ClientBranchModel->where('id',$branch_id)->first();
|
||||
|
||||
return json_encode($branch);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function status_client_branch()
|
||||
{
|
||||
try {
|
||||
@ -399,9 +317,7 @@ class ClientController extends BaseController
|
||||
$data = [
|
||||
'is_active' => $is_active
|
||||
];
|
||||
|
||||
$updated = $this->ClientBranchModel->update($client_branch_id, $data);
|
||||
|
||||
if ($updated) {
|
||||
return $this->respond(['status' => 'success','code' => 200,'data' => true],200);
|
||||
} else {
|
||||
@ -413,41 +329,33 @@ class ClientController extends BaseController
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function client_upload()
|
||||
{
|
||||
if ($_FILES['file']['name']) {
|
||||
$allowed_extension = ['xls', 'xlsx'];
|
||||
$file_array = explode(".", $_FILES['file']['name']);
|
||||
$file_extension = end($file_array);
|
||||
|
||||
if (in_array($file_extension, $allowed_extension)) {
|
||||
$file_name = $_FILES['file']['tmp_name'];
|
||||
$spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($file_name);
|
||||
$data = $spreadsheet->getActiveSheet()->toArray();
|
||||
|
||||
// Extract headers and data
|
||||
$headers = array_shift($data);
|
||||
$nameIndex = array_search('Name', $headers);
|
||||
$panNoIndex = array_search('PAN No', $headers);
|
||||
$emailIndex = array_search('Email', $headers);
|
||||
$mobileNoIndex = array_search('Mobile No', $headers);
|
||||
|
||||
if ($nameIndex === false || $panNoIndex === false || $emailIndex === false || $mobileNoIndex === false) {
|
||||
echo "Required columns (Name, PAN No, Email, Mobile No) not found in the spreadsheet.";
|
||||
return;
|
||||
}
|
||||
|
||||
$groupedData = [];
|
||||
|
||||
// Group data by the "Name" field
|
||||
foreach ($data as $row) {
|
||||
$name = $row[$nameIndex];
|
||||
$panNo = $row[$panNoIndex];
|
||||
$email = $row[$emailIndex];
|
||||
$mobileNo = $row[$mobileNoIndex];
|
||||
|
||||
if (!isset($groupedData[$name])) {
|
||||
$groupedData[$name] = [
|
||||
'name' => $name,
|
||||
@ -457,7 +365,6 @@ class ClientController extends BaseController
|
||||
'branches' => []
|
||||
];
|
||||
}
|
||||
|
||||
$branch = [];
|
||||
foreach ($headers as $index => $header) {
|
||||
// print_r($header);die;
|
||||
@ -491,10 +398,8 @@ class ClientController extends BaseController
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$groupedData[$name]['branches'][] = $branch;
|
||||
}
|
||||
|
||||
foreach ($groupedData as $key => $value) {
|
||||
// print_r($value);
|
||||
$created_by = $this->session->get('is_staff_logged_in');
|
||||
@ -504,7 +409,6 @@ class ClientController extends BaseController
|
||||
->where('branches.branch_id ',$branch_id)
|
||||
->first();
|
||||
$business_id = $business['business_id'];
|
||||
|
||||
$insertData = [
|
||||
"name" => $value['name'],
|
||||
"pan_no" => $value['pan_no'],
|
||||
@ -514,9 +418,7 @@ class ClientController extends BaseController
|
||||
"branch_id" => $branch_id,
|
||||
"business_id" => $business_id
|
||||
];
|
||||
|
||||
$client = $this->ClientModel->insert($insertData);
|
||||
|
||||
if($client){
|
||||
if($value['branches']){
|
||||
foreach ($value['branches'] as $key => $branch) {
|
||||
@ -534,10 +436,8 @@ class ClientController extends BaseController
|
||||
];
|
||||
$clientBranch = $this->ClientBranchModel->insert($insertBranchData);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return json_encode(true);
|
||||
} else {
|
||||
@ -547,11 +447,6 @@ class ClientController extends BaseController
|
||||
echo "No file uploaded.";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -12,7 +12,6 @@ use App\Models\TemplateModel;
|
||||
|
||||
use CodeIgniter\API\ResponseTrait;
|
||||
|
||||
|
||||
class StaffController extends BaseController
|
||||
{
|
||||
public $session;
|
||||
@ -38,18 +37,14 @@ class StaffController extends BaseController
|
||||
$this->BranchModel = new BranchModel();
|
||||
$this->TemplateModel = new TemplateModel();
|
||||
}
|
||||
|
||||
|
||||
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()
|
||||
{
|
||||
|
||||
// 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->request->getmethod() == 'POST')
|
||||
{
|
||||
@ -63,21 +58,17 @@ class StaffController extends BaseController
|
||||
$this->session->setTempdata('error','Staff Deactivated',3);
|
||||
return redirect()->to(base_url()."staff");
|
||||
}
|
||||
|
||||
if (password_verify($password, $staffdata['password']))
|
||||
{
|
||||
$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']);
|
||||
|
||||
|
||||
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');
|
||||
}
|
||||
else{
|
||||
@ -88,10 +79,7 @@ class StaffController extends BaseController
|
||||
$this->session->setTempdata('error','Email or Password is invalid',3);
|
||||
return redirect()->to(base_url()."staff");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
//get method
|
||||
return view('staff_login');
|
||||
}
|
||||
@ -103,18 +91,10 @@ class StaffController extends BaseController
|
||||
return redirect()->to(base_url()."staff");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// staff crud
|
||||
public function staff_list()
|
||||
{
|
||||
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'));
|
||||
$staffdata = $this->StaffModel->where('staff_id',$this->session->get('is_staff_logged_in'))->get()->getRow();
|
||||
echo view('layout/header', ['Data'=>$staffdata]);
|
||||
@ -123,81 +103,60 @@ 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')
|
||||
{
|
||||
$email = $this->request->getVar('email');
|
||||
$staff = $this->StaffModel->where('email', $email)->first();
|
||||
|
||||
if($staff){
|
||||
return json_encode('mail_exists');
|
||||
}else{
|
||||
$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');
|
||||
|
||||
$staffData['business_id'] = json_encode($this->request->getVar('business_id'));
|
||||
|
||||
$insert = $this->StaffModel->save($staffData);
|
||||
if($insert)
|
||||
{
|
||||
return json_encode('staff_created');
|
||||
// return redirect()->to(base_url()."staff_list");
|
||||
}
|
||||
}
|
||||
|
||||
}else{
|
||||
|
||||
$staffdata = $this->StaffModel->where('staff_id',$this->session->get('is_staff_logged_in'))->get()->getRow();
|
||||
$data['business'] = $this->BusinessModel->where('isactive', 1)->findAll();
|
||||
// $data['branch'] = $this->BranchModel->where('isactive', 1)->findAll();
|
||||
$data['page_heading'] = "Create Staff";
|
||||
echo view('layout/header', ['Data'=>$staffdata]);
|
||||
echo view('staff_form', $data);
|
||||
echo view('layout/footer');
|
||||
}
|
||||
}
|
||||
|
||||
public function staff_edit($staff_id = null)
|
||||
{
|
||||
if(!$this->session->has('is_staff_logged_in')){ return redirect()->to(base_url().'staff'); }
|
||||
if($this->request->getmethod() == 'POST')
|
||||
{
|
||||
//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');
|
||||
// return redirect()->to(base_url()."staff_list");
|
||||
$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');
|
||||
}else{
|
||||
|
||||
$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();
|
||||
// print_r($data['staffData']->business_id);die;
|
||||
$data['page_heading'] = "Edit Staff";
|
||||
echo view('layout/header', ['Data'=>$staffdata]);
|
||||
echo view('staff_form',$data);
|
||||
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();
|
||||
$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();
|
||||
@ -205,21 +164,17 @@ class StaffController extends BaseController
|
||||
}else{
|
||||
$businessData[] = $this->BusinessModel->where('business_id', $businessIds)->first();
|
||||
}
|
||||
|
||||
return json_encode($businessData);
|
||||
|
||||
}
|
||||
|
||||
|
||||
// client crud
|
||||
public function client_list()
|
||||
{
|
||||
if(!$this->session->has('is_staff_logged_in')){ return redirect()->to(base_url().'staff'); }
|
||||
|
||||
|
||||
$data['clientList'] = $this->ClientModel->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();
|
||||
foreach (json_decode($staffdata->business_id) as $key => $value) {
|
||||
$business = $this->BusinessModel->where('business_id', $value)->first();
|
||||
if ($business) {
|
||||
|
||||
@ -180,7 +180,6 @@
|
||||
<ul class="list-unstyled topnav-menu float-right mb-0">
|
||||
|
||||
<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"
|
||||
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>
|
||||
<?php } ?>
|
||||
</li>
|
||||
<li>
|
||||
<?php if(isset($_SESSION['logged_in_staff_business_id']) && $_SESSION['logged_in_staff_business_id']) { ?>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user