From 250c124dc5e09747e4d44fe84c24a3044e5775d7 Mon Sep 17 00:00:00 2001 From: VE10-Sanjeev Date: Mon, 11 Dec 2023 09:55:43 +0530 Subject: [PATCH] Issues Fixes : ps --- app/Config/Constants.php | 3 + app/Config/Routes.php | 8 +- app/Controllers/Customer.php | 36 ++-- app/Controllers/Home.php | 41 ++++ app/Controllers/Invoice.php | 49 +++-- app/Controllers/Notifications.php | 198 ++++++++++++++++++- app/Controllers/Subscription.php | 4 +- app/Models/CustomerModel.php | 14 +- app/Models/HomeModel.php | 4 +- app/Models/InvoiceModel.php | 15 +- app/Models/NotificationModel.php | 17 +- app/Views/campaign_creation.php | 4 +- app/Views/campaign_creation_form.php | 9 +- app/Views/customer_form.php | 41 +++- app/Views/customer_group_form.php | 6 +- app/Views/invoice_form.php | 272 ++++++++++++++------------- app/Views/invoice_pdf_template.php | 2 + app/Views/notifications_form.php | 4 +- app/Views/template_creation_form.php | 2 +- app/Views/user_form.php | 45 ++++- 20 files changed, 561 insertions(+), 213 deletions(-) diff --git a/app/Config/Constants.php b/app/Config/Constants.php index 970e6799..306ba1c1 100644 --- a/app/Config/Constants.php +++ b/app/Config/Constants.php @@ -126,6 +126,9 @@ define('order_child_column', ["invoice_id","wp_api_line_items_id","customer_id"] // define('WAAI_TOKEN', '6568739969f28'); // define('WAAI_INSTANCE', '656876690A9FD'); +define('WAAI_TOKEN', getenv('WAAI_TOKEN')); +define('WAAI_INSTANCE', getenv('WAAI_INSTANCE')); + define('SEND_WAAI_URL', 'https://waai.in/api/send'); define('SEND_WAAI_GROUP_URL', 'https://waai.in/api/send_group'); define('EXPIRAY_NOTIFY_TEMPLATE_EMAIL','EXPIRAY_NOTIFY_TEMPLATE_EMAIL'); diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 96592346..e9db508c 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -83,6 +83,7 @@ $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"); +$routes->post("check_existing/", "Home::check_existing/"); # Scheme Routes $routes->get("scheme_list/", "Scheme::index"); @@ -112,8 +113,10 @@ $routes->get("invoice_list/", "Invoice::index"); $routes->get("new_book_invoice/(:any)", "Invoice::new_book_invoice/$1"); $routes->get("new_subscription_invoice/(:any)", "Invoice::new_subscription_invoice/$1"); -$routes->post("load_details1/", "Invoice::load_details1/"); -$routes->post("load_details2/", "Invoice::load_details2/"); + +$routes->post("get_customer_billing_details", "Invoice::get_customer_billing_details"); +$routes->post("get_customer_membership_details", "Invoice::get_customer_membership_details"); +$routes->post("get_customer_shipping_details", "Invoice::get_customer_shipping_details"); $routes->post("save_invoice/", "Invoice::save_invoice/"); $routes->get("delete_invoice/(:any)", "Invoice::delete_invoice/$1"); $routes->add('approve_invoice/(:num)', 'Invoice::approve_invoice/$1'); @@ -147,6 +150,7 @@ $routes->get('campaign_creation_delete/(:any)', 'Notifications::campaign_creatio $routes->post("campaign_creation_insert", "Notifications::campaign_creation_insert"); +$routes->get('auto_scheduled_notification/', 'Notifications::auto_scheduled_notification'); # Api integration Routes $routes->post('api/(:any)', 'ApiIntegration::api_integration/$1'); diff --git a/app/Controllers/Customer.php b/app/Controllers/Customer.php index e9545830..3fef3672 100644 --- a/app/Controllers/Customer.php +++ b/app/Controllers/Customer.php @@ -353,23 +353,18 @@ class Customer extends BaseController helper('session'); $model = new CustomerModel(); $model->setTable('customer_groups'); - $where = ['isactive' => 1,'group_id'=>$id]; + $where = ['group_id'=>$id]; $result = $model->where($where)->findAll(); $db = \Config\Database::connect(); $sql = (string)$result[0]['group_query']; - //print_r($sql);die; + if($sql){ $query = $db->query($sql); $results = $query->getResultArray(); - if(empty($results)){ - throw new \Exception("Data Not Available"); - }else{ - return $this->response->setJSON($results); - } + return $this->response->setJSON($results); }else{ return $this->response->setJSON([]); } - } catch (\Exception $e) { $this->logger->error("Customer Group: Err Occur = ".$e->getMessage()." File = ". $e->getFile() . " Line = " . $e->getLine()); session()->setFlashdata('error', 'Message: ' . $e->getMessage()); @@ -488,7 +483,9 @@ class Customer extends BaseController // 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; - $sql = "SELECT CA.city,CA.state,I.invoice_date,C.customer_id,CONCAT(C.first_name,'',C.last_name) as customer_name,C.email,C.mobile_no ,S.to_subscription as due_date, C.isactive ,count(I.invoice_id) as invoice_count_raised_by_customer, S.scheme_id , CM.name + $sql = "SELECT CA.city,CA.state,I.invoice_date,C.customer_id,CONCAT(C.first_name,' ',C.last_name) as customer_name,C.email,C.mobile_no ,S.to_subscription as due_date, C.isactive ,count(I.invoice_id) as invoice_count_raised_by_customer, S.scheme_id , CM.name as scheme_name ,CM.name, + DATE_FORMAT(S.to_subscription, '%d/%m/%Y') AS formatted_due_date, + DATE_FORMAT(I.invoice_date, '%d/%m/%Y') AS formatted_invoice_date FROM customers as C LEFT JOIN invoice I on I.customer_id = C.customer_id and I.isactive = 1 LEFT JOIN customer_addresses CA on CA.customer_id = C.customer_id and CA.address_type = 1 and CA.isactive = 1 @@ -504,18 +501,31 @@ class Customer extends BaseController $results = $query->getResult(); $this->logger->info("Customer Group: ".json_encode($results)); $group_id = $request_data['group_id']; // Get the ID for update - $isactive = $group_id != "" ? $request_data['isactive'] : 'on'; + $isactive = $group_id == "" ? 1 : (isset($request_data['isactive']) && $request_data['isactive'] == 'on' ? 1 : 0); if($string_flag == "save"){ $data['group_query'] = $sql; $data['group_id'] = $group_id; - $data['isactive'] = (($isactive == 'on') ? 1 : 0); + $data['isactive'] = $isactive; $data['created_by'] = $session_uid; $data['updated_by'] = $session_uid; - $statement = $model->saveGroupDetails($data); + if($group_id != ""){ + $cmod = new CustomerModel(); + $cmod->setTable('customer_groups'); + $where = ['group_id'=>(int)$group_id]; + $isactive_check = $cmod->where($where)->select('isactive')->first(); + if($isactive_check['isactive'] == '0' && $isactive == '0'){ + $statement['success'] = 'Customer Group already In-Active. can`t able to update.'; + $statement['error'] = ""; + $statement['log'] = "Customer Group: already inactive status.Can`t able to Updated Customer Group ID = " .$group_id ; + }else{ + $statement = $model->saveGroupDetails($data); + } + }else{ + $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']); diff --git a/app/Controllers/Home.php b/app/Controllers/Home.php index 61d7f837..f815ceda 100644 --- a/app/Controllers/Home.php +++ b/app/Controllers/Home.php @@ -35,4 +35,45 @@ class Home extends BaseController } + // public function check_existing() + // { + // $value = $this->request->getPost('value'); + // $table = $this->request->getPost('module'); + // $field = $this->request->getPost('field'); + // $model = new HomeModel(); + // $model->setTable($table); + // $where = [$field => $value]; + // $check_existing = $model->where($where)->count(); + // $statement_string = ucfirst(str_replace('_', ' ', $field)); + // if($check_existing>0){ + // $data['status'] = true; + // $data['message'] = $statement_string." Already existing"; + // } + // else{ + // $data['status'] = false; + // $data['message'] = ""; + // } + // return $this->response->setJSON(['data' => $data]); + // } + + public function check_existing() + { + $value = $this->request->getPost('value'); + $table = $this->request->getPost('module'); + $field = $this->request->getPost('field'); + $model = new HomeModel(); + // $model->setTable('customers'); + $model->setTable((string)$table); + $where = [$field => $value]; + $check_existing = $model->where($where)->findAll(); + + $statement_string = ucfirst(str_replace('_', ' ', (string)$field)); + $data = ['status' => false, 'message' => '']; // Initialize the data array + if (!empty($check_existing)) { + $data['status'] = true; + $data['message'] = $statement_string." Already existing"; + } + return $this->response->setJSON(['data' => $data]); + } + } diff --git a/app/Controllers/Invoice.php b/app/Controllers/Invoice.php index 368a7341..78fd1ccd 100644 --- a/app/Controllers/Invoice.php +++ b/app/Controllers/Invoice.php @@ -21,10 +21,10 @@ class Invoice extends BaseController if (!empty($session_role) && $session_role !== "sadmin") { $this->logger->info("Invoice: Listing In Admin BID = " . $session_bid); - $where = ['I.business_id' => (int)$session_bid, 'I.isactive' => 1]; + $where = ['I.business_id' => (int)$session_bid, 'I.isactive' => 1,'I.invoice_type'=>1]; } else { $this->logger->info("Invoice: Listing In the Super-Admin "); - $where = ['I.business_id != ' => NULL, 'I.isactive != ' => NULL]; + $where = ['I.business_id != ' => NULL, 'I.isactive != ' => NULL,'I.invoice_type'=>1]; } $model = new InvoiceModel(); @@ -53,14 +53,17 @@ class Invoice extends BaseController if ($id === '0') { $this->logger->info("Book Invoice: In Add Details"); $data['page_name'] = 'Add Book Invoice Details'; - $data['invoice_type'] = '2'; + $data['invoice_type'] = '1'; $data['invoice_details'] = []; $data['invoice_item_details'] = []; } elseif ($id !== '0') { $this->logger->info("Book Invoice: In Edit Details ID =" . $id); $data['page_name'] = 'Edit Book Invoice Details'; - $data['invoice_type'] ='2'; - $data['invoice_details'] = $model->where(['invoice_id' => $id, 'isactive' => 1])->first(); + $data['invoice_type'] ='1'; + $data['invoice_details'] = $model->where(['invoice_id' => $id, 'isactive' => 1])->first(); + $select = ["customer_address_id", "CONCAT(address_1,' ',address_2) as address"]; + $where = ['address_type'=>2,'customer_addresses.isactive' => 1, 'customer_addresses.customer_id' => (int)$data['invoice_details']['customer_id']]; + $data['customer_shipping_arr'] = $this->get_customer_address($where, $select); $data['invoice_item_details'] = $this->get_invoice_item($id); } // print_r($data['invoice_details']);die; @@ -81,45 +84,53 @@ class Invoice extends BaseController if ($id === '0') { $this->logger->info("Subscription Invoice: In Add Page"); $data['page_name'] = 'Add Subscription Invoice Details'; - $data['invoice_type'] ='1'; + $data['invoice_type'] ='2'; $data['invoice_details'] = []; $data['invoice_item_details'] = []; } elseif ($id !== '0') { $this->logger->info("Subscription Invoice: In Edit Page ID =" . $id); $data['page_name'] = 'Edit Subscription Invoice Details'; - $data['invoice_type'] ='1'; + $data['invoice_type'] ='2'; $data['invoice_details'] = $model->where(['invoice_id' => $id, 'isactive' => 1])->first(); + $select = ["customer_address_id", "CONCAT(address_1,' ',address_2) as address"]; + $where = ['address_type'=>2,'customer_addresses.isactive' => 1, 'customer_addresses.customer_id' => (int)$data['invoice_details']['customer_id']]; + $data['customer_shipping_arr'] = $this->get_customer_address($where, $select); $data['invoice_item_details'] = $this->get_invoice_item($id); } $this->render_page('invoice_form', $data); } - - ## For Ajax Call To Fetch/Retrive All Address Details Based On Customer... - public function load_details1() + ## For Ajax Call To Fetch/Retrive Membership Details Only Based On Customer... + public function get_customer_membership_details() { - $id = $this->request->getPost('selectedValue'); + $customer_id = $this->request->getPost('customer_id'); + $data['customer_membership'] = $this->get_customer_membership("membership",(int)$customer_id); + return $this->response->setJSON(['data' => $data]); + } + + ## For Ajax Call To Fetch/Retrive Billing Address Details Only Based On Customer... + public function get_customer_billing_details() + { + $id = $this->request->getPost('customer_id'); $where = ['customer_addresses.isactive' => 1, 'customer_addresses.customer_id' => (int)$id]; $where['address_type'] = 1; $data['customer_billing'] = $this->get_customer_address($where, []); $select = ["customer_address_id", "CONCAT(address_1,' ',address_2) as address"]; $where['address_type'] = 2; $data['customer_shipping'] = $this->get_customer_address($where, $select); - $data['customer_membership'] = $this->get_customer_membership("membership",(int)$id); return $this->response->setJSON(['data' => $data]); } ## For Ajax Call To Fetch/Retrive Shipping Address Details Only Based On Customer... - public function load_details2() + public function get_customer_shipping_details() { - $customer_id = $this->request->getPost('customerValue'); - $address_id = $this->request->getPost('selectedValue'); + $customer_id = $this->request->getPost('customer_id'); + $address_id = $this->request->getPost('shipping_address_id'); $where = ['customer_addresses.isactive' => 1, 'customer_addresses.customer_id' => (int)$customer_id, 'address_type' => 2, 'customer_address_id' => (int)$address_id]; $data['customer_shipping'] = $this->get_customer_address($where, []); return $this->response->setJSON(['data' => $data]); } - // public function generate_serial_no(){} ## For Gethering Address Details... public function get_customer_address($where, $select) @@ -227,7 +238,7 @@ class Invoice extends BaseController $invoiceItems = $this->get_invoice_item($invoice_id); - if ($invoiceType === '1') { + if ($invoiceType === '2') { // Extract necessary data $customerId = (int)$this->request->getPost('customer_name'); $invoiceId = $invoice_id; // You have this value already @@ -268,8 +279,8 @@ class Invoice extends BaseController - if ($invoiceType === '1') { - // If the invoice_type is 1 (subscription invoice), redirect to the subscription list. + if ($invoiceType === '2') { + // If the invoice_type is 2 (subscription invoice), redirect to the subscription list. return redirect()->route('subscribers_list'); // Adjust the route name as needed. } else { // For other invoice types, redirect to the invoice list. diff --git a/app/Controllers/Notifications.php b/app/Controllers/Notifications.php index a3a4d214..59442d31 100755 --- a/app/Controllers/Notifications.php +++ b/app/Controllers/Notifications.php @@ -291,7 +291,7 @@ class Notifications extends BaseController helper('session'); $session_uid = get_logged_user_id(); $model = new NotificationModel(); - $model->setTable('templates'); + $model->setTable('notification_campaign'); $where = ['campaign_id'=>(int)$id]; $result = $model->where($where)->findAll(); if ($result) { @@ -324,8 +324,9 @@ class Notifications extends BaseController $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; + $request_data = $this->request->getPost(); + $isactive = $id == "" ? 1 : (isset($request_data['isactive']) && $request_data['isactive'] == 'on' ? 1 : 0); + $data = [ 'campaign_id' => $id, 'campaign_name' => $this->request->getPost('campaign_name'), @@ -334,11 +335,25 @@ class Notifications extends BaseController '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, + 'isactive' => $isactive, 'created_by' => $session_uid, 'updated_by' => $session_uid ]; + if($id != ""){ + $notify_mod = new NotificationModel(); + $notify_mod->setTable('notification_campaign'); + $where = ['campaign_id'=>(int)$id]; + $isactive_check = $notify_mod->where($where)->select('isactive')->first(); + if((int)$isactive_check['isactive'] === 0 && $isactive === 0){ + $statement['success'] = 'Notification Campaign already In-Active. can`t able to update.'; + $statement['error'] = ""; + $statement['log'] = "Notification Campaign: already inactive status.Can`t able to update, Notification Campaign Group ID = " .$id ; + }else{ + $statement = $model->saveDetails($data,'campaign_id','notification_campaign'); + } + }else{ $statement = $model->saveDetails($data,'campaign_id','notification_campaign'); + } if ($statement['success']) { session()->setFlashdata('success', $statement['success']); $this->logger->info($statement['log']); @@ -407,7 +422,7 @@ class Notifications extends BaseController } //Step 4: Prepare email content based on the template $emailContent = $templateName[0]['message']; - $emailContent = str_replace("{User}", $fullName, $emailContent); + $emailContent = str_replace("{USER_NAME}", $fullName, $emailContent); $emailContent = str_replace("{SCHEME_NAME}", $schemename, $emailContent); $emailContent = str_replace("{EXPIRY_DATE}", $expirydate, $emailContent); @@ -434,6 +449,179 @@ class Notifications extends BaseController $templateName = $NotificationModel->getTempName(); } } + + public function auto_scheduled_notification() + { + $this->logger->info("Auto Scheduled Notification Started"); + $model = new NotificationModel(); + $model->setTable('notification_campaign'); + $where = ['status'=>0]; + $notification_campaign_result = $model->where($where)->findAll(); + $today = date('Y-m-d'); + $customer_details = array(); + if (!empty($notification_campaign_result)) { + foreach ($notification_campaign_result as $n => $ncr) { + if($today == $ncr['scheduled_date']){ + $this->logger->info("Step 1 : (Campaign) Scheduled Date = " .$ncr['scheduled_date']."/".$ncr['scheduled_time'].", Today = ".$today ); + $customer_details = $this->auto_scheduled_template_details($ncr); + }else{ + $this->logger->info("Step 1 : (Campaign) Scheduled Date = " .$ncr['scheduled_date'].", Today = ".$today ); + } + } + if(!empty($customer_details)){ + $customer_details = $this->auto_scheduled_send_message($customer_details); + } + }else{ + $this->logger->info("Step 1 : Campaign details not found "); + $this->logger->info("Auto Scheduled Notification End"); + } + } + + public function auto_scheduled_template_details($ncr){ + $this->logger->info("To Retrieved Template for Auto Scheduled"); + $template_id = $ncr['template_id']; + $group_id = $ncr['group_id']; + $nc_mode = $ncr['mode']; + $model = new NotificationModel(); + $model->setTable('templates'); + $where = ['template_id'=>$template_id]; + $template_result = $model->where($where)->findAll(); + $flattened_array = array(); // its have customer Details... + if (!empty($template_result)) { + $group_details = array(); + foreach ($template_result as $t => $tr) { + $this->logger->info("Step 2 : (Template) id = ".$tr['template_id']."/".$tr['template_name']." , Template Mode = ".$tr['mode']." NotifyCampian Mode = ".$nc_mode); + $details = $this->auto_scheduled_customer_group_details($tr,$ncr); + if(!empty($details)){ + foreach ($details as $d => $dr) { + $group_details[] = $dr['group_query_results']; + } + } + if(!empty($group_details)){ + foreach ($group_details as $sub_array) { + foreach ($sub_array as $inner_array) { + $flattened_array[] = $inner_array; + } + } + } + + // Don't Delete It Duplication Check 07-12-2023 + // // Extract customer IDs using array_column + // $customer_ids = array_column($flattened_array, 'customer_id'); + // // Find unique customer IDs + // $unique_customer_ids = array_unique($customer_ids); + // // Initialize a new array for unique data + // $unique_data = []; + // // Iterate through the original data and keep only unique entries + // foreach ($flattened_array as $entry) { + // if (in_array($entry['customer_id'], $unique_customer_ids)) { + // $unique_data[] = $entry; + // // Remove the customer ID from the unique array to avoid duplicates + // unset($unique_customer_ids[array_search($entry['customer_id'], $unique_customer_ids)]); + // } + // } + // // Now $uniqueData contains entries with unique customer IDs + // print_r($unique_data); + } + }else{ + $this->logger->info("Step 2 : Template Details details not found"); + $this->logger->info("Auto Scheduled Notification End"); + } + return $flattened_array; + } + + public function auto_scheduled_customer_group_details($tr_object,$ncr_object){ + $this->logger->info("To Retrieved Customer Group Details for Auto Scheduled"); + $group_id = $ncr_object['group_id']; + $nc_mode = $ncr_object['mode']; + $group_arr = unserialize($group_id); + $t_mode = $tr_object['mode']; + $group_details = []; + if (!empty($group_arr)) { + $this->logger->info("Step 3 : (Customer Group) id = ".implode(", ", $group_arr)); + $model = new NotificationModel(); + $model->setTable('customer_groups'); + $group_arr_result = $model->whereIn('group_id', $group_arr)->findAll(); + + if (!empty($group_arr_result)) { + foreach ($group_arr_result as $g => $gar) { + $group_details[$g]['group_query'] = $gar['group_query']; + $group_details[$g]['group_id'] = $gar['group_id']; + $db = \Config\Database::connect(); + $sql = (string)$gar['group_query']; + if($sql){ + $query = $db->query($sql); + $results = $query->getResultArray(); + foreach ($results as &$row) { + $row['group_id'] = $gar['group_id']; + $row['nc_mode'] = $nc_mode; // mode from notification_campaign Table Cross Check purpose + $row['t_mode'] = $t_mode; // mode from template Table Cross Check purpose + $row['template_message'] = $tr_object['message']; + $row['campaign_id'] = $ncr_object['campaign_id']; + } + $group_details[$g]['group_query_results'] = $results; + $group_details[$g]['group_query_customer_count'] = count($results); + $this->logger->info("Step 3 : Customer Group SQL customer count = ".count($results)." group id = ".$gar['group_id']); + + }else{ + $this->logger->info("Step 3 : Customer Group SQL not found"); + } + } + }else{ + $this->logger->info("Step 3 : Customer Group details not found"); + } + }else{ + $this->logger->info("Step 3 : Customer Group ID not found"); + } + return $group_details; + } + + public function auto_scheduled_send_message($customer_details){ + $this->logger->info("To Send Message on Customer for Auto Scheduled"); + if (!empty($customer_details)) { + foreach($customer_details as $c => $cd) { + switch($cd['nc_mode']) { + case "Whatsapp": + $this->auto_scheduled_whatsapp($cd); + break; + case "Email": + $this->auto_scheduled_email($cd); + break; + default: + $this->logger->error("Can't able to identity the mode for Auto Scheduled"); + } + } + } + } + + public function auto_scheduled_whatsapp($cd){ + // $cd["city"] + // $cd["state"] + // $cd["invoice_date"] + // $cd["customer_id"] + echo $cd["customer_name"]; + // $cd["email"] + // $cd["mobile_no"] + // $cd["due_date"] + // $cd["isactive"] + // $cd["invoice_count_raised_by_customer"] + // $cd["scheme_id"] + // $cd["name"] + // $cd["group_id"] + // $cd["nc_mode"] + // $cd["t_mode"] + // $cd["template_message"] + // $cd["campaign_id"] + echo "
";
+            print_r($cd);
+            echo "
"; + } + public function auto_scheduled_email($cd){ + echo $cd["customer_name"]; + echo "
";
+            print_r($cd);
+            echo "
"; + } } \ No newline at end of file diff --git a/app/Controllers/Subscription.php b/app/Controllers/Subscription.php index d77b3abf..c8352b11 100644 --- a/app/Controllers/Subscription.php +++ b/app/Controllers/Subscription.php @@ -20,10 +20,10 @@ class Subscription extends BaseController if (!empty($session_role) && $session_role !== "sadmin") { $this->logger->info("Invoice: Listing In Admin BID = " . $session_bid); - $where = ['I.business_id' => (int)$session_bid, 'I.isactive' => 1]; + $where = ['I.business_id' => (int)$session_bid, 'I.isactive' => 1,'I.invoice_type'=>2]; } else { $this->logger->info("Invoice: Listing In the Super-Admin "); - $where = ['I.business_id != ' => NULL, 'I.isactive != ' => NULL]; + $where = ['I.business_id != ' => NULL, 'I.isactive != ' => NULL,'I.invoice_type'=>2]; } $model = new InvoiceModel(); diff --git a/app/Models/CustomerModel.php b/app/Models/CustomerModel.php index 666cea06..e81ce68c 100644 --- a/app/Models/CustomerModel.php +++ b/app/Models/CustomerModel.php @@ -93,24 +93,24 @@ class CustomerModel extends Model public function getInvoicesByCustomerId($customer_id) { return $this->db->table('invoice') - ->select('invoice_number, subtotal, invoice_date') + ->select('invoice_number, subtotal,total_amount, invoice_date,DATE_FORMAT(invoice_date, "%d/%m/%Y") AS formatted_invoice_date,invoice_type') ->where('customer_id', $customer_id) + ->where('invoice.invoice_type = "1"') ->get() ->getResult(); + // print_r($this->db->getLastQuery());die; } public function getSubscriberDataByCustomerId($customerId) { // Assuming 'subscription' is the table name where subscriber data is stored. $builder = $this->db->table('subscription'); $builder->join('books', 'books.book_id = subscription.scheme_id'); - - + $builder->join('invoice', 'subscription.customer_id = invoice.customer_id', 'left'); // Define the columns you want to select from the subscription table. - $builder->select('subscription.*,books.title'); - + $builder->select('subscription.*,books.title,DATE_FORMAT(subscription.from_subscription, "%d/%m/%Y") AS formatted_from_subscription,DATE_FORMAT(subscription.to_subscription, "%d/%m/%Y") AS formatted_to_subscription'); // Add a where condition to filter results based on customer ID. - $builder->where('customer_id', $customerId); - + $builder->where('subscription.customer_id', $customerId); + $builder->where('invoice.invoice_type = "2"'); // Default type is 2 (subscription). // Execute the query and return the result as an array of objects. return $builder->get()->getResult(); } diff --git a/app/Models/HomeModel.php b/app/Models/HomeModel.php index d6d91c2f..dc61e807 100644 --- a/app/Models/HomeModel.php +++ b/app/Models/HomeModel.php @@ -65,7 +65,7 @@ class HomeModel extends Model ->join('books as BK', 'BK.book_id = S.scheme_id', 'left') ->join('book_categories as BC', 'BC.book_id = S.scheme_id', 'left') ->join('category as CM', 'CM.id = BC.category_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.business_id, S.to_subscription, S.from_subscription, BK.title, BK.book_id,DATEDIFF(S.to_subscription, CURDATE()) as countdays,DATE_FORMAT(S.to_subscription, "%d-%m-%Y") as to_subscription_date_format') + ->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.business_id, S.to_subscription, S.from_subscription, BK.title, BK.book_id,DATEDIFF(S.to_subscription, CURDATE()) as countdays,DATE_FORMAT(S.to_subscription, "%d/%m/%Y") as to_subscription_date_format') ->where('S.to_subscription >=', $now) ->where('S.to_subscription <=', $last30days) // ->where('BC.category_id', 5) @@ -81,7 +81,7 @@ class HomeModel extends Model $oneMonthAgo = date('Y-m-d', strtotime($now . ' -1 month')); return $this->db->table('books as B') - ->select("B.book_id, B.title, B.created_on, B.publisher, B.author, B.publication_date, DATE_FORMAT(B.publication_date, '%d-%m-%Y') as publication_date_format, GROUP_CONCAT(CM.name, ',') as categories") + ->select("B.book_id, B.title, B.created_on, B.publisher, B.author, B.publication_date, DATE_FORMAT(B.publication_date, '%d/%m/%Y') as publication_date_format, GROUP_CONCAT(CM.name, ',') as categories") ->join('book_categories as BC', 'BC.book_id = B.book_id and BC.isactive = 1', 'left') ->join('category as CM', 'BC.category_id = CM.id', 'left') ->where('B.created_on >=', $oneMonthAgo) diff --git a/app/Models/InvoiceModel.php b/app/Models/InvoiceModel.php index 21b2138a..5b980bc8 100644 --- a/app/Models/InvoiceModel.php +++ b/app/Models/InvoiceModel.php @@ -86,7 +86,7 @@ public function updateData($table, $data, $where) ->orderBy('invoice_id', 'DESC') ->get() ->getResultArray(); - + // print_r($this->db->getLastQuery());die; // I.shipping_address_id, I.billing_address_id, } @@ -169,19 +169,18 @@ public function updateData($table, $data, $where) public function getMembershipListForCustomer($category, $id) { - $data = $this->db->table('subscription as S') + 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('book_categories as BC', 'BC.category_id = S.scheme_id', 'left') - ->join('books as BK', 'BC.book_id = BK.book_id', 'left') + ->join('books as BK', 'BK.book_id = S.scheme_id', 'left') + ->join('book_categories as BC', 'BC.book_id = S.scheme_id', 'left') + ->join('category as CM', 'CM.id = BC.category_id', 'left') ->select('S.customer_id, CONCAT(C.first_name, " ", C.last_name) as customer_name, S.sub_id, S.scheme_id, DATE_FORMAT(S.from_subscription, "%d/%m/%Y") AS formatted_from_subscription, DATE_FORMAT(S.to_subscription, "%d/%m/%Y") AS formatted_to_subscription, S.from_subscription, S.to_subscription, S.created_on, CM.name, BK.title, BK.book_id') - ->where('CM.name', strtolower($category)) + ->where('LOWER(CM.name)', strtolower($category)) ->where('S.customer_id', $id) + ->orderBy('S.to_subscription', 'ASC') ->groupBy('S.sub_id') - ->orderBy('S.created_on', 'ASC') ->get() ->getResultArray(); - return $data; } public function getProductImgs($productId) diff --git a/app/Models/NotificationModel.php b/app/Models/NotificationModel.php index 1c3c2ee9..564863d0 100644 --- a/app/Models/NotificationModel.php +++ b/app/Models/NotificationModel.php @@ -47,30 +47,31 @@ class NotificationModel extends Model public function saveDetails($data,$pk_name,$t_name){ $id = $data[$pk_name]; + $statement_string = ucfirst(str_replace('_', ' ', $t_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['success'] = $statement_string.' has been updated successfully.'; $statement['error'] = ""; - $statement['log'] = ucfirst($t_name).": has been updated successfully. Updated ".$pk_name." = " .$id." Affected Rows = ".$affectedRows; + $statement['log'] = $statement_string.": 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 ; + $statement['error'] = $statement_string.' update failed. Please try again.'; + $statement['log'] = $statement_string.": 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['success'] = $statement_string.' has been Inserted successfully.'; $statement['error'] = ""; - $statement['log'] = ucfirst($t_name).": has been added successfully. Inserted ID = " .$insertID ; + $statement['log'] = $statement_string.": 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."; + $statement['error'] = $statement_string." could not be added. Please try again.."; + $statement['log'] = $statement_string.": Err could not be added. Please try again."; } } return $statement; diff --git a/app/Views/campaign_creation.php b/app/Views/campaign_creation.php index f82ef560..b4b91efd 100644 --- a/app/Views/campaign_creation.php +++ b/app/Views/campaign_creation.php @@ -49,8 +49,8 @@ $class = 'badge badge-soft-danger'; $message = 'In-Active'; } - $scheduled_date = date('d/m/Y', strtotime($c['scheduled_date'])); - $scheduled_time = date('h:i A', strtotime($c['scheduled_time'])); + $scheduled_date = $c['scheduled_date'] != "" ? date('d/m/Y', strtotime($c['scheduled_date'])) : ""; + $scheduled_time = $c['scheduled_time'] != "00:00:00" ? date('h:i A', strtotime($c['scheduled_time'])) : ""; ?> diff --git a/app/Views/campaign_creation_form.php b/app/Views/campaign_creation_form.php index 8adf5f5a..0df4ab01 100644 --- a/app/Views/campaign_creation_form.php +++ b/app/Views/campaign_creation_form.php @@ -15,7 +15,7 @@ + +
Please provide.
@@ -62,7 +63,7 @@ diff --git a/app/Views/customer_form.php b/app/Views/customer_form.php index 77381f9f..15b629ab 100644 --- a/app/Views/customer_form.php +++ b/app/Views/customer_form.php @@ -36,7 +36,7 @@
- +
@@ -47,9 +47,10 @@
+91
- +
Please provide.
+
@@ -270,8 +271,8 @@ title ?> - from_subscription ?> - to_subscription ?> + formatted_from_subscription ?> + formatted_to_subscription ?> @@ -289,16 +290,15 @@ Invoice Number Invoice Date - Subtotal + Total invoice_number ?> - invoice_date ?> - subtotal ?> - + formatted_invoice_date ?> + total_amount ?> @@ -541,6 +541,31 @@ validationMessage.style.color = "red"; } } + function checkExisting(inputvalue,fieldname,elementid){ + spanid = elementid == 'cmail' ? "emailValidationMessage" : "mobileValidationMessage"; + var validationMessage = document.getElementById(spanid); + $.ajax({ + type: "POST", + url: "", + data: { + value: inputvalue, + module: 'customers', + field: fieldname + }, + success: function(response) { + if (response['data']['status']) { + validationMessage.textContent = response['data']['message']; + validationMessage.style.color = "red"; + document.getElementById(elementid).value = ""; + } else { + validationMessage.textContent = ""; + } + }, + error: function() { + alert("Error occur."); + } + }); + } diff --git a/app/Views/invoice_form.php b/app/Views/invoice_form.php index af660c8e..f72db1be 100644 --- a/app/Views/invoice_form.php +++ b/app/Views/invoice_form.php @@ -3,6 +3,7 @@ width: 249px !important; } +
@@ -14,7 +15,7 @@
- isactive == 0) ? 'disabled' : ''; ?> @@ -34,7 +35,7 @@
-
@@ -295,7 +296,7 @@ - +
@@ -511,13 +512,32 @@ diff --git a/app/Views/invoice_pdf_template.php b/app/Views/invoice_pdf_template.php index 82c88e7c..a6f78090 100644 --- a/app/Views/invoice_pdf_template.php +++ b/app/Views/invoice_pdf_template.php @@ -286,9 +286,11 @@ if (count($invoiceDateParts) === 3) { Discount :   ₹discount, 2, '.', ',') ?> + shipping_label != '') : ?> shipping_label?> :   ₹shipping_charge, 2, '.', ',') ?> + Total :   ₹total_amount, 2, '.', ',') ?> diff --git a/app/Views/notifications_form.php b/app/Views/notifications_form.php index ef0c535c..fa9e5f09 100644 --- a/app/Views/notifications_form.php +++ b/app/Views/notifications_form.php @@ -112,7 +112,7 @@
@@ -176,7 +176,7 @@
- +
diff --git a/app/Views/template_creation_form.php b/app/Views/template_creation_form.php index 3183df4d..54558be0 100644 --- a/app/Views/template_creation_form.php +++ b/app/Views/template_creation_form.php @@ -34,7 +34,7 @@ diff --git a/app/Views/user_form.php b/app/Views/user_form.php index 46539835..f2482b84 100644 --- a/app/Views/user_form.php +++ b/app/Views/user_form.php @@ -11,7 +11,8 @@
- + +
@@ -179,6 +180,48 @@ } } +