diff --git a/app/Config/Routes.php b/app/Config/Routes.php index b61b6a8..157ab9c 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -65,6 +65,8 @@ use CodeIgniter\Router\RouteCollection; $routes->match(['get','post'],'/template_preview','MasterController::template_preview'); $routes->match(['get','post'],'/shared_docs_list','MasterController::shared_docs_list'); + $routes->match(['get','post'],'/shared_doc_non_financial_year_to','MasterController::shared_doc_non_financial_year_to'); + $routes->match(['get','post'],'/set_include_archived_session/(:any)','MasterController::set_include_archived_session/$1'); $routes->match(['get','post'],'/get_templates','MasterController::get_templates'); $routes->match(['get','post'],'/create_docs','MasterController::create_docs'); $routes->match(['get','post'],'/client_docs_preview','MasterController::client_docs_preview'); diff --git a/app/Controllers/MasterController.php b/app/Controllers/MasterController.php index 3e66405..ac08f6f 100644 --- a/app/Controllers/MasterController.php +++ b/app/Controllers/MasterController.php @@ -302,11 +302,31 @@ class MasterController extends BaseController public function shared_docs_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'); } + $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 + $financialYearStart = new \DateTime($currentDate->format('Y') . '-04-01'); + $financialYearEnd = new \DateTime(($currentDate->format('Y') + 1) . '-03-31'); + } else { + // If the current month is before April, the financial year started last year + $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'){ - $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') + + 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') @@ -314,13 +334,24 @@ 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')) + }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{ @@ -337,7 +368,8 @@ class MasterController extends BaseController ->join('client_branch', 'client_branch.id = client_docs.client_branch_id', 'left') ->join('client', 'client.client_id = client_branch.client_id ' , 'left') // ->where('client.business_id', $business_id) - // ->where('service_group.business_id', $business_id ) + ->where('client_docs.created_at >=', $financialYearStart) + ->where('client_docs.created_at <=', $financialYearEnd) // ->where("JSON_CONTAINS(service_group.business_id, '" . $business_id . "')") ->orderBy('client_docs.id', 'DESC') ->get() @@ -368,30 +400,44 @@ class MasterController extends BaseController // Fetch all doc_status entries and group them by client_docs_id - foreach ($data['doc_list'] as $doc) { - // print_r($doc['id']);die; - $doc_id_temp = $doc['id']; - $docStatusByClientId[$doc_id_temp] = $this->db->table('docs_status') - ->where('client_docs_id', $doc_id_temp) - ->where('status', "Approved") - ->get() - ->getResultArray(); - } - // Assign doc_status arrays to each document in doc_list - foreach ($data['doc_list'] as &$doc) { - $doc['doc_status'] = isset($docStatusByClientId[$doc['id']]) ? $docStatusByClientId[$doc['id']] : []; - } - $data['clientdata'] = $this->ClientBranchModel->select('client.name as client_name , client_branch.name as client_branch_name , client_branch.id as client_branch_id') ->join('client', 'client_branch.client_id = client.client_id', 'left') // ->where('client.business_id',$this->session->get('logged_in_staff_business_id')) ->findAll(); + $data['serviceGroupData'] = $this->ServiceGroupModel->findAll(); + foreach ($data['serviceGroupData'] as $key => $value) { + $check_its_okay = 0; + foreach (json_decode($value['business_id']) as $values) { + if($values == $business_id){ + $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') + ->where('client_docs_id', $doc_id_temp) + ->where('status', "Approved") + ->get() + ->getResultArray(); + } + // Assign doc_status arrays to each document in doc_list + foreach ($data['doc_list'] as &$doc) { + $doc['doc_status'] = isset($docStatusByClientId[$doc['id']]) ? $docStatusByClientId[$doc['id']] : []; + } $data['business_list'] = []; foreach (json_decode($staffdata->business_id) as $key => $value) { $business = $this->BusinessModel->where('business_id', $value)->first(); @@ -407,6 +453,85 @@ class MasterController extends BaseController } + 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); + }else{ + $this->session->set('include_archived', $checked_or_not); + } + print_r($this->session->get('include_archived'));die; + 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 + $financialYearStart = new \DateTime($currentDate->format('Y') . '-04-01'); + $financialYearEnd = new \DateTime(($currentDate->format('Y') + 1) . '-03-31'); + } else { + // If the current month is before April, the financial year started last year + $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'){ + $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(); + + + // 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') + ->where('client_docs_id', $doc_id_temp) + ->where('status', "Approved") + ->get() + ->getResultArray(); + } + // Assign doc_status arrays to each document in doc_list + foreach ($data['doc_list'] as &$doc) { + $doc['doc_status'] = isset($docStatusByClientId[$doc['id']]) ? $docStatusByClientId[$doc['id']] : []; + } + $data['business_list'] = []; + foreach (json_decode($staffdata->business_id) as $key => $value) { + $business = $this->BusinessModel->where('business_id', $value)->first(); + if ($business) { + $data['business_list'][] = $business; + } + } + // echo"
";
+ // print_r($data);die;
+ echo view('layout/header', ['Data'=>$staffdata]);
+ echo view('share_docs',$data);
+ echo view('layout/footer');
+ }
+
public function shared_document_edit()
{
if(!$this->session->has('is_staff_logged_in')){ return redirect()->to(base_url().'staff'); }
@@ -648,7 +773,8 @@ class MasterController extends BaseController
$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',$this->session->get('logged_in_staff_branch_id'))
+ ->where('branches.branch_id',1)
->get()->getRow();
$subject = 'BB-Sign Verify Document';
$message = "Dear " . $clientData->name . ",
" . $businessData->business_name . " has requested your approval for a document. Please click the link below to preview and approve.
" . $url;
diff --git a/app/Controllers/StaffController.php b/app/Controllers/StaffController.php
index 38b2f35..7e77ca3 100644
--- a/app/Controllers/StaffController.php
+++ b/app/Controllers/StaffController.php
@@ -220,6 +220,12 @@ class StaffController extends BaseController
$data['clientList'] = $this->ClientModel->findAll();
$staffdata = $this->StaffModel->where('staff_id',$this->session->get('is_staff_logged_in'))->get()->getRow();
+ foreach (json_decode($staffdata->business_id) as $key => $value) {
+ $business = $this->BusinessModel->where('business_id', $value)->first();
+ if ($business) {
+ $data['business_list'][] = $business;
+ }
+ }
echo view('layout/header', ['Data'=>$staffdata]);
echo view('client_list',$data);
echo view('layout/footer');
@@ -265,12 +271,15 @@ class StaffController extends BaseController
{
$clientData = $this->request->getVar();
$clientData['created_by'] = $this->session->get('is_staff_logged_in');
- $clientData['branch_id'] = $this->session->get('logged_in_staff_branch_id');
- $business= $this->BranchModel->select('*')
- ->join('business' , 'branches.business_id = business.business_id', 'left')
- ->where('branches.branch_id ',$clientData['branch_id'])
- ->first();
- $clientData['business_id'] = $business['business_id'];
+ // $clientData['business_id'] = $this->session->get('logged_in_staff_business_id');
+ // $business= $this->BranchModel->select('*')
+ // ->join('business' , 'branches.business_id = business.business_id', 'left')
+ // ->where('branches.branch_id ',$clientData['branch_id'])
+ // ->first();
+ // $business= $this->BusinessModel->select('*')
+ // ->where('business_id ',$clientData['business_id'])
+ // ->first();
+ // $clientData['business_id'] = $business['business_id'];
// $insert = $this->ClientModel->save($clientData);
$insert = $this->ClientModel->insert($clientData);
if($insert)
@@ -285,6 +294,8 @@ class StaffController extends BaseController
$data['pin_code'] = $clientData['pin_code'];
$data['mobile_no'] = $clientData['branch_mobile_no'];
$data['gst_no'] = $clientData['gst_no'];
+ $data['sms'] = $clientData['sms'];
+ $data['whatsapp'] = $clientData['whatsapp'];
$branch_insert = $this->ClientBranchModel->insert($data);
@@ -321,8 +332,15 @@ class StaffController extends BaseController
echo true;
}else{
$staffdata = $this->StaffModel->where('staff_id',$this->session->get('is_staff_logged_in'))->get()->getRow();
+ $business_list = [];
+ foreach (json_decode($staffdata->business_id) as $key => $value) {
+ $business = $this->BusinessModel->where('business_id', $value)->first();
+ if ($business) {
+ $business_list[] = $business;
+ }
+ }
echo view('layout/header', ['Data'=>$staffdata]);
- echo view('staff_profile',['staff'=>$staffdata]);
+ echo view('staff_profile',['staff'=>$staffdata, 'business_list'=> $business_list]);
echo view('layout/footer');
}
}
diff --git a/app/Views/branch_list.php b/app/Views/branch_list.php
index 6b865f6..b860958 100644
--- a/app/Views/branch_list.php
+++ b/app/Views/branch_list.php
@@ -210,10 +210,10 @@
datatable_bikeModel = $('#business_branch_table').DataTable({
"order": [[0, 'asc']], // Set initial sorting to descending on the first column
"dom": 'Bfrtip', // Show export buttons
- "buttons": [{extend: 'pdfHtml5',title: 'Products', text: 'PDF',},
- {extend: 'print',title: 'Products',text: 'Print',},
+ "buttons": [{extend: 'pdfHtml5',title: 'Branches', text: 'PDF',},
+ {extend: 'print',title: 'Branches',text: 'Print',},
{extend: 'copy',text: 'Copy', titleAttr: 'Copy',},
- {extend: 'csv',text: 'CSV', title: 'Products', }],
+ {extend: 'csv',text: 'CSV', title: 'Branches', }],
"language": {
"search": "Search: " // Customize search label
},
diff --git a/app/Views/business_list.php b/app/Views/business_list.php
index 755685a..82f47c9 100644
--- a/app/Views/business_list.php
+++ b/app/Views/business_list.php
@@ -108,10 +108,10 @@
datatable_bikeModel = $('#business_table').DataTable({
"order": [[0, 'asc']], // Set initial sorting to descending on the first column
"dom": 'Bfrtip', // Show export buttons
- "buttons": [{extend: 'pdfHtml5',title: 'Products', text: 'PDF',},
- {extend: 'print',title: 'Products',text: 'Print',},
+ "buttons": [{extend: 'pdfHtml5',title: 'Business', text: 'PDF',},
+ {extend: 'print',title: 'Business',text: 'Print',},
{extend: 'copy',text: 'Copy', titleAttr: 'Copy',},
- {extend: 'csv',text: 'CSV', title: 'Products', }],
+ {extend: 'csv',text: 'CSV', title: 'Business', }],
"language": {
"search": "Search: " // Customize search label
},
diff --git a/app/Views/client_branch_list.php b/app/Views/client_branch_list.php
index de033c3..5c23601 100644
--- a/app/Views/client_branch_list.php
+++ b/app/Views/client_branch_list.php
@@ -95,7 +95,7 @@