diff --git a/app/Config/Routes.php b/app/Config/Routes.php
index ab3447ce..aae2854b 100755
--- a/app/Config/Routes.php
+++ b/app/Config/Routes.php
@@ -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');
diff --git a/app/Controllers/Invoice.php b/app/Controllers/Invoice.php
index 2bfee999..5db9e0d1 100755
--- a/app/Controllers/Invoice.php
+++ b/app/Controllers/Invoice.php
@@ -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 "
";
+ // // 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 "";
- // 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 "
....................";
+ //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);
diff --git a/app/Controllers/Notifications.php b/app/Controllers/Notifications.php
index b1860ebe..bd244e0f 100755
--- a/app/Controllers/Notifications.php
+++ b/app/Controllers/Notifications.php
@@ -603,6 +603,7 @@ class Notifications extends BaseController
$emailTemplateName = $NotificationModel->getTempName(EXPIRAY_NOTIFY_TEMPLATE_EMAIL);
echo "Started.
Dated = ".$newDate."
There are ".count($queryResult)." persons
";
+ //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);
}
diff --git a/app/Controllers/Payment.php b/app/Controllers/Payment.php
index 03cee08c..3451e61f 100644
--- a/app/Controllers/Payment.php
+++ b/app/Controllers/Payment.php
@@ -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 "Transaction status is success
";
- return redirect()->to(base_url('/payment_success'));
+
+ return redirect()->to(base_url('/payment_success?' . $queryString));
} else {
echo "Processing ...
";
- return redirect()->to(base_url('/payment_failure'));
-
- }
+ $queryString = http_build_query($paramList);
+ return redirect()->to(base_url('/payment_failure?' . $queryString));
+ }
} else {
- echo "Checksum mismatched.";
+ 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 "
";
+print_r($checkSum);
+}
}
diff --git a/app/Models/InvoiceModel.php b/app/Models/InvoiceModel.php
index cb88c6a7..84437ed1 100755
--- a/app/Models/InvoiceModel.php
+++ b/app/Models/InvoiceModel.php
@@ -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";
diff --git a/app/Models/SubscriptionModel.php b/app/Models/SubscriptionModel.php
index 03856096..f89fd459 100755
--- a/app/Models/SubscriptionModel.php
+++ b/app/Models/SubscriptionModel.php
@@ -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;
diff --git a/app/Models/TransactionModel.php b/app/Models/TransactionModel.php
new file mode 100644
index 00000000..340c4f83
--- /dev/null
+++ b/app/Models/TransactionModel.php
@@ -0,0 +1,9 @@
+= $startDate && $startDateTime <= $endDate) {
echo $startDateTime ;
}
diff --git a/app/Views/received_payments_report.php b/app/Views/received_payments_report.php
index 7a34123f..0173f488 100644
--- a/app/Views/received_payments_report.php
+++ b/app/Views/received_payments_report.php
@@ -30,24 +30,24 @@
| Invoice ID |
- Customer Name |
- Total Amount |
- Payment Status |
- Payment Method |
Invoice Date |
+ Customer Name |
+ Payment Method |
+ Payment Status |
+ Total Amount |
|
- = $row['first_name'] ?> |
- = $row['total_amount'] ?> |
- = $row['payment_status'] ?> |
- = $row['payment_method']?> |
+ $invoice_date = date("d/m/Y", $unixTime);?>
= $invoice_date ?> |
+ = $row['first_name'] ?> |
+ = $row['payment_method']?> |
+ = $row['payment_status'] ?> |
+ = $row['total_amount'] ?> |
diff --git a/app/Views/report_book_publish.php b/app/Views/report_book_publish.php
index fe257600..56644345 100755
--- a/app/Views/report_book_publish.php
+++ b/app/Views/report_book_publish.php
@@ -40,11 +40,11 @@
| id |
+ Inv Date |
Book Name |
Author |
- Cost |
Published By |
- Inv Date |
+ Cost |
@@ -53,11 +53,11 @@
| invoice_id; ?> |
+ invoice_date)) ?> |
title; ?> |
- publisher; ?> |
- price ?> |
+ author; ?> |
publishers_code?> |
- invoice_date)) ?> |
+ price ?> |
diff --git a/app/Views/report_general_invoice.php b/app/Views/report_general_invoice.php
index f3b50f4f..30dbf33d 100755
--- a/app/Views/report_general_invoice.php
+++ b/app/Views/report_general_invoice.php
@@ -34,10 +34,9 @@
-
-
-
-
+
+
+
@@ -46,14 +45,17 @@
| Invoice No |
Invoice Date |
Customer Name |
- GST |
- Discount |
Count |
- OT Charges |
- Total |
+ Invoice Type |
Status |
- Type of Invoice |
Payment |
+ Discount (₹) |
+ OT Charges (₹) |
+ GST (%) |
+ Total (₹) |
+
+
+
@@ -65,14 +67,15 @@
invoice_number; ?> |
formatted_invoice_date; ?> |
first_name . " " . $row->last_name; ?> |
- tax ? $row->tax . '%' : '0%'; ?> |
- discount, 2, '.', ','); ?> |
item_count; ?> |
- shipping_charge, 2, '.', ','); ?> |
- total_amount, 2, '.', ','); ?> |
+ invoice_type == 1) ? 'Book' : 'Membership'; ?> |
status; ?> |
- invoice_type == 1) ? 'Book Invoice' : 'Membership Invoice'; ?> |
payment_method; ?> |
+ discount, 2, '.', ','); ?> |
+ shipping_charge, 2, '.', ','); ?> |
+ tax ? $row->tax : '0.00'; ?> |
+ total_amount, 2, '.', ','); ?> |
+
diff --git a/app/Views/report_itemwise.php b/app/Views/report_itemwise.php
index 24a6ddd2..ff26e960 100755
--- a/app/Views/report_itemwise.php
+++ b/app/Views/report_itemwise.php
@@ -56,26 +56,27 @@