resin stock changes -vadivel J
This commit is contained in:
parent
c6821967d6
commit
590e2fd1ec
@ -449,3 +449,6 @@ $routes->post('updateBagStockDetails', 'StockController::updateBagStockDetails')
|
||||
$routes->match(['GET','POST'],'dustAndRoughStockDetails', 'StockController::loadView_dustAndRoughStockDetails');
|
||||
$routes->post('updateDustAndRoughStockDetails', 'StockController::updateDustAndRoughStockDetails');
|
||||
|
||||
//Resin stock details
|
||||
$routes->match(['GET','POST'],'resinStockDetails', 'StockController::loadView_resinStockDetails');
|
||||
$routes->post('updateResinStockDetails', 'StockController::updateResinStockDetails');
|
||||
@ -13,6 +13,7 @@ use App\Models\Inwardgateregister_model;
|
||||
use App\Models\Rawmaterialdetails_model;
|
||||
use App\Models\BagStockDetailsModel;
|
||||
use App\Models\DustAndRoughModel;
|
||||
use App\Models\ResinStockModel;
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
use DateTime;
|
||||
|
||||
@ -31,6 +32,7 @@ class StockController extends BaseController
|
||||
protected $bagStockDetails_model;
|
||||
protected $Rawmaterialdetails_model;
|
||||
protected $dustAndRoughStockDetails_model;
|
||||
protected $resinStockDetails_model;
|
||||
|
||||
/**
|
||||
* This is default constructor of the class
|
||||
@ -39,16 +41,27 @@ class StockController extends BaseController
|
||||
{
|
||||
$this->db = \Config\Database::connect();
|
||||
parent::__construct();
|
||||
$this->coatingMachineDetails_model = new CoatingMachineDetailsModel();
|
||||
$this->drierMachineDetails_model = new DrierMachineDetailsModel();
|
||||
$this->factoryMachine_model = new FactoryMachineModel();
|
||||
$this->factoryVehicleDieselDetails_model = new FactoryVehicleDieselDetailsModel();
|
||||
$this->coatingMachineDetails_model = new CoatingMachineDetailsModel();
|
||||
|
||||
$this->drierMachineDetails_model = new DrierMachineDetailsModel();
|
||||
|
||||
$this->factoryMachine_model = new FactoryMachineModel();
|
||||
|
||||
$this->factoryVehicleDieselDetails_model = new FactoryVehicleDieselDetailsModel();
|
||||
|
||||
$this->factoryVehicleDieselStockSummary_model = new FactoryVehicleDieselStockSummaryModel();
|
||||
$this->rawmaterialdetails_model = new Rawmaterialdetails_model();
|
||||
$this->incomingSilicaSandDetails_model = new IncomingSilicaSandDetailsModel();
|
||||
$this->inwardGateRegister_model = new Inwardgateregister_model();
|
||||
$this->bagStockDetails_model = new BagStockDetailsModel();
|
||||
$this->dustAndRoughStockDetails_model = new DustAndRoughModel();
|
||||
|
||||
$this->rawmaterialdetails_model = new Rawmaterialdetails_model();
|
||||
|
||||
$this->incomingSilicaSandDetails_model = new IncomingSilicaSandDetailsModel();
|
||||
|
||||
$this->inwardGateRegister_model = new Inwardgateregister_model();
|
||||
|
||||
$this->bagStockDetails_model = new BagStockDetailsModel();
|
||||
|
||||
$this->dustAndRoughStockDetails_model = new DustAndRoughModel();
|
||||
|
||||
$this->resinStockDetails_model = new ResinStockModel() ;
|
||||
|
||||
|
||||
$this->session = session();
|
||||
@ -441,8 +454,6 @@ class StockController extends BaseController
|
||||
->orderBy('date','asc')
|
||||
->findAll();
|
||||
|
||||
|
||||
|
||||
$date = DateTime::createFromFormat('Y-m', $month);
|
||||
|
||||
$formattedDate = $date->format('M-Y');
|
||||
@ -492,6 +503,153 @@ class StockController extends BaseController
|
||||
}
|
||||
|
||||
|
||||
//Resin Stock Details
|
||||
|
||||
public function loadView_resinStockDetails(){
|
||||
|
||||
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']='Resin Stock Details';
|
||||
|
||||
|
||||
$previousMonth = DateTime::createFromFormat('Y-m', $month)->modify('-1 month')->format('Y-m');
|
||||
$previousMonthStartDate = "$previousMonth-01";
|
||||
$previousMonthEndDate = date("Y-m-t", strtotime($previousMonthStartDate));
|
||||
$data['previousMonthResinStockDetails'] = $this->resinStockDetails_model
|
||||
->select(['materialCode', 'date' ,'balanceStock'])
|
||||
->distinct()
|
||||
->where('date =', $previousMonthEndDate)
|
||||
->groupBy(['materialCode','date'])
|
||||
->orderBy('date','desc')
|
||||
->orderBy('materialCode','asc')
|
||||
->findAll();
|
||||
|
||||
|
||||
|
||||
|
||||
$startDate = "$month-01";
|
||||
$endDate = date("Y-m-t", strtotime($startDate));
|
||||
$data['resinStockDetails'] = $this->resinStockDetails_model
|
||||
->where('date >=', $startDate)
|
||||
->where('date <=', $endDate)
|
||||
->groupBy(['materialCode','date'])
|
||||
->orderBy('date','asc')
|
||||
->orderBy('materialCode','asc')
|
||||
->findAll();
|
||||
|
||||
// Initialize an empty array to hold the grouped data
|
||||
$data['groupedResinStockDetails'] = [];
|
||||
|
||||
// Temporary array to store grouped data by date
|
||||
$groupedByDate = [];
|
||||
|
||||
// Group by 'date'
|
||||
foreach ($data['resinStockDetails'] as $detail) {
|
||||
$date = $detail['date'];
|
||||
|
||||
// Initialize the array for this date if it doesn't exist
|
||||
if (!isset($groupedByDate[$date])) {
|
||||
$groupedByDate[$date] = [];
|
||||
}
|
||||
|
||||
// Append the detail to the sub-array for this date
|
||||
$groupedByDate[$date][] = $detail;
|
||||
}
|
||||
|
||||
// Reset the structure to have indexed arrays without the date keys
|
||||
$data['groupedResinStockDetails'] = array_values($groupedByDate);
|
||||
|
||||
|
||||
|
||||
$resinMaterials= $this->rawmaterialdetails_model->getAllResinMaterialCode();
|
||||
|
||||
foreach($resinMaterials as $key => $resinMaterial){
|
||||
$materialCode = $resinMaterial['MaterialCode'];
|
||||
$resinMaterials[$key]['customers'] = $this->bagStockDetails_model
|
||||
->select('customer')
|
||||
->where('date >=', $startDate)
|
||||
->where('date <=', $endDate)
|
||||
->where('materialCode', $materialCode)
|
||||
->first()['customer'] ?? '';
|
||||
}
|
||||
|
||||
$resinMaterialCount = count($resinMaterials);
|
||||
|
||||
$data['resinMaterialCount'] = $resinMaterialCount;
|
||||
$data['resinMaterials'] = $resinMaterials;
|
||||
|
||||
$date = DateTime::createFromFormat('Y-m', $month);
|
||||
|
||||
$formattedDate = $date->format('M-Y');
|
||||
|
||||
$data['month']=$formattedDate;
|
||||
|
||||
return $this->loadViews("resinStockDetails", $this->global, $data, NULL);
|
||||
|
||||
}
|
||||
|
||||
public function updateResinStockDetails(){
|
||||
|
||||
|
||||
$postData = $this->request->getPost();
|
||||
|
||||
$updateResinStockDetailsData = json_decode($postData['updateResinStockDetails'], true);
|
||||
|
||||
foreach($updateResinStockDetailsData as $data){
|
||||
|
||||
$date = $data['date'];
|
||||
$materialCode = $data['materialCode'];
|
||||
|
||||
|
||||
$dbData= [
|
||||
'date' =>$data['date'],
|
||||
'materialCode' =>$data['materialCode'],
|
||||
'customer' =>$data['customer'],
|
||||
'opening' =>$data['opening'],
|
||||
'receipt' =>$data['receipt'],
|
||||
'used' =>$data['used'],
|
||||
'balanceStock' =>$data['balanceStock'],
|
||||
];
|
||||
|
||||
$resultExists = $this->resinStockDetails_model
|
||||
->where('date',$date)
|
||||
->where('materialCode',$materialCode)
|
||||
->first();
|
||||
|
||||
|
||||
if(!empty($resultExists)){
|
||||
|
||||
$updated = $this->resinStockDetails_model
|
||||
->where('date',$date)
|
||||
->where('materialCode',$materialCode)
|
||||
->set($dbData)
|
||||
->update();
|
||||
|
||||
}else{
|
||||
$inserted = $this->resinStockDetails_model->insert($dbData);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
echo "Data Saved Successfully";
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@ -150,6 +150,20 @@ class Rawmaterialdetails_model extends Model
|
||||
|
||||
}
|
||||
|
||||
function getAllResinMaterialCode(){
|
||||
|
||||
$builder = $this->db->table('t_materialmaster')
|
||||
->select('MaterialCode , MaterialName')
|
||||
->where('IsActive', 1)
|
||||
->where('Category', 'plastic_chemicals')
|
||||
->orderBy('MaterialCode', 'asc');
|
||||
$query = $builder->get();
|
||||
$materialResults = $query->getResultArray();
|
||||
|
||||
return $materialResults;
|
||||
|
||||
}
|
||||
|
||||
|
||||
function getMaterialstock($MaterialCode, $currentdate)
|
||||
|
||||
|
||||
48
app/Models/ResinStockModel.php
Normal file
48
app/Models/ResinStockModel.php
Normal file
@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use CodeIgniter\Model;
|
||||
|
||||
class ResinStockModel extends Model
|
||||
{
|
||||
protected $table = 't_resinStockDetails';
|
||||
protected $primaryKey = 'id';
|
||||
protected $useAutoIncrement = true;
|
||||
protected $returnType = 'array';
|
||||
protected $useSoftDeletes = false;
|
||||
protected $protectFields = true;
|
||||
protected $allowedFields = [
|
||||
'date', 'materialCode', 'customer', 'opening', 'receipt', 'used', 'balanceStock'
|
||||
];
|
||||
|
||||
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 = [];
|
||||
}
|
||||
@ -237,7 +237,11 @@
|
||||
foreach($dustAndRoughStockDetails as $dustAndRoughStockDetailsIndex => $dustAndRoughStockDetail){
|
||||
?>
|
||||
<tr>
|
||||
<td class="celda_normal"><?= $dustAndRoughStockDetail['date'] ?></td>
|
||||
<td class="celda_normal">
|
||||
<?php
|
||||
echo date("d-m-Y", strtotime($dustAndRoughStockDetail['date']));
|
||||
?>
|
||||
</td>
|
||||
|
||||
<td class="celda_normal finalRough"
|
||||
data-id="<?= $dustAndRoughStockDetail['date'] ?>"
|
||||
@ -282,7 +286,11 @@
|
||||
foreach($datesInMonth as $datesInMonthIndex => $dateInMonth){
|
||||
?>
|
||||
<tr>
|
||||
<td class="celda_normal"><?= $dateInMonth?></td>
|
||||
<td class="celda_normal">
|
||||
<?php
|
||||
echo date("d-m-Y", strtotime($dateInMonth));
|
||||
?>
|
||||
</td>
|
||||
|
||||
<td class="celda_normal finalRough"
|
||||
data-id="<?= $dateInMonth ?>"
|
||||
|
||||
@ -778,6 +778,9 @@
|
||||
<a href="<?php echo base_url(); ?>bagStockDetails" class="dropdown-item"><i class="ri-file-info-line align-middle mr-1"></i>Bag Stock Details</a>
|
||||
|
||||
<a href="<?php echo base_url(); ?>dustAndRoughStockDetails" class="dropdown-item"><i class="ri-file-info-line align-middle mr-1"></i>Dust And Rough Stock Details</a>
|
||||
|
||||
<a href="<?php echo base_url(); ?>resinStockDetails" class="dropdown-item"><i class="ri-file-info-line align-middle mr-1"></i>Resin Stock Details</a>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
|
||||
640
app/Views/resinStockDetails.php
Normal file
640
app/Views/resinStockDetails.php
Normal file
@ -0,0 +1,640 @@
|
||||
<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;
|
||||
}
|
||||
|
||||
.modal {
|
||||
padding-right: 30% ! important;
|
||||
}
|
||||
</style>
|
||||
<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">Bag Stock 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('bagStockDetails'); ?>" 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>
|
||||
</form>
|
||||
|
||||
|
||||
|
||||
<div class="table-responsive">
|
||||
<table id="bagStockDetailsTableId" 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($bagMaterials as $bagMaterial){ ?>
|
||||
<!-- this will loop till materials present -->
|
||||
<th class="celda_encabezado_general" colspan="4">
|
||||
<?= $bagMaterial['MaterialName']?>
|
||||
<!-- (<?= $bagMaterial['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){ ?>
|
||||
<!-- 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($groupedBagStockDetails))
|
||||
{
|
||||
//dd($groupedBagStockDetails);
|
||||
foreach($groupedBagStockDetails as $groupedBagStockDetailsIndex => $bagStockDetails){
|
||||
?>
|
||||
<tr>
|
||||
<?php foreach($bagStockDetails as $bagStockIndex => $bagStock){ ?>
|
||||
<?php if ($bagStockIndex == 0): ?>
|
||||
<?php
|
||||
$startDate =DateTime::createFromFormat('Y-m-d', $bagStock['date'])->format('d-m-Y');
|
||||
?>
|
||||
<td class="celda_normal">
|
||||
<?= $startDate ?>
|
||||
</td>
|
||||
<?php endif; ?>
|
||||
|
||||
<td style="display:none">
|
||||
<?= $bagStock['date']?>
|
||||
</td>
|
||||
<td style="display:none"
|
||||
data-id="<?=$bagStock['date']?> <?=$bagStock['materialCode']?>"
|
||||
class="materialCode" ><?= $bagStock['materialCode']?>
|
||||
</td>
|
||||
|
||||
<td style="display:none" class="celda_normal customer"
|
||||
data-materialCode="<?=$bagStock['materialCode']?>"
|
||||
data-id="<?=$bagStock['date']?> <?=$bagStock['materialCode']?>">
|
||||
<?= $bagStock['customer']?>
|
||||
</td>
|
||||
|
||||
<td class="celda_normal openingStock"
|
||||
data-id="<?=$bagStock['date']?> <?=$bagStock['materialCode']?>"
|
||||
|
||||
<?php if ($groupedBagStockDetailsIndex == 0): ?>
|
||||
oninput="openingStockChange(this)"
|
||||
contenteditable="true"
|
||||
<?php endif; ?>
|
||||
|
||||
><?= $bagStock['opening']?>
|
||||
</td>
|
||||
|
||||
<td class="celda_normal receiptStock"
|
||||
data-id="<?=$bagStock['date']?> <?=$bagStock['materialCode']?>"
|
||||
oninput="receiptStockChange(this)"
|
||||
contenteditable="true">
|
||||
<?= $bagStock['receipt']?>
|
||||
</td>
|
||||
|
||||
<td class="celda_normal usedStock"
|
||||
data-id="<?=$bagStock['date']?> <?=$bagStock['materialCode']?>"
|
||||
oninput="usedStockChange(this)"
|
||||
contenteditable="true"><?= $bagStock['used']?>
|
||||
</td>
|
||||
|
||||
<td class="celda_normal balanceStock"
|
||||
data-id="<?=$bagStock['date']?> <?=$bagStock['materialCode']?>">
|
||||
<?= $bagStock['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
|
||||
|
||||
$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');
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<?php foreach($datesInMonth as $datesInMonthIndex => $dateInMonth){ ?>
|
||||
<tr>
|
||||
<?php
|
||||
foreach($bagMaterials as $bagMaterialIndex => $bagMaterial){ ?>
|
||||
<!-- this will loop till materials present -->
|
||||
|
||||
<?php if ($bagMaterialIndex == 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?> <?=$bagMaterial['MaterialCode']?>">
|
||||
<?= $bagMaterial['MaterialCode']?>
|
||||
</td>
|
||||
|
||||
<td class="celda_normal customer" style="display:none"
|
||||
data-materialCode="<?=$bagMaterial['MaterialCode']?>"
|
||||
data-id="<?=$dateInMonth?> <?=$bagMaterial['MaterialCode']?>">
|
||||
<?= $bagMaterial['customers']?>
|
||||
</td>
|
||||
|
||||
<td class="celda_normal openingStock"
|
||||
data-id="<?=$dateInMonth?> <?=$bagMaterial['MaterialCode']?>"
|
||||
<?php if($datesInMonthIndex == 0){ ?>
|
||||
|
||||
oninput="openingStockChange(this)"
|
||||
contenteditable="true"
|
||||
|
||||
<?php }?>
|
||||
><?= $previousMonthBagStockDetails[$bagMaterialIndex]['balanceStock']??'0' ?></td>
|
||||
|
||||
<td class="celda_normal receiptStock"
|
||||
data-id="<?=$dateInMonth?> <?=$bagMaterial['MaterialCode']?>"
|
||||
oninput="receiptStockChange(this)"
|
||||
contenteditable="true">0</td>
|
||||
|
||||
<td class="celda_normal usedStock"
|
||||
data-id="<?=$dateInMonth?> <?=$bagMaterial['MaterialCode']?>"
|
||||
oninput="usedStockChange(this)"
|
||||
contenteditable="true">0</td>
|
||||
|
||||
<td class="celda_normal balanceStock"
|
||||
data-id="<?=$dateInMonth?> <?=$bagMaterial['MaterialCode']?>"
|
||||
><?= $previousMonthBagStockDetails[$bagMaterialIndex]['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>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
|
||||
$(document).ready(function () {
|
||||
|
||||
$('#saveId').click(function () {
|
||||
|
||||
//table to json function
|
||||
|
||||
var updateBagStockDetails = tableToJson();
|
||||
|
||||
|
||||
alert('Updation may take a while, And we appreciate your patience..!!');
|
||||
|
||||
$('#loader').show();
|
||||
$.ajax({
|
||||
data: {
|
||||
updateBagStockDetails
|
||||
},
|
||||
type: "POST",
|
||||
url: "<?php echo base_url() ?>updateBagStockDetails",
|
||||
|
||||
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 = $('#bagStockDetailsTableId');
|
||||
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 = $('#bagStockDetailsTableId');
|
||||
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;
|
||||
|
||||
// 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>
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user