stock module latest today vadivel J 21-02-2025

This commit is contained in:
vadivelJ96 2025-02-21 18:26:32 +05:30
parent 2885d14239
commit 474e2c0392
2 changed files with 287 additions and 108 deletions

View File

@ -2545,7 +2545,7 @@ class StockController extends BaseController
$this->global['pageTitle'] = 'Diesel Machine Stock Details'; $this->global['pageTitle'] = 'Diesel Machine Stock Details';
// Get the previous month's last date resin stock details for next month updation // Get the previous month's last date diesel stock details for next month updation
$previousMonth = DateTime::createFromFormat('Y-m', $month)->modify('-1 month')->format('Y-m'); $previousMonth = DateTime::createFromFormat('Y-m', $month)->modify('-1 month')->format('Y-m');
$previousMonthStartDate = "$previousMonth-01"; $previousMonthStartDate = "$previousMonth-01";

View File

@ -21,7 +21,16 @@
background-color: #50bbd9; background-color: #50bbd9;
color: #ffffff; color: #ffffff;
} }
/*
.grab {
cursor: grab; /* Default open-hand cursor */
}
.grab:active {
cursor: grabbing; /* Closed-hand cursor when dragging */
}
/*
.fht-table td[contenteditable="true"] { .fht-table td[contenteditable="true"] {
background-color: lightyellow; background-color: lightyellow;
color:rgb(13, 7, 7); color:rgb(13, 7, 7);
@ -155,14 +164,14 @@
} }
.celda_encabezado_total { .celda_encabezado_total {
background-color:#ffffff !important; background-color: #ffffff !important;
border: 1px solid #ffffff; border: 1px solid #ffffff;
color: #ffffff !important; color: #ffffff !important;
font-weight: bold; font-weight: bold;
padding: 6px 10px; padding: 6px 10px;
text-align: center; text-align: center;
} }
.celda_normal { .celda_normal {
/*background-color: #fff;*/ /*background-color: #fff;*/
/* <!-- ad9271 into ffffff brown-light to green-light --> */ /* <!-- ad9271 into ffffff brown-light to green-light --> */
@ -176,12 +185,14 @@
.fht-table thead { .fht-table thead {
position: sticky; position: sticky;
top: 0; top: 0;
z-index: 20; /* Ensure the entire header stays above table rows */ z-index: 20;
background-color: #50bbd9; /* Header background color */ /* Ensure the entire header stays above table rows */
background-color: #50bbd9;
/* Header background color */
} }
.dropdown-menu { .dropdown-menu {
z-index :25 ; z-index: 25;
} }
@ -190,8 +201,10 @@
.fht-table thead th { .fht-table thead th {
position: sticky; position: sticky;
top: 0; top: 0;
z-index: 11; /* Higher than table rows but lower than first column */ z-index: 11;
background-color: #50bbd9; /* Green background */ /* Higher than table rows but lower than first column */
background-color: #50bbd9;
/* Green background */
color: #ffffff; color: #ffffff;
border: 1px solid #ddd; border: 1px solid #ddd;
padding: 10px; padding: 10px;
@ -203,7 +216,8 @@
position: sticky; position: sticky;
left: 0; left: 0;
background-color: #50bbd9; background-color: #50bbd9;
z-index: 15; /* Ensures it stays above other cells */ z-index: 15;
/* Ensures it stays above other cells */
border-right: 2px solid #ddd; border-right: 2px solid #ddd;
color: #ffffff; color: #ffffff;
} }
@ -211,17 +225,16 @@
/* Table Wrapper for Scrolling */ /* Table Wrapper for Scrolling */
.table-responsive { .table-responsive {
overflow-x: auto; overflow-x: auto;
overflow-y: auto; overflow-y: auto;
max-height: 500px; /* Adjust as needed */ max-height: 500px;
/* Adjust as needed */
position: relative; position: relative;
} }
td{ td {
min-width: 100px; min-width: 100px;
max-width: 100px; max-width: 100px;
} }
</style> </style>
@ -291,10 +304,14 @@ foreach ($period as $day) {
class="form-control mt-2" data-provide="datepicker" class="form-control mt-2" data-provide="datepicker"
data-date-format="M-yyyy" data-date-min-view-mode="1"> data-date-format="M-yyyy" data-date-min-view-mode="1">
</div> </div>
<div class="form-group col-md-2"> <div class="form-group col-md-3">
<button type="submit" class="btn btn-success"> Change Month </button> <button type="submit" class="btn btn-success"> Change Month </button>
<button type="button" class="btn" style="background-color:maroon;color:white" data-target="#customizeModalId"
data-toggle="modal">
Customize
</button>
</div> </div>
<div class="col-md-1"></div>
<div class="col-6"> <div class="col-6">
<div class="dropdown float-right"> <div class="dropdown float-right">
<a href="#" class="dropdown-toggle arrow-none" data-toggle="dropdown" <a href="#" class="dropdown-toggle arrow-none" data-toggle="dropdown"
@ -354,9 +371,9 @@ foreach ($period as $day) {
<?php if (!empty($groupedResinStockDetails)) { <?php if (!empty($groupedResinStockDetails)) {
$summary = []; $summary = [];
foreach ($groupedResinStockDetails as $groupedResinStockDetailsIndex => $resinStockDetails) { foreach ($groupedResinStockDetails as $groupedResinStockDetailsIndex => $resinStockDetails) {
?> ?>
@ -370,9 +387,9 @@ foreach ($period as $day) {
echo 'style="background: #cef0ad;"'; echo 'style="background: #cef0ad;"';
} }
?>> ?>>
<?php foreach ($resinStockDetails as $resinStockIndex => $resinStock) { <?php foreach ($resinStockDetails as $resinStockIndex => $resinStock) {
?> ?>
<?php if ($resinStockIndex == 0): ?> <?php if ($resinStockIndex == 0): ?>
<?php <?php
$startDate = DateTime::createFromFormat('Y-m-d', $resinStock['date'])->format('d-m-Y'); $startDate = DateTime::createFromFormat('Y-m-d', $resinStock['date'])->format('d-m-Y');
@ -424,32 +441,31 @@ foreach ($period as $day) {
<?= $resinStock['balanceStock'] ?? ' ' ?> <?= $resinStock['balanceStock'] ?? ' ' ?>
</td> </td>
<?php <?php
//before closing inner loop we just adding the total values insidde it //before closing inner loop we just adding the total values insidde it
$materialCode = $resinStock['materialCode']; // Unique identifier
// Initialize the material entry if it doesn't exist $materialCode = $resinStock['materialCode']; // Unique identifier
if (!isset($summary[$materialCode])) {
$summary[$materialCode] = [
'opening' => "-" ,
'receipt' => 0,
'used' => 0,
'balanceStock' => 0,
];
}
// Sum values for the material // Initialize the material entry if it doesn't exist
; if (!isset($summary[$materialCode])) {
$summary[$materialCode]['opening'] = "-" ; $summary[$materialCode] = [
$summary[$materialCode]['receipt'] += is_numeric($resinStock['receipt']) ? $resinStock['receipt'] : 0; 'opening' => "-",
$summary[$materialCode]['used'] += is_numeric($resinStock['used']) ? $resinStock['used'] : 0; 'receipt' => 0,
$summary[$materialCode]['balanceStock'] = is_numeric($resinStock['balanceStock']) ? $resinStock['balanceStock'] : 0; 'used' => 0,
'balanceStock' => 0,
];
}
} ?> // Sum values for the material
;
$summary[$materialCode]['opening'] = "-";
$summary[$materialCode]['receipt'] += is_numeric($resinStock['receipt']) ? $resinStock['receipt'] : 0;
$summary[$materialCode]['used'] += is_numeric($resinStock['used']) ? $resinStock['used'] : 0;
$summary[$materialCode]['balanceStock'] = is_numeric($resinStock['balanceStock']) ? $resinStock['balanceStock'] : 0;
} ?>
</tr> </tr>
@ -457,41 +473,41 @@ foreach ($period as $day) {
<div class="table-responsive"> <div class="table-responsive">
<table id="resinStockDetailsTableSummaryId" class="fht-table table-striped"> <table id="resinStockDetailsTableSummaryId" class="fht-table table-striped">
<thead > <thead>
<th class="celda_encabezado_total">Total Sum</th> <th class="celda_encabezado_total">Total Sum</th>
<?php foreach($summary as $each){ ?> <?php foreach ($summary as $each) { ?>
<th class="celda_encabezado_total">Opening Stock</th> <th class="celda_encabezado_total">Opening Stock</th>
<th class="celda_encabezado_total">Receipt</th> <th class="celda_encabezado_total">Receipt</th>
<th class="celda_encabezado_total">Used</th> <th class="celda_encabezado_total">Used</th>
<th class="celda_encabezado_total">Balance Stock</th> <th class="celda_encabezado_total">Balance Stock</th>
<?php } ?> <?php } ?>
</thead> </thead>
<tbody>
<tr> <tbody>
<td style="background-color:rgb(189, 9, 6); color:#ffff;"> <tr>
<b> Total </b>
</td>
<?php foreach($summary as $each){ ?> <td style="background-color:rgb(189, 9, 6); color:#ffff;">
<b> Total </b>
</td>
<?php foreach ($summary as $each) { ?>
<td class="celda_normal "><?=$each['opening']?></td>
<td class="celda_normal "><?=$each['receipt']?></td>
<td class="celda_normal "><?=$each['used']?></td>
<td class="celda_normal "><?=$each['balanceStock']?></td>
<?php } ?>
</tr> <td class="celda_normal "><?= $each['opening'] ?></td>
<td class="celda_normal "><?= $each['receipt'] ?></td>
<td class="celda_normal "><?= $each['used'] ?></td>
<td class="celda_normal "><?= $each['balanceStock'] ?></td>
</tbody> <?php } ?>
</table>
</tr>
</tbody>
</table>
</div> </div>
<!-- this else condition work if groupedBagStockDetails is empty and creating new records <!-- this else condition work if groupedBagStockDetails is empty and creating new records
@ -511,7 +527,7 @@ foreach ($period as $day) {
} }
?>> ?>>
<?php <?php
// dd($resinMaterials); // dd($resinMaterials);
foreach ($resinMaterials as $resinMaterialIndex => $resinMaterial) { ?> foreach ($resinMaterials as $resinMaterialIndex => $resinMaterial) { ?>
<!-- this will loop till materials present --> <!-- this will loop till materials present -->
@ -640,6 +656,86 @@ foreach ($period as $day) {
<!---------------------------------------
this modal is used to customize table header
1)list table header order
2)choose which material/machines you want
------------------------------------------------------------>
<div>
<div class="modal fade" id="customizeModalId" tabindex="-1" role="dialog" aria-labelledby="customizeModalLabel" aria-hidden="true">
<div class="modal-dialog modal-md">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="customizeModalLabel">Customize</h4>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
<div class="modal-body">
<div class="row">
<!-- Dropdown to add back removed items -->
<div class="col">
<div class="form-group">
<label for="customizeHeader"> Add For This Month </label>
<select id="customizeHeader" class="form-control" onchange="addBackToList()">
<option value="">Select</option>
</select>
</div>
</div>
</div>
<div class="row">
<div class="col">
<h5>List of Selected Items</h5>
<div id="selectedItemsContainer">
<ul id="sortableList">
<?php foreach ($resinMaterials as $resinMaterial): ?>
<div class="sortable-item" draggable="true" id="<?= $resinMaterial['MaterialCode'] ?>_container">
<input type="checkbox"
id="<?= $resinMaterial['MaterialCode'] ?>_checkboxId"
name="materialCodes[]"
value="<?= $resinMaterial['MaterialCode'] ?>"
onclick="removeSelectedMaterial(this)"
checked>
<label class="grab" for="<?= $resinMaterial['MaterialCode'] ?>_checkboxId">
<?= $resinMaterial['MaterialName']; ?>
</label>
<br>
</div>
<?php endforeach; ?>
</ul>
</div>
</div>
</div>
<button type="button" class="btn btn-primary float-right"> Apply </button>
</div>
</div>
</div>
</div>
</div>
<!-- modal section ends -->
<script> <script>
function navigateToResin() { function navigateToResin() {
@ -817,7 +913,7 @@ foreach ($period as $day) {
} }
function receiptStockChange(tdElement) { function receiptStockChange(tdElement) {
try { try {
let dataId = tdElement.getAttribute('data-id'); let dataId = tdElement.getAttribute('data-id');
let [date, materialCode] = tdElement.getAttribute('data-id').split(' '); let [date, materialCode] = tdElement.getAttribute('data-id').split(' ');
let openingStock = validateInput(document.querySelector(`td.openingStock[data-id="${dataId}"]`).innerText); let openingStock = validateInput(document.querySelector(`td.openingStock[data-id="${dataId}"]`).innerText);
@ -845,7 +941,7 @@ foreach ($period as $day) {
let [date, materialCode] = tdElement.getAttribute('data-id').split(' '); let [date, materialCode] = tdElement.getAttribute('data-id').split(' ');
let openingStock = validateInput(document.querySelector(`td.openingStock[data-id="${dataId}"]`).innerText); let openingStock = validateInput(document.querySelector(`td.openingStock[data-id="${dataId}"]`).innerText);
let receiptStock = validateInput(document.querySelector(`td.receiptStock[data-id="${dataId}"]`).innerText); let receiptStock = validateInput(document.querySelector(`td.receiptStock[data-id="${dataId}"]`).innerText);
let usedStock = validateInput(tdElement.innerText); let usedStock = validateInput(tdElement.innerText);
let currentBalanceStock = (Number(openingStock) + Number(receiptStock)) - Number(usedStock); let currentBalanceStock = (Number(openingStock) + Number(receiptStock)) - Number(usedStock);
document.querySelector(`td.balanceStock[data-id="${dataId}"]`).innerText = currentBalanceStock; document.querySelector(`td.balanceStock[data-id="${dataId}"]`).innerText = currentBalanceStock;
@ -881,8 +977,6 @@ foreach ($period as $day) {
return input; return input;
} }
</script> </script>
<script> <script>
@ -921,20 +1015,19 @@ foreach ($period as $day) {
<script> <script>
$(document).ready(function() {
$(document).ready(function(){
function exportTableToExcel(tableID, filename = '') { function exportTableToExcel(tableID, filename = '') {
let table = document.getElementById(tableID); let table = document.getElementById(tableID);
let cloneTable = table.cloneNode(true); // Clone the table to modify let cloneTable = table.cloneNode(true); // Clone the table to modify
// Remove hidden rows // Remove hidden rows
$(cloneTable).find('tr').filter(function () { $(cloneTable).find('tr').filter(function() {
return $(this).css('display') === 'none'; return $(this).css('display') === 'none';
}).remove(); }).remove();
// Remove hidden columns // Remove hidden columns
$(cloneTable).find('th, td').each(function () { $(cloneTable).find('th, td').each(function() {
if ($(this).css('display') === 'none') { if ($(this).css('display') === 'none') {
$(this).remove(); $(this).remove();
} }
@ -948,53 +1041,139 @@ foreach ($period as $day) {
let tableId = 'resinStockDetailsTableId'; let tableId = 'resinStockDetailsTableId';
document.getElementById('resinStockExport').addEventListener('click',function(){ document.getElementById('resinStockExport').addEventListener('click', function() {
exportTableToExcel(tableId,'Resin_Stock_Details<?=$month?>.xlsx'); exportTableToExcel(tableId, 'Resin_Stock_Details<?= $month ?>.xlsx');
}) })
}) })
</script> </script>
<script> <script>
document.addEventListener("keydown", function (event) { document.addEventListener("keydown", function(event) {
if (event.key === "Enter") { if (event.key === "Enter") {
let activeElement = document.activeElement; let activeElement = document.activeElement;
// Check if the focused element is inside a table // Check if the focused element is inside a table
let cell = activeElement.closest("td, th"); let cell = activeElement.closest("td, th");
let table = activeElement.closest("table"); let table = activeElement.closest("table");
if (table && cell) { if (table && cell) {
event.preventDefault(); // Prevent form submission event.preventDefault(); // Prevent form submission
let columnIndex = cell.cellIndex; // Get the current column index let columnIndex = cell.cellIndex; // Get the current column index
let currentRow = cell.parentElement; // Get the current row 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 let nextRow = currentRow.nextElementSibling; // Get the next row
if (nextRow) {
let nextCell = nextRow.cells[columnIndex];
if (nextCell) { // Move to the same column in the next row if available
if (nextRow) {
nextCell.focus();
let nextCell = nextRow.cells[columnIndex];
if (nextCell) {
nextCell.focus();
}
} }
} }
} }
});
</script>
<script>
document.addEventListener("DOMContentLoaded", function () {
const list = document.getElementById("sortableList");
let draggedItem = null;
function attachDragEvents(item) {
item.setAttribute("draggable", "true");
item.addEventListener("dragstart", (event) => {
draggedItem = event.target;
event.target.classList.add("dragging");
});
item.addEventListener("dragend", (event) => {
event.target.classList.remove("dragging");
});
} }
list.addEventListener("dragover", (event) => {
event.preventDefault(); // Allow dropping
const dragging = document.querySelector(".dragging");
const closestItem = getClosestItem(list, event.clientY);
if (closestItem) {
list.insertBefore(dragging, closestItem);
} else {
list.appendChild(dragging);
}
});
function getClosestItem(container, y) {
const items = [...container.querySelectorAll(".sortable-item:not(.dragging)")];
return items.reduce((closest, child) => {
const box = child.getBoundingClientRect();
const offset = y - box.top - box.height / 2;
return offset < 0 && offset > closest.offset
? { offset, element: child }
: closest;
}, { offset: Number.NEGATIVE_INFINITY }).element;
}
// Attach drag events to existing items
document.querySelectorAll(".sortable-item").forEach(attachDragEvents);
window.removeSelectedMaterial = function (checkbox) {
let container = checkbox.closest(".sortable-item");
let materialCode = checkbox.value;
let materialName = container.querySelector("label").innerText;
let dropdown = document.getElementById("customizeHeader");
let newOption = document.createElement("option");
newOption.value = materialCode;
newOption.text = materialName;
dropdown.appendChild(newOption);
container.remove();
};
window.addBackToList = function () {
let dropdown = document.getElementById("customizeHeader");
let selectedOption = dropdown.options[dropdown.selectedIndex];
if (selectedOption.value !== "") {
let materialCode = selectedOption.value;
let materialName = selectedOption.text;
let container = document.createElement("div");
container.classList.add("sortable-item");
container.id = materialCode + "_container";
container.innerHTML = `
<input type="checkbox" id="${materialCode}_checkboxId"
name="materialCodes[]" value="${materialCode}"
onclick="removeSelectedMaterial(this)" checked>
<label class="grab" for="${materialCode}_checkboxId"> ${materialName} </label>
<br>
`;
attachDragEvents(container);
document.getElementById("sortableList").appendChild(container);
dropdown.removeChild(selectedOption);
}
};
}); });
</script> </script>