From a22dde67deb49c6b1b790ca54a61e029a0e9d30e Mon Sep 17 00:00:00 2001 From: VE10-Sanjeev Date: Thu, 26 Oct 2023 17:03:29 +0530 Subject: [PATCH] Customer group,notify template creation : ps --- app/Config/Routes.php | 22 +- app/Controllers/Customer.php | 218 +++++++++++++++++++- app/Controllers/Notifications.php | 229 ++++++++++++++++++++- app/Models/CustomerModel.php | 43 ++++ app/Models/NotificationModel.php | 85 +++++++- app/Views/campaign_creation.php | 86 ++++++++ app/Views/campaign_creation_form.php | 139 +++++++++++++ app/Views/customer_group.php | 151 ++++++++++++++ app/Views/customer_group_form.php | 292 +++++++++++++++++++++++++++ app/Views/template/footer.php | 5 +- app/Views/template/header.php | 34 +++- app/Views/template_creation.php | 91 +++++++++ app/Views/template_creation_form.php | 104 ++++++++++ 13 files changed, 1478 insertions(+), 21 deletions(-) create mode 100644 app/Views/campaign_creation.php create mode 100644 app/Views/campaign_creation_form.php create mode 100644 app/Views/customer_group.php create mode 100644 app/Views/customer_group_form.php create mode 100644 app/Views/template_creation.php create mode 100644 app/Views/template_creation_form.php diff --git a/app/Config/Routes.php b/app/Config/Routes.php index d67e19b0..3bf3c339 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -77,6 +77,13 @@ $routes->get("new_customer/(:any)", "Customer::new_customer/$1"); $routes->post("insert_customer", "Customer::insert_customer"); $routes->get("delete_customer/(:any)", "Customer::delete_customer/$1"); +# Routes for Customer group +$routes->get('customer_group/', 'Customer::customer_group'); +$routes->get('view_customer_group/(:any)', 'Customer::view_customer_group/$1'); +$routes->get('preview_customer_group/(:any)', 'Customer::preview_customer_group/$1'); +$routes->get('delete_customer_group/(:any)', 'Customer::delete_customer_group/$1'); +$routes->post("insert_customer_group", "Customer::insert_customer_group"); + # Scheme Routes $routes->get("scheme_list/", "Scheme::index"); $routes->get("new_scheme/(:any)", "Scheme::new_scheme/$1"); @@ -115,7 +122,20 @@ $routes->get('print_address/(:num)', 'Invoice::print_address/$1'); $routes->get('send_whatsapp_message/', 'Notifications::send_whatsapp_message'); $routes->post('whatsapp_custom_notifications/', 'Notifications::whatsapp_custom_notifications'); $routes->match(['post', 'get'], 'mail_custom_notifications', 'Notifications::mail_custom_notifications'); -$routes->get('customer_group_notifications/', 'Notifications::customer_group_notifications'); +// $routes->match(['post', 'get'], 'due_date_notifications', 'Notifications::due_date_notifications'); +// $routes->get('due_date_notifications/(:any)', 'Notifications::due_date_notifications/$1'); +$routes->get('due_date_notifications', 'Notifications::due_date_notifications'); +$routes->get('template_creation/', 'Notifications::template_creation'); +$routes->get('template_creation_form/(:any)', 'Notifications::template_creation_form/$1'); +$routes->get('template_creation_delete/(:any)', 'Notifications::template_creation_delete/$1'); +$routes->post("template_creation_insert", "Notifications::template_creation_insert"); + +$routes->get('campaign_creation/', 'Notifications::campaign_creation'); +$routes->get('campaign_creation_form/(:any)', 'Notifications::campaign_creation_form/$1'); +$routes->get('campaign_creation_delete/(:any)', 'Notifications::campaign_creation_delete/$1'); +$routes->post("campaign_creation_insert", "Notifications::campaign_creation_insert"); + + # Api integration Routes $routes->post('api/(:any)', 'ApiIntegration::api_integration/$1'); diff --git a/app/Controllers/Customer.php b/app/Controllers/Customer.php index fc900f4d..c29e1438 100644 --- a/app/Controllers/Customer.php +++ b/app/Controllers/Customer.php @@ -83,7 +83,7 @@ class Customer extends BaseController public function insert_customer() { $requestData = $this->request->getPost(); - print_r($requestData);die; + // print_r($requestData);die; $this->logger->info("Customer: Inserting/Updating Details"); try { helper('session'); @@ -290,5 +290,221 @@ class Customer extends BaseController $state_details = $model->orderBy('state_id', 'ASC')->findAll(); return $state_details; } + + public function customer_group(){ + $data['page_name'] = 'Customer Group'; + $model = new CustomerModel(); + $data['customer_group'] = $model->getGroupDetails(); + $this->render_page('customer_group', $data); + } + public function view_customer_group($id){ + helper('session'); + $session_bid = get_business_id(); + + $data['field'] = [ + '' => 'Choose the Field', + 'city' => 'City', + 'state' => 'State', + 'type' => 'Type', + 'postal code' => 'Postal Code', + 'schemes' => 'Schemes', + 'category' => 'Category' + ]; + $data['operator'] = [ + '' => 'Choose the operator', + 'equal' => 'equal to (=)', + 'not equal' => 'not equal (!=)', + 'like' => 'like (%)', + 'contain' => 'contain (in)', + 'not contain' => 'not contain (not in)', + 'between' => 'between (between)', + 'greater than' => 'greater than (>)', + 'greater than or equal to' => 'greater than or equal to (>=)', + 'less than' => 'lesser than (<)', + 'less than or equal to' => 'greater than or equal to (<=)' + ]; + $data['customer_group'] = []; + if ($id === '0') { + // Add Customer + $data['page_name'] = 'Customer Group From'; + } else if ($id !== '0') { + // Edit Customer + $data['page_name'] = 'Customer Group From'; + + // Load your Customer Model + $model = new CustomerModel(); + $model->setTable('customer_groups'); + $where = ['group_id'=>$id]; + $result = $model->where($where)->findAll(); + + if (!empty($result)) { + $data['customer_group']['groupname'] = $result[0]['group_name']; + $data['customer_group']['column'] = unserialize($result[0]['column']); + $data['customer_group']['operator'] = unserialize($result[0]['operator']); + $data['customer_group']['values'] = unserialize($result[0]['value']); + $data['customer_group']['group_id'] = $result[0]['group_id']; + $data['customer_group']['isactive'] = $result[0]['isactive']; + } + } + $this->render_page('customer_group_form', $data); + } + public function preview_customer_group($id){ + helper('session'); + $model = new CustomerModel(); + $model->setTable('customer_groups'); + $where = ['isactive' => 1,'group_id'=>$id]; + $result = $model->where($where)->findAll(); + $db = \Config\Database::connect(); + $sql = (string)$result[0]['group_query']; + $query = $db->query($sql); + $results = $query->getResultArray(); + return $this->response->setJSON($results); + } + public function delete_customer_group($id){ + try { + helper('session'); + $session_uid = get_logged_user_id(); + $model = new CustomerModel(); + $model->setTable('customer_groups'); + $where = ['isactive' => 1,'group_id'=>(int)$id]; + $result = $model->where($where)->findAll(); + if ($result) { + $this->logger->Info("Customer Group: Going to Inactive ID = ".$id); + $data = ['isactive' => 0 , 'updated_by' => $session_uid,'group_id'=>(int)$id]; + $statement = $model->saveGroupDetails($data);// just updating Inactive status only. + if ($statement['success']) { + session()->setFlashdata('success', $statement['success'] ? 'Deleted successfully.' : "" ); + $this->logger->info($statement['log']); + } else if ($statement['error']) { + session()->setFlashdata('error', $statement['error']); + $this->logger->error($statement['log']); + }else{ + throw new \Exception("Customer Group: Err Occur on data the Customer Group Inactive"); + } + } + } catch (\Exception $e) { + $this->logger->error("Customer Group: Err Occur = ".$e->getMessage()." File = ". $e->getFile() . " Line = " . $e->getLine()); + session()->setFlashdata('error', 'Message: ' . $e->getMessage()); + } + return redirect()->route('customer_group'); + + } + public function insert_customer_group(){ + + try { + $this->logger->info("Customer Group: Inserting/Updating Details"); + helper('session'); + $session_uid = get_logged_user_id(); + $request_data = $this->request->getPost(); + $string_flag = $request_data['string_flag']; + // $this->logger->info("Customer Group: Request data = ".json_encode($request_data)); + + $model = new CustomerModel(); + // Array ( [groupname] => nil [column] => Array ( [0] => city [1] => state ) [operator] => Array ( [0] => not contain [1] => not equal ) [values] => Array ( [0] => 2 [1] => 3 ) ) + $data = [ + 'group_name' => $request_data['groupname'], + 'column' => serialize($request_data['column']), + 'operator' => serialize($request_data['operator']), + 'value' => serialize($request_data['values']) + ]; + // Initialize an empty array to store the conditions + $conditions = array(); + + // Loop through the elements and build the conditions + for ($i = 0; $i < count($request_data['column']); $i++) { + $column = $request_data['column'][$i]; + $operator = $request_data['operator'][$i]; + $value = $request_data['values'][$i]; + + // Handle different operators and build corresponding conditions + switch ($operator) { + case 'equal': + $conditionStrings[] = "$column = '$value'"; + break; + case 'not equal': + $conditionStrings[] = "$column <> '$value'"; + break; + case 'like': + $conditionStrings[] = "$column LIKE '%$value%'"; + break; + case 'contain': + case 'where in': + $values = explode(',', $value); + $conditions[] = "$column IN ('" . implode("', '", $values) . "')"; + break; + case 'not contain': + case 'where not in': + $values = explode(',', $value); + $conditions[] = "$column NOT IN ('" . implode("', '", $values) . "')"; + break; + case 'between': + $dates = explode(',', $value); + $conditionStrings[] = "$column BETWEEN '$dates[0]' AND '$dates[1]'"; + break; + case 'greater than': + $conditionStrings[] = "$column > $value"; + break; + case 'greater than or equal to': + $conditionStrings[] = "$column >= $value"; + break; + case 'less than': + $conditionStrings[] = "$column < $value"; + break; + case 'less than or equal to': + $conditionStrings[] = "$column <= $value"; + break; + } + } + + // Join the conditions with 'AND' + $whereCondition = implode(' AND ', $conditionStrings); + // echo "*************** whereCondition =>>> "; + // echo $whereCondition; + // If a groupname is specified, include it in the condition + // if ($conditionsArray['groupname'] !== 'nil') { + // $whereCondition = "($whereCondition) AND groupname = '{$conditionsArray['groupname']}'"; + // } + + // Now you can use $whereCondition in your SQL query + $db = \Config\Database::connect(); + $sql = "SELECT customer_id,CONCAT(first_name,'',last_name) as customer_name,email,mobile_no FROM customers WHERE ".$whereCondition; + + // echo $sql; + // Execute the query + $query = $db->query($sql); + + // Get the result + $results = $query->getResult(); + $group_id = $request_data['group_id']; // Get the ID for update + $isactive = $request_data['isactive']; + if($string_flag == "save"){ + $data['group_query'] = $sql; + $data['group_id'] = $group_id; + $data['isactive'] = $group_id ? (($isactive == 'on') ? 1 : 0) : 1; + $data['created_by'] = $session_uid; + $data['updated_by'] = $session_uid; + $statement = $model->saveGroupDetails($data); + if ($statement['success']) { + session()->setFlashdata('success', $statement['success']); + $this->logger->info($statement['log']); + + } else if ($statement['error']) { + session()->setFlashdata('error', $statement['error']); + $this->logger->error($statement['log']); + }else{ + throw new \Exception("Customer Group: Err Occur on data the Save"); + } + + }else if($string_flag == "preview"){ + return $this->response->setJSON($results); + }else{ + throw new \Exception("Data Not Found"); + } + } catch (\Exception $e) { + $this->logger->error("Customer Group: Err Occur = ".$e->getMessage()." File = ". $e->getFile() . " Line = " . $e->getLine()); + session()->setFlashdata('error', 'Message: ' . $e->getMessage()); + } + return redirect()->route('customer_group'); + } } diff --git a/app/Controllers/Notifications.php b/app/Controllers/Notifications.php index 0542c981..30c70f29 100755 --- a/app/Controllers/Notifications.php +++ b/app/Controllers/Notifications.php @@ -74,9 +74,14 @@ class Notifications extends BaseController public function due_date_notifications() { + $date = $this->request->getGet('date'); + $model = new NotificationModel(); - $details = $model->getSubscriptionDueDetail(); - + $details = $model->getSubscriptionDueDetail($date); + // echo "
";
+        // print_r($details);
+        // echo "
"; + // die; $records = []; $recipient_name = ""; $recipient_email = ""; @@ -135,7 +140,223 @@ class Notifications extends BaseController } - public function customer_group_notifications(){ - echo "customer_group_notifications";die; + public function template_creation(){ + $data['page_name'] = 'Template'; + $model = new NotificationModel(); + $data['template'] = $model->getTemplateDetails(); + $this->render_page('template_creation', $data); + // echo "templates";die; } + + public function template_creation_form($id){ + + $data['group_details'] = $this->get_group_details(); + $model = new NotificationModel(); + if ($id === '0') { + $this->logger->info("Template Creation: In Add Page"); + $data['page_name'] = 'Add Template'; + $data['template_details'] = []; + } elseif ($id !== '0') { + $this->logger->info("Template Creation: In Edit Page ID =" . $id); + $data['page_name'] = 'Edit Template'; + $model->setTable('templates'); + $where = ['template_id'=>(int)$id]; + $result = $model->where($where)->findAll(); + $data['template_details'] = !empty($result[0]) ? $result[0] : []; + } + // print_r($data['template_details']);die(); + $this->render_page('template_creation_form', $data); + } + + public function template_creation_delete($id){ + try { + helper('session'); + $session_uid = get_logged_user_id(); + $model = new NotificationModel(); + $model->setTable('templates'); + $where = ['template_id'=>(int)$id]; + $result = $model->where($where)->findAll(); + if ($result) { + $this->logger->Info("Template: Going to Inactive ID = ".$id); + $data = ['isactive' => 0 , 'updated_by' => $session_uid,'template_id'=>(int)$id]; + $statement = $model->saveDetails($data,'template_id','templates');// just updating Inactive status only. + if ($statement['success']) { + session()->setFlashdata('success', $statement['success'] ? 'Deleted successfully.' : "" ); + $this->logger->info($statement['log']); + } else if ($statement['error']) { + session()->setFlashdata('error', $statement['error']); + $this->logger->error($statement['log']); + }else{ + throw new \Exception("Template: Err Occur on data the Template Inactive"); + } + } + } catch (\Exception $e) { + $this->logger->error("Template: Err Occur = ".$e->getMessage()." File = ". $e->getFile() . " Line = " . $e->getLine()); + session()->setFlashdata('error', 'Message: ' . $e->getMessage()); + } + return redirect()->route('template_creation'); + + } + + public function get_group_details() + { + $model = new NotificationModel(); + $model->setTable('customer_groups'); + $details = $model->where('isactive',1)->orderBy('group_id', 'ASC')->findAll(); + return $details; + } + public function get_template_details(){ + $model = new NotificationModel(); + $model->setTable('templates'); + $details = $model->where('isactive',1)->orderBy('template_id', 'ASC')->findAll(); + return $details; + } + + public function template_creation_insert(){ + $this->logger->info("Template: Inserting/Updating Details"); + try { + ## Declarions + helper('session'); + $model = new NotificationModel(); + $session_uid = get_logged_user_id(); + $id = $this->request->getPost('template_id'); + $subject = $this->request->getPost('subject') ? $this->request->getPost('subject') : NULL; + $isactive = $this->request->getPost('isactive'); + $data = [ + 'template_id' => $id, + 'template_name' => $this->request->getPost('templatename'), + 'subject' => $subject, + 'message' => $this->request->getPost('templatemessage'), + 'mode' => $this->request->getPost('mode'), + 'group_id' => $this->request->getPost('group_id'), + 'isactive' => $id ? (($isactive == 'on') ? 1 : 0) : 1, + 'created_by' => $session_uid, + 'updated_by' => $session_uid + ]; + $statement = $model->saveDetails($data,'template_id','templates'); + if ($statement['success']) { + session()->setFlashdata('success', $statement['success']); + $this->logger->info($statement['log']); + } else if ($statement['error']) { + session()->setFlashdata('error', $statement['error']); + $this->logger->error($statement['log']); + }else{ + throw new \Exception("Template: Err Occur"); + } + + + }catch(\Exception $e) { + $this->logger->error("Template: Err Occur =".$e->getMessage()); + session()->setFlashdata('error', 'Message: ' .$e->getMessage()); + } + return redirect()->route('template_creation'); + } + + public function campaign_creation(){ + $data['page_name'] = 'Campaign'; + $model = new NotificationModel(); + $data['campaign'] = $model->getCampaignDetails(); + $this->render_page('campaign_creation', $data); + // echo "templates";die; + } + + public function campaign_creation_form($id){ + + $data['group_details'] = $this->get_group_details(); + $data['template_details'] = $this->get_template_details(); + $model = new NotificationModel(); + if ($id === '0') { + $this->logger->info("Campaign Creation: In Add Page"); + $data['page_name'] = 'Add Campaign'; + $data['campaign_details'] = []; + } elseif ($id !== '0') { + $this->logger->info("Campaign Creation: In Edit Page ID =" . $id); + $data['page_name'] = 'Edit Campaign'; + $model->setTable('notification_campaign'); + $where = ['campaign_id'=>(int)$id]; + $result = $model->where($where)->findAll(); + if (!empty($result)) { + foreach ($result as $i => $item) { + $result[$i]['group_id'] = unserialize($item['group_id']); + } + } + $data['campaign_details'] = !empty($result[0]) ? $result[0] : []; + + } + $this->render_page('campaign_creation_form', $data); + } + + public function campaign_creation_delete($id){ + try { + helper('session'); + $session_uid = get_logged_user_id(); + $model = new NotificationModel(); + $model->setTable('templates'); + $where = ['campaign_id'=>(int)$id]; + $result = $model->where($where)->findAll(); + if ($result) { + $this->logger->Info("Campaign: Going to Inactive ID = ".$id); + $data = ['isactive' => 0 , 'updated_by' => $session_uid,'campaign_id'=>(int)$id]; + $statement = $model->saveDetails($data,'campaign_id','notification_campaign');// just updating Inactive status only. + if ($statement['success']) { + session()->setFlashdata('success', $statement['success'] ? 'Deleted successfully.' : "" ); + $this->logger->info($statement['log']); + } else if ($statement['error']) { + session()->setFlashdata('error', $statement['error']); + $this->logger->error($statement['log']); + }else{ + throw new \Exception("Campaign: Err Occur on data the Template Inactive"); + } + } + } catch (\Exception $e) { + $this->logger->error("Campaign: Err Occur = ".$e->getMessage()." File = ". $e->getFile() . " Line = " . $e->getLine()); + session()->setFlashdata('error', 'Message: ' . $e->getMessage()); + } + return redirect()->route('campaign_creation'); + + } + + public function campaign_creation_insert(){ + $this->logger->info("Campaign: Inserting/Updating Details"); + try { + ## Declarions + helper('session'); + $model = new NotificationModel(); + $session_uid = get_logged_user_id(); + $id = $this->request->getPost('campaign_id'); + $isactive = $this->request->getPost('isactive'); + // print_r($this->request->getPost());die; + $data = [ + 'campaign_id' => $id, + 'campaign_name' => $this->request->getPost('campaign_name'), + 'template_id' => $this->request->getPost('template_id'), + 'scheduled_date' => $this->request->getPost('scheduled_date'), + 'scheduled_time' => $this->request->getPost('scheduled_time'), + 'mode' => $this->request->getPost('mode'), + 'group_id' => serialize($this->request->getPost('group_id')), + 'isactive' => $id ? (($isactive == 'on') ? 1 : 0) : 1, + 'created_by' => $session_uid, + 'updated_by' => $session_uid + ]; + $statement = $model->saveDetails($data,'campaign_id','notification_campaign'); + if ($statement['success']) { + session()->setFlashdata('success', $statement['success']); + $this->logger->info($statement['log']); + } else if ($statement['error']) { + session()->setFlashdata('error', $statement['error']); + $this->logger->error($statement['log']); + }else{ + throw new \Exception("Campaign: Err Occur"); + } + + + }catch(\Exception $e) { + $this->logger->error("Campaign: Err Occur =".$e->getMessage()); + session()->setFlashdata('error', 'Message: ' .$e->getMessage()); + } + return redirect()->route('campaign_creation'); + } + + + } diff --git a/app/Models/CustomerModel.php b/app/Models/CustomerModel.php index 7afe40a5..66dc7ea6 100644 --- a/app/Models/CustomerModel.php +++ b/app/Models/CustomerModel.php @@ -115,5 +115,48 @@ public function getSubscriberDataByCustomerId($customerId) return $builder->get()->getResult(); } +public function saveGroupDetails($data){ + $id = $data['group_id']; + if($id != ''){ + unset($data['group_id']); // Remove the id from the data to avoid updating it + unset($data['created_by']); // bcoz here data Updating here. + if ($this->db->table('customer_groups')->where('group_id', $id)->update($data)) { + $affectedRows = $this->db->affectedRows(); + $statement['success'] = 'Customer Group has been updated successfully.'; + $statement['error'] = ""; + $statement['log'] = "Customer Group: has been updated successfully. Updated Customer Group ID = " .$id." Affected Rows = ".$affectedRows; + } else { + $statement['success'] = ""; + $statement['error'] = 'Customer group update failed. Please try again.'; + $statement['log'] = "Customer Group: Err Failed to update ID = " .$id ; + } + }else{ + unset($data['updated_by']); + if ($this->db->table('customer_groups')->insert($data)) { + $insertID = $this->db->insertID(); + $statement['success'] = 'Customer Group has been Inserted successfully.'; + $statement['error'] = ""; + $statement['log'] = "Customer Group : has been added successfully. Inserted ID = " .$insertID ; + } else { + $statement['success'] = ""; + $statement['error'] = "Customer could not be added. Please try again.."; + $statement['log'] = "Customer: Err could not be added. Please try again."; + } + } +return $statement; +} + +public function getGroupDetails() +{ +return $this->db->table('customer_groups as CG' ) +->join('users as U1', 'U1.user_id = CG.created_by', 'left') +->join('users as U2', 'U2.user_id = CG.updated_by', 'left') +->select('CG.group_id,CG.group_name,CG.created_on,CG.created_by,CG.updated_on,CG.updated_by,DATE_FORMAT(CG.created_on, "%d-%m-%Y %h:%i %p") AS formatted_created_on,concat(U1.first_name," ",U1.last_name) as created_by_name,concat(U2.first_name," ",U2.last_name) as updated_by_name,CG.isactive') +// ->where(['CG.isactive' => 1]) +->get() +->getResultArray(); +} + + } ?> \ No newline at end of file diff --git a/app/Models/NotificationModel.php b/app/Models/NotificationModel.php index 73ab77f3..31416afd 100644 --- a/app/Models/NotificationModel.php +++ b/app/Models/NotificationModel.php @@ -20,19 +20,94 @@ class NotificationModel extends Model // ->findAll(); // } - public function getSubscriptionDueDetail(){ - $now = date('Y-m-d'); - $lastWeek = date('Y-m-d', strtotime('+7 days')); + public function getSubscriptionDueDetail($date){ + // $now = date('Y-m-d'); + // $lastWeek = date('Y-m-d', strtotime('+7 days')); + // $date_format = date('Y-m-d', $date); return $this->db->table('subscription as S' ) ->join('customers as C', 'C.customer_id = S.customer_id', 'left') ->join('category as CM', 'CM.id = S.scheme_id', 'left') ->join('business as B', 'B.business_id = S.business_id', 'left') ->join('book_categories as BC', 'BC.category_id = S.scheme_id', 'left') ->join('books as BK', 'BC.book_id = BK.book_id', 'left') - ->select('CM.name,concat(C.first_name, " ", C.last_name) as customer_name,C.email as customer_email,C.mobile_no as customer_mobile,S.sub_id,S.scheme_id,S.customer_id,S.from_subscription,S.to_subscription,S.business_id,B.title as business_name,B.address as business_address,B.city as business_city,B.state as business_state,B.postal_code as business_postal_code,B.email as business_email,B.mobile_no as business_mobile_no,S.to_subscription,S.from_subscription,BK.title,BK.book_id') - ->where('S.to_subscription >=', $now)->where('S.to_subscription <=',$lastWeek) + ->select('concat("Your subscription going to expried in ",DATEDIFF(S.to_subscription, CURDATE())," days") as statement,DATEDIFF(S.to_subscription, CURDATE()) as countdays,CM.name,concat(C.first_name, " ", C.last_name) as customer_name,C.email as customer_email,C.mobile_no as customer_mobile,S.sub_id,S.scheme_id,S.customer_id,S.from_subscription,S.to_subscription,S.business_id,B.title as business_name,B.address as business_address,B.city as business_city,B.state as business_state,B.postal_code as business_postal_code,B.email as business_email,B.mobile_no as business_mobile_no,S.to_subscription,S.from_subscription,BK.title,BK.book_id') + // ->where('S.to_subscription >=', $now)->where('S.to_subscription <=',$lastWeek) + ->where('S.to_subscription =',date('Y-m-d', strtotime($date))) ->groupBy('S.sub_id') ->get()->getResultArray(); } + + public function getTemplateDetails(){ + return $this->db->table('templates as T' ) + ->join('users as U1', 'U1.user_id = T.created_by', 'left') + ->join('users as U2', 'U2.user_id = T.updated_by', 'left') + ->join('customer_groups as CG', 'CG.group_id = T.group_id', 'left') + ->select('T.template_id,T.template_name,T.mode,CG.group_id,CG.group_name,T.created_on,T.created_by,T.updated_on,T.updated_by,DATE_FORMAT(T.created_on, "%d-%m-%Y %h:%i %p") AS formatted_created_on,concat(U1.first_name," ",U1.last_name) as created_by_name,concat(U2.first_name," ",U2.last_name) as updated_by_name,T.isactive') + ->get()->getResultArray(); + } + + public function saveDetails($data,$pk_name,$t_name){ + $id = $data[$pk_name]; + if($id != ''){ + unset($data[$pk_name]); // Remove the id from the data to avoid updating it + unset($data['created_by']); // bcoz here data Updating here. + if ($this->db->table($t_name)->where($pk_name, $id)->update($data)) { + $affectedRows = $this->db->affectedRows(); + $statement['success'] = ucfirst($t_name).' has been updated successfully.'; + $statement['error'] = ""; + $statement['log'] = ucfirst($t_name).": has been updated successfully. Updated ".$pk_name." = " .$id." Affected Rows = ".$affectedRows; + } else { + $statement['success'] = ""; + $statement['error'] = ucfirst($t_name).' update failed. Please try again.'; + $statement['log'] = ucfirst($t_name).": Err Failed to update ID = " .$id ; + } + }else{ + unset($data['updated_by']); + if ($this->db->table($t_name)->insert($data)) { + $insertID = $this->db->insertID(); + $statement['success'] = ucfirst($t_name).' has been Inserted successfully.'; + $statement['error'] = ""; + $statement['log'] = ucfirst($t_name).": has been added successfully. Inserted ID = " .$insertID ; + } else { + $statement['success'] = ""; + $statement['error'] = ucfirst($t_name)." could not be added. Please try again.."; + $statement['log'] = ucfirst($t_name).": Err could not be added. Please try again."; + } + } + return $statement; +} + +public function getCampaignDetails(){ + $result = $this->db->table('notification_campaign as NC' ) + ->join('users as U1', 'U1.user_id = NC.created_by', 'left') + ->join('users as U2', 'U2.user_id = NC.updated_by', 'left') + ->join('templates as T', 'T.template_id = NC.template_id', 'left') + ->select('NC.campaign_id,NC.campaign_name,T.template_id,T.template_name,NC.mode,NC.created_on,NC.created_by,NC.updated_on,NC.updated_by,DATE_FORMAT(NC.created_on, "%d-%m-%Y %h:%i %p") AS formatted_created_on,concat(U1.first_name," ",U1.last_name) as created_by_name,concat(U2.first_name," ",U2.last_name) as updated_by_name,NC.isactive,NC.group_id,NC.scheduled_date,NC.scheduled_time') + ->get()->getResultArray(); + + if (!empty($result)) { + foreach ($result as $i => $item) { + $group_id = unserialize($item['group_id']); + $group_names = []; + + foreach ($group_id as $j) { + $cg_data = $this->db->table('customer_groups as CG') + ->select('CG.group_id, CG.group_name, CG.isactive') + ->where(['CG.isactive' => 1, 'CG.group_id' => $j]) + ->get() + ->getRowArray(); + + if ($cg_data) { + $group_names[] = $cg_data['group_name']; + } + } + + $result[$i]['group_name'] = !empty($group_names) ? implode(", ", $group_names) : ''; + } + } + + return $result; +} + } diff --git a/app/Views/campaign_creation.php b/app/Views/campaign_creation.php new file mode 100644 index 00000000..80064304 --- /dev/null +++ b/app/Views/campaign_creation.php @@ -0,0 +1,86 @@ +
+
+
+
+ +
+

