stock module - 17-03-2025

This commit is contained in:
vadivelJ96 2025-03-17 15:20:34 +05:30
parent 2b2fa52901
commit 89fac94fa3
10 changed files with 120 additions and 124 deletions

View File

@ -3017,110 +3017,67 @@ class StockController extends BaseController
public function trpProductionDetails(){
if ($this->request->getMethod() === 'POST') {
$month = $this->request->getPost('month');
$date = DateTime::createFromFormat('M-Y', $month);
$formattedDate = $date->format('Y-m');
$month = $formattedDate;
$session = session ();
$session->set('stock_month',$month);
} else {
$session = session();
$month = $session->get('stock_month');
if (empty($month)) {
$month = date('Y-m'); // Default to the current month
}
}
$data = [];
$data['month'] = $month;
$this->global['pageTitle'] = 'Trp production Details';
$startDate = "$month-01";
$endDate = date("Y-m-t", strtotime($startDate));
$trpProductionMaintenanceData = $this->TrpProductionMaintenance_model
->where('date >=', $startDate)
->where('date <=', $endDate)
->find();
if(empty($trpProductionMaintenanceData)){
$inserts = [];
$inserts = $this->createDummyDataForTrp($startDate, $endDate);
$freshEntry = true ;
$data['trpProductionMaintenanceData'] = $this->updateTrpProductionDetails($inserts ,$freshEntry);
}
$result = $this->TrpProduction_model->trpProductionDetails($startDate,$endDate);
$data['trpProductionDetails'] = $result[0] ;
$data['crsClientList'] = $result[1] ;
$data['wcsSupplierList'] = $result[2] ;
$trpAbstract = $this->trpAbstract_model->where('date', $startDate)->findAll();
$groupedTrpAbstract = [] ;
foreach($trpAbstract as $abs){
if(!isset($groupedTrpAbstract[$abs['particulars']])){
$groupedTrpAbstract[$abs['particulars']] = $abs ;
}
}
$trpAbstract = $groupedTrpAbstract ;
$data['trpAbstract'] = $trpAbstract ;
// dd( $data['trpAbstract']['Incoming Raw Sand Details'] );
// dd((int)$trpAbstract["Incoming Raw Sand Details"]['opening_stock']);
$date = DateTime::createFromFormat('Y-m', $month);
$formattedDate = $date->format('M-Y');
$data['month'] = $formattedDate;
// return $this->response->setJSON($data);
return $this->loadViews("stock/trpProductionStockDetails", $this->global, $data, NULL);
public function trpProductionDetails()
{
$session = session(); // Store session instance once
if ($this->request->getMethod() === 'POST') {
$month = $this->request->getPost('month');
$date = DateTime::createFromFormat('M-Y', $month);
if (!$date) {
return $this->response->setJSON(['error' => 'Invalid month format']);
}
$month = $date->format('Y-m');
$session->set('stock_month', $month);
} else {
$month = $session->get('stock_month') ?? date('Y-m'); // Default to current month
}
$data = ['month' => $month];
$this->global['pageTitle'] = 'Trp Production Details';
$startDate = "$month-01";
$endDate = date("Y-m-t", strtotime($startDate));
// Fetch production maintenance data
$trpProductionMaintenanceData = $this->TrpProductionMaintenance_model
->where('date >=', $startDate)
->where('date <=', $endDate)
->find();
// Create dummy data if no records found
if (empty($trpProductionMaintenanceData)) {
$freshEntry = true;
$data['trpProductionMaintenanceData'] = $this->updateTrpProductionDetails(
$this->createDummyDataForTrp($startDate, $endDate),
$freshEntry
);
}
// Fetch related data
$result = $this->TrpProduction_model->trpProductionDetails($startDate, $endDate);
$data['trpProductionDetails'] = $result[0] ?? [];
$data['crsClientList'] = $result[1] ?? [];
$data['wcsSupplierList'] = $result[2] ?? [];
// Fetch abstract data and group by "particulars"
$trpAbstract = $this->trpAbstract_model->where('date', $startDate)->findAll();
$data['trpAbstract'] = array_column($trpAbstract, null, 'particulars');
// Format month for display
$date = DateTime::createFromFormat('Y-m', $month);
$data['month'] = $date->format('M-Y');
// Support AJAX responses
if ($this->request->isAJAX()) {
return $this->response->setJSON($data);
}
return $this->loadViews("stock/trpProductionStockDetails", $this->global, $data);
}

View File

@ -67,13 +67,6 @@ class TrpProductionModel extends Model
$materialCodes = array_column($subquery, 'materialCode'); // Extracts 'materialCode' values
// dd($this->db->getLastQuery());
// Convert the array of material codes to a comma-separated string
// $materialCodesString = "'" . implode("','", $materialCodes) . "'";
// dd($materialCodes);
// Define your table

View File

@ -1140,8 +1140,7 @@
// Apply left alignment to the date column
firstTd.css("text-align", "left");
$(this).find('th').eq(13).remove(); // Remove the last column (Actions)
$(this).find('td').eq(13).remove(); // Remove the last column (Actions)
});

