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
{
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')
$data['branch'] = $this->BranchModel->select('branches.*, business.business_name')
->join('business', 'branches.business_id = business.business_id', 'left')
->findAll();
$data['business_list'] = $BusinessModel->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);
$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);
$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,15 +86,11 @@ 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()
{
try {

View File

@ -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);
$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') {
$data['business'] = [];
$data['page_name']="Add Branch";
} else if ($business_id !== '0') {
$BusinessModel = new BusinessModel();
$business=$BusinessModel->getBusinessById($business_id);
$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();
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);
// }
}
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);
}
}
}

View File

@ -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');
}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,11 +95,9 @@ 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();
@ -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,13 +276,10 @@ 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');
@ -360,7 +288,6 @@ 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);
}
@ -369,28 +296,19 @@ class ClientController extends BaseController
public function edit_client_branch()
{
$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.";
}
}
}

View File

@ -38,8 +38,6 @@ class MasterController extends BaseController
use ResponseTrait;
public function __construct()
{
$this->session = session();
@ -55,13 +53,9 @@ class MasterController extends BaseController
$this->DocsStatusModel = new DocsStatusModel();
$this->db = \Config\Database::connect();
}
function getBusinessDetails($businessIds) {
// This is just a placeholder for your actual database call
// Replace this with your actual query logic
$businessDetails = [];
foreach ($businessIds as $businessId) {
// Example data fetched from the database
@ -70,24 +64,17 @@ class MasterController extends BaseController
return $businessDetails;
}
public function service_group_list()
{
if(!$this->session->has('is_staff_logged_in')){ return redirect()->to(base_url().'staff'); }
// Fetch all service groups
$serviceGroups = $this->ServiceGroupModel->select('service_group.*')
->findAll();
$serviceGroups = $this->ServiceGroupModel->select('service_group.*')->findAll();
// Fetch services grouped by service_group_id
$services = $this->ServiceGroupModel->select('service_group.service_group_id, services.service_name')
->join('services', 'service_group.service_group_id = services.service_group_id', 'left')
->findAll();
// Initialize an array to store service counts and service names by group
$serviceCounts = [];
$serviceNamesByGroup = [];
// Group services by service group id and count services
foreach ($services as $service) {
$serviceGroupId = $service['service_group_id'];
@ -100,104 +87,71 @@ class MasterController extends BaseController
$serviceNamesByGroup[$serviceGroupId][] = $service['service_name'];
}
}
// Assign service counts and names to service groups
foreach ($serviceGroups as &$group) {
$groupId = $group['service_group_id'];
$group['service_count'] = isset($serviceCounts[$groupId]) ? $serviceCounts[$groupId] : 0;
$group['service_list'] = isset($serviceNamesByGroup[$groupId]) ? $serviceNamesByGroup[$groupId] : [];
}
// Set the modified service groups to the data array
$data['serviceGroupList'] = $serviceGroups;
foreach ($serviceGroups as &$group) {
$groupId = $group['service_group_id'];
$group['service_count'] = isset($serviceNamesByGroup[$groupId]) ? count($serviceNamesByGroup[$groupId]) : 0;
$group['service_list'] = isset($serviceNamesByGroup[$groupId]) ? $serviceNamesByGroup[$groupId] : [];
}
// Set the modified service groups to the data array
$data['serviceGroupList'] = $serviceGroups;
$data['business_list'] = $this->BusinessModel->findAll();
$staffdata = $this->StaffModel->where('staff_id',$this->session->get('is_staff_logged_in'))->get()->getRow();
foreach ($data['serviceGroupList'] as $key => $value) {
// Decode the JSON encoded business_id
$businessIds = json_decode($value['business_id'], true);
// Find the business details
$businessDetails = $this->getBusinessDetails($businessIds);
// Add business count
$value['business_count'] = count($businessIds);
// Add business details to the service group
$value['business_list'] = $businessDetails;
// Update the serviceGroupList array with the new data
$data['serviceGroupList'][$key] = $value;
}
// echo "<pre>";
// print_r($data);die;
echo view('layout/header', ['Data'=>$staffdata]);
echo view('service_group_list',$data);
echo view('layout/footer');
}
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();
$this->ServiceGroupModel->where('service_group_id', $this->request->getVar('service_group_id') )->set($serviceGroupData)
->update();
}else{
$serviceGroupData = $this->request->getVar();
$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);
}
return redirect()->to(base_url()."service_group_list");
}
}
public function service_group_edit()
{
if(!$this->session->has('is_staff_logged_in')){ return redirect()->to(base_url().'staff'); }
$service_group_id = $this->request->getVar('service_group_id');
$data = $this->ServiceGroupModel->where('service_group_id',$service_group_id)->get()->getRow();
return $this->response->setJSON(['success' => true , 'data' =>$data]);
}
public function service_list()
{
if(!$this->session->has('is_staff_logged_in')){ return redirect()->to(base_url().'staff'); }
$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')
@ -216,33 +170,23 @@ class MasterController extends BaseController
echo view('layout/header', ['Data'=>$staffdata]);
echo view('service_list',$data);
echo view('layout/footer');
}
public function service_create()
{
if(!$this->session->has('is_staff_logged_in')){ return redirect()->to(base_url().'staff'); }
if($this->request->getmethod() == 'POST')
{
$serviceData = $this->request->getVar();
if( isset($serviceData['service_id']) ){
$this->ServiceModel->where('service_id', $this->request->getVar('service_id') )->set($serviceData)->update();
}else{
$serviceData = $this->request->getVar();
$serviceData['branch_id'] = $this->session->get('logged_in_staff_branch_id');
$this->ServiceModel->insert($serviceData);
}
return redirect()->to(base_url()."service_list");
}else{
$staffdata = $this->StaffModel->where('staff_id',$this->session->get('is_staff_logged_in'))->get()->getRow();
echo view('layout/header', ['Data'=>$staffdata]);
echo view('service_form');
@ -253,30 +197,18 @@ class MasterController extends BaseController
public function service_edit()
{
if(!$this->session->has('is_staff_logged_in')){ return redirect()->to(base_url().'staff'); }
$service_id = $this->request->getVar('service_id');
$data = $this->ServiceModel->where('service_id',$service_id)->get()->getRow();
return $this->response->setJSON(['success' => true , 'data' =>$data]);
}
public function template_list()
{
if(!$this->session->has('is_staff_logged_in')){ return redirect()->to(base_url().'staff'); }
$data['templateData'] = $this->TemplateModel->select('template.* , services.service_name , service_group.group_name')
->join('services', 'services.service_id = template.service_id', 'left')
->join('service_group', 'template.service_group_id = service_group.service_group_id', 'left')
->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();
@ -287,17 +219,14 @@ class MasterController extends BaseController
echo view('layout/header', ['Data'=>$staffdata]);
echo view('template_list',$data);
echo view('layout/footer');
}
public function template_create()
{
if(!$this->session->has('is_staff_logged_in')){ return redirect()->to(base_url().'staff'); }
if($this->request->getmethod() == 'POST')
{
$templateData = $this->request->getVar();
if($this->request->getVar('template_id') != 'null'){
$id = $this->request->getVar('template_id');
unset($templateData['template_id']);
@ -308,15 +237,10 @@ class MasterController extends BaseController
$this->TemplateModel->insert($templateData);
return $this->response->setJSON(['success' => true , 'service_id' =>$this->request->getVar('service_id')]);
}
}else{
$id = $this->request->getVar('service_id');
$data['AllServiceGroupData'] = $this->ServiceGroupModel->findAll();
$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();
@ -330,59 +254,46 @@ class MasterController extends BaseController
}
}
public function template_edit()
{
if(!$this->session->has('is_staff_logged_in')){ return redirect()->to(base_url().'staff'); }
$id = $this->request->getVar('template_id');
$data['templateData'] = $this->TemplateModel->where('md5(template_id)',$id)->get()->getRow();
$data['serviceData'] = $this->ServiceModel->where('service_id',$data['templateData']->service_id)->get()->getRow();
// $data['AllServiceData'] = $this->ServiceModel->where('branch_id',$this->session->get('logged_in_staff_branch_id'))->findAll();
$data['AllServiceData'] = $this->ServiceModel->findAll();
$data['serviceGroupData'] = $this->ServiceGroupModel->where('service_group_id',$data['templateData']->service_group_id)->get()->getRow();
// $data['AllServiceGroupData'] = $this->ServiceGroupModel->where('branch_id',$this->session->get('logged_in_staff_branch_id'))->findAll();
$data['serviceGroupData'] = $this->ServiceGroupModel->where('service_group_id',$data['templateData']->service_group_id)
->get()
->getRow();
$data['AllServiceGroupData'] = $this->ServiceGroupModel->findAll();
$data['BusinessData'] = $this->BusinessModel->where('business_id',$data['templateData']->template_header_business)->where('isactive',1)->get()->getRow();
$data['BusinessData'] = $this->BusinessModel->where('business_id',$data['templateData']->template_header_business)
->where('isactive',1)
->get()
->getRow();
$data['AllBusinessData'] = $this->BusinessModel->where('isactive',1)->findAll();
$staffdata = $this->StaffModel->where('staff_id',$this->session->get('is_staff_logged_in'))->get()->getRow();
echo view('layout/header', ['Data'=>$staffdata]);
echo view('template_form',$data);
echo view('layout/footer');
}
public function template_preview()
{
if(!$this->session->has('is_staff_logged_in')){ return redirect()->to(base_url().'staff'); }
$id = $this->request->getVar('template_id');
$data['templateData'] = $this->TemplateModel->where('md5(template_id)',$id)->get()->getRow();
$data['serviceData'] = $this->ServiceModel->where('service_id',$data['templateData']->service_id)->get()->getRow();
$data['businessData'] = $this->BusinessModel->where('business_id',$data['templateData']->template_header_business)->get()->getRow();
$data['businessData'] = $this->BusinessModel->where('business_id',$data['templateData']->template_header_business)
->get()
->getRow();
$staffdata = $this->StaffModel->where('staff_id',$this->session->get('is_staff_logged_in'))->get()->getRow();
$data['body_html'] = $data['templateData']->body_html;
// echo view('layout/header', ['Data'=>$staffdata]);
echo view('template_preview',$data);
// echo view('layout/footer');
}
public function shared_docs_list()
{
if(!$this->session->has('is_staff_logged_in')){ return redirect()->to(base_url().'staff'); }
$currentDate = new \DateTime();
// Determine the start and end dates of the current financial year
if ($currentDate->format('n') >= 4) {
// If the current month is April (4) or later, the financial year started this year
@ -393,46 +304,11 @@ class MasterController extends BaseController
$financialYearStart = new \DateTime(($currentDate->format('Y') - 1) . '-04-01');
$financialYearEnd = new \DateTime($currentDate->format('Y') . '-03-31');
}
// Convert to the format suitable for your database (assuming MySQL)
$financialYearStart = $financialYearStart->format('Y-m-d');
$financialYearEnd = $financialYearEnd->format('Y-m-d');
$staffdata = $this->StaffModel->where('staff_id',$this->session->get('is_staff_logged_in'))->get()->getRow();
if($this->session->get('logged_in_staff_role') == 'Admin'){
$includeArchived = $this->session->get('include_archived');
if (isset($includeArchived) && $includeArchived == 'false') {
$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();
}else{
$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')
->where('client_docs.created_at >=', $financialYearStart)
->where('client_docs.created_at <=', $financialYearEnd)
->orderBy('client_docs.id','DESC')
->findAll();
}
// 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,
@ -451,9 +327,6 @@ class MasterController extends BaseController
->get()
->getResultArray();
$business_id_check = 0;
// echo "<pre>";
// 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){
@ -461,30 +334,19 @@ class MasterController extends BaseController
}
}
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 "<pre>";
// print_r($data['doc_list']);die;
$docStatusByClientId = [];
// Fetch all doc_status entries and group them by client_docs_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();
foreach ($data['serviceGroupData'] as $key => $value) {
$check_its_okay = 0;
foreach (json_decode($value['business_id']) as $values) {
@ -492,16 +354,12 @@ class MasterController extends BaseController
$check_its_okay =1;
}
}
if($check_its_okay == 0){
unset($data['serviceGroupData'][$key]);
}
$check_its_okay = 0;
}
}
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')
->select('created_at as doc_created_date')
@ -521,16 +379,12 @@ class MasterController extends BaseController
$data['business_list'][] = $business;
}
}
// echo"<pre>";
// print_r($data);die;
echo view('layout/header', ['Data'=>$staffdata]);
echo view('share_docs',$data);
echo view('layout/footer');
}
public function set_include_archived_session($checked_or_not) {
// print_r($checked_or_not);die;
if($checked_or_not == true){
// $includeArchived = $this->request->getGet('include_archived');
$this->session->set('include_archived', $checked_or_not);
@ -541,11 +395,9 @@ class MasterController extends BaseController
return $this->response->setJSON(['status' => 'success']);
}
public function shared_doc_non_financial_year_to(){
if(!$this->session->has('is_staff_logged_in')){ return redirect()->to(base_url().'staff'); }
$currentDate = new \DateTime();
// Determine the start and end dates of the current financial year
if ($currentDate->format('n') >= 4) {
// If the current month is April (4) or later, the financial year started this year
@ -556,7 +408,6 @@ class MasterController extends BaseController
$financialYearStart = new \DateTime(($currentDate->format('Y') - 1) . '-04-01');
$financialYearEnd = new \DateTime($currentDate->format('Y') . '-03-31');
}
// Convert to the format suitable for your database (assuming MySQL)
$financialYearStart = $financialYearStart->format('Y-m-d');
$financialYearEnd = $financialYearEnd->format('Y-m-d');
@ -570,18 +421,13 @@ class MasterController extends BaseController
->join('client', 'client.client_id = client_branch.client_id', 'left')
->orderBy('client_docs.id','DESC')
->findAll();
// 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();
}
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')
->select('created_at as doc_created_date')
@ -601,8 +447,6 @@ class MasterController extends BaseController
$data['business_list'][] = $business;
}
}
// echo"<pre>";
// print_r($data);die;
echo view('layout/header', ['Data'=>$staffdata]);
echo view('share_docs',$data);
echo view('layout/footer');
@ -618,17 +462,13 @@ class MasterController extends BaseController
unset($data['id']);
$this->ClientDocsModel->where('id', $id )->set($data)->update();
return $this->response->setJSON(['success' => true ]);
}else{
$id = $this->request->getVar('doc_id');
$data['templateData'] = $this->ClientDocsModel->where('md5(id)',$id)->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('edit_shared_doc',$data);
echo view('layout/footer');
}
@ -636,33 +476,24 @@ class MasterController extends BaseController
public function get_service_data()
{
$service_group_id = $this->request->getVar('service_group_id');
$result = $this->ServiceModel->where('service_group_id',$service_group_id)->findAll();
return $this->response->setJSON(['count'=>count($result) , 'data'=>$result ]);
}
public function get_templates()
{
$result = $this->TemplateModel->where('service_id',$this->request->getVar('service_id'))->findAll();
return $this->response->setJSON(['count'=>count($result) , 'data'=>$result ]);
}
public function create_docs()
{
$docData = $this->request->getVar();
$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);
if($insert){
$data['client_docs_id'] = $insert;
$data['is_staff'] = 1;
$data['created_by'] = $this->session->get('is_staff_logged_in');
@ -672,8 +503,6 @@ class MasterController extends BaseController
} else {
echo false;
}
}
public function client_docs_preview()
@ -683,18 +512,16 @@ class MasterController extends BaseController
}else if($this->session->has('is_client_logged_in')){
$userData = $this->ClientBranchModel->where('id',$this->session->get('is_client_logged_in'))->get()->getRow();
}
$doc_id = $this->request->getVar('doc_id');
$data['docData'] = $this->ClientDocsModel->docPreview($doc_id);
$data['clientData'] = $this->ClientBranchModel->select('client.name , client.pan_no ,client_branch.gst_no , client_branch.mobile_no , client_branch.email , client_branch.address , client_branch.country , client_branch.state , client_branch.city , client_branch.pin_code ')
$data['clientData'] = $this->ClientBranchModel->select('client.name , client.pan_no ,
client_branch.gst_no , client_branch.mobile_no ,
client_branch.email , client_branch.address ,
client_branch.country , client_branch.state ,
client_branch.city , client_branch.pin_code ')
->join('client', 'client_branch.client_id = client.client_id', 'left')
->where('client_branch.id',$data['docData']->client_branch_id)
->get()->getRow();
$data['header_html'] = $data['docData']->header_html;
$data['footer_html'] = $data['docData']->footer_html;
$data['body_html'] = $data['docData']->body_html;
@ -703,25 +530,19 @@ class MasterController extends BaseController
$placeHolder = '%'.$key.'%';
$data['body_html'] = str_replace($placeHolder,$value,$data['body_html']);
}
if($data['docData']->is_active == 1){
$DateAndYears = $data['docData']->place_holder_object;
}else{
$DateAndYears = $this->dateAndYearPlaceholder();
}
//replace Date and Year values in template content
// print_r($DateAndYears);die;
foreach (json_decode($DateAndYears,true) as $key => $value) {
$placeHolder = '%'.$key.'%';
$data['body_html'] = str_replace($placeHolder,$value,$data['body_html']);
}
echo view('layout/header', ['Data'=>$userData]);
echo view('client_docs_preview',$data);
echo view('layout/footer');
}
public function dateAndYearPlaceholder()
@ -729,8 +550,6 @@ class MasterController extends BaseController
$currentDate = date('d-m-Y');
$currentYear = date('Y');
$currentMonth = date('m');
if ($currentMonth >= 4) {
$financialYearStart = $currentYear . '-04-01';
$financialYearEnd = ($currentYear + 1) . '-03-31';
@ -740,7 +559,6 @@ class MasterController extends BaseController
$q2 = '01-07-' . $currentYear . ' to ' . '30-09-' . $currentYear;
$q3 = '01-10-' . $currentYear . ' to ' . '31-12-' . $currentYear;
$q4 = '01-01-' . ($currentYear + 1) . ' to ' . '31-03-' . ($currentYear + 1);
} else {
$financialYearStart = ($currentYear - 1) . '-04-01';
$financialYearEnd = $currentYear . '-03-31';
@ -751,7 +569,6 @@ class MasterController extends BaseController
$q3 = '01-10-' . ($currentYear - 1) . ' to ' . '31-12-' . ($currentYear - 1);
$q4 = '01-01-' . $currentYear . ' to ' . '31-03-' . $currentYear;
}
$DateAndYears = [
"CD" => $currentDate,
"CY" => $currentYear,
@ -762,9 +579,7 @@ class MasterController extends BaseController
"Q3" => $q3,
"Q4" => $q4,
];
return json_encode($DateAndYears);
}
public function client_docs_histroy($doc_id)
@ -774,18 +589,14 @@ class MasterController extends BaseController
}else if($this->session->has('is_client_logged_in')){
$userData = $this->ClientBranchModel->where('id',$this->session->get('is_client_logged_in'))->get()->getRow();
}
$data['docData'] = $this->ClientDocsModel->docPreview($doc_id);
// Fetch the document history
$clientDocHistory = $this->DocsStatusModel->select('*')
->where('client_docs_id', $doc_id)
->get()
->getResult();
// Initialize an array to store the augmented results
$augmentedHistory = [];
foreach ($clientDocHistory as $history) {
if ($history->is_staff == 1) {
// Fetch staff details
@ -804,75 +615,45 @@ class MasterController extends BaseController
$history->creator_details = $clientDetails;
$history->creator_type = 'client';
}
// Add the augmented history to the array
$augmentedHistory[] = $history;
}
// Assign the augmented history to the data array
$data['client_doc_history'] = $augmentedHistory;
// Debug output
// echo "<pre>";
// print_r($data['client_doc_history']);
// die;
return json_encode($data);
// echo view('layout/header', ['Data'=>$userData]);
// echo view('doc_history',$data);
// echo view('layout/footer');
}
public function change_doc_status()
{
try {
$doc_id = $this->request->getPost('doc_id');
$is_active = $this->request->getPost('is_active');
$data['is_active'] = $is_active;
if($is_active == 1){
$DateAndYears = $this->dateAndYearPlaceholder();
$data['place_holder_object'] = $DateAndYears;
$MailHelper = new MailHelper();
$clientData = $this->ClientDocsModel->select('client.name , client_branch.email, client_branch.*')
->join('client_branch', 'client_docs.client_branch_id = client_branch.id', 'left')
->join('client', 'client_branch.client_id = client.client_id', 'left')
->where('client_docs.id', $doc_id)->get()->getRow();
$documentUrl = base_url();
helper('url');
$url ='<a href="' . generate_signed_url('preview', ['doc_id'=> md5($doc_id)], 36000) . '">Preview and Approve Document</a>';
// $url = '<a href="' . $documentUrl . '">Preview and Approve Document</a>';
$businessData = $this->BranchModel->select('branches.* , business.business_name ')
->join('business', 'branches.business_id = business.business_id', 'left')
// ->where('branches.branch_id',$this->session->get('logged_in_staff_branch_id'))
->where('branches.branch_id',1)
->where('branches.branch_id',$this->session->get('logged_in_staff_branch_id'))
->get()->getRow();
$subject = 'BB-Sign Verify Document';
$message = "Dear " . $clientData->name . ",<br>" . $businessData->business_name . " has requested your approval for a document. Please click the link below to preview and approve.<br><br>" . $url;
$mail_send = $MailHelper->send_url_email($clientData->email , $businessData->email, $subject, $message);
$notificationHelper = new NotificationHelper();
$number = '91'.$clientData->mobile_no; // Replace with dynamic recipient number
if($clientData->whatsapp == 1){
$whatsApp_message = "Dear " . $clientData->name . "," . $businessData->business_name . " has requested your approval for a document. Please click the link below to preview and approve." ;
$notificationHelper->sendWhatsAppMessage($number, $whatsApp_message, $url);
}
$statusData['client_docs_id'] = $doc_id;
$statusData['is_staff'] = 1;
$statusData['created_by'] = $this->session->get('is_staff_logged_in');
@ -885,9 +666,7 @@ class MasterController extends BaseController
$statusData['status'] = 'Revert';
$this->DocsStatusModel->insert($statusData);
}
$updated = $this->ClientDocsModel->update($doc_id, $data);
if ($updated) {
return $this->response->setJSON(['status' => 'success','code' => 200,'data' => true],200);
} else {
@ -899,60 +678,42 @@ class MasterController extends BaseController
}
}
public function rememeber_notification()
{
try {
$doc_id = $this->request->getPost('doc_id');
$MailHelper = new MailHelper();
$clientData = $this->ClientDocsModel->select('client.name , client_branch.email, client_branch.mobile_no')
->join('client_branch', 'client_docs.client_branch_id = client_branch.id', 'left')
->join('client', 'client_branch.client_id = client.client_id', 'left')
->where('client_docs.id', $doc_id)->get()->getRow();
helper('url');
$url ='<a href="' . generate_signed_url('preview', ['doc_id'=>md5($doc_id)], 100) . '">Preview and Approve Document</a>';
// $url = '<a href="'.base_url().'">Click here</a>';
$businessData = $this->BranchModel->select('branches.* , business.business_name ')
->join('business', 'branches.business_id = business.business_id', 'left')
->where('branches.branch_id',$this->session->get('logged_in_staff_branch_id'))
->get()->getRow();
$subject = 'BB-Sign Verify Document';
$message = "Dear " . $clientData->name . ",<br>" . $businessData->business_name . " has requested your approval for a document. Please click the link below to preview and approve.<br><br>" . $url;
$MailHelper->send_url_email($clientData->email , $businessData->email, $subject, $message);
$notificationHelper = new NotificationHelper();
$number = '91'.$clientData->mobile_no; // Replace with dynamic recipient number
if($clientData->whatsapp == 1){
$whatsApp_message = "Dear " . $clientData->name . "," . $businessData->business_name . " has requested your approval for a document. Please click the link below to preview and approve." ;
$notificationHelper->sendWhatsAppMessage($number, $whatsApp_message, $url);
}
return $this->respond(['success' => true, 'data' => 'Remember Send Successfully']);
} catch (\Exception $exception) {
return $this->response->setJSON(['status' => 'failed','code' => 500,'data' => $exception],500);
}
}
public function doc_generate_otp()
{
try {
$mobile_no = $this->request->getPost('mobile_no');
$client_data = $this->ClientBranchModel->where('mobile_no', $mobile_no )->first();
if($client_data){
$id = $this->request->getPost('doc_id');
$otp = mt_rand(100000, 999999);
$data = ['otp' => $otp];
@ -964,25 +725,18 @@ class MasterController extends BaseController
->join('client', 'client.client_id = client_branch.client_id', 'left')
->where('client_docs.id', $id)
->first();
$update = $this->ClientDocsModel->update($id, $data);
if($update){
$notificationHelper = new NotificationHelper();
$number = '91'.$mobile_no; // Replace with dynamic recipient number
$message = 'Document Verification OTP : ' . $otp;
if($client_data['whatsapp'] == 1){
$notificationHelper->sendWhatsAppMessage($number, $message);
}
if($client_data['sms'] == 1){
$notificationHelper->sendSms($number, $client_data['name'] , $otp, '', 'doc_verify',$clint_full_data);
}
return $this->respond(['success' => true, 'otp' => $otp]);
}
} else {
return false;
@ -993,23 +747,17 @@ class MasterController extends BaseController
}
}
public function doc_verify_otp()
{
try {
$id = $this->request->getPost('doc_id');
$otp = $this->request->getPost('otp');
$client_doc_data = $this->ClientDocsModel->where('id', $id )->where('otp', $otp)->first();
$data = ['otp' =>'' ,'rejection_reason' =>''];
if($client_doc_data){
$data['is_approved'] = $this->request->getPost('is_approved');
$data['ip_address'] = $this->request->getPost('clientIp');
$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;
@ -1022,13 +770,10 @@ class MasterController extends BaseController
$statusData['status'] = 'Approved';
$statusData['note'] = $this->request->getPost('clientIp');
$this->DocsStatusModel->insert($statusData);
if($update){
return json_encode(true);
}
} else {
return json_encode('');
}
} catch (\Exception $e) {
@ -1037,16 +782,12 @@ class MasterController extends BaseController
}
}
public function status_service()
{
try {
$service_id = $this->request->getPost('service_id');
$is_active = $this->request->getPost('is_active');
$data = ['is_active' => $is_active];
$updated = $this->ServiceModel->update($service_id, $data);
if ($updated) {
return $this->respond(['status' => 'success','code' => 200,'data' => true],200);
@ -1059,24 +800,18 @@ class MasterController extends BaseController
}
}
public function download_doc(){
if ($this->request->getMethod() === 'POST') {
// Get the HTML content from the POST request
$htmlContent = $this->request->getPost('htmlContent');
try {
// Create new PDF document
$mpdf = new Mpdf();
$mpdf->WriteHTML($htmlContent);
// Output PDF to a string
$pdfContent = $mpdf->Output('', 'S');
// Encode PDF content to base64
$base64Pdf = base64_encode($pdfContent);
// print_r("hello");die;
// Set response headers
return $this->respond(['pdf' => $base64Pdf], 200);
} catch (\Exception $e) {
@ -1088,6 +823,4 @@ class MasterController extends BaseController
return $this->fail('Invalid request method', 405);
}
}
}

View File

@ -12,7 +12,6 @@ use App\Models\TemplateModel;
use CodeIgniter\API\ResponseTrait;
class StaffController extends BaseController
{
public $session;
@ -39,17 +38,13 @@ class StaffController extends BaseController
$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");
}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) {

View File

@ -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']) { ?>