Issues Fixes : ps

This commit is contained in:
VE10-Sanjeev 2023-12-11 09:55:43 +05:30
parent ae5526db8e
commit 250c124dc5
20 changed files with 561 additions and 213 deletions

View File

@ -126,6 +126,9 @@ define('order_child_column', ["invoice_id","wp_api_line_items_id","customer_id"]
// define('WAAI_TOKEN', '6568739969f28'); // define('WAAI_TOKEN', '6568739969f28');
// define('WAAI_INSTANCE', '656876690A9FD'); // 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_URL', 'https://waai.in/api/send');
define('SEND_WAAI_GROUP_URL', 'https://waai.in/api/send_group'); define('SEND_WAAI_GROUP_URL', 'https://waai.in/api/send_group');
define('EXPIRAY_NOTIFY_TEMPLATE_EMAIL','EXPIRAY_NOTIFY_TEMPLATE_EMAIL'); define('EXPIRAY_NOTIFY_TEMPLATE_EMAIL','EXPIRAY_NOTIFY_TEMPLATE_EMAIL');

View File

@ -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('preview_customer_group/(:any)', 'Customer::preview_customer_group/$1');
$routes->get('delete_customer_group/(:any)', 'Customer::delete_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("insert_customer_group", "Customer::insert_customer_group");
$routes->post("check_existing/", "Home::check_existing/");
# Scheme Routes # Scheme Routes
$routes->get("scheme_list/", "Scheme::index"); $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_book_invoice/(:any)", "Invoice::new_book_invoice/$1");
$routes->get("new_subscription_invoice/(:any)", "Invoice::new_subscription_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->post("save_invoice/", "Invoice::save_invoice/");
$routes->get("delete_invoice/(:any)", "Invoice::delete_invoice/$1"); $routes->get("delete_invoice/(:any)", "Invoice::delete_invoice/$1");
$routes->add('approve_invoice/(:num)', 'Invoice::approve_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->post("campaign_creation_insert", "Notifications::campaign_creation_insert");
$routes->get('auto_scheduled_notification/', 'Notifications::auto_scheduled_notification');
# Api integration Routes # Api integration Routes
$routes->post('api/(:any)', 'ApiIntegration::api_integration/$1'); $routes->post('api/(:any)', 'ApiIntegration::api_integration/$1');

View File

@ -353,23 +353,18 @@ class Customer extends BaseController
helper('session'); helper('session');
$model = new CustomerModel(); $model = new CustomerModel();
$model->setTable('customer_groups'); $model->setTable('customer_groups');
$where = ['isactive' => 1,'group_id'=>$id]; $where = ['group_id'=>$id];
$result = $model->where($where)->findAll(); $result = $model->where($where)->findAll();
$db = \Config\Database::connect(); $db = \Config\Database::connect();
$sql = (string)$result[0]['group_query']; $sql = (string)$result[0]['group_query'];
//print_r($sql);die;
if($sql){ if($sql){
$query = $db->query($sql); $query = $db->query($sql);
$results = $query->getResultArray(); $results = $query->getResultArray();
if(empty($results)){
throw new \Exception("Data Not Available");
}else{
return $this->response->setJSON($results); return $this->response->setJSON($results);
}
}else{ }else{
return $this->response->setJSON([]); return $this->response->setJSON([]);
} }
} catch (\Exception $e) { } catch (\Exception $e) {
$this->logger->error("Customer Group: Err Occur = ".$e->getMessage()." File = ". $e->getFile() . " Line = " . $e->getLine()); $this->logger->error("Customer Group: Err Occur = ".$e->getMessage()." File = ". $e->getFile() . " Line = " . $e->getLine());
session()->setFlashdata('error', 'Message: ' . $e->getMessage()); session()->setFlashdata('error', 'Message: ' . $e->getMessage());
@ -488,7 +483,9 @@ class Customer extends BaseController
// Now you can use $whereCondition in your SQL query // Now you can use $whereCondition in your SQL query
$db = \Config\Database::connect(); $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 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 FROM customers as C
LEFT JOIN invoice I on I.customer_id = C.customer_id and I.isactive = 1 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 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(); $results = $query->getResult();
$this->logger->info("Customer Group: ".json_encode($results)); $this->logger->info("Customer Group: ".json_encode($results));
$group_id = $request_data['group_id']; // Get the ID for update $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"){ if($string_flag == "save"){
$data['group_query'] = $sql; $data['group_query'] = $sql;
$data['group_id'] = $group_id; $data['group_id'] = $group_id;
$data['isactive'] = (($isactive == 'on') ? 1 : 0); $data['isactive'] = $isactive;
$data['created_by'] = $session_uid; $data['created_by'] = $session_uid;
$data['updated_by'] = $session_uid; $data['updated_by'] = $session_uid;
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); $statement = $model->saveGroupDetails($data);
}
}else{
$statement = $model->saveGroupDetails($data);
}
if ($statement['success']) { if ($statement['success']) {
session()->setFlashdata('success', $statement['success']); session()->setFlashdata('success', $statement['success']);
$this->logger->info($statement['log']); $this->logger->info($statement['log']);
} else if ($statement['error']) { } else if ($statement['error']) {
session()->setFlashdata('error', $statement['error']); session()->setFlashdata('error', $statement['error']);
$this->logger->error($statement['log']); $this->logger->error($statement['log']);

View File

@ -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]);
}
} }

View File

