FIX_INVOICE_ORDER_IN_REPORTS

This commit is contained in:
Srinivas-Saravanan 2025-03-07 16:02:22 +05:30
parent b61e133a6d
commit a85a43f69c
6 changed files with 848 additions and 834 deletions

View File

@ -1,4 +1,5 @@
<?php
namespace App\Models;
use App\Controllers\Books;
@ -7,64 +8,67 @@ use CodeIgniter\Model;
class InvoiceModel extends Model
{
protected $table = 'invoice';
protected $primaryKey = 'invoice_id';
// protected $allowedFields = ['invoice_id','invoice_number','customer_id','invoice_date','event_id','business_id','created_on','business_id'];
protected $allowedFields = ['invoice_id', 'invoice_number', 'customer_id','notes', 'invoice_date', 'due_date', 'subtotal', 'tax','dis_type', 'discount', 'shipping_charge','shipping_label','total_amount', 'payment_status', 'order_number','invoice_type', 'payment_method', 'event_id', 'business_id', 'shipping_address_id', 'billing_address_id', 'created_on', 'created_by', 'updated_on', 'updated_by','category','isactive','billing_address','shipping_address','status','payment_note','exact_total_amount'];
protected $table = 'invoice';
protected $primaryKey = 'invoice_id';
// protected $allowedFields = ['invoice_id','invoice_number','customer_id','invoice_date','event_id','business_id','created_on','business_id'];
protected $allowedFields = ['invoice_id', 'invoice_number', 'customer_id', 'notes', 'invoice_date', 'due_date', 'subtotal', 'tax', 'dis_type', 'discount', 'shipping_charge', 'shipping_label', 'total_amount', 'payment_status', 'order_number', 'invoice_type', 'payment_method', 'event_id', 'business_id', 'shipping_address_id', 'billing_address_id', 'created_on', 'created_by', 'updated_on', 'updated_by', 'category', 'isactive', 'billing_address', 'shipping_address', 'status', 'payment_note', 'exact_total_amount'];
public function saveInvoiceItemDetails($data){
public function saveInvoiceItemDetails($data)
{
$i = 0;
$statement = [];
foreach ($data as $row) {
$id = isset($row['invoice_child_id']) ? $row['invoice_child_id'] : '';
if($id != ''){
if ($id != '') {
unset($row['invoice_child_id']); // Remove the id from the data to avoid updating it
unset($row['created_by']); // bcoz here data are Updating here.
$this->db->table('invoiceitems')->where('invoice_child_id', $id)->update($row);// Update the row with the specified id
$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{
if (!empty($row['updated_by'])){
$statement[$i] = "Invoice Item - " . $id . " " . $affectedRows ? " Updated" : " Not Updated";
} 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";
$statement[$i] = "Invoice Item - " . $insertID . " Inserted";
}
}
return $statement;
}
}
public function inactiveMissingInvoiceItemDetails($where,$missingValues){
public function inactiveMissingInvoiceItemDetails($where, $missingValues)
{
$dataToUpdate = ['isactive' => 0];
$this->db->table('invoiceitems')->where($where)->whereIn('invoice_child_id',$missingValues)->update($dataToUpdate);
}
$this->db->table('invoiceitems')->where($where)->whereIn('invoice_child_id', $missingValues)->update($dataToUpdate);
}
public function deleteMissingInvoiceItemDetails($where, $missingValues) {
public function deleteMissingInvoiceItemDetails($where, $missingValues)
{
$this->db->table('invoiceitems')
->where($where)
->whereIn('invoice_child_id', $missingValues)
->delete();
}
}
public function updateData($table, $data, $where)
{
public function updateData($table, $data, $where)
{
$this->db->table($table)->update($data, $where);
$affected_rows = $this->db->affectedRows();
return $affected_rows;
}
}
public function InactiveSubscriptionDraftDetails($where,$update_by_id)
{
public function InactiveSubscriptionDraftDetails($where, $update_by_id)
{
$result = $this->getJoinedData($where);
$inactive_invoice_ids = array();
foreach ($result as $item) {
$inactive_invoice_ids[] = $item['invoice_id'];
}
if(count($inactive_invoice_ids)>0){
if (count($inactive_invoice_ids) > 0) {
$this->db->table('subscription')
->whereIn('invoice_id', $inactive_invoice_ids)
->set('isactive', 0)
@ -73,35 +77,36 @@ public function InactiveSubscriptionDraftDetails($where,$update_by_id)
}
return $inactive_invoice_ids;
}
}
public function deleteSubscriptionDraftDetails($where,$update_by_id)
{
public function deleteSubscriptionDraftDetails($where, $update_by_id)
{
$result = $this->getJoinedData($where);
$delete_invoice_ids = array();
foreach ($result as $item) {
$delete_invoice_ids[] = $item['invoice_id'];
}
if(count($delete_invoice_ids)>0){
if (count($delete_invoice_ids) > 0) {
$this->db->table('subscription')
->whereIn('invoice_id', $delete_invoice_ids)
->delete();
}
return $delete_invoice_ids;
}
}
## check the customer the scheme already Exist
public function existsSubscriptionDetails($where){
## check the customer the scheme already Exist
public function existsSubscriptionDetails($where)
{
$result = $this->getJoinedData($where);
if(count($result)>0){
if (count($result) > 0) {
return 1;
}else{
} else {
return 0;
}
}
}
public function getSubscriptionInvoiceDetail($where)
{
public function getSubscriptionInvoiceDetail($where)
{
$result = $this->getJoinedData($where);
// print_r($result);die;
if (!empty($result)) {
@ -113,7 +118,7 @@ public function getSubscriptionInvoiceDetail($where)
if (strtolower($child->category_name) == strtolower('Membership')) {
$schemes[] = [
'scheme_name' => $child->title,
'scheme_code' => !empty($child->short_code)?$child->short_code:$child->title,
'scheme_code' => !empty($child->short_code) ? $child->short_code : $child->title,
];
}
}
@ -124,12 +129,12 @@ public function getSubscriptionInvoiceDetail($where)
}
}
return $result;
}
}
public function getJoinedData($where, $orderby = [])
{
public function getJoinedData($where, $orderby = [])
{
// dd($where);
$query = $this->db->table($this->table.' as I' )
$query = $this->db->table($this->table . ' as I')
->join('customers as C', 'C.customer_id = I.customer_id', 'left')
->join('subscription as S', 'S.invoice_id = I.invoice_id', 'left')
->join('events as E', 'E.event_id = I.event_id', 'left')
@ -153,29 +158,32 @@ public function getJoinedData($where, $orderby = [])
//echo $this->db->getLastQuery();die;
return $resultArray;
}
}
## subscription_inactive
public function subscription_inactive(){
public function subscription_inactive()
{
$now = date('Y-m-d');
$result = $this->db->table('subscription as S')
->select('S.sub_id, S.scheme_id, S.customer_id, S.business_id,S.invoice_id,S.mode,S.from_subscription, S.to_subscription, S.is_renew, S.isactive')
->where("S.isactive",1)
->where("S.to_subscription < ",$now)
->where("S.isactive", 1)
->where("S.to_subscription < ", $now)
->get()
->getResultArray();
// echo "<pre>";print_r($result);echo "</pre>";die;
$returnMessages = [];$i = 0 ;$j = 0;
$returnMessages = [];
$i = 0;
$j = 0;
if (!empty($result)) {
foreach ($result as $row) {
// $this->db->table('invoiceitems')->where(['invoice_id' => $row['invoice_id']])->update(['from_subscription' => NULL,'to_subscription' => NULL]);//first child
$this->db->table('subscription')->where(['sub_id' => $row['sub_id']])->update(['isactive' => 0]);//second child
$this->db->table('subscription')->where(['sub_id' => $row['sub_id']])->update(['isactive' => 0]); //second child
$affectedRows = $this->db->affectedRows();
if ($affectedRows) {
$returnMessages['message'] = "Success for sub_id: " . $row['sub_id'];
$returnMessages['success_rating'] = $i++;
}else {
} else {
$returnMessages['message'] = 'Failed to update subscription with sub_id ' . $row['sub_id'] . '. No rows were affected.';
$returnMessages['error_rating'] = $j++;
}
@ -190,12 +198,12 @@ public function getJoinedData($where, $orderby = [])
public function getDetailForApproveNotifications($where)
{
$result = $this->getJoinedData($where);
if(!empty($result)){
if (!empty($result)) {
foreach ($result as $object) {
$invoiceId = $object['invoice_id'];
$items = $this->getInvoiceItems($invoiceId,'');
$items = $this->getInvoiceItems($invoiceId, '');
}
}else{
} else {
$items = [];
}
$data['invoice'] = $result;
@ -240,10 +248,10 @@ public function getJoinedData($where, $orderby = [])
// Fetch invoice data
return $this->db->table('invoice')
->where('invoice_id', $id)
->join('customers as C','C.customer_id= invoice.customer_id','left')
->join('business as B','B.business_id = invoice.business_id','left')
->join('customer_addresses as A','A.customer_address_id=invoice.billing_address_id AND A.address_type = 1','left')
->join('customer_addresses as S','S.customer_address_id=invoice.shipping_address_id AND S.address_type = 2','left')
->join('customers as C', 'C.customer_id= invoice.customer_id', 'left')
->join('business as B', 'B.business_id = invoice.business_id', 'left')
->join('customer_addresses as A', 'A.customer_address_id=invoice.billing_address_id AND A.address_type = 1', 'left')
->join('customer_addresses as S', 'S.customer_address_id=invoice.shipping_address_id AND S.address_type = 2', 'left')
->join('states', 'states.state_short_name = A.state AND A.country = "IN"', 'left')
->join('countries', 'countries.country_short_name = A.country', 'left')
->select('invoice.*,DATE_FORMAT(invoice.invoice_date, "%d/%m/%Y") AS formatted_invoice_date,DATE_FORMAT(invoice.due_date, "%d/%m/%Y") AS formatted_due_date ,CONCAT_WS(" ", C.first_name, C.last_name) as customer_name,C.mobile_no,C.email,A.address_1, A.address_2,A.postal_code,A.city, A.state,C.mobile_no as customer_mobile')
@ -254,10 +262,9 @@ public function getJoinedData($where, $orderby = [])
->select('CONCAT_WS(" ", S.first_name, S.last_name) as customer_shipper_name,concat(S.address_1," ", S.address_2) as customer_ship_address,S.postal_code as customer_ship_postal_code ,S.city as customer_ship_city, countries.country_name as customer_ship_country,S.country as scountry,S.state as sstate,S.customer_address_id as saddr_id,S.email as semail,S.mobile_no as smobile')
->get()
->getResult();
}
// this function Also Used For Approve Notification.
public function getInvoiceItems($id,$stringflag)
public function getInvoiceItems($id, $stringflag)
{
if ($stringflag == 'groupby') {
@ -308,7 +315,7 @@ public function getJoinedData($where, $orderby = [])
public function getProductImgs($productId)
{
$data = $this->db->table('book_images')
->where(['book_id' => $productId,'book_images.isactive'=>1])
->where(['book_id' => $productId, 'book_images.isactive' => 1])
// ->join('books as B', 'B.book_id = invoiceitems.product', 'left')
// ->join('book_images as BI', 'BI.book_id = invoiceitems.product', 'left')
->select('book_images.*')
@ -355,13 +362,13 @@ public function getJoinedData($where, $orderby = [])
return $data;
}
public function insertupdateSubscriptionData($data,$invoice_status)
{
public function insertupdateSubscriptionData($data, $invoice_status)
{
if (!empty($data)) {
$invoice_id = $data['invoice_id'];
$customer_id = $data['customer_id'];
$scheme_id = $data['scheme_id'];
$data['isactive'] = $invoice_status === 'Approved' ? 1 : 0 ;
$data['isactive'] = $invoice_status === 'Approved' ? 1 : 0;
$where = ['invoice_id' => $invoice_id]; // invoice id refer with srinivasan // initally invoice id, scheme id and customer id
$query = $this->db->table('subscription')->select('sub_id')->where($where)->get()->getRow();
@ -374,12 +381,12 @@ public function insertupdateSubscriptionData($data,$invoice_status)
}
}
return false;
}
}
// ***********************REPORT**********************
// ***********************REPORT**********************
public function get_general_invoice_data($f_date = null, $t_date = null)
{
public function get_general_invoice_data($f_date = null, $t_date = null)
{
// Fetch invoice data
$query = $this->db->table('invoice')
->select('invoice.*,DATE_FORMAT(invoice.invoice_date, "%d/%m/%Y") AS formatted_invoice_date, customers.*, COUNT(invoiceitems.product) as item_count')
@ -402,11 +409,11 @@ public function get_general_invoice_data($f_date = null, $t_date = null)
->getResult();
return $result;
}
}
public function get_mem_invoice_data($f_date = null, $t_date = null)
{
public function get_mem_invoice_data($f_date = null, $t_date = null)
{
// Fetch invoice data
$query = $this->db->table('invoice')
->select('invoice.*, customers.*, COUNT(invoiceitems.product) as item_count,DATE_FORMAT(invoice.invoice_date, "%d/%m/%Y") AS formatted_invoice_date,subscription.from_subscription,subscription.to_subscription,DATE_FORMAT(subscription.from_subscription, "%d/%m/%Y") AS formatted_from_date,DATE_FORMAT(subscription.to_subscription, "%d/%m/%Y") AS formatted_to_date')
@ -429,40 +436,39 @@ public function get_mem_invoice_data($f_date = null, $t_date = null)
->getResult();
return $result;
}
}
// public function itemwise_report_data($f_date = null, $t_date = null)
// {
// // Fetch invoice data
// $query = $this->db->table('invoice')
// ->select('invoice.*, books.* , COUNT(invoiceitems.product) as item_count , sum(invoiceitems.product * invoiceitems.unit_price) as item_cost')
// ->where('invoice.isactive', 1)
// ->where('books.isactive', 1);
// public function itemwise_report_data($f_date = null, $t_date = null)
// {
// // Fetch invoice data
// $query = $this->db->table('invoice')
// ->select('invoice.*, books.* , COUNT(invoiceitems.product) as item_count , sum(invoiceitems.product * invoiceitems.unit_price) as item_cost')
// ->where('invoice.isactive', 1)
// ->where('books.isactive', 1);
// // Add date range filter if provided
// if ($f_date !== null && $t_date !== null) {
// $query->where('invoice.invoice_date >=', $f_date)
// ->where('invoice.invoice_date <=', $t_date);
// }
// // Add date range filter if provided
// if ($f_date !== null && $t_date !== null) {
// $query->where('invoice.invoice_date >=', $f_date)
// ->where('invoice.invoice_date <=', $t_date);
// }
// $result = $query->join('invoiceitems', 'invoiceitems.invoice_id = invoice.invoice_id', 'left')
// ->join('books', 'books.book_id = invoiceitems.product', 'left')
// ->groupBy('books.book_id')
// ->get()
// ->getResult();
// $result = $query->join('invoiceitems', 'invoiceitems.invoice_id = invoice.invoice_id', 'left')
// ->join('books', 'books.book_id = invoiceitems.product', 'left')
// ->groupBy('books.book_id')
// ->get()
// ->getResult();
// return $result;
// }
public function itemwise_report_data($f_date = null, $t_date = null)
{
// return $result;
// }
public function itemwise_report_data($f_date = null, $t_date = null)
{
// Fetch invoice data
$query = $this->db->table('invoice')
->select('books.publishers_code, COUNT(invoiceitems.product) as publisher_item_count, books.title as book_name, COUNT(invoiceitems.product) as item_count, SUM(invoiceitems.quantity * invoiceitems.unit_price) as total_cost ,DATE_FORMAT(books.publication_date, "%d/%m/%Y") AS book_publication_date');
$query->where('invoice.isactive', 1)
->where('invoice.invoice_type',1)
->where('invoice.invoice_type', 1)
->where('books.isactive', 1);
// Add date range filter if provided
@ -493,7 +499,7 @@ public function itemwise_report_data($f_date = null, $t_date = null)
'publisher_item_count' => 0,
'publisher_total_cost' => 0,
'books' => [],
'book_name'=>'',
'book_name' => '',
];
}
@ -505,16 +511,16 @@ public function itemwise_report_data($f_date = null, $t_date = null)
'book_name' => $row->book_name,
'item_count' => $row->item_count,
'total_cost' => $row->total_cost,
'book_publication_date' =>$row->book_publication_date,
'book_publication_date' => $row->book_publication_date,
];
}
return array_values($groupedResult);
}
}
public function getInvoiceIdByMd5($md5Hash)
{
public function getInvoiceIdByMd5($md5Hash)
{
$result = $this->db->table($this->table)
->select('invoice_id')
->get()
@ -527,61 +533,61 @@ public function getInvoiceIdByMd5($md5Hash)
}
return null;
}
// public function getExpiredCustomers($f_date = null, $t_date = null)
// {
// $now = date('Y-m-d');
// $futureDate = date('Y-m-d', strtotime($now . ' +30 days'));
}
// public function getExpiredCustomers($f_date = null, $t_date = null)
// {
// $now = date('Y-m-d');
// $futureDate = date('Y-m-d', strtotime($now . ' +30 days'));
// $query = $this->db->table('subscription as S'); // Define $query here
// $query = $this->db->table('subscription as S'); // Define $query here
// if ($f_date !== null && $t_date !== null) {
// $query->where('S.to_subscription >=', $f_date)
// ->where('S.to_subscription <=', $t_date);
// }
// if ($f_date !== null && $t_date !== null) {
// $query->where('S.to_subscription >=', $f_date)
// ->where('S.to_subscription <=', $t_date);
// }
// $result = $query
// ->select('S.customer_id,S.sub_id, S.from_subscription, S.to_subscription, C.first_name, C.last_name, C.email, C.mobile_no, S.scheme_id,B.short_code')
// ->join('customers as C', 'C.customer_id = S.customer_id', 'left')
// ->join('books as B', 'B.book_id = S.scheme_id', 'left')
// ->where('S.isactive', 1)
// ->where('S.to_subscription <', $futureDate)
// ->get()
// ->getResultArray();
// // print_r($result);
// // echo "<pre>";
// // echo $this->db->getLastQuery();
// // echo "</pre>";die;
// echo $this->db->getLastQuery();
// die();
// $result = $query
// ->select('S.customer_id,S.sub_id, S.from_subscription, S.to_subscription, C.first_name, C.last_name, C.email, C.mobile_no, S.scheme_id,B.short_code')
// ->join('customers as C', 'C.customer_id = S.customer_id', 'left')
// ->join('books as B', 'B.book_id = S.scheme_id', 'left')
// ->where('S.isactive', 1)
// ->where('S.to_subscription <', $futureDate)
// ->get()
// ->getResultArray();
// // print_r($result);
// // echo "<pre>";
// // echo $this->db->getLastQuery();
// // echo "</pre>";die;
// echo $this->db->getLastQuery();
// die();
// return $result;
// return $result;
// }
public function getExpiredCustomers($f_date = null, $t_date = null)
{
// }
public function getExpiredCustomers($f_date = null, $t_date = null)
{
// Set timezone for accurate date calculation
date_default_timezone_set('Asia/Kolkata');
// Calculate the date 30 days from now
$futureDate = date('Y-m-d', strtotime('+30 days'));
$query = $this->db->table('subscription as S');
$query = $this->db->table('subscription as S');
if (!empty($f_date) && !empty($t_date)) {
if (!empty($f_date) && !empty($t_date)) {
$query->where('S.to_subscription >=', $f_date)
->where('S.to_subscription <=', $t_date);
} else {
} else {
$query->where('S.to_subscription >=', date('Y-m-d'))
->where('S.to_subscription <=', $futureDate);
}
}
$subquery = $this->db->table('subscription as S2')
$subquery = $this->db->table('subscription as S2')
->select('S.sub_id')
->where('S2.customer_id = S.customer_id')
->where('S.sub_id = S2.is_renew');
$result = $query
$result = $query
->select('S.customer_id, S.sub_id, S.from_subscription, S.to_subscription,
C.first_name, C.last_name, C.email, C.mobile_no,
S.scheme_id, B.short_code, S.membership_id')
@ -599,8 +605,9 @@ $result = $query
// Fetch results as an associative array
return $result->getResultArray();
}
public function getActiveMembers(){
}
public function getActiveMembers()
{
$result =
$this->db->table('subscription as S')
->select('S.customer_id, S.sub_id, S.from_subscription, S.to_subscription,
@ -613,11 +620,10 @@ public function getActiveMembers(){
->orderBy('S.to_subscription', 'ASC')
->get();
return $result->getResultArray();
}
}
public function itemwise_report_data_with_publish_code($f_date = null, $t_date = null)
{
public function itemwise_report_data_with_publish_code($f_date = null, $t_date = null)
{
// Fetch invoice data
$query = $this->db->table('invoice')
->select('invoice.*, books.* , COUNT(invoiceitems.product) as item_count , sum(invoiceitems.product * invoiceitems.unit_price) as item_cost')
@ -639,11 +645,9 @@ public function itemwise_report_data_with_publish_code($f_date = null, $t_date =
// print_r($result);die;
return $result;
}
public function userwise_eventwise_report($f_date = null, $t_date = null){
}
public function userwise_eventwise_report($f_date = null, $t_date = null) {
$builder = $this->db->table('invoice');
$builder->select([
@ -654,6 +658,7 @@ public function userwise_eventwise_report($f_date = null, $t_date = null){
'COUNT(invoice.created_by) AS books_sold',
'ABS(SUM(invoice.exact_total_amount)) AS total_amount',
'invoice.payment_method',
// 'DATE(invoice.invoice_date) AS invoice_date' // Convert to DATE
'invoice.invoice_date'
]);
@ -663,26 +668,31 @@ public function userwise_eventwise_report($f_date = null, $t_date = null){
$builder->join('books', 'books.book_id = invoiceitems.product');
$builder->where('invoice.event_id <>', 0);
if ($f_date !== null && $t_date !== null) {
$builder->where('invoice.invoice_date >=', $f_date)
->where('invoice.invoice_date <=', $t_date);
}
$builder->groupBy([
'invoice_date',
'users.user_id',
'users.first_name',
'events.event_name',
'payment_method'
'events.event_name'
]);
// Order by the converted date
$builder->orderBy('invoice_date', 'DESC');
$query = $builder->get();
$results = $query->getResultArray();
return $results;
}
$result = $query->getResultArray();
// dd($result);
return $result;
}
public function getPaymentReport($f_date = null, $t_date = null)
{
public function getPaymentReport($f_date = null, $t_date = null)
{
$builder = $this->db->table('invoice');
$builder->select('invoice.invoice_number, customers.first_name, invoice.total_amount, invoice.payment_status, invoice.payment_method, invoice.invoice_date');
@ -691,7 +701,7 @@ 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');
$builder->where('invoice.status', 'Approved');
$query = $builder->get();
$result1 = $query->getResultArray();
$builder->select('payment_method, SUM(exact_total_amount) as total_amount');
@ -703,20 +713,20 @@ public function getPaymentReport($f_date = null, $t_date = null)
$query2 = $builder->get();
$paymentMethodTotals = $query2->getResultArray();
$paymentMethodMap = [];
foreach ($paymentMethodTotals as $row) {
foreach ($paymentMethodTotals as $row) {
$paymentMethodMap[$row['payment_method']] = $row['total_amount'];
}
}
$result2 = $paymentMethodMap;
// log_message('info',json_encode($results));
// dd($results);
// log_message('info',json_encode($results));
// dd($results);
$results = [
'result1'=>$result1,
'result2'=>$result2
'result1' => $result1,
'result2' => $result2
];
return $results;
}
public function itemwise_report_data_with_payment_method($f_date = null, $t_date = null)
{
}
public function itemwise_report_data_with_payment_method($f_date = null, $t_date = null)
{
$builder = $this->db->table('invoice');
$builder->select('books.publishers_code,
COUNT(invoiceitems.product) AS publisher_item_count,
@ -771,11 +781,11 @@ public function itemwise_report_data_with_payment_method($f_date = null, $t_date
}
return array_values($groupedResult);
}
}
public function updateInvoiceStatus($invoiceId, $voidReason)
{
public function updateInvoiceStatus($invoiceId, $voidReason)
{
// Assuming 'invoices' is the name of your table
$builder = $this->db->table('invoice');
@ -793,9 +803,9 @@ public function updateInvoiceStatus($invoiceId, $voidReason)
$updated = $builder->update($data);
return $updated;
}
public function updateInvoiceCancelStatus($invoiceIds, $cancelReason)
{
}
public function updateInvoiceCancelStatus($invoiceIds, $cancelReason)
{
// Assuming 'invoices' is the name of your table
$builder = $this->db->table('invoice');
@ -813,23 +823,19 @@ public function updateInvoiceCancelStatus($invoiceIds, $cancelReason)
$updated = $builder->update($data);
return $updated;
}
public function getActiveSchemes(){
$builder = $this->db->table($this->table.' as I' );
}
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->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;
}
}
}

View File

@ -12,7 +12,7 @@
<button type="button" id="callajax" class="btn btn-primary" onclick="sendsms()">Send Message</button>
</div>
<div class="col-md-4">
<input id = 'date_picker' class="form-control input-daterange-datepicker" type="text" name="date" value="<?php echo $selected_data; ?>" />
<input id='date_picker' class="form-control input-daterange-datepicker" type="text" name="date" value="<?php echo $selected_data; ?>" />
</div>
<div class="col-md-2">
<button type="submit" class="btn btn-primary" onclick="generateData()">Generate Report</button>
@ -23,8 +23,8 @@
<br>
<div class="col-md-12" style="margin: 15px;" id="target-div"></div>
</div>
<div id="modal_table">
<div class="table-responsive">
<div id="modal_table">
<div class="table-responsive">
<table id="datatable-buttons" class="table table-striped nowrap w-100">
<thead>
<tr>
@ -40,10 +40,13 @@
<tbody id="table-body">
</tbody>
</table>
</div></div></div></div> <!-- end card body-->
</table>
</div>
</div>
</div>
</div> <!-- end card body-->
</div> <!-- end card -->
</div><!-- end col--><!-- end row-->
</div><!-- end col--><!-- end row-->
<script>
$(document).ready(function() {
@ -53,7 +56,7 @@
"ordering": false,
"paging": true,
"searching": true,
"autoWidth":true
"autoWidth": true
});
@ -77,15 +80,14 @@
.on('cancel.daterangepicker', function() {
$(this).val('');
});
});
});
</script>
<script>
function sendsms(){
function sendsms() {
var params = $("#params").val();
var params2 = $("#date_picker").val();
console.log("The param passed is "+params2);
if(params2){
console.log("The param passed is " + params2);
if (params2) {
var dates = params2.split(" - ");
var from_date = dates[0];
var to_date = dates[1];
@ -93,17 +95,17 @@
if (!params && !(params2)) {
alert("Enter a valid number of days.");
return;
}else{
console.log("param 1 is "+params);
console.log("params 2 is "+ params2);
} else {
console.log("param 1 is " + params);
console.log("params 2 is " + params2);
console.log('<?= base_url() . 'getExpCustomerDetail/' ?>');
$.ajax({
type: "POST",
url: `<?= base_url() . 'getExpCustomerDetail/' ?>${params}/${params2}`,
data: {
from_date : from_date,
to_date : to_date,
params : params
from_date: from_date,
to_date: to_date,
params: params
},
success: function(response) {
@ -121,7 +123,7 @@
}
}
function generateData(){
function generateData() {
var date = $("#date_picker").val();
console.log(date);
$.ajax({
@ -130,7 +132,7 @@
data: {
date: date
},
success: function(response){
success: function(response) {
console.log(response);
var data = response.data;
var table = $('#datatable-buttons').DataTable();
@ -144,9 +146,14 @@
var sentDateFormatted = ('0' + sentTime.getDate()).slice(-2) + '/' +
('0' + (sentTime.getMonth() + 1)).slice(-2) + '/' +
sentTime.getFullYear();
var sentTimeFormatted = ('0' + sentTime.getHours()).slice(-2) + ':' +
('0' + sentTime.getMinutes()).slice(-2) + ':' +
('0' + sentTime.getSeconds()).slice(-2);
var hours = sentTime.getHours();
var minutes = ('0' + sentTime.getMinutes()).slice(-2);
var ampm = hours >= 12 ? 'PM' : 'AM';
hours = hours % 12 || 12; // Convert 0 (midnight) and 12 (noon) properly
var sentTimeFormatted = ('0' + hours).slice(-2) + ':' + minutes + ' ' + ampm;
var sentDateTimeFormatted = sentDateFormatted + ' ' + sentTimeFormatted; // Combine date and time
var sentDateTimeFormatted = sentDateFormatted + ' ' + sentTimeFormatted; // Combine date and time
table.row.add([
item.first_name + ' ' + item.last_name,
@ -170,12 +177,13 @@
$('#modal_table').show();
}
},
error: function(xhr, status, error){
error: function(xhr, status, error) {
console.error("Ajax Error: ", error);
}
});
}
function regenerateFilters(table) {
}
function regenerateFilters(table) {
$('#datatable-buttons thead tr:eq(1)').remove();
$('#datatable-buttons thead tr').clone(true).appendTo('#datatable-buttons thead');
@ -200,7 +208,5 @@ function regenerateFilters(table) {
}
});
});
}
}
</script>

View File

@ -6,20 +6,20 @@
<th><b>SCHEME Name</b></th>
<th>Date/Time</th>
<th><b>ORDER ID</b></th>
<th>Payment Status</th>
<th style="text-align: left;">Payment Status</th>
<th><b>Amount</b></th>
</tr>
</thead>
<tbody class="custom-tbody">
<?php foreach ($payment_status_data as $row) { ?>
<tr>
<td><?= isset($row['customer_name'])?$row['customer_name']:"-"?></td>
<td><?= isset($row['membership_id'])?$row['membership_id']:"-"?></td>
<td><?= isset($row['scheme_name'])?$row['scheme_name']:"-"?></td>
<td><?= isset($row['created_at'])? date("d/m/Y H:i:s", strtotime($row['created_at'])) : '-' ?></td>
<td><?= isset($row['order_id'])?$row['order_id']:"-"?></td>
<td><?= isset($row['payment_status'])?$row['payment_status']:"-" ?></td>
<td><?= isset($row['amount'])?$row['amount']:"-"?></td>
<td style="text-align: left;"><?= isset($row['customer_name'])?$row['customer_name']:"-"?></td>
<td style="text-align: left;"><?= isset($row['membership_id'])?$row['membership_id']:"-"?></td>
<td style="text-align: left;"><?= isset($row['scheme_name'])?$row['scheme_name']:"-"?></td>
<td style="text-align: left;"><?= isset($row['created_at']) ? date("d/m/Y h:i A", strtotime($row['created_at'])) : '-' ?></td>
<td style="text-align: left;"><?= isset($row['order_id'])?$row['order_id']:"-"?></td>
<td style="text-align: left;"><?= isset($row['payment_status'])?$row['payment_status']:"-" ?></td>
<td style="text-align: right;"><?= isset($row['amount'])?$row['amount']:"-"?></td>
</tr>
<?php } ?>
</tbody>

View File

@ -156,7 +156,7 @@
<script>
$(document).ready(function () {
var table = $('#datatable-buttons').DataTable({
"order": [[1, 'desc']],
"order": [[0, 'desc']],
dom: '<"row mb-3"<"col-md-6 d-flex align-items-center"B><"col-md-6 d-flex justify-content-end"f>>rtip',
buttons: [
{

View File

@ -149,7 +149,7 @@
var table = $('#datatable-buttons').DataTable({
"order": [
[1, 'desc']
// [0, 'desc']
],
"dom": '<"row mb-3"<"col-md-6 d-flex align-items-center"B><"col-md-6 d-flex justify-content-end"f>>rtip',
buttons: [{

View File

@ -38,7 +38,7 @@
<th>Event Name</th>
<th>User Name</th>
<th>Books Sold</th>
<th>Payment Method</th>
<!-- <th>Payment Method</th> -->
<th>Total Amount</th>
</tr>
</thead>
@ -46,13 +46,15 @@
<?php foreach ($report_data as $row) { ?>
<tr>
<td hidden><?php echo $row["user_id"]; ?></td>
<?php $unixTime = strtotime($row['invoice_date']);
$invoice_date = date("d/m/Y", $unixTime);?>
<?php
// Since invoice_date is now a proper date, we can format it directly
$invoice_date = date("d/m/Y", strtotime($row['invoice_date']));
?>
<td><?= $invoice_date ?></td>
<td style="text-align: left;"><?= $row['event_name'] ?></td>
<td style="text-align: left;"><?= $row['first_name'].' ('.$row['role'].')'?></td>
<td style="text-align: left;"><?= $row['first_name'] . ' (' . $row['role'] . ')' ?></td>
<td style="text-align: center;"><?= $row['books_sold'] ?></td>
<td style="text-align: left;"><?= strtoupper($row['payment_method'])?></td>
<!-- <td style="text-align: left;"><?= strtoupper($row['payment_method']) ?></td> -->
<td style="text-align:right;padding-right: 67px;"><?= $row['total_amount'] ?></td>
</tr>
<?php } ?>
@ -67,22 +69,22 @@
<!-- end row-->
<script>
$(document).ready(function () {
$(document).ready(function() {
var table = $('#datatable-buttons').DataTable({
"order": [[0, 'desc']],
ordering: false,
// "order": [[0, 'desc']],
// "order": [[0, 'desc']],
"dom": '<"row mb-3"<"col-md-6 d-flex align-items-center"B><"col-md-6 d-flex justify-content-end"f>>rtip',
buttons: [
{
buttons: [{
extend: 'print',
title: '<?= $page_name.' ' .$selected_data ?>',
title: '<?= $page_name . ' ' . $selected_data ?>',
text: 'Print',
customize: function (win) { }
customize: function(win) {}
},
{
extend: 'csv',
text: 'CSV',
title: '<?= $page_name.' ' .$selected_data ?>',
title: '<?= $page_name . ' ' . $selected_data ?>',
exportOptions: {}
}
]