Merge pull request 'Removed unwanted logic from target plan page' (#1227) from ranjith-dev into master
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 20s
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 20s
Reviewed-on: #1227
This commit was merged in pull request #1227.
This commit is contained in:
@@ -463,12 +463,12 @@ class ProductionTargetPlan extends Component
|
|||||||
$this->leaveDates = [];
|
$this->leaveDates = [];
|
||||||
|
|
||||||
if (!$plantId || !$lineId || !$month || !$year) {
|
if (!$plantId || !$lineId || !$month || !$year) {
|
||||||
// $this->records = [];
|
|
||||||
// $this->dates = [];
|
|
||||||
// $this->leaveDates = [];
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$startDate = Carbon::create($year, $month, 1)->startOfDay();
|
||||||
|
$endDate = $startDate->copy()->addMonth();
|
||||||
|
|
||||||
$dates = $this->getMonthDates($month, $year);
|
$dates = $this->getMonthDates($month, $year);
|
||||||
$this->dates = $dates;
|
$this->dates = $dates;
|
||||||
|
|
||||||
@@ -478,8 +478,10 @@ class ProductionTargetPlan extends Component
|
|||||||
->join('plants', 'plants.id', '=', 'production_plans.plant_id')
|
->join('plants', 'plants.id', '=', 'production_plans.plant_id')
|
||||||
->where('production_plans.plant_id', $plantId)
|
->where('production_plans.plant_id', $plantId)
|
||||||
->where('production_plans.line_id', $lineId)
|
->where('production_plans.line_id', $lineId)
|
||||||
->whereMonth('production_plans.created_at', $month)
|
// ->whereMonth('production_plans.created_at', $month)
|
||||||
->whereYear('production_plans.created_at', $year)
|
// ->whereYear('production_plans.created_at', $year)
|
||||||
|
->where('production_plans.created_at', '>=', $startDate)
|
||||||
|
->where('production_plans.created_at', '<', $endDate)
|
||||||
->select(
|
->select(
|
||||||
'production_plans.item_id',
|
'production_plans.item_id',
|
||||||
'production_plans.plant_id',
|
'production_plans.plant_id',
|
||||||
@@ -492,7 +494,6 @@ class ProductionTargetPlan extends Component
|
|||||||
'items.description as item_description',
|
'items.description as item_description',
|
||||||
'items.hourly_quantity as hourly_quantity',
|
'items.hourly_quantity as hourly_quantity',
|
||||||
'lines.name as line_name',
|
'lines.name as line_name',
|
||||||
// 'lines.line_capacity as line_capacity',
|
|
||||||
'plants.name as plant_name'
|
'plants.name as plant_name'
|
||||||
)
|
)
|
||||||
->get();
|
->get();
|
||||||
@@ -505,7 +506,7 @@ class ProductionTargetPlan extends Component
|
|||||||
|
|
||||||
$this->leaveDates = $leaveDates;
|
$this->leaveDates = $leaveDates;
|
||||||
|
|
||||||
$start = microtime(true);
|
$leaveDateLookup = array_fill_keys($leaveDates, true);
|
||||||
|
|
||||||
$producedData = QualityValidation::selectRaw("
|
$producedData = QualityValidation::selectRaw("
|
||||||
quality_validations.plant_id,
|
quality_validations.plant_id,
|
||||||
@@ -522,8 +523,10 @@ class ProductionTargetPlan extends Component
|
|||||||
)
|
)
|
||||||
->where('quality_validations.plant_id', $plantId)
|
->where('quality_validations.plant_id', $plantId)
|
||||||
->where('quality_validations.line_id', $lineId)
|
->where('quality_validations.line_id', $lineId)
|
||||||
->whereMonth('quality_validations.created_at', $month)
|
// ->whereMonth('quality_validations.created_at', $month)
|
||||||
->whereYear('quality_validations.created_at', $year)
|
// ->whereYear('quality_validations.created_at', $year)
|
||||||
|
->where('quality_validations.created_at', '>=', $startDate)
|
||||||
|
->where('quality_validations.created_at', '<', $endDate)
|
||||||
->groupBy(
|
->groupBy(
|
||||||
'quality_validations.plant_id',
|
'quality_validations.plant_id',
|
||||||
'quality_validations.line_id',
|
'quality_validations.line_id',
|
||||||
@@ -542,32 +545,18 @@ class ProductionTargetPlan extends Component
|
|||||||
|
|
||||||
$row = $plan->toArray();
|
$row = $plan->toArray();
|
||||||
|
|
||||||
/*
|
|
||||||
* Calculate the normal daily target.
|
|
||||||
*
|
|
||||||
* Example:
|
|
||||||
* Plan quantity = 60
|
|
||||||
* Working days = 3
|
|
||||||
*
|
|
||||||
* Normal daily target = 60 / 3 = 20
|
|
||||||
*/
|
|
||||||
$workingDays = (int) ($row['working_days'] ?? 0);
|
$workingDays = (int) ($row['working_days'] ?? 0);
|
||||||
|
|
||||||
$normalDailyTarget = $workingDays > 0
|
$normalDailyTarget = $workingDays > 0
|
||||||
? round((float) $row['plan_quantity'] / $workingDays, 2)
|
? round((float) $row['plan_quantity'] / $workingDays, 2)
|
||||||
: 0;
|
: 0;
|
||||||
|
|
||||||
/*
|
|
||||||
* This stores the uncompleted quantity from the previous
|
|
||||||
* working day and carries it to the next working day.
|
|
||||||
*/
|
|
||||||
$pendingQty = 0;
|
$pendingQty = 0;
|
||||||
|
|
||||||
$lineCapacity = (float) ($row['line_capacity'] ?? 0);
|
$lineCapacity = (float) ($row['line_capacity'] ?? 0);
|
||||||
$dailyHourlyQuantity = (float) ($row['hourly_quantity'] ?? 0);
|
$dailyHourlyQuantity = (float) ($row['hourly_quantity'] ?? 0);
|
||||||
|
|
||||||
$row['category'] = $row['category'] ?? '-';
|
$row['category'] = $row['category'] ?? '-';
|
||||||
$row['daily_hourly_quantity'] = [];
|
|
||||||
$row['daily_target_dynamic'] = [];
|
$row['daily_target_dynamic'] = [];
|
||||||
$row['produced_quantity'] = [];
|
$row['produced_quantity'] = [];
|
||||||
|
|
||||||
@@ -575,61 +564,22 @@ class ProductionTargetPlan extends Component
|
|||||||
|
|
||||||
foreach ($dates as $date) {
|
foreach ($dates as $date) {
|
||||||
|
|
||||||
/*
|
// if (in_array($date, $leaveDates)) {
|
||||||
* Skip leave dates.
|
if (isset($leaveDateLookup[$date])) {
|
||||||
*
|
|
||||||
* Pending quantity is NOT changed here.
|
|
||||||
* Therefore it will carry forward to the next working day.
|
|
||||||
*/
|
|
||||||
if (in_array($date, $leaveDates)) {
|
|
||||||
|
|
||||||
$row['daily_hourly_quantity'][$date] = '-';
|
|
||||||
$row['daily_target_dynamic'][$date] = '-';
|
$row['daily_target_dynamic'][$date] = '-';
|
||||||
$row['produced_quantity'][$date] = '-';
|
$row['produced_quantity'][$date] = '-';
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
$todayTarget = round($normalDailyTarget + $pendingQty,2);
|
||||||
* Today's target:
|
|
||||||
*
|
|
||||||
* Normal daily target
|
|
||||||
* +
|
|
||||||
* Previous day's pending quantity
|
|
||||||
*/
|
|
||||||
$todayTarget = round(
|
|
||||||
$normalDailyTarget + $pendingQty,
|
|
||||||
2
|
|
||||||
);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Get actual produced quantity for this item/date.
|
|
||||||
*/
|
|
||||||
$producedQty = $producedData[$key][$date]->total_qty ?? 0;
|
$producedQty = $producedData[$key][$date]->total_qty ?? 0;
|
||||||
|
|
||||||
/*
|
|
||||||
* Store today's values.
|
|
||||||
*/
|
|
||||||
$row['daily_target_dynamic'][$date] = $todayTarget;
|
$row['daily_target_dynamic'][$date] = $todayTarget;
|
||||||
$row['produced_quantity'][$date] = $producedQty;
|
$row['produced_quantity'][$date] = $producedQty;
|
||||||
$row['daily_hourly_quantity'][$date] = $dailyHourlyQuantity * 22.5;
|
|
||||||
|
|
||||||
/*
|
$pendingQty = max(0,$todayTarget - $producedQty);
|
||||||
* Calculate today's pending quantity.
|
|
||||||
*
|
|
||||||
* Example:
|
|
||||||
*
|
|
||||||
* Target = 40
|
|
||||||
* Produced = 30
|
|
||||||
*
|
|
||||||
* Pending = 10
|
|
||||||
*
|
|
||||||
* This 10 will be added to tomorrow's target.
|
|
||||||
*/
|
|
||||||
$pendingQty = max(
|
|
||||||
0,
|
|
||||||
$todayTarget - $producedQty
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$records[] = $row;
|
$records[] = $row;
|
||||||
@@ -666,12 +616,12 @@ class ProductionTargetPlan extends Component
|
|||||||
$this->leaveDates = [];
|
$this->leaveDates = [];
|
||||||
|
|
||||||
if (!$plantId || !$lineId || !$month || !$year || !$category) {
|
if (!$plantId || !$lineId || !$month || !$year || !$category) {
|
||||||
// $this->records = [];
|
|
||||||
// $this->dates = [];
|
|
||||||
// $this->leaveDates = [];
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$startDate = Carbon::create($year, $month, 1)->startOfDay();
|
||||||
|
$endDate = $startDate->copy()->addMonth();
|
||||||
|
|
||||||
$dates = $this->getMonthDates($month, $year);
|
$dates = $this->getMonthDates($month, $year);
|
||||||
$this->dates = $dates;
|
$this->dates = $dates;
|
||||||
|
|
||||||
@@ -682,8 +632,10 @@ class ProductionTargetPlan extends Component
|
|||||||
->where('production_plans.plant_id', $plantId)
|
->where('production_plans.plant_id', $plantId)
|
||||||
->where('production_plans.line_id', $lineId)
|
->where('production_plans.line_id', $lineId)
|
||||||
->where('items.category', $category)
|
->where('items.category', $category)
|
||||||
->whereMonth('production_plans.created_at', $month)
|
// ->whereMonth('production_plans.created_at', $month)
|
||||||
->whereYear('production_plans.created_at', $year)
|
// ->whereYear('production_plans.created_at', $year)
|
||||||
|
->where('production_plans.created_at', '>=', $startDate)
|
||||||
|
->where('production_plans.created_at', '<', $endDate)
|
||||||
->select(
|
->select(
|
||||||
'production_plans.item_id',
|
'production_plans.item_id',
|
||||||
'production_plans.plant_id',
|
'production_plans.plant_id',
|
||||||
@@ -726,8 +678,10 @@ class ProductionTargetPlan extends Component
|
|||||||
->where('items.category', $category)
|
->where('items.category', $category)
|
||||||
->where('quality_validations.plant_id', $plantId)
|
->where('quality_validations.plant_id', $plantId)
|
||||||
->where('quality_validations.line_id', $lineId)
|
->where('quality_validations.line_id', $lineId)
|
||||||
->whereMonth('quality_validations.created_at', $month)
|
->where('quality_validations.created_at', '>=', $startDate)
|
||||||
->whereYear('quality_validations.created_at', $year)
|
->where('quality_validations.created_at', '<', $endDate)
|
||||||
|
// ->whereMonth('quality_validations.created_at', $month)
|
||||||
|
// ->whereYear('quality_validations.created_at', $year)
|
||||||
->groupBy(
|
->groupBy(
|
||||||
'quality_validations.plant_id',
|
'quality_validations.plant_id',
|
||||||
'quality_validations.line_id',
|
'quality_validations.line_id',
|
||||||
@@ -758,7 +712,7 @@ class ProductionTargetPlan extends Component
|
|||||||
$dailyHourlyQuantity = (float) ($row['hourly_quantity'] ?? 0);
|
$dailyHourlyQuantity = (float) ($row['hourly_quantity'] ?? 0);
|
||||||
|
|
||||||
$row['category'] = $row['category'] ?? '-';
|
$row['category'] = $row['category'] ?? '-';
|
||||||
$row['daily_hourly_quantity'] = [];
|
// $row['daily_hourly_quantity'] = [];
|
||||||
$row['daily_target_dynamic'] = [];
|
$row['daily_target_dynamic'] = [];
|
||||||
$row['produced_quantity'] = [];
|
$row['produced_quantity'] = [];
|
||||||
|
|
||||||
@@ -767,7 +721,7 @@ class ProductionTargetPlan extends Component
|
|||||||
foreach ($dates as $date) {
|
foreach ($dates as $date) {
|
||||||
if (in_array($date, $leaveDates)) {
|
if (in_array($date, $leaveDates)) {
|
||||||
|
|
||||||
$row['daily_hourly_quantity'][$date] = '-';
|
// $row['daily_hourly_quantity'][$date] = '-';
|
||||||
$row['daily_target_dynamic'][$date] = '-';
|
$row['daily_target_dynamic'][$date] = '-';
|
||||||
$row['produced_quantity'][$date] = '-';
|
$row['produced_quantity'][$date] = '-';
|
||||||
|
|
||||||
@@ -783,7 +737,7 @@ class ProductionTargetPlan extends Component
|
|||||||
|
|
||||||
$row['daily_target_dynamic'][$date] = $todayTarget;
|
$row['daily_target_dynamic'][$date] = $todayTarget;
|
||||||
$row['produced_quantity'][$date] = $producedQty;
|
$row['produced_quantity'][$date] = $producedQty;
|
||||||
$row['daily_hourly_quantity'][$date] = $dailyHourlyQuantity * 22.5;
|
// $row['daily_hourly_quantity'][$date] = $dailyHourlyQuantity * 22.5;
|
||||||
|
|
||||||
$pendingQty = max(
|
$pendingQty = max(
|
||||||
0,
|
0,
|
||||||
@@ -804,8 +758,10 @@ class ProductionTargetPlan extends Component
|
|||||||
|
|
||||||
$this->monthlyActualQuantity = QualityValidation::where('plant_id', $plantId)
|
$this->monthlyActualQuantity = QualityValidation::where('plant_id', $plantId)
|
||||||
->where('line_id', $lineId)
|
->where('line_id', $lineId)
|
||||||
->whereYear('created_at', $year)
|
->where('created_at', '>=', $startDate)
|
||||||
->whereMonth('created_at', $month)
|
->where('created_at', '<', $endDate)
|
||||||
|
// ->whereYear('created_at', $year)
|
||||||
|
// ->whereMonth('created_at', $month)
|
||||||
->count();
|
->count();
|
||||||
|
|
||||||
$this->efficiency = $this->monthlyRecords > 0
|
$this->efficiency = $this->monthlyRecords > 0
|
||||||
|
|||||||
Reference in New Issue
Block a user