Issues Fixes : ps

This commit is contained in:
VE10-Sanjeev 2023-12-26 15:15:21 +05:30
parent 7550adfcf0
commit 47428911e7
7 changed files with 90 additions and 33 deletions

View File

@ -247,6 +247,7 @@ class Invoice extends BaseController
$from_sub_date = $item['from_subscription'];
$to_sub_date = $item['to_subscription'];
$subscription_data = [
'customer_id' => (int)$customer_id,
'invoice_id' => $invoice_id,
@ -257,17 +258,10 @@ class Invoice extends BaseController
'created_by' =>get_logged_user_id(),
];
$subscription_where = ['scheme_id' => $product_id,'customer_id' => $customer_id,'invoice_id' => $invoice_id];
$subscription_details = $model->getData('subscription', $subscription_where);
if(count($subscription_details)==0){
$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));
$subscriptionModel->insertSubscriptionData($subscription_data);
}else{
unset($subscription_data['created_by']);
$subscription_data['updated_by'] =get_logged_user_id();
$subscription_where = ['sub_id' => (int)$subscription_details[0]->sub_id];
$subscriptionModel->updateData('subscription', $subscription_data, $subscription_where);
}
}
}
@ -282,10 +276,12 @@ class Invoice extends BaseController
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('invoice_list'); // Adjust the route name as needed.
}
}

View File

