changes in gas stock module -vadivel J

This commit is contained in:
vadivel J 2024-11-13 10:13:55 +05:30
parent b79e3b0f3d
commit d3fdd57fda
3 changed files with 203 additions and 104 deletions

View File

@ -769,7 +769,7 @@ class StockController extends BaseController
SUM(totalGasconsumption) AS coatingMachineGasconsumption,
SUM(totalCoatingSandInKg) / 1000 AS coatedSand
FROM t_coatingMachineDetails
WHERE is_active = 1
WHERE is_active = 1
AND date >= ' . $this->db->escape($startDate) . '
AND date <= ' . $this->db->escape($endDate) . '
GROUP BY date
@ -797,7 +797,62 @@ class StockController extends BaseController
}
public function updateGasStockDetails(){
echo "welcome to update Gas Stock Details";
$postData = $this->request->getPost();
$updateGasStockDetailsData = json_decode($postData['updateGasStockDetails'], true);
$updates = [];
$inserts = [];
foreach($updateGasStockDetailsData as $data){
$date = $data['date'];
$dbData = [
'date' =>$data['date'],
'opening' =>$data['opening'],
'purchaseBharath' =>$data['purchaseBharath'],
'purchaseIndian' =>$data['purchaseIndian'],
'total' =>$data['total'],
'consumption' =>$data['consumption'],
'balanceStock' =>$data['balanceStock'],
];
$resultExists = $this->gasStockDetails_model
->where('date',$date)
->first();
if(empty($resultExists)){
$inserts[] = $dbData;
}else{
$dbData['id']=$resultExists['id'];
$updates[] = $dbData ;
}
}
if (!empty($inserts)) {
$this->gasStockDetails_model->insertBatch($inserts);
}
if (!empty($updates)) {
$updateResult = $this->gasStockDetails_model->updateBatch($updates, 'id');
if ($updateResult === FALSE) {
echo "Error during update";
} else {
echo "Data Updated Successfully";
return;
}
}
echo "Data Saved Successfully";
}

View File

