stock module - 03-04-2025

This commit is contained in:
vadivelJ96 2025-04-03 17:22:40 +05:30
parent 663e526f29
commit 81d569dc01
6 changed files with 792 additions and 1334 deletions

View File

@ -1525,6 +1525,10 @@ function updateIGRWeight(){
/*
********************************************************* sec_gas_shortage_starts **************************************************************
*/
public function gasCylinderEntered(){
$this->global['pageTitle'] = 'Gas Cylinder Entered';
@ -1533,7 +1537,7 @@ function updateIGRWeight(){
$gasMaterialCodes = array_column($gasMaterialCodes,'MaterialCode');
$igrDetailsListByMcatGas = $this->inwardgateregister_model->getIgrDetailsListByMcatGas($gasMaterialCodes);
$igrDetailsListByMcatGas = $this->inwardgateregister_model->getIgrDetailsListByMcatGas($gasMaterialCodes,"gas_entered");
$data['gasCylinderEnteredList'] = $igrDetailsListByMcatGas;
@ -1544,9 +1548,16 @@ function updateIGRWeight(){
public function gasCylinderPending(){
$this->global['pageTitle'] = 'Gas Shortage List';
$data['gasShortageList'] = $this->gasShortage_model->findAll();
$this->global['pageTitle'] = 'Gas Cylinder Pending';
$gasMaterialCodes = $this->rawMaterialDetails_model->getAllGasMaterialCode();
$gasMaterialCodes = array_column($gasMaterialCodes,'MaterialCode');
$igrDetailsListByMcatGas = $this->inwardgateregister_model->getIgrDetailsListByMcatGas($gasMaterialCodes,"gas_pending");
$data['gasCylinderPendingList'] = $igrDetailsListByMcatGas;
$this->loadViews("gasCylinderPending", $this->global, $data, NULL);
@ -1555,58 +1566,125 @@ function updateIGRWeight(){
public function gasCylinderReturned(){
$this->global['pageTitle'] = 'Gas Shortage List';
$this->global['pageTitle'] = 'Gas Cylinder Returned';
$data['gasShortageList'] = $this->gasShortage_model->findAll();
$gasMaterialCodes = $this->rawMaterialDetails_model->getAllGasMaterialCode();
$gasMaterialCodes = array_column($gasMaterialCodes,'MaterialCode');
$igrDetailsListByMcatGas = $this->inwardgateregister_model->getIgrDetailsListByMcatGas($gasMaterialCodes,"gas_returned");
$data['gasCylinderReturnedList'] = $igrDetailsListByMcatGas;
$this->loadViews("gasCylinderReturned", $this->global, $data, NULL);
}
public function getGasShortageDetail(){
$postData = $this->request->getPost();
$shortage = $this->gasShortage_model->where('id',$postData['id'])->find();
return $this->response->setJSON(['status' => 'success', 'data' => $shortage]);
}
public function updateGasShortage()
{
$postData = $this->request->getPost();
// Validate required data
if (!$postData) {
return $this->response->setJSON(['status' => 'error', 'message' => 'Invalid request. No data received.']);
}
try {
// Validate required fields for adding
if ( !isset($postData['invoiceNo']) ) {
return $this->response->setJSON(['status' => 'error', 'message' => 'Missing required fields: invoice No.']);
}
$postData = $this->request->getJSON(true); // Convert JSON to an associative array
// Handle update (edit)
if (isset($postData["id"])) {
return $this->gasShortage_model->update($postData["id"], $postData)
? $this->response->setJSON(['status' => 'success', 'message' => 'Gas shortage details updated successfully.'])
: $this->response->setJSON(['status' => 'error', 'message' => 'Failed to update gas shortage details.']);
}
// Insert new shortage (add)
return ($insertId = $this->gasShortage_model->insert($postData))
? $this->response->setJSON(['status' => 'success', 'message' => 'Gas shortage details added successfully.', 'data' => ['id' => $insertId]])
: $this->response->setJSON(['status' => 'error', 'message' => 'Failed to save gas shortage details.']);
// Validate if any data is received
if (!$postData) {
return $this->response->setJSON([
'status' => 'error',
'message' => 'Invalid request. No data received.'
]);
}
// Validate required fields
if (empty($postData['invoiceNo']) ) {
return $this->response->setJSON([
'status' => 'error',
'message' => 'Missing invoiceNo data.'
]);
}
$updates = [];
$inserts = [];
if(isset($postData['id'])){ //update operation
$cylinderData = [
'id' => $postData['id'],
'IGRNO' => $postData['IGRNO'] ?? '',
'fullCylinderDate' => $postData['fullCylinderDate'] ?? '',
'emptyCylinderDate' => $postData['emptyCylinderDate'] ?? '',
'invoiceNo' => $postData['invoiceNo'] ?? '',
'cylinderNo' => $postData['cylinderNo'],
'grossWeight' => $postData['grossWeight'],
'tareWeight' => $postData['tareWeight'] ?? '',
'netWeight' => $postData['netWeight'] ?? '',
'actualWeight' => $postData['actualWeight'],
'shortage' => $postData['shortage'] ?? '',
'gas_cylinder_status' => "gas_returned"
];
$updates[] = $cylinderData ;
}else{//Insert Operation
// Process each cylinder entry
foreach ($postData['cylinders'] as $cylinder) {
// Ensure cylinder data is valid
if (!isset($cylinder['cylinderNo'], $cylinder['grossWeight'], $cylinder['actualWeight'])) {
continue; // Skip incomplete data
}
$cylinderData = [
'IGRNO' => $postData['IGRNO'] ?? '',
'fullCylinderDate' => $postData['fullCylinderDate'] ?? '',
'emptyCylinderDate' => $postData['emptyCylinderDate'] ?? '',
'invoiceNo' => $postData['invoiceNo'] ?? '',
'cylinderNo' => $cylinder['cylinderNo'],
'grossWeight' => $cylinder['grossWeight'],
'tareWeight' => $cylinder['tareWeight'] ?? '',
'netWeight' => $cylinder['netWeight'] ?? '',
'actualWeight' => $cylinder['actualWeight'],
'shortage' => $cylinder['shortage'] ?? '',
'gas_cylinder_status' => 'gas_pending'
];
$inserts[] = $cylinderData;
}
}
if (!empty($updates)) {
$this->gasShortage_model->updateBatch($updates, 'id');
}
if (!empty($inserts)) {
$this->gasShortage_model->insertBatch($inserts);
}
return $this->response->setJSON([
'status' => 'success',
'message' => 'Gas shortage details processed successfully.'
]);
} catch (\Throwable $th) {
// Log the error for debugging
log_message('error', 'Gas Shortage Update Error: ' . $th->getMessage());
return $this->response->setJSON([
'status' => 'error',
'message' => 'An unexpected error occurred while processing gas shortage details.',
'error' => $th->getMessage()
]);
}
}
/*
********************************************************* sec_gas_shortage_ends **************************************************************
*/
}

View File

@ -13,8 +13,18 @@ class GasShortageModel extends Model
protected $useSoftDeletes = false;
protected $protectFields = true;
protected $allowedFields =
['fullCylinderDate','emptyCylinderDate','invoiceNo',
'cylinderNo','grossWeight','tareWeight','netWeight','actualWeight','shortage'
['id',
'IGRNO',
'fullCylinderDate',
'emptyCylinderDate',
'invoiceNo',
'cylinderNo',
'grossWeight',
'tareWeight',
'netWeight',
'actualWeight',
'shortage',
'gas_cylinder_status'
];
protected bool $allowEmptyInserts = false;

View File

@ -1380,26 +1380,42 @@ $builder = $this->db->table('t_igr_history')
}
//Mcat -materialCategory
public function getIgrDetailsListByMcatGas($gasMaterialCodes){
public function getIgrDetailsListByMcatGas($gasMaterialCodes,$gas_status){
$result = $this->db->table('t_igr_details as t_igrd')
$builder = $this->db->table('t_igr_details as t_igrd')
->select("
t_igrd.IGRNO,
SUM(t_igrd.QuantityAsPerInvoice) as gasCylinderCount,
t_igrd.IGRNO as IGRNO-,
(t_igrd.QuantityAsPerInvoice) as gasCylinderCount,
t_sd.SupplierName,
t_igrm.*,
'gas entered' AS status
t_mm.MaterialName,
t_gsd.*
")
->join('t_igr_master t_igrm', 't_igrm.IGRNO = t_igrd.IGRNO')
->join('t_purchaseorder_master t_pom', 't_igrm.PONO = t_pom.PONO', 'left')
->join('t_supplierdetailsn t_sd', 't_sd.SupplierID = t_pom.SupplierID')
->join('t_gasshortagedetails t_gsd', 't_gsd.IGRNO = t_igrd.IGRNO', 'left')
->whereIn('MaterialCode', $gasMaterialCodes)
->where("DATE(t_igrd.CreatedDate) BETWEEN '2025-01-01' AND '2025-01-31' ")
->where('t_gsd.IGRNO IS NULL')
->groupBy('t_igrd.IGRNO')
->get()
->getResultArray();
->join('t_materialmaster t_mm','t_mm.MaterialCode = t_igrd.MaterialCode','left')
->whereIn('t_igrd.MaterialCode', $gasMaterialCodes)
->where("DATE(t_igrd.CreatedDate) >= '2025-04-01' ");
switch ($gas_status) {
case "gas_entered":
$builder->where('t_gsd.gas_cylinder_status IS NULL');
break;
case "gas_pending":
$builder->where('t_gsd.gas_cylinder_status','gas_pending');
break;
case "gas_returned":
$builder->where('t_gsd.gas_cylinder_status','gas_returned');
break;
default:
$builder->where('t_gsd.gas_cylinder_status IS NULL');
}
$result = $builder->get()->getResultArray();

View File

@ -203,22 +203,27 @@
<table id="view_inward_gate_register" class="table table-bordered table-hover">
<thead>
<tr>
<!-- basic details -->
<th>Full Cylinder Date</th>
<th>IGR No</th>
<th>Supplier</th>
<th>Bill/Invoice No</th>
<th>Cylinder Name</th>
<!-- cylinderdetails -->
<!-- least details -->
<th>Bill Date</th>
<th>Driver Name</th>
<th>Vehicle No</th>
<th>Cylinder Count</th>
<th>Status</th>
<th>Gas Details</th>
</tr>
</thead>
<tbody>
<?php if(empty($gasCylinderEnteredList)){?>
<p> No Gas Cylinder Entered in the Given Dates..!!</p>
<p align="center"> No Gas Cylinder Entered in the Given Dates..!!</p>
<?php }else{ ?>
<?php foreach($gasCylinderEnteredList as $index => $gasCylinder):
@ -228,22 +233,39 @@
<tr>
<!-- basic details -->
<!-- td:eq(0) -->
<td><?=$gasCylinder['MaterialRcvdDate']?></td>
<td><?=$gasCylinder['IGRNO']?></td>
<!-- td:eq(1) -->
<td><?=$gasCylinder['IGRNO-']?></td>
<!-- td:eq(2) -->
<td><?=$gasCylinder['SupplierName']?></td>
<!-- td:eq(3) -->
<td><?=$gasCylinder['DeliveryChellanOrInvoiceNo']?></td>
<!-- td:eq(4) -->
<td><?=$gasCylinder['MaterialName']?></td>
<!-- cylinderdetails -->
<!-- least details -->
<!-- td:eq(5) -->
<td><?=$gasCylinder['DeliveryChellanDate']?></td>
<!-- td:eq(6) -->
<td><?=$gasCylinder['DriverName']?></td>
<!-- td:eq(7) -->
<td><?=$gasCylinder['VehicleNo']?></td>
<!-- td:eq(8) -->
<td><?=$gasCylinder['gasCylinderCount']?></td>
<td><?=$gasCylinder['status']?></td>
<!-- #gasEnteredDetails modal will open when clicking this button -->
<!-- #gasEnteredDetails modal will open when clicking this button -->
<td>
<a href="#">
<i class="fa fa-edit enter-gas-details" ></i>
<i class="fa fa-edit gas-entered-details" ></i>
</a>
</td>
@ -277,7 +299,7 @@
<div class="modal-dialog modal-xl">
<div class="modal-content" style="border: 1px solid #ddd; margin-top: 73px; box-shadow: 0 0 40px rgb(0 0 0 / 43%);">
<div class="modal-header">
<h4 class="modal-title">Enter Gas Cylinder Details </h4>
<h4 class="modal-title">Gas Cylinder Details </h4>
<button type="button" class="close" data-dismiss="modal"
aria-hidden="true">×</button>
@ -340,6 +362,11 @@
<input type="text" class="form-control" id="vehicleNo" name="vehicleNo" value="" readonly>
</div>
<div class="col-md-4">
<label for="cylinderCount"> Cylinder Name </label>
<input type="text" class="form-control" id="cylinderName" name="cylinderName" value="" readonly>
</div>
<div class="col-md-4">
<label for="cylinderCount"> Cylinder Count </label>
<input type="text" class="form-control" id="cylinderCount" name="cylinderCount" value="" readonly>
@ -485,7 +512,7 @@
$("#resetButton").click(function() {
$("#fromDate").val('');
$("#toDate").val('');
window.location="ViewIGR"
window.location="gasCylinderEntered"
});
// Automatically focus and open the To Date picker when From Date is selected
@ -533,7 +560,7 @@
<!-- while Opening gasEnteredDetails modal -->
<script>
$(document).on('click', '.enter-gas-details', function() {
$(document).on('click', '.gas-entered-details', function() {
let row = $(this).closest("tr");
@ -542,10 +569,13 @@
let igrNo = row.find("td:eq(1)").text().trim();
let supplierName = row.find("td:eq(2)").text().trim();
let invoiceNo = row.find("td:eq(3)").text().trim();
let billDate = row.find("td:eq(4)").text().trim();
let driverName = row.find("td:eq(5)").text().trim();
let vehicleNo = row.find("td:eq(6)").text().trim();
let cylinderCount = parseInt(row.find("td:eq(7)").text().trim(), 10);
let cylinderName = row.find("td:eq(4)").text().trim();
let billDate = row.find("td:eq(5)").text().trim();
let driverName = row.find("td:eq(6)").text().trim();
let vehicleNo = row.find("td:eq(7)").text().trim();
let cylinderCount = parseInt(row.find("td:eq(8)").text().trim(), 10);
// Convert fullCylinderDate to YYYY-MM-DD
if (fullCylinderDate) {
@ -567,6 +597,7 @@
$('#billDate').val(billDate);
$('#driverName').val(driverName);
$('#vehicleNo').val(vehicleNo);
$('#cylinderName').val(cylinderName);
$('#cylinderCount').val(cylinderCount);
// Clear previous cylinder inputs
@ -618,6 +649,7 @@
$('#billDate').val(" ");
$('#driverName').val(" ");
$('#vehicleNo').val(" ");
$('#cylinderName').val(" ");
$('#cylinderCount').val(" ");
$('#cylinderDiv').html("");
});
@ -644,21 +676,22 @@ $(document).ready(function () {
// Collecting form data
let formData = {
fullCylinderDate: $("#fullCylinderDate").val(),
igrNo: $("#IGRNO").val(),
supplierName: $("#supplierName").val(),
invoiceNo: $("#invoiceNo").val(),
billDate: $("#billDate").val(),
driverName: $("#driverName").val(),
vehicleNo: $("#vehicleNo").val(),
cylinderCount: $("#cylinderCount").val(),
IGRNO: $("#IGRNO").val(),
supplierName: $("#supplierName").val(),
invoiceNo: $("#invoiceNo").val(),
billDate: $("#billDate").val(),
driverName: $("#driverName").val(),
vehicleNo: $("#vehicleNo").val(),
cylinderName: $('#cylinderName').val(),
cylinderCount: $("#cylinderCount").val(),
cylinders: [] // Array to store cylinder details
};
// Loop through dynamically generated cylinder inputs
$("#cylinderDiv .form-group.row.dynamicField").each(function () {
let cylinderData = {
cylinderNo: $(this).find("input[name='cylinderNumber[]']").val(),
grossWeight: $(this).find("input[name='grossWeight[]']").val(),
cylinderNo : $(this).find("input[name='cylinderNumber[]']").val(),
grossWeight : $(this).find("input[name='grossWeight[]']").val(),
actualWeight: $(this).find("input[name='actualWeight[]']").val(),
};
formData.cylinders.push(cylinderData);
@ -666,8 +699,6 @@ $(document).ready(function () {
console.log(formData); // Debugging - Check if data is correct
return;
$('#loader').show(); // Show loader
$.ajax({

File diff suppressed because it is too large Load Diff

View File

@ -203,31 +203,83 @@
<table id="view_inward_gate_register" class="table table-bordered table-hover">
<thead>
<tr>
<th>Full Cylinder Date</th>
<!-- basic details -->
<th>Full Cylinder Date</th>
<th>IGR No</th>
<th>Supplier</th>
<th>Bill/Invoice No</th>
<th>Cylinder Name</th>
<!-- cylinderdetails -->
<th>Cylinder No</th>
<th>Gross Weight</th>
<th>Empty Cylinder Date</th>
<th>Tare Weight</th>
<th>Net Weight</th>
<th>Tare Weight</th>
<th>Net Weight</th>
<th>Actual Weight</th>
<th>shortage</th>
<th>Bill/Invoice No</th>
<th>Shortage</th>
<!-- least details -->
<th>Bill Date</th>
<th>Driver Name</th>
<th>Vehicle No</th>
<th>Status</th>
<th>Action</th>
<th>Gas Details</th>
</tr>
</thead>
<tbody>
<?php if(empty($gasCylinderReturnedList)){?>
<p align="center" > No Gas Cylinder Entered in the Given Dates..!!</p>
<?php }else{ ?>
<?php foreach($gasCylinderReturnedList as $index => $gasCylinder):
$gasCylinder['MaterialRcvdDate'] = date('d-m-Y',strtotime($gasCylinder['MaterialRcvdDate']));
$gasCylinder['DeliveryChellanDate'] = date('d-m-Y',strtotime($gasCylinder['DeliveryChellanDate']));
$gasCylinder['emptyCylinderDate'] = date('d-m-Y',strtotime($gasCylinder['emptyCylinderDate']));
?>
<tr>
<!-- basic details -->
<td><?=$gasCylinder['MaterialRcvdDate']?></td>
<td><?=$gasCylinder['IGRNO-']?></td>
<td><?=$gasCylinder['SupplierName']?></td>
<td><?=$gasCylinder['DeliveryChellanOrInvoiceNo']?></td>
<td><?=$gasCylinder['MaterialName']?></td>
<!-- cylinderdetails -->
<td><?=$gasCylinder['cylinderNo']?></td>
<td><?=$gasCylinder['grossWeight']?></td>
<td><?=$gasCylinder['emptyCylinderDate']?></td>
<td><?=$gasCylinder['tareWeight']?></td>
<td><?=$gasCylinder['netWeight']?></td>
<td><?=$gasCylinder['actualWeight']?></td>
<td><?=$gasCylinder['shortage']?></td>
<!-- least details -->
<td><?=$gasCylinder['DeliveryChellanDate']?></td>
<td><?=$gasCylinder['DriverName']?></td>
<td><?=$gasCylinder['VehicleNo']?></td>
<!-- #gasEnteredDetails modal will open when clicking this button -->
<td>
<a href="#">
<i class="fa fa-edit gas-entered-details" ></i>
</a>
</td>
</tr>
<?php endforeach ?>
<?php } ?>
</tbody>
</table>
@ -246,68 +298,14 @@
<!-- gas shortage list gasShortageList-->
<!-- Modal -->
<div id="gasShortageList" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="gasShortageListLabel" aria-hidden="true">
<div class="modal-dialog modal-xl " role="document">
<div class="modal-content" style="border: 1px solid #ddd; margin-top: 73px; box-shadow: 0 0 40px rgb(0 0 0 / 43%);">
<div class="modal-header">
<h5 class="modal-title" id="gasShortageListLabel" align="center">List of Gas Shortages</h5>
<button type="button" class="btn btn-primary btn-sm" id="exportGasShortage" style="margin-left: 10px;">
Export &nbsp;
<i class="fa fa-download" style="color:white;"></i>
</button>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body" >
<table id="gasShortageTable" class="table table-bordered table-hover">
<thead>
<tr>
<th>Full Cylinder Date</th>
<th>Empty Cylinder Date</th>
<th>Invoice No</th>
<th>Cylinder No</th>
<th>Gross Weight</th>
<th>Tare Weight</th>
<th>Net Weight</th>
<th>Actual Weight</th>
<th>Shortage</th>
<th style="display:none">ID</th>
<th>Action</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<!-- end of gas shortage list -->
<!-- gas Shortage Calculator modal addGasShortageCalculator -->
<div id="gasShortageCalculator" data-form="add" class="modal fade" tabindex="-1" role="dialog"
<!-- gas Entered modal -->
<div id="gasEnteredDetails" data-form="add" class="modal fade" tabindex="-1" role="dialog"
aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">
<div class="modal-dialog modal-large">
<div class="modal-dialog modal-xl">
<div class="modal-content" style="border: 1px solid #ddd; margin-top: 73px; box-shadow: 0 0 40px rgb(0 0 0 / 43%);">
<div class="modal-header">
<h4 class="modal-title">Add Gas Shortage </h4>
<h4 class="modal-title">Gas Cylinder Details </h4>
<button type="button" class="close" data-dismiss="modal"
aria-hidden="true">×</button>
</div>
@ -317,78 +315,81 @@
<form action="#">
<!-- first row full cylinder date and empty cylinder date -->
<!-- first row -->
<div class="form-group row">
<div class="col-md-6">
<label for="fullCylinderDateId"> Full Cylinder Date</label>
<input type="date" class="form-control" id="fullCylinderDateId" name="fullCylinderDate" value="" required>
<div class="col-md-4">
<label for="fullCylinderDate"> Full Cylinder Date</label>
<input type="date" class="form-control" id="fullCylinderDate" name="fullCylinderDate" value="" readonly>
</div>
<div class="col-md-6">
<label for="emptyCylinderDateId"> Empty Cylinder Date</label>
<input type="date" class="form-control" id="emptyCylinderDateId" name="emptyCylinderDate" value="" required>
<div class="col-md-4">
<label for="IGRNO"> IGRNO</label>
<input type="text" class="form-control" id="IGRNO" name="IGRNO" value="" readonly>
</div>
<div class="col-md-4">
<label for="supplierName"> Supplier Name</label>
<input type="text" class="form-control" id="supplierName" name="supplierName" value="" readonly>
</div>
</div>
<!-- second row cylinder no and Invoice No-->
<!-- second row -->
<div class="form-group row">
<div class="col-md-6">
<label for="invoiceNoId"> Invoice No / Bill No</label>
<input type="text" class="form-control" id="invoiceNoId" name="invoiceNo" value="" readonly>
<div class="col-md-4">
<label for="invoiceNo"> Bill No/Invoice No </label>
<input type="text" class="form-control" id="invoiceNo" name="invoiceNo" value="" readonly>
</div>
<div class="col-md-6">
<label for="cylinderNoId"> Cylinder No </label>
<input type="text" class="form-control" id="cylinderNoId" name="cylinderNo" value="" required>
<div class="col-md-4">
<label for="billDate"> Bill Date</label>
<input type="date" class="form-control" id="billDate" name="billDate" value="" readonly>
</div>
<div class="col-md-4">
<label for="driverName"> Driver Name</label>
<input type="text" class="form-control" id="driverName" name="driverName" value="" readonly>
</div>
</div>
<!-- third row gross weight and tare weight -->
<div class="form-group row">
<div class="col-md-6">
<label for="grossWeightId"> Gross Weight </label>
<input type="text" class="form-control" id="grossWeightId" name="grossWeight" value="" required>
</div>
<div class="col-md-6">
<label for="tareWeightId"> Tare Weight </label>
<input type="text" class="form-control" id="tareWeightId" name="tareWeight" value="" required>
</div>
</div>
<!-- fourth row NetWeight and actual weight -->
<div class="form-group row">
<div class="col-md-6">
<label for="actualWeightId"> Actual Weight </label>
<input type="text" class="form-control" id="actualWeightId" name="actualWeight" value="" required>
</div>
<div class="col-md-6">
<label for="netWeightId"> Net Weight (Gross-Tare)</label>
<input type="text" class="form-control" id="netWeightId" name="netWeight" value="" readonly>
</div>
</div>
<!-- fifth row Gas Shortage -->
<div class="form-group row">
<div class="col-md-6">
<label for="shortageId"> Gas Shortage(Actual-Net)</label>
<input type="text" class="form-control" id="shortageId" name="shortage" value="" readonly>
</div>
</div>
<!-- third row -->
<div class="form-group row">
<div class="col-md-4">
<label for="vehicleNo"> Vehicle No</label>
<input type="text" class="form-control" id="vehicleNo" name="vehicleNo" value="" readonly>
</div>
<div class="col-md-4">
<label for="cylinderCount"> Cylinder Name </label>
<input type="text" class="form-control" id="cylinderName" name="cylinderName" value="" readonly>
</div>
<div class="col-md-4">
<label for="cylinderCount"> Cylinder Count </label>
<input type="text" class="form-control" id="cylinderCount" name="cylinderCount" value="" readonly>
</div>
</div>
<hr>
<!-- fourth row -->
<div id="cylinderDiv">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary waves-effect"
data-dismiss="modal" value="Cancel">Cancel</button>
@ -404,102 +405,6 @@
<!-- end gas shortage calculator modal -->
<!-- Edit gas Shortage Calculator modal editgasShortageCalculator -->
<div id="editGasShortageCalculator" data-form="edit" class="modal fade" tabindex="-1" role="dialog"
aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">
<div class="modal-dialog modal-large">
<div class="modal-content" style="border: 1px solid #ddd; margin-top: 73px; box-shadow: 0 0 40px rgb(0 0 0 / 43%);">
<div class="modal-header">
<h4 class="modal-title">Update Gas Shortage </h4>
<button type="button" class="close" data-dismiss="modal"
aria-hidden="true">×</button>
</div>
<form action="#">
<div class="modal-body p-4">
<!-- first row full cylinder date and empty cylinder date -->
<div class="form-group row">
<div class="col-md-6">
<label for="editFullCylinderDateId"> Full Cylinder Date</label>
<input type="date" class="form-control" id="editFullCylinderDateId" name="fullCylinderDate" value="" required>
</div>
<div class="col-md-6">
<label for="editEmptyCylinderDateId"> Empty Cylinder Date</label>
<input type="date" class="form-control" id="editEmptyCylinderDateId" name="emptyCylinderDate" value="" required>
</div>
</div>
<!-- second row cylinder no and Invoice No-->
<div class="form-group row">
<div class="col-md-6">
<label for="editInvoiceNoId"> Invoice No / Bill No</label>
<input type="text" class="form-control" id="editInvoiceNoId" name="invoiceNo" value="" readonly>
</div>
<div class="col-md-6">
<label for="editCylinderNoId"> Cylinder No </label>
<input type="text" class="form-control" id="editCylinderNoId" name="cylinderNo" value="" required>
</div>
</div>
<!-- third row gross weight and tare weight -->
<div class="form-group row">
<div class="col-md-6">
<label for="editGrossWeightId"> Gross Weight </label>
<input type="text" class="form-control" id="editGrossWeightId" name="grossWeight" value="" required>
</div>
<div class="col-md-6">
<label for="editTareWeightId"> Tare Weight </label>
<input type="text" class="form-control" id="editTareWeightId" name="tareWeight" value="" required>
</div>
</div>
<!-- fourth row NetWeight and actual weight -->
<div class="form-group row">
<div class="col-md-6">
<label for="editActualWeightId"> Actual Weight </label>
<input type="text" class="form-control" id="editActualWeightId" name="actualWeight" value="" required>
</div>
<div class="col-md-6">
<label for="editNetWeightId"> Net Weight (Gross-Tare)</label>
<input type="text" class="form-control" id="editNetWeightId" name="netWeight" value="" readonly>
</div>
</div>
<!-- fifth row Gas Shortage -->
<div class="form-group row">
<div class="col-md-6">
<label for="editShortageId"> Gas Shortage(Actual-Net)</label>
<input type="text" class="form-control" id="editShortageId" name="shortage" value="" readonly>
</div>
</div>
<!-- hidden fields -->
<input type="hidden" id="editId" name="id" value="" >
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary waves-effect"
data-dismiss="modal" value="Cancel">Cancel</button>
<button type="submit"
class="btn btn-info waves-effect waves-light" >Save</button>
</div>
</form>
</div>
</div>
</div>
<!-- end gas shortage calculator modal -->
@ -612,7 +517,7 @@
$("#resetButton").click(function() {
$("#fromDate").val('');
$("#toDate").val('');
window.location="ViewIGR"
window.location="gasCylinderReturned"
});
// Automatically focus and open the To Date picker when From Date is selected
@ -657,95 +562,99 @@
<!-- while Opening gasEnteredDetails modal -->
<script>
$(document).on('click', '.gas-entered-details', function() {
<!-- 02-04-2025 new gas shortage calculator -->
<!-- add gas shortage calculator -->
<script>
$('#grossWeightId, #tareWeightId,#actualWeightId').change(function() {
console.log("fine here ");
let grossWeightVal = $('#grossWeightId').val().trim();
let tareWeightVal = $('#tareWeightId').val().trim();
// Ensure both fields have values before calculation
if (grossWeightVal === '' || tareWeightVal === '') {
return;
}
let grossWeight = validateNumber(grossWeightVal);
let tareWeight = validateNumber(tareWeightVal);
let netWeight = grossWeight - tareWeight;
$('#netWeightId').val(netWeight);
let actualWeightVal = $('#actualWeightId').val().trim();
// Ensure both fields have values before calculation
if (actualWeightVal === '' || netWeight === '') {
return;
}
let actualWeight = validateNumber(actualWeightVal);
let shortage = actualWeight - netWeight;
$('#shortageId').val(shortage);
});
function validateNumber(givenValue) {
givenValue = givenValue.trim();
if (/^\d+$/.test(givenValue)) {
return parseInt(givenValue, 10); // Convert string to number
} else {
alert('Please Enter a Valid Number..!!');
return 0; // Invalid number
}
}
</script>
<!-- while opening add gas shortage modal -->
<script>
$(document).ready(function(){
$('#gasShortageCalculator').on("shown.bs.modal", function(e){
//invoice needed to store it in the shortage table ,
// coz based on this we can limit the addition of shortage must not exceed than given qty
let invoiceNo = $('#Invoice_No').val();
let row = $(this).closest("tr");
let materialReceivedDate = $('#MaterialRcvdDate').val().split("-");
let fullCylinderDate = row.find("td:eq(0)").text().trim();
let igrNo = row.find("td:eq(1)").text().trim();
let supplierName = row.find("td:eq(2)").text().trim();
let invoiceNo = row.find("td:eq(3)").text().trim();
let billDate = row.find("td:eq(4)").text().trim();
let driverName = row.find("td:eq(5)").text().trim();
let vehicleNo = row.find("td:eq(6)").text().trim();
let cylinderName = row.find("td:eq(7)").text().trim();
let cylinderCount = parseInt(row.find("td:eq(8)").text().trim(), 10);
//converting it to y-m-d format;
console.log(`${materialReceivedDate[2]}-${materialReceivedDate[1]}-${materialReceivedDate[0]}`);
// Convert fullCylinderDate to YYYY-MM-DD
if (fullCylinderDate) {
let dateParts = fullCylinderDate.split("-");
fullCylinderDate = `${dateParts[2]}-${dateParts[1]}-${dateParts[0]}`;
}
$('#invoiceNoId').val(invoiceNo);
$('#fullCylinderDateId').val(`${materialReceivedDate[2]}-${materialReceivedDate[1]}-${materialReceivedDate[0]}`);
});
});
</script>
// Convert billDate to YYYY-MM-DD
if (billDate) {
let dateParts = billDate.split("-");
billDate = `${dateParts[2]}-${dateParts[1]}-${dateParts[0]}`;
}
<!-- while closing add gas shortage modal -->
// Assign values to modal inputs
$('#fullCylinderDate').val(fullCylinderDate);
$('#IGRNO').val(igrNo);
$('#supplierName').val(supplierName);
$('#invoiceNo').val(invoiceNo);
$('#billDate').val(billDate);
$('#driverName').val(driverName);
$('#vehicleNo').val(vehicleNo);
$('#cylinderName').val(cylinderName);
$('#cylinderCount').val(cylinderCount);
// Clear previous cylinder inputs
$('#cylinderDiv').html("");
// Generate cylinder input fields dynamically
if (cylinderCount > 0) {
let inputFields = `
<div class="form-group row">
<div class="col-md-4"><label>Cylinder Number</label> <span class="text-danger">*</span> </div>
<div class="col-md-4"><label>Gross Weight</label> <span class="text-danger">*</span> </div>
<div class="col-md-4"><label>Actual Weight</label> <span class="text-danger">*</span> </div>
</div>`;
for (let i = 1; i <= cylinderCount; i++) {
inputFields += `
<div class="form-group row dynamicField">
<div class="col-md-4">
<input type="text" class="form-control" name="cylinderNumber[]" placeholder="Cylinder ${i}" required>
</div>
<div class="col-md-4">
<input type="number" class="form-control" name="grossWeight[]" placeholder="Gross Weight ${i}" required>
</div>
<div class="col-md-4">
<input type="number" class="form-control" name="actualWeight[]" placeholder="Actual Weight ${i}" required>
</div>
</div>`;
}
$('#cylinderDiv').html(inputFields);
}
// Show the modal
$('#gasEnteredDetails').modal('show');
});
</script>
<!-- while closing gasEnteredDetails modal -->
<script>
$(document).ready(function(){
$('#gasShortageCalculator').on("hide.bs.modal", function(e){
$('#invoiceNoId').val(' ');
$('#fullCylinderDateId').val(" ");
$('#emptyCylinderDateId').val(" ");
$('#cylinderNoId').val(" ");
$('#grossWeightId').val(" ");
$('#tareWeightId').val(" ");
$('#actualWeightId').val(" ");
$('#netWeightId').val(" ");
$('#shortageId').val(" ");
$('#gasEnteredDetails').on("hide.bs.modal", function(e){
$('#fullCylinderDate').val(" ");
$('#IGRNO').val(" ");
$('#supplierName').val(" ");
$('#invoiceNo').val(" ");
$('#billDate').val(" ");
$('#driverName').val(" ");
$('#vehicleNo').val(" ");
$('#cylinderName').val(" ");
$('#cylinderCount').val(" ");
$('#cylinderDiv').html("");
});
});
</script>
@ -753,357 +662,75 @@
<!-- end of add gas shortage calculator -->
<!-- edit gasShortageCalculator -->
<script>
$('#editGrossWeightId,#editTareWeightId,#editActualWeightId').change(function() {
let grossWeightVal = $('#editGrossWeightId').val().trim();
let tareWeightVal = $('#editTareWeightId').val().trim();
// Ensure both fields have values before calculation
if (grossWeightVal === '' || tareWeightVal === '') {
return;
}
let grossWeight = validateNumber(grossWeightVal);
let tareWeight = validateNumber(tareWeightVal);
let netWeight = grossWeight - tareWeight;
$('#editNetWeightId').val(netWeight);
let actualWeightVal = $('#editActualWeightId').val().trim();
// Ensure both fields have values before calculation
if (actualWeightVal === '' || netWeight === '') {
return;
}
let actualWeight = validateNumber(actualWeightVal);
let shortage = actualWeight - netWeight;
$('#editShortageId').val(shortage);
});
</script>
<!-- while opening edit gas shortage modal -->
<script>
$(document).ready(function(){
$('#editGasShortageCalculator').on("shown.bs.modal", function(e){
//invoice needed to store it in the shortage table ,
// coz based on this we can limit the addition of shortage must not exceed than given qty
let invoiceNo = $('#Invoice_No').val();
let materialReceivedDate = $('#MaterialRcvdDate').val().split("-");
//converting it to y-m-d format;
console.log(`${materialReceivedDate[2]}-${materialReceivedDate[1]}-${materialReceivedDate[0]}`);
$('#editInvoiceNoId').val(invoiceNo);
$('#editFullCylinderDateId').val(`${materialReceivedDate[2]}-${materialReceivedDate[1]}-${materialReceivedDate[0]}`);
});
});
</script>
<!-- while closing edit gas shortage modal -->
<script>
$(document).ready(function(){
$('#editGasShortageCalculator').on("hide.bs.modal", function(e){
$('#editInvoiceNoId').val(' ');
$('#editFullCylinderDateId').val(" ");
$('#editEmptyCylinderDateId').val(" ");
$('#editCylinderNoId').val(" ");
$('#editGrossWeightId').val(" ");
$('#editTareWeightId').val(" ");
$('#editActualWeightId').val(" ");
$('#editNetWeightId').val(" ");
$('#editShortageId').val(" ");
});
});
</script>
<!-- end of edit gasShortageCalculator -->
<!-- while opening gasShortageList -->
<script>
$(document).ready(function(){
$('#gasShortageList').on("shown.bs.modal",function(e){
let invoiceNo = $('#Invoice_No').val();
console.log("invoice no", invoiceNo);
$('#loader').show();
$.ajax({
type: "POST",
url: "<?php echo base_url()?>/gasShortageList", // 🔹 Change this to your actual backend endpoint
data: {invoiceNo},
dataType: "json",
success: function (response) {
if (response.status === "success") {
let data = response.data ;
let tableData = '';
data.forEach((val) => {
let fullCylinderDate = val.fullCylinderDate.split("-").reverse().join("-");
let emptyCylinderDate = val.emptyCylinderDate.split("-").reverse().join('-');
tableData += `
<tr>
<td>${fullCylinderDate}</td>
<td>${emptyCylinderDate}</td>
<td>${val.invoiceNo}</td>
<td>${val.cylinderNo}</td>
<td>${val.grossWeight}</td>
<td>${val.tareWeight}</td>
<td>${val.netWeight}</td>
<td>${val.actualWeight}</td>
<td>${val.shortage}</td>
<td style="display:none">${val.id}</td>
<td style="width: 25px; cursor: pointer;">
<i class="fa fa-solid fa-edit btnEditGasShortageCalculator"
style="text-align: center;"
data-toggle="modal"
data-target="#editGasShortageCalculator"
data-id="${val.id}"
title="Edit Gas Shortage List">
</i>
</td>
</tr>`;
});
// Assuming you have a table with ID "gasShortageTable"
$("#gasShortageTable tbody").html(tableData);
} else {
alert("Error: " + response.message);
}
},
error: function (xhr, status, error) {
console.log(xhr.responseText);
alert("Something went wrong! Please try again.");
},
complete:function(){
console.log("ajax call is completed..!!");
$('#loader').hide();
}
});
})
})
</script>
<!-- while closing gasShortageList -->
<script>
$(document).ready(function(){
$('#gasShortageList').on("hide.bs.modal",function(){
$("#gasShortageTable tbody").html(" ");
})
})
</script>
<!-- ajax call for gas Shortage -->
<script>
$("#gasShortageCalculator, #editGasShortageCalculator").submit(function (event) {
event.preventDefault(); // Prevent form reload
$(document).ready(function () {
$("#gasEnteredDetails form").submit(function (event) {
event.preventDefault(); // Prevent form reload
let formData;
let method = $("#gasEnteredDetails").data("form"); // Get form type
let method = $(this).closest(".modal").data("form");
// Collecting form data
let formData = {
fullCylinderDate: $("#fullCylinderDate").val(),
IGRNO: $("#IGRNO").val(),
supplierName: $("#supplierName").val(),
invoiceNo: $("#invoiceNo").val(),
billDate: $("#billDate").val(),
driverName: $("#driverName").val(),
vehicleNo: $("#vehicleNo").val(),
cylinderName: $('#cylinderName').val(),
cylinderCount: $("#cylinderCount").val(),
cylinders: [] // Array to store cylinder details
};
// Prepare form data
let addFormData = {
fullCylinderDate: $('#fullCylinderDateId').val(),
emptyCylinderDate: $('#emptyCylinderDateId').val(),
invoiceNo: $('#invoiceNoId').val(),
cylinderNo: $('#cylinderNoId').val(),
grossWeight: $('#grossWeightId').val(),
tareWeight: $('#tareWeightId').val(),
actualWeight: $('#actualWeightId').val(),
netWeight: $('#netWeightId').val(),
shortage: $('#shortageId').val()
// Loop through dynamically generated cylinder inputs
$("#cylinderDiv .form-group.row.dynamicField").each(function () {
let cylinderData = {
cylinderNo : $(this).find("input[name='cylinderNumber[]']").val(),
grossWeight : $(this).find("input[name='grossWeight[]']").val(),
actualWeight: $(this).find("input[name='actualWeight[]']").val(),
};
let editFormData = {
fullCylinderDate: $('#editFullCylinderDateId').val(),
emptyCylinderDate: $('#editEmptyCylinderDateId').val(),
invoiceNo: $('#editInvoiceNoId').val(),
cylinderNo: $('#editCylinderNoId').val(),
grossWeight: $('#editGrossWeightId').val(),
tareWeight: $('#editTareWeightId').val(),
actualWeight: $('#editActualWeightId').val(),
netWeight: $('#editNetWeightId').val(),
shortage: $('#editShortageId').val(),
id : $('#editId').val()
};
if(method == "add"){ formData = addFormData ;}
if(method == "edit"){ formData = editFormData ;}
$('#loader').show();
$.ajax({
type: "POST",
url: "<?php echo base_url()?>/updateGasShortage", // 🔹 Change this to your actual backend endpoint
data: formData,
dataType: "json",
success: function (response) {
if (response.status === "success") {
alert("Gas Shortage Data Saved Successfully!");
$('#gasShortageCalculator').modal('hide'); // Close modal
$('#editGasShortageCalculator').modal('hide');
} else {
alert("Error: " + response.message);
}
},
error: function (xhr, status, error) {
console.log(xhr.responseText);
alert("Something went wrong! Please try again.");
},
complete:function(){
console.log("ajax call is completed..!!");
$('#loader').hide();
}
});
formData.cylinders.push(cylinderData);
});
</script>
console.log(formData); // Debugging - Check if data is correct
<!-- when edit modal of #editGasShortageCalculator clicked..!!-->
<script>
$(document).on("click", ".btnEditGasShortageCalculator", function () {
console.log("Edit modal opening place");
let id = $(this).data("id");
console.log("Editing ID:", id);
// Smooth transition: First hide, then show after 300ms
$("#gasShortageList").modal("hide");
setTimeout(() => {
$("#editGasShortageCalculator").modal("show");
}, 300);
$('#loader').show();
// AJAX request to fetch data
$.ajax({
type: "POST",
url: "<?php echo base_url()?>/getGasShortageDetail",
data: { id: id },
dataType: "json",
success: function (response) {
if (response.status === "success") {
let data = response.data;
console.log(data);
if(data.length > 0){
data = data[0];
console.log(data);
// Populate the modal fields
$("#editFullCylinderDateId").val(data.fullCylinderDate);
$("#editEmptyCylinderDateId").val(data.emptyCylinderDate);
$("#editInvoiceNoId").val(data.invoiceNo);
$("#editCylinderNoId").val(data.cylinderNo);
$("#editGrossWeightId").val(data.grossWeight);
$("#editTareWeightId").val(data.tareWeight);
$("#editNetWeightId").val(data.netWeight);
$("#editActualWeightId").val(data.actualWeight);
$("#editShortageId").val(data.shortage);
$("#editId").val(data.id); // Hidden field for ID
}
} else {
alert("Error: " + response.message);
}
},
error: function (xhr, status, error) {
console.log(xhr.responseText);
alert("Something went wrong! Please try again.");
},
complete:function(){
console.log("ajax call is completed..!!");
$('#loader').hide();
}
});
});
$('#loader').show(); // Show loader
$.ajax({
type: "POST",
url: "<?php echo base_url()?>/updateGasShortage", // Adjust endpoint as needed
data: JSON.stringify(formData), // Send data as JSON
contentType: "application/json",
dataType: "json",
success: function (response) {
if (response.status === "success") {
alert("Gas Shortage Data Saved Successfully!");
$('#gasEnteredDetails').modal('hide'); // Close modal
} else {
alert("Error: " + response.message);
}
},
error: function (xhr, status, error) {
console.log(xhr.responseText);
alert("Something went wrong! Please try again.");
},
complete: function () {
console.log("AJAX request completed.");
$('#loader').hide();
}
});
});
});
</script>
<!-- this script is to export the shortage list in excel format -->
<script>
$(document).ready(function(){
function exportTableToExcel(tableID, filename = '') {
let table = document.getElementById(tableID);
let cloneTable = table.cloneNode(true); // Clone the table to modify
// Remove hidden rows
$(cloneTable).find('tr').filter(function () {
return $(this).css('display') === 'none';
}).remove();
// Remove hidden columns
$(cloneTable).find('th, td').each(function () {
if ($(this).css('display') === 'none') {
$(this).remove();
}
});
let ws = XLSX.utils.table_to_sheet(cloneTable); // Convert modified table to sheet
let wb = XLSX.utils.book_new(); // Create a new workbook
XLSX.utils.book_append_sheet(wb, ws, 'Sheet1'); // Append sheet to workbook
XLSX.writeFile(wb, filename || 'export.xlsx'); // Save the file
}
let tableId = 'gasShortageTable';
document.getElementById('exportGasShortage').addEventListener('click',function(){
exportTableToExcel(tableId, 'gas_shortage.xlsx');
})
})
</script>