Sales : GWM

This commit is contained in:
Gowtham M 2024-12-24 17:34:05 +05:30
parent 46a14dd422
commit b3c03ff6ba
6 changed files with 125 additions and 33 deletions

View File

@ -412,6 +412,7 @@ $routes->get('deleteAttachment', 'Sales::deleteAttachment');
$routes->post('saveAttachment', 'Sales::saveAttachment');
$routes->get('sales_invoice', 'Sales::sales_invoice');
$routes->post('sales_invoice', 'Sales::sales_invoice');
$routes->post('download_sales_invoice', 'Sales::download_sales_invoice');
$routes->post('updateInvRecQty', 'Sales::updateInvRecQty');
// transporter Routes

View File

@ -8,6 +8,8 @@ use App\Models\Ipinvoice_model;
use App\Models\Ipattachment_model;
require_once 'vendor/autoload.php';
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
class Sales extends BaseController
{
@ -40,6 +42,7 @@ class Sales extends BaseController
return $formattedNumber;
}
public function sales_dashboard()
{
$this->global['pageTitle'] = 'Sales Dashboard';
@ -97,12 +100,12 @@ class Sales extends BaseController
{
$toDate = date('Y-m-d');
$fromDate = date('Y-m-d', strtotime('-90 days', strtotime($toDate)));
} elseif ($this->request->getMethod() === 'POST') {
$fromDate = $this->request->getPost('fromDate');
$toDate = $this->request->getPost('toDate');
$fromDate = date('Y-m-d', strtotime($fromDate));
$toDate = date('Y-m-d', strtotime($toDate));
}
} elseif ($this->request->getMethod() === 'POST') {
$fromDate = $this->request->getPost('fromDate');
$toDate = $this->request->getPost('toDate');
$fromDate = date('Y-m-d', strtotime($fromDate));
$toDate = date('Y-m-d', strtotime($toDate));
}
$this->global['pageTitle'] = 'Sales Invoice';
$data['sales_invoice'] = $this->ipinvoice_model->saleInvoiceListing($fromDate , $toDate);
@ -114,6 +117,62 @@ class Sales extends BaseController
$this->loadViews("sales_invoice", $this->global, $data, NULL);
}
public function download_sales_invoice()
{
// Fetch data from the model
$fromDate = $this->request->getPost('fromDate');
$toDate = $this->request->getPost('toDate');
$fromDate = date('Y-m-d', strtotime($fromDate));
$toDate = date('Y-m-d', strtotime($toDate));
$sales_invoice = $this->ipinvoice_model->saleInvoiceListing($fromDate, $toDate);
// Start building the table
$html = '<table id="datatable-buttosns" class="table dt-responsive nowrap w-100">
<thead>
<tr>
<th>Invoice Date</th>
<th>Invoice No</th>
<th>Client Name</th>
<th>Product</th>
<th>Quantity</th>
<th>Rec Qty</th>
<th>Rate</th>
<th>Sub Total</th>
<th>GST</th>
<th>Total</th>
<th>Status</th>
</tr>
</thead>
<tbody>';
foreach ($sales_invoice as $invoice) {
$subtotal = $invoice->item_price * $invoice->item_quantity;
$cgst_amount = ($subtotal * $invoice->cgst) / 100;
$sgst_amount = ($subtotal * $invoice->sgst) / 100;
$total = $subtotal + $cgst_amount + $sgst_amount;
$html .= '<tr>
<td>' . date('d-m-Y', strtotime($invoice->invoice_date_created)) . '</td>
<td>' . $invoice->invoice_number . '</td>
<td>' . $invoice->client_name . '</td>
<td>' . $invoice->item_name . '</td>
<td>' . number_format($invoice->item_quantity, 2, '.', ',') . '</td>
<td>' . (!empty($invoice->received_qty) ? $invoice->received_qty : '') . '</td>
<td>' . number_format($invoice->item_price, 2, '.', ',') . '</td>
<td>' . number_format($subtotal, 2, '.', ',') . '</td>
<td>' . number_format($cgst_amount + $sgst_amount, 2, '.', ',') . '</td>
<td>' . number_format($total, 2, '.', ',') . '</td>
<td>' . $invoice->status . '</td>
</tr>';
}
$html .= '</tbody></table>';
return $this->response->setJSON(['html' => $html]);
}
// View Invoice
function ViewInvoice($InvoiceNO = '')