@ -267,22 +267,44 @@
<tbody style="background-color: #fff;" >
<?php if(!empty($gasStockDetails)){
foreach($gasStockDetails as $index => $gasStockDetail){
$date = Datetime::createFromFormat('Y-m-d',$gasStockDetail['date'])->format('d-m-Y')
?>
<tr>
<td class="celda_normal"><?=$gasStockDetail['date']??'-'?></td>
<td class="celda_normal"><?=$gasStockDetail['opening']??'0'?></td>
<td class="celda_normal"><?=$gasStockDetail['purchaseBharath']??'0'?></td>
<td class="celda_normal"><?=$gasStockDetail['purchaseIndian']??'0'?></td>
<td class="celda_normal"><?=$gasStockDetail['total']??'0'?></td>
<td class="celda_normal"><?=$gasStockDetail['consumption']??'0'?></td>
<td class="celda_normal"><?=$gasStockDetail['balanceStock']??'0'?></td>
<td class="celda_normal"><?=$gasStockDetail['consumption']??'0'?></td>
<td class="celda_normal"><?=$date??'-'?></td>
<!-- only setting opening stock editable for first day of the month -->
<td class="celda_normal openingStock"
<?php if($index==0){echo"contenteditable='true'";}?>
oninput="openingStockChange(this)"
data-id="<?=$gasStockDetail['date']?>"
><?=$gasStockDetail['opening']??'0'?></td>
<td class="celda_normal purchaseBharath"
oninput="purchaseBharathStockChange(this)"
data-id="<?=$gasStockDetail['date']?>"
contenteditable="true"><?=$gasStockDetail['purchaseBharath']??'0'?></td>
<td class="celda_normal purchaseIndian"
oninput="purchaseIndianStockChange(this)"
data-id="<?=$gasStockDetail['date']?>"
contenteditable="true"><?=$gasStockDetail['purchaseIndian']??'0'?></td>
<td class="celda_normal total"
data-id="<?=$gasStockDetail['date']?>"
><?=$gasStockDetail['total']??'0'?></td>
<td class="celda_normal consumption"
data-id="<?=$gasStockDetail['date']?>"
><?=$gasStockDetail['consumption']??'0'?></td>
<td class="celda_normal balanceStock"
data-id="<?=$gasStockDetail['date']?>"
><?=$gasStockDetail['balanceStock']??'0'?></td>
<td class="celda_normal"><?=$gasStockDetail['drierMachineGasConsumption']??'0'?></td>
<td class="celda_normal"><?=$gasStockDetail['sandDried']??'0'?></td>
<td class="celda_normal"><?=$gasStockDetail['consumption']??'0'?></td>
<td class="celda_normal"><?=$gasStockDetail['coatedSand']??'0'?></td>
<td class="celda_normal"><?=$gasStockDetail['coatedSand']??'0'?></td>
<td class="celda_normal"><?=$gasStockDetail['coatedSand']??'0'?></td>
<td class="celda_normal"><?=$gasStockDetail['coatingMachineGasconsumption']??'0'?></td>
<td class="celda_normal"><?=$gasStockDetail['coatedSand']??'0'?></td>
<td class="celda_normal"><?=$gasStockDetail['trpMachineGasconsumption']??'0'?></td>
<td class="celda_normal"><?=$gasStockDetail['sandTrp']??'0'?></td>
<td class="celda_normal"><?=$gasStockDetail['rotaryDrierMachineGasconsumption']??'0'?></td>
</tr>
<?php }
}else{
@ -307,23 +329,42 @@
foreach ($datesInMonth as $datesInMonthIndex => $dateInMonth) {
$dateInMonthDmYFormat = Datetime::createFromFormat('Y-m-d',$dateInMonth)->format('d-m-Y')
?>
<tr>
<td class="celda_normal"><?=$dateInMonth??'-'?></td>
<td class="celda_normal"><?='0'?></td>
<td class="celda_normal"><?='0'?></td>
<td class="celda_normal"><?='0'?></td>
<td class="celda_normal"><?='0'?></td>
<td class="celda_normal"><?='0'?></td>
<td class="celda_normal"><?='0'?></td>
<td class="celda_normal"><?='0'?></td>
<td class="celda_normal"><?='0'?></td>
<td class="celda_normal"><?='0'?></td>
<td class="celda_normal"><?='0'?></td>
<td class="celda_normal"><?='0'?></td>
<td class="celda_normal"><?='0'?></td>
<td class="celda_normal"><?='0'?></td>
<tr>
<td class="celda_normal"><?=$dateInMonthDmYFormat??'-'?></td>
<!-- only setting opening stock editable for first day of the month -->
<td class="celda_normal openingStock"
<?php if($datesInMonthIndex==0){echo"contenteditable='true'";}?>
oninput="openingStockChange(this)"
data-id="<?=$dateInMonth?>"
>0</td>
<td class="celda_normal purchaseBharath"
oninput="purchaseBharathStockChange(this)"
data-id="<?=$dateInMonth?>"
contenteditable="true">0</td>
<td class="celda_normal purchaseIndian"
oninput="purchaseIndianStockChange(this)"
data-id="<?=$dateInMonth?>"
contenteditable="true">0</td>
<td class="celda_normal total"
data-id="<?=$dateInMonth?>"
>0</td>
<td class="celda_normal consumption"
data-id="<?=$dateInMonth?>"
>0</td>
<td class="celda_normal balanceStock"
data-id="<?=$dateInMonth?>"
>0</td>
<td class="celda_normal">0</td>
<td class="celda_normal">0</td>
<td class="celda_normal">0</td>
<td class="celda_normal">0</td>
<td class="celda_normal">0</td>
<td class="celda_normal">0</td>
<td class="celda_normal">0</td>
</tr>
<?php }
}?>
@ -364,7 +405,7 @@
//table to json function
var updateBagStockDetails = tableToJson();
var updateGasStockDetails = tableToJson();
alert('Updation may take a while, And we appreciate your patience..!!');
@ -372,10 +413,10 @@
$('#loader').show();
$.ajax({
data: {
updateBagStockDetails
updateGasStockDetails
},
type: "POST",
url: "<?php echo base_url() ?>updateBagStockDetails",
url: "<?php echo base_url() ?>updateGasStockDetails",
success: function (data) {
if (data) {
@ -406,32 +447,27 @@
<script>
function tableToJson() {
const table = $('#bagStockDetailsTableId');
const table = $('#gasStockDetailsTableId');
const rows = [];
//this table to json is customized for bagstock not for all
table.find('tbody tr').each(function() {
table.find('tbody tr').each(function() {
const rowCells = $(this).find('td');
const date = rowCells.eq(0).text().trim();
/** we get eight entries against a material so we loop from 1 to 7 and so on
in a single row **/
for (let i = 1; i < rowCells.length; i += 7) {
let date = rowCells.eq(0).text().trim().split('-');
date=`${date[2]}-${date[1]}-${date[0]}`;
const rowData = {
date: rowCells.eq(i).text().trim(),
materialCode: 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()
date,
opening: rowCells.eq(1).text().trim()|| '0',
purchaseBharath: rowCells.eq(2).text().trim()|| '0',
purchaseIndian: rowCells.eq(3).text().trim()|| '0',
total: rowCells.eq(4).text().trim()|| '0',
consumption: rowCells.eq(5).text().trim()|| '0',
balanceStock: rowCells.eq(6).text().trim()|| '0'
};
rows.push(rowData);
}
});
return JSON.stringify(rows, null, 2);
@ -445,14 +481,18 @@
try{
let dataId = tdElement.getAttribute('data-id');
let [date,materialCode] = tdElement.getAttribute('data-id').split(' ');
let date = dataId;
let openingStock = tdElement.innerText;
let usedStock = document.querySelector(`td.usedStock[data-id="${dataId}"]`).innerText;
let receiptStock = document.querySelector(`td.receiptStock[data-id="${dataId}"]`).innerText;
let currentBalanceStock = (Number(openingStock) + Number(receiptStock)) - Number(usedStock);
document.querySelector(`td.balanceStock[data-id="${dataId}"]`).innerText=currentBalanceStock;
let purchaseBharathStock = document.querySelector(`td.purchaseBharath[data-id="${dataId}"]`).innerText;
let purchaseIndianStock = document.querySelector(`td.purchaseIndian[data-id="${dataId}"]`).innerText;
let toatalGasConsumption = document.querySelector(`td.consumption[data-id="${dataId}"]`).innerText;
let totalGas = (Number(openingStock) + Number(purchaseBharathStock)) + Number(purchaseIndianStock);
let currentBalanceStock = Number(totalGas) - Number(toatalGasConsumption);
updateStockValue( date,materialCode,currentBalanceStock )
document.querySelector(`td.total[data-id="${dataId}"]`).innerText=totalGas;
document.querySelector(`td.balanceStock[data-id="${dataId}"]`).innerText= currentBalanceStock;
updateStockValue( date,currentBalanceStock )
} catch(error){
@ -462,18 +502,22 @@
}
}
function receiptStockChange(tdElement) {
try{
function purchaseBharathStockChange(tdElement) {
try{
let dataId = tdElement.getAttribute('data-id');
let [date,materialCode] = tdElement.getAttribute('data-id').split(' ');
let date = dataId;
let openingStock = document.querySelector(`td.openingStock[data-id="${dataId}"]`).innerText;
let receiptStock = tdElement.innerText;
let usedStock = document.querySelector(`td.usedStock[data-id="${dataId}"]`).innerText;
let currentBalanceStock = (Number(openingStock) + Number(receiptStock)) - Number(usedStock);
document.querySelector(`td.balanceStock[data-id="${dataId}"]`).innerText=currentBalanceStock;
updateStockValue( date,materialCode,currentBalanceStock )
let purchaseBharathStock = tdElement.innerText;
let purchaseIndianStock = document.querySelector(`td.purchaseIndian[data-id="${dataId}"]`).innerText;
let toatalGasConsumption = document.querySelector(`td.consumption[data-id="${dataId}"]`).innerText;
let totalGas = (Number(openingStock) + Number(purchaseBharathStock)) + Number(purchaseIndianStock);
let currentBalanceStock = Number(totalGas) - Number(toatalGasConsumption);
document.querySelector(`td.total[data-id="${dataId}"]`).innerText=totalGas;
document.querySelector(`td.balanceStock[data-id="${dataId}"]`).innerText= currentBalanceStock;
updateStockValue( date,currentBalanceStock )
} catch(error){
@ -484,72 +528,72 @@
function usedStockChange(tdElement) {
function purchaseIndianStockChange(tdElement) {
try {
try{
let dataId = tdElement.getAttribute('data-id');
let [date,materialCode] = tdElement.getAttribute('data-id').split(' ');
let date = dataId;
let openingStock = document.querySelector(`td.openingStock[data-id="${dataId}"]`).innerText;
let receiptStock = document.querySelector(`td.receiptStock[data-id="${dataId}"]`).innerText;
let usedStock = tdElement.innerText;
let currentBalanceStock = ( Number(openingStock) + Number(receiptStock) ) - Number(usedStock);
document.querySelector(`td.balanceStock[data-id="${dataId}"]`).innerText=currentBalanceStock;
updateStockValue( date,materialCode,currentBalanceStock )
let purchaseBharathStock = document.querySelector(`td.purchaseBharath[data-id="${dataId}"]`).innerText;
let purchaseIndianStock = tdElement.innerText;
let toatalGasConsumption = document.querySelector(`td.consumption[data-id="${dataId}"]`).innerText;
let totalGas = (Number(openingStock) + Number(purchaseBharathStock)) + Number(purchaseIndianStock);
let currentBalanceStock = Number(totalGas) - Number(toatalGasConsumption);
} catch (error) {
document.querySelector(`td.total[data-id="${dataId}"]`).innerText = totalGas;
document.querySelector(`td.balanceStock[data-id="${dataId}"]`).innerText = currentBalanceStock;
updateStockValue( date,currentBalanceStock )
} catch(error){
console.error("There is an error updating stock ..!!" + error);
console.error("There is an error updating stock ..!!" + error);
}
}
}
</script>
<script>
function updateStockValue( date, materialCode, currentBalanceStock ){
function updateStockValue( date, currentBalanceStock ){
const table = $('#bagStockDetailsTableId');
const table = $('#gasStockDetailsTableId');
const rows = [];
table.find('tbody tr').each(function() {
const rowCells = $(this).find('td');
const otherDate = rowCells.eq(1).text().trim();
let otherDate = rowCells.eq(0).text().trim().split('-');
otherDate=`${otherDate[2]}-${otherDate[1]}-${otherDate[0]}`;
if( new Date(otherDate) > new Date(date) ){ //other records present after it
/**this data-id ,openingStock ,used stock , current Balance Stock
is for changing subsequent dates not the earlier one **/
let dataId = `${otherDate} ${materialCode}`;
let dataId = `${otherDate}`;
document.querySelector(`td.openingStock[data-id="${dataId}"]`).innerText=currentBalanceStock;
let usedStock = document.querySelector(`td.usedStock[data-id="${dataId}"]`).innerText;
let openingStock = currentBalanceStock ;
let receiptStock = document.querySelector(`td.receiptStock[data-id="${dataId}"]`).innerText;
let purchaseBharathStock = document.querySelector(`td.purchaseBharath[data-id="${dataId}"]`).innerText;
currentBalanceStock = (Number(currentBalanceStock) + Number(receiptStock)) - Number(usedStock);
let purchaseIndianStock = document.querySelector(`td.purchaseIndian[data-id="${dataId}"]`).innerText;
let toatalGasConsumption = document.querySelector(`td.consumption[data-id="${dataId}"]`).innerText;
let totalGas = (Number(openingStock) + Number(purchaseBharathStock)) + Number(purchaseIndianStock);
currentBalanceStock = Number(totalGas) - Number(toatalGasConsumption);
document.querySelector(`td.total[data-id="${dataId}"]`).innerText= totalGas;
document.querySelector(`td.balanceStock[data-id="${dataId}"]`).innerText=currentBalanceStock;
document.querySelector(`td.balanceStock[data-id="${dataId}"]`).innerText = currentBalanceStock;
// console.log( 'other date' , new Date(otherDate));
// console.log('new balance stock' , currentBalanceStock)
}
})
}
}
function customerChange(thElement){
let materialCode = thElement.getAttribute('data-materialCode');
let newCustomerValue = thElement.innerText;
let matchingCustomerData = document.querySelectorAll(`td.customer[data-materialCode="${materialCode}"]`);
matchingCustomerData.forEach((element,index)=>{
element.innerText=newCustomerValue;
})
}
</script>

View File

@ -767,7 +767,7 @@
<div class="dropdown-menu" aria-labelledby="topnav-stock">
<div class="">
<a href="<?php echo base_url(); ?>incomingSilicaSandDetails" class="dropdown-item"><i class="ri-file-info-line align-middle mr-1"></i>incoming silica sand Details</a>
<a href="<?php echo base_url(); ?>incomingSilicaSandDetails" class="dropdown-item"><i class="ri-file-info-line align-middle mr-1"></i>Incoming Silica Sand Details</a>
<a href="<?php echo base_url(); ?>drierMachineDetails" class="dropdown-item"><i class="ri-file-info-line align-middle mr-1"></i>10 TON Drier Details</a>