invoice,subcription

This commit is contained in:
heama 2023-10-20 15:57:49 +05:30
parent 23684a827f
commit 1ff9d8d5a5
9 changed files with 141 additions and 87 deletions

View File

@ -258,7 +258,14 @@ class Invoice extends BaseController
}
return redirect()->route('invoice_list');
if ($invoiceType === '1') {
// If the invoice_type is 1 (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.
return redirect()->route('invoice_list'); // Adjust the route name as needed.
}
}
## For Updating Events Details ..

View File

@ -6,6 +6,7 @@ namespace App\Controllers;
use App\Models\CustomerModel;
use App\Models\SubscriptionModel;
use App\Models\SchemeModel;
use App\Models\InvoiceModel;
use Mpdf\Mpdf;
class Subscription extends BaseController
@ -17,15 +18,26 @@ class Subscription extends BaseController
$session_bid = get_business_id();
if (!empty($session_role) && $session_role !== "sadmin") {
$where = ['subscription.business_id'=>(int)$session_bid];
}else{ $where = ['subscription.business_id != '=>NULL];}
$this->logger->info("Invoice: Listing In Admin BID = " . $session_bid);
$where = ['I.business_id' => (int)$session_bid, 'I.isactive' => 1];
} else {
$this->logger->info("Invoice: Listing In the Super-Admin ");
$where = ['I.business_id != ' => NULL, 'I.isactive != ' => NULL];
}
$model = new InvoiceModel();
$data['page_name'] = 'Subscription Invoice Details';
$data['invoice'] = $model->getJoinedData($where);
$this->logger->info("Invoice: Listing Count ." . count($data['invoice']));
$SubscriptionModel = new SubscriptionModel();
$data['page_name'] = 'Subscription Details';
// $data['subscriber'] = $SubscriptionModel->where($where)->findAll();;
$data['subscriber'] = $SubscriptionModel->getAllSubscribersWithNames($where);
// $data['subscriber'] = $SubscriptionModel->where($where)->findAll();;
$SubscriptionModel = new SubscriptionModel();
$swhere = ['subscription.business_id' => (int)$session_bid];
$data['subscriber'] = $SubscriptionModel->getAllSubscribersWithNames($swhere);
$this->render_page('subscribers_list', $data);
}else {
return redirect()->to('login');
@ -109,32 +121,34 @@ public function add_subscription() {
// }
public function download_details()
{
$selectedScheme = $this->request->getPost('selected_scheme');
$selectedSchemes = $this->request->getPost('selected_schemes');
// Call the model method to get all customer details for the selected scheme
$subscriptionModel = new SubscriptionModel();
$customerDetails = $subscriptionModel->getAllCustomerDetailsBySchemeName($selectedScheme);
// Initialize an empty PDF
$pdf = new Mpdf();
// Create an HTML content string using the view file (similar to print_addresses.php)
if (!empty($customerDetails)) {
$html = view('print_addresses_form', ['customerDetails' => $customerDetails]);
// Iterate through selected schemes
foreach ($selectedSchemes as $selectedScheme) {
// Call the model method to get customer details for each selected scheme
$subscriptionModel = new SubscriptionModel();
$customerDetails = $subscriptionModel->getAllCustomerDetailsBySchemeName($selectedScheme);
// Generate a PDF from the HTML content
$pdf = new Mpdf();
// Create an HTML content string for the current scheme
if (!empty($customerDetails)) {
$html = view('print_addresses_form', ['customerDetails' => $customerDetails]);
$pdf->WriteHTML($html);
// Set the PDF filename
$filename = 'CustomerDetails_' . date('YmdHis') . '.pdf';
// Output the PDF for download
$pdf->Output($filename, 'D');
} else {
// Handle the case where no customer details are found for the selected scheme
echo 'No customer details found for the selected scheme.';
// Add the current scheme's details to the PDF
$pdf->WriteHTML($html);
}
}
// Set the PDF filename
$filename = 'CustomerDetails_' . date('YmdHis') . '.pdf';
// Output the PDF for download
$pdf->Output($filename, 'D');
}
}
// public function generate_pdf()
// {

View File

@ -48,6 +48,7 @@ public function updateData($table, $data, $where)
{
return $this->db->table($this->table.' as I' )
->join('customers as C', 'C.customer_id = I.customer_id', 'left')
->join('events as E', 'E.id = I.event_id', 'left')
->join('business as B', 'B.business_id = I.business_id', 'left')
@ -55,6 +56,7 @@ public function updateData($table, $data, $where)
->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')
->where($where)
->orderBy('invoice_id', 'DESC')
->get()
->getResultArray();

View File

@ -48,8 +48,8 @@ public function getCustomerAddressesBySchemeName($schemeName)
$builder->join('customers', 'customers.customer_id = subscription.customer_id');
$builder->join('customer_addresses', 'customer_addresses.customer_id = subscription.customer_id');
$builder->join('business', 'business.business_id = subscription.business_id');
$builder->join('schemes', 'schemes.scheme_id = subscription.scheme_id');
$builder->where('schemes.scheme_name', $schemeName);
$builder->join('books', 'books.book_id = subscription.scheme_id');
$builder->where('books.title', $schemeName);
$query = $builder->get();
@ -89,12 +89,12 @@ public function getCustomerAddressesBySchemeName($schemeName)
public function getAllCustomerDetailsBySchemeName($schemeName)
{
$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,business.address,business.city,business.state,business.postal_code,schemes.scheme_name,from_subscription,to_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,business.address,business.city,business.state,business.postal_code,books.title,from_subscription,to_subscription');
$builder->join('customers', 'customers.customer_id = subscription.customer_id');
$builder->join('customer_addresses', 'customer_addresses.customer_id = customers.customer_id');
$builder->join('business', 'business.business_id = subscription.business_id');
$builder->join('schemes', 'schemes.scheme_id = subscription.scheme_id');
$builder->where('schemes.scheme_name', $schemeName);
$builder->join('books', 'books.book_id = subscription.scheme_id');
$builder->where('books.title', $schemeName);
$builder->where('customer_addresses.address_type', 2); // Filter by address_type 2
$builder->orderBy('customers.customer_id', 'ASC'); // Order by customer_id to group by customers
@ -132,7 +132,7 @@ public function getAllCustomerDetailsBySchemeName($schemeName)
'postal_code' => $row['postal_code'],
'title' => $row['title'],
'to_subscription'=>$row['to_subscription'],
'scheme_name'=>$row['scheme_name'],
'title'=>$row['title'],
];
$currentCustomerID = $customerID;

View File

@ -217,7 +217,7 @@
name="discount_amount[]" oninput="calculateInvoice(this)" />
</td>
<td style="width:10%;">
<td style="width:12%;">
<select class="form-control item-discount-type"
name="discount_type[]" oninput="calculateInvoice(this)">
<option value=""></option>
@ -267,11 +267,9 @@
$isSubscriptionInvoice = ($page_name === 'Add Subscription Invoice Details' || $page_name === 'Edit Subscription Invoice Details');
// Conditionally set the "hidden" attribute for the fields
$balanceHidden = $isSubscriptionInvoice ? 'hidden' : '';
$paidAmountHidden = $isSubscriptionInvoice ? 'hidden' : '';
$shippingChargesHidden = $isSubscriptionInvoice ? 'hidden' : '';
$balanceStyle = $isSubscriptionInvoice ? 'display: none;' : '';
$paidAmountStyle = $isSubscriptionInvoice ? 'display: none;' : '';
$shippingChargesStyle = $isSubscriptionInvoice ? 'display: none;' : '';
?>
<div class="form-group">
@ -306,19 +304,19 @@ $shippingChargesStyle = $isSubscriptionInvoice ? 'display: none;' : '';
</div>
<div class="form-group">
<label for="balanceAmount" style="<?= $balanceStyle ?>">Balance
<label for="balanceAmount" >Balance
Amount:</label>
<input type="number" class="form-control" id="balanceAmount"
name="balanceAmount"
value="<?= (isset($invoice_details['status']) && $invoice_details['status'] === 'Draft') ? (isset($invoice_details['total_amount']) ? $invoice_details['total_amount'] : '') : '0' ?>"
oninput="calculateOverallTotals()" <?= $balanceHidden ?>>
oninput="calculateOverallTotals()" >
</div>
<div class="form-group">
<label for="paidAmount" style="<?= $paidAmountStyle ?>">Paid Amount:</label>
<label for="paidAmount">Paid Amount:</label>
<input type="number" class="form-control" id="paidAmount" name="paidAmount"
value="<?= (isset($invoice_details['status']) && $invoice_details['status'] === 'Approved') ? (isset($invoice_details['total_amount']) ? $invoice_details['total_amount'] : '') : '0' ?>"
oninput="calculateOverallTotals()" <?= $paidAmountHidden ?>>
oninput="calculateOverallTotals()" >
</div>
</div>
</div>
@ -438,7 +436,7 @@ $shippingChargesStyle = $isSubscriptionInvoice ? 'display: none;' : '';
cell6.innerHTML =
'<input type="text" class="form-control item-discount-amount" name="discount_amount[]">';
cell7.innerHTML =
'<select class="form-control item-discount-type" name="discount_type[]" oninput="calculateInvoice(this)"><option value="₹">₹</option><option value="%">%</option></select>';
'<select class="form-control item-discount-type" style=""width:12%;" name="discount_type[]" oninput="calculateInvoice(this)"><option value="₹">₹</option><option value="%">%</option></select>';
cell8.innerHTML =
'<input type="hidden" class="form-control" id="hiddenInvoiceChildId" placeholder="hidden for invoice child/item id" name="invoice_child_id[]" value=""><center><i class="fa fa-trash remove-item "></center>';

View File

@ -56,6 +56,7 @@
<table id="scroll-horizontal-datatable_wrapper" class="table w-100 nowrap">
<thead class="thead-light">
<tr>
<th hidden></th>
<th>Invoice Number</th>
<th>Invoice Date</th>
@ -74,6 +75,7 @@
<tbody>
<?php foreach ($invoice as $row): ?>
<tr>
<?php if ($row['invoice_type'] == 2): // Check if it's a subscription invoice ?>
<td hidden><?= $row['invoice_id'] ?></td>
<td><?= $row['invoice_number']; ?></td>
<td><?= $row['invoice_date']; ?></td>
@ -91,7 +93,7 @@
<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>&nbsp;
</tr>
<?php endif; ?>
<?php endforeach; ?>
</tbody>
</table>

View File

@ -253,8 +253,10 @@ if (count($invoiceDateParts) === 3) {
<?php if (!empty($item->imgs[0]->wp_img_url)) : ?>
<img src="<?= $item->imgs[0]->wp_img_url?>" alt="Product Image"style="max-width: 50px; max-height: 30px;">
<?php else : ?>
<?php if (isset($item->imgs[0]) && !empty($item->imgs[0]->img_name)) : ?>
<img src="<?= base_url('public/uploads/' . $item->imgs[0]->img_name) ?>" alt="Fallback Image"style="max-width: 50px; max-height: 30px;">
<?php endif; ?>
<?php endif; ?>
<?php endif; ?>
</td>
<td><?= $item->title ?></td>
@ -288,8 +290,19 @@ if (count($invoiceDateParts) === 3) {
<td colspan="5" align="right"><?= $value->shipping_label?> : &nbsp;&nbsp;₹<?= number_format($value->shipping_charge, 2, '.', ',') ?></td>
</tr>
<tr>
<td colspan="5" align="right">Total : &nbsp;&nbsp;<?= number_format($value->subtotal, 2, '.', ',') ?></td>
<td colspan="5" align="right">Total : &nbsp;&nbsp;<?= number_format($value->total_amount, 2, '.', ',') ?></td>
</tr>
<?php if ($value->status === 'Draft'): ?>
<!-- Set Balance if status is draft and paid is 0 -->
<tr>
<td colspan="5" align="right">Balance : &nbsp;&nbsp;<?= number_format($value->total_amount, 2, '.', ',') ?></td>
</tr>
<?php endif; ?>
<?php if ($value->status === 'Approved'): ?>
<tr>
<td colspan="5" align="right">Paid : &nbsp;&nbsp;<?= number_format($value->total_amount, 2, '.', ',') ?></td>
</tr>
<?php endif; ?>
<?php endforeach; ?>
</table>

View File

@ -82,7 +82,7 @@
<img src="barcode.png" alt="Barcode">
</div>
<div class="footer">"<?= $customer['scheme_name'] ?>" Expires on "<?= date('d-m-Y', strtotime($customer['to_subscription'])) ?>" </div>
<div class="footer">"<?= $customer['title'] ?>" Expires on "<?= date('d-m-Y', strtotime($customer['to_subscription'])) ?>" </div>
</div>
<?php endforeach; ?>
</body>

View File

@ -16,34 +16,49 @@
<!-- <table id="alternative-page-datatable" class="table table-borderless table-hover table-centered m-0"> -->
<!-- <table class="table table-borderless table-hover table-centered m-0"> -->
<!-- <table id="basic-datatable" class="table dt-responsive w-100"> -->
<table id="scroll-horizontal-datatable_old" class="table w-100 nowrap">
<table id="scroll-horizontal-datatable_subcription" class="table w-100 nowrap">
<thead class="thead-light">
<tr>
<th hidden ></th>
<th>Scheme Name</th>
<th hidden></th>
<th>Invoice Number</th>
<th>Invoice Date</th>
<th>Customer Name</th>
<th>Subscription From</th>
<th>Subscription To</th>
<th>Mode</th>
</tr>
<!-- <th>Book Name</th>
<th>Quantity</th>
<th>Price</th>
<th>Discount</th>
<th>Tax</th> -->
<th>Status</th>
<th>Total</th>
<th align="center">Action</th>
</tr>
</thead>
<tbody>
<?php foreach ($subscriber as $value) :?>
<?php foreach ($invoice as $row): ?>
<tr>
<td hidden><?= $value['sub_id'];?></td>
<td><?= $value['title']; ?></td>
<td><?= $value['customer_name']; ?></td>
<td><?= $value['from_subscription']; ?></td>
<td><?= $value['to_subscription']; ?></td>
<td><?= $value['mode']; ?></td>
</tr>
<?php endforeach; ?>
<?php if ($row['invoice_type'] == 1): ?>
<td hidden><?= $row['invoice_id'] ?></td>
<td><?= $row['invoice_number']; ?></td>
<td><?= $row['invoice_date']; ?></td>
<td><?= $row['customer_name']; ?></td>
<td><?= $row['status']; ?></td>
<td> <span data-plugin="counterup"><?= $row['total_amount']; ?></span></td>
<td><a href="<?= "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'] == 1): ?>
<a href="<?= "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'] == 2): ?>
<a href="<?= "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>&nbsp;
</tr>
<?php endif; ?>
<?php endforeach; ?>
</tbody>
</table>
<!-- Address Print Popup (Modal) -->
<!-- Scheme List Modal -->
<!-- Scheme List Modal -->
<!-- Create a modal for scheme selection -->
@ -62,21 +77,23 @@
<!-- ... Inside the modal in subscriber_list.php ... -->
<form action="<?= base_url('subscription/download_details'); ?>" method="post">
<div class="form-group">
<?php
$uniqueSchemes = []; // Array to track unique scheme names
foreach ($subscriber as $scheme) :
// Check if the scheme name is already in the unique list
if (!in_array($scheme['title'], $uniqueSchemes)) {
$uniqueSchemes[] = $scheme['title']; // Add to unique list
?>
<div class="form-check">
<input class="form-check-input" type="radio" name="selected_scheme" value="<?= $scheme['title']; ?>">
<label class="form-check-label"><?= $scheme['title']; ?></label>
</div>
<?php
}
endforeach;
?>
<div class="form-group">
<?php
$uniqueSchemes = [];
foreach ($subscriber as $scheme) :
if (!in_array($scheme['title'], $uniqueSchemes)) {
$uniqueSchemes[] = $scheme['title'];
?>
<div class="form-check">
<input class="form-check-input" type="checkbox" name="selected_schemes[]" value="<?= $scheme['title']; ?>">
<label class="form-check-label"><?= $scheme['title']; ?></label>
</div>
<?php
}
endforeach;
?>
</div>
</div>
<button type="submit" class="btn btn-primary">Download Details</button>
</form>
@ -90,14 +107,15 @@
</div> <!-- end card body-->
</div> <!-- end card -->
</div><!-- end col-->
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script>
$(document).ready(function() {
$('#scroll-horizontal-datatable_old').DataTable({
$('#scroll-horizontal-datatable_subcription').DataTable({
"order": [[0, "desc"]] // 0 is the column index
});