resin stock finished

This commit is contained in:
vadivel J 2024-11-08 12:00:02 +05:30
parent 1126731c5a
commit 7975bf5739
2 changed files with 86 additions and 95 deletions

View File

@ -499,21 +499,21 @@ class StockController extends BaseController
}
}
if (!empty($inserts)) {
$this->dustAndRoughStockDetails_model->insertBatch($inserts);
}
if (!empty($inserts)) {
$this->dustAndRoughStockDetails_model->insertBatch($inserts);
}
if (!empty($updates)) {
if (!empty($updates)) {
$updateResult = $this->dustAndRoughStockDetails_model->updateBatch($updates, 'date');
if ($updateResult === FALSE) {
echo "Error during update";
} else {
echo "Data Updated Successfully";
return;
}
}
$updateResult = $this->dustAndRoughStockDetails_model->updateBatch($updates, 'date');
if ($updateResult === FALSE) {
echo "Error during update";
} else {
echo "Data Updated Successfully";
return;
}
}
echo "Data Saved Successfully";
@ -525,7 +525,7 @@ class StockController extends BaseController
public function loadView_resinStockDetails(){
if ($this->request->getMethod() === 'POST'){
$month = $this->request->getPost('month');
$date = DateTime::createFromFormat('M-Y', $month);
@ -628,13 +628,17 @@ class StockController extends BaseController
$updateResinStockDetailsData = json_decode($postData['updateResinStockDetails'], true);
$updates = [];
$inserts = [];
foreach($updateResinStockDetailsData as $data){
$date = $data['date'];
$materialCode = $data['materialCode'];
$dbData= [
$dbData = [
'date' =>$data['date'],
'materialCode' =>$data['materialCode'],
'customer' =>$data['customer'],
@ -650,19 +654,30 @@ class StockController extends BaseController
->first();
if(!empty($resultExists)){
$updated = $this->resinStockDetails_model
->where('date',$date)
->where('materialCode',$materialCode)
->set($dbData)
->update();
if(empty($resultExists)){
$inserts[] = $dbData;
}else{
$inserted = $this->resinStockDetails_model->insert($dbData);
$updates[] = $dbData;
}
}
}
if (!empty($inserts)) {
$this->resinStockDetails_model->insertBatch($inserts);
}
if (!empty($updates)) {
$updateResult = $this->resinStockDetails_model->updateBatch($updates, 'id');
if ($updateResult === FALSE) {
echo "Error during update";
} else {
echo "Data Updated Successfully";
return;
}
}
echo "Data Saved Successfully";

View File

@ -173,7 +173,7 @@
<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">Bag Stock Details </h4>
<h4 class="page-title">Resin Stock Details </h4>
</li>
</ol>
</div>
@ -193,7 +193,7 @@
<div class="card-body">
<form action="<?= base_url('bagStockDetails'); ?>" method="post">
<form action="<?= base_url('resinStockDetails'); ?>" method="post">
<div class="row">
<div class="col-3">
@ -210,7 +210,7 @@
<div class="table-responsive">
<table id="bagStockDetailsTableId" class="fht-table table-striped">
<table id="resinStockDetailsTableId" class="fht-table table-striped">
<thead class="celda_encabezado_general" style="padding: 10px;">
@ -218,34 +218,21 @@
<th class="celda_encabezado_general" colspan="1">material </th>
<?php foreach($bagMaterials as $bagMaterial){ ?>
<?php foreach($resinMaterials as $resinMaterial){ ?>
<!-- this will loop till materials present -->
<th class="celda_encabezado_general" colspan="4">
<?= $bagMaterial['MaterialName']?>
<!-- (<?= $bagMaterial['MaterialCode']?>) -->
<?= $resinMaterial['MaterialName']?>
<!-- (<?= $resinMaterial['MaterialCode']?>) -->
</th>
<?php } ?>
</tr>
<tr>
<th class="celda_encabezado_general" colspan="1"> Customer </th>
<?php foreach($bagMaterials as $bagMaterial){ ?>
<!-- this will loop till materials present -->
<th class="celda_encabezado_general" colspan="4"
data-materialCode="<?=$bagMaterial['MaterialCode']?>"
oninput="customerChange(this)" contenteditable="true">
<?= $bagMaterial['customers']?>
</th>
</th>
<?php } ?>
</tr>
<tr>
<th class="celda_encabezado_general" colspan="1">Date </th>
<?php foreach($bagMaterials as $bagMaterial){ ?>
<?php foreach($resinMaterials as $resinMaterial){ ?>
<!-- this will loop till materials present -->
<th class="celda_encabezado_general" style="display:none">Date</th>
<th class="celda_encabezado_general" style="display:none"> material</th>
@ -262,16 +249,16 @@
<tbody style="background-color: #fff;" >
<?php if(!empty($groupedBagStockDetails))
<?php if(!empty($groupedResinStockDetails))
{
//dd($groupedBagStockDetails);
foreach($groupedBagStockDetails as $groupedBagStockDetailsIndex => $bagStockDetails){
foreach($groupedResinStockDetails as $groupedResinStockDetailsIndex => $resinStockDetails){
?>
<tr>
<?php foreach($bagStockDetails as $bagStockIndex => $bagStock){ ?>
<?php if ($bagStockIndex == 0): ?>
<?php foreach($resinStockDetails as $resinStockIndex => $resinStock){ ?>
<?php if ($resinStockIndex == 0): ?>
<?php
$startDate =DateTime::createFromFormat('Y-m-d', $bagStock['date'])->format('d-m-Y');
$startDate =DateTime::createFromFormat('Y-m-d', $resinStock['date'])->format('d-m-Y');
?>
<td class="celda_normal">
<?= $startDate ?>
@ -279,46 +266,46 @@
<?php endif; ?>
<td style="display:none">
<?= $bagStock['date']?>
<?= $resinStock['date']?>
</td>
<td style="display:none"
data-id="<?=$bagStock['date']?> <?=$bagStock['materialCode']?>"
class="materialCode" ><?= $bagStock['materialCode']?>
data-id="<?=$resinStock['date']?> <?=$resinStock['materialCode']?>"
class="materialCode" ><?= $resinStock['materialCode']?>
</td>
<td style="display:none" class="celda_normal customer"
data-materialCode="<?=$bagStock['materialCode']?>"
data-id="<?=$bagStock['date']?> <?=$bagStock['materialCode']?>">
<?= $bagStock['customer']?>
data-materialCode="<?=$resinStock['materialCode']?>"
data-id="<?=$resinStock['date']?> <?=$resinStock['materialCode']?>">
<?= $resinStock['customer']?>
</td>
<td class="celda_normal openingStock"
data-id="<?=$bagStock['date']?> <?=$bagStock['materialCode']?>"
data-id="<?=$resinStock['date']?> <?=$resinStock['materialCode']?>"
<?php if ($groupedBagStockDetailsIndex == 0): ?>
<?php if ($groupedResinStockDetailsIndex == 0): ?>
oninput="openingStockChange(this)"
contenteditable="true"
<?php endif; ?>
><?= $bagStock['opening']?>
><?= $resinStock['opening']?>
</td>
<td class="celda_normal receiptStock"
data-id="<?=$bagStock['date']?> <?=$bagStock['materialCode']?>"
data-id="<?=$resinStock['date']?> <?=$resinStock['materialCode']?>"
oninput="receiptStockChange(this)"
contenteditable="true">
<?= $bagStock['receipt']?>
<?= $resinStock['receipt']?>
</td>
<td class="celda_normal usedStock"
data-id="<?=$bagStock['date']?> <?=$bagStock['materialCode']?>"
data-id="<?=$resinStock['date']?> <?=$resinStock['materialCode']?>"
oninput="usedStockChange(this)"
contenteditable="true"><?= $bagStock['used']?>
contenteditable="true"><?= $resinStock['used']?>
</td>
<td class="celda_normal balanceStock"
data-id="<?=$bagStock['date']?> <?=$bagStock['materialCode']?>">
<?= $bagStock['balanceStock']?>
data-id="<?=$resinStock['date']?> <?=$resinStock['materialCode']?>">
<?= $resinStock['balanceStock']?>
</td>
<?php } ?>
@ -355,10 +342,10 @@
<?php foreach($datesInMonth as $datesInMonthIndex => $dateInMonth){ ?>
<tr>
<?php
foreach($bagMaterials as $bagMaterialIndex => $bagMaterial){ ?>
foreach($resinMaterials as $resinMaterialIndex => $resinMaterial){ ?>
<!-- this will loop till materials present -->
<?php if ($bagMaterialIndex == 0): ?>
<?php if ($resinMaterialIndex == 0): ?>
<?php
$startDate =DateTime::createFromFormat('Y-m-d', $dateInMonth)->format('d-m-Y');
?>
@ -372,39 +359,39 @@
</td>
<td class="celda_normal" style="display:none"
data-id="<?=$dateInMonth?> <?=$bagMaterial['MaterialCode']?>">
<?= $bagMaterial['MaterialCode']?>
data-id="<?=$dateInMonth?> <?=$resinMaterial['MaterialCode']?>">
<?= $resinMaterial['MaterialCode']?>
</td>
<td class="celda_normal customer" style="display:none"
data-materialCode="<?=$bagMaterial['MaterialCode']?>"
data-id="<?=$dateInMonth?> <?=$bagMaterial['MaterialCode']?>">
<?= $bagMaterial['customers']?>
data-materialCode="<?=$resinMaterial['MaterialCode']?>"
data-id="<?=$dateInMonth?> <?=$resinMaterial['MaterialCode']?>">
<?= $resinMaterial['customers']?>
</td>
<td class="celda_normal openingStock"
data-id="<?=$dateInMonth?> <?=$bagMaterial['MaterialCode']?>"
data-id="<?=$dateInMonth?> <?=$resinMaterial['MaterialCode']?>"
<?php if($datesInMonthIndex == 0){ ?>
oninput="openingStockChange(this)"
contenteditable="true"
<?php }?>
><?= $previousMonthBagStockDetails[$bagMaterialIndex]['balanceStock']??'0' ?></td>
><?= $previousMonthResinStockDetails[$resinMaterialIndex]['balanceStock']??'0' ?></td>
<td class="celda_normal receiptStock"
data-id="<?=$dateInMonth?> <?=$bagMaterial['MaterialCode']?>"
data-id="<?=$dateInMonth?> <?=$resinMaterial['MaterialCode']?>"
oninput="receiptStockChange(this)"
contenteditable="true">0</td>
<td class="celda_normal usedStock"
data-id="<?=$dateInMonth?> <?=$bagMaterial['MaterialCode']?>"
data-id="<?=$dateInMonth?> <?=$resinMaterial['MaterialCode']?>"
oninput="usedStockChange(this)"
contenteditable="true">0</td>
<td class="celda_normal balanceStock"
data-id="<?=$dateInMonth?> <?=$bagMaterial['MaterialCode']?>"
><?= $previousMonthBagStockDetails[$bagMaterialIndex]['balanceStock']??'0' ?></td>
data-id="<?=$dateInMonth?> <?=$resinMaterial['MaterialCode']?>"
><?= $previousMonthResinStockDetails[$resinMaterialIndex]['balanceStock']??'0' ?></td>
<?php } ?>
</tr>
<?php } ?>
@ -448,7 +435,7 @@
//table to json function
var updateBagStockDetails = tableToJson();
var updateResinStockDetails = tableToJson();
alert('Updation may take a while, And we appreciate your patience..!!');
@ -456,10 +443,10 @@
$('#loader').show();
$.ajax({
data: {
updateBagStockDetails
updateResinStockDetails
},
type: "POST",
url: "<?php echo base_url() ?>updateBagStockDetails",
url: "<?php echo base_url() ?>updateResinStockDetails",
success: function (data) {
if (data) {
@ -490,7 +477,7 @@
<script>
function tableToJson() {
const table = $('#bagStockDetailsTableId');
const table = $('#resinStockDetailsTableId');
const rows = [];
//this table to json is customized for bagstock not for all
@ -594,7 +581,7 @@
function updateStockValue( date, materialCode, currentBalanceStock ){
const table = $('#bagStockDetailsTableId');
const table = $('#resinStockDetailsTableId');
const rows = [];
table.find('tbody tr').each(function() {
@ -619,21 +606,10 @@
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>