@ -20,7 +20,7 @@ class Subscription extends BaseController
if (!empty($session_role) && $session_role !== "sadmin") {
$this->logger->info("Invoice: Listing In Admin BID = " . $session_bid);
$where = ['I.business_id' => (int)$session_bid, 'I.isactive' => 1,'I.invoice_type'=>2];
$where = ['I.business_id' => (int)$session_bid, 'I.isactive' => 1,'I.invoice_type'=>2,'S.isactive'=>1];
} else {
$this->logger->info("Invoice: Listing In the Super-Admin ");
$where = ['I.business_id != ' => NULL, 'I.isactive != ' => NULL,'I.invoice_type'=>2];

View File

@ -102,18 +102,20 @@ class CustomerModel extends Model
}
public function getSubscriberDataByCustomerId($customerId)
{
// Default invoice type is 2 (subscription).
$where = ['subscription.customer_id'=> $customerId,'invoice.invoice_type' => 2,'subscription.isactive' => 1];
// Assuming 'subscription' is the table name where subscriber data is stored.
$builder = $this->db->table('subscription');
$builder->join('books', 'books.book_id = subscription.scheme_id');
$builder->join('invoice', 'subscription.customer_id = invoice.customer_id', 'left');
// Define the columns you want to select from the subscription table.
$builder->select('subscription.*,books.title,DATE_FORMAT(subscription.from_subscription, "%d/%m/%Y") AS formatted_from_subscription,DATE_FORMAT(subscription.to_subscription, "%d/%m/%Y") AS formatted_to_subscription');
$builder->select('subscription.*,books.title,DATE_FORMAT(subscription.from_subscription, "%d/%m/%Y") AS formatted_from_subscription,DATE_FORMAT(subscription.to_subscription, "%d/%m/%Y") AS formatted_to_subscription,DATEDIFF(subscription.to_subscription, subscription.from_subscription) as subscription_in_days');
// Add a where condition to filter results based on customer ID.
$builder->where('subscription.customer_id', $customerId);
$builder->where('invoice.invoice_type = "2"'); // Default type is 2 (subscription).
$builder->where($where);
$builder->groupBy('subscription.sub_id');
// Execute the query and return the result as an array of objects.
return $builder->get()->getResult();
print_r($this->db->getLastQuery());die;
}
public function saveGroupDetails($data){

View File

@ -44,6 +44,25 @@ public function updateData($table, $data, $where)
return $affected_rows;
}
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){
$this->db->table('subscription')
->whereIn('invoice_id', $inactive_invoice_ids)
->set('isactive', 0)
->set('updated_by', $update_by_id)
->update();
}
return $inactive_invoice_ids;
}
public function getSubscriptionInvoiceDetail($where)
{
$result = $this->getJoinedData($where);
@ -74,8 +93,9 @@ public function updateData($table, $data, $where)
->join('business as B', 'B.business_id = I.business_id', 'left')
->join('users as U1', 'U1.user_id = I.created_by', 'left')
->join('users as U2', 'U2.user_id = I.updated_by', 'left')
->select('I.invoice_id, I.invoice_number, I.customer_id,concat(C.first_name," ",C.last_name) as customer_name , I.invoice_date, I.due_date, I.subtotal, I.tax, I.discount, I.total_amount,I.status, I.payment_status, I.order_number, I.payment_method,I.invoice_type, I.event_id,E.event_name, I.business_id,B.title as business_name, I.created_on, I.created_by,concat(U1.first_name," ",U1.last_name) as created_by_name, I.updated_on, I.updated_by,concat(U2.first_name," ",U2.last_name) as updated_by_name, I.isactive,C.email as customer_email,C.mobile_no as customer_mobile,I.shipping_address_id,I.shipping_address,I.billing_address_id,I.billing_address,B.address as business_address,B.city as business_city,B.state as business_state,B.postal_code as business_postal_code,B.email as business_email,B.mobile_no as business_mobile_no,S.from_subscription,S.to_subscription')
->select('I.invoice_id, I.invoice_number, I.customer_id,concat(C.first_name," ",C.last_name) as customer_name , I.invoice_date, I.due_date, I.subtotal, I.tax, I.discount, I.total_amount,I.status, I.payment_status, I.order_number, I.payment_method,I.invoice_type, I.event_id,E.event_name, I.business_id,B.title as business_name, I.created_on, I.created_by,concat(U1.first_name," ",U1.last_name) as created_by_name, I.updated_on, I.updated_by,concat(U2.first_name," ",U2.last_name) as updated_by_name, I.isactive,C.email as customer_email,C.mobile_no as customer_mobile,I.shipping_address_id,I.shipping_address,I.billing_address_id,I.billing_address,B.address as business_address,B.city as business_city,B.state as business_state,B.postal_code as business_postal_code,B.email as business_email,B.mobile_no as business_mobile_no,S.from_subscription,S.to_subscription,DATEDIFF(S.to_subscription, S.from_subscription) as subscription_in_days,S.scheme_id')
->where($where)
// ->like('C.first_name',"%John%")
->orderBy('I.invoice_id', 'DESC')
->groupBy('I.invoice_id')
->get()

View File

@ -265,14 +265,28 @@
<th>Subscription Name</th>
<th>From Subscription</th>
<th>To Subscription</th>
<th>Expiring Status</th>
</tr>
</thead>
<tbody>
<?php foreach ($subscriptions as $subscription) : ?>
<?php foreach ($subscriptions as $subscription) :
$daysRemaining = (int)$subscription->subscription_in_days;
if ($daysRemaining <= 0) {
$class = 'text-danger';
$message = "Expired";
} elseif ($daysRemaining <= 3) {
$s = $daysRemaining == 1 ? "" : "s";
$class = 'text-warning';
$message = "Expire in $daysRemaining day".$s;
} else {
$class = 'text-success';
$message = $daysRemaining ." days until Expiration";
}?>
<tr>
<td><?= $subscription->title ?></td>
<td><?= $subscription->formatted_from_subscription ?></td>
<td><?= $subscription->formatted_to_subscription ?></td>
<td><span class="<?php echo $class; ?>"><?php echo $message; ?></span></td>
</tr>
<?php endforeach; ?>
</tbody>

View File

@ -153,7 +153,8 @@
<?php endforeach;
} else { ?>
<tr>
<td style="width:30% !important;"><select class="form-control book-select" id="book0" name="item_details[]" onchange="displayBookTag(this,0)" required data-toggle="select2" style="width: 249px !important;">
<td style="width:30% !important;">
<select class="form-control book-select" id="book0" name="item_details[]" onchange="displayBookTag(this,0)" required data-toggle="select2" style="width: 249px !important;">
<option value="">Select a <?= $flag_name ?></option>
<?php
foreach ($books as $book) :
@ -328,8 +329,8 @@
var cell7 = newRow.insertCell(6);
var cell8 = newRow.insertCell(7);
cell1.innerHTML = `<select class="form-control book-select" id="book${counter}" name="item_details[]" onchange="displayBookTag(this, ${counter})" data-toggle="select2">
<option value="">Select a <?php $flag_name ?></option>
cell1.innerHTML = `<select class="form-control book-select" id="book${counter}" name="item_details[]" onchange="displayBookTag(this, ${counter})" data-toggle="select2" required>
<option value=""><?= "Select a ".$flag_name ?></option>
<?php foreach ($books as $book) : if ((int)$book->isactive === 1) : ?>
<option value="<?= $book->book_id ?>"><?= $book->title ?></option>
<?php endif; endforeach; ?>
@ -695,7 +696,7 @@
cm = response['data']['customer_membership'];
if (cm.length > 0) {
$(".subscribedetails").show(); // Change this line to use the class selector
$("#schemeName").text(cm[0].title + " ( From: " + cm[0].formatted_from_subscription + " To: " + cm[0].formatted_to_subscription+" )");
$("#schemeName").text("Earlier Membership : "+cm[0].title + " ( From: " + cm[0].formatted_from_subscription + " To: " + cm[0].formatted_to_subscription+" )");
} else {
$(".subscribedetails").show(); // Change this line to use the class selector
$("#schemeName").text("No Earlier Membership found");

View File

@ -9,6 +9,24 @@
</div><!-- end col-->
<br>
<h4 class="header-title mb-3"><?= $page_name; ?></h4>
<?php if (session()->getFlashdata('success') || session()->getFlashdata('error')) : ?>
<?php if (session()->getFlashdata('success')) : ?>
<div class="alert alert-success alert-dismissible fade show" role="alert">
<?= session('success') ?>
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<?php endif; ?>
<?php if (session()->getFlashdata('error')) : ?>
<div class="alert alert-danger alert-dismissible fade show" role="alert">
<?= session('error') ?>
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<?php endif; ?>
<?php endif; ?>
<div class="table-responsive">
<table id="scroll-horizontal-datatable_subcription" class="table w-100 nowrap">
<thead class="thead-light">
@ -21,6 +39,7 @@
<th>Customer Name</th>
<th>Scheme Name</th>
<th>Status</th>
<th>Expiring Status</th>
<th>Total</th>
<th align="center">Action</th>
</tr>
@ -28,10 +47,21 @@
<tbody>
<?php
foreach ($invoice as $row) :
if ($row['invoice_type'] == 2) :
$invoice_date = date('d/m/Y', strtotime($row['invoice_date']));
$from_date = date('d/m/Y', strtotime($row['from_subscription']));
$to_date = date('d/m/Y', strtotime($row['to_subscription']));
$daysRemaining = (int)$row['subscription_in_days'];
if ($daysRemaining <= 0) {
$class = 'text-danger';
$message = "Expired";
} elseif ($daysRemaining <= 7) {
$s = $daysRemaining == 1 ? "" : "s";
$class = 'text-warning';
$message = "Expire in $daysRemaining day".$s;
} else {
$class = 'text-success';
$message = $daysRemaining ."days until Expiration";
}
?>
<tr>
<td hidden><?= $row['invoice_id'] ?></td>
@ -42,20 +72,14 @@
<td><?= $row['customer_name']; ?></td>
<td><?= $row['scheme_name']; ?></td>
<td><?= $row['status']; ?></td>
<td><span class="<?php echo $class; ?>"><?php echo $message; ?></span></td>
<td><?= "" . $row['total_amount']; ?></td>
<td>
<!-- <a href="<?= base_url() . "approve_invoice/" . $row['invoice_id']; ?>" class="approve-button" title="Approve the Invoice"><i class="ri-checkbox-circle-fill"></i></a>&nbsp; -->
<?php if ($row['invoice_type'] == 2) : ?>
<a href="<?= base_url() . "new_subscription_invoice/" . $row['invoice_id']; ?>" class="edit-button" title="Edit the Invoice"><i class="ri-pencil-line" title="Edit the Invoice"></i></a>&nbsp;
<?php elseif ($row['invoice_type'] == 1) : ?>
<a href="<?= base_url() . "new_book_invoice/" . $row['invoice_id']; ?>" class="edit-button" title="Edit the Invoice"><i class="ri-pencil-line" title="Edit the Invoice"></i></a>&nbsp;
<?php endif; ?>
<a href="<?= base_url("generate_invoice_pdf/{$row['invoice_id']}") ?>" class="download-pdf-button" title="Download the Invoice"><i class="ri-file-download-line"></i></a>&nbsp;
<a href="<?= base_url("print_address/{$row['invoice_id']}") ?>" class="print-address-button" title="Print Address"><i class="ri-printer-line"></i></a>
</td>
</tr>
<?php endif; ?>
<?php endforeach; ?>
</tbody>
</table>