View File

@ -59,12 +59,7 @@
<script src="<?php echo base_url(); ?>public/new_assets/js/pages/form-wizard.init.js"></script>
<!-- Plugins js -->
<script src="<?php echo base_url(); ?>public/new_assets/libs/moment/min/moment.min.js"></script>
<script src="<?php echo base_url(); ?>public/new_assets/libs/x-editable/bootstrap-editable/js/bootstrap-editable.min.js"></script>
<!-- Init js-->
<script src="<?php echo base_url(); ?>public/new_assets/js/pages/form-xeditable.init.js"></script>
<script>
$(document).ready(function() {
$('select').addClass('form-control');
@ -73,7 +68,7 @@
autoclose: true,
orientation: 'bottom',
format: 'dd-mm-yyyy',
todayHighlight: true });
todayHighlight: true });
form = $(".form-date-search")
.datepicker({
autoclose: true,

View File

@ -217,14 +217,7 @@
/* Darker red on hover */
color: white;
}
.editableform{
position: relative;
}
.editableform .editable-buttons{
position: absolute;
right: 0;
top: 0;
}
</style>
<style>

View File

@ -190,6 +190,9 @@
<div class="card">
<div class="row">
<div class="col-md-10">
<form class="Date-filter-form" style="margin-top: 14px;margin-bottom: -11px;margin-left: 33px;"
method="post" action="<?= base_url('sales_invoice'); ?>">
@ -213,7 +216,16 @@
<div class="error" id="error"></div>
</form>
</div>
<div class="col-md-2 text-right" style="padding-right: 36px !important;">
<button class="btn btn-secondary" id="excel-download" style="margin-top: 14px; margin-bottom: -11px; " type="button"><span>Excel</span></button>
</div>
</div>
@ -367,12 +379,13 @@
</div>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.18.0/xlsx.full.min.js"></script>
<script>
$(document).ready(function () {
// Handle click on the <a> tag
$(document).on('click', '.editable-field', function (e) {
e.preventDefault();
const $link = $(this);
@ -424,6 +437,46 @@ $(document).ready(function () {
$editContainer.hide();
$link.show();
});
document.getElementById("excel-download").addEventListener("click", function () {
const fromDate = document.getElementById("fromDate").value;
const toDate = document.getElementById("toDate").value;
if (!fromDate || !toDate) {
alert("Please select both From and To dates.");
return;
}
$('#loader').show();
$.ajax({
url: '<?php echo base_url() ?>download_sales_invoice',
method: 'POST',
data: { fromDate: fromDate, toDate: toDate },
success: function (response) {
const html = response.html;
// Create a temporary DOM element to hold the table HTML
const tempDiv = document.createElement('div');
tempDiv.innerHTML = html;
// Get the table
const table = tempDiv.querySelector('table');
// Use SheetJS to create an Excel file from the HTML table
const wb = XLSX.utils.table_to_book(table, {sheet: "Invoice Data"});
// Generate Excel file and trigger download
XLSX.writeFile(wb, 'Sales_Invoice_Report.xlsx');
$('#loader').hide();
},
error: function (xhr) {
$('#loader').hide();
alert('Failed to Download.');
}
});
});
});
@ -431,10 +484,8 @@ $(document).ready(function () {
$(document).ready(function() {
// Initialize the DataTable
var table = $('#datatable-buttosns').DataTable({
dom: 'Blfrtip',
buttons: [
'excel', 'pdf'
],
pageLength: 10,
lengthMenu: [[10, 20, 30, 50, -1],[10, 20, 30, 50, "All"]],
responsive: false,
@ -566,7 +617,7 @@ $(document).ready(function () {
invoice_attachment_id: $(button).attr('id')
},
success: function(response) {
console.log(response);
window.location.reload();
},
error: function() {

View File

@ -1729,13 +1729,6 @@
exportOptions: {
columns: ':not(:last-child)' // Exclude the last column
}
},
{
extend: 'pdf',
text: 'PDF',
exportOptions: {
columns: ':not(:last-child)' // Exclude the last column
}
}
],
pageLength: 10,