Added Capacity quantity and over all efficiency column mail table #435
@@ -3,6 +3,7 @@
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Mail\ProductionMail;
|
||||
use App\Models\Item;
|
||||
use App\Models\Line;
|
||||
use App\Models\Plant;
|
||||
use App\Models\ProductionPlan;
|
||||
@@ -75,59 +76,211 @@ class SendProductionReport extends Command
|
||||
|
||||
// .
|
||||
|
||||
// foreach ($plants as $plant) {
|
||||
// $lines = Line::where('plant_id', $plant->id)->get();
|
||||
|
||||
// foreach ($lines as $line) {
|
||||
|
||||
// $month = $startDate->month;
|
||||
// $year = $startDate->year;
|
||||
|
||||
// $workingDays = ProductionPlan::where('plant_id', $plantId)
|
||||
// ->whereMonth('created_at', $month)
|
||||
// ->whereYear('created_at', $year)
|
||||
// ->value('working_days') ?? 0;
|
||||
|
||||
// $totalTargetQuantity = 0;
|
||||
|
||||
// $monthlyPlan = ProductionPlan::where('plant_id', $plantId)
|
||||
// ->where('line_id', $line->id)
|
||||
// ->whereMonth('created_at', $month)
|
||||
// ->whereYear('created_at', $year)
|
||||
// ->sum('plan_quantity'); // / $workingDays
|
||||
|
||||
// $dailyTarget = $workingDays > 0
|
||||
// ? $monthlyPlan / $workingDays
|
||||
// : 0;
|
||||
|
||||
// $dailyTarget = round($dailyTarget, 2);
|
||||
|
||||
// // $totalTargetQuantity = round($totalTargetQuantity, 2);
|
||||
|
||||
// $monthStart = $startDate->copy()->startOfMonth();
|
||||
// $completedDays = $monthStart->diffInDays($startDate);
|
||||
|
||||
// $expectedTillYesterday = $dailyTarget * $completedDays;
|
||||
|
||||
// if (strtolower($line->type) == 'fg line') {
|
||||
// $productionQuantity = \App\Models\QualityValidation::where('plant_id', $plant->id)
|
||||
// ->where('line_id', $line->id)
|
||||
// ->whereBetween('created_at', [$startDate, $endDate])
|
||||
// ->count();
|
||||
// } else {
|
||||
// $productionQuantity = ProductionQuantity::where('plant_id', $plant->id)
|
||||
// ->where('line_id', $line->id)
|
||||
// ->whereBetween('created_at', [$startDate, $endDate])
|
||||
// ->count();
|
||||
// }
|
||||
|
||||
// $previousRemaining = max(0, $expectedTillYesterday - $productionQuantity);
|
||||
|
||||
// $totalTargetQuantity = round($dailyTarget + $previousRemaining, 2);
|
||||
|
||||
// $tableData[] = [
|
||||
// 'no' => $no++,
|
||||
// 'plant' => $plant->name,
|
||||
// 'line' => $line->name,
|
||||
// 'type' => $line->type,
|
||||
// 'targetQuantity' => $totalTargetQuantity,
|
||||
// 'productionQuantity' => $productionQuantity,
|
||||
// ];
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
//..New Logic
|
||||
|
||||
foreach ($plants as $plant) {
|
||||
|
||||
$lines = Line::where('plant_id', $plant->id)->get();
|
||||
|
||||
foreach ($lines as $line) {
|
||||
$targetQuantity = ProductionPlan::where('plant_id', $plant->id)
|
||||
|
||||
$month = $startDate->month;
|
||||
$year = $startDate->year;
|
||||
|
||||
$workingDays = ProductionPlan::where('plant_id', $plant->id)
|
||||
->where('line_id', $line->id)
|
||||
->whereBetween('created_at', [$PlanstartDate, $planendDate])
|
||||
->whereMonth('created_at', $month)
|
||||
->whereYear('created_at', $year)
|
||||
->value('working_days') ?? 0;
|
||||
|
||||
$monthlyPlan = ProductionPlan::where('plant_id', $plant->id)
|
||||
->where('line_id', $line->id)
|
||||
->whereMonth('created_at', $month)
|
||||
->whereYear('created_at', $year)
|
||||
->sum('plan_quantity');
|
||||
|
||||
/** @phpstan-ignore property.notFound */
|
||||
$dailyTarget = $workingDays > 0 ? $monthlyPlan / $workingDays : 0;
|
||||
|
||||
$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);
|
||||
|
||||
$itemIds = ProductionPlan::where('plant_id', $plant->id)
|
||||
->where('line_id', $line->id)
|
||||
->whereMonth('created_at', $month)
|
||||
->whereYear('created_at', $year)
|
||||
->distinct()
|
||||
->pluck('item_id');
|
||||
|
||||
$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)
|
||||
->whereBetween('created_at', [$startDate, $endDate])
|
||||
->count();
|
||||
|
||||
} else {
|
||||
|
||||
$productionQuantity = ProductionQuantity::where('plant_id', $plant->id)
|
||||
->where('line_id', $line->id)
|
||||
->whereBetween('created_at', [$startDate, $endDate])
|
||||
->count();
|
||||
}
|
||||
|
||||
if ($capacityQuan > 0) {
|
||||
$efficiency = ($productionQuantity / $capacityQuan) * 100;
|
||||
} else {
|
||||
$efficiency = 0;
|
||||
}
|
||||
|
||||
$efficiency = round($efficiency, 2);
|
||||
|
||||
$tableData[] = [
|
||||
'no' => $no++,
|
||||
'plant' => $plant->name,
|
||||
'line' => $line->name,
|
||||
'type' => $line->type,
|
||||
'targetQuantity' => $targetQuantity,
|
||||
'line' => $line->name,
|
||||
'capacityQuantity' => floor($capacityQuan),
|
||||
'targetQuantity' => floor($totalTargetQuantity),
|
||||
'productionQuantity' => $productionQuantity,
|
||||
'efficiency' => $efficiency . '%',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
// $this->table(['No', 'Plant', 'Line', 'Target Quantity', 'Production Quantity'], $fgTableData);
|
||||
// $service = new \App\Services\ProductionTargetService();
|
||||
|
||||
// $this->table(['No', 'Plant', 'Line', 'Target Quantity', 'Production Quantity'], $tableData);
|
||||
// $year = $startDate->year;
|
||||
// $month = $startDate->month;
|
||||
|
||||
// if (!empty($emails)) {
|
||||
// foreach ($emails as $email) {
|
||||
// Mail::to($email)->send(new ProductionMail($tableData));
|
||||
// }
|
||||
// } else {
|
||||
// $this->info('No recipients found for ProductionMailAlert.');
|
||||
// }
|
||||
// [$records, $dates] = $service->generate(
|
||||
// $plantId,
|
||||
// $year,
|
||||
// $month,
|
||||
// );
|
||||
|
||||
// $this->info("Production report sent to " . count($emails) . " recipient(s).");
|
||||
// Preview in console
|
||||
$mail = new ProductionMail($scheduleType, $tableData);
|
||||
|
||||
// $mail = new ProductionMail($scheduleType,$tableData,$records,$dates);
|
||||
|
||||
$contentVars = $mail->content()->with;
|
||||
|
||||
$this->info($contentVars['greeting'] ?? 'Production Report');
|
||||
$this->table(
|
||||
['No', 'Plant', 'Line', 'Type', 'Target Quantity', 'Production Quantity'],
|
||||
['No', 'Plant', 'Line', 'Type', 'Capacity Quantity', 'Target Quantity', 'Production Quantity'],
|
||||
$tableData
|
||||
);
|
||||
$this->info($contentVars['wishes'] ?? '');
|
||||
|
||||
@@ -61,9 +61,11 @@
|
||||
<th style="text-align: center; border: 1px solid #444; padding: 8px; background: #f2f2f2;">No</th>
|
||||
<th style="text-align: center; border: 1px solid #444; padding: 8px; background: #f2f2f2; white-space: nowrap;">Plant</th>
|
||||
<th style="text-align: center; border: 1px solid #444; padding: 8px; background: #f2f2f2; white-space: nowrap;">Line</th>
|
||||
<th style="text-align: center; border: 1px solid #444; padding: 8px; background: #f2f2f2;">Target Quantity</th>
|
||||
<th style="text-align: center; border: 1px solid #444; padding: 8px; background: #f2f2f2;">Line Type</th>
|
||||
<th style="text-align: center; border: 1px solid #444; padding: 8px; background: #f2f2f2;">Capacity Quantity</th>
|
||||
<th style="text-align: center; border: 1px solid #444; padding: 8px; background: #f2f2f2;">Target Quantity</th>
|
||||
<th style="text-align: center; border: 1px solid #444; padding: 8px; background: #f2f2f2;">Production Quantity</th>
|
||||
<th style="text-align: center; border: 1px solid #444; padding: 8px; background: #f2f2f2;">OverAll Efficiency(%)</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@@ -72,9 +74,11 @@
|
||||
<td style="border: 1px solid #444; padding: 8px; text-align: center;">{{ $row['no'] }}</td>
|
||||
<td style="border: 1px solid #444; padding: 8px; text-align: center; white-space: nowrap;">{{ $row['plant'] }}</td>
|
||||
<td style="border: 1px solid #444; padding: 8px; text-align: center; white-space: nowrap;">{{ $row['line'] }}</td>
|
||||
<td style="border: 1px solid #444; padding: 8px; text-align: center;">{{ $row['targetQuantity'] }}</td>
|
||||
<td style="border: 1px solid #444; padding: 8px; text-align: center;">{{ $row['type'] }}</td>
|
||||
<td style="border: 1px solid #444; padding: 8px; text-align: center;">{{ $row['capacityQuantity'] }}</td>
|
||||
<td style="border: 1px solid #444; padding: 8px; text-align: center;">{{ $row['targetQuantity'] }}</td>
|
||||
<td style="border: 1px solid #444; padding: 8px; text-align: center;">{{ $row['productionQuantity'] }}</td>
|
||||
<td style="border: 1px solid #444; padding: 8px; text-align: center;">{{ $row['efficiency'] }}</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
|
||||
Reference in New Issue
Block a user