Merge pull request 'ranjith-dev' (#1170) from ranjith-dev into master
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 19s

Reviewed-on: #1170
This commit was merged in pull request #1170.
This commit is contained in:
2026-10-05 05:15:25 +00:00
2 changed files with 73 additions and 56 deletions

View File

@@ -33,13 +33,10 @@ class SendProductionReport extends Command
*/
public function handle()
{
// ini_set('max_execution_time', 0); // disable limit
// set_time_limit(0);
$scheduleType = $this->argument('schedule_type');
$plantId = (int) $this->argument('plant'); // cast to int for safety
$plantId = (int) $this->argument('plant');
// Fetch mail rules based on schedule type
$mailRules = \App\Models\AlertMailRule::where('module', 'ProductionQuantities')
->where('rule_name', 'ProductionMail')
->where('schedule_type', $scheduleType)
@@ -190,53 +187,11 @@ class SendProductionReport extends Command
$dailyTarget = round($dailyTarget, 2);
$leaveDatesString = ProductionPlan::where('plant_id', $plant->id)
->where('line_id', $line->id)
->whereMonth('created_at', $month)
->whereYear('created_at', $year)
->value('leave_dates');
$leaveDates = $leaveDatesString ? explode(',', $leaveDatesString) : [];
$monthStart = $startDate->copy()->startOfMonth();
$yesterday = $startDate->copy()->subDay();
$completedDays = 0;
$currentDate = $monthStart->copy();
while ($currentDate->lte($yesterday)) {
if (!in_array($currentDate->format('Y-m-d'), $leaveDates)) {
$completedDays++;
}
$currentDate->addDay();
}
$expectedTillYesterday = $dailyTarget * $completedDays;
if (strtolower($line->type) == 'fg line') {
$producedTillYesterday = \App\Models\QualityValidation::where('plant_id', $plant->id)
->where('line_id', $line->id)
->whereMonth('created_at', $month)
->whereYear('created_at', $year)
->where('created_at', '<', $startDate)
->count();
} else {
$producedTillYesterday = ProductionQuantity::where('plant_id', $plant->id)
->where('line_id', $line->id)
->whereMonth('created_at', $month)
->whereYear('created_at', $year)
->where('created_at', '<', $startDate)
->count();
}
$previousRemaining = max(0, $expectedTillYesterday - $producedTillYesterday);
$totalTargetQuantity = round($dailyTarget + $previousRemaining, 2);
// $leaveDatesString = ProductionPlan::where('plant_id', $plant->id)
// ->where('line_id', $line->id)
// ->whereMonth('created_at', $month)
// ->whereYear('created_at', $year)
// ->value('leave_dates');
$itemIds = ProductionPlan::where('plant_id', $plant->id)
->where('line_id', $line->id)
@@ -245,15 +200,70 @@ class SendProductionReport extends Command
->distinct()
->pluck('item_id');
$totalHourlyQuantity = Item::whereIn('id', $itemIds)
->sum('hourly_quantity');
// $leaveDates = $leaveDatesString ? explode(',', $leaveDatesString) : [];
$capacityQuan = $totalHourlyQuantity * 22.5;
// $monthStart = $startDate->copy()->startOfMonth();
// $monthStart = $startDate->copy()->startOfMonth()->setTime(8, 0, 0);
// $yesterday = $startDate->copy()->subDay()->setTime(8, 0, 0);
// $completedDays = 0;
// $currentDate = $monthStart->copy();
// while ($currentDate->lte($yesterday)) {
// if (!in_array($currentDate->format('Y-m-d'), $leaveDates)) {
// $completedDays++;
// }
// $currentDate->addDay();
// }
// $expectedTillYesterday = $dailyTarget * $completedDays;
// if (strtolower($line->type) == 'fg line') {
// $producedTillYesterday = \App\Models\QualityValidation::where('plant_id', $plant->id)
// ->where('line_id', $line->id)
// ->whereIn('item_id', $itemIds)
// ->whereMonth('created_at', $month)
// ->whereYear('created_at', $year)
// ->where('created_at', '<', $startDate)
// ->count();
// } else {
// $producedTillYesterday = ProductionQuantity::where('plant_id', $plant->id)
// ->where('line_id', $line->id)
// ->whereIn('item_id', $itemIds)
// ->whereMonth('created_at', $month)
// ->whereYear('created_at', $year)
// ->where('created_at', '<', $startDate)
// ->count();
// }
// $previousRemaining = max(0, $expectedTillYesterday - $producedTillYesterday);
// $totalTargetQuantity = round($dailyTarget + $previousRemaining, 2);
$totalTargetQuantity = round($dailyTarget, 2);
// $totalHourlyQuantity = Item::whereIn('id', $itemIds)
// ->sum('hourly_quantity');
// $capacityQuan = $totalHourlyQuantity * 22.5;
if (strtolower($line->type) == 'fg line') {
$productionQuantity = \App\Models\QualityValidation::where('plant_id', $plant->id)
->where('line_id', $line->id)
->whereIn('item_id', $itemIds)
->whereBetween('created_at', [$startDate, $endDate])
->count();
$nonPlannedproductionQuantity = \App\Models\QualityValidation::where('plant_id', $plant->id)
->where('line_id', $line->id)
->whereNotIn('item_id', $itemIds)
->whereBetween('created_at', [$startDate, $endDate])
->count();
@@ -286,6 +296,7 @@ class SendProductionReport extends Command
$dayproductionQuantity = \App\Models\QualityValidation::where('plant_id', $plant->id)
->where('line_id', $line->id)
->whereIn('item_id', $itemIds)
->whereBetween('created_at', [
$startDate->copy()->setTime(8, 0, 0),
$startDate->copy()->setTime(19, 30, 0),
@@ -294,6 +305,7 @@ class SendProductionReport extends Command
$nightproductionQuantity = \App\Models\QualityValidation::where('plant_id', $plant->id)
->where('line_id', $line->id)
->whereIn('item_id', $itemIds)
->whereBetween('created_at', [
$startDate->copy()->setTime(19, 30, 0),
$endDate->copy()->setTime(8, 0, 0),
@@ -331,7 +343,7 @@ class SendProductionReport extends Command
'plant' => $plant->name,
'type' => $line->type,
'line' => $line->name,
'capacityQuantity' => floor($capacityQuan),
// 'capacityQuantity' => floor($capacityQuan),
'dayShiftPlanQuantity' => floor($dayShiftPlanQuan),
'dayShiftActualQuantity' => floor($dayproductionQuantity),
'dayShiftEfficiency' => floor($dayShiftEfficiency) . '%',
@@ -342,6 +354,7 @@ class SendProductionReport extends Command
'productionQuantity' => $productionQuantity,
'uom' => $line->uom,
'efficiency' => $efficiency . '%',
'nonPlannedQuantity' => $nonPlannedproductionQuantity,
];
}
}

View File

@@ -1,7 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<title>Invoice Table</title>
<title>Production Table</title>
<style>
table {
border-collapse: collapse;
@@ -143,6 +143,7 @@
<th rowspan="2" style="border:1px solid #444; padding:8px; background:#f2f2f2; text-align:center;">Actual Quantity</th>
<th rowspan="2" style="border:1px solid #444; padding:8px; background:#f2f2f2; text-align:center;">UOM</th>
<th rowspan="2" style="border:1px solid #444; padding:8px; background:#f2f2f2; text-align:center;">Plan Vs Actual Efficiency(%)</th>
<th rowspan="2" style="border:1px solid #444; padding:8px; background:#f2f2f2; text-align:center;">Non Planned Production Quantity</th>
</tr>
<tr>
<th style="border:1px solid #444; padding:8px; background:#f2f2f2; text-align:center;">Plan Quantity</th>
@@ -227,6 +228,9 @@
<td style="text-align:center; border:1px solid #444; padding:8px; background-color: {{ $efficiencyColor }}; color: #fff; font-weight: bold;">
{{ $row['efficiency'] }}
</td>
<td style="text-align:center; border:1px solid #444; padding:8px;">
{{ $row['nonPlannedQuantity'] }}
</td>
</tr>
@endforeach