Added production non planned livewire page
Some checks failed
Gemini PR Review / Gemini PR Review (pull_request) Failing after 1m13s
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (pull_request) Successful in 16s
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 1m44s
Laravel Pint / pint (pull_request) Successful in 2m47s
Laravel Larastan / larastan (pull_request) Failing after 8m1s
Some checks failed
Gemini PR Review / Gemini PR Review (pull_request) Failing after 1m13s
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (pull_request) Successful in 16s
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 1m44s
Laravel Pint / pint (pull_request) Successful in 2m47s
Laravel Larastan / larastan (pull_request) Failing after 8m1s
This commit is contained in:
278
app/Livewire/ProductionNonPlanned.php
Normal file
278
app/Livewire/ProductionNonPlanned.php
Normal file
@@ -0,0 +1,278 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Livewire;
|
||||||
|
|
||||||
|
use App\Models\ProductionPlan;
|
||||||
|
use App\Models\QualityValidation;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Livewire\Component;
|
||||||
|
|
||||||
|
class ProductionNonPlanned extends Component
|
||||||
|
{
|
||||||
|
public $plantId, $lineId, $month, $year, $category, $date;
|
||||||
|
|
||||||
|
public $records = [];
|
||||||
|
|
||||||
|
public $nonPlannedRecords = [];
|
||||||
|
|
||||||
|
public int $nonPlannedCount = 0;
|
||||||
|
|
||||||
|
public int $nonPlannedQuantity = 0;
|
||||||
|
|
||||||
|
// public $dates = [];
|
||||||
|
|
||||||
|
public $monthlyRecords = [];
|
||||||
|
|
||||||
|
public $efficiency = [];
|
||||||
|
|
||||||
|
public $monthlyActualQuantity = [];
|
||||||
|
|
||||||
|
public $leaveDates = [];
|
||||||
|
|
||||||
|
public $dates;
|
||||||
|
|
||||||
|
public $productionPlanDates = '';
|
||||||
|
|
||||||
|
|
||||||
|
protected $listeners = [
|
||||||
|
'loadData' => 'loadProductionData',
|
||||||
|
'loadDataCategory' => 'loadProductionCategoryData'
|
||||||
|
];
|
||||||
|
|
||||||
|
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'
|
||||||
|
)
|
||||||
|
->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("
|
||||||
|
sticker_masters.item_id,
|
||||||
|
items.code as item_code,
|
||||||
|
items.description as item_description,
|
||||||
|
items.category as item_category,
|
||||||
|
COUNT(*) as total_qty
|
||||||
|
")
|
||||||
|
->groupBy(
|
||||||
|
'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 loadProductionCategoryData($date, $plantId, $lineId, $category)
|
||||||
|
{
|
||||||
|
$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)
|
||||||
|
->where('items.category', $category)
|
||||||
|
->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'
|
||||||
|
)
|
||||||
|
->where('quality_validations.plant_id', $plantId)
|
||||||
|
->where('quality_validations.line_id', $lineId)
|
||||||
|
->where('items.category', $category)
|
||||||
|
->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("
|
||||||
|
sticker_masters.item_id,
|
||||||
|
items.code as item_code,
|
||||||
|
items.description as item_description,
|
||||||
|
items.category as item_category,
|
||||||
|
COUNT(*) as total_qty
|
||||||
|
")
|
||||||
|
->groupBy(
|
||||||
|
'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 render()
|
||||||
|
{
|
||||||
|
// return view('livewire.production-non-planned');
|
||||||
|
return view('livewire.production-non-planned', [
|
||||||
|
'records' => $this->records,
|
||||||
|
'monthlyRecords' => $this->monthlyRecords,
|
||||||
|
'monthlyActualRecords' => $this->monthlyActualQuantity,
|
||||||
|
'monthlyEfficiency' => $this->efficiency,
|
||||||
|
'dates' => $this->dates,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
30
resources/views/livewire/production-non-planned.blade.php
Normal file
30
resources/views/livewire/production-non-planned.blade.php
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
<div class="p-4">
|
||||||
|
<div class="p-4 mt-6">
|
||||||
|
<h2 class="text-lg font-bold mb-4 text-gray-700 uppercase tracking-wider">
|
||||||
|
NON PLANNED PRODUCTION:
|
||||||
|
</h2>
|
||||||
|
|
||||||
|
<div class="overflow-x-auto rounded-lg shadow">
|
||||||
|
<table class="w-full divide-y divide-gray-200 text-sm text-center">
|
||||||
|
<thead class="bg-gray-100 text-sm font-semibold uppercase text-gray-700">
|
||||||
|
<tr>
|
||||||
|
<th class="border px-4 py-2">No</th>
|
||||||
|
<th class="border px-4 py-2">Item Code</th>
|
||||||
|
<th class="border px-4 py-2">Category</th>
|
||||||
|
<th class="border px-4 py-2">Non Planned Quantity</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
@foreach ($nonPlannedRecords as $index => $item)
|
||||||
|
<tr>
|
||||||
|
<td class="border px-4 py-2">{{ $index + 1 }}</td>
|
||||||
|
<td class="border px-4 py-2">{{ $item['item_code'] }}</td>
|
||||||
|
<td class="border px-4 py-2">{{ $item['item_category'] }}</td>
|
||||||
|
<td class="border px-4 py-2">{{ $item['total_qty'] }}</td>
|
||||||
|
</tr>
|
||||||
|
@endforeach
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
Reference in New Issue
Block a user