changed logic in item overview final updation #1351
@@ -13,6 +13,8 @@ class ItemOverview extends ChartWidget
|
|||||||
{
|
{
|
||||||
protected static ?string $heading = 'Hourly Production';
|
protected static ?string $heading = 'Hourly Production';
|
||||||
|
|
||||||
|
public ?string $filter = 'today';
|
||||||
|
|
||||||
protected int|string|array $columnSpan = '12';
|
protected int|string|array $columnSpan = '12';
|
||||||
|
|
||||||
protected static ?string $maxHeight = '400px';
|
protected static ?string $maxHeight = '400px';
|
||||||
@@ -150,6 +152,8 @@ class ItemOverview extends ChartWidget
|
|||||||
// $planQuantity
|
// $planQuantity
|
||||||
// );
|
// );
|
||||||
|
|
||||||
|
$planData = [];
|
||||||
|
|
||||||
if ($activeFilter === 'today') {
|
if ($activeFilter === 'today') {
|
||||||
|
|
||||||
$monthlyPlanQuantity = \DB::table('production_plans')
|
$monthlyPlanQuantity = \DB::table('production_plans')
|
||||||
@@ -159,18 +163,16 @@ class ItemOverview extends ChartWidget
|
|||||||
->whereMonth('created_at', $startDate->month)
|
->whereMonth('created_at', $startDate->month)
|
||||||
->sum('plan_quantity');
|
->sum('plan_quantity');
|
||||||
|
|
||||||
// Calculate daily target directly
|
$weeksCount = (int) ceil(now()->daysInMonth / 7);
|
||||||
$weeksCount = (int) ceil($startDate->daysInMonth / 7);
|
|
||||||
|
|
||||||
$dailyPlan = $weeksCount > 0
|
$dailyPlan = $weeksCount > 0
|
||||||
? round($monthlyPlanQuantity / ($weeksCount * 7), 2)
|
? round($monthlyPlanQuantity / ($weeksCount * 7), 2)
|
||||||
: 0;
|
: 0;
|
||||||
|
|
||||||
// Calculate hourly target
|
|
||||||
$hourlyPlan = round($dailyPlan / 22.5, 2);
|
$hourlyPlan = round($dailyPlan / 22.5, 2);
|
||||||
|
|
||||||
// Same hourly plan value for every hour
|
$planData = array_fill(0, count($orderedData), $hourlyPlan);
|
||||||
$planData = array_fill(0, 24, $hourlyPlan);
|
|
||||||
}
|
}
|
||||||
if ($activeFilter === 'yesterday') {
|
if ($activeFilter === 'yesterday') {
|
||||||
|
|
||||||
@@ -240,14 +242,7 @@ class ItemOverview extends ChartWidget
|
|||||||
// Monday through Sunday
|
// Monday through Sunday
|
||||||
$planData = array_fill(0, 7, $dailyPlan);
|
$planData = array_fill(0, 7, $dailyPlan);
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
// This Week: each day's production / 22.5
|
|
||||||
// This Month: each week's production / 22.5
|
|
||||||
$planData = array_map(
|
|
||||||
fn ($quantity) => round($quantity / 22.5, 2),
|
|
||||||
$orderedData
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'datasets' => [
|
'datasets' => [
|
||||||
|
|||||||
Reference in New Issue
Block a user