stock module - 15-03-2025

This commit is contained in:
vadivelJ96 2025-03-17 12:04:51 +05:30
parent f7a0d44692
commit 6a95add649
12 changed files with 348 additions and 113 deletions

View File

@ -1135,17 +1135,25 @@ class StockController extends BaseController
// Update stock values for each day in the month
foreach ($resultExists as $index => $result) {
if ($index == 0) {
// Update the first entry with new consumption
$result['consumption'] = (float)($result['consumption']) + (float)($consumption);
$result['total'] = (float)$result['opening'] + (float)$result['purchaseBharath'] + (float)$result['purchaseIndian'];
$result['consumption'] = (float)($result['consumption']) + (float)($consumption);
$result['total'] = (float)$result['opening'] + (float)$result['purchaseBharath'] + (float)$result['purchaseIndian'];
$result['balanceStock'] = $result['total'] - $result['consumption'];
$updatedOpeningStock = (int)$result['balanceStock'];
$updatedOpeningStock = (int)$result['balanceStock'];
} else {
// Update subsequent entries based on previous balance
$result['opening'] = (float)$updatedOpeningStock;
$result['total'] = (float)$result['opening'] + (float)$result['purchaseBharath'] + (float)$result['purchaseIndian'];
$result['balanceStock'] = (float)$result['total'] - (float)$result['consumption'];
$updatedOpeningStock = (int)$result['balanceStock'];
}
@ -1159,6 +1167,8 @@ class StockController extends BaseController
} else {
return 0;
}
} else {
// Get the last date of the previous month
$previousMonthDate = new DateTime($date);
@ -3277,7 +3287,7 @@ class StockController extends BaseController
$this->TrpProductionWaste_model->insertBatch($insertWaste);
}
// Update existing records in batch
if (!empty($updateMaintenance)) {
$this->TrpProductionMaintenance_model->updateBatch($updateMaintenance, 'id');

View File

@ -1604,41 +1604,47 @@
<script>
$(document).ready(function(){
$(document).ready(function () {
function exportTableToExcel(tableID, filename = '') {
let table = document.getElementById(tableID);
let rows = [];
function exportTableToExcel(tableID, filename = '') {
let table = document.getElementById(tableID);
// Extract table data row-by-row
$(table).find('tr').each(function (rowIndex) {
let rowData = [];
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();
}
$(this).find('th, td').each(function (colIndex) {
// Skip hidden columns
if ($(this).css('display') === 'none') return;
let cellText = $(this).text().trim();
rowData.push(cellText);
});
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
}
// Add the cleaned row only if it has data
if (rowData.length > 0) {
rows.push(rowData);
}
});
let tableId = 'coatingMachineDetailTableId';
// Create a worksheet from array (no DOM needed!)
let ws = XLSX.utils.aoa_to_sheet(rows);
let wb = XLSX.utils.book_new();
XLSX.utils.book_append_sheet(wb, ws, 'Sheet1');
XLSX.writeFile(wb, filename || 'export.xlsx');
}
document.getElementById('coatingMachineDetailsExport').addEventListener('click',function(){
let tableId = 'coatingMachineDetailTableId';
exportTableToExcel(tableId,'coatingMachineDetails_<?=$month?>.xlsx');
document.getElementById('coatingMachineDetailsExport').addEventListener('click', function () {
exportTableToExcel(tableId, 'coatingMachineDetails_<?=$month?>.xlsx');
});
});
})
})

View File

