Changed logic in production non planned page
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 18s
Gemini PR Review / Gemini PR Review (pull_request) Failing after 20s
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (pull_request) Successful in 16s
Laravel Pint / pint (pull_request) Successful in 4m26s
Laravel Larastan / larastan (pull_request) Failing after 5m52s
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 18s
Gemini PR Review / Gemini PR Review (pull_request) Failing after 20s
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (pull_request) Successful in 16s
Laravel Pint / pint (pull_request) Successful in 4m26s
Laravel Larastan / larastan (pull_request) Failing after 5m52s
This commit is contained in:
@@ -4,6 +4,8 @@ namespace App\Livewire;
|
|||||||
|
|
||||||
use App\Exports\ProductionNonPlanExport;
|
use App\Exports\ProductionNonPlanExport;
|
||||||
use App\Models\ProductionPlan;
|
use App\Models\ProductionPlan;
|
||||||
|
use App\Models\ProductionQuantity;
|
||||||
|
use App\Models\Line;
|
||||||
use App\Models\QualityValidation;
|
use App\Models\QualityValidation;
|
||||||
use Illuminate\Support\Carbon;
|
use Illuminate\Support\Carbon;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
@@ -41,6 +43,133 @@ class ProductionNonPlanned extends Component
|
|||||||
'loadDataExport' => 'exportNonPlannedData'
|
'loadDataExport' => 'exportNonPlannedData'
|
||||||
];
|
];
|
||||||
|
|
||||||
|
// public function loadProductionData($date, $plantId, $lineId)
|
||||||
|
// {
|
||||||
|
// $this->dates = [];
|
||||||
|
// $this->leaveDates = [];
|
||||||
|
|
||||||
|
// $this->nonPlannedRecords = [];
|
||||||
|
// $this->nonPlannedCount = 0;
|
||||||
|
// $this->nonPlannedQuantity = 0;
|
||||||
|
|
||||||
|
// if (!$plantId || !$lineId || !$date) {
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// $selectedDate = Carbon::parse($date);
|
||||||
|
|
||||||
|
// $date = $selectedDate->toDateString();
|
||||||
|
// $month = $selectedDate->month;
|
||||||
|
// $year = $selectedDate->year;
|
||||||
|
|
||||||
|
// $startDate = Carbon::parse($date)->setTime(8, 0, 0);
|
||||||
|
// $endDate = $startDate->copy()->addDay();
|
||||||
|
|
||||||
|
// $plans = ProductionPlan::query()
|
||||||
|
// ->join('items', 'items.id', '=', 'production_plans.item_id')
|
||||||
|
// ->join('lines', 'lines.id', '=', 'production_plans.line_id')
|
||||||
|
// ->join('plants', 'plants.id', '=', 'production_plans.plant_id')
|
||||||
|
// ->where('production_plans.plant_id', $plantId)
|
||||||
|
// ->where('production_plans.line_id', $lineId)
|
||||||
|
// ->whereMonth('production_plans.created_at', $month)
|
||||||
|
// ->whereYear('production_plans.created_at', $year)
|
||||||
|
// ->select(
|
||||||
|
// 'production_plans.item_id',
|
||||||
|
// 'production_plans.plant_id',
|
||||||
|
// 'production_plans.line_id',
|
||||||
|
// 'production_plans.plan_quantity',
|
||||||
|
// 'production_plans.working_days',
|
||||||
|
// 'production_plans.leave_dates',
|
||||||
|
// 'items.code as item_code',
|
||||||
|
// 'items.category as category',
|
||||||
|
// 'items.description as item_description',
|
||||||
|
// 'items.hourly_quantity as hourly_quantity',
|
||||||
|
// 'lines.name as line_name',
|
||||||
|
// 'plants.name as plant_name'
|
||||||
|
// )
|
||||||
|
// ->get();
|
||||||
|
|
||||||
|
// $plannedItemIds = $plans
|
||||||
|
// ->pluck('item_id')
|
||||||
|
// ->filter(fn ($id) => $id != null)
|
||||||
|
// ->unique()
|
||||||
|
// ->values();
|
||||||
|
|
||||||
|
// $leaveDates = [];
|
||||||
|
|
||||||
|
// if ($plans->isNotEmpty() && $plans->first()->leave_dates) {
|
||||||
|
// $leaveDates = array_map(
|
||||||
|
// 'trim',
|
||||||
|
// explode(',', $plans->first()->leave_dates)
|
||||||
|
// );
|
||||||
|
// }
|
||||||
|
|
||||||
|
// $this->leaveDates = $leaveDates;
|
||||||
|
|
||||||
|
// $nonPlannedQuery = QualityValidation::query()
|
||||||
|
// ->join(
|
||||||
|
// 'sticker_masters',
|
||||||
|
// 'sticker_masters.id',
|
||||||
|
// '=',
|
||||||
|
// 'quality_validations.sticker_master_id'
|
||||||
|
// )
|
||||||
|
// ->join(
|
||||||
|
// 'items',
|
||||||
|
// 'items.id',
|
||||||
|
// '=',
|
||||||
|
// 'sticker_masters.item_id'
|
||||||
|
// )
|
||||||
|
// ->join(
|
||||||
|
// 'plants',
|
||||||
|
// 'plants.id',
|
||||||
|
// '=',
|
||||||
|
// 'quality_validations.plant_id'
|
||||||
|
// )
|
||||||
|
// ->join(
|
||||||
|
// 'lines',
|
||||||
|
// 'lines.id',
|
||||||
|
// '=',
|
||||||
|
// 'quality_validations.line_id'
|
||||||
|
// )
|
||||||
|
// ->where('quality_validations.plant_id', $plantId)
|
||||||
|
// ->where('quality_validations.line_id', $lineId)
|
||||||
|
// ->where('quality_validations.created_at', '>=', $startDate)
|
||||||
|
// ->where('quality_validations.created_at', '<', $endDate);
|
||||||
|
|
||||||
|
// if ($plannedItemIds->isNotEmpty()) {
|
||||||
|
// $nonPlannedQuery->whereNotIn(
|
||||||
|
// 'sticker_masters.item_id',
|
||||||
|
// $plannedItemIds
|
||||||
|
// );
|
||||||
|
// }
|
||||||
|
|
||||||
|
// $nonPlannedData = $nonPlannedQuery
|
||||||
|
// ->selectRaw("
|
||||||
|
// plants.name as plant_name,
|
||||||
|
// lines.name as line_name,
|
||||||
|
// sticker_masters.item_id,
|
||||||
|
// items.code as item_code,
|
||||||
|
// items.description as item_description,
|
||||||
|
// items.category as item_category,
|
||||||
|
// COUNT(*) as total_qty
|
||||||
|
// ")
|
||||||
|
// ->groupBy(
|
||||||
|
// 'plants.name',
|
||||||
|
// 'lines.name',
|
||||||
|
// 'sticker_masters.item_id',
|
||||||
|
// 'items.code',
|
||||||
|
// 'items.description',
|
||||||
|
// 'items.category'
|
||||||
|
// )
|
||||||
|
// ->get();
|
||||||
|
|
||||||
|
// $this->nonPlannedRecords = $nonPlannedData->toArray();
|
||||||
|
|
||||||
|
// $this->nonPlannedCount = $nonPlannedData->count();
|
||||||
|
|
||||||
|
// $this->nonPlannedQuantity = (int) $nonPlannedData->sum('total_qty');
|
||||||
|
// }
|
||||||
|
|
||||||
public function loadProductionData($date, $plantId, $lineId)
|
public function loadProductionData($date, $plantId, $lineId)
|
||||||
{
|
{
|
||||||
$this->dates = [];
|
$this->dates = [];
|
||||||
@@ -63,6 +192,7 @@ class ProductionNonPlanned extends Component
|
|||||||
$startDate = Carbon::parse($date)->setTime(8, 0, 0);
|
$startDate = Carbon::parse($date)->setTime(8, 0, 0);
|
||||||
$endDate = $startDate->copy()->addDay();
|
$endDate = $startDate->copy()->addDay();
|
||||||
|
|
||||||
|
// Get production plans
|
||||||
$plans = ProductionPlan::query()
|
$plans = ProductionPlan::query()
|
||||||
->join('items', 'items.id', '=', 'production_plans.item_id')
|
->join('items', 'items.id', '=', 'production_plans.item_id')
|
||||||
->join('lines', 'lines.id', '=', 'production_plans.line_id')
|
->join('lines', 'lines.id', '=', 'production_plans.line_id')
|
||||||
@@ -87,12 +217,20 @@ class ProductionNonPlanned extends Component
|
|||||||
)
|
)
|
||||||
->get();
|
->get();
|
||||||
|
|
||||||
|
// Get line details
|
||||||
|
$line = Line::find($lineId);
|
||||||
|
|
||||||
|
$lineName = $line?->name;
|
||||||
|
$lineType = $line?->type;
|
||||||
|
|
||||||
|
// Get planned item IDs
|
||||||
$plannedItemIds = $plans
|
$plannedItemIds = $plans
|
||||||
->pluck('item_id')
|
->pluck('item_id')
|
||||||
->filter(fn ($id) => $id != null)
|
->filter()
|
||||||
->unique()
|
->unique()
|
||||||
->values();
|
->values();
|
||||||
|
|
||||||
|
// Get leave dates
|
||||||
$leaveDates = [];
|
$leaveDates = [];
|
||||||
|
|
||||||
if ($plans->isNotEmpty() && $plans->first()->leave_dates) {
|
if ($plans->isNotEmpty() && $plans->first()->leave_dates) {
|
||||||
@@ -104,63 +242,121 @@ class ProductionNonPlanned extends Component
|
|||||||
|
|
||||||
$this->leaveDates = $leaveDates;
|
$this->leaveDates = $leaveDates;
|
||||||
|
|
||||||
$nonPlannedQuery = QualityValidation::query()
|
// Fetch non-planned production based on line type
|
||||||
->join(
|
if ($lineType === 'Base FG Line') {
|
||||||
'sticker_masters',
|
|
||||||
'sticker_masters.id',
|
|
||||||
'=',
|
|
||||||
'quality_validations.sticker_master_id'
|
|
||||||
)
|
|
||||||
->join(
|
|
||||||
'items',
|
|
||||||
'items.id',
|
|
||||||
'=',
|
|
||||||
'sticker_masters.item_id'
|
|
||||||
)
|
|
||||||
->join(
|
|
||||||
'plants',
|
|
||||||
'plants.id',
|
|
||||||
'=',
|
|
||||||
'quality_validations.plant_id'
|
|
||||||
)
|
|
||||||
->join(
|
|
||||||
'lines',
|
|
||||||
'lines.id',
|
|
||||||
'=',
|
|
||||||
'quality_validations.line_id'
|
|
||||||
)
|
|
||||||
->where('quality_validations.plant_id', $plantId)
|
|
||||||
->where('quality_validations.line_id', $lineId)
|
|
||||||
->where('quality_validations.created_at', '>=', $startDate)
|
|
||||||
->where('quality_validations.created_at', '<', $endDate);
|
|
||||||
|
|
||||||
if ($plannedItemIds->isNotEmpty()) {
|
$nonPlannedQuery = ProductionQuantity::query()
|
||||||
$nonPlannedQuery->whereNotIn(
|
->join(
|
||||||
'sticker_masters.item_id',
|
'items',
|
||||||
$plannedItemIds
|
'items.id',
|
||||||
);
|
'=',
|
||||||
|
'production_quantities.item_id'
|
||||||
|
)
|
||||||
|
->join(
|
||||||
|
'plants',
|
||||||
|
'plants.id',
|
||||||
|
'=',
|
||||||
|
'production_quantities.plant_id'
|
||||||
|
)
|
||||||
|
->join(
|
||||||
|
'lines',
|
||||||
|
'lines.id',
|
||||||
|
'=',
|
||||||
|
'production_quantities.line_id'
|
||||||
|
)
|
||||||
|
->where('production_quantities.plant_id', $plantId)
|
||||||
|
->where('production_quantities.line_id', $lineId)
|
||||||
|
->where('production_quantities.created_at', '>=', $startDate)
|
||||||
|
->where('production_quantities.created_at', '<', $endDate);
|
||||||
|
|
||||||
|
if ($plannedItemIds->isNotEmpty()) {
|
||||||
|
$nonPlannedQuery->whereNotIn(
|
||||||
|
'production_quantities.item_id',
|
||||||
|
$plannedItemIds
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$nonPlannedData = $nonPlannedQuery
|
||||||
|
->selectRaw("
|
||||||
|
plants.name as plant_name,
|
||||||
|
lines.name as line_name,
|
||||||
|
production_quantities.item_id,
|
||||||
|
items.code as item_code,
|
||||||
|
items.description as item_description,
|
||||||
|
items.category as item_category,
|
||||||
|
COUNT(*) as total_qty
|
||||||
|
")
|
||||||
|
->groupBy(
|
||||||
|
'plants.name',
|
||||||
|
'lines.name',
|
||||||
|
'production_quantities.item_id',
|
||||||
|
'items.code',
|
||||||
|
'items.description',
|
||||||
|
'items.category'
|
||||||
|
)
|
||||||
|
->get();
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
$nonPlannedQuery = QualityValidation::query()
|
||||||
|
->join(
|
||||||
|
'sticker_masters',
|
||||||
|
'sticker_masters.id',
|
||||||
|
'=',
|
||||||
|
'quality_validations.sticker_master_id'
|
||||||
|
)
|
||||||
|
->join(
|
||||||
|
'items',
|
||||||
|
'items.id',
|
||||||
|
'=',
|
||||||
|
'sticker_masters.item_id'
|
||||||
|
)
|
||||||
|
->join(
|
||||||
|
'plants',
|
||||||
|
'plants.id',
|
||||||
|
'=',
|
||||||
|
'quality_validations.plant_id'
|
||||||
|
)
|
||||||
|
->join(
|
||||||
|
'lines',
|
||||||
|
'lines.id',
|
||||||
|
'=',
|
||||||
|
'quality_validations.line_id'
|
||||||
|
)
|
||||||
|
->where('quality_validations.plant_id', $plantId)
|
||||||
|
->where('quality_validations.line_id', $lineId)
|
||||||
|
->where('quality_validations.created_at', '>=', $startDate)
|
||||||
|
->where('quality_validations.created_at', '<', $endDate);
|
||||||
|
|
||||||
|
if ($plannedItemIds->isNotEmpty()) {
|
||||||
|
$nonPlannedQuery->whereNotIn(
|
||||||
|
'sticker_masters.item_id',
|
||||||
|
$plannedItemIds
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$nonPlannedData = $nonPlannedQuery
|
||||||
|
->selectRaw("
|
||||||
|
plants.name as plant_name,
|
||||||
|
lines.name as line_name,
|
||||||
|
sticker_masters.item_id,
|
||||||
|
items.code as item_code,
|
||||||
|
items.description as item_description,
|
||||||
|
items.category as item_category,
|
||||||
|
COUNT(*) as total_qty
|
||||||
|
")
|
||||||
|
->groupBy(
|
||||||
|
'plants.name',
|
||||||
|
'lines.name',
|
||||||
|
'sticker_masters.item_id',
|
||||||
|
'items.code',
|
||||||
|
'items.description',
|
||||||
|
'items.category'
|
||||||
|
)
|
||||||
|
->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
$nonPlannedData = $nonPlannedQuery
|
// Assign non-planned records
|
||||||
->selectRaw("
|
|
||||||
plants.name as plant_name,
|
|
||||||
lines.name as line_name,
|
|
||||||
sticker_masters.item_id,
|
|
||||||
items.code as item_code,
|
|
||||||
items.description as item_description,
|
|
||||||
items.category as item_category,
|
|
||||||
COUNT(*) as total_qty
|
|
||||||
")
|
|
||||||
->groupBy(
|
|
||||||
'plants.name',
|
|
||||||
'lines.name',
|
|
||||||
'sticker_masters.item_id',
|
|
||||||
'items.code',
|
|
||||||
'items.description',
|
|
||||||
'items.category'
|
|
||||||
)
|
|
||||||
->get();
|
|
||||||
|
|
||||||
$this->nonPlannedRecords = $nonPlannedData->toArray();
|
$this->nonPlannedRecords = $nonPlannedData->toArray();
|
||||||
|
|
||||||
$this->nonPlannedCount = $nonPlannedData->count();
|
$this->nonPlannedCount = $nonPlannedData->count();
|
||||||
@@ -168,6 +364,7 @@ class ProductionNonPlanned extends Component
|
|||||||
$this->nonPlannedQuantity = (int) $nonPlannedData->sum('total_qty');
|
$this->nonPlannedQuantity = (int) $nonPlannedData->sum('total_qty');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function loadProductionCategoryData($date, $plantId, $lineId, $category)
|
public function loadProductionCategoryData($date, $plantId, $lineId, $category)
|
||||||
{
|
{
|
||||||
$this->dates = [];
|
$this->dates = [];
|
||||||
|
|||||||
Reference in New Issue
Block a user