diff --git a/app/Config/Routes.php b/app/Config/Routes.php index f3ea3138..a7740738 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -330,6 +330,7 @@ $routes->post('updateGasShortage','Inwardgateregister::updateGasShortage'); $routes->get('gasCylinderEntered','Inwardgateregister::gasCylinderEntered'); $routes->get('gasCylinderPending','Inwardgateregister::gasCylinderPending'); $routes->get('gasCylinderReturned','Inwardgateregister::gasCylinderReturned'); +$routes->post('gasCylindersByIgr','Inwardgateregister::gasCylindersByIgr'); $routes->post('getGasShortageDetail',"Inwardgateregister::getGasShortageDetail"); diff --git a/app/Controllers/Inwardgateregister.php b/app/Controllers/Inwardgateregister.php index 7d50bf69..696df7f7 100755 --- a/app/Controllers/Inwardgateregister.php +++ b/app/Controllers/Inwardgateregister.php @@ -1696,6 +1696,26 @@ function updateIGRWeight(){ ]); } } + + public function gasCylindersByIgr(){ + + $IGRNO = $this->request->getPost('IGRNO'); + + $gasMaterialCodes = $this->rawMaterialDetails_model->getAllGasMaterialCode(); + + $gasMaterialCodes = array_column($gasMaterialCodes,'MaterialCode'); + + $cylinderDetails = $this->inwardgateregister_model->gasCylindersByIgr($IGRNO , $gasMaterialCodes); + + $response = [ + 'status' => 'success', + 'message' => 'Gas cylinders retrieved successfully.', + 'data' => $cylinderDetails + ]; + + return $this->response->setJSON($response); + + } /* ********************************************************* sec_gas_shortage_ends ************************************************************** diff --git a/app/Models/Inwardgateregister_model.php b/app/Models/Inwardgateregister_model.php index c162bb3a..a7983aa8 100755 --- a/app/Models/Inwardgateregister_model.php +++ b/app/Models/Inwardgateregister_model.php @@ -1515,4 +1515,41 @@ class Inwardgateregister_model extends Model return $result; } + + public function gasCylindersByIgr($IGRNO, $gasMaterialCodes) { + + $builder = $this->db->table('t_igr_master as t_igrm') + ->select(" + t_igrm.IGRNO, + tgsd.fullCylinderDate, + tgsd.cylinderNo, + tgsd.grossWeight, + tgsd.emptyCylinderDate, + tgsd.tareWeight, + tgsd.netWeight, + tgsd.actualWeight, + tgsd.shortage, + tgsd.invoiceNo, + t_igrm.DeliveryChellanDate, + t_igrm.DriverName, + t_igrm.VehicleNo + + ") + + ->join('t_igr_details tigrd', 'tigrd.IGRNO = t_igrm.IGRNO') + ->join('t_purchaseorder_master tpom', 'tpom.PONO = t_igrm.PONO', 'left') + ->join('t_supplierdetailsn tsd', 'tsd.SupplierID = tpom.SupplierID') + ->join('t_gasshortagedetails tgsd', 'tgsd.IGRNO = t_igrm.IGRNO', 'left') + + ->whereIn('tigrd.MaterialCode', $gasMaterialCodes) + ->where("DATE(tigrd.CreatedDate) >= '2025-04-01'") + ->where('tgsd.gas_cylinder_status', 'gas_returned') + ->where('t_igrm.IGRNO', $IGRNO); // Direct where clause on IGRNO in master table + + $result = $builder->get()->getResultArray(); + + return $result; + } + + } diff --git a/app/Views/gasCylinderReturned.php b/app/Views/gasCylinderReturned.php index 9ea0eb9d..d5c542c6 100644 --- a/app/Views/gasCylinderReturned.php +++ b/app/Views/gasCylinderReturned.php @@ -3,17 +3,15 @@ @@ -148,14 +148,14 @@
-
- -
+
+ +
@@ -171,30 +171,30 @@
-
- - - + - - + + - - - - - -
-
-
+ + + + + + + + +
+ +
@@ -203,76 +203,92 @@ - - + + - + - + - - + + + - + + - -

No Gas Cylinder Returned in the Given Dates..!!

- + +

No Gas Cylinder Returned in the Given Dates..!!

+ - $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'])); - ?> + $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'])); + ?> - - - - - - - - - - - - - - - - - + - + + + + + + - - - - + + + + + + + + + - - - - - + + + + + + + + + + + + +
Full Cylinder DateFull Cylinder Date IGR NoSupplierSupplier Bill/Invoice No Cylinder Name Gross Weight Empty Cylinder DateTare WeightNet WeightTare WeightNet Weight Actual Weight ShortageCylinder Count Cylinder Pending Bill Date Driver Name Vehicle NoDownload
+ +
+
+ +
+
@@ -304,31 +320,41 @@ console.log("Received date string:", dateString); // Split the date string into date and time components - var dateTimeParts = dateString.split(' '); - var dateParts = dateTimeParts[0].split('-'); - var timeParts = dateTimeParts[1].split(':'); + var dateTimeParts = dateString?.split(' '); + var dateParts = dateTimeParts[0]?.split('-'); + var timeParts = dateTimeParts[1]?.split(':'); // Extract individual components var year = parseInt(dateParts[0], 10); var month = parseInt(dateParts[1], 10) - 1; // Months are zero-based in JavaScript var day = parseInt(dateParts[2], 10); - var hours = parseInt(timeParts[0], 10); - var minutes = parseInt(timeParts[1], 10); - var seconds = parseInt(timeParts[2], 10); + var hours = 0; + var minutes = 0; + var seconds = 0; + + + if(timeParts){ + // Extract time components + hours = parseInt(timeParts[0], 10); + minutes = parseInt(timeParts[1], 10); + seconds = parseInt(timeParts[2], 10); + } + // Create a new Date object var date = new Date(year, month, day, hours, minutes, seconds); // Extract date components - var day = date.getDate().toString().padStart(2, '0'); - var month = (date.getMonth() + 1).toString().padStart(2, '0'); // Months are zero-based - var year = date.getFullYear(); + day = date.getDate().toString().padStart(2, '0'); + month = (date.getMonth() + 1).toString().padStart(2, '0'); // Months are zero-based + year = date.getFullYear(); // Extract time components - var hours = date.getHours().toString().padStart(2, '0'); - var minutes = date.getMinutes().toString().padStart(2, '0'); - var seconds = date.getSeconds().toString().padStart(2, '0'); + hours = date.getHours().toString().padStart(2, '0'); + minutes = date.getMinutes().toString().padStart(2, '0'); + seconds = date.getSeconds().toString().padStart(2, '0'); + var formattedDate = ''; // Format the date and time in DD-MM-YYYY HH:MM:SS format if (flag == 1) { @@ -355,9 +381,8 @@ + let fromDateObj = new Date(fromDate.split('-').reverse().join('-')); + let toDateObj = new Date(toDate.split('-').reverse().join('-')); + if (fromDateObj > toDateObj) { + alert('Incorrect Date Applied For Filter..!!'); + $('#toDate').attr('min', fromDate); + $('#toDate').val(''); - - - - - - - - - - - - - - - + if (cylinderPendingCount > 0) { + alert("Please clear the " + cylinderPendingCount + " pending cylinders before downloading the Excel file."); + return false; + } + $("#loader").show(); + $.ajax({ + type: "POST", + url: "gasCylindersByIgr", + data: { + IGRNO: igrNo + }, + success: function(response) { + $("#loader").hide(); + if (response.status === "success") { + console.log(response.data); // Debugging - Check if data is correct + + let tableHTML = ` + + + + + + + + + + + + + + + + + + + + + `; + + let totalShortage = 0; + let totalNetWeight = 0; + let totalActualWeight = 0; + + response.data.forEach(item => { + + totalShortage += Number(item.shortage); + + totalNetWeight += Number(item.netWeight); + + totalActualWeight += Number(item.actualWeight); + + item.fullCylinderDate = formatDateTime(item.fullCylinderDate, 1); + item.emptyCylinderDate = formatDateTime(item.emptyCylinderDate, 1); + item.DeliveryChellanDate = formatDateTime(item.DeliveryChellanDate, 1); + + tableHTML += ` + + + + + + + + + + + + + + + + + + `; + }); + + tableHTML += ` + + + + + + + + + + + + + + + + + + + + + +
IGRNOFull Cylinder DateCylinder NoGross WeightEmpty Cylinder Return DateTare WeightNet WeightActual WeightShortageBill NoBill DateDriver NameVehicle No
${item.IGRNO}${item.fullCylinderDate}${item.cylinderNo}${item.grossWeight}${item.emptyCylinderDate}${item.tareWeight}${item.netWeight}${item.actualWeight}${item.shortage}${item.invoiceNo}${item.DeliveryChellanDate}${item.DriverName}${item.VehicleNo}
 
Weight${totalNetWeight}${totalActualWeight}${totalShortage}
+ `; + + $("#excelTableDiv").html(tableHTML); + + let table = document.getElementById('excelTable'); + + let filename = "GasCylinderReturned_" + igrNo + ".xlsx"; + + let rows = []; + + // Extract table data row-by-row + $(table).find('tr').each(function(rowIndex) { + let rowData = []; + + $(this).find('th, td').each(function(colIndex) { + // Skip hidden columns + if ($(this).css('display') === 'none') return; + let cellText = $(this).text().trim(); + rowData.push(cellText); + }); + + // Add the cleaned row only if it has data + if (rowData.length > 0) { + rows.push(rowData); + } + }); + + // Create a worksheet from array (no DOM needed!) + let ws = XLSX.utils.aoa_to_sheet(rows); + + // Define column widths (in character units) + const columnWidth = 15; // Set your desired width here + const wscols = []; + for (let i = 0; i < Object.keys(response.data[0]).length; i++) { + wscols.push({ + wch: columnWidth + }); + } + ws['!cols'] = wscols; + + let wb = XLSX.utils.book_new(); + XLSX.utils.book_append_sheet(wb, ws, 'Sheet1'); + XLSX.writeFile(wb, filename || 'export.xlsx'); + } + }, + + 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(); // Hide loader + } + }); + } + \ No newline at end of file