diff --git a/app/Controllers/Customer.php b/app/Controllers/Customer.php index 04ddaedc..bfd7f1be 100644 --- a/app/Controllers/Customer.php +++ b/app/Controllers/Customer.php @@ -302,14 +302,14 @@ class Customer extends BaseController $session_bid = get_business_id(); $data['field'] = [ - '' => 'Choose the Field', - 'C.type' => 'Type', - 'CA.city' => 'City', - 'CA.state' => 'State', - 'CM.name' => 'Category', - 'I.invoice_date' => 'Invoice Date', - 'S.to_subscription' => 'Due Date', - ]; + ['value'=>'','fieldflag'=>1,'text'=> 'Choose the Field','disable' => false], + ['value'=>'C.type','fieldflag'=>1,'text'=> 'Type','disable' => false], + ['value'=>'CA.city','fieldflag'=>1,'text'=> 'City','disable' => false], + ['value'=>'CA.state','fieldflag'=>1,'text'=> 'State','disable' => false], + ['value'=>'CM.name','fieldflag'=>1,'text'=> 'Category','disable' => false], + ['value'=>'I.invoice_date','fieldflag'=>2,'text'=> 'Invoice Date','disable' => false], + ['value'=>'S.to_subscription','fieldflag'=>2,'text'=> 'Due Date','disable' => false]]; + $data['operator'] = [ '' => 'Choose the operator', 'equal' => 'Equal to (=)', @@ -498,7 +498,6 @@ class Customer extends BaseController LEFT JOIN category CM on CM.id = S.scheme_id WHERE C.isactive = 1 AND ".$whereCondition." GROUP BY C.customer_id"; $this->logger->info("Customer Group: SQL = ".$sql); - // echo $sql; // Execute the query $query = $db->query($sql); diff --git a/app/Models/NotificationModel.php b/app/Models/NotificationModel.php index 926e2189..6d42bd89 100644 --- a/app/Models/NotificationModel.php +++ b/app/Models/NotificationModel.php @@ -88,25 +88,63 @@ public function getCampaignDetails(){ foreach ($result as $i => $item) { $group_id = unserialize($item['group_id']); $group_names = []; - + $group_query = []; foreach ($group_id as $j) { $cg_data = $this->db->table('customer_groups as CG') - ->select('CG.group_id, CG.group_name, CG.isactive') + ->select('CG.group_id, CG.group_name,CG.group_query, CG.isactive') ->where(['CG.isactive' => 1, 'CG.group_id' => $j]) ->get() ->getRowArray(); if ($cg_data) { $group_names[] = $cg_data['group_name']; + $group_query[] = $cg_data['group_query']; + // array_push($group_sql, $cg_data['group_query']); } } - $result[$i]['group_name'] = !empty($group_names) ? implode(", ", $group_names) : ''; + $result[$i]['customer_group'] = !empty($group_query) ? $this->customerGroupQueryExecution($group_query) : ''; + $result[$i]['customer_group_count'] = !empty($result[$i]['customer_group']) ? count($this->customerGroupQueryExecution($group_query)) : 0; } } - return $result; } +public function customerGroupQueryExecution($queries){ + + $results = []; + + // Execute the queries + foreach ($queries as $query) { + if(!empty($query)){ + $queryResult = $this->db->query($query)->getResult(); + $results[] = $queryResult;} + } + // echo "
"; + // print_r($results); + // echo ""; + // Create a new array to store the unique results based on customer_id + $uniqueCustomers = array(); + + foreach ($results as $innerArray) { + foreach ($innerArray as $customer) { + $customerId = $customer->customer_id; + + // Check if the customer_id already exists in $uniqueCustomers + if (!isset($uniqueCustomers[$customerId])) { + $uniqueCustomers[$customerId] = $customer; + } + } + } + + // Convert the $uniqueCustomers array back to a numerically indexed array + $uniqueCustomers = array_values($uniqueCustomers); + return $uniqueCustomers; + // echo "
"; + // print_r($uniqueCustomers); + // echo ""; + // die; + } + } diff --git a/app/Views/campaign_creation.php b/app/Views/campaign_creation.php index 6f3793dd..f82ef560 100644 --- a/app/Views/campaign_creation.php +++ b/app/Views/campaign_creation.php @@ -33,6 +33,7 @@