ria/app/Views/sales_dashboard.php
2025-05-17 15:18:50 +05:30

472 lines
21 KiB
PHP
Executable File

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
<style>
</style>
<div class="content-page">
<div class="content">
<!-- Start Content-->
<div class="container-fluid">
<!-- start page title -->
<div>
<div class="row">
<div class="col-12">
<div class="page-title-box page-title-box-alt">
</div>
</div>
</div>
<div class="row">
<!-- Today Sales -->
<div class="col-lg-4 col-xl-4">
<div class="card">
<div class="card-body" style="height: 150px;">
<div class="d-flex justify-content-between align-items-center">
<h3 class="mb-0">Today Sales</h3>
<h4 class="mb-0 mt-0">
<span data-plugin="counterup" class="card_font_colorset_green" style="font-size: 20.7215px;">
<?php echo $today_sales->Invoices ?>
</span> Invoices
</h4>
</div>
<div class="d-flex justify-content-between align-items-center mt-3">
<div class="text-left">
<p class="text-muted mb-0">Qty in Kgs</p>
<h4 class="mb-1 mt-0">
<span data-plugin="counterup" class="card_font_colorset_green"><?php echo $today_sales->Qty ?></span>
</h4>
</div>
<div class="text-left">
<p class="text-muted mb-0">Sales in Rs.</p>
<h4 class="mb-1 mt-0">
<span class="card_font_colorset_green"><?php echo $today_sales->Sales; ?></span>
</h4>
</div>
</div>
</div>
</div>
</div>
<!-- This Month Sales -->
<div class="col-lg-4 col-xl-4">
<div class="card">
<div class="card-body" style="height: 150px;">
<div class="d-flex justify-content-between align-items-center">
<h3 class="mb-0">This Month Sales</h3>
<h4 class="mb-0 mt-0">
<span data-plugin="counterup" class="card_font_colorset_bule" style="font-size: 20.7215px;">
<?php echo $this_month_sales->Invoices ?>
</span> Invoices
</h4>
</div>
<div class="d-flex justify-content-between align-items-center mt-3">
<div class="text-left">
<p class="text-muted mb-0">Qty in Kgs</p>
<h4 class="mb-1 mt-0">
<span data-plugin="counterup" class="card_font_colorset_bule"><?php echo $this_month_sales->Qty ?></span>
</h4>
</div>
<div class="text-left">
<p class="text-muted mb-0">Sales in Rs.</p>
<h4 class="mb-1 mt-0">
<span class="card_font_colorset_bule"><?php echo $this_month_sales->Sales; ?></span>
</h4>
</div>
</div>
</div>
</div>
</div>
<!-- This Year Sales -->
<div class="col-lg-4 col-xl-4">
<div class="card">
<div class="card-body" style="height: 150px;">
<div class="d-flex justify-content-between align-items-center">
<h3 class="mb-0">This Year Sales</h3>
<h4 class="mb-0 mt-0">
<span data-plugin="counterup" class="card_font_colorset_red" style="font-size: 20.7215px;">
<?php echo $this_year_sales->Invoices ?>
</span> Invoices
</h4>
</div>
<div class="d-flex justify-content-between align-items-center mt-3">
<div class="text-left">
<p class="text-muted mb-0">Qty in Kgs</p>
<h4 class="mb-1 mt-0">
<span data-plugin="counterup" class="card_font_colorset_red"><?php echo $this_year_sales->Qty ?></span>
</h4>
</div>
<div class="text-left">
<p class="text-muted mb-0">Sales in Rs.</p>
<h4 class="mb-1 mt-0">
<span class="card_font_colorset_red"><?php echo $this_year_sales->Sales; ?></span>
</h4>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-xl-12 col-md-12">
<div class="card">
<div class="card-body">
<h4 class="header-title">This Month Stock Closing</h4>
<div class="d-flex justify-content-between align-items-center">
<div>
<a class="btn btn-primary btn-sm px-2" href="<?php echo base_url(); ?>sales_dashboard?stock=resin">Resin</a>
<a class="btn btn-secondary btn-sm px-2" href="<?php echo base_url(); ?>sales_dashboard?stock=bag">Bag</a>
<a class="btn btn-success btn-sm px-2" href="<?php echo base_url(); ?>sales_dashboard?stock=gas">Gas</a>
<a class="btn btn-danger btn-sm px-2" href="<?php echo base_url(); ?>sales_dashboard?stock=diesel">Diesel</a>
</div>
<div>
<button class="btn btn-primary btn-sm px-2" id="xldwnldStockDbd">Excel</button>
</div>
</div>
<?php if(isset($givenStock)){
switch ($givenStock) {
case 'gas':
$href = base_url('gasStockDetails');
break;
case 'diesel':
$href = base_url('dieselMachineDetails');
break;
case 'resin':
$href = base_url('resinStockDetails');
break;
case 'bag':
$href = base_url('bagStockDetails');
break;
default:
$href = base_url('resinStockDetails');
}
}?>
<table id="stockClosing" class="table dt-responsive nowrap w-100">
<thead>
<?php if (is_array($stock[0]['header'])) { ?>
<tr>
<th>S.NO</th>
<th>Material Code</th>
<th>Material Description</th>
<th>Unit Of Measurement</th>
<th>Closing Stock</th>
</tr>
<?php } else { ?>
<tr>
<th>S.NO</th>
<th>Stock</th>
<th>Closing Stock</th>
</tr>
<?php } ?>
</thead>
<tbody>
<?php if (is_array($stock[0]['header'])) { ?>
<?php foreach ($stock[2]['body'] as $index => $body) { ?>
<tr>
<td> <?php echo $index + 1 ?></td>
<td> <?php echo $stock[1]['materialCode'][$index] ?> </td>
<td> <a href="<?=$href?>">
<?php echo $stock[0]['header'][$index] ?>
</a>
</td>
<td><?php echo $stock[3]['uom'][$index] ?> </td>
<td> <?php echo $body ?></td>
</tr>
<?php } ?>
<?php } else { ?>
<tr>
<td> 1 </td>
<td>
<a href="<?=$href?>">
<?php echo $stock[0]['header'] ?>
</a>
</td>
<td> <?php echo $stock[1]['body'] ?></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-xl-12 col-md-12">
<div class="card">
<div class="card-body">
<h4 class="header-title">This Year Sales Trend</h4>
<canvas id="salesComparisonChart" height="60"></canvas>
</div>
</div>
</div>
</div>
<!-- <div class="row">
<div class="col-12">
<div class="page-title-box page-title-box-alt">
<h4 class="page-title">Invoices Table</h4>
</div>
</div>
</div> -->
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-body" style="overflow-x:scroll;">
<!-- <div class="row">
<div class="col-12">
<div class="page-title-box page-title-box-alt">
<h4 class="page-title">Invoices Table</h4>
</div>
</div>
</div> -->
<table id="datatable-buttonss" class="table dt-responsive nowrap w-100">
<thead>
<tr>
<th>Invoice No.</th>
<th>Invoice Date</th>
<th>Invoice Time</th>
<th>Vehicle No.</th>
<th>Product</th>
<th>Client</th>
<th>Quantity</th>
<th>Rate</th>
<th>Value</th>
<th>CGST</th>
<th>SGST</th>
<th>IGST</th>
<th>TCS</th>
<th>Total</th>
</tr>
</thead>
<tbody>
<?php foreach ($get_today_invoices as $invoice) : ?>
<tr>
<td><?php echo $invoice['Invoice No.']; ?></td>
<td><?php echo $invoice['Invoice Date']; ?></td>
<td><?php echo $invoice['Invoice Time']; ?></td>
<td><?php echo $invoice['Vehicle No.']; ?></td>
<td><?php echo $invoice['Product']; ?></td>
<td><?php echo $invoice['Client']; ?></td>
<td align="right"> <?php echo number_format($invoice['Quantity'], 2, '.', ',') ?></td>
<td align="right"> <?php echo number_format($invoice['Rate'], 2, '.', ',') ?></td>
<td align="right"> <?php echo number_format($invoice['Value'], 2, '.', ',') ?></td>
<td align="right"> <?php echo number_format($invoice['CGST'], 2, '.', ',') ?></td>
<td align="right"> <?php echo number_format($invoice['SGST'], 2, '.', ',') ?></td>
<td align="right"> <?php echo number_format($invoice['IGST'], 2, '.', ',') ?></td>
<td align="right"> <?php echo number_format($invoice['TCS'], 2, '.', ',') ?></td>
<td align="right"> <?php echo number_format($invoice['Total'], 2, '.', ',') ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<br>
</div> <!-- end card body-->
</div> <!-- end card -->
</div><!-- end col-->
</div>
</div>
<!-- end row -->
<!-- end page title -->
</div> <!-- container -->
</div> <!-- content -->
</div>
<script>
$(document).ready(function() {
$('#datatable-buttonss').DataTable({
dom: 'Blfrtip',
buttons: [
'excel', 'pdf'
],
pageLength: 10,
lengthMenu: [
[10, 20, 30, 50, -1],
[10, 20, 30, 50, "All"]
],
responsive: false,
order: false,
language: {
paginate: {
next: '<i class="fas fa-angle-right"></i>', // Next button icon
previous: '<i class="fas fa-angle-left"></i>' // Previous button icon
}
}
});
});
</script>
<script>
$(document).ready(function() {
var table = $('#stockClosing').DataTable({
dom: 'Brtip', // Remove length and search inputs
lengthChange: false,
searching: false,
buttons: [''],
responsive: true,
order: false,
language: {
paginate: {
next: '<i class="fas fa-angle-right"></i>',
previous: '<i class="fas fa-angle-left"></i>'
}
}
});
// Move Excel button to custom div
// table.buttons().container().appendTo('#exportExcelBtn');
});
</script>
<script>
const currentYearSales = <?php echo json_encode($currentYearSales); ?>;
const lastYearSales = <?php echo json_encode($lastYearSales); ?>;
const ctx = document.getElementById('salesComparisonChart').getContext('2d');
const salesComparisonChart = new Chart(ctx, {
type: 'bar', // Bar chart
data: {
labels: ['April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December', 'January', 'February', 'March'], // Months of the year
datasets: [{
label: 'Current Year Sales',
data: currentYearSales,
backgroundColor: 'rgba(86, 166, 75, 0.6)', // Green color with opacity
borderColor: 'rgb(86, 166, 75)', // Green border color
borderWidth: 1,
},
{
label: 'Last Year Sales',
data: lastYearSales,
backgroundColor: 'rgba(173, 3, 23, 0.6)', // Red color with opacity
borderColor: 'rgb(173, 3, 23)', // Red border color
borderWidth: 1,
}
]
},
options: {
scales: {
y: {
beginAtZero: true, // Ensures the y-axis starts at zero
ticks: {
stepSize: 10000000, // Sets the interval between ticks
callback: function(value) {
return value.toLocaleString('en-IN'); // Return plain number without formatting
}
},
min: 0, // Minimum value for y-axis
max: 50000000 // Maximum value for y-axis
}
},
plugins: {
legend: {
display: true,
labels: {
color: '#495057' // Color of legend text
}
}
}
}
});
</script>
<script>
$(document).ready(function() {
function exportTableToExcel(tableID, filename = '') {
let table = document.getElementById(tableID);
let cloneTable = table.cloneNode(true); // Clone the table to modify
// Remove hidden rows
$(cloneTable).find('tr').filter(function() {
return $(this).css('display') === 'none';
}).remove();
// Remove hidden columns
$(cloneTable).find('th, td').each(function() {
if ($(this).css('display') === 'none') {
$(this).remove();
}
});
let ws = XLSX.utils.table_to_sheet(cloneTable);
// Set column width to 10 for all columns
let colCount = 0;
$(cloneTable).find('tr').each(function() {
let count = $(this).find('th, td').length;
if (count > colCount) colCount = count;
});
let wscols = [];
for (let i = 0; i < colCount; i++) {
wscols.push({ wch: 10 }); // Set width of 10 for all columns
}
ws['!cols'] = wscols;
let wb = XLSX.utils.book_new(); // Create a new workbook
XLSX.utils.book_append_sheet(wb, ws, 'Sheet1'); // Append sheet to workbook
XLSX.writeFile(wb, filename || 'export.xlsx'); // Save the file
}
let tableId = 'stockClosing';
document.getElementById('xldwnldStockDbd').addEventListener('click', function() {
<?php $month = date('d-m-Y'); ?>
exportTableToExcel(tableId, 'Stock Closing-<?= $month ?>.xlsx');
})
})
</script>