From 27c6a2cc3c1253899cece5eb66c0cba4446e7cf5 Mon Sep 17 00:00:00 2001 From: aadhavan valli Date: Fri, 28 Jun 2024 15:27:36 +0530 Subject: [PATCH] CHANGE_TRACKER_ISSUE : AADHAVAN --- app/Controllers/BranchController.php | 2 +- app/Controllers/ClientController.php | 27 ++++- app/Controllers/MasterController.php | 158 ++++++++++++++++++++++----- app/Helpers/NotificationHelper.php | 33 ++++++ app/Views/branch_list.php | 12 +- app/Views/business_form.php | 2 +- app/Views/client_branch_list.php | 2 + app/Views/client_login.php | 1 + app/Views/service_group_list.php | 106 +++++++++++++++++- app/Views/service_list.php | 4 +- app/Views/share_docs.php | 61 +++++++++-- app/Views/staff_form.php | 2 +- app/Views/template_form.php | 31 +++++- 13 files changed, 386 insertions(+), 55 deletions(-) diff --git a/app/Controllers/BranchController.php b/app/Controllers/BranchController.php index 05405a6..f5282ca 100644 --- a/app/Controllers/BranchController.php +++ b/app/Controllers/BranchController.php @@ -70,7 +70,7 @@ class BranchController extends BaseController $BranchModel->insert($data); - return; + return json_encode(true); } diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index 3162472..018cb75 100644 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -91,6 +91,7 @@ class ClientController extends BaseController $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(); @@ -192,12 +193,28 @@ class ClientController extends BaseController $number = '91'. $client_branch_data['mobile_no']; // Replace with dynamic recipient number $message = 'Login OTP is: ' . $otp; - try { - $notificationHelper->sendWhatsAppMessage($number, $message); - return $this->respond(['success' => true, 'otp' => $otp]); - } catch (\Exception $e) { - return $this->respond(['Error' => $e->getMessage()]); + if($client_branch_data['whatsapp'] == 1){ + try { + $notificationHelper->sendWhatsAppMessage($number, $message); + // return $this->respond(['success' => true, 'otp' => $otp]); + } catch (\Exception $e) { + return $this->respond(['Error' => $e->getMessage()]); + } } + + if($client_branch_data['sms'] == 1){ + try { + $notificationHelper->sendSms(); + // return $this->respond(['success' => true, 'otp' => $otp]); + } catch (\Exception $e) { + return $this->respond(['Error' => $e->getMessage()]); + } + } + + + return $this->respond(['success' => true, 'otp' => $otp]); + + // Return success response with OTP } catch (\Exception $e) { diff --git a/app/Controllers/MasterController.php b/app/Controllers/MasterController.php index ac08f6f..2331286 100644 --- a/app/Controllers/MasterController.php +++ b/app/Controllers/MasterController.php @@ -59,19 +59,93 @@ class MasterController extends BaseController } + 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 + $businessDetails[] = $this->BusinessModel->select('business_name')->where('business_id', $businessId)->first(); + } + return $businessDetails; + } public function service_group_list() { if(!$this->session->has('is_staff_logged_in')){ return redirect()->to(base_url().'staff'); } - $data['serviceGroupList'] = $this->ServiceGroupModel->select('service_group.* , COUNT(services.service_id) as service_count') - ->join('services', 'service_group.service_group_id = services.service_group_id', 'left') - // ->where('service_group.business_id',$this->session->get('logged_in_staff_business_id')) - ->groupBy('service_group.service_group_id') - ->findAll(); + // Fetch all service groups + $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']; + if (!isset($serviceCounts[$serviceGroupId])) { + $serviceCounts[$serviceGroupId] = 0; + $serviceNamesByGroup[$serviceGroupId] = []; + } + if (!empty($service['service_name'])) { + $serviceCounts[$serviceGroupId]++; + $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 "
";
+        // print_r($data);die;
         echo view('layout/header', ['Data'=>$staffdata]);
         echo view('service_group_list',$data);
         echo view('layout/footer');
@@ -266,10 +340,12 @@ class MasterController extends BaseController
             $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->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['AllServiceGroupData'] = $this->ServiceGroupModel->where('branch_id',$this->session->get('logged_in_staff_branch_id'))->findAll();
+            $data['AllServiceGroupData'] = $this->ServiceGroupModel->findAll();
             
             $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();
@@ -581,7 +657,6 @@ class MasterController extends BaseController
     {
 
         $docData = $this->request->getVar();
-        $docData['is_active'] = 1;
         $docData['created_by'] = $this->session->has('is_staff_logged_in');  
         $docData['body_html'] = $this->TemplateModel->where('template_id',$this->request->getVar('template_id'))->get()->getRow()->body_html;
         $insert = $this->ClientDocsModel->insert($docData);
@@ -635,6 +710,7 @@ class MasterController extends BaseController
             $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']);
@@ -763,7 +839,7 @@ class MasterController extends BaseController
 
                 $MailHelper = new MailHelper();
 
-                $clientData =  $this->ClientDocsModel->select('client.name , client_branch.email, client_branch.mobile_no')
+                $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();
@@ -784,14 +860,20 @@ class MasterController extends BaseController
                 $notificationHelper = new NotificationHelper();
                 $number = '91'.$clientData->mobile_no; // Replace with dynamic recipient number
 
-                try {
-                    $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, 'otp' => $otp]);
-                } catch (\Exception $e) {
-                    return $this->respond(['Error' => $e->getMessage()]);
+                
+                // print_r($clientData);die;
+                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, 'otp' => $otp]);
+                   
+                }
+                
+                if($clientData->sms == 1){
+                        $notificationHelper->sendSms();
                 }
 
