FEATURE_NEW PAYMENT CALLBACK URL ADDED

This commit is contained in:
Srinivas-Saravanan 2024-11-12 16:09:05 +05:30
parent 37dc008a4e
commit fbae302ed0
16 changed files with 654 additions and 282 deletions

View File

@ -196,8 +196,9 @@ $routes->match(['get','post'],'/response','Payment::response/');
$routes->get('/payment_failure', 'Payment::payment_failure');
$routes->get('/payment_success','Payment::payment_success');
$routes->match(['get','post'],'/subscription_renewal/(:any)','Payment::index/$1');
$routes->get('dummy', 'Payment::dummy');
// $routes->group("api", function ($routes) {
// $routes->group("api", function ($routes) {
// // $routes->post("create_products/", "ApiIntegration::save_book_details");
// // $routes->match(['put', 'post', 'get', 'delete'], 'products', 'ApiIntegration::book_api_integration');
// // $routes->match(['put', 'post', 'get', 'delete'], 'customers', 'ApiIntegration::customer_api_integration');

View File

@ -9,7 +9,7 @@ use App\Models\BusinessModel;
use App\Models\BooksModel;
use App\Helpers\NotificationHelper;
use App\Helpers\date_picker;
use App\Models\SubscriptionModel;
use Mpdf\Mpdf;
use Dompdf\Dompdf;
@ -185,197 +185,362 @@ class Invoice extends BaseController
}
## To insert or update the details of the invoice
// public function save_invoice()
// {
// // echo "<pre>";
// // print_r($this->request->getPost());die;
// $this->logger->info("Invoice: Insert/Update Details");
// try {
// ## Declarions
// helper('session');
// helper('financial_year_helper');
// $model = new InvoiceModel();
// $duedate = $this->request->getVar('due_date');
// $invdate = $this->request->getVar('invoice_date');
// $invoice_status = $this->request->getPost('status');
// $invoice_id = (!empty($this->request->getPost('invoice_id'))) ? $this->request->getPost('invoice_id') : "";
// $customer_id = (int)$this->request->getPost('customer_name');
// $invoiceType = $this->request->getPost('invoice_type');
// $msg_flag_name = ((int)$invoiceType === 1) ? "Invoice " : "Subscription ";
// $renewal = 0;
// if ((int)$invoiceType === 2 && $invoice_status == 'Approved') {
// $requestData = $this->request->getPost();
// $itemid = $requestData['invoice_child_id'];
// $count = count($itemid);
// $scheme_id = null;
// if ($count > 0) {
// for ($x = 0; $x < $count; $x++) {
// if (!empty($requestData['item_details'][$x])) {
// $scheme_id = (int)$requestData['item_details'][$x];
// }
// }
// }
// // $now = date('Y-m-d');
// // $get_exists_subscription_where = ['S.customer_id' => (int)$customer_id,'S.scheme_id' => $scheme_id,'I.status' => 'Approved','I.isactive' => 1,"S.to_subscription <= "=>$now];
// $get_exists_subscription_where = ['S.customer_id' => (int)$customer_id, 'S.scheme_id' => $scheme_id, 'I.status' => 'Approved', 'I.isactive' => 1];
// $get_exists_subscription_dtls = $model->existsSubscriptionDetails($get_exists_subscription_where);
// if ($get_exists_subscription_dtls) {
// // session()->setFlashdata('success', 'This Scheme Already Existing in this Customer.');
// $this->logger->info($msg_flag_name . ": This Scheme Already Existing in this Customer. ");
// $renewal = 1;
// }
// }
// $invdate_dbformat = (!empty($invdate)) ? \DateTime::createFromFormat('d/m/Y', $invdate)->format('Y-m-d') : NULL;
// $duedate_dbformat = (!empty($duedate)) ? \DateTime::createFromFormat('d/m/Y', $duedate)->format('Y-m-d') : NULL;
// ## Array Formation For Invoice Details..
// $data = [
// 'invoice_number' => $this->request->getPost('invoice_number'),
// 'invoice_type' => $this->request->getPost('invoice_type'),
// 'customer_id' => $customer_id,
// 'billing_address_id' => (int)$this->request->getPost('billing_address_id'),
// 'billing_address' => $this->request->getPost('billing_address'),
// 'shipping_address_id' => (int)$this->request->getPost('shipping_address_id'),
// 'shipping_address' => $this->request->getPost('shipping_address'),
// 'notes' => $this->request->getPost('notes'),
// 'invoice_date' => $invdate_dbformat,
// 'due_date' => $duedate_dbformat,
// 'subtotal' => (float)$this->request->getPost('sub_total'),
// 'tax' => (float)$this->request->getPost('invoice_tax'),
// 'dis_type' => $this->request->getPost('dis_type'),
// 'discount' => (float)$this->request->getPost('discount'),
// 'exact_total_amount' => (float)$this->request->getPost('exact_total_amount'),
// 'total_amount' => (int)$this->request->getPost('grand_total'),
// 'shipping_charge' => ((int)$invoiceType === 1) ? (float)$this->request->getPost('shippingCharges') : NULL,
// 'shipping_label' => ((int)$invoiceType === 1) ? $this->request->getPost('shippingChargesLabel') : NULL,
// 'order_number' => $this->request->getPost('order_number'),
// 'payment_method' => $invoice_status !== 'Draft' ? $this->request->getPost('payment_method') : NULL, // "Credit Card," "Cash on Delivery," "PayPal","PayTm","Gpay"
// 'payment_status' => 'Pending', //"Paid," "Pending," "Failed," "Refunded," "Canceled," "Authorized," and "Completed."
// 'payment_note' => $this->request->getPost('payment_note'),
// 'event_id' => (int)$this->request->getPost('event_id'),
// 'business_id' => (int)get_business_id(),
// 'status' => $invoice_status,
// 'isactive' => 1,
// ];
// ## Based on the invoice ID, we designated Insert or Update on Details...
// if (empty($invoice_id)) {
// $data['created_by'] = (int)get_logged_user_id();
// if ($model->insert($data, 'invoices')) {
// $invoice_id = $model->insertID();
// session()->setFlashdata('success', $msg_flag_name . 'has been added successfully.');
// $this->logger->info($msg_flag_name . ": has been added successfully. Inserted ID = " . $invoice_id);
// // If it's a subscription invoice, also store data in the 'subscription' table
// } else {
// session()->setFlashdata('error', $msg_flag_name . 'could not be added. Please try again.');
// $this->logger->error($msg_flag_name . ": Err Occur could not be added. Please try again.");
// }
// } else {
// $data['updated_by'] = (int)get_logged_user_id();
// if ($model->update($invoice_id, $data)) {
// // echo $model->getLastQuery();die;
// session()->setFlashdata('success', $msg_flag_name . 'has been updated successfully.');
// $this->logger->info($msg_flag_name . ": has been updated successfully. Updated ID = " . $invoice_id);
// } else {
// session()->setFlashdata('error', $msg_flag_name . 'update failed. Please try again.');
// $this->logger->error($msg_flag_name . ": Err Failed to update ID =" . $invoice_id);
// }
// }
// $requestData = $this->request->getPost();
// if ($this->request->getPost('next_id')) {
// ## Array Formation For Invoice Numbering Format Details..
// $update_invoice_numbering = [
// 'id' => 1,
// 'id_formating' => get_financial_year(),
// 'next_id' => (int)$this->request->getPost('next_id'),
// 'business_id' => (int)get_business_id(),
// 'updated_by' => get_logged_user_id()
// ];
// $this->update_number_formatting($update_invoice_numbering);
// }
// ## For Invoice Item Details Insert/Update..
// $this->save_invoice_item($invoice_id, $requestData, (int)$this->request->getVar('product'));
// ## Subscription..
// if ((int)$invoiceType === 2) {
// // Loop through invoice items and store them in the 'subscription' table
// $subscriptionModel = new InvoiceModel(); // Replace with your actual model
// $invoiceItems = $this->get_invoice_item($invoice_id);
// foreach ($invoiceItems as $item) {
// $product_id = $item['product'];
// $from_sub_date = $item['from_subscription'];
// $to_sub_date = $item['to_subscription'];
// $subscription_data = [
// 'customer_id' => (int)$customer_id,
// 'invoice_id' => $invoice_id,
// 'scheme_id' => $product_id,
// 'from_subscription' => $from_sub_date,
// 'to_subscription' => $to_sub_date,
// 'business_id' => get_business_id(),
// 'created_by' => get_logged_user_id(),
// 'is_renew' => $renewal
// ];
// if ($invoice_status == 'Draft') {
// $get_subscription_draft_dtl_where = ['S.customer_id' => $customer_id, 'I.status' => $invoice_status];
// // $get_subscription_draft_dtl_id = $model->InactiveSubscriptionDraftDetails($get_subscription_draft_dtl_where,get_logged_user_id());
// // $this->logger->info($msg_flag_name.": has been Inactived. Inv ID = ".implode(", ", $get_subscription_draft_dtl_id));
// $get_subscription_draft_dtl_id = $model->deleteSubscriptionDraftDetails($get_subscription_draft_dtl_where, get_logged_user_id());
// $this->logger->info($msg_flag_name . ": has been Deleted. Inv ID = " . implode(", ", $get_subscription_draft_dtl_id));
// // $subscriptionModel->insertSubscriptionData($subscription_data);
// } else {
// // Check if there is a draft entry for the customer_id and scheme_id
// $get_subscription_draft_dtl_where = [
// 'S.customer_id' => $customer_id,
// 'S.scheme_id' => $scheme_id, // Assuming scheme_id is available here
// 'I.status' => 'Draft'
// ];
// $get_subscription_draft_dtl_id = $model->deleteSubscriptionDraftDetails($get_subscription_draft_dtl_where, get_logged_user_id());
// $this->logger->info($msg_flag_name . ": Draft entry has been deleted. Inv ID = " . implode(", ", $get_subscription_draft_dtl_id));
// // Now insert the new entry
// }
// }
// $subscriptionModel->insertSubscriptionData($subscription_data);
// }
// ## Notification For Approve..
// $this->logger->info($msg_flag_name . ": ID = " . $invoice_id . ", Status =" . $invoice_status);
// if ($invoice_status == 'Approved' && $invoice_id != "") {
// $this->logger->info($msg_flag_name . ": in " . $invoice_status . ". ID = " . $invoice_id);
// $this->approve_notifications((int)$invoice_id);
// }
// } catch (\Exception $e) {
// $this->logger->error($msg_flag_name . ": Err Occur =" . $e->getMessage());
// session()->setFlashdata('error', 'Message: ' . $e->getMessage());
// }
// if ($invoiceType === '2') {
// $this->logger->info(session()->getFlashdata());
// // 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.
// $this->logger->info(session()->getFlashdata());
// return redirect()->route('offline_invoice'); // Adjust the route name as needed.
// }
// }
public function save_invoice()
{
{
helper('session');
helper('financial_year_helper');
$this->logger->info("Invoice: Insert/Update Details");
// echo "<pre>";
// print_r($this->request->getPost());die;
$this->logger->info("Invoice: Insert/Update Details");
try {
try {
// Retrieve form data
$invoice_status = $this->request->getPost('status');
$invoice_id = (!empty($this->request->getPost('invoice_id'))) ? $this->request->getPost('invoice_id') : "";
$invoiceType = $this->request->getPost('invoice_type');
$msg_flag_name = ((int)$invoiceType === 1) ? "Invoice " : "Subscription ";
## Declarions
helper('session');
helper('financial_year_helper');
// Handle invoice creation or update
$invoice_id = $this->create_or_update_invoice($invoice_id, $msg_flag_name);
$model = new InvoiceModel();
$duedate = $this->request->getVar('due_date');
$invdate = $this->request->getVar('invoice_date');
$invoice_status = $this->request->getPost('status');
$invoice_id = (!empty($this->request->getPost('invoice_id'))) ? $this->request->getPost('invoice_id') : "";
$customer_id = (int)$this->request->getPost('customer_name');
$invoiceType = $this->request->getPost('invoice_type');
$msg_flag_name = ((int)$invoiceType === 1) ? "Invoice " : "Subscription ";
$renewal = 0;
if ((int)$invoiceType === 2 && $invoice_status == 'Approved') {
$requestData = $this->request->getPost();
$itemid = $requestData['invoice_child_id'];
$count = count($itemid);
$scheme_id = null;
if ($count > 0) {
for ($x = 0; $x < $count; $x++) {
if (!empty($requestData['item_details'][$x])) {
$scheme_id = (int)$requestData['item_details'][$x];
}
}
}
// $now = date('Y-m-d');
// $get_exists_subscription_where = ['S.customer_id' => (int)$customer_id,'S.scheme_id' => $scheme_id,'I.status' => 'Approved','I.isactive' => 1,"S.to_subscription <= "=>$now];
$get_exists_subscription_where = ['S.customer_id' => (int)$customer_id, 'S.scheme_id' => $scheme_id, 'I.status' => 'Approved', 'I.isactive' => 1];
$get_exists_subscription_dtls = $model->existsSubscriptionDetails($get_exists_subscription_where);
if ($get_exists_subscription_dtls) {
// session()->setFlashdata('success', 'This Scheme Already Existing in this Customer.');
$this->logger->info($msg_flag_name . ": This Scheme Already Existing in this Customer. ");
$renewal = 1;
}
}
$invdate_dbformat = (!empty($invdate)) ? \DateTime::createFromFormat('d/m/Y', $invdate)->format('Y-m-d') : NULL;
$duedate_dbformat = (!empty($duedate)) ? \DateTime::createFromFormat('d/m/Y', $duedate)->format('Y-m-d') : NULL;
## Array Formation For Invoice Details..
$data = [
'invoice_number' => $this->request->getPost('invoice_number'),
'invoice_type' => $this->request->getPost('invoice_type'),
'customer_id' => $customer_id,
'billing_address_id' => (int)$this->request->getPost('billing_address_id'),
'billing_address' => $this->request->getPost('billing_address'),
'shipping_address_id' => (int)$this->request->getPost('shipping_address_id'),
'shipping_address' => $this->request->getPost('shipping_address'),
'notes' => $this->request->getPost('notes'),
'invoice_date' => $invdate_dbformat,
'due_date' => $duedate_dbformat,
'subtotal' => (float)$this->request->getPost('sub_total'),
'tax' => (float)$this->request->getPost('invoice_tax'),
'dis_type' => $this->request->getPost('dis_type'),
'discount' => (float)$this->request->getPost('discount'),
'exact_total_amount' => (float)$this->request->getPost('exact_total_amount'),
'total_amount' => (int)$this->request->getPost('grand_total'),
'shipping_charge' => ((int)$invoiceType === 1) ? (float)$this->request->getPost('shippingCharges') : NULL,
'shipping_label' => ((int)$invoiceType === 1) ? $this->request->getPost('shippingChargesLabel') : NULL,
'order_number' => $this->request->getPost('order_number'),
'payment_method' => $invoice_status !== 'Draft' ? $this->request->getPost('payment_method') : NULL, // "Credit Card," "Cash on Delivery," "PayPal","PayTm","Gpay"
'payment_status' => 'Pending', //"Paid," "Pending," "Failed," "Refunded," "Canceled," "Authorized," and "Completed."
'payment_note' => $this->request->getPost('payment_note'),
'event_id' => (int)$this->request->getPost('event_id'),
'business_id' => (int)get_business_id(),
'status' => $invoice_status,
'isactive' => 1,
];
## Based on the invoice ID, we designated Insert or Update on Details...
if (empty($invoice_id)) {
$data['created_by'] = (int)get_logged_user_id();
if ($model->insert($data, 'invoices')) {
$invoice_id = $model->insertID();
session()->setFlashdata('success', $msg_flag_name . 'has been added successfully.');
$this->logger->info($msg_flag_name . ": has been added successfully. Inserted ID = " . $invoice_id);
// If it's a subscription invoice, also store data in the 'subscription' table
} else {
session()->setFlashdata('error', $msg_flag_name . 'could not be added. Please try again.');
$this->logger->error($msg_flag_name . ": Err Occur could not be added. Please try again.");
}
} else {
$data['updated_by'] = (int)get_logged_user_id();
if ($model->update($invoice_id, $data)) {
// echo $model->getLastQuery();die;
session()->setFlashdata('success', $msg_flag_name . 'has been updated successfully.');
$this->logger->info($msg_flag_name . ": has been updated successfully. Updated ID = " . $invoice_id);
} else {
session()->setFlashdata('error', $msg_flag_name . 'update failed. Please try again.');
$this->logger->error($msg_flag_name . ": Err Failed to update ID =" . $invoice_id);
}
}
$requestData = $this->request->getPost();
if ($this->request->getPost('next_id')) {
## Array Formation For Invoice Numbering Format Details..
$update_invoice_numbering = [
'id' => 1,
'id_formating' => get_financial_year(),
'next_id' => (int)$this->request->getPost('next_id'),
'business_id' => (int)get_business_id(),
'updated_by' => get_logged_user_id()
];
$this->update_number_formatting($update_invoice_numbering);
}
## For Invoice Item Details Insert/Update..
$this->save_invoice_item($invoice_id, $requestData, (int)$this->request->getVar('product'));
## Subscription..
if ((int)$invoiceType === 2) {
// Loop through invoice items and store them in the 'subscription' table
$subscriptionModel = new InvoiceModel(); // Replace with your actual model
$invoiceItems = $this->get_invoice_item($invoice_id);
foreach ($invoiceItems as $item) {
$product_id = $item['product'];
$from_sub_date = $item['from_subscription'];
$to_sub_date = $item['to_subscription'];
// Handle invoice items creation or update
$this->create_or_update_invoice_items($invoice_id);
$update_invoice_numbering = [
'id' => 1,
'id_formating' => get_financial_year(),
'next_id' => (int)$this->request->getPost('next_id'),
'business_id' => (int)get_business_id(),
'updated_by' => get_logged_user_id()
];
$this->update_number_formatting($update_invoice_numbering);
$subscription_data = [
'customer_id' => (int)$customer_id,
'invoice_id' => $invoice_id,
'scheme_id' => $product_id,
'from_subscription' => $from_sub_date,
'to_subscription' => $to_sub_date,
'business_id' => get_business_id(),
'created_by' => get_logged_user_id(),
'is_renew' => $renewal
];
if ($invoice_status == 'Draft') {
$get_subscription_draft_dtl_where = ['S.customer_id' => $customer_id, 'I.status' => $invoice_status];
// $get_subscription_draft_dtl_id = $model->InactiveSubscriptionDraftDetails($get_subscription_draft_dtl_where,get_logged_user_id());
// $this->logger->info($msg_flag_name.": has been Inactived. Inv ID = ".implode(", ", $get_subscription_draft_dtl_id));
$get_subscription_draft_dtl_id = $model->deleteSubscriptionDraftDetails($get_subscription_draft_dtl_where, get_logged_user_id());
$this->logger->info($msg_flag_name . ": has been Deleted. Inv ID = " . implode(", ", $get_subscription_draft_dtl_id));
// $subscriptionModel->insertSubscriptionData($subscription_data);
} else {
// Check if there is a draft entry for the customer_id and scheme_id
$get_subscription_draft_dtl_where = [
'S.customer_id' => $customer_id,
'S.scheme_id' => $scheme_id, // Assuming scheme_id is available here
'I.status' => 'Draft'
];
$get_subscription_draft_dtl_id = $model->deleteSubscriptionDraftDetails($get_subscription_draft_dtl_where, get_logged_user_id());
$this->logger->info($msg_flag_name . ": Draft entry has been deleted. Inv ID = " . implode(", ", $get_subscription_draft_dtl_id));
// Now insert the new entry
}
}
$subscriptionModel->insertSubscriptionData($subscription_data);
}
## Notification For Approve..
$this->logger->info($msg_flag_name . ": ID = " . $invoice_id . ", Status =" . $invoice_status);
if ($invoice_status == 'Approved' && $invoice_id != "") {
$this->logger->info($msg_flag_name . ": in " . $invoice_status . ". ID = " . $invoice_id);
$this->approve_notifications((int)$invoice_id);
}
} catch (\Exception $e) {
$this->logger->error($msg_flag_name . ": Err Occur =" . $e->getMessage());
session()->setFlashdata('error', 'Message: ' . $e->getMessage());
// Handle subscription if invoice type is subscription
if ((int)$invoiceType === 2) {
$this->create_or_update_subscription($invoice_id, $msg_flag_name);
}
// Send notification if invoice is approved
$this->logger->info($msg_flag_name . ": ID = " . $invoice_id . ", Status =" . $invoice_status);
if ($invoice_status == 'Approved' && $invoice_id != "") {
$this->logger->info($msg_flag_name . ": in " . $invoice_status . ". ID = " . $invoice_id);
$this->approve_notifications((int)$invoice_id);
}
// Redirect to the appropriate route based on the invoice type
if ($invoiceType === '2') {
$this->logger->info(session()->getFlashdata());
// 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');
} else {
// For other invoice types, redirect to the invoice list.
$this->logger->info(session()->getFlashdata());
return redirect()->route('offline_invoice'); // Adjust the route name as needed.
return redirect()->route('offline_invoice');
}
} catch (\Exception $e) {
$this->logger->error("Error Occurred: " . $e->getMessage());
session()->setFlashdata('error', 'Message: ' . $e->getMessage());
}
}
public function create_or_update_invoice($invoice_id, $msg_flag_name)
{
$model = new InvoiceModel();
$invoice_status = $this->request->getPost('status');
$customer_id = (int)$this->request->getPost('customer_name');
$invoiceType = $this->request->getPost('invoice_type');
// Prepare invoice data
$data = $this->prepare_invoice_data($invoice_id, $msg_flag_name);
// Insert or update invoice based on ID
if (empty($invoice_id)) {
$data['created_by'] = (int)get_logged_user_id();
if ($model->insert($data, 'invoices')) {
$invoice_id = $model->insertID();
session()->setFlashdata('success', $msg_flag_name . 'has been added successfully.');
$this->logger->info($msg_flag_name . ": Added successfully. ID = " . $invoice_id);
} else {
session()->setFlashdata('error', $msg_flag_name . 'could not be added. Please try again.');
$this->logger->error($msg_flag_name . ": Could not be added.");
}
} else {
$data['updated_by'] = (int)get_logged_user_id();
if ($model->update($invoice_id, $data)) {
session()->setFlashdata('success', $msg_flag_name . 'has been updated successfully.');
$this->logger->info($msg_flag_name . ": Updated successfully. ID = " . $invoice_id);
} else {
session()->setFlashdata('error', $msg_flag_name . 'update failed. Please try again.');
$this->logger->error($msg_flag_name . ": Failed to update ID = " . $invoice_id);
}
}
return $invoice_id;
}
public function prepare_invoice_data($invoice_id, $msg_flag_name)
{
$invdate = $this->request->getVar('invoice_date');
$duedate = $this->request->getVar('due_date');
$invoice_status = $this->request->getPost('status');
$invoiceType = $this->request->getPost('invoice_type');
// Convert dates to database format
$invdate_dbformat = (!empty($invdate)) ? \DateTime::createFromFormat('d/m/Y', $invdate)->format('Y-m-d') : NULL;
$duedate_dbformat = (!empty($duedate)) ? \DateTime::createFromFormat('d/m/Y', $duedate)->format('Y-m-d') : NULL;
// Prepare invoice data array
return [
'invoice_number' => $this->request->getPost('invoice_number'),
'invoice_type' => $invoiceType,
'customer_id' => (int)$this->request->getPost('customer_name'),
'billing_address_id' => (int)$this->request->getPost('billing_address_id'),
'billing_address' => $this->request->getPost('billing_address'),
'shipping_address_id' => (int)$this->request->getPost('shipping_address_id'),
'shipping_address' => $this->request->getPost('shipping_address'),
'notes' => $this->request->getPost('notes'),
'invoice_date' => $invdate_dbformat,
'due_date' => $duedate_dbformat,
'subtotal' => (float)$this->request->getPost('sub_total'),
'tax' => (float)$this->request->getPost('invoice_tax'),
'dis_type' => $this->request->getPost('dis_type'),
'discount' => (float)$this->request->getPost('discount'),
'exact_total_amount' => (float)$this->request->getPost('exact_total_amount'),
'total_amount' => (int)$this->request->getPost('grand_total'),
'shipping_charge' => ((int)$invoiceType === 1) ? (float)$this->request->getPost('shippingCharges') : NULL,
'shipping_label' => ((int)$invoiceType === 1) ? $this->request->getPost('shippingChargesLabel') : NULL,
'order_number' => $this->request->getPost('order_number'),
'payment_method' => $invoice_status !== 'Draft' ? $this->request->getPost('payment_method') : NULL,
'payment_status' => 'Pending',
'payment_note' => $this->request->getPost('payment_note'),
'event_id' => (int)$this->request->getPost('event_id'),
'business_id' => (int)get_business_id(),
'status' => $invoice_status,
'isactive' => 1,
];
}
public function create_or_update_invoice_items($invoice_id)
{
$this->save_invoice_item($invoice_id, $this->request->getPost(), (int)$this->request->getVar('product'));
}
public function create_or_update_subscription($invoice_id, $msg_flag_name = null)
{
$model = new InvoiceModel();
$subModel = new SubscriptionModel();
$customer_id = (int)$this->request->getPost('customer_name');
$invoiceItems = $this->get_invoice_item($invoice_id);
$renewal = 0;
foreach ($invoiceItems as $item) {
$product_id = $item['product'];
$from_sub_date = $item['from_subscription'];
$to_sub_date = $item['to_subscription'];
$result = $subModel->selectMax('membership_id')->first();
$max_membership_id = $result ? $result['membership_id'] : null;
// Prepare subscription data
$subscription_data = [
'customer_id' => $customer_id,
'invoice_id' => $invoice_id,
'scheme_id' => $product_id,
'from_subscription' => $from_sub_date,
'to_subscription' => $to_sub_date,
'business_id' => get_business_id(),
'created_by' => get_logged_user_id(),
'is_renew' => $renewal,
'membership_id'=>$max_membership_id +1
];
// Insert the subscription data
$model->insertSubscriptionData($subscription_data);
}
}
## For Updating Events Details ..
public function update_number_formatting($update_events)
{
@ -389,6 +554,7 @@ class Invoice extends BaseController
$update_data = ['next_id' => $update_events['next_id'], 'updated_by' => $update_events['updated_by']];
$model->updateData('invoice_number_formatting', $update_data, $update_where);
}
log_message('debug',"inside update_number_formatting");
}
## To insert or update invoice item details based on invoice ID
@ -424,11 +590,17 @@ class Invoice extends BaseController
}
}
// echo "<br/>....................";
//var_dump($itemid);die();
$count = count($itemid);
log_message('info','the count is '.$count);
log_message('debug','request data = '.json_encode($requestData));
$invoiceitem_arr = [];
if ($count > 0) {
for ($x = 0; $x < $count; $x++) {
log_message('info','inside the for loop');
if (!empty($requestData['item_details'][$x])) {
log_message('debug','inside 1');
$invoiceitem_arr[$x]['invoice_id'] = $id;
$invoiceitem_arr[$x]['product'] = (int)$requestData['item_details'][$x];
$invoiceitem_arr[$x]['description'] = $requestData['description'][$x];
@ -451,7 +623,12 @@ class Invoice extends BaseController
$invoiceitem_arr[$x]['isactive'] = 1;
$invoiceitem_arr[$x]['invoice_child_id'] = $itemid[$x];
}
else{
log_message('info','inside else');
}
}
log_message('info','this is inside the save_invoice_item'.json_encode($invoiceitem_arr));
$statement = $model->saveInvoiceItemDetails($invoiceitem_arr);
}
return $statement;
@ -462,7 +639,7 @@ class Invoice extends BaseController
{
$model = new InvoiceModel();
$model->setTable('invoiceitems');
$where = ['isactive' => 1, 'invoice_id' => (int)$id];
$where = ['isactive' => 1, 'invoice_id' => $id];
$details = $model->where($where)->findAll();
return $details;
}
@ -1316,7 +1493,6 @@ class Invoice extends BaseController
$response['invoice']['message'] = 'Subscription Master (Invoice) There Is No Changes to Updated';
$this->logger->error("Update Approval Subscription Master (Invoice) Err Failed to update ID =" . $invoice_id);
}
## Invoice Line Item..
$invoice_child_id = $requestData['invoice_child_id'];
$count = count($invoice_child_id);