+ getFlashdata('success') || session()->getFlashdata('error')) : ?> + getFlashdata('success')) : ?> + + + getFlashdata('error')) : ?> + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Campaign NameTemplate NameGroup NameScheduled atCreated atCreated byStatusAction
+ " class="edit-button" title="Click to Edit Campaign" > + " class="delete-button" title="Click to Delete Campaign" > +
+
+
+
+
+
+ + diff --git a/app/Views/campaign_creation_form.php b/app/Views/campaign_creation_form.php new file mode 100644 index 00000000..4ed11e47 --- /dev/null +++ b/app/Views/campaign_creation_form.php @@ -0,0 +1,139 @@ +
+
+
+
+

+
" method="post" enctype="multipart/form-data"> +
+
+
+ + +
Please provide.
+
+
+ + + +
+
+ + +
+
+ +
+
+ + +
+
+ + +
+
+
+
+ +
+
+ +
+
+ +
+
+
+ +
+ + + +
+ > + +
+
+ + +
+
+
+
+
+
+ + \ No newline at end of file diff --git a/app/Views/customer_group.php b/app/Views/customer_group.php new file mode 100644 index 00000000..3cc75e0e --- /dev/null +++ b/app/Views/customer_group.php @@ -0,0 +1,151 @@ +
+
+
+
+ +
+

