Sales : GWM
This commit is contained in:
parent
46a14dd422
commit
b3c03ff6ba
@ -412,6 +412,7 @@ $routes->get('deleteAttachment', 'Sales::deleteAttachment');
|
|||||||
$routes->post('saveAttachment', 'Sales::saveAttachment');
|
$routes->post('saveAttachment', 'Sales::saveAttachment');
|
||||||
$routes->get('sales_invoice', 'Sales::sales_invoice');
|
$routes->get('sales_invoice', 'Sales::sales_invoice');
|
||||||
$routes->post('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');
|
$routes->post('updateInvRecQty', 'Sales::updateInvRecQty');
|
||||||
|
|
||||||
// transporter Routes
|
// transporter Routes
|
||||||
|
|||||||
@ -8,6 +8,8 @@ use App\Models\Ipinvoice_model;
|
|||||||
use App\Models\Ipattachment_model;
|
use App\Models\Ipattachment_model;
|
||||||
require_once 'vendor/autoload.php';
|
require_once 'vendor/autoload.php';
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
|
||||||
|
|
||||||
class Sales extends BaseController
|
class Sales extends BaseController
|
||||||
{
|
{
|
||||||
@ -40,6 +42,7 @@ class Sales extends BaseController
|
|||||||
|
|
||||||
return $formattedNumber;
|
return $formattedNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function sales_dashboard()
|
public function sales_dashboard()
|
||||||
{
|
{
|
||||||
$this->global['pageTitle'] = 'Sales Dashboard';
|
$this->global['pageTitle'] = 'Sales Dashboard';
|
||||||
@ -97,12 +100,12 @@ class Sales extends BaseController
|
|||||||
{
|
{
|
||||||
$toDate = date('Y-m-d');
|
$toDate = date('Y-m-d');
|
||||||
$fromDate = date('Y-m-d', strtotime('-90 days', strtotime($toDate)));
|
$fromDate = date('Y-m-d', strtotime('-90 days', strtotime($toDate)));
|
||||||
} elseif ($this->request->getMethod() === 'POST') {
|
} elseif ($this->request->getMethod() === 'POST') {
|
||||||
$fromDate = $this->request->getPost('fromDate');
|
$fromDate = $this->request->getPost('fromDate');
|
||||||
$toDate = $this->request->getPost('toDate');
|
$toDate = $this->request->getPost('toDate');
|
||||||
$fromDate = date('Y-m-d', strtotime($fromDate));
|
$fromDate = date('Y-m-d', strtotime($fromDate));
|
||||||
$toDate = date('Y-m-d', strtotime($toDate));
|
$toDate = date('Y-m-d', strtotime($toDate));
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->global['pageTitle'] = 'Sales Invoice';
|
$this->global['pageTitle'] = 'Sales Invoice';
|
||||||
$data['sales_invoice'] = $this->ipinvoice_model->saleInvoiceListing($fromDate , $toDate);
|
$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);
|
$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
|
// View Invoice
|
||||||
function ViewInvoice($InvoiceNO = '')
|
function ViewInvoice($InvoiceNO = '')
|
||||||
|
|||||||
@ -59,12 +59,7 @@
|
|||||||
<script src="<?php echo base_url(); ?>public/new_assets/js/pages/form-wizard.init.js"></script>
|
<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>
|
<script>
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
$('select').addClass('form-control');
|
$('select').addClass('form-control');
|
||||||
@ -73,7 +68,7 @@
|
|||||||
autoclose: true,
|
autoclose: true,
|
||||||
orientation: 'bottom',
|
orientation: 'bottom',
|
||||||
format: 'dd-mm-yyyy',
|
format: 'dd-mm-yyyy',
|
||||||
todayHighlight: true });
|
todayHighlight: true });
|
||||||
form = $(".form-date-search")
|
form = $(".form-date-search")
|
||||||
.datepicker({
|
.datepicker({
|
||||||
autoclose: true,
|
autoclose: true,
|
||||||
|
|||||||
@ -217,14 +217,7 @@
|
|||||||
/* Darker red on hover */
|
/* Darker red on hover */
|
||||||
color: white;
|
color: white;
|
||||||
}
|
}
|
||||||
.editableform{
|
|
||||||
position: relative;
|
|
||||||
}
|
|
||||||
.editableform .editable-buttons{
|
|
||||||
position: absolute;
|
|
||||||
right: 0;
|
|
||||||
top: 0;
|
|
||||||
}
|
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
|||||||
@ -190,6 +190,9 @@
|
|||||||
<div class="card">
|
<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;"
|
<form class="Date-filter-form" style="margin-top: 14px;margin-bottom: -11px;margin-left: 33px;"
|
||||||
method="post" action="<?= base_url('sales_invoice'); ?>">
|
method="post" action="<?= base_url('sales_invoice'); ?>">
|
||||||
|
|
||||||
@ -213,7 +216,16 @@
|
|||||||
|
|
||||||
|
|
||||||
<div class="error" id="error"></div>
|
<div class="error" id="error"></div>
|
||||||
|
|
||||||
|
|
||||||
</form>
|
</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>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.18.0/xlsx.full.min.js"></script>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
|
|
||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
// Handle click on the <a> tag
|
|
||||||
$(document).on('click', '.editable-field', function (e) {
|
$(document).on('click', '.editable-field', function (e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
const $link = $(this);
|
const $link = $(this);
|
||||||
@ -424,6 +437,46 @@ $(document).ready(function () {
|
|||||||
$editContainer.hide();
|
$editContainer.hide();
|
||||||
$link.show();
|
$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() {
|
$(document).ready(function() {
|
||||||
// Initialize the DataTable
|
// Initialize the DataTable
|
||||||
var table = $('#datatable-buttosns').DataTable({
|
var table = $('#datatable-buttosns').DataTable({
|
||||||
dom: 'Blfrtip',
|
|
||||||
buttons: [
|
|
||||||
'excel', 'pdf'
|
|
||||||
],
|
|
||||||
pageLength: 10,
|
pageLength: 10,
|
||||||
lengthMenu: [[10, 20, 30, 50, -1],[10, 20, 30, 50, "All"]],
|
lengthMenu: [[10, 20, 30, 50, -1],[10, 20, 30, 50, "All"]],
|
||||||
responsive: false,
|
responsive: false,
|
||||||
@ -566,7 +617,7 @@ $(document).ready(function () {
|
|||||||
invoice_attachment_id: $(button).attr('id')
|
invoice_attachment_id: $(button).attr('id')
|
||||||
},
|
},
|
||||||
success: function(response) {
|
success: function(response) {
|
||||||
console.log(response);
|
window.location.reload();
|
||||||
},
|
},
|
||||||
error: function() {
|
error: function() {
|
||||||
|
|
||||||
|
|||||||
@ -1729,13 +1729,6 @@
|
|||||||
exportOptions: {
|
exportOptions: {
|
||||||
columns: ':not(:last-child)' // Exclude the last column
|
columns: ':not(:last-child)' // Exclude the last column
|
||||||
}
|
}
|
||||||
},
|
|
||||||
{
|
|
||||||
extend: 'pdf',
|
|
||||||
text: 'PDF',
|
|
||||||
exportOptions: {
|
|
||||||
columns: ':not(:last-child)' // Exclude the last column
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
pageLength: 10,
|
pageLength: 10,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user