ria/app/Views/stock/dustAndRoughStockDetails.php
2025-03-27 18:48:26 +05:30

987 lines
34 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<style type="text/css">
.num {
text-align: right;
}
.fht-table,
.fht-table thead,
.fht-table tfoot,
.fht-table tbody,
.fht-table tr,
.fht-table th,
.fht-table td {
margin: 0;
}
.fht-table td {
text-align: center;
}
.grab {
cursor: grab; /* Default open-hand cursor */
}
.grab:active {
cursor: grabbing; /* Closed-hand cursor when dragging */
}
/* .fht-table td[contenteditable="true"] {
background-color: lightyellow;
color:rgb(13, 7, 7);
} */
.fht-table td:hover {
background-color: rgb(170, 222, 167);
color:rgb(2, 2, 2);
transform: scale(1.25); /* Increases size by 25% */
transition: transform 0.5s ease-in-out; /* Smooth scaling effect */
}
.fht-table tr:hover {
background-color: rgb(170, 222, 167);
color:rgb(2, 2, 2);
}
.fht-table {
border: 0 none;
height: auto;
width: auto;
border-collapse: collapse;
border-spacing: 0;
/*table-layout: fixed; Algoritmo de distribucion fijo */
white-space: nowrap;
}
.fht-table th,
.fht-table td {
overflow: hidden;
}
.fht-table-wrapper,
.fht-table-wrapper .fht-thead,
.fht-table-wrapper .fht-tfoot,
.fht-table-wrapper .fht-fixed-column .fht-tbody,
.fht-table-wrapper .fht-fixed-body .fht-tbody,
.fht-table-wrapper .fht-tbody {
overflow: hidden;
position: relative;
}
.fht-table-wrapper .fht-fixed-body .fht-tbody,
.fht-table-wrapper .fht-tbody {
overflow: auto;
}
.fht-table-wrapper .fht-table .fht-cell {
overflow: hidden;
height: 1px;
}
.fht-table-wrapper .fht-fixed-column,
.fht-table-wrapper .fht-fixed-body {
top: 0;
left: 0;
position: absolute;
}
.fht-table-wrapper .fht-fixed-column {
z-index: 1;
}
.fht-fixed-body .fht-thead table {
margin-right: 20px;
border: 0 none;
}
/*For Examples*/
.ContenedorTabla {
height: 500px;
margin: 0 auto;
overflow: auto;
width: auto;
position: relative;
}
.header,
.main {
display: inline-block;
height: auto;
width: 100%;
}
.titulosHeader {
border-bottom: 1px solid #e8bb25;
height: auto;
margin-bottom: 10px;
padding-bottom: 8px;
padding-top: 8px;
width: 100%;
}
._Separador {
background-color: #fff;
height: 12px;
border-left: 1px solid #ccc;
border-right: 1px solid #ccc;
width: 7px;
}
._Separador div {
width: 4px;
}
/*style excel*/
.excel_cell {
border: 1px solid #CCC;
color: #222;
text-align: center;
font-size: 13px;
font-weight: normal;
padding: 4px;
white-space: pre-line;
empty-cells: show;
}
._cell_header {
background-color: #EEE;
}
._cell_Default {
background-color: #FFF;
text-align: left;
}
.excel_cell div {
width: 30px;
height: 20px;
}
.celda_encabezado_general {
background-color: #50bbd9;
border: 1px solid #ccc;
color: #ffffff;
font-weight: bold;
padding: 6px 10px;
text-align: center;
}
.celda_encabezado_total {
background-color: #ffffff !important;
border: 1px solid #ffffff;
color: #ffffff !important;
font-weight: bold;
padding: 6px 10px;
text-align: center;
}
.celda_normal {
/*background-color: #fff;*/
/* <!-- ad9271 into ffffff brown-light to green-light --> */
text-align: center;
border: 1px solid #ccc;
padding: 10px 6px;
}
/* Make entire thead sticky */
.fht-table thead {
position: sticky;
top: 0;
z-index: 20;
/* Ensure the entire header stays above table rows */
background-color: #50bbd9;
/* Header background color */
}
.dropdown-menu {
z-index: 25;
}
/* Ensure each <th> in thead stays sticky */
.fht-table thead th {
position: sticky;
top: 0;
z-index: 11;
/* Higher than table rows but lower than first column */
background-color: #50bbd9;
/* Green background */
color: #ffffff;
border: 1px solid #ddd;
padding: 10px;
}
/* Sticky First Column */
.fht-table th:nth-child(1),
.fht-table td:nth-child(1) {
position: sticky;
left: 0;
background-color: #50bbd9;
z-index: 15;
/* Ensures it stays above other cells */
border-right: 2px solid #ddd;
color: #ffffff;
}
/* Table Wrapper for Scrolling */
.table-responsive {
overflow-x: auto;
overflow-y: auto;
max-height: 500px;
max-width: 100%;
position: relative;
}
/* Adjust heights based on screen zoom */
@media only screen and (min-height: 1400px) { /* Approximate Zoom < 100% */
.table-responsive { max-height: 425px; }
}
@media only screen and (min-height: 1200px) { /* Approximate Zoom ~ 90% */
.table-responsive { max-height: 500px; }
}
@media only screen and (min-height: 1000px) { /* Approximate Zoom ~ 80% */
.table-responsive { max-height: 600px; }
}
@media only screen and (min-height: 800px) { /* Approximate Zoom ~ 75% */
.table-responsive { max-height: 650px; }
}
td {
min-width: 100px;
max-width: 100px;
}
tfoot tr {
background-color:rgb(235, 236, 203);
}
body[data-layout-mode = horizontal] .container-fluid{
max-width: 100%;
}
.card-body{
padding-top : 0;
padding-bottom : 0;
}
.card{ margin-bottom: 5px;}
</style>
<div class="content-page">
<div class="content">
<!-- Start Content-->
<div class="container-fluid">
<!-- start page title -->
<div>
<div class="row">
<div class="col-6">
<div class="page-title-box page-title-box-alt">
<div class="page-title-right">
<ol class="breadcrumb m-0">
<li class="breadcrumb-item"><a href="javascript: void(0);">Stocks</a></li>
<li class="breadcrumb-item active">
<h4 class="page-title">Dust And Rough Stock Details </h4>
</li>
</ol>
</div>
</div>
</div>
<div class="col-6 text-right">
<!-- Right-aligned buttons or links can be added here -->
</div>
</div>
<div class="row" align="center">
<div class="col-12">
<div class="card" id="fullscreenDiv">
<div class="card-body" >
<form id="changeMonthForm" action="<?= base_url('dustAndRoughStockDetails'); ?>" method="post">
<div class="row">
<?php $today = date('M-Y'); ?>
<div class="col-3">
</div>
<div class="col-2 mt-2">
<input type="text" name="month" id="month" value="<?php echo "$month" ?>"
class="form-control "
data-provide="datepicker"
data-date-format="M-yyyy"
data-date-min-view-mode="1" readonly
style="max-width: 175px;">
</div>
<div class="col-3 text-right d-flex" style="justify-content: end;" >
<input type="text" id="searchInput" placeholder="Search..."
class="mt-2"
style="padding: 8px;margin-bottom: 10px;width: 150px;border: 1px solid #ccc;
border-radius: 5px;margin-right:15px;">
<i class="fa fa-table btn-lg mt-2"
title="Date Range Filter"
style="font-size: x-large; cursor:pointer;"
data-toggle="modal"
data-target="#filterModalId">
</i>
<i class="fa fa-download btn-lg mt-2"
title="Excel Download"
style="font-size: x-large; cursor:pointer;"
id="dustAndRoughStockExport">
</i>
<i class="fe-maximize noti-icon btn-lg mt-2"
title="Full Screen"
style="font-size: x-large; cursor:pointer;"
onclick="toggleDivFullscreen()" >
</i>
<i class="fa fa-save btn-lg mt-2"
title="Save"
style="font-size: x-large; cursor:pointer;"
id="saveId"
>
</i>
</div>
<div class="col-2">
</div>
</div>
</form>
<div class="table-responsive" id="table-responsive">
<table style="width: 700px;" id="dustAndRoughStockDetailsTableId" class="fht-table ">
<thead class="celda_encabezado_general" style="padding: 10px;">
<tr>
<th
style="width: 100px;"
class="celda_encabezado_general" rowspan="2" colspan="1">Date </th>
<th class="celda_encabezado_general" colspan="1">Final Rough </th>
<th class="celda_encabezado_general" colspan="1">Dust </th>
<th class="celda_encabezado_general" rowspan="2" colspan="1">Total </th>
</tr>
<tr>
<th class="celda_encabezado_general" colspan="1">+16 Mesh </th>
<th class="celda_encabezado_general" colspan="1">10 Ton Dryer </th>
</tr>
</thead>
<tbody style="background-color: #fff;" >
<?php
if(!empty($dustAndRoughStockDetails)){
$summary = [] ;
foreach($dustAndRoughStockDetails as $dustAndRoughStockDetailsIndex => $dustAndRoughStockDetail){
?>
<tr
<?php
$currentDate = date('d-m-Y');
$dateInMonthDmYFormat=DateTime::createFromFormat('Y-m-d', $dustAndRoughStockDetail['date'])->format('d-m-Y');
if ($dateInMonthDmYFormat === $currentDate) { echo 'style="background: #cef0ad;"';}
?>
>
<td class="celda_normal">
<?php
echo date("d-m-Y", strtotime($dustAndRoughStockDetail['date']));
?>
</td>
<td class="celda_normal finalRough"
data-id="<?= $dustAndRoughStockDetail['date'] ?>"
oninput="finalRoughStockChange(this)"
contenteditable="true"
><?= $dustAndRoughStockDetail['finalRough'] ?? ' ' ?></td>
<td class="celda_normal dust"
data-id="<?= $dustAndRoughStockDetail['date'] ?>"
oninput="dustStockChange(this)"
contenteditable="true"
><?= $dustAndRoughStockDetail['dust'] ?? ' ' ?></td>
<td class="celda_normal total"
data-id="<?= $dustAndRoughStockDetail['date'] ?>"
><?= $dustAndRoughStockDetail['total'] ?? ' ' ?></td>
</tr>
<?php
//before closing inner loop
if (!isset($summary['finalRough'])) {
$summary['finalRough'] = 0 ;
$summary['dust'] = 0 ;
$summary['total'] = 0 ;
}
$summary['finalRough'] += $dustAndRoughStockDetail['finalRough'] == "-" ? 0 : (float) $dustAndRoughStockDetail['finalRough'] ;
$summary['dust'] += $dustAndRoughStockDetail['dust'] == "-" ? 0 : (float) $dustAndRoughStockDetail['dust'] ;
$summary['total'] += $dustAndRoughStockDetail['total'] == "-" ? 0 : (float) $dustAndRoughStockDetail['total'] ;
} ?>
<tfoot>
<tr>
<td style="background-color:rgb(189, 9, 6); color:#ffff;"> Total </td>
<td class="celda_normal "> <b> <?=$summary['finalRough']?> </b> </td>
<td class="celda_normal "> <b> <?=$summary['dust']?> </b> </td>
<td class="celda_normal "> <b> <?=$summary['total']?> </b> </td>
</tr>
</tfoot>
<?php }else{
$date = DateTime::createFromFormat('M-Y', $month);
$startDate = $date->modify('first day of this month')->format('Y-m-d');
$endDate = $date->modify('last day of this month')->format('Y-m-d');
$datesInMonth = [];
$period = new DatePeriod(
new DateTime($startDate),
new DateInterval('P1D'),
(new DateTime($endDate))->modify('+1 day')
);
foreach ($period as $day) {
$datesInMonth[] = $day->format('Y-m-d');
}
foreach($datesInMonth as $datesInMonthIndex => $dateInMonth){
?>
<tr
<?php
$currentDate = date('d-m-Y');
$dateInMonthDmYFormat=date("d-m-Y", strtotime($dateInMonth));
if ($dateInMonthDmYFormat === $currentDate) { echo 'style="background: #cef0ad;"';}
?>
>
<td class="celda_normal">
<?php
echo date("d-m-Y", strtotime($dateInMonth));
?>
</td>
<td class="celda_normal finalRough"
data-id="<?= $dateInMonth ?>"
oninput="finalRoughStockChange(this)"
contenteditable="true"
><?= ' ' ?></td>
<td class="celda_normal dust"
data-id="<?= $dateInMonth ?>"
oninput="dustStockChange(this)"
contenteditable="true"
><?= ' ' ?></td>
<td class="celda_normal total"
data-id="<?= $dateInMonth ?>"
><?= ' ' ?></td>
</tr>
<?php
}
}
?>
</tbody>
</table>
</div>
</div>
</div> <!-- End card-body -->
</div> <!-- End card -->
</div> <!-- End col -->
</div> <!-- End row -->
</div>
</div> <!-- End container-fluid -->
</div>
</div>
<!-- modal section -->
<!-- filter modal -->
<div class="modal fade" id="filterModalId" tabindex="-1" role="dialog" aria-labelledby="filterModalLabelId" aria-hidden="true">
<div class="modal-dialog modal-md">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="filterModalLabelId">Filter Options</h4>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
<div class="modal-body">
<div class="row">
<?php
$currentDateInDmY = date('d-m-Y');
?>
<?php
$startDate = DateTime::createFromFormat('M-Y', $month);
if ($startDate) {
$startDate->modify('first day of this month');
$daysInMonth = $startDate->format('t');
$dateArray = [];
for ($i = 0; $i < $daysInMonth; $i++) {
$dateArray[] = $startDate->format('d-m-Y');
$startDate->modify('+1 day');
}
} else {
echo "Invalid date format.";
}
?>
<!-- From Date Filter -->
<div class="col-md-6">
<div class="form-group">
<label for="fromDateFilter">Select From Date</label>
<select id="fromDateFilter" name="fromDateFilter" class="form-control select2">
<?php if (!empty($dateArray)) : ?>
<?php foreach ($dateArray as $index => $date) : ?>
<option value="<?= $date ?>" ><?= $date ?></option>
<?php endforeach; ?>
<?php endif; ?>
</select>
</div>
</div>
<!-- To Date Filter -->
<div class="col-md-6">
<div class="form-group">
<label for="toDateFilter">Select Date</label>
<select id="toDateFilter" name="toDateFilter" class="form-control select2">
<?php if (!empty($dateArray)) : ?>
<?php foreach ($dateArray as $date) : ?>
<option value="<?= $date ?>" <?= ($date == $currentDateInDmY) || ($date == $dateArray[9]) ?"selected" :" " ?> ><?= $date ?></option>
<?php endforeach; ?>
<?php endif; ?>
</select>
</div>
</div>
</div>
<button class="btn btn-primary float-right" onclick="customFilterDate()">Filter</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div>
<!-- end modal section -->
<script>
function customFilterDate(){
let fromDate = $('#fromDateFilter').val(); //01-12-2024
let toDate = $('#toDateFilter').val(); //05-12-2024
$('#dustAndRoughStockDetailsTableId').find('tbody tr').each(function() {
const rowCells = $(this).find('td');
let tableDate = rowCells.eq(0).text();
let result = checkDateRange(fromDate,toDate,tableDate);
if (result) {
$(this).show();
} else {
$(this).hide();
}
});
$('#filterModalId').modal('hide');
}
function checkDateRange(fromDate, toDate, tableDate) {
// Convert the dates to a comparable format (YYYY-MM-DD)
let from = convertToDate(fromDate);
let to = convertToDate(toDate);
let table = convertToDate(tableDate);
// Return true if the table date is within the range
return table >= from && table <= to;
}
function convertToDate(dateString) {
// Convert from DD-MM-YYYY to YYYY-MM-DD for comparison
let parts = dateString.split('-');
return new Date(parts[2], parts[1] - 1, parts[0]); // Year, Month (0-based), Day
}
</script>
<script>
$(document).ready(function(){
$('.select2').select2();
})
</script>
<script type="text/javascript">
$(document).ready(function () {
$('#saveId').click(function () {
//table to json function
var updateDustAndRoughStockDetails = tableToJson();
alert('Updation may take a while, And we appreciate your patience..!!');
$('#loader').show();
$.ajax({
data: {
updateDustAndRoughStockDetails
},
type: "POST",
url: "<?php echo base_url() ?>updateDustAndRoughStockDetails",
success: function (data) {
if (data) {
$('#loader').hide();
console.log(data);
alert(data);
window.location.reload();
}
},
error: function(xhr, status, error) {
alert("An error occurred while processing the request. Please try again.");
console.error("Error Code:", xhr.status);
console.error("Error Message:", error);
console.error("Response Text:", xhr.responseText);
},
complete: function() {
$('#loader').hide();
}
});
});
});
</script>
<script>
function tableToJson() {
const table = $('#dustAndRoughStockDetailsTableId');
const rows = [];
//this table to json is customized for bagstock not for all
table.find('tbody tr').each(function() {
const rowCells = $(this).find('td');
/** we get eight entries against a material so we loop from 1 to 7 and so on
in a single row **/
const rowData = {
date: rowCells.eq(0).text().trim(),
finalRough: rowCells.eq(1).text().trim(),
dust: rowCells.eq(2).text().trim(),
total: rowCells.eq(3).text().trim(),
};
rows.push(rowData);
});
return JSON.stringify(rows, null, 2);
}
</script>
<script>
function finalRoughStockChange(tdElement) {
try {
let dataId = tdElement.getAttribute('data-id')
let finalRoughStock = validateInput(tdElement.innerText);
let dustStock = validateInput(document.querySelector(`td.dust[data-id="${dataId}"]`).innerText);
let total = (Number(finalRoughStock) + Number(dustStock)) ;
document.querySelector(`td.total[data-id="${dataId}"]`).innerText=total;
} catch(error){
console.error("There is an error updating stock ..!!" + error);
}
}
function dustStockChange(tdElement) {
try{
let dataId = tdElement.getAttribute('data-id')
let finalRoughStock = validateInput(document.querySelector(`td.finalRough[data-id="${dataId}"]`).innerText);
let dustStock = validateInput(tdElement.innerText);
let total = (Number(finalRoughStock) + Number(dustStock)) ;
document.querySelector(`td.total[data-id="${dataId}"]`).innerText = total;
} catch(error){
console.error("There is an error updating stock ..!!" + error);
}
}
function validateInput(input) {
if (input == '' || input == ' ' || input == '-') {
return 0;
}
//one of the type in empty space character list is 10
if (typeof input === 'string' && input.split('').map(char => char.charCodeAt(0))[0] == 10) {
return 0;
}
// Validate against the regex
const isValid = /^-?\d*\.?\d*$/.test(input);
if (!isValid) {
alert('Invalid input! Please enter a valid number.');
return 0;
}
return input;
}
</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();
}
});
$(cloneTable).find('tbody tr').each(function() {
let firstTd = $(this).find('td').eq(0); // Get the first column (Date)
// Convert Date Format (Assuming it's in YYYY-MM-DD format)
let originalDate = firstTd.text().trim(); // Get the text value
let parts = originalDate.split('-'); // Split into [YYYY, MM, DD]
if (parts.length === 3) {
let formattedDate = `${parts[2]}-${parts[1]}-${parts[0]}`; // Rearrange to DD-MM-YYYY
firstTd.text(formattedDate); // Update the cell value
}
// Apply left alignment to the date column
firstTd.css("text-align", "left");
});
let ws = XLSX.utils.table_to_sheet(cloneTable); // Convert modified table to sheet
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 = 'dustAndRoughStockDetailsTableId';
document.getElementById('dustAndRoughStockExport').addEventListener('click',function(){
exportTableToExcel(tableId ,'dustAndRoughStockDetails.xlsx');
})
})
</script>
<script>
document.addEventListener("keydown", function (event) {
if (event.key === "Enter") {
let activeElement = document.activeElement;
// Check if the focused element is inside a table
let cell = activeElement.closest("td, th");
let table = activeElement.closest("table");
if (table && cell) {
event.preventDefault(); // Prevent form submission
let columnIndex = cell.cellIndex; // Get the current column index
let currentRow = cell.parentElement; // Get the current row
let nextRow = currentRow.nextElementSibling; // Get the next row
// Move to the same column in the next row if available
if (nextRow) {
let nextCell = nextRow.cells[columnIndex];
if (nextCell) {
nextCell.focus();
}
}
}
}
});
</script>
<script>
$('#month').change(function(){
$('#changeMonthForm').submit();
})
$(document).ready(function () {
$('#month').datepicker({
format: "M-yyyy", // Format as "Jan-2025"
minViewMode: 1, // Month-Year Picker
autoclose: true,
todayHighlight: true,
orientation: "auto" // Adjusts automatically, or use "top" / "bottom"
}).on('focus', function() {
$(this).datepicker('show'); // Ensure it opens on focus
});
});
</script>
<script>
function toggleDivFullscreen() {
let div = document.getElementById("fullscreenDiv");
let tableResponsive = document.getElementById("table-responsive"); // Select the table container inside div
if (!document.fullscreenElement) {
div.requestFullscreen().then(() => {
div.style.width = "100vw"; // Full viewport width
div.style.height = "100vh"; // Full viewport height
// If .table-responsive exists, set its height to 90vh
if (tableResponsive) {
tableResponsive.style.maxHeight = "90vh";
tableResponsive.style.overflowY = "auto"; // Allow scrolling if needed
}
}).catch(err => console.log("Error enabling fullscreen:", err));
} else {
document.exitFullscreen().then(() => {
div.style.width = "100%";
div.style.height = "100%";
// Reset .table-responsive height when exiting fullscreen
if (tableResponsive) {
tableResponsive.style.height = "auto";
}
}).catch(err => console.log("Error exiting fullscreen:", err));
}
}
$("#searchInput").on("keyup", function () {
let value = $(this).val().toLowerCase(); // Convert input to lowercase for case-insensitive search
$(".table-responsive tbody tr").filter(function () {
$(this).toggle($(this).text().toLowerCase().indexOf(value) > -1);
});
});
</script>