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,111 +3017,68 @@ class StockController extends BaseController
public function trpProductionDetails(){ public function trpProductionDetails()
{
$session = session(); // Store session instance once
if ($this->request->getMethod() === 'POST') { if ($this->request->getMethod() === 'POST') {
$month = $this->request->getPost('month'); $month = $this->request->getPost('month');
$date = DateTime::createFromFormat('M-Y', $month); $date = DateTime::createFromFormat('M-Y', $month);
$formattedDate = $date->format('Y-m'); if (!$date) {
return $this->response->setJSON(['error' => 'Invalid month format']);
$month = $formattedDate; }
$session = session ();
$session->set('stock_month',$month);
$month = $date->format('Y-m');
$session->set('stock_month', $month);
} else { } else {
$month = $session->get('stock_month') ?? date('Y-m'); // Default to current month
$session = session();
$month = $session->get('stock_month');
if (empty($month)) {
$month = date('Y-m'); // Default to the current month
} }
} $data = ['month' => $month];
$this->global['pageTitle'] = 'Trp Production Details';
$data = [];
$data['month'] = $month;
$this->global['pageTitle'] = 'Trp production Details';
$startDate = "$month-01"; $startDate = "$month-01";
$endDate = date("Y-m-t", strtotime($startDate)); $endDate = date("Y-m-t", strtotime($startDate));
// Fetch production maintenance data
$trpProductionMaintenanceData = $this->TrpProductionMaintenance_model $trpProductionMaintenanceData = $this->TrpProductionMaintenance_model
->where('date >=', $startDate) ->where('date >=', $startDate)
->where('date <=', $endDate) ->where('date <=', $endDate)
->find(); ->find();
if(empty($trpProductionMaintenanceData)){ // Create dummy data if no records found
if (empty($trpProductionMaintenanceData)) {
$inserts = []; $freshEntry = true;
$data['trpProductionMaintenanceData'] = $this->updateTrpProductionDetails(
$inserts = $this->createDummyDataForTrp($startDate, $endDate); $this->createDummyDataForTrp($startDate, $endDate),
$freshEntry
$freshEntry = true ; );
$data['trpProductionMaintenanceData'] = $this->updateTrpProductionDetails($inserts ,$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"
$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(); $trpAbstract = $this->trpAbstract_model->where('date', $startDate)->findAll();
$data['trpAbstract'] = array_column($trpAbstract, null, 'particulars');
// Format month for display
$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); $date = DateTime::createFromFormat('Y-m', $month);
$data['month'] = $date->format('M-Y');
$formattedDate = $date->format('M-Y'); // Support AJAX responses
if ($this->request->isAJAX()) {
$data['month'] = $formattedDate; return $this->response->setJSON($data);
// return $this->response->setJSON($data);
return $this->loadViews("stock/trpProductionStockDetails", $this->global, $data, NULL);
} }
return $this->loadViews("stock/trpProductionStockDetails", $this->global, $data);
}

View File

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

View File

@ -1140,8 +1140,7 @@
// Apply left alignment to the date column // Apply left alignment to the date column
firstTd.css("text-align", "left"); 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 // Apply left alignment to the date column
firstTd.css("text-align", "left"); 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 // Apply left alignment to the date column
firstTd.css("text-align", "left"); 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 // Apply left alignment to the date column
firstTd.css("text-align", "left"); 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 // Apply left alignment to the date column
firstTd.css("text-align", "left"); 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 // Apply left alignment to the date column
firstTd.css("text-align", "left"); 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>
<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 // Apply left alignment to the date column
firstTd.css("text-align", "left"); 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)
}); });