+                
                 $statusData['client_docs_id'] = $doc_id;
                 $statusData['is_staff'] = 1;
                 $statusData['created_by'] = $this->session->get('is_staff_logged_in');
@@ -845,13 +927,24 @@ class MasterController extends BaseController
             $notificationHelper = new NotificationHelper();
             $number = '91'.$clientData->mobile_no; // Replace with dynamic recipient number
 
-            try {
-                $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 $e) {
-                return $this->respond(['Error' => $e->getMessage()]);
-            }            
+            if($clientData->whatsapp == 1){
+                try {
+                    $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);
+                } catch (\Exception $e) {
+                    return $this->respond(['Error' => $e->getMessage()]);
+                }
+            }
+            
+            if($clientData->sms == 1){
+                try {
+                    $notificationHelper->sendSms();
+                } catch (\Exception $e) {
+                    return $this->respond(['Error' => $e->getMessage()]);
+                }
+            }           
+
+            return $this->respond(['success' => true, 'data' => 'Remember Send Successfully']);
         } catch (\Exception $exception) {
             return $this->response->setJSON(['status' => 'failed','code' => 500,'data' => $exception],500);
        }
@@ -878,12 +971,23 @@ class MasterController extends BaseController
                     $number = '91'.$mobile_no; // Replace with dynamic recipient number
                     $message = 'Document Verification OTP : ' . $otp;
 
-                    try {
-                        $notificationHelper->sendWhatsAppMessage($number, $message);
-                        return $this->respond(['success' => true, 'otp' => $otp]);
-                    } catch (\Exception $e) {
-                        return $this->respond(['Error' => $e->getMessage()]);
+                   
+                    if($client_data['whatsapp'] == 1){
+                        try {
+                            $notificationHelper->sendWhatsAppMessage($number, $message);
+                            return $this->respond(['success' => true, 'otp' => $otp]);
+                        } catch (\Exception $e) {
+                            return $this->respond(['Error' => $e->getMessage()]);
+                        }
                     }
+                    
+                    if($client_data['sms'] == 1){
+                        try {
+                            $notificationHelper->sendSms();
+                        } catch (\Exception $e) {
+                            return $this->respond(['Error' => $e->getMessage()]);
+                        }
+                    }   
                 }
             } else {
                 return false;
diff --git a/app/Helpers/NotificationHelper.php b/app/Helpers/NotificationHelper.php
index d496d12..c65a54b 100644
--- a/app/Helpers/NotificationHelper.php
+++ b/app/Helpers/NotificationHelper.php
@@ -3,11 +3,13 @@
 // app/Helpers/NotificationHelper.php
 
 namespace App\Helpers;
+use CodeIgniter\API\ResponseTrait;
 
 class NotificationHelper
 {
     protected $email;
     protected $logger;
+	use ResponseTrait;
 
     public function __construct()
     {
@@ -79,6 +81,37 @@ class NotificationHelper
         return true;
     }
     
+    public function sendSms()
+    {
+        $apiKey = 'HgvlULWCIrs'; // Your API key
+        // $mobileNumbers = '919894638731'; // Recipient mobile numbers
+        $mobileNumbers = '916379103977'; // Recipient mobile numbers
+        $DLTTemplateID = '1105171896608602869';  // DLT Template ID
+        $senderId = 'LDRAJ'; // Sender ID
+        $message = 'Dear Gowtham, 986532 is OTP to approve Service group for service name purposes.';
+        $serviceName = 'TEMPLATE_BASED'; // Service name
+
+        // URL encode the message
+        $encodedMessage = urlencode($message);
+
+        // Initialize cURL
+        $ch = curl_init();
+
+        // Set cURL options
+        curl_setopt($ch, CURLOPT_URL, "https://smsapi.24x7sms.com/api_2.0/SendSMS.aspx?APIKEY=$apiKey&MobileNo=$mobileNumbers&SenderID=$senderId&Message=$encodedMessage&ServiceName=$serviceName&DLTTemplateID=$DLTTemplateID");
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
+
+        // Execute cURL request and get the response
+        $output = curl_exec($ch);
+
+        // Close cURL session
+        curl_close($ch);
+
+        // Output the response (for testing purposes)
+        // return $this->response->setJSON(['response' => $output]);
+        return json_encode(['response' => $output]);
+    }
+
 }
 
 ?>
diff --git a/app/Views/branch_list.php b/app/Views/branch_list.php
index b860958..a59d019 100644
--- a/app/Views/branch_list.php
+++ b/app/Views/branch_list.php
@@ -120,7 +120,7 @@
                         
- $value) { ?> @@ -233,7 +233,10 @@ if(!formDataValidate){ return ; } - + if($('#business').val() == 0){ + toastr.warning('Select Business'); + return; + } var formData = { business_id: $('#business').val(), gstno: $('#gst_no').val(), @@ -274,7 +277,7 @@ console.log(response); $('#business_branch_submit').removeAttr('disabled'); - $('#bike_model_login-modal').modal('hide'); + $('#branch-create-modal').modal('hide'); window.location.reload(); }, @@ -292,7 +295,7 @@ dataType: 'json', success: function(response) { // console.log(response); - $('#business').val(response.business_id); + $('#business').val(response.business_id).trigger('change'); $('#branch_name').val(response.branch_name); $('#gst_no').val(response.gstno); $('#email').val(response.email); @@ -315,6 +318,7 @@ $('#add_branch_model_open').click( function(){ $('#branch_action_type').html('Add Branch'); + $('#business').val(0).trigger('change'); $('#model_form_data')[0].reset(); }) diff --git a/app/Views/business_form.php b/app/Views/business_form.php index 9dd0ab4..7717e21 100644 --- a/app/Views/business_form.php +++ b/app/Views/business_form.php @@ -14,7 +14,7 @@

- Back + Back