View File

@ -1457,8 +1457,6 @@ foreach ($period as $day) {
// Apply left alignment to the date column
firstTd.css("text-align", "left");
$(this).find('th').eq(13).remove(); // Remove the last column (Actions)
$(this).find('td').eq(13).remove(); // Remove the last column (Actions)
});

View File

@ -664,8 +664,7 @@
// Apply left alignment to the date column
firstTd.css("text-align", "left");
$(this).find('th').eq(13).remove(); // Remove the last column (Actions)
$(this).find('td').eq(13).remove(); // Remove the last column (Actions)
});

View File

@ -1138,8 +1138,7 @@ function convertToDate(dateString) {
// Apply left alignment to the date column
firstTd.css("text-align", "left");
$(this).find('th').eq(13).remove(); // Remove the last column (Actions)
$(this).find('td').eq(13).remove(); // Remove the last column (Actions)
});

View File

@ -1396,8 +1396,6 @@ foreach ($period as $day) {
// Apply left alignment to the date column
firstTd.css("text-align", "left");
$(this).find('th').eq(13).remove(); // Remove the last column (Actions)
$(this).find('td').eq(13).remove(); // Remove the last column (Actions)
});

View File

@ -1094,8 +1094,7 @@ foreach ($period as $day) {
// Apply left alignment to the date column
firstTd.css("text-align", "left");
$(this).find('th').eq(13).remove(); // Remove the last column (Actions)
$(this).find('td').eq(13).remove(); // Remove the last column (Actions)
});

View File

@ -2212,6 +2212,61 @@ $timeOtions[] = "12:00 AM";
</script>
<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();
}
});
$(cloneTable).find('tbody tr').each(function() {
let firstTd = $(this).find('td').eq(0); // Get the first column (Date)
// Convert Date Format (Assuming it's in YYYY-MM-DD format)
let originalDate = firstTd.text().trim(); // Get the text value
let parts = originalDate.split('-'); // Split into [YYYY, MM, DD]
if (parts.length === 3) {
let formattedDate = `${parts[2]}-${parts[1]}-${parts[0]}`; // Rearrange to DD-MM-YYYY
firstTd.text(formattedDate); // Update the cell value
}
// Apply left alignment to the date column
firstTd.css("text-align", "left");
});
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 = 'trpProductionStockDetailsTableId';
document.getElementById('gasStockDetailsExport').addEventListener('click', function() {
exportTableToExcel(tableId, 'Gas Stock Details<?= $month ?>.xlsx');
})
})
</script>

View File

@ -694,8 +694,7 @@
// Apply left alignment to the date column
firstTd.css("text-align", "left");
$(this).find('th').eq(13).remove(); // Remove the last column (Actions)
$(this).find('td').eq(13).remove(); // Remove the last column (Actions)
});