@ -21,10 +21,10 @@ class Invoice extends BaseController
if (!empty($session_role) && $session_role !== "sadmin") { if (!empty($session_role) && $session_role !== "sadmin") {
$this->logger->info("Invoice: Listing In Admin BID = " . $session_bid); $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 { } else {
$this->logger->info("Invoice: Listing In the Super-Admin "); $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(); $model = new InvoiceModel();
@ -53,14 +53,17 @@ class Invoice extends BaseController
if ($id === '0') { if ($id === '0') {
$this->logger->info("Book Invoice: In Add Details"); $this->logger->info("Book Invoice: In Add Details");
$data['page_name'] = 'Add Book Invoice Details'; $data['page_name'] = 'Add Book Invoice Details';
$data['invoice_type'] = '2'; $data['invoice_type'] = '1';
$data['invoice_details'] = []; $data['invoice_details'] = [];
$data['invoice_item_details'] = []; $data['invoice_item_details'] = [];
} elseif ($id !== '0') { } elseif ($id !== '0') {
$this->logger->info("Book Invoice: In Edit Details ID =" . $id); $this->logger->info("Book Invoice: In Edit Details ID =" . $id);
$data['page_name'] = 'Edit Book Invoice Details'; $data['page_name'] = 'Edit Book Invoice Details';
$data['invoice_type'] ='2'; $data['invoice_type'] ='1';
$data['invoice_details'] = $model->where(['invoice_id' => $id, 'isactive' => 1])->first(); $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); $data['invoice_item_details'] = $this->get_invoice_item($id);
} }
// print_r($data['invoice_details']);die; // print_r($data['invoice_details']);die;
@ -81,45 +84,53 @@ class Invoice extends BaseController
if ($id === '0') { if ($id === '0') {
$this->logger->info("Subscription Invoice: In Add Page"); $this->logger->info("Subscription Invoice: In Add Page");
$data['page_name'] = 'Add Subscription Invoice Details'; $data['page_name'] = 'Add Subscription Invoice Details';
$data['invoice_type'] ='1'; $data['invoice_type'] ='2';
$data['invoice_details'] = []; $data['invoice_details'] = [];
$data['invoice_item_details'] = []; $data['invoice_item_details'] = [];
} elseif ($id !== '0') { } elseif ($id !== '0') {
$this->logger->info("Subscription Invoice: In Edit Page ID =" . $id); $this->logger->info("Subscription Invoice: In Edit Page ID =" . $id);
$data['page_name'] = 'Edit Subscription Invoice Details'; $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(); $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); $data['invoice_item_details'] = $this->get_invoice_item($id);
} }
$this->render_page('invoice_form', $data); $this->render_page('invoice_form', $data);
} }
## For Ajax Call To Fetch/Retrive Membership Details Only Based On Customer...
## For Ajax Call To Fetch/Retrive All Address Details Based On Customer... public function get_customer_membership_details()
public function load_details1()
{ {
$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 = ['customer_addresses.isactive' => 1, 'customer_addresses.customer_id' => (int)$id];
$where['address_type'] = 1; $where['address_type'] = 1;
$data['customer_billing'] = $this->get_customer_address($where, []); $data['customer_billing'] = $this->get_customer_address($where, []);
$select = ["customer_address_id", "CONCAT(address_1,' ',address_2) as address"]; $select = ["customer_address_id", "CONCAT(address_1,' ',address_2) as address"];
$where['address_type'] = 2; $where['address_type'] = 2;
$data['customer_shipping'] = $this->get_customer_address($where, $select); $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]); return $this->response->setJSON(['data' => $data]);
} }
## For Ajax Call To Fetch/Retrive Shipping Address Details Only Based On Customer... ## 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'); $customer_id = $this->request->getPost('customer_id');
$address_id = $this->request->getPost('selectedValue'); $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]; $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, []); $data['customer_shipping'] = $this->get_customer_address($where, []);
return $this->response->setJSON(['data' => $data]); return $this->response->setJSON(['data' => $data]);
} }
// public function generate_serial_no(){}
## For Gethering Address Details... ## For Gethering Address Details...
public function get_customer_address($where, $select) public function get_customer_address($where, $select)
@ -227,7 +238,7 @@ class Invoice extends BaseController
$invoiceItems = $this->get_invoice_item($invoice_id); $invoiceItems = $this->get_invoice_item($invoice_id);
if ($invoiceType === '1') { if ($invoiceType === '2') {
// Extract necessary data // Extract necessary data
$customerId = (int)$this->request->getPost('customer_name'); $customerId = (int)$this->request->getPost('customer_name');
$invoiceId = $invoice_id; // You have this value already $invoiceId = $invoice_id; // You have this value already
@ -268,8 +279,8 @@ class Invoice extends BaseController
if ($invoiceType === '1') { if ($invoiceType === '2') {
// If the invoice_type is 1 (subscription invoice), redirect to the subscription list. // If the invoice_type is 2 (subscription invoice), redirect to the subscription list.
return redirect()->route('subscribers_list'); // Adjust the route name as needed. return redirect()->route('subscribers_list'); // Adjust the route name as needed.
} else { } else {
// For other invoice types, redirect to the invoice list. // For other invoice types, redirect to the invoice list.

View File

@ -291,7 +291,7 @@ class Notifications extends BaseController
helper('session'); helper('session');
$session_uid = get_logged_user_id(); $session_uid = get_logged_user_id();
$model = new NotificationModel(); $model = new NotificationModel();
$model->setTable('templates'); $model->setTable('notification_campaign');
$where = ['campaign_id'=>(int)$id]; $where = ['campaign_id'=>(int)$id];
$result = $model->where($where)->findAll(); $result = $model->where($where)->findAll();
if ($result) { if ($result) {
@ -324,8 +324,9 @@ class Notifications extends BaseController
$model = new NotificationModel(); $model = new NotificationModel();
$session_uid = get_logged_user_id(); $session_uid = get_logged_user_id();
$id = $this->request->getPost('campaign_id'); $id = $this->request->getPost('campaign_id');
$isactive = $this->request->getPost('isactive'); $request_data = $this->request->getPost();
// print_r($this->request->getPost());die; $isactive = $id == "" ? 1 : (isset($request_data['isactive']) && $request_data['isactive'] == 'on' ? 1 : 0);
$data = [ $data = [
'campaign_id' => $id, 'campaign_id' => $id,
'campaign_name' => $this->request->getPost('campaign_name'), 'campaign_name' => $this->request->getPost('campaign_name'),
@ -334,11 +335,25 @@ class Notifications extends BaseController
'scheduled_time' => $this->request->getPost('scheduled_time'), 'scheduled_time' => $this->request->getPost('scheduled_time'),
'mode' => $this->request->getPost('mode'), 'mode' => $this->request->getPost('mode'),
'group_id' => serialize($this->request->getPost('group_id')), 'group_id' => serialize($this->request->getPost('group_id')),
'isactive' => $id ? (($isactive == 'on') ? 1 : 0) : 1, 'isactive' => $isactive,
'created_by' => $session_uid, 'created_by' => $session_uid,
'updated_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'); $statement = $model->saveDetails($data,'campaign_id','notification_campaign');
}
}else{
$statement = $model->saveDetails($data,'campaign_id','notification_campaign');
}
if ($statement['success']) { if ($statement['success']) {
session()->setFlashdata('success', $statement['success']); session()->setFlashdata('success', $statement['success']);
$this->logger->info($statement['log']); $this->logger->info($statement['log']);
@ -407,7 +422,7 @@ class Notifications extends BaseController
} }
//Step 4: Prepare email content based on the template //Step 4: Prepare email content based on the template
$emailContent = $templateName[0]['message']; $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("{SCHEME_NAME}", $schemename, $emailContent);
$emailContent = str_replace("{EXPIRY_DATE}", $expirydate, $emailContent); $emailContent = str_replace("{EXPIRY_DATE}", $expirydate, $emailContent);
@ -434,6 +449,179 @@ class Notifications extends BaseController
$templateName = $NotificationModel->getTempName(); $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 "<pre>";
print_r($cd);
echo "</pre>";
}
public function auto_scheduled_email($cd){
echo $cd["customer_name"];
echo "<pre>";
print_r($cd);
echo "</pre>";
}
} }

View File

@ -20,10 +20,10 @@ class Subscription extends BaseController
if (!empty($session_role) && $session_role !== "sadmin") { if (!empty($session_role) && $session_role !== "sadmin") {
$this->logger->info("Invoice: Listing In Admin BID = " . $session_bid); $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 { } else {
$this->logger->info("Invoice: Listing In the Super-Admin "); $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(); $model = new InvoiceModel();

View File

@ -93,24 +93,24 @@ class CustomerModel extends Model
public function getInvoicesByCustomerId($customer_id) public function getInvoicesByCustomerId($customer_id)
{ {
return $this->db->table('invoice') 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('customer_id', $customer_id)
->where('invoice.invoice_type = "1"')
->get() ->get()
->getResult(); ->getResult();
// print_r($this->db->getLastQuery());die;
} }
public function getSubscriberDataByCustomerId($customerId) public function getSubscriberDataByCustomerId($customerId)
{ {
// Assuming 'subscription' is the table name where subscriber data is stored. // Assuming 'subscription' is the table name where subscriber data is stored.
$builder = $this->db->table('subscription'); $builder = $this->db->table('subscription');
$builder->join('books', 'books.book_id = subscription.scheme_id'); $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. // 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. // 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. // Execute the query and return the result as an array of objects.
return $builder->get()->getResult(); return $builder->get()->getResult();
} }

View File

@ -65,7 +65,7 @@ class HomeModel extends Model
->join('books as BK', 'BK.book_id = S.scheme_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('book_categories as BC', 'BC.book_id = S.scheme_id', 'left')
->join('category as CM', 'CM.id = BC.category_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 >=', $now)
->where('S.to_subscription <=', $last30days) ->where('S.to_subscription <=', $last30days)
// ->where('BC.category_id', 5) // ->where('BC.category_id', 5)
@ -81,7 +81,7 @@ class HomeModel extends Model
$oneMonthAgo = date('Y-m-d', strtotime($now . ' -1 month')); $oneMonthAgo = date('Y-m-d', strtotime($now . ' -1 month'));
return $this->db->table('books as B') 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('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') ->join('category as CM', 'BC.category_id = CM.id', 'left')
->where('B.created_on >=', $oneMonthAgo) ->where('B.created_on >=', $oneMonthAgo)

View File

@ -86,7 +86,7 @@ public function updateData($table, $data, $where)
->orderBy('invoice_id', 'DESC') ->orderBy('invoice_id', 'DESC')
->get() ->get()
->getResultArray(); ->getResultArray();
// print_r($this->db->getLastQuery());die;
// I.shipping_address_id, I.billing_address_id, // I.shipping_address_id, I.billing_address_id,
} }
@ -169,19 +169,18 @@ public function updateData($table, $data, $where)
public function getMembershipListForCustomer($category, $id) 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('customers as C', 'C.customer_id = S.customer_id', 'left')
->join('category as CM', 'CM.id = S.scheme_id', 'left') ->join('books as BK', 'BK.book_id = S.scheme_id', 'left')
->join('book_categories as BC', 'BC.category_id = S.scheme_id', 'left') ->join('book_categories as BC', 'BC.book_id = S.scheme_id', 'left')
->join('books as BK', 'BC.book_id = BK.book_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') ->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) ->where('S.customer_id', $id)
->orderBy('S.to_subscription', 'ASC')
->groupBy('S.sub_id') ->groupBy('S.sub_id')
->orderBy('S.created_on', 'ASC')
->get() ->get()
->getResultArray(); ->getResultArray();
return $data;
} }
public function getProductImgs($productId) public function getProductImgs($productId)

View File

@ -47,30 +47,31 @@ class NotificationModel extends Model
public function saveDetails($data,$pk_name,$t_name){ public function saveDetails($data,$pk_name,$t_name){
$id = $data[$pk_name]; $id = $data[$pk_name];
$statement_string = ucfirst(str_replace('_', ' ', $t_name));
if($id != ''){ if($id != ''){
unset($data[$pk_name]); // Remove the id from the data to avoid updating it unset($data[$pk_name]); // Remove the id from the data to avoid updating it
unset($data['created_by']); // bcoz here data Updating here. unset($data['created_by']); // bcoz here data Updating here.
if ($this->db->table($t_name)->where($pk_name, $id)->update($data)) { if ($this->db->table($t_name)->where($pk_name, $id)->update($data)) {
$affectedRows = $this->db->affectedRows(); $affectedRows = $this->db->affectedRows();
$statement['success'] = ucfirst($t_name).' has been updated successfully.'; $statement['success'] = $statement_string.' has been updated successfully.';
$statement['error'] = ""; $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 { } else {
$statement['success'] = ""; $statement['success'] = "";
$statement['error'] = ucfirst($t_name).' update failed. Please try again.'; $statement['error'] = $statement_string.' update failed. Please try again.';
$statement['log'] = ucfirst($t_name).": Err Failed to update ID = " .$id ; $statement['log'] = $statement_string.": Err Failed to update ID = " .$id ;
} }
}else{ }else{
unset($data['updated_by']); unset($data['updated_by']);
if ($this->db->table($t_name)->insert($data)) { if ($this->db->table($t_name)->insert($data)) {
$insertID = $this->db->insertID(); $insertID = $this->db->insertID();
$statement['success'] = ucfirst($t_name).' has been Inserted successfully.'; $statement['success'] = $statement_string.' has been Inserted successfully.';
$statement['error'] = ""; $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 { } else {
$statement['success'] = ""; $statement['success'] = "";
$statement['error'] = ucfirst($t_name)." could not be added. Please try again.."; $statement['error'] = $statement_string." could not be added. Please try again..";
$statement['log'] = ucfirst($t_name).": Err could not be added. Please try again."; $statement['log'] = $statement_string.": Err could not be added. Please try again.";
} }
} }
return $statement; return $statement;

View File

@ -49,8 +49,8 @@
$class = 'badge badge-soft-danger'; $class = 'badge badge-soft-danger';
$message = 'In-Active'; $message = 'In-Active';
} }
$scheduled_date = date('d/m/Y', strtotime($c['scheduled_date'])); $scheduled_date = $c['scheduled_date'] != "" ? date('d/m/Y', strtotime($c['scheduled_date'])) : "";
$scheduled_time = date('h:i A', strtotime($c['scheduled_time'])); $scheduled_time = $c['scheduled_time'] != "00:00:00" ? date('h:i A', strtotime($c['scheduled_time'])) : "";
?> ?>
<tr> <tr>
<td hidden><?= $c['campaign_id']; ?></td> <td hidden><?= $c['campaign_id']; ?></td>

View File

@ -15,7 +15,7 @@
<label for="group_id" class="col-form-label">Group<span class="text-danger"> *</span></label> <label for="group_id" class="col-form-label">Group<span class="text-danger"> *</span></label>
<!-- <select id="group_id" name="group_id[]" class="form-control select2-multiple" data-toggle="select2" multiple="multiple" data-placeholder="Choose ..." required> --> <!-- <select id="group_id" name="group_id[]" class="form-control select2-multiple" data-toggle="select2" multiple="multiple" data-placeholder="Choose ..." required> -->
<select id="group_id" name="group_id[]" class="form-control" multiple="multiple" required> <select id="group_id" name="group_id[]" class="form-control" multiple="multiple" required>
<option value="">Choose the Group</option> <!-- <option value="">Choose the Group</option> -->
<?php foreach ($group_details as $value) { ?> <?php foreach ($group_details as $value) { ?>
<option value="<?php echo $value['group_id']; ?>" <option value="<?php echo $value['group_id']; ?>"
<?php if (isset($campaign_details['group_id']) && in_array($value['group_id'], $campaign_details['group_id'])) echo "selected"; ?>> <?php if (isset($campaign_details['group_id']) && in_array($value['group_id'], $campaign_details['group_id'])) echo "selected"; ?>>
@ -38,10 +38,11 @@
</div> </div>
</div> </div>
<div class="form-group col-md-8"> <div class="form-group col-md-8">
<label for="scheduled" class="col-form-label">Scheduled Date/Time<span class="text-danger"></span></label> <label for="scheduled" class="col-form-label">Scheduled Date/Time<span class="text-danger"> *</span></label>
<div class="row"> <div class="row">
<div class="col-6"> <div class="col-6">
<input class="form-control" type="date" name="scheduled_date" id="example-date" value="<?= isset($campaign_details['scheduled_date']) ? $campaign_details['scheduled_date'] : '' ?>"> <input class="form-control" type="date" name="scheduled_date" id="example-date" value="<?= isset($campaign_details['scheduled_date']) ? $campaign_details['scheduled_date'] : '' ?>" required>
<div class="invalid-feedback"> Please provide. </div>
</div> </div>
<div class="col-6"> <div class="col-6">
<input class="form-control" type="time" name="scheduled_time" id="example-time" value="<?= isset($campaign_details['scheduled_time']) ? $campaign_details['scheduled_time'] : '' ?>"> <input class="form-control" type="time" name="scheduled_time" id="example-time" value="<?= isset($campaign_details['scheduled_time']) ? $campaign_details['scheduled_time'] : '' ?>">
@ -62,7 +63,7 @@
<label for="templatemessage" class="col-form-label">Template Message<span class="text-danger"> *</span></label> <label for="templatemessage" class="col-form-label">Template Message<span class="text-danger"> *</span></label>
<textarea id="summernote-basic" name="templatemessage" class="form-control" rows="7"> <textarea id="summernote-basic" name="templatemessage" class="form-control" rows="7">
<?php if(isset($campaign_details['message'])){ echo $campaign_details['message']; }else{ ?> <?php if(isset($campaign_details['message'])){ echo $campaign_details['message']; }else{ ?>
<h5>Hello {User}, </h5> <h5>Hello {USER_NAME}, </h5>
<p>Please, write text here!</p> <p>Please, write text here!</p>
<?php } ?> <?php } ?>
</textarea> </textarea>

View File

@ -36,7 +36,7 @@
</div> </div>
<div class="form-group col-md-4"> <div class="form-group col-md-4">
<label for="cmail" class="col-form-label">Email</label> <label for="cmail" class="col-form-label">Email</label>
<input type="text" class="form-control" id="cmail" name="cmail" value="<?= isset($customer['email']) ? $customer['email'] : '' ?>" placeholder="Email" onkeyup="validateEmail(this.value)" /> <input type="text" class="form-control" id="cmail" name="cmail" value="<?= isset($customer['email']) ? $customer['email'] : '' ?>" placeholder="Email" onkeyup="validateEmail(this.value)" onchange="checkExisting(this.value,'email','cmail')" />
<span id="emailValidationMessage"></span> <span id="emailValidationMessage"></span>
</div> </div>
</div> </div>
@ -47,9 +47,10 @@
<div class="input-group-prepend"> <div class="input-group-prepend">
<div class="input-group-text">+91</div> <div class="input-group-text">+91</div>
</div> </div>
<input type="text" class="form-control" name="cmobile" value="<?= isset($customer['mobile_no']) ? $customer['mobile_no'] : '' ?>" placeholder="Mobile Number (Enter only numbers)" required maxlength="10" onkeypress="return restriction(event)" /> <input type="text" class="form-control" id="cmobile" name="cmobile" value="<?= isset($customer['mobile_no']) ? $customer['mobile_no'] : '' ?>" placeholder="Mobile Number (Enter only numbers)" required maxlength="10" onkeypress="return restriction(event)" onchange="checkExisting(this.value,'mobile_no','cmobile')" />
<div class="invalid-feedback"> Please provide. </div> <div class="invalid-feedback"> Please provide. </div>
</div> </div>
<span id="mobileValidationMessage"></span>
</div> </div>
<div class="form-group col-md-4"> <div class="form-group col-md-4">
<label for="dob" class="col-form-label">Date Of Birth</label> <label for="dob" class="col-form-label">Date Of Birth</label>
@ -270,8 +271,8 @@
<?php foreach ($subscriptionData as $subscription) : ?> <?php foreach ($subscriptionData as $subscription) : ?>
<tr> <tr>
<td><?= $subscription->title ?></td> <td><?= $subscription->title ?></td>
<td><?= $subscription->from_subscription ?></td> <td><?= $subscription->formatted_from_subscription ?></td>
<td><?= $subscription->to_subscription ?></td> <td><?= $subscription->formatted_to_subscription ?></td>
</tr> </tr>
<?php endforeach; ?> <?php endforeach; ?>
</tbody> </tbody>
@ -289,16 +290,15 @@
<tr> <tr>
<th>Invoice Number</th> <th>Invoice Number</th>
<th>Invoice Date</th> <th>Invoice Date</th>
<th>Subtotal</th> <th>Total</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<?php foreach ($invoices as $value) : ?> <?php foreach ($invoices as $value) : ?>
<tr> <tr>
<td><?= $value->invoice_number ?></td> <td><?= $value->invoice_number ?></td>
<td><?= $value->invoice_date ?></td> <td><?= $value->formatted_invoice_date ?></td>
<td><?= $value->subtotal ?></td> <td><?= '&#x20B9; '.$value->total_amount ?></td>
</tr> </tr>
<?php endforeach; ?> <?php endforeach; ?>
</tbody> </tbody>
@ -541,6 +541,31 @@
validationMessage.style.color = "red"; validationMessage.style.color = "red";
} }
} }
function checkExisting(inputvalue,fieldname,elementid){
spanid = elementid == 'cmail' ? "emailValidationMessage" : "mobileValidationMessage";
var validationMessage = document.getElementById(spanid);
$.ajax({
type: "POST",
url: "<?= base_url() . 'check_existing' ?>",
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.");
}
});
}
</script> </script>
<script> <script>
function restriction(event) { function restriction(event) {

View File

@ -155,7 +155,7 @@
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<button id="save" class="btn btn-success waves-effect waves-light mr-1" type="submit" id="submitBtn"> Submit </button> <button id="save" class="btn btn-success waves-effect waves-light mr-1" type="submit"> Submit </button>
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button> <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<!-- <button type="button" class="btn btn-primary">Save changes</button> --> <!-- <button type="button" class="btn btn-primary">Save changes</button> -->
</div> </div>
@ -586,10 +586,10 @@ function restriction(event,temporary_flag) {
form.reportValidity(); // Display validation error messages form.reportValidity(); // Display validation error messages
event.preventDefault(); // Prevent form submission if it's not valid event.preventDefault(); // Prevent form submission if it's not valid
$('#submitBtn').prop('disabled', false); $('#save').prop('disabled', false);
} else { } else {
$('#submitBtn').prop('disabled', true); $('#save').prop('disabled', true);
} }
}); });
</script> </script>

View File

@ -3,6 +3,7 @@
width: 249px !important; width: 249px !important;
} }
</style> </style>
<div class="row"> <div class="row">
<div class="col-lg-12"> <div class="col-lg-12">
<div class="card"> <div class="card">
@ -14,7 +15,7 @@
<div class="form-row"> <div class="form-row">
<div class="form-group col-md-6"> <div class="form-group col-md-6">
<label for="customerName">Customer Name<span class="text-danger"> *</span></label> <label for="customerName">Customer Name<span class="text-danger"> *</span></label>
<select class="form-control" id="customerName" name="customer_name" required data-toggle="select2"> <select class="form-control" id="customerName" name="customer_name" required data-toggle="select2" onchange="get_customer_billing_details(this.value); get_customer_membership_details(this.value)">
<option value="">Select a customer</option> <option value="">Select a customer</option>
<?php foreach ($customers as $customer) : ?> <?php foreach ($customers as $customer) : ?>
<?php $disabled = ((int)$customer->isactive == 0) ? 'disabled' : ''; ?> <?php $disabled = ((int)$customer->isactive == 0) ? 'disabled' : ''; ?>
@ -34,7 +35,7 @@
<div class="form-group col-md-6"> <div class="form-group col-md-6">
<label for="loadShippingDropdown">Shipping Address</label> <label for="loadShippingDropdown">Shipping Address</label>
<select class="form-control" id="loadShippingDropdown" name="shipping_address_id" data-toggle="select2"> <select class="form-control" id="loadShippingDropdown" name="shipping_address_id" data-toggle="select2" onchange="get_customer_shipping_details(this.value)">
<option value="">Select an address</option> <option value="">Select an address</option>
</select> </select>
</div> </div>
@ -295,7 +296,7 @@
<!-- Show the "Save as Approved" button only if the status is not "Approved" --> <!-- Show the "Save as Approved" button only if the status is not "Approved" -->
<button type="button" class="btn btn-primary waves-effect mr-1" name="saveas" value="Approved" id="saveApprovedButton">Save as Approved</button> <button type="button" class="btn btn-primary waves-effect mr-1" name="saveas" value="Approved" id="saveApprovedButton">Save as Approved</button>
<?php endif; ?> <?php endif; ?>
<input type="hidden" name="invoice_type" value="<?php echo ($page_name === 'Add Subscription Invoice Details' || $page_name === 'Edit Subscription Invoice Details') ? '1' : '2'; ?>"> <input type="hidden" name="invoice_type" value="<?php echo ($page_name === 'Add Subscription Invoice Details' || $page_name === 'Edit Subscription Invoice Details') ? '2' : '1'; ?>">
</div> </div>
</form> </form>
</div> </div>
@ -511,13 +512,32 @@
</script> </script>
<script> <script>
global_billarr = "";
global_billid = "";
$(document).ready(function() { $(document).ready(function() {
// $("#invoiceNumber").val(final_sno).prop("readonly", true);
var iid_arr = <?php echo json_encode($invoice_item_details); ?>; var iid_arr = <?php echo json_encode($invoice_item_details); ?>;
var cust_id = "<?= isset($invoice_details['customer_id']) ? $invoice_details['customer_id'] : ""; ?>"; var custid = "<?= isset($invoice_details['customer_id']) ? $invoice_details['customer_id'] : ""; ?>";
var ship_addr_id = "<?= isset($invoice_details['shipping_address_id']) ? $invoice_details['shipping_address_id'] : ""; ?>";
var inv_number = "<?= isset($invoice_details['invoice_number']) ? $invoice_details['invoice_number'] : ""; ?>"; var inv_number = "<?= isset($invoice_details['invoice_number']) ? $invoice_details['invoice_number'] : ""; ?>";
if (custid != '') {
var ship_addrid = "<?= isset($invoice_details['shipping_address_id']) ? $invoice_details['shipping_address_id'] : ""; ?>";
var bill_addrid = "<?= isset($invoice_details['billing_address_id']) ? $invoice_details['billing_address_id'] : ""; ?>";
var cust_ship_arr = <?= isset($customer_shipping_arr) ? json_encode($customer_shipping_arr) : "[]"; ?>;
if (cust_ship_arr.length > 0) {
$.each(cust_ship_arr, function(k, v) {
$('#loadShippingDropdown').append($('<option>', {
value: v.customer_address_id,
text: v.address,
selected: (v.customer_address_id == ship_addrid) ? true : false
}));
});
}
if ((bill_addrid === "" || parseInt(bill_addrid) === 0)) {
$('#editAddressesCheckbox').prop('checked', true);
$("#storeBillingAddress").prop("readonly", false);
}
$('#hiddenBillingAddressId').val(bill_addrid);
get_customer_membership_details(custid)
}
if (inv_number != '') { if (inv_number != '') {
$("#invoiceNumber").val(inv_number).prop("readonly", true); $("#invoiceNumber").val(inv_number).prop("readonly", true);
}else{ }else{
@ -530,52 +550,61 @@
$("#invoiceNumber").val(final_sno).prop("readonly", true); $("#invoiceNumber").val(final_sno).prop("readonly", true);
} }
if (cust_id != '') {
load_details1(ship_addr_id, cust_id);
load_details2(ship_addr_id, cust_id);
}
var fromDateValue = "<?= isset($invoice_item_details[0]['from_subscription']) ? $invoice_item_details[0]['from_subscription'] : ""; ?>"; var fromDateValue = "<?= isset($invoice_item_details[0]['from_subscription']) ? $invoice_item_details[0]['from_subscription'] : ""; ?>";
if (fromDateValue != '') { if (fromDateValue != '') {
updateToDateMinDate(fromDateValue) updateToDateMinDate(fromDateValue)
} }
var bill_addr = "";
$("#customerName").change(function() {
var cust_id = $(this).val();
var ship_addr_id = "";
load_details1(ship_addr_id, cust_id);
$('#storeShippingAddress').val('');
});
$("#loadShippingDropdown").change(function() {
var ship_addr_id = $(this).val();
var cust_id = $("#customerName").val();
load_details2(ship_addr_id, cust_id);
});
$("#editAddressesCheckbox").on("change", function() { $("#editAddressesCheckbox").on("change", function() {
if ($(this).is(":checked")) { if ($(this).is(":checked")) {
$("#storeBillingAddress").prop("readonly", false); $("#storeBillingAddress").prop("readonly", false);
$('#hiddenBillingAddressId').val(0);
} else { } else {
$("#storeBillingAddress").prop("readonly", true); $("#storeBillingAddress").prop("readonly", true);
if(global_billarr !== ""){
$("#storeBillingAddress").val(global_billarr);
$('#hiddenBillingAddressId').val(global_billid);
}
} }
}); });
function load_details1(ship_addr_id, cust_id) { function generateSerialNumber(filtered_data) {
var next_id_string = filtered_data[0].next_id;
var left_pad_string = filtered_data[0].left_pad;
var prefix_string = String(filtered_data[0].id_formating);
var left_pad_numberic = parseInt(left_pad_string);
var next_id_numberic = parseInt(next_id_string);
var padded_id = next_id_string.padStart(left_pad_numberic, '0');
var serial_number = prefix_string + '-' + padded_id;
next_id_numberic++;
$("#hiddenNextId").val(next_id_numberic).prop("readonly", true);
return serial_number;
}
});
// Billing ajax call
function get_customer_billing_details(cust_id) {
$.ajax({ $.ajax({
type: "POST", type: "POST",
url: "<?= base_url() . 'load_details1' ?>", url: "<?= base_url() . 'get_customer_billing_details' ?>",
data: { data: {
selectedValue: cust_id customer_id: cust_id
}, },
success: function(response) { success: function(response) {
cs = response['data']['customer_shipping']; cs = response['data']['customer_shipping'];
cb = response['data']['customer_billing']; cb = response['data']['customer_billing'];
cm = response['data']['customer_membership'];
$('#hiddenBillingAddressId').val(''); $('#hiddenBillingAddressId').val('');
customer_billing = ""; $("#editAddressesCheckbox").prop("checked", false);
global_billarr = "";
global_billid = "";
var customer_billing_addressDetails = []; var customer_billing_addressDetails = [];
if (cb.length > 0) { if (cb.length > 0) {
$.each(cb, function(k, v) { $.each(cb, function(k, v) {
@ -586,26 +615,12 @@
state ? customer_billing_addressDetails.push(state):""; state ? customer_billing_addressDetails.push(state):"";
v.country_name ? customer_billing_addressDetails.push(v.country_name) :""; v.country_name ? customer_billing_addressDetails.push(v.country_name) :"";
customer_billing_id = v.customer_address_id; customer_billing_id = v.customer_address_id;
}); });
} }
if (cm.length > 0) { global_billarr = customer_billing_addressDetails.join(', \n')+".";
$(".subscribedetails").show(); // Change this line to use the class selector global_billid = customer_billing_id;
$("#schemeName").text(cm[0].title + " ( From: " + cm[0].formatted_from_subscription + " To: " + cm[0].formatted_to_subscription+" )"); $("#storeBillingAddress").val(global_billarr).prop("readonly", true);
} else { $('#hiddenBillingAddressId').val(global_billid);
$(".subscribedetails").show(); // Change this line to use the class selector
$("#schemeName").text("No Earlier Membership found");
}
if ((bill_addr != "") && (bill_addr != customer_billing)) {
$("#storeBillingAddress").val(bill_addr).prop("readonly", false);
$('#editAddressesCheckbox').prop('checked', true);
} else {
$("#storeBillingAddress").val(customer_billing_addressDetails.join(', \n')+".").prop("readonly", true);
$('#editAddressesCheckbox').prop('checked', false);
}
$('#hiddenBillingAddressId').val(customer_billing_id);
if (cs.length > 0) { if (cs.length > 0) {
$('#loadShippingDropdown').empty(); $('#loadShippingDropdown').empty();
$('#loadShippingDropdown').append($('<option>', { $('#loadShippingDropdown').append($('<option>', {
@ -616,12 +631,9 @@
$('#loadShippingDropdown').append($('<option>', { $('#loadShippingDropdown').append($('<option>', {
value: v.customer_address_id, value: v.customer_address_id,
text: v.address, text: v.address,
selected: (v.customer_address_id ==
ship_addr_id) ?
true : false
})); }));
}); });
$("#storeShippingAddress").val('');
} }
}, },
error: function() { error: function() {
@ -630,14 +642,16 @@
}); });
} }
function load_details2(ship_addr_id, cust_id) {
// shipping ajax call
function get_customer_shipping_details(ship_addr_id) {
var cust_id = $("#customerName").val();
$.ajax({ $.ajax({
type: "POST", type: "POST",
url: "<?= base_url() . 'load_details2' ?>", url: "<?= base_url() . 'get_customer_shipping_details' ?>",
data: { data: {
selectedValue: ship_addr_id, shipping_address_id: ship_addr_id,
customerValue: cust_id customer_id: cust_id
}, },
success: function(response) { success: function(response) {
cs = response['data']['customer_shipping']; cs = response['data']['customer_shipping'];
@ -662,25 +676,31 @@
}); });
} }
function generateSerialNumber(filtered_data) { // membership ajax call
function get_customer_membership_details(cust_id){
var next_id_string = filtered_data[0].next_id; $.ajax({
var left_pad_string = filtered_data[0].left_pad; type: "POST",
var prefix_string = String(filtered_data[0].id_formating); url: "<?= base_url() . 'get_customer_membership_details' ?>",
data: {
var left_pad_numberic = parseInt(left_pad_string); customer_id: cust_id
var next_id_numberic = parseInt(next_id_string); },
success: function(response) {
var padded_id = next_id_string.padStart(left_pad_numberic, '0'); cm = response['data']['customer_membership'];
if (cm.length > 0) {
var serial_number = prefix_string + '-' + padded_id; $(".subscribedetails").show(); // Change this line to use the class selector
next_id_numberic++; $("#schemeName").text(cm[0].title + " ( From: " + cm[0].formatted_from_subscription + " To: " + cm[0].formatted_to_subscription+" )");
$("#hiddenNextId").val(next_id_numberic).prop("readonly", true); } else {
$(".subscribedetails").show(); // Change this line to use the class selector
return serial_number; $("#schemeName").text("No Earlier Membership found");
}
},
error: function() {
alert("Error fetching address.");
}
});
} }
});
</script> </script>
<!-- bill_addr = "<?= isset($invoice_details['billing_address']) ? $invoice_details['billing_address'] : ""; ?>"; --> <!-- bill_addr = "<?= isset($invoice_details['billing_address']) ? $invoice_details['billing_address'] : ""; ?>"; -->
<!-- if (bill_addr != '') { $("#storeBillingAddress").val(bill_addr);} --> <!-- if (bill_addr != '') { $("#storeBillingAddress").val(bill_addr);} -->

View File

@ -286,9 +286,11 @@ if (count($invoiceDateParts) === 3) {
<tr> <tr>
<td colspan="5" align="right">Discount : &nbsp;&nbsp;<?= number_format($value->discount, 2, '.', ',') ?></td> <td colspan="5" align="right">Discount : &nbsp;&nbsp;<?= number_format($value->discount, 2, '.', ',') ?></td>
</tr> </tr>
<?php if ($value->shipping_label != '') : ?>
<tr> <tr>
<td colspan="5" align="right"><?= $value->shipping_label?> : &nbsp;&nbsp;₹<?= number_format($value->shipping_charge, 2, '.', ',') ?></td> <td colspan="5" align="right"><?= $value->shipping_label?> : &nbsp;&nbsp;₹<?= number_format($value->shipping_charge, 2, '.', ',') ?></td>
</tr> </tr>
<?php endif; ?>
<tr> <tr>
<td colspan="5" align="right">Total : &nbsp;&nbsp;<?= number_format($value->total_amount, 2, '.', ',') ?></td> <td colspan="5" align="right">Total : &nbsp;&nbsp;<?= number_format($value->total_amount, 2, '.', ',') ?></td>
</tr> </tr>

View File

@ -112,7 +112,7 @@
<label for="body" class="col-4 col-form-label">Body</label> <label for="body" class="col-4 col-form-label">Body</label>
<div class="col-7"> <div class="col-7">
<textarea id="summernote-basic" name="description" class="form-control" rows="7"> <textarea id="summernote-basic" name="description" class="form-control" rows="7">
<h5>Hello {User}, </h5> <h5>Hello {USER_NAME}, </h5>
<p>We create simple, flat & responsive custom mail template.</p> <p>We create simple, flat & responsive custom mail template.</p>
<p>Please, write text here!</p> <p>Please, write text here!</p>
</textarea> </textarea>
@ -176,7 +176,7 @@
<div class="form-group row"> <div class="form-group row">
<label for="message" class="col-4 col-form-label">Message</label> <label for="message" class="col-4 col-form-label">Message</label>
<div class="col-7"> <div class="col-7">
<textarea id="message" name="description" class="form-control" rows="5">Hello {User},Please,write text here!</textarea> <textarea id="message" name="description" class="form-control" rows="5">Hello {USER_NAME},Please,write text here!</textarea>
</div> </div>
</div> </div>
<div class="form-group text-right m-b-0"> <div class="form-group text-right m-b-0">

View File

@ -34,7 +34,7 @@
<label for="templatemessage" class="col-form-label">Template Message<span class="text-danger"> *</span></label> <label for="templatemessage" class="col-form-label">Template Message<span class="text-danger"> *</span></label>
<textarea id="summernote-basic" name="templatemessage" class="form-control" rows="7"> <textarea id="summernote-basic" name="templatemessage" class="form-control" rows="7">
<?php if(isset($template_details['message'])){ echo $template_details['message']; }else{ ?> <?php if(isset($template_details['message'])){ echo $template_details['message']; }else{ ?>
<h5>Hello {User}, </h5> <h5>Hello {USER_NAME}, </h5>
<p>Please, write text here!</p> <p>Please, write text here!</p>
<?php } ?> <?php } ?>
</textarea> </textarea>

View File

@ -11,7 +11,8 @@
<div class="form-row"> <div class="form-row">
<div class="form-group col-md-6"> <div class="form-group col-md-6">
<label for="email" class="col-form-label">Email<span class="text-danger">*</span></label> <label for="email" class="col-form-label">Email<span class="text-danger">*</span></label>
<input type="email" class="form-control" id="email" name="email" placeholder="Email" value="<?= isset($details['email']) ? $details['email'] : '' ?>" required /> <input type="email" class="form-control" id="email" name="email" placeholder="Email" value="<?= isset($details['email']) ? $details['email'] : '' ?>" required onchange="checkExistingEmail(this.value)" />
<span id="emailValidationMessage"></span>
</div> </div>
<?php if (empty($details)) { ?> <?php if (empty($details)) { ?>
@ -179,6 +180,48 @@
} }
} }
</script> </script>
<script>
function validateEmail(email) {
// Regular expression for a basic email validation
var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
var emailInput = document.getElementById("email");
var validationMessage = document.getElementById("emailValidationMessage");
if (emailPattern.test(email)) {
validationMessage.textContent = "";
} else if (email == "") {
validationMessage.textContent = "";
} else {
validationMessage.textContent = "Invalid email address";
validationMessage.style.color = "red";
}
}
function checkExistingEmail(email){
var validationMessage = document.getElementById("emailValidationMessage");
$.ajax({
type: "POST",
url: "<?= base_url() . 'check_existing' ?>",
data: {
value: email,
module: 'users',
field: 'email'
},
success: function(response) {
if (response['data']['status']) {
validationMessage.textContent = response['data']['message'];
validationMessage.style.color = "red";
document.getElementById('email').value = "";
} else {
validationMessage.textContent = "";
}
},
error: function() {
alert("Error occur.");
}
});
}
</script>
<script> <script>
document.getElementById('myForm').addEventListener('submit', function(event) { document.getElementById('myForm').addEventListener('submit', function(event) {
var form = event.target; var form = event.target;