diff --git a/app/Controllers/Invoice.php b/app/Controllers/Invoice.php index d7f60f53..95c21b1c 100755 --- a/app/Controllers/Invoice.php +++ b/app/Controllers/Invoice.php @@ -390,7 +390,6 @@ class Invoice extends BaseController // Handle invoice creation or update $invoice_id = $this->create_or_update_invoice($invoice_id, $msg_flag_name); - // Handle invoice items creation or update $this->create_or_update_invoice_items($invoice_id); $update_invoice_numbering = [ @@ -433,17 +432,20 @@ public function create_or_update_invoice($invoice_id, $msg_flag_name) $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); + if($data['status'] == 'Approved'){ + session()->setFlashdata('success', $msg_flag_name . 'has been added successfully.'); + $this->logger->info($msg_flag_name . ": Added successfully. ID = " . $invoice_id); + }else{ + session()->setFlashdata('success',$msg_flag_name . 'has been added to draft successfully'); + } + } else { session()->setFlashdata('error', $msg_flag_name . 'could not be added. Please try again.'); $this->logger->error($msg_flag_name . ": Could not be added."); @@ -535,22 +537,14 @@ public function create_or_update_subscription($invoice_id,$invoice_status, $msg_ $to_sub_date = $item['to_subscription']; //check if membership id is already set for the customer - $membership = $subModel->check_existing_membership_id($customer_id); - //dd($membership); - if (count($membership)>0){ - $member = (array)$membership[0]; - //dd($member); - $membership_id = $member['membership_id']; - //dd($membership_id); - } - else{ + $membership_id = $this->generate_membership_id(6); // To check if the generated membership is already created for another customer $result = $subModel->where('membership_id',$membership_id)->findAll(); if (count($result)>0){ $membership_id = $this->generate_membership_id(6); } - } + // Prepare subscription data $subscription_data = [ @@ -943,7 +937,8 @@ public function create_or_update_subscription($invoice_id,$invoice_status, $msg_ $htmlFooter = '
'; - $mpdf->setHTMLFooter($htmlFooter); + $mpdf->setHTMLFooter($htmlFooter); + // Generate the PDF content (HTML) @@ -1201,7 +1196,13 @@ public function create_or_update_subscription($invoice_id,$invoice_status, $msg_ $this->logger->info("Itemwise Report "); } $this->logger->info("'Membership Renewals Report'"); - $data['page_name'] = 'Membership Renewals Report'; + if (empty($data['selected_data'])){ + //dd($data['selected_data']); + $data['page_name'] = 'Membership Renewals Report (30 days)'; + }else{ + list($fromDate, $toDate) = explode(" - ", $data['selected_data']); + $data['page_name'] = 'Membership Renewals Report -
(From '.$fromDate.' To '.$toDate.')'; + } $this->render_page('report_expired_customers', $data); } @@ -1286,6 +1287,7 @@ public function create_or_update_subscription($invoice_id,$invoice_status, $msg_ $data['selected_data'] = $this->request->getVar('date'); } $data['page_name'] = 'Received Payments Report'; + log_message('info',json_encode($data)); $this->render_page('received_payments_report',$data); } public function itemwise_report_with_payment_method(){ @@ -1309,8 +1311,7 @@ public function create_or_update_subscription($invoice_id,$invoice_status, $msg_ } $data['page_name'] = 'Sales By Books'; - // var_dump($data); - // die(); + // dd($data); $this->render_page('itemwise_report_with_payment_method',$data); } @@ -1586,7 +1587,6 @@ public function create_or_update_subscription($invoice_id,$invoice_status, $msg_ $product_id =(int)$requestData['item_details'][$x]; $from_sub_date = \DateTime::createFromFormat('d/m/Y', $requestData['from_subscription'])->format('Y-m-d'); $to_sub_date = \DateTime::createFromFormat('d/m/Y', $requestData['to_subscription'])->format('Y-m-d'); - $subscription_data = [ 'customer_id' => $customer_id, 'invoice_id' => $invoice_id, @@ -1616,7 +1616,7 @@ public function create_or_update_subscription($invoice_id,$invoice_status, $msg_ $response['subscription']['message'] = 'Subscription There Is No Changes to Updated'; } $response['success'] = true; - $response['message'] = "Successfully Updation"; + $response['message'] = "Successfully Updated"; } catch (\Exception $e) { $response['success'] = false; $response['message'] = 'Error: ' . $e->getMessage(); diff --git a/app/Controllers/Payment.php b/app/Controllers/Payment.php index 7abf990e..1421329d 100644 --- a/app/Controllers/Payment.php +++ b/app/Controllers/Payment.php @@ -74,10 +74,10 @@ class Payment extends BaseController { $userAgent = $_SERVER['HTTP_USER_AGENT']; $payment_method = preg_match('/mobile/i', $userAgent) ? "mobile" : 'website'; - + $data = $_POST; $paramList = array(); $CUST_ID = (string) $this->request->getPost("CustomerID"); - $ORDER_ID = (string) uniqid($CUST_ID . "_"); + $ORDER_ID = (string) $this->request->getPost("membership_id"); $CHANNEL_ID = ($payment_method == "mobile") ? (string) env('Channel_ID_Mobile') : (string) env('Channel_ID_WEB'); $TXN_AMOUNT = (string) $this->request->getPost("amount"); @@ -161,12 +161,15 @@ 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]; + $past_membership_id = $this->request->getVar('ORDERID'); + $payment_method = $this->request->getVar('PAYMENTMODE'); + $subModel = new SubscriptionModel(); + $customer = $subModel->select('customer_id')->where('membership_id',$past_membership_id)->first(); + $customer_id = $customer['customer_id']; + //dd($past_membership_id); + // $parts = explode('_', $ORDER_ID); + // $customer_id = (int)$parts[0]; $currentDate = date('Y-m-d'); - - // Assuming the model is used for database interactions $bookModel = new BooksModel(); $model = new InvoiceModel(); $db = \Config\Database::connect(); @@ -196,9 +199,11 @@ public function payment_success() { 'sub_total' => $amount, 'exact_total_amount' => $amount, 'grand_total' => $amount, + 'total_amount' => $amount, 'invoice_date' => $currentDate, 'billing_address'=> $address['address_1'], - 'billing_address_id' => isset($address['customer_address_id']) ? $address['customer_address_id'] : '' + 'billing_address_id' => isset($address['customer_address_id']) ? $address['customer_address_id'] : '', + 'payment_method' => $payment_method, ]; $model->save($data); $update_invoice_numbering = [ @@ -211,10 +216,20 @@ public function payment_success() { // var_dump($update_invoice_numbering);die(); $save_invoice = new Invoice(); $save_invoice->update_number_formatting($update_invoice_numbering); + //get the invoice id to insert into the invoiceitems table $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))); + $previous_to_sub = $subModel->select('to_subscription')->where('customer_id',$customer_id)->where('membership_id',$past_membership_id)->first(); + $new_subscription_date = $previous_to_sub['to_subscription']; + // Create a DateTime object from the existing subscription date + $date = new \DateTime($new_subscription_date); + + // Add one day + $date->add(new \DateInterval('P1D')); + + // Format the date (optional, if you need it in a specific format) + $fsubscription = $date->format('Y-m-d'); + $tsubscription = date('Y-m-d', strtotime('+1 year', strtotime($fsubscription))); $data['item_details'] = 3; $requestData = [ 'invoice_id' =>$invoice_id['invoice_id'], @@ -224,12 +239,15 @@ public function payment_success() { 'created_on'=>$currentDate, 'isactive'=>1, 'from_subscription' =>$fsubscription, - 'to_subscription' =>$tsubscription + 'to_subscription' =>$tsubscription, + ]; $invoice = new Invoice(); $db->table('invoiceitems')->insert($requestData); $model3 = new SubscriptionModel(); - $membership_id = $model3->select('membership_id')->where('customer_id',$customer_id)->first(); + $invoiceController = new Invoice(); + $membership_id = $invoiceController->generate_membership_id(6); + //$membership_id = $model3->select('membership_id')->where('customer_id',$customer_id)->first(); // if ($membership_id<=0){ // $membership_id = $invoice->generate_membership_id(6); // } @@ -242,7 +260,7 @@ public function payment_success() { 'is_renew' => 1, 'business_id'=>2, 'status' =>1, - 'membership_id' =>$membership_id['membership_id'] + 'membership_id' =>$membership_id ]; $db->table('subscription')->insert($subscriptionData); diff --git a/app/Controllers/Subscription.php b/app/Controllers/Subscription.php index dcf7b9b1..5325bb1e 100755 --- a/app/Controllers/Subscription.php +++ b/app/Controllers/Subscription.php @@ -31,11 +31,11 @@ class Subscription extends BaseController $data['invoice'] = $model->getSubscriptionInvoiceDetail($where); $this->logger->info("Invoice: Listing Count ." . count($data['invoice'])); - + $data['active_schemes'] = $model->getActiveSchemes(); // $data['subscriber'] = $SubscriptionModel->where($where)->findAll();; - + //dd($data); $SubscriptionModel = new SubscriptionModel(); $swhere = ['subscription.business_id' => (int)$session_bid]; $data['subscriber'] = $SubscriptionModel->getAllSubscribersWithNames($swhere); @@ -174,7 +174,7 @@ public function download_details_by_hema() $details =$subscriptionModel->getBothDetailsSchemeName($selectedScheme); } - + $customerDetails = array_merge($customerDetails, $details); } diff --git a/app/Models/InvoiceModel.php b/app/Models/InvoiceModel.php index 5dc2a705..70e3deb3 100755 --- a/app/Models/InvoiceModel.php +++ b/app/Models/InvoiceModel.php @@ -666,8 +666,28 @@ public function getPaymentReport($f_date = null, $t_date = null) $builder->where('invoice.invoice_date >=', $f_date) ->where('invoice.invoice_date <=', $t_date); } + $builder->where('invoice.status','Approved'); $query = $builder->get(); - $results = $query->getResultArray(); + $result1 = $query->getResultArray(); + $builder->select('payment_method, SUM(exact_total_amount) as total_amount'); + if ($f_date !== null && $t_date !== null) { + $builder->where('invoice.invoice_date >=', $f_date) + ->where('invoice.invoice_date <=', $t_date); + } + $builder->groupBy('payment_method'); + $query2 = $builder->get(); + $paymentMethodTotals = $query2->getResultArray(); + $paymentMethodMap = []; +foreach ($paymentMethodTotals as $row) { + $paymentMethodMap[$row['payment_method']] = $row['total_amount']; +} + $result2 = $paymentMethodMap; +// log_message('info',json_encode($results)); +// dd($results); + $results = [ + 'result1'=>$result1, + 'result2'=>$result2 + ]; return $results; } public function itemwise_report_data_with_payment_method($f_date = null, $t_date = null) @@ -769,6 +789,19 @@ public function updateInvoiceCancelStatus($invoiceIds, $cancelReason) return $updated; } +public function getActiveSchemes(){ + $builder = $this->db->table($this->table.' as I' ); + $builder->select('books.short_code'); + $builder->join('subscription','subscription.invoice_id = I.invoice_id'); + $builder->join('invoiceitems','invoiceitems.invoice_id = I.invoice_id'); + $builder->join('books','invoiceitems.product = books.book_id'); + $builder->groupBy('short_code'); + + $query = $builder->get(); + $results = $query->getResultArray(); + + return $results; +} diff --git a/app/Models/SubscriptionModel.php b/app/Models/SubscriptionModel.php index 8966b6b1..139e4fda 100755 --- a/app/Models/SubscriptionModel.php +++ b/app/Models/SubscriptionModel.php @@ -91,7 +91,7 @@ public function getAllCustomerDetailsBySchemeName($schemeName) // echo "addresses - Customer"; $currentDate = date('Y-m-d'); $builder = $this->db->table('subscription'); - $builder->select('customers.customer_id, CONCAT(customers.first_name, " ", customers.last_name) as customer_name,customer_addresses.mobile_no, customer_addresses.address_1,customer_addresses.address_2, customer_addresses.city, customer_addresses.state, customer_addresses.postal_code,business.title as business_name,business.address as business_address,business.city as business_city,business.state as business_state,business.postal_code as business_postal_code,books.title,from_subscription,to_subscription,business.title as business_name,business.mobile_no as business_mobile_no,states.state_name'); + $builder->select('customers.customer_id, CONCAT(customers.first_name, " ", customers.last_name) as customer_name,customer_addresses.mobile_no, customer_addresses.address_1,customer_addresses.address_2, customer_addresses.city, customer_addresses.state, customer_addresses.postal_code,business.title as business_name,business.address as business_address,business.city as business_city,business.state as business_state,business.postal_code as business_postal_code,books.title,from_subscription,to_subscription,business.title as business_name,business.mobile_no as business_mobile_no,states.state_name','subscription.membership_id'); $builder->join('customers', 'customers.customer_id = subscription.customer_id'); $builder->join('customer_addresses', 'customer_addresses.customer_id = customers.customer_id AND customer_addresses.address_type = 2','left'); $builder->join('business', 'business.business_id = subscription.business_id'); @@ -162,7 +162,7 @@ public function getAllExpiredCustomerDetailsByScheme($schemeName) $currentDate = date('Y-m-d'); $builder = $this->db->table('subscription'); - $builder->select('customers.customer_id, CONCAT(customers.first_name, " ", customers.last_name) as customer_name, customer_addresses.mobile_no, customer_addresses.address_1, customer_addresses.address_2, customer_addresses.city, customer_addresses.state, customer_addresses.postal_code, business.title as business_name, books.title, from_subscription, to_subscription, business.mobile_no as business_mobile_no, states.state_name'); + $builder->select('customers.customer_id, CONCAT(customers.first_name, " ", customers.last_name) as customer_name, customer_addresses.mobile_no, customer_addresses.address_1, customer_addresses.address_2, customer_addresses.city, customer_addresses.state, customer_addresses.postal_code, business.title as business_name, books.title, from_subscription, to_subscription, business.mobile_no as business_mobile_no, states.state_name','subscription.membership_id'); $builder->join('customers', 'customers.customer_id = subscription.customer_id'); $builder->join('customer_addresses', 'customer_addresses.customer_id = customers.customer_id And customer_addresses.address_type = 2','left'); $builder->join('business', 'business.business_id = subscription.business_id'); @@ -227,7 +227,7 @@ public function getQueryforSubscriptionDetailsBySchemeName($flag,$condition, $va $builder->select(" CONCAT_WS(' ', c.first_name, c.last_name) as customer_name, c.customer_id, c.mobile_no, c.email, DATEDIFF(s.to_subscription, CURDATE()) AS remaining_days, - s.from_subscription, s.to_subscription, s.scheme_id, bs.title, s.membership_id,s.sub_id, + s.from_subscription, s.to_subscription, s.scheme_id, bs.title, s.membership_id,s.sub_id,bs.title, i.invoice_id, i.invoice_date, i.shipping_address_id, ca.customer_address_id, ca.address_1, ca.address_2, ca.city, ca.state, ca.postal_code, ca.address_type, st.state_name, b.title as business_name, b.address as business_address, b.city as business_city, @@ -294,6 +294,7 @@ public function getQueryforSubscriptionDetailsBySchemeName($flag,$condition, $va 'invoice_id' => $row['invoice_id'], 'invoice_date' => $row['invoice_date'], 'customer_name' => $row['customer_name'], + 'membership_id' =>$row['membership_id'], 'from_subscription' => $row['from_subscription'], 'address_1' => $row['address_1'], 'address_2' => $row['address_2'], @@ -365,6 +366,7 @@ public function getQueryforSubscriptionDetailsBySchemeName($flag,$condition, $va $builder = $this->db->table('subscription'); $builder->select('membership_id'); $builder->where('customer_id', $customer_id); + $builder->where('isactive',1); $builder->orderBy('sub_id', 'DESC'); $builder->limit(1); $output = $builder->get()->getResult(); diff --git a/app/Views/invoice_form.php b/app/Views/invoice_form.php index c70b250e..8a744bb9 100755 --- a/app/Views/invoice_form.php +++ b/app/Views/invoice_form.php @@ -1570,7 +1570,7 @@ if (isset($invoice_item_details[0]['to_subscription']) && !empty($invoice_item_d $(".subscribedetails").show(); // Change this line to use the class selector let message = "No Earlier Membership found"; //$("#schemeName").text(message); - // showAlert(message); // kannan sir tolded no membership founded means don't show the alert dated on 21/nov/2024 evening + //showAlert(message) } }, error: function() { diff --git a/app/Views/invoice_pdf_template.php b/app/Views/invoice_pdf_template.php index 1d3e70a0..fdc850cd 100755 --- a/app/Views/invoice_pdf_template.php +++ b/app/Views/invoice_pdf_template.php @@ -198,15 +198,15 @@ BILLING TO :
customer_biller_name) && trim($value->customer_biller_name) !== '' ? $value->customer_biller_name : $value->customer_name ?>
customer_bill_address && ($value->baddr_id !== null || $value->baddr_id !== '')) { ?> - customer_bill_address ? $value->customer_bill_address . " ," : "" ?>
+ customer_bill_address ? $value->customer_bill_address . "," : "" ?>
customer_bill_city ? $value->customer_bill_city : "" ?> customer_bill_state ? $value->customer_bill_state : "" ?> customer_bill_postal_code ? " - " . $value->customer_bill_postal_code : ""; ?> customer_bill_country ? $value->customer_bill_country . "." : $value->bcountry ?>
baddr_id === null || $value->baddr_id === '') { echo $value->billing_address ? '

' . $value->billing_address . '

' : ''; } ?> - bmobile ? "Phone : +91" . $value->bmobile . " ." : ($value->mobile_no ? "Phone : +91" . $value->mobile_no . " ." : "") ?>
- bemail ? "Email : " . $value->bemail . " ." : ($value->email ? "Email : " . $value->email . " ." : "" ) ?> + bmobile ? "Phone : +91" . $value->bmobile . "." : ($value->mobile_no ? "Phone : +91" . $value->mobile_no . "." : "") ?>
+ bemail ? "Email : " . $value->bemail . "." : ($value->email ? "Email : " . $value->email . "." : "" ) ?> @@ -215,15 +215,15 @@ SHIPPING TO :
customer_shipper_name) && trim($value->customer_shipper_name) !== '' ? $value->customer_shipper_name : $value->customer_name ?>
customer_ship_address && ($value->saddr_id !== null || $value->saddr_id !== '')) { ?> - customer_ship_address ? $value->customer_ship_address . " ," : "" ?>
+ customer_ship_address ? $value->customer_ship_address . "," : "" ?>
customer_ship_city ? $value->customer_ship_city : "" ?> customer_ship_state ? $value->customer_bill_state : "" ?> customer_ship_postal_code ? " - " . $value->customer_ship_postal_code : ""; ?> customer_ship_country ? $value->customer_ship_country . "." : $value->scountry ?>
saddr_id === null || $value->saddr_id === '') { echo $value->shipping_address ? '

' . $value->shipping_address . '

' : ''; } ?> - smobile ? "Phone : +91" . $value->smobile . " ." : "" ?>
- semail ? "Email : " . $value->semail . " ." : "" ?> + smobile ? "Phone : +91" . $value->smobile . "." : "" ?>
+ semail ? "Email : " . $value->semail . "." : "" ?> diff --git a/app/Views/itemwise_report_with_payment_method.php b/app/Views/itemwise_report_with_payment_method.php index 4ca7a9b3..c7099b3d 100644 --- a/app/Views/itemwise_report_with_payment_method.php +++ b/app/Views/itemwise_report_with_payment_method.php @@ -48,7 +48,7 @@ book_name ?> item_count ?> total_cost, 2) ?> - payment_method ?> + payment_method) ?> diff --git a/app/Views/print_addresses_form.php b/app/Views/print_addresses_form.php index 6879853b..f797b885 100755 --- a/app/Views/print_addresses_form.php +++ b/app/Views/print_addresses_form.php @@ -67,9 +67,11 @@
- - -
+ + + +
+ ,
,
diff --git a/app/Views/received_payments_report.php b/app/Views/received_payments_report.php index 8d54057a..ef94f2d6 100644 --- a/app/Views/received_payments_report.php +++ b/app/Views/received_payments_report.php @@ -1,11 +1,48 @@ - -
-
-
-

