Changed logic in production target plan #1088
@@ -222,28 +222,59 @@ class ProductionTargetPlan extends Component
|
|||||||
|
|
||||||
$this->leaveDates = $leaveDates;
|
$this->leaveDates = $leaveDates;
|
||||||
|
|
||||||
|
// $producedData = QualityValidation::selectRaw("
|
||||||
|
// plant_id,
|
||||||
|
// line_id,
|
||||||
|
// sticker_master_id,
|
||||||
|
// DATE(created_at) as prod_date,
|
||||||
|
// COUNT(*) as total_qty
|
||||||
|
// ")
|
||||||
|
// ->where('plant_id', $plantId)
|
||||||
|
// ->where('line_id', $lineId)
|
||||||
|
// ->whereMonth('created_at', $month)
|
||||||
|
// ->whereYear('created_at', $year)
|
||||||
|
// ->when($category, function ($query) use ($category) {
|
||||||
|
// $query->whereHas('item', function ($q) use ($category) {
|
||||||
|
// $q->where('category', $category);
|
||||||
|
// });
|
||||||
|
// })
|
||||||
|
// ->groupBy('plant_id', 'line_id', 'sticker_master_id', DB::raw('DATE(created_at)'))
|
||||||
|
// ->get()
|
||||||
|
// ->groupBy(fn($row) =>
|
||||||
|
// $row->plant_id . '_' . $row->line_id . '_' . $row->item_id
|
||||||
|
// )
|
||||||
|
// ->map(fn($group) => $group->keyBy('prod_date'));
|
||||||
|
|
||||||
$producedData = QualityValidation::selectRaw("
|
$producedData = QualityValidation::selectRaw("
|
||||||
plant_id,
|
quality_validations.plant_id,
|
||||||
line_id,
|
quality_validations.line_id,
|
||||||
item_id,
|
quality_validations.sticker_master_id,
|
||||||
DATE(created_at) as prod_date,
|
sticker_masters.item_id,
|
||||||
COUNT(*) as total_qty
|
DATE(quality_validations.created_at) as prod_date,
|
||||||
")
|
COUNT(*) as total_qty
|
||||||
->where('plant_id', $plantId)
|
")
|
||||||
->where('line_id', $lineId)
|
->join('sticker_masters', 'sticker_masters.id', '=', 'quality_validations.sticker_master_id')
|
||||||
->whereMonth('created_at', $month)
|
->where('quality_validations.plant_id', $plantId)
|
||||||
->whereYear('created_at', $year)
|
->where('quality_validations.line_id', $lineId)
|
||||||
->when($category, function ($query) use ($category) {
|
->whereMonth('quality_validations.created_at', $month)
|
||||||
$query->whereHas('item', function ($q) use ($category) {
|
->whereYear('quality_validations.created_at', $year)
|
||||||
$q->where('category', $category);
|
->when($category, function ($query) use ($category) {
|
||||||
});
|
$query->whereHas('item', function ($q) use ($category) {
|
||||||
})
|
$q->where('category', $category);
|
||||||
->groupBy('plant_id', 'line_id', 'item_id', DB::raw('DATE(created_at)'))
|
});
|
||||||
->get()
|
})
|
||||||
->groupBy(fn($row) =>
|
->groupBy(
|
||||||
$row->plant_id . '_' . $row->line_id . '_' . $row->item_id
|
'quality_validations.plant_id',
|
||||||
)
|
'quality_validations.line_id',
|
||||||
->map(fn($group) => $group->keyBy('prod_date'));
|
'quality_validations.sticker_master_id',
|
||||||
|
'sticker_masters.item_id',
|
||||||
|
DB::raw('DATE(quality_validations.created_at)')
|
||||||
|
)
|
||||||
|
->get()
|
||||||
|
->groupBy(fn($row) =>
|
||||||
|
$row->plant_id . '_' . $row->line_id . '_' . $row->item_id
|
||||||
|
)
|
||||||
|
->map(fn($group) => $group->keyBy('prod_date'));
|
||||||
|
|
||||||
|
|
||||||
$records = [];
|
$records = [];
|
||||||
|
|||||||
Reference in New Issue
Block a user