bag stock module table to json conversion done

This commit is contained in:
vadivel J 2024-10-28 18:17:40 +05:30
parent 0d1d94ecf5
commit 06bc75aa2f

View File

@ -208,85 +208,105 @@
</div>
</form>
<table id="data-table">
<thead>
<tr>
<th rowspan="4" colspan="1">
Material <br><br> Customer <br><br> Date
</th>
</tr>
<tr>
<?php foreach ($materials as $material) { ?>
<th colspan="4"><?php echo ($material) ?></th>
<?php } ?>
</tr>
<tr>
<?php foreach ($materials as $material) { ?>
<th colspan="4" contenteditable="true">
customers
</th>
<?php } ?>
</tr>
<tr>
<?php foreach ($materials as $material) { ?>
<th>info1</th>
<th>info2</th>
<th>info3</th>
<th>info4</th>
<?php } ?>
</tr>
</thead>
<tbody>
<tr>
<td>23-10-2024</td>
<td>472</td>
<td></td>
<td>-</td>
<td>472</td>
<td>472</td>
<td></td>
<td>-</td>
<td>472</td>
</tr>
<!-- Add more rows as needed -->
</tbody>
</table>
<!-- Add table-responsive for horizontal scroll -->
<div class="table-responsive">
<table id="bagStockDetailsTableId" class="fht-table table-striped"
style="font-size: small;">
<thead>
style="font-size: small;">
<thead class="celda_encabezado_general" style="padding: 10px;">
<tr>
<th class="celda_encabezado_general" style="padding: 10px;">S.NO </th>
<th class="celda_encabezado_general" style="padding: 10px;">IGR No </th>
<th colspan="1">material </th>
<th colspan="4">material 1</th>
<th colspan="4">material 2</th>
</tr>
<tr>
<th colspan="1">Customer </th>
<th colspan="4" contenteditable="true">
<?php echo $customer??'Customer' ?>
</th>
<th colspan="4" contenteditable="true">
<?php echo $customer??'Customer2' ?>
</th>
</tr>
<tr>
<th colspan="1">Date </th>
<th style="display:none">Date</th>
<th style="display:none"> material</th>
<th style="display:none"> customer</th>
<th>Opening</th>
<th>Receipt</th>
<th>Used</th>
<th>Balance Stock</th>
<th style="display:none">Date</th>
<th style="display:none"> material</th>
<th style="display:none"> customer</th>
<th>Opening</th>
<th>Receipt</th>
<th>Used</th>
<th>Balance Stock</th>
</tr>
</thead>
<tbody style="background-color: #fff;">
<tbody style="background-color: #fff;" >
<tr id="1">
<td width="45" height="45" class="celda_normal">1</td>
<td class="celda_normal">
data 2
</td>
<tr>
<td class="celda_normal" >23-10-2024</td>
<td style="display:none">23-10-2024</td>
<td style="display:none"> material 1</td>
<td style="display:none"> customer 1</td>
<td class="celda_normal" >472</td>
<td class="celda_normal">11212</td>
<td class="celda_normal">-</td>
<td class="celda_normal">472</td>
<td style="display:none">23-10-2024</td>
<td style="display:none"> material 2</td>
<td style="display:none"> customer 2</td>
<td class="celda_normal" >472</td>
<td class="celda_normal">11212</td>
<td class="celda_normal">-</td>
<td class="celda_normal">472</td>
</tr>
<tr>
<td class="celda_normal" >23-10-2024</td>
<td style="display:none">Date</td>
<td style="display:none"> material 1</td>
<td style="display:none"> customer 1</td>
<td class="celda_normal" >472</td>
<td class="celda_normal">11212</td>
<td class="celda_normal">-</td>
<td class="celda_normal">472</td>
<td style="display:none">Date</td>
<td style="display:none"> material 1</td>
<td style="display:none"> customer 1</td>
<td class="celda_normal" >472</td>
<td class="celda_normal">11212</td>
<td class="celda_normal">-</td>
<td class="celda_normal">472</td>
</tr>
</tbody>
</table>
</div><!-- End table-responsive -->
</div>
<div class="row">
<div class="col-md-12 text-right">
@ -349,8 +369,45 @@
});
});
</script>
<script>
function tableToJson() {
const table = $('#bagStockDetailsTableId');
const rows = [];
table.find('tbody tr').each(function() {
const rowCells = $(this).find('td');
const date = rowCells.eq(0).text().trim();
for (let i = 1; i < rowCells.length; i += 7) {
const rowData = {
date: rowCells.eq(i).text().trim(),
material: rowCells.eq(i+1).text().trim(),
customer: rowCells.eq(i+2).text().trim(),
opening: rowCells.eq(i+3).text().trim(),
receipt: rowCells.eq(i + 4).text().trim(),
used: rowCells.eq(i + 5).text().trim(),
balanceStock: rowCells.eq(i + 6).text().trim()
};
rows.push(rowData);
}
});
return JSON.stringify(rows, null, 2);
}
console.log(tableToJson());
$('#saveId').on('click', function() {
const jsonResult = tableToJson();
console.log(jsonResult);
});
</script>