+ + +
+
+
+

+
-
-
+ +
@@ -18,9 +55,48 @@
+
+
+ +
+
+
+ +
@@ -38,20 +114,29 @@ - + + - + - + + + + - + + Total Amount + +
@@ -60,88 +145,89 @@
- - - - - + + + + \ No newline at end of file + \ No newline at end of file diff --git a/app/Views/report_expired_customers.php b/app/Views/report_expired_customers.php index a74eff08..10d9f56a 100755 --- a/app/Views/report_expired_customers.php +++ b/app/Views/report_expired_customers.php @@ -1,6 +1,6 @@
-
+

diff --git a/app/Views/report_general_invoice.php b/app/Views/report_general_invoice.php index 64756a52..01a28cda 100755 --- a/app/Views/report_general_invoice.php +++ b/app/Views/report_general_invoice.php @@ -73,7 +73,7 @@ item_count; ?> invoice_type == 1) ? 'Book' : 'Membership'; ?> status; ?> - payment_method; ?> + payment_method); ?> discount, 2, '.', ','); ?> shipping_charge, 2, '.', ','); ?> tax ? $row->tax : '0.00'; ?> diff --git a/app/Views/report_userwise_and_eventwise.php b/app/Views/report_userwise_and_eventwise.php index 8d80c850..b56c172a 100644 --- a/app/Views/report_userwise_and_eventwise.php +++ b/app/Views/report_userwise_and_eventwise.php @@ -48,7 +48,7 @@ - + diff --git a/app/Views/subscribers_list.php b/app/Views/subscribers_list.php index 6aee1e6e..5a0bf486 100755 --- a/app/Views/subscribers_list.php +++ b/app/Views/subscribers_list.php @@ -136,16 +136,23 @@ // foreach ($subscriber as $scheme) : // if (!in_array($scheme['title'], $uniqueSchemes)) { // $uniqueSchemes[] = $scheme['title']; + //log_message('info',json_encode($membershipbooks)); if (!empty($membershipbooks)) : + if(!empty($active_schemes)): foreach ($membershipbooks as $scheme) : + foreach($active_schemes as $active): + if ($scheme->short_code == $active['short_code']): ?>
- +
diff --git a/app/Views/subscription_renewal.php b/app/Views/subscription_renewal.php index f38479ff..7f6465a5 100644 --- a/app/Views/subscription_renewal.php +++ b/app/Views/subscription_renewal.php @@ -34,7 +34,7 @@ } .subscription-status { font-size: 0.85rem; - color: #6c757d; + } .hidden-details { margin-top: 10px; @@ -50,6 +50,9 @@
+

Subscription Renewal

@@ -57,7 +60,7 @@
- +
@@ -91,7 +94,7 @@