stock module latest today vadivel J 04-1-2025

This commit is contained in:
vadivelJ96 2025-01-04 18:43:59 +05:30
parent 3113701bd0
commit 609e3f9d5e
5 changed files with 1114 additions and 2 deletions

View File

@ -18,6 +18,9 @@ use App\Models\DustAndRoughModel;
use App\Models\ResinStockModel;
use App\Models\GasStockModel;
use App\Models\TrpSandUseStockModel;
use App\Models\TrpProductionModel;
use App\Models\TrpProductionMaintenanceModel;
use App\Models\TrpProductionWasteModel;
use CodeIgniter\HTTP\ResponseInterface;
use DateTime;
use DatePeriod;
@ -45,6 +48,12 @@ class StockController extends BaseController
protected $TrpSandUseStock_model;
protected $TrpProduction_model;
protected $TrpProductionMaintenance_model;
protected $TrpProductionWaste_model;
protected $db;
/**
@ -85,6 +94,12 @@ class StockController extends BaseController
$this->TrpSandUseStock_model = new TrpSandUseStockModel();
$this->TrpProduction_model = new TrpProductionModel();
$this->TrpProductionMaintenance_model = new TrpProductionMaintenanceModel();
$this->TrpProductionWaste_model = new TrpProductionWasteModel();
$this->session = session();
helper('form');
@ -1210,6 +1225,7 @@ class StockController extends BaseController
}
public function updateTrpSandUseStockDetails(){
$postData = $this->request->getPost();
$updateTrpSandUseStockDetailsData = json_decode($postData['updateTrpSandUseStockDetails'], true);
@ -1266,9 +1282,183 @@ class StockController extends BaseController
public function trpProductionDetails(){}
public function trpProductionDetails(){
public function updateTrpProductionDetails(){}
if ($this->request->getMethod() === 'POST') {
$month = $this->request->getPost('month');
$date = DateTime::createFromFormat('M-Y', $month);
$formattedDate = $date->format('Y-m');
$month = $formattedDate;
} else {
$month = date('Y-m');
}
$data = [];
$data['month'] = $month;
$this->global['pageTitle'] = 'Trp production Details';
$startDate = "$month-01";
$endDate = date("Y-m-t", strtotime($startDate));
$data['trpProductionDetails'] = $this->TrpProductionMaintenance_model
->join('t_trpProduction', 't_trpProduction.date = t_trpProductionMaintenance.date')
->join('t_trpProductionWaste', 't_trpProductionWaste.date = t_trpProductionMaintenance.date')
->join('t_')
->where('date >=', $startDate)
->where('date <=', $endDate)
->orderBy('date', 'asc')
->findAll();
$date = DateTime::createFromFormat('Y-m', $month);
$formattedDate = $date->format('M-Y');
$data['month'] = $formattedDate;
return $this->loadViews("trpSandUseStockDetails", $this->global, $data, NULL);
}
public function updateTrpProductionDetails() {
$postData = $this->request->getPost();
$updateTrpProductionDetails = json_decode($postData['updateTrpProductionDetails'], true);
$updateProduction = [];
$updateMaintanence = [];
$updateWaste = [];
$insertProduction = [];
$insertMaintanence = [];
$insertWaste = [];
foreach ($updateTrpProductionDetails as $data) {
$data['date'] = $this->convertToDateWithFlexibleFormats($data['Date'], ["d-m-Y", "Y-m-d", "m/d/Y", "m-d-Y"], "Y-m-d");
$date = $data['date'];
$dbDataTrpMaintenance = [
'date' => $data['date'],
'openingTime' => $data['openingTime'],
'closingTime' => $data['closingTime'],
'totalHours' => $data['totalHours'],
'coldStart' => $data['coldStart'],
'breakdownHours' => $data['breakdownHours'],
'burnerFiringHours' => $data['burnerFiringHours'],
'sandFeedingHours' => $data['sandFeedingHours'],
'workingPersonEngineers' => $data['workingPersonEngineers'],
'workingPersonSupervisiors' => $data['workingPersonSupervisiors'],
'workingPersonOperators' => $data['workingPersonOperators'],
'rollerDrivers' => $data['rollerDrivers'],
'natureOfMaintenance' => $data['natureOfMaintenance'],
'location' => $data['location'],
'description' => $data['description']
];
$dbDataTrpProduction = [
'date' => $data['date'],
'gasReceiptBg' => $data['gasReceiptBg'],
'gasReceiptPg' => $data['gasReceiptPg'],
'physicalGasConsumption'=> $data['physicalGasConsumption'],
'trpPlusDrierGasConsumption'=> $data['trpPlusDrierGasConsumption'],
'trpPhysicalGasPerTon' => $data['trpPhysicalGasPerTon'],
'panelGasConsumption' => $data['panelGasConsumption'],
'panelGasPerTon' => $data['panelGasPerTon'],
'edRunningHours' => $data['edRunningHours'],
'edProduction' => $data['edProduction'],
'edUsage' => $data['edUsage'],
'trpProduction' => $data['trpProduction'],
'trpProductionPerHour' => $data['trpProductionPerHour'],
'waterReceipt' => $data['waterReceipt'],
'waterConsumption' => $data['waterConsumption'],
'ebReading' => $data['ebReading'],
'ebReadingPerUnitTon' => $data['ebReadingPerUnitTon'],
];
$dbDataTrpWaste = [
'date' => $data['date'],
'msSeperation' => $data['msSeperation'],
'edWaste' => $data['edWaste'],
'coolerBags' => $data['coolerBags'],
'edPlus20Waste' => $data['edPlus20Waste'],
'cycloneWaste' => $data['cycloneWaste'],
];
$trpMaintenanceResultExists = $this->TrpProductionMaintenance_model
->where('date', $date)
->first();
$trpProductionResultExists = $this->TrpProduction_model
->where('date', $date)
->first();
$trpWasteResultExists = $this->TrpProductionWaste_model
->where('date', $date)
->first();
if (empty($trpMaintenanceResultExists)) {
$insertMaintanence[] = $dbDataTrpMaintenance;
$insertProduction[] = $dbDataTrpProduction;
$insertWaste[] = $dbDataTrpWaste;
} else {
$dbDataTrpMaintenance['id'] = $trpMaintenanceResultExists['id'];
$dbDataTrpProduction['id'] = $trpProductionResultExists['id'];
$dbDataTrpWaste['id'] = $trpWasteResultExists['id'];
$updateMaintanence[] = $dbDataTrpMaintenance;
$updateProduction[] = $dbDataTrpProduction;
$updateWaste[] = $dbDataTrpWaste;
}
}
// Start the transaction
$this->db->transBegin();
try {
if (!empty($insertMaintanence)) {
$this->TrpProductionMaintenance_model->insertBatch($insertMaintanence);
}
if (!empty($insertProduction)) {
$this->TrpProduction_model->insertBatch($insertProduction);
}
if (!empty($insertWaste)) {
$this->TrpProductionWaste_model->insertBatch($insertWaste);
}
if (!empty($updateMaintanence)) {
$this->TrpProductionMaintenance_model->updateBatch($updateMaintanence, 'id');
}
if (!empty($updateProduction)) {
$this->TrpProduction_model->updateBatch($updateProduction, 'id');
}
if (!empty($updateWaste)) {
$this->TrpProductionWaste_model->updateBatch($updateWaste, 'id');
}
// Commit the transaction if all operations are successful
$this->db->transCommit();
echo "Data Saved Successfully";
} catch (\Exception $error) {
// Rollback the transaction in case of any errors
$this->db->transRollback();
echo "An error occurred: " . $error->getMessage();
}
}

View File

@ -0,0 +1,48 @@
<?php
namespace App\Models;
use CodeIgniter\Model;
class TrpProductionMaintenanceModel extends Model
{
protected $table = 't_trpProductionMaintenanceDetails';
protected $primaryKey = 'id';
protected $useAutoIncrement = true;
protected $returnType = 'array';
protected $useSoftDeletes = false;
protected $protectFields = true;
protected $allowedFields = ['date', 'openingTime', 'closingTime', 'totalHours', 'coldStart', 'breakdownHours', 'burnerFiringHours',
'sandFeedingHours', 'workingPersonEngineers', 'workingPersonSupervisiors', 'workingPersonOperators',
'rollerDrivers', 'natureOfMaintenance', 'location', 'description'];
protected bool $allowEmptyInserts = false;
protected bool $updateOnlyChanged = true;
protected array $casts = [];
protected array $castHandlers = [];
// Dates
protected $useTimestamps = false;
protected $dateFormat = 'datetime';
protected $createdField = 'created_at';
protected $updatedField = 'updated_at';
protected $deletedField = 'deleted_at';
// Validation
protected $validationRules = [];
protected $validationMessages = [];
protected $skipValidation = false;
protected $cleanValidationRules = true;
// Callbacks
protected $allowCallbacks = true;
protected $beforeInsert = [];
protected $afterInsert = [];
protected $beforeUpdate = [];
protected $afterUpdate = [];
protected $beforeFind = [];
protected $afterFind = [];
protected $beforeDelete = [];
protected $afterDelete = [];
}

View File

@ -0,0 +1,49 @@
<?php
namespace App\Models;
use CodeIgniter\Model;
class TrpProductionModel extends Model
{
protected $table = 't_trpProductionDetails';
protected $primaryKey = 'id';
protected $useAutoIncrement = true;
protected $returnType = 'array';
protected $useSoftDeletes = false;
protected $protectFields = true;
protected $allowedFields = ['date', 'gasReceiptBg', 'gasReceiptPg', 'physicalGasConsumption', 'trpPlusDrierGasConsumption',
'trpPhysicalGasPerTon', 'panelGasConsumption','panelGasPerTon','edRunningHours','edProduction','edUsage',
'trpProduction', 'trpProductionPerHour', 'waterReceipt', 'waterConsumption' ,'ebReading',
'ebReadingPerUnitTon'];
protected bool $allowEmptyInserts = false;
protected bool $updateOnlyChanged = true;
protected array $casts = [];
protected array $castHandlers = [];
// Dates
protected $useTimestamps = false;
protected $dateFormat = 'datetime';
protected $createdField = 'created_at';
protected $updatedField = 'updated_at';
protected $deletedField = 'deleted_at';
// Validation
protected $validationRules = [];
protected $validationMessages = [];
protected $skipValidation = false;
protected $cleanValidationRules = true;
// Callbacks
protected $allowCallbacks = true;
protected $beforeInsert = [];
protected $afterInsert = [];
protected $beforeUpdate = [];
protected $afterUpdate = [];
protected $beforeFind = [];
protected $afterFind = [];
protected $beforeDelete = [];
protected $afterDelete = [];
}

View File

@ -0,0 +1,46 @@
<?php
namespace App\Models;
use CodeIgniter\Model;
class TrpProductionWasteModel extends Model
{
protected $table = 't_trpProductionWasteDetails';
protected $primaryKey = 'id';
protected $useAutoIncrement = true;
protected $returnType = 'array';
protected $useSoftDeletes = false;
protected $protectFields = true;
protected $allowedFields = ['date','msSeperation','edWaste','coolerBags','edPlus20Waste','cycloneWaste'];
protected bool $allowEmptyInserts = false;
protected bool $updateOnlyChanged = true;
protected array $casts = [];
protected array $castHandlers = [];
// Dates
protected $useTimestamps = false;
protected $dateFormat = 'datetime';
protected $createdField = 'created_at';
protected $updatedField = 'updated_at';
protected $deletedField = 'deleted_at';
// Validation
protected $validationRules = [];
protected $validationMessages = [];
protected $skipValidation = false;
protected $cleanValidationRules = true;
// Callbacks
protected $allowCallbacks = true;
protected $beforeInsert = [];
protected $afterInsert = [];
protected $beforeUpdate = [];
protected $afterUpdate = [];
protected $beforeFind = [];
protected $afterFind = [];
protected $beforeDelete = [];
protected $afterDelete = [];
}

View File

@ -0,0 +1,779 @@
<style type="text/css">
.num {
text-align: right;
}
.fht-table,
.fht-table thead,
.fht-table tfoot,
.fht-table tbody,
.fht-table tr,
.fht-table th,
.fht-table td {
margin: 0;
}
.fht-table td {
text-align: center;
}
.fht-table td:hover {
background-color: #00a65a;
color: #ffffff;
}
.fht-table {
border: 0 none;
height: auto;
width: auto;
border-collapse: collapse;
border-spacing: 0;
/*table-layout: fixed; Algoritmo de distribucion fijo */
white-space: nowrap;
}
.fht-table th,
.fht-table td {
overflow: hidden;
}
.fht-table-wrapper,
.fht-table-wrapper .fht-thead,
.fht-table-wrapper .fht-tfoot,
.fht-table-wrapper .fht-fixed-column .fht-tbody,
.fht-table-wrapper .fht-fixed-body .fht-tbody,
.fht-table-wrapper .fht-tbody {
overflow: hidden;
position: relative;
}
.fht-table-wrapper .fht-fixed-body .fht-tbody,
.fht-table-wrapper .fht-tbody {
overflow: auto;
}
.fht-table-wrapper .fht-table .fht-cell {
overflow: hidden;
height: 1px;
}
.fht-table-wrapper .fht-fixed-column,
.fht-table-wrapper .fht-fixed-body {
top: 0;
left: 0;
position: absolute;
}
.fht-table-wrapper .fht-fixed-column {
z-index: 1;
}
.fht-fixed-body .fht-thead table {
margin-right: 20px;
border: 0 none;
}
/*For Examples*/
.ContenedorTabla {
height: 500px;
margin: 0 auto;
overflow: auto;
width: auto;
position: relative;
}
.header,
.main {
display: inline-block;
height: auto;
width: 100%;
}
.titulosHeader {
border-bottom: 1px solid #e8bb25;
height: auto;
margin-bottom: 10px;
padding-bottom: 8px;
padding-top: 8px;
width: 100%;
}
.celda_encabezado_general {
background-color: #00a65a;
border: 1px solid #ccc;
color: #ffffff;
font-weight: bold;
padding: 6px 10px;;
text-align: center;
}
._Separador {
background-color: #fff;
height: 12px;
border-left: 1px solid #ccc;
border-right: 1px solid #ccc;
width: 7px;
}
._Separador div {
width: 4px;
}
.celda_normal {
/*background-color: #fff;*/
/* <!-- ad9271 into ffffff brown-light to green-light --> */
text-align: center;
border: 1px solid #ccc;
padding: 2px 4px;
}
/*style excel*/
.excel_cell {
border: 1px solid #CCC;
color: #222;
text-align: center;
font-size: 13px;
font-weight: normal;
padding: 4px;
white-space: pre-line;
empty-cells: show;
}
._cell_header {
background-color: #EEE;
}
._cell_Default {
background-color: #FFF;
text-align: left;
}
.excel_cell div {
width: 30px;
height: 20px;
}
#resinStockDetailsTableId th:nth-child(1),
#resinStockDetailsTableId td:nth-child(1) {
position: sticky;
left: 0;
background-color: #00a65a;
z-index: 2;
border-right: 2px solid #ddd;
color: #ffffff;
}
.modal {
padding-right: 30% ! important;
}
</style>
<?php
$date = DateTime::createFromFormat('M-Y', $month);
$startDate = $date->modify('first day of this month')->format('Y-m-d');
$endDate = $date->modify('last day of this month')->format('Y-m-d');
$datesInMonth = [];
$period = new DatePeriod(
new DateTime($startDate),
new DateInterval('P1D'),
(new DateTime($endDate))->modify('+1 day')
);
foreach ($period as $day) {
$datesInMonth[] = $day->format('Y-m-d');
}
?>
<div class="content-page">
<div class="content">
<!-- Start Content-->
<div class="container-fluid">
<!-- start page title -->
<div>
<div class="row">
<div class="col-6">
<div class="page-title-box page-title-box-alt">
<div class="page-title-right">
<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">TRP Production Details </h4>
</li>
</ol>
</div>
</div>
</div>
<div class="col-6 text-right">
<!-- Right-aligned buttons or links can be added here -->
</div>
</div>
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-body">
<form action="<?= base_url('resinStockDetails'); ?>" method="post">
<div class="row">
<div class="col-3">
<input type="text" name="month" id="month" value="<?php echo "$month" ?>"
class="form-control mt-2" data-provide="datepicker"
data-date-format="M-yyyy" data-date-min-view-mode="1">
</div>
<div class="form-group col-md-2">
<button type="submit" class="btn btn-success"> Change Month </button>
</div>
<div class="col-md-1"></div>
<div class="col-6">
<div class="dropdown float-right">
<a href="#" class="dropdown-toggle arrow-none" data-toggle="dropdown"
aria-expanded="false">
<i class="mdi mdi-dots-vertical m-0 text-muted h3"></i>
</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>
</div>
</div>
</div>
</div>
</form>
<div class="table-responsive">
<table id="resinStockDetailsTableId" class="fht-table table-striped">
<thead class="celda_encabezado_general" style="padding: 10px;">
<tr>
<th class="celda_encabezado_general" colspan="1">material </th>
<?php foreach($resinMaterials as $resinMaterial){ ?>
<!-- this will loop till materials present -->
<th class="celda_encabezado_general" colspan="4">
<?= $resinMaterial['MaterialName']?>
<!-- (<?= $resinMaterial['MaterialCode']?>) -->
</th>
<?php } ?>
</tr>
<tr>
<th class="celda_encabezado_general" colspan="1">Date </th>
<?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>
<th class="celda_encabezado_general" style="display:none"> customer</th>
<th class="celda_encabezado_general">Opening Stock</th>
<th class="celda_encabezado_general">Receipt</th>
<th class="celda_encabezado_general">Used</th>
<th class="celda_encabezado_general">Balance Stock</th>
<?php } ?>
</tr>
</thead>
<tbody style="background-color: #fff;" >
<?php if(!empty($groupedResinStockDetails))
{
//dd($groupedResinStockDetails);
foreach($groupedResinStockDetails as $groupedResinStockDetailsIndex => $resinStockDetails){
?>
<tr
<?php
$currentDate = date('d-m-Y');
$dateInMonthDmYFormat= DateTime::createFromFormat('Y-m-d', $resinStockDetails[0]['date'])->format('d-m-Y');
if ($dateInMonthDmYFormat === $currentDate) { echo 'style="background: #cef0ad;"';}
?>
>
<?php foreach($resinStockDetails as $resinStockIndex => $resinStock){ ?>
<?php if ($resinStockIndex == 0): ?>
<?php
$startDate =DateTime::createFromFormat('Y-m-d', $resinStock['date'])->format('d-m-Y');
?>
<td class="celda_normal">
<?= $startDate ?>
</td>
<?php endif; ?>
<td style="display:none">
<?= $resinStock['date']?>
</td>
<td style="display:none"
data-id="<?=$resinStock['date']?> <?=$resinStock['materialCode']?>"
class="materialCode" ><?= $resinStock['materialCode']?>
</td>
<td style="display:none" class="celda_normal customer"
data-materialCode="<?=$resinStock['materialCode']?>"
data-id="<?=$resinStock['date']?> <?=$resinStock['materialCode']?>">
<?= $resinStock['customer']?>
</td>
<td class="celda_normal openingStock"
data-id="<?=$resinStock['date']?> <?=$resinStock['materialCode']?>"
<?php if ($groupedResinStockDetailsIndex == 0): ?>
oninput="openingStockChange(this)"
contenteditable="true"
<?php endif; ?>
><?= $resinStock['opening']?>
</td>
<td class="celda_normal receiptStock"
data-id="<?=$resinStock['date']?> <?=$resinStock['materialCode']?>"
oninput="receiptStockChange(this)"
contenteditable="true">
<?= $resinStock['receipt']?>
</td>
<td class="celda_normal usedStock"
data-id="<?=$resinStock['date']?> <?=$resinStock['materialCode']?>"
oninput="usedStockChange(this)"
contenteditable="true"><?= $resinStock['used']?>
</td>
<td class="celda_normal balanceStock"
data-id="<?=$resinStock['date']?> <?=$resinStock['materialCode']?>">
<?= $resinStock['balanceStock']?>
</td>
<?php } ?>
</tr>
<?php } ?>
<!-- this else condition work if groupedBagStockDetails is empty and creating new records
with initial values 0 for entire month -->
<?php } else { ?>
<?php foreach($datesInMonth as $datesInMonthIndex => $dateInMonth){ ?>
<tr
<?php
$currentDate = date('d-m-Y');
$dateInMonthDmYFormat= DateTime::createFromFormat('Y-m-d', $dateInMonth)->format('d-m-Y');
if ($dateInMonthDmYFormat === $currentDate) { echo 'style="background: #cef0ad;"';}
?>
>
<?php
foreach($resinMaterials as $resinMaterialIndex => $resinMaterial){ ?>
<!-- this will loop till materials present -->
<?php if ($resinMaterialIndex == 0): ?>
<?php
$startDate =DateTime::createFromFormat('Y-m-d', $dateInMonth)->format('d-m-Y');
?>
<td class="celda_normal">
<?= $startDate ?>
</td>
<?php endif; ?>
<td class="celda_normal" style="display:none">
<?= $dateInMonth?>
</td>
<td class="celda_normal" style="display:none"
data-id="<?=$dateInMonth?> <?=$resinMaterial['MaterialCode']?>">
<?= $resinMaterial['MaterialCode']?>
</td>
<td class="celda_normal customer" style="display:none"
data-materialCode="<?=$resinMaterial['MaterialCode']?>"
data-id="<?=$dateInMonth?> <?=$resinMaterial['MaterialCode']?>">
<?= $resinMaterial['customers']?>
</td>
<td class="celda_normal openingStock"
data-id="<?=$dateInMonth?> <?=$resinMaterial['MaterialCode']?>"
<?php if($datesInMonthIndex == 0){ ?>
oninput="openingStockChange(this)"
contenteditable="true"
<?php }?>
><?= $previousMonthResinStockDetails[$resinMaterialIndex]['balanceStock']??'0' ?></td>
<td class="celda_normal receiptStock"
data-id="<?=$dateInMonth?> <?=$resinMaterial['MaterialCode']?>"
oninput="receiptStockChange(this)"
contenteditable="true">0</td>
<td class="celda_normal usedStock"
data-id="<?=$dateInMonth?> <?=$resinMaterial['MaterialCode']?>"
oninput="usedStockChange(this)"
contenteditable="true">0</td>
<td class="celda_normal balanceStock"
data-id="<?=$dateInMonth?> <?=$resinMaterial['MaterialCode']?>"
><?= $previousMonthResinStockDetails[$resinMaterialIndex]['balanceStock']??'0' ?></td>
<?php } ?>
</tr>
<?php } ?>
<?php }?>
</tbody>
</table>
</div>
<div class="row">
<div class="col-md-12 text-right">
<input type="button" class="btn btn-success" id="saveId" value="save">
</div>
</div>
</div>
</div> <!-- End card-body -->
</div> <!-- End card -->
</div> <!-- End col -->
</div> <!-- End row -->
</div>
</div> <!-- End container-fluid -->
</div>
</div>
<div >
<div class="modal fade" id="bs-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg" >
<div class="modal-content" >
<div class="modal-header">
<h4 class="modal-title" id="myLargeModalLabel">Navigation Options</h4>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
<div class="modal-body">
<div class="row">
<!-- bag Dropdown -->
<div class="col-md-6">
<div class="form-group">
<label for="resinDropdown">Select Bag</label>
<select id="resinDropdown" class="form-control">
<option value="">Select Resin</option>
<?php foreach($resinMaterials as $resinMaterial): ?>
<option value=" <?= $resinMaterial['MaterialName']?>">
<?= $resinMaterial['MaterialName']?>
</option>
<?php endforeach; ?>
</select>
</div>
</div>
<!-- Date Dropdown -->
<div class="col-md-6">
<div class="form-group">
<label for="dateDropdown">Select Date</label>
<select id="dateDropdown" class="form-control">
<?php foreach($datesInMonth as $selectDate): ?>
<?php $selectDate=DateTime::createFromFormat('Y-m-d', $selectDate)->format('d-m-Y'); ?>
<option value="<?=$selectDate?>"><?=$selectDate?></option>
<?php endforeach; ?>
</select>
</div>
</div>
</div>
<button class="btn btn-primary float-right" onclick="navigateToResin()">Navigate</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
</div>
<script>
function navigateToResin() {
$('.close').click();
const resinDropdown = document.getElementById('resinDropdown');
const dateDropdown = document.getElementById('dateDropdown');
const selectedResin = resinDropdown.value;
const selectedDate = dateDropdown.value;
const table = document.getElementById('resinStockDetailsTableId');
const headerCells = table.querySelectorAll('thead tr:nth-child(1) th');
const rows = table.querySelectorAll('tbody tr');
let targetColumnIndex = -1;
headerCells.forEach((header, index) => {
if ((header.innerText.trim()) === selectedResin.trim()) {
targetColumnIndex = index;
return;
}
});
if (targetColumnIndex === -1) {
console.log("Resin column not found.");
return;
}
let targetRow = null;
rows.forEach(row => {
const dateCell = row.querySelector('td:first-child');
if (dateCell && dateCell.textContent.trim() === selectedDate) {
targetRow = row;
}
});
if (!targetRow) {
console.log("Date row not found.");
return;
}
console.log(targetColumnIndex);
console.log(targetRow);
targetColumnIndex = targetColumnIndex * 7;
targetRow.cells[targetColumnIndex].scrollIntoView({
behavior: 'smooth',
inline: 'center',
block: 'center'
});
const highlightDuration = 10000;
for (let i = targetColumnIndex-4 ; i <= targetColumnIndex ; i++) {
const cell = targetRow.cells[i];
if (cell) {
cell.style.transition = "background-color 0.5s";
cell.style.backgroundColor = "#df9675";
setTimeout(() => {
cell.style.backgroundColor = "";
}, highlightDuration);
}
}
}
</script>
<script type="text/javascript">
$(document).ready(function () {
$('#saveId').click(function () {
//table to json function
var updateResinStockDetails = tableToJson();
alert('Updation may take a while, And we appreciate your patience..!!');
$('#loader').show();
$.ajax({
data: {
updateResinStockDetails
},
type: "POST",
url: "<?php echo base_url() ?>updateResinStockDetails",
success: function (data) {
if (data) {
$('#loader').hide();
console.log(data);
alert(data);
}
},
error: function(xhr, status, error) {
alert("An error occurred while processing the request. Please try again.");
console.error("Error Code:", xhr.status);
console.error("Error Message:", error);
console.error("Response Text:", xhr.responseText);
},
complete: function() {
$('#loader').hide();
}
});
});
});
</script>
<script>
function tableToJson() {
const table = $('#resinStockDetailsTableId');
const rows = [];
//this table to json is customized for bagstock not for all
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) {
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()
};
rows.push(rowData);
}
});
return JSON.stringify(rows, null, 2);
}
</script>
<script>
function openingStockChange(tdElement) {
try{
let dataId = tdElement.getAttribute('data-id');
let [date,materialCode] = tdElement.getAttribute('data-id').split(' ');
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;
updateStockValue( date,materialCode,currentBalanceStock )
} catch(error){
console.error("There is an error updating stock ..!!" + error);
}
}
function receiptStockChange(tdElement) {
try{
let dataId = tdElement.getAttribute('data-id');
let [date,materialCode] = tdElement.getAttribute('data-id').split(' ');
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 )
} catch(error){
console.error("There is an error updating stock ..!!" + error);
}
}
function usedStockChange(tdElement) {
try {
let dataId = tdElement.getAttribute('data-id');
let [date,materialCode] = tdElement.getAttribute('data-id').split(' ');
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 )
} catch (error) {
console.error("There is an error updating stock ..!!" + error);
}
}
</script>
<script>
function updateStockValue( date, materialCode, currentBalanceStock ){
const table = $('#resinStockDetailsTableId');
const rows = [];
table.find('tbody tr').each(function() {
const rowCells = $(this).find('td');
const otherDate = rowCells.eq(1).text().trim();
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}`;
document.querySelector(`td.openingStock[data-id="${dataId}"]`).innerText=currentBalanceStock;
let usedStock = document.querySelector(`td.usedStock[data-id="${dataId}"]`).innerText;
let receiptStock = document.querySelector(`td.receiptStock[data-id="${dataId}"]`).innerText;
currentBalanceStock = (Number(currentBalanceStock) + Number(receiptStock)) - Number(usedStock);
document.querySelector(`td.balanceStock[data-id="${dataId}"]`).innerText=currentBalanceStock;
}
})
}
</script>