@ -1110,7 +1110,8 @@
$(document).ready(function(){
function exportTableToExcel(tableID, filename = '') {
let table = document.getElementById(tableID);
let table = document.getElementById(tableID);
let cloneTable = table.cloneNode(true); // Clone the table to modify
// Remove hidden rows
@ -1124,6 +1125,25 @@
$(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");
$(this).find('th').eq(13).remove(); // Remove the last column (Actions)
$(this).find('td').eq(13).remove(); // Remove the last column (Actions)
});
let ws = XLSX.utils.table_to_sheet(cloneTable); // Convert modified table to sheet
let wb = XLSX.utils.book_new(); // Create a new workbook
@ -1131,6 +1151,7 @@
XLSX.writeFile(wb, filename || 'export.xlsx'); // Save the file
}
let tableId = 'bagStockDetailsTableId';
document.getElementById('bagStockExport').addEventListener('click',function(){

View File

@ -1427,7 +1427,8 @@ foreach ($period as $day) {
$(document).ready(function(){
function exportTableToExcel(tableID, filename = '') {
let table = document.getElementById(tableID);
let table = document.getElementById(tableID);
let cloneTable = table.cloneNode(true); // Clone the table to modify
// Remove hidden rows
@ -1441,6 +1442,25 @@ foreach ($period as $day) {
$(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");
$(this).find('th').eq(13).remove(); // Remove the last column (Actions)
$(this).find('td').eq(13).remove(); // Remove the last column (Actions)
});
let ws = XLSX.utils.table_to_sheet(cloneTable); // Convert modified table to sheet
let wb = XLSX.utils.book_new(); // Create a new workbook

View File

@ -1305,36 +1305,37 @@ function convertToDate(dateString) {
$(document).ready(function(){
function exportTableToExcel(tableID, filename = '') {
let table = document.getElementById(tableID);
let rows = table.rows;
let data = [];
function exportTableToExcel(tableID, filename = '') {
let table = document.getElementById(tableID);
let rows = [];
for (let i = 0; i < rows.length; i++) {
let row = rows[i];
let cols = row.querySelectorAll('td, th');
let rowData = [];
// Extract table data row-by-row
$(table).find('tr').each(function (rowIndex) {
let rowData = [];
$(this).find('th, td').each(function (colIndex) {
// Skip hidden columns
if ($(this).css('display') === 'none') return;
for (let j = 0; j < cols.length; j++) {
let cell = cols[j];
let cellText = $(this).text().trim();
// Check if the cell contains a <select> dropdown
let select = cell.querySelector('select');
if (select) {
rowData.push(select.options[select.selectedIndex].text); // Get only selected value
} else {
rowData.push(cell.innerText.trim()); // Normal text
}
}
data.push(rowData);
rowData.push(cellText);
});
// Add the cleaned row only if it has data
if (rowData.length > 0) {
rows.push(rowData);
}
});
let wb = XLSX.utils.book_new();
let ws = XLSX.utils.aoa_to_sheet(data);
XLSX.utils.book_append_sheet(wb, ws, 'Sheet1');
XLSX.writeFile(wb, filename || 'export.xlsx');
}
// Create a worksheet from array (no DOM needed!)
let ws = XLSX.utils.aoa_to_sheet(rows);
let wb = XLSX.utils.book_new();
XLSX.utils.book_append_sheet(wb, ws, 'Sheet1');
XLSX.writeFile(wb, filename || 'export.xlsx');
}
let tableId = 'drierTable';

View File

@ -463,7 +463,7 @@
<br>
<div class="row">
<div class="col-md-12 text-center">
<div class="col-md-12 text-left" style="margin-left :350px !important ;" >
<input type="button" class="btn btn-success px-4" id="saveId" value="save">
</div>
</div>
@ -633,13 +633,50 @@
$(document).ready(function(){
function exportTableToExcel(tableID, filename = '') {
let table = document.getElementById(tableID);
let ws = XLSX.utils.table_to_sheet(table); // Convert table to worksheet
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");
$(this).find('th').eq(13).remove(); // Remove the last column (Actions)
$(this).find('td').eq(13).remove(); // Remove the last column (Actions)
});
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(){

View File

@ -280,10 +280,14 @@
<div class="dropdown-menu dropdown-menu-right">
<a style="cursor:pointer"
class="dropdown-item" data-toggle="modal" data-target="#filterModalId">Filter</a>
<a style="cursor:pointer"
class="dropdown-item" id="gasStockDetailsExport" href="#">Export</a>
</div>
</div>
</div>
</div>
</form>
@ -1095,6 +1099,69 @@ function convertToDate(dateString) {
return input;
}
</script>
<!-- excel export -->
<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");
$(this).find('th').eq(13).remove(); // Remove the last column (Actions)
$(this).find('td').eq(13).remove(); // Remove the last column (Actions)
});
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 = 'gasStockDetailsTableId';
document.getElementById('gasStockDetailsExport').addEventListener('click',function(){
exportTableToExcel(tableId,'gasStockDetails<?=$month?>.xlsx');
})
})
</script>
<script>

View File

@ -315,6 +315,7 @@
<a style="cursor:pointer"
class="dropdown-item" id="incomingSilicaSandDetailsExport" href="#">Export</a>
</div>
</div>
</div>
</div>
@ -1726,51 +1727,59 @@ $(document).ready(function() {
<script>
$(document).ready(function(){
function exportTableToExcel(tableID, filename = '') {
let table = document.getElementById(tableID);
let cloneTable = table.cloneNode(true); // Clone the table to modify
function exportTableToExcel(tableID, filename = '') {
let table = document.getElementById(tableID);
// 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 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 rows = cloneTable.rows;
let data = [];
$(cloneTable).find('tbody tr').each(function() {
let invoiceTd = $(this).find('td').eq(2); // Get the first column (Date)
let materialReceivedTd = $(this).find('td').eq(3); // Get the second column (Material Received)
// Convert Date Format (Assuming it's in YYYY-MM-DD format)
let originalInvoiceDate = invoiceTd.text().trim(); // Get the text value
let originalMaterialReceivedDate = materialReceivedTd.text().trim(); // Get the text value
for (let i = 0; i < rows.length; i++) {
let row = rows[i];
let cols = row.querySelectorAll('td, th');
let rowData = [];
let originalInvoiceParts = originalInvoiceDate.split('-'); // Split into [YYYY, MM, DD]
let originalMaterialReceivedParts = originalMaterialReceivedDate.split('-'); // Split into [YYYY, MM, DD]
for (let j = 0; j < cols.length; j++) {
let cell = cols[j];
// Check if the cell contains a <select> dropdown
let select = cell.querySelector('select');
if (select) {
rowData.push(select.options[select.selectedIndex].text); // Get only selected value
} else {
rowData.push(cell.innerText.trim()); // Normal text
}
}
data.push(rowData);
if (originalInvoiceParts.length === 3) {
let formattedDate = `${originalInvoiceParts[2]}-${originalInvoiceParts[1]}-${originalInvoiceParts[0]}`; // Rearrange to DD-MM-YYYY
invoiceTd.text(formattedDate); // Update the cell value
}
let wb = XLSX.utils.book_new();
let ws = XLSX.utils.aoa_to_sheet(data);
XLSX.utils.book_append_sheet(wb, ws, 'Sheet1');
XLSX.writeFile(wb, filename || 'export.xlsx');
}
if (originalMaterialReceivedParts.length === 3) {
let formattedDate = `${originalMaterialReceivedParts[2]}-${originalMaterialReceivedParts[1]}-${originalMaterialReceivedParts[0]}`; // Rearrange to DD-MM-YYYY
materialReceivedTd.text(formattedDate); // Update the cell value
}
// Apply left alignment to the date column
invoiceTd.css("text-align", "left");
materialReceivedTd.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 = 'incomingSilicaSandDetailsTable';

View File

@ -1365,27 +1365,49 @@ foreach ($period as $day) {
$(document).ready(function() {
function exportTableToExcel(tableID, filename = '') {
let table = document.getElementById(tableID);
let table = document.getElementById(tableID);
let cloneTable = table.cloneNode(true); // Clone the table to modify
// Remove hidden rows
$(cloneTable).find('tr').filter(function() {
$(cloneTable).find('tr').filter(function () {
return $(this).css('display') === 'none';
}).remove();
// Remove hidden columns
$(cloneTable).find('th, td').each(function() {
$(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");
$(this).find('th').eq(13).remove(); // Remove the last column (Actions)
$(this).find('td').eq(13).remove(); // Remove the last column (Actions)
});
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 = 'powerStockDetailsTableId';
document.getElementById('powerConsumptionExport').addEventListener('click', function() {

View File

@ -1064,20 +1064,40 @@ foreach ($period as $day) {
$(document).ready(function() {
function exportTableToExcel(tableID, filename = '') {
let table = document.getElementById(tableID);
let table = document.getElementById(tableID);
let cloneTable = table.cloneNode(true); // Clone the table to modify
// Remove hidden rows
$(cloneTable).find('tr').filter(function() {
$(cloneTable).find('tr').filter(function () {
return $(this).css('display') === 'none';
}).remove();
// Remove hidden columns
$(cloneTable).find('th, td').each(function() {
$(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");
$(this).find('th').eq(13).remove(); // Remove the last column (Actions)
$(this).find('td').eq(13).remove(); // Remove the last column (Actions)
});
let ws = XLSX.utils.table_to_sheet(cloneTable); // Convert modified table to sheet
let wb = XLSX.utils.book_new(); // Create a new workbook

View File

@ -331,11 +331,12 @@ $timeOtions[] = "12:00 AM";
</a>
<div class="dropdown-menu dropdown-menu-right">
<a class="dropdown-item" data-toggle="modal" data-target="#bs-example-modal-lg">Navigation</a>
<a class="dropdown-item" href="#">Export</a>
<a style="cursor:pointer"
class="dropdown-item" id="gasStockDetailsExport" href="#">Export</a>
</div>
</div>
</div>
</div>
</div>
</form>

View File

@ -488,7 +488,7 @@
<br>
<div class="row">
<div class="col-md-12 text-center">
<div class="col-md-12 text-left" style="margin-left :350px !important ;" >
<input type="button" class="btn btn-success px-4" id="saveId" value="save">
</div>
</div>
@ -663,7 +663,8 @@
$(document).ready(function(){
function exportTableToExcel(tableID, filename = '') {
let table = document.getElementById(tableID);
let table = document.getElementById(tableID);
let cloneTable = table.cloneNode(true); // Clone the table to modify
// Remove hidden rows
@ -678,6 +679,26 @@
}
});
$(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");
$(this).find('th').eq(13).remove(); // Remove the last column (Actions)
$(this).find('td').eq(13).remove(); // Remove the last column (Actions)
});
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