+ getFlashdata('success') || session()->getFlashdata('error')) : ?> + getFlashdata('success')) : ?> + + + getFlashdata('error')) : ?> + + + +
+ + + + + + + + + + + + + + + + + + + + + + +
Group NameCreated atCreated byStatusAction
+ " class="edit-button" title="Edit" > + + " class="delete-button" title="Delete" > +
+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/app/Views/customer_group_form.php b/app/Views/customer_group_form.php new file mode 100644 index 00000000..ecad5b56 --- /dev/null +++ b/app/Views/customer_group_form.php @@ -0,0 +1,292 @@ +
+
+
+
+

+

+
+
+
+ + +
Please provide.
+
+
+
+
+
+

Select Criteria

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
FieldConditionValueAction
+ + + + + " /> + + +
+ + + + + + + +
+
+ + +
+ +
+ > + +
+ + + +
+
+ + + +
+
+
+
+
+ + + + + + + + + + + diff --git a/app/Views/template/footer.php b/app/Views/template/footer.php index 6d7a6d4e..db72a6c3 100644 --- a/app/Views/template/footer.php +++ b/app/Views/template/footer.php @@ -784,9 +784,12 @@ - + + + + + \ No newline at end of file diff --git a/app/Views/template_creation_form.php b/app/Views/template_creation_form.php new file mode 100644 index 00000000..68ddc31a --- /dev/null +++ b/app/Views/template_creation_form.php @@ -0,0 +1,104 @@ +
+
+
+
+

+
" method="post" enctype="multipart/form-data"> +
+
+
+ + +
Please provide.
+
+
+ + +
+
+ +
+
+ + +
+
+ + +
+
+
+ +
+ + +
+ +
+ + +
+
+ + +
+ > + +
+
+ + +
+
+
+
+
+
+ \ No newline at end of file