View File

@ -603,6 +603,7 @@ class Notifications extends BaseController
$emailTemplateName = $NotificationModel->getTempName(EXPIRAY_NOTIFY_TEMPLATE_EMAIL);
echo "Started.<br> Dated = ".$newDate." <br> There are ".count($queryResult)." persons <br>";
//print_r($queryResult);die();
foreach ($queryResult as $inx => $row) {
$status = $row['status'];
$userFirstName = $row['first_name'];
@ -612,6 +613,7 @@ class Notifications extends BaseController
$schemename = $row['title'];
$expirydate = $row['to_subscription'];
$customerId = $row['customer_id'];
$membership_id = $row['membership_id'];
if (empty($fullName)) {
$this->logger->error('There is no subcription Name');
continue;
@ -637,8 +639,8 @@ class Notifications extends BaseController
if (isset($expirydate)) {
$emailContent = str_replace("{EXPIRY_DATE}", $expirydate, $emailContent);
}
if (isset($customerId)) {
$emailContent = str_replace("{RENEWAL_LINK}", base_url() . 'subscription_renewal/' . $customerId, $emailContent);
if (isset($membership_id)) {
$emailContent = str_replace("{RENEWAL_LINK}", base_url() . 'subscription_renewal/' .'MEM'. $membership_id, $emailContent);
}

View File

@ -4,12 +4,9 @@ namespace App\Controllers;
use App\Models\CustomerModel;
use App\Models\InvoiceModel;
use App\Models\SchemeModel;
use App\Models\TransactionModel;
use App\Models\SubscriptionModel;
use paytmpg\pg\request\InitiateTransactionRequestBody;
use paytmpg\pg\response\InitiateTransactionResponse;
use paytmpg\pg\constants\MerchantProperties;
use paytmpg\pg\process\Transaction;
require_once('vendor/autoload.php');
define('PROJECT', 'vendor/paytm/paytm-pg');
@ -21,21 +18,24 @@ class Payment extends BaseController
helper('encdec_paytm');
}
public function index($subscriptionID = null)
public function index($membership_id = null)
{
$model = new CustomerModel();
$model2 = new SubscriptionModel();
if ($subscriptionID != null){
$customer_details = $model->get_customer_details_by_customer_id($subscriptionID);
$scheme = $model2->get_subscription_details_by_customerID($subscriptionID);
if ($membership_id != null){;
$membership_id2 = substr($membership_id, 3);
$customer_id = $model2->select('customer_id')->where('membership_id',$membership_id2)->first();
$customer_details = $model->get_customer_details_by_customer_id($customer_id);
$scheme = $model2->get_subscription_details_by_membership_id($membership_id2);
//var_dump($customer_details);die();
$response = [
'customer_details' => $customer_details,
'scheme' => $scheme,
'subscriptionID' =>$subscriptionID
'membership_id' =>$membership_id,
'CustomerID' =>$customer_id
];
//var_dump($response);die();
return view('subscription_renewal',$response);
}
else{
@ -45,15 +45,17 @@ class Payment extends BaseController
}
else {
//echo "inside else";die();
$customer_id = $this->request->getPost('customerID');
$membership_id = $this->request->getPost('membership_id');
$membership_id = substr($membership_id, 3);
$scheme = $model2->get_subscription_details_by_membership_id($membership_id);
$customer_id = $model2->select('customer_id')->where('membership_id',$membership_id)->first();
$customer_details = $model->get_customer_details_by_customer_id($customer_id);
$scheme = $model2->get_subscription_details_by_customerID($customer_id);
log_message('info','inside the method post');
$response = [
'customer_details' => $customer_details,
'scheme' => $scheme
'scheme' => $scheme,
'CustomerID' =>$customer_id
];
//var_dump($response);die();
return $this->response->setJSON($response);
}
}
@ -95,6 +97,8 @@ public function tresponse() {
print_r($paramList);
$isValidChecksum = "FALSE";
$paramList = $_POST;
// dd($paramList);
$paytmChecksum = isset($_POST["CHECKSUMHASH"]) ? $_POST["CHECKSUMHASH"] : "";
$result['receivedFromPaytm'] = $paramList;
// Verify checksum
@ -110,26 +114,182 @@ public function tresponse() {
log_message('error',json_encode($paramList));
}
if ($_POST["STATUS"] == "TXN_SUCCESS") {
$queryString = http_build_query($paramList);
echo "<b>Transaction status is success</b><br/>";
return redirect()->to(base_url('/payment_success'));
return redirect()->to(base_url('/payment_success?' . $queryString));
} else {
echo "<b>Processing ...</b><br/>";
return redirect()->to(base_url('/payment_failure'));
}
$queryString = http_build_query($paramList);
return redirect()->to(base_url('/payment_failure?' . $queryString));
}
} else {
echo "<b>Checksum mismatched.</b>";
log_message('error','Checksum Mismatched');
return view('/payment_failure');
}
}
public function payment_failure(){
$paramList = [
'BANKTXNID' => $this->request->getVar('BANKTXNID'),
'CHECKSUMHASH' => $this->request->getVar('CHECKSUMHASH'),
'GATEWAYNAME' => $this->request->getVar('GATEWAYNAME'),
'ORDERID' => $this->request->getVar('ORDERID'),
'PAYMENTMODE' => $this->request->getVar('PAYMENTMODE'),
'STATUS' => $this->request->getVar('STATUS'),
'TXNAMOUNT' => $this->request->getVar('TXNAMOUNT'),
'TXNDATE' => $this->request->getVar('TXNDATE'),
'TXNID' => $this->request->getVar('TXNID'),
'is_active' => 1
];
$model4 = new TransactionModel();
$model4->save($paramList);
return view('/payment_failure');
}
public function payment_success(){
public function payment_success() {
helper('session');
helper('financial_year_helper');
$ORDER_ID = $this->request->getVar('ORDERID');
$parts = explode('_', $ORDER_ID);
$customer_id = (int)$parts[0];
$currentDate = date('Y-m-d');
// Assuming the model is used for database interactions
$model = new InvoiceModel();
$db = \Config\Database::connect();
$address = $db->table('customer_addresses')->select('address_1','customer_address_id')->where('customer_id',$customer_id)->get()->getRowArray();
$next_id_row = $db->table('invoice_number_formatting')->select('next_id, left_pad')->get()->getRowArray();
$filtered_data = [
[
'next_id' => $next_id_row['next_id'],
'left_pad' => $next_id_row['left_pad']
]
];
$financial_year = get_financial_year();
$result = $this->generateSerialNumber($filtered_data, $financial_year);
//var_dump($result);die();
$invoice_number = $result['serial_number'];
$next_id_numeric = $result['next_id'];
$data = [
'invoice_number' => $invoice_number,
'invoice_type' => 2,
'customer_id' => $customer_id,
'payment_status' => 'Paid',
'sub_total' => 1500,
'exact_total_amount' => 1500.00,
'grand_total' => 1500.00,
'invoice_date' => $currentDate,
'billing_address'=> $address['address_1'],
'billing_address_id' => isset($address['customer_address_id']) ? $address['customer_address_id'] : ''
];
$model->save($data);
$update_invoice_numbering = [
'id' => 1,
'id_formating' => get_financial_year(),
'next_id' => (int)$next_id_numeric,
'business_id' => 2,
'updated_by' => null !== ($userId = get_logged_user_id()) ? $userId : '',
];
// var_dump($update_invoice_numbering);die();
$save_invoice = new Invoice();
$save_invoice->update_number_formatting($update_invoice_numbering);
$invoice_id = $model->select('invoice_id')->where('invoice_number',$invoice_number)->first();
//var_dump($invoice_id['invoice_id']);die();
$fsubscription = $currentDate;
$tsubscription = date('Y-m-d', strtotime('+1 year', strtotime($currentDate)));
$data['item_details'] = 3;
$requestData = [
'invoice_id' =>$invoice_id['invoice_id'],
'product' => $data['item_details'],
'quantity' =>1,
'subtotal' => $data['sub_total'],
'created_on'=>$currentDate,
'isactive'=>1,
'from_subscription' =>$fsubscription,
'to_subscription' =>$tsubscription
];
$db->table('invoiceitems')->insert($requestData);
$model3 = new SubscriptionModel();
$id_exist = $model3->where('customer_id',$customer_id)->first();
if ($id_exist>0){
$subscriptionData = [
'scheme_id' =>3,
'customer_id' => $customer_id,
'invoice_id' => $invoice_id,
'from_subscription'=>$fsubscription,
'to_subscription'=>$tsubscription,
'is_renew' => 'renewal'
];
$db->table('subscription')->where('customer_id', $customer_id)->update($subscriptionData);
}else{
$subscriptionData = [
'scheme_id' =>3,
'customer_id' => $customer_id,
'invoice_id' => $invoice_id,
'from_subscription'=>$fsubscription,
'to_subscription'=>$tsubscription,
'is_renew' =>0
];
$db->table('subscription')->insert($subscriptionData);
}
$paramList = [
'BANKTXNID' => $this->request->getVar('BANKTXNID'),
'CHECKSUMHASH' => $this->request->getVar('CHECKSUMHASH'),
'GATEWAYNAME' => $this->request->getVar('GATEWAYNAME'),
'ORDERID' => $this->request->getVar('ORDERID'),
'PAYMENTMODE' => $this->request->getVar('PAYMENTMODE'),
'STATUS' => $this->request->getVar('STATUS'),
'TXNAMOUNT' => $this->request->getVar('TXNAMOUNT'),
'TXNDATE' => $this->request->getVar('TXNDATE'),
'TXNID' => $this->request->getVar('TXNID'),
'invoice_id' => $invoice_id,
'is_active' => 1
];
$model4 = new TransactionModel();
$model4->save($paramList);
log_message('info','sent data' .json_encode($data));
return view('/payment_success');
}
public function generateSerialNumber($filtered_data, $financial_year) {
$next_id_string = $filtered_data[0]['next_id'];
$left_pad_string = $filtered_data[0]['left_pad'];
$prefix_string = $financial_year;
$left_pad_numeric = (int)$left_pad_string;
$next_id_numeric = (int)$next_id_string;
$padded_id = str_pad($next_id_string, $left_pad_numeric, '0', STR_PAD_LEFT);
$serial_number = $prefix_string . '-' . $padded_id;
$next_id_numeric++;
return ['serial_number' => $serial_number, 'next_id' => $next_id_numeric];
}
public function dummy(){
$paramList["MID"] = 'VIJAYA69114768822289';
$paramList["ORDER_ID"] = '63_6731c6eeb58fd';
$paramList["CUST_ID"] = '63';
$paramList["INDUSTRY_TYPE_ID"] = 'Retail105';
$paramList["CHANNEL_ID"] = 'WEB';
$paramList["TXN_AMOUNT"] = 1.00;
$paramList["WEBSITE"] = 'DEFAULT';
$paramList["CALLBACK_URL"] = (string) base_url('tresponse');
$checkSum = getChecksumFromArray($paramList, 'x%4%KwIyHW!P2&tF');
print_r($paramList);
echo "<br>";
print_r($checkSum);
}
}

View File

@ -22,8 +22,10 @@ public function saveInvoiceItemDetails($data){
$this->db->table('invoiceitems')->where('invoice_child_id', $id)->update($row);// Update the row with the specified id
$affectedRows = $this->db->affectedRows();
$statement[$i] = "Invoice Item - ".$id." ".$affectedRows ? " Updated":" Not Updated";
}else{
unset($row['updated_by']); // bcoz here data are inserting here.
}else{
if (!empty($row['updated_by'])){
unset($row['updated_by']); // bcoz here data are inserting here.
}
$this->db->table('invoiceitems')->insert($row);
$insertID = $this->db->insertID();
$statement[$i] = "Invoice Item - ".$insertID." Inserted";

View File

@ -338,12 +338,12 @@ public function getQueryforSubscriptionDetailsBySchemeName($flag,$condition, $va
$query = $builder->get();
return $query->getResult();
}
public function get_subscription_details_by_customerID($customerID)
public function get_subscription_details_by_membership_id($membership_id)
{
$builder = $this->db->table('subscription');
$builder->select('subscription.from_subscription, subscription.to_subscription, subscription.scheme_id,books.price ,books.short_code');
$builder->join('books', 'subscription.scheme_id = books.book_id', 'left');
$builder->where('subscription.customer_id', $customerID);
$builder->join('books', 'subscription.scheme_id = books.book_id');
$builder->where('subscription.membership_id', $membership_id);
$result = $builder->get()->getRowArray();
return $result;

View File

@ -0,0 +1,9 @@
<?php
namespace App\Models;
use CodeIgniter\Model;
class TransactionModel extends Model
{
protected $table = 'transactions';
protected $primaryKey = 'transaction_id';
protected $allowedFields = ['BANKTXNID','CHECKSUMHASH','GATEWAYNAME','ORDERID','PAYMENTMODE','STATUS','TXNAMOUNT','TXNDATE','TXNID','transaction_id','invoice_id','created_at','updated_at','isactive'];
}

View File

@ -177,7 +177,7 @@
$lastStartDateTime = ($lastNotification && isset($lastNotification['start_date_time'])) ? $lastNotification['start_date_time'] : '';
$startDateTime = $lastStartDateTime ? date('d/m/Y', strtotime($lastStartDateTime)) : '';
if($lastNotification['receiving_status']){
if(isset($lastNotification['receiving_status'])){
if ($startDateTime >= $startDate && $startDateTime <= $endDate) {
echo $startDateTime ;
}

View File

@ -30,24 +30,24 @@
<thead>
<tr>
<th>Invoice ID</th>
<th>Customer Name</th>
<th>Total Amount</th>
<th>Payment Status</th>
<th>Payment Method</th>
<th>Invoice Date</th>
<th>Customer Name</th>
<th>Payment Method</th>
<th>Payment Status</th>
<th>Total Amount</th>
</tr>
</thead>
<tbody>
<?php foreach ($payment_data as $row) { ?>
<tr>
<td style="text-align: left;"><?php echo $row["invoice_number"]; ?></td>
<td style="text-align: left;"><?= $row['first_name'] ?></td>
<td style="text-align: right;"><?= $row['total_amount'] ?></td>
<td><?= $row['payment_status'] ?></td>
<td><?= $row['payment_method']?></td>
<?php $unixTime = strtotime($row['invoice_date']);
$invoice_date = date("d-m-Y", $unixTime);?>
$invoice_date = date("d/m/Y", $unixTime);?>
<td><?= $invoice_date ?></td>
<td style="text-align: left;"><?= $row['first_name'] ?></td>
<td><?= $row['payment_method']?></td>
<td><?= $row['payment_status'] ?></td>
<td style="text-align: right;"><?= $row['total_amount'] ?></td>
</tr>
<?php } ?>
</tbody>

View File

@ -40,11 +40,11 @@
<thead>
<tr>
<th hidden>id</th>
<th>Inv Date</th>
<th>Book Name</th>
<th>Author</th>
<th>Cost</th>
<th>Published By</th>
<th>Inv Date</th>
<th>Cost</th>
</tr>
</thead>
@ -53,11 +53,11 @@
<?php foreach ($report_data as $row) { ?>
<tr>
<td hidden><?php echo $row->invoice_id; ?></td>
<td style = "text-align:center"><?php echo date("d/m/Y",strtotime($row->invoice_date)) ?></td>
<td style="text-align: left;"><?php echo $row->title; ?></td>
<td style="text-align: left;"><?php echo $row->publisher; ?></td>
<td style="text-align: end;"><?php echo $row->price ?></td>
<td style="text-align: left;"><?php echo $row->author; ?></td>
<td style="text-align: left;"><?php echo $row->publishers_code?></td>
<td style = "text-align:center"><?php echo date("d/m/Y",strtotime($row->invoice_date)) ?></td>
<td style="text-align: end;"><?php echo $row->price ?></td>
</tr>
<?php } ?>
</tbody>

View File

@ -34,10 +34,9 @@
<div class="col-12">
<div class="card">
<div class="card-body">
<div class="col-md-12">
<button type="button" class="btn btn-primary show-column-selection-modal" style="margin-left: 870px;">Select Columns</button>
</div>
<div class="col-md-12 d-flex justify-content-end">
<button type="button" class="btn btn-primary show-column-selection-modal" style="margin-left: auto;">Select Columns</button>
</div>
<div class="table-responsive">
<table id="datatable-buttons" class="table table-striped nowrap w-100">
<thead>
@ -46,14 +45,17 @@
<th>Invoice No</th>
<th>Invoice Date</th>
<th>Customer Name</th>
<th>GST</th>
<th>Discount</th>
<th>Count</th>
<th>OT Charges</th>
<th>Total</th>
<th>Invoice Type</th>
<th>Status</th>
<th>Type of Invoice</th>
<th>Payment</th>
<th>Discount ()</th>
<th>OT Charges ()</th>
<th>GST (%)</th>
<th>Total ()</th>
</tr>
</thead>
@ -65,14 +67,15 @@
<td><?php echo $row->invoice_number; ?></td>
<td style="text-align: left;"><?php echo $row->formatted_invoice_date; ?></td>
<td style="text-align: left;"><?php echo $row->first_name . " " . $row->last_name; ?></td>
<td><?php echo $row->tax ? $row->tax . '%' : '0%'; ?></td>
<td><?php echo '₹' . number_format($row->discount, 2, '.', ','); ?></td>
<td style="text-align: center;"><?php echo $row->item_count; ?></td>
<td style="text-align: right;"><?php echo '₹' . number_format($row->shipping_charge, 2, '.', ','); ?></td>
<td style="text-align: right;"><?php echo '₹' . number_format($row->total_amount, 2, '.', ','); ?></td>
<td><?php echo ($row->invoice_type == 1) ? 'Book' : 'Membership'; ?></td>
<td><?php echo $row->status; ?></td>
<td><?php echo ($row->invoice_type == 1) ? 'Book Invoice' : 'Membership Invoice'; ?></td>
<td><?php echo $row->payment_method; ?></td>
<td style="text-align: right;"><?php echo number_format($row->discount, 2, '.', ','); ?></td>
<td style="text-align: right;"><?php echo number_format($row->shipping_charge, 2, '.', ','); ?></td>
<td style="text-align: right;"><?php echo $row->tax ? $row->tax : '0.00'; ?></td>
<td style="text-align: right;"><?php echo number_format($row->total_amount, 2, '.', ','); ?></td>
</tr>
<?php } ?>
</tbody>

View File

@ -56,26 +56,27 @@
<table id="datatable-buttons" class="table table-striped nowrap w-100">
<thead class="custom-thead">
<tr>
<th><b>Published Date</b></th>
<th><b>Publisher Code</b></th>
<th><b>Publisher Item Count</b></th>
<th><b>Publisher Total Cost</b></th>
<th><b>Book Name</b></th>
<th><b>Item Count</b></th>
<th><b>Total Cost</b></th>
<th><b>Published Date</b></th>
</tr>
</thead>
<tbody class="custom-tbody">
<?php foreach ($report_data as $row) { ?>
<?php foreach ($row->books as $book) { ?>
<tr>
<td style="text-align: left;"><?php echo isset($row->publisher_code)? $row->publisher_code:'-'; ?></td>
<td><?php echo $book->book_publication_date; ?></td>
<td style="text-align: left;"><?php echo isset($row->publisher_code)? $row->publisher_code:'-'; ?></td>
<td style="text-align: center;"><?php echo $row->publisher_item_count; ?></td>
<td style="text-align: right;"><?php echo number_format($row->publisher_total_cost, 2); ?></td>
<td style="text-align: left;"><?php echo $book->book_name; ?></td>
<td style="text-align: center;"><?php echo $book->item_count; ?></td>
<td style="text-align: right;"><?php echo number_format($book->total_cost, 2); ?></td>
<td><?php echo $book->book_publication_date; ?></td>
</tr>
<?php } ?>
<?php } ?>

View File

@ -30,26 +30,26 @@
<thead>
<tr>
<th hidden>id</th>
<th>User Name</th>
<th>Event Name</th>
<th>Books Sold</th>
<th>Total Amount</th>
<th>Payment Method</th>
<th>Invoice Date</th>
<th>Event Name</th>
<th>User Name</th>
<th>Books Sold</th>
<th>Payment Method</th>
<th>Total Amount</th>
</tr>
</thead>
<tbody>
<?php foreach ($report_data as $row) { ?>
<tr>
<td hidden><?php echo $row["user_id"]; ?></td>
<td style="text-align: left;"><?= $row['first_name']?></td>
<td style="text-align: left;"><?= $row['event_name'] ?></td>
<td style="text-align: center;"><?= $row['books_sold'] ?></td>
<td style="text-align: right;"><?= $row['total_amount'] ?></td>
<td style="text-align: left;"><?= $row['payment_method']?></td>
<?php $unixTime = strtotime($row['invoice_date']);
$invoice_date = date("d-m-Y", $unixTime);?>
$invoice_date = date("d/m/Y", $unixTime);?>
<td><?= $invoice_date ?></td>
<td style="text-align: left;"><?= $row['event_name'] ?></td>
<td style="text-align: left;"><?= $row['first_name']?></td>
<td style="text-align: center;"><?= $row['books_sold'] ?></td>
<td style="text-align: left;"><?= $row['payment_method']?></td>
<td style="text-align: right;"><?= $row['total_amount'] ?></td>
</tr>
<?php } ?>
</tbody>

View File

@ -40,7 +40,7 @@
<th>Expiring Status</th>
<th>Invoice Number</th>
<th>Invoice Date</th>
<th>Total</th>
<th>Total () </th>
<th>Status</th>
<th align="center" id="action-column">Action</th>
</tr>
@ -99,7 +99,7 @@
<td data-order="<?= $message; ?>"><span class="<?php echo $class; ?>"><?php echo $message; ?></span></td>
<td data-order="<?= $row['invoice_number']; ?>"><?= $row['invoice_number']; ?></td>
<td data-order="<?= strtotime($row['invoice_date']); ?>"><?= $invoice_date; ?></td>
<td data-order="<?= $row['total_amount']; ?>"><?= "" . $row['total_amount']; ?></td>
<td data-order="<?= $row['total_amount']; ?>"><?=$row['total_amount']; ?></td>
<td data-order="<?= $row['status']; ?>"><?= $row['status']; ?></td>
<td>
<a href="<?= base_url() . "new_subscription_invoice/" . $row['invoice_id']; ?>" class="edit-button" title="Edit the Invoice"><i class="ri-pencil-line" title="Edit the Invoice"></i></a>&nbsp;

View File

@ -57,10 +57,11 @@
<div class="card-body">
<form action="<?= base_url('pay') ?>" method="post">
<div class="form-group">
<label for="CustomerID">Subscription ID</label>
<input type="text" value="<?= isset($subscriptionID) && ($subscriptionID != null) ? $subscriptionID : '' ?>" class="form-control" id="CustomerID" name="CustomerID" placeholder="Enter your Subscription ID" required>
<label for="membership_id">Membership ID</label>
<input type="text" value="<?= isset($membership_id) && ($membership_id != null) ? $membership_id : '' ?>" class="form-control" id="membership_id" name="membership_id" placeholder="Enter your Membership ID" required>
</div>
<input type="hidden" name = 'amount' value = 1500>
<input type="hidden" name = 'amount' value = 1>
<input type="hidden" id="CustomerID" name = 'CustomerID' value = <?=isset($CustomerID)? $CustomerID['customer_id']: '' ?>>
<!-- Customer Information Section (Hidden Initially) -->
<div id="customerInfo" class="hidden-details d-none">
<div>
@ -97,13 +98,13 @@
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script>
<?php
if (isset($subscriptionID)){?>
if (isset($membership_id)){?>
$(document).ready(function(){
var customerID = $('#CustomerID').val();
var membership_id = $('#membership_id').val();
$.ajax({
type: 'POST',
url: "<?= base_url('/subscription_renewal') ?>",
data: {customerID: customerID},
data: {membership_id: membership_id},
dataType: 'json',
success: function(response) {
if (response.customer_details) {
@ -118,7 +119,7 @@
response.customer_details.country
].filter(Boolean).join(', ')
);
console.log("Customer Details received");
// Display customer information
$('#customerInfo').removeClass('d-none');
@ -147,12 +148,12 @@
});
<?php } ?>
$(document).ready(function(){
$('#CustomerID').on('change', function(){
var customerID = $(this).val();
$('#membership_id').on('change', function(){
var membership_id = $(this).val();
$.ajax({
type: 'POST',
url: "<?= base_url('/subscription_renewal') ?>",
data: {customerID: customerID},
data: {membership_id: membership_id},
dataType: 'json',
success: function(response) {
if (response.customer_details) {
@ -169,20 +170,23 @@
);
// Display customer information
$('#customerInfo').removeClass('d-none');
$('#CustomerID').val(response.CustomerID.customer_id);
if (response.scheme) {
// Calculate expiration
var date = new Date();
var remaining = new Date(response.scheme.to_subscription);
var remainingDays = Math.ceil((remaining - date) / (1000 * 60 * 60 * 24));
console.log(response.scheme.to_subscription);
var expirationMessage = '';
if (remainingDays > 0) {
expirationMessage = 'Your Subscription plan "' + response.scheme.short_code + '" is going to expire in ' + remainingDays +
' days on ' + remaining.toLocaleDateString('en-GB') + '.';
} else {
} else if (remainingDays < 0) {
remainingDays = Math.abs(remainingDays);
expirationMessage = 'Your Subscription plan "' + response.scheme.short_code + '" has already expired ' + remainingDays +
' days ago on ' + remaining.toLocaleDateString('en-GB') + '.';
}else{
}
$('#expirationMessage').text(expirationMessage);
}

View File

@ -315,26 +315,40 @@ class Query implements QueryInterface
* Match bindings
*/
protected function matchNamedBinds(string $sql, array $binds): string
{
$replacers = [];
{
$replacers = [];
foreach ($binds as $placeholder => $value) {
// $value[1] contains the boolean whether should be escaped or not
foreach ($binds as $placeholder => $value) {
// Check if the value is an object
if (is_object($value[0])) {
// If it's an object, extract a property or handle conversion manually
// For example, you could use $value[0]->id or $value[0]->amount
// Choose which property you want to use or convert to a string
$escapedValue = $value[1] ? $this->db->escape($value[0]->id) : $value[0]->id;
} else {
// If it's not an object, just escape the value normally
$escapedValue = $value[1] ? $this->db->escape($value[0]) : $value[0];
// In order to correctly handle backlashes in saved strings
// we will need to preg_quote, so remove the wrapping escape characters
// otherwise it will get escaped.
if (is_array($value[0])) {
$escapedValue = '(' . implode(',', $escapedValue) . ')';
}
$replacers[":{$placeholder}:"] = $escapedValue;
}
return strtr($sql, $replacers);
// Handle array values separately (e.g., implode them into a string)
if (is_array($value[0])) {
$escapedValue = '(' . implode(',', $escapedValue) . ')';
}
// Store the placeholder and the escaped value
$replacers[":{$placeholder}:"] = $escapedValue;
}
// Replace named placeholders with their corresponding escaped values using str_replace
foreach ($replacers as $placeholder => $escapedValue) {
$sql = str_replace($placeholder, $escapedValue, $sql);
}
return $sql;
}
/**
* Match bindings
*/