Compare commits
172 Commits
ranjith-de
...
a2958c999c
| Author | SHA1 | Date | |
|---|---|---|---|
| a2958c999c | |||
| 051616da25 | |||
| 8cf1063e2a | |||
| b7ec4f4c1a | |||
| f26209f3db | |||
| 23914944ca | |||
| e4b951ff77 | |||
| 2c8efe351b | |||
| f63ec1feee | |||
| c63b24e249 | |||
| 549c22f0e5 | |||
| bf055b7672 | |||
| 2eaf01bec8 | |||
| b6478b5feb | |||
| 6d32be91f7 | |||
| 525d951df7 | |||
| 1e208bfd7f | |||
| 8b3a65c4f3 | |||
| 089678dfb3 | |||
| afef84e0c7 | |||
| 7c3845ce7c | |||
| 97c38d9554 | |||
| 2571d0ac57 | |||
| c2b7c43bf0 | |||
| d993b64906 | |||
| 0c9d5a7964 | |||
| aa0b94a975 | |||
| ae0bc9dcd6 | |||
| 5d8e5d13f5 | |||
| 6747abb2db | |||
| d27ab1d98e | |||
| 0f38a9ff1b | |||
| 667682201a | |||
| e20caa54c7 | |||
| efa6410cd9 | |||
| eae7e76ea4 | |||
| 30e4415af9 | |||
| 40014570c9 | |||
| c5e45cd6dd | |||
| 2d40e51e78 | |||
| 98a3c5bc8e | |||
| e969e54f59 | |||
| 6bad120e70 | |||
| 02dea13222 | |||
| 07c642e3bd | |||
| 33e3b247b3 | |||
| 0bcc8d2113 | |||
| ff607695bc | |||
| 006857ec89 | |||
| 107e8cf505 | |||
| 49d5dfb664 | |||
| cf097255a0 | |||
| 27223612d3 | |||
| 22de1ba081 | |||
| d7c2fc3ff9 | |||
| 29a7a66ff4 | |||
| 5f87467dbf | |||
| c01df679a0 | |||
| 4b653f6bb0 | |||
| a877623567 | |||
| e8a6e88eac | |||
| ab49a0fc7c | |||
| e320e4486f | |||
| 4b5cdef55a | |||
| 82a022d3b4 | |||
| 7ec116ca0b | |||
| 048f069dd7 | |||
| b83e26c9d6 | |||
| 945d50c504 | |||
| ae0758a9c0 | |||
| 238d7bdfa7 | |||
| be1e7f36b2 | |||
| 165b7e6a77 | |||
| d0269a646c | |||
| 3eccb1c7d5 | |||
| 83888054e9 | |||
| 22e2fbd25d | |||
| d5d1243d5c | |||
| 2d2d3ac8c5 | |||
| 6e9e57682c | |||
| 3fa6ca578b | |||
| bc43d5ddf1 | |||
| 201c55121e | |||
| aa91bd80de | |||
| d4fc6f6f33 | |||
| dade6a3c0c | |||
| d8aea01b26 | |||
| a690faf6d7 | |||
| dd6cbd92a2 | |||
| b54a9af78b | |||
| 57f059aca8 | |||
| 5688e93862 | |||
| 8b556d3c9c | |||
| 091aaaa0d7 | |||
| 9dd5d04b3c | |||
| 4ac3eb4f2f | |||
| bcd493901c | |||
| af3259a842 | |||
| 6f41238b1e | |||
| 8779e66a18 | |||
| e0384780dc | |||
| afbbfe2aca | |||
| 4fb04c9fa8 | |||
| 656c58999c | |||
| 102bc62805 | |||
| ef1ad62749 | |||
| 1e0193e6c9 | |||
| 18c203552c | |||
| 61190edcce | |||
| 62774aec0f | |||
| 44e58d2d78 | |||
| 3ac4f88155 | |||
| 818f8a3e08 | |||
| 86798212d0 | |||
| 837bd58177 | |||
| d8b29ba000 | |||
| d1db3e0dad | |||
| f274de00e1 | |||
| f9c6405b61 | |||
| 7ec34a04fc | |||
| 9256e1ed12 | |||
| b334ba60fa | |||
| 8c81c140d1 | |||
| 5ff8acac74 | |||
| 2f2bab37d4 | |||
| a8d72923ae | |||
| e39ab23142 | |||
| 2373e1d427 | |||
| baa165e285 | |||
| 53e671d612 | |||
| 58be303cfe | |||
| a1c39c5f0e | |||
| 41e8c04b9d | |||
| 6a30fbc8f2 | |||
| 9e57461d3a | |||
| ab5a6b94c9 | |||
| 84b78ea0c1 | |||
| 5e46b080c5 | |||
| 17f337e8db | |||
| 2781d57e3f | |||
| 5628e8abd4 | |||
| e56733ce44 | |||
| b3f32f6813 | |||
| b2937ccfa8 | |||
| 026e4982b8 | |||
| 6478bc3722 | |||
| 1ab7ed2da9 | |||
| 9ecd04f0e3 | |||
| 53179ea538 | |||
| b4e24c581e | |||
| 4938fa62a7 | |||
| 01f6288c63 | |||
| c9c7c38088 | |||
| 90cfe9ef0d | |||
| aa806f2fe3 | |||
| 0eb6f76ca6 | |||
| 73366ccd70 | |||
| acbecedce9 | |||
| 614d89932b | |||
| c839c6fdbc | |||
| d9445a9d4b | |||
| 50476c8a2c | |||
| c57cfe71ca | |||
| 96c08c34c1 | |||
| 19cf7c8edd | |||
| 66086dd2d7 | |||
| 5da724c9a4 | |||
| 6b723c0929 | |||
| 8e20d0732d | |||
| 1d8fb1c9aa | |||
| 33bbce47ba | |||
| 860ff96134 |
@@ -1,62 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Exports;
|
|
||||||
|
|
||||||
use Maatwebsite\Excel\Concerns\FromCollection;
|
|
||||||
use Maatwebsite\Excel\Concerns\FromArray;
|
|
||||||
use Maatwebsite\Excel\Concerns\WithHeadings;
|
|
||||||
use Maatwebsite\Excel\Concerns\WithMapping;
|
|
||||||
|
|
||||||
class ProductionPlanExport implements FromArray, WithHeadings, WithMapping
|
|
||||||
{
|
|
||||||
|
|
||||||
protected array $data;
|
|
||||||
protected array $dates;
|
|
||||||
|
|
||||||
public function __construct(array $data, array $dates)
|
|
||||||
{
|
|
||||||
$this->data = $data;
|
|
||||||
$this->dates = $dates;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function array(): array
|
|
||||||
{
|
|
||||||
return $this->data;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function headings(): array
|
|
||||||
{
|
|
||||||
$headings = [
|
|
||||||
'Plant Name',
|
|
||||||
'Line Name',
|
|
||||||
'Item Code',
|
|
||||||
];
|
|
||||||
|
|
||||||
// Add dynamic headings for each date: Target / Produced
|
|
||||||
foreach ($this->dates as $date) {
|
|
||||||
$headings[] = $date . ' - Target Plan';
|
|
||||||
$headings[] = $date . ' - Produced Quantity';
|
|
||||||
}
|
|
||||||
|
|
||||||
return $headings;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function map($row): array
|
|
||||||
{
|
|
||||||
$mapped = [
|
|
||||||
$row['plant_name'] ?? '',
|
|
||||||
$row['line_name'] ?? '',
|
|
||||||
$row['item_code'] ?? '',
|
|
||||||
];
|
|
||||||
|
|
||||||
// Add daily target and produced quantity for each date
|
|
||||||
foreach ($this->dates as $date) {
|
|
||||||
// $mapped[] = $row['daily_target_dynamic'] ?? 0;
|
|
||||||
$mapped[] = $row['daily_target_dynamic'][$date] ?? '-';
|
|
||||||
$mapped[] = $row['produced_quantity'][$date] ?? 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $mapped;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -3,7 +3,6 @@
|
|||||||
namespace App\Filament\Imports;
|
namespace App\Filament\Imports;
|
||||||
|
|
||||||
use App\Models\Block;
|
use App\Models\Block;
|
||||||
use App\Models\Item;
|
|
||||||
use App\Models\Line;
|
use App\Models\Line;
|
||||||
use App\Models\Plant;
|
use App\Models\Plant;
|
||||||
use App\Models\ProductionPlan;
|
use App\Models\ProductionPlan;
|
||||||
@@ -24,33 +23,11 @@ class ProductionPlanImporter extends Importer
|
|||||||
public static function getColumns(): array
|
public static function getColumns(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
// ImportColumn::make('created_at')
|
ImportColumn::make('created_at')
|
||||||
// ->requiredMapping()
|
|
||||||
// ->exampleHeader('Created DateTime')
|
|
||||||
// ->example(['01-01-2025 08:00:00', '01-01-2025 19:30:00'])
|
|
||||||
// ->label('Created DateTime')
|
|
||||||
// ->rules(['required']),
|
|
||||||
|
|
||||||
ImportColumn::make('plant')
|
|
||||||
->requiredMapping()
|
->requiredMapping()
|
||||||
->exampleHeader('Plant Code')
|
->exampleHeader('Created DateTime')
|
||||||
->example(['1000', '1000'])
|
->example(['01-01-2025 08:00:00', '01-01-2025 19:30:00'])
|
||||||
->label('Plant Code')
|
->label('Created DateTime')
|
||||||
->relationship(resolveUsing: 'code')
|
|
||||||
->rules(['required']),
|
|
||||||
ImportColumn::make('line')
|
|
||||||
->requiredMapping()
|
|
||||||
->exampleHeader('Line Name')
|
|
||||||
->example(['4 inch pump line', '4 inch pump line'])
|
|
||||||
->label('Line Name')
|
|
||||||
->relationship(resolveUsing: 'name')
|
|
||||||
->rules(['required']),
|
|
||||||
ImportColumn::make('item')
|
|
||||||
->requiredMapping()
|
|
||||||
->exampleHeader('Item Code')
|
|
||||||
->example(['123456', '210987'])
|
|
||||||
->label('Item Code')
|
|
||||||
->relationship(resolveUsing: 'code')
|
|
||||||
->rules(['required']),
|
->rules(['required']),
|
||||||
ImportColumn::make('plan_quantity')
|
ImportColumn::make('plan_quantity')
|
||||||
->requiredMapping()
|
->requiredMapping()
|
||||||
@@ -59,111 +36,175 @@ class ProductionPlanImporter extends Importer
|
|||||||
->label('Plan Quantity')
|
->label('Plan Quantity')
|
||||||
->numeric()
|
->numeric()
|
||||||
->rules(['required', 'integer']),
|
->rules(['required', 'integer']),
|
||||||
// ImportColumn::make('production_quantity')
|
ImportColumn::make('production_quantity')
|
||||||
// ->requiredMapping()
|
->requiredMapping()
|
||||||
// ->exampleHeader('Production Quantity')
|
->exampleHeader('Production Quantity')
|
||||||
// ->example(['0', '0'])
|
->example(['0', '0'])
|
||||||
// ->label('Production Quantity')
|
->label('Production Quantity')
|
||||||
// ->numeric()
|
->numeric()
|
||||||
// ->rules(['required', 'integer']),
|
->rules(['required', 'integer']),
|
||||||
|
ImportColumn::make('line')
|
||||||
// ImportColumn::make('block_reference')
|
->requiredMapping()
|
||||||
// ->requiredMapping() // Or optionalMapping() if not always present
|
->exampleHeader('Line Name')
|
||||||
// ->exampleHeader('Block Name')
|
->example(['4 inch pump line', '4 inch pump line'])
|
||||||
// ->example(['Block A', 'Block A'])
|
->label('Line Name')
|
||||||
// ->label('Block Name')
|
->relationship(resolveUsing:'name')
|
||||||
// ->rules(['required']), // Or remove if not required
|
->rules(['required']),
|
||||||
// ImportColumn::make('shift')
|
ImportColumn::make('block_reference')
|
||||||
// ->requiredMapping()
|
->requiredMapping() // Or optionalMapping() if not always present
|
||||||
// ->exampleHeader('Shift Name') // ID
|
->exampleHeader('Block Name')
|
||||||
// ->example(['Day', 'Night']) // '2', '7'
|
->example(['Block A', 'Block A'])
|
||||||
// ->label('Shift Name') // ID
|
->label('Block Name')
|
||||||
// ->relationship(resolveUsing: 'name')
|
->rules(['required']), // Or remove if not required
|
||||||
// ->rules(['required']),
|
ImportColumn::make('shift')
|
||||||
|
->requiredMapping()
|
||||||
// ImportColumn::make('updated_at')
|
->exampleHeader('Shift Name') //ID
|
||||||
// ->requiredMapping()
|
->example(['Day', 'Night']) //'2', '7'
|
||||||
// ->exampleHeader('Updated DateTime')
|
->label('Shift Name') // ID
|
||||||
// ->example(['01-01-2025 08:00:00', '01-01-2025 19:30:00'])
|
->relationship(resolveUsing: 'name')
|
||||||
// ->label('Updated DateTime')
|
->rules(['required']),
|
||||||
// ->rules(['required']),
|
ImportColumn::make('plant')
|
||||||
// ImportColumn::make('operator_id')
|
->requiredMapping()
|
||||||
// ->requiredMapping()
|
->exampleHeader('Plant Name')
|
||||||
// ->exampleHeader('Operator ID')
|
->example(['Ransar Industries-I', 'Ransar Industries-I'])
|
||||||
// ->example([Filament::auth()->user()->name, Filament::auth()->user()->name])
|
->label('Plant Name')
|
||||||
// ->label('Operator ID')
|
->relationship(resolveUsing:'name')
|
||||||
// ->rules(['required']),
|
->rules(['required']),
|
||||||
|
ImportColumn::make('updated_at')
|
||||||
|
->requiredMapping()
|
||||||
|
->exampleHeader('Updated DateTime')
|
||||||
|
->example(['01-01-2025 08:00:00', '01-01-2025 19:30:00'])
|
||||||
|
->label('Updated DateTime')
|
||||||
|
->rules(['required']),
|
||||||
|
ImportColumn::make('operator_id')
|
||||||
|
->requiredMapping()
|
||||||
|
->exampleHeader('Operator ID')
|
||||||
|
->example([Filament::auth()->user()->name, Filament::auth()->user()->name])
|
||||||
|
->label('Operator ID')
|
||||||
|
->rules(['required']),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function resolveRecord(): ?ProductionPlan
|
public function resolveRecord(): ?ProductionPlan
|
||||||
{
|
{
|
||||||
$warnMsg = [];
|
$warnMsg = [];
|
||||||
$plantCod = $this->data['plant'];
|
$plant = Plant::where('name', $this->data['plant'])->first();
|
||||||
$itemCod = $this->data['item'];
|
|
||||||
$plant = null;
|
|
||||||
$line = null;
|
$line = null;
|
||||||
$block = null;
|
$block = null;
|
||||||
|
if (!$plant) {
|
||||||
if (Str::length($plantCod) < 4 || ! is_numeric($plantCod) || ! preg_match('/^[1-9]\d{3,}$/', $plantCod)) {
|
$warnMsg[] = "Plant not found";
|
||||||
$warnMsg[] = 'Invalid plant code found';
|
|
||||||
} else {
|
|
||||||
$plant = Plant::where('code', $plantCod)->first();
|
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
if (! $plant) {
|
|
||||||
$warnMsg[] = 'Plant not found';
|
|
||||||
} else {
|
|
||||||
$line = Line::where('name', $this->data['line'])->where('plant_id', $plant->id)->first();
|
$line = Line::where('name', $this->data['line'])->where('plant_id', $plant->id)->first();
|
||||||
|
//block_reference
|
||||||
|
$block = Block::where('name', $this->data['block_reference'])->where('plant_id', $plant->id)->first();
|
||||||
|
}
|
||||||
|
if (!$line) {
|
||||||
|
$warnMsg[] = "Line not found";
|
||||||
|
}
|
||||||
|
$shift = null;
|
||||||
|
if (!$block) {
|
||||||
|
$warnMsg[] = "Block not found";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$shift = Shift::where('name', $this->data['shift'])->where('plant_id', $plant->id)->where('block_id', $block->id)->first();
|
||||||
|
}
|
||||||
|
//$shift = Shift::where('id', $this->data['shift'])->where('plant_id', $plant->id)->first();
|
||||||
|
if (!$shift) {
|
||||||
|
$warnMsg[] = "Shift not found";
|
||||||
|
}
|
||||||
|
if (Str::length($this->data['plan_quantity']) < 0 || !is_numeric($this->data['plan_quantity']) || $this->data['plan_quantity'] <= 0) {
|
||||||
|
$warnMsg[] = "Invalid plan quantity found";
|
||||||
|
}
|
||||||
|
if (Str::length($this->data['production_quantity']) < 0 || !is_numeric($this->data['production_quantity']) || $this->data['production_quantity'] < 0) {
|
||||||
|
$warnMsg[] = "Invalid production quantity found";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! $line) {
|
$fromDate = $this->data['created_at'];
|
||||||
$warnMsg[] = 'Line not found';
|
$toDate = $this->data['updated_at'];
|
||||||
|
|
||||||
|
$formats = ['d-m-Y H:i', 'd-m-Y H:i:s']; //'07-05-2025 08:00' or '07-05-2025 08:00:00'
|
||||||
|
|
||||||
|
$fdateTime = null;
|
||||||
|
$tdateTime = null;
|
||||||
|
// Try parsing with multiple formats
|
||||||
|
foreach ($formats as $format) {
|
||||||
|
try {
|
||||||
|
$fdateTime = Carbon::createFromFormat($format, $fromDate);
|
||||||
|
break;
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
// Optionally collect warning messages
|
||||||
|
// $warnMsg[] = "Date format mismatch with format: $format";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Str::length($itemCod) < 6 || ! is_numeric($itemCod)) {
|
foreach ($formats as $format) {
|
||||||
$warnMsg[] = 'Invalid item code found';
|
try {
|
||||||
} else {
|
$tdateTime = Carbon::createFromFormat($format, $toDate);
|
||||||
$item = Item::where('code', $itemCod)->first();
|
break;
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
// Optionally collect warning messages
|
||||||
|
// $warnMsg[] = "Date format mismatch with format: $format";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! $item) {
|
$fDateOnly = '';
|
||||||
$warnMsg[] = 'Item not found';
|
if (!isset($fdateTime)) {
|
||||||
|
// throw new \Exception('Invalid date time format');
|
||||||
|
$warnMsg[] = "Invalid 'Created DateTime' format. Expected DD-MM-YYYY HH:MM:SS";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$fDateOnly = $fdateTime->toDateString();
|
||||||
|
}
|
||||||
|
if (!isset($tdateTime)) {
|
||||||
|
$warnMsg[] = "Invalid 'Updated DateTime' format. Expected DD-MM-YYYY HH:MM:SS";
|
||||||
}
|
}
|
||||||
|
|
||||||
$plantId = $plant->id;
|
if (isset($fdateTime) && isset($tdateTime)) {
|
||||||
|
if ($fdateTime->greaterThan($tdateTime)) {
|
||||||
$itemAgaPlant = Item::where('plant_id', $plantId)->where('code', $itemCod)->first();
|
$warnMsg[] = "'Created DataTime' is greater than 'Updated DateTime'.";
|
||||||
|
}
|
||||||
if(!$itemAgaPlant){
|
|
||||||
$warnMsg[] = 'Item not found against plant code';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$user = Filament::auth()->user();
|
// if (!$fromDate) {
|
||||||
|
// $warnMsg[] = "Invalid 'Created DateTime' format. Expected DD-MM-YYYY HH:MM:SS";
|
||||||
|
// }
|
||||||
|
// else if (!$toDate) {
|
||||||
|
// $warnMsg[] = "Invalid 'Updated DateTime' format. Expected DD-MM-YYYY HH:MM:SS";
|
||||||
|
// }
|
||||||
|
|
||||||
$operatorName = $user->name;
|
$user = User::where('name', $this->data['operator_id'])->first();
|
||||||
|
if (!$user) {
|
||||||
if (Str::length($this->data['plan_quantity']) < 0 || ! is_numeric($this->data['plan_quantity']) || $this->data['plan_quantity'] <= 0) {
|
$warnMsg[] = "Operator ID not found";
|
||||||
$warnMsg[] = 'Invalid plan quantity found';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! empty($warnMsg)) {
|
if (!empty($warnMsg)) {
|
||||||
throw new RowImportFailedException(implode(', ', $warnMsg));
|
throw new RowImportFailedException(implode(', ', $warnMsg));
|
||||||
} else {
|
}
|
||||||
|
else { //if (empty($warnMsg))
|
||||||
$productionPlan = ProductionPlan::where('plant_id', $plant->id)
|
$productionPlan = ProductionPlan::where('plant_id', $plant->id)
|
||||||
->where('line_id', $line->id)
|
->where('shift_id', $shift->id)
|
||||||
->where('item_id', $itemAgaPlant->id)
|
->where('line_id', $line->id)
|
||||||
->latest()
|
->whereDate('created_at', $fDateOnly)
|
||||||
->first();
|
// ->where('plan_quantity', $productionQuantity->plan_quantity)
|
||||||
|
->latest()
|
||||||
|
->first();
|
||||||
|
|
||||||
if ($productionPlan) {
|
if ($productionPlan) {
|
||||||
|
// if($productionPlan->production_quantity)
|
||||||
|
// {
|
||||||
|
// throw new RowImportFailedException("{$productionPlan->created_at}, {$productionPlan->production_quantity}");
|
||||||
|
// }
|
||||||
|
// $warnMsg[] = "Production plan already exist on '{$fDateOnly}'!";
|
||||||
|
|
||||||
$productionPlan->update([
|
$productionPlan->update([
|
||||||
'plan_quantity' => $this->data['plan_quantity'],
|
'plan_quantity' => $this->data['plan_quantity'],
|
||||||
'operator_id' => $operatorName,
|
// 'production_quantity' => $productionPlan->production_quantity,
|
||||||
|
// 'created_at' => $productionPlan->created_at,//$fdateTime->format('Y-m-d H:i:s'),
|
||||||
|
// 'updated_at' => $tdateTime->format('Y-m-d H:i:s'),
|
||||||
|
'operator_id' => $this->data['operator_id'],
|
||||||
]);
|
]);
|
||||||
$productionPlan->save();
|
$productionPlan->save();
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -171,23 +212,28 @@ class ProductionPlanImporter extends Importer
|
|||||||
ProductionPlan::updateOrCreate([
|
ProductionPlan::updateOrCreate([
|
||||||
'plant_id' => $plant->id,
|
'plant_id' => $plant->id,
|
||||||
'line_id' => $line->id,
|
'line_id' => $line->id,
|
||||||
'item_id' => $itemAgaPlant->id,
|
'shift_id' => $shift->id,
|
||||||
// 'shift_id' => $shift->id,
|
|
||||||
'plan_quantity' => $this->data['plan_quantity'],
|
'plan_quantity' => $this->data['plan_quantity'],
|
||||||
'created_at' =>now(),
|
'production_quantity' => $this->data['production_quantity'],
|
||||||
'updated_at' => now(),
|
'created_at' => $fdateTime->format('Y-m-d H:i:s'),//$this->data['created_at'],
|
||||||
'operator_id' => $operatorName,
|
'updated_at' => $tdateTime->format('Y-m-d H:i:s'),//$this->data['updated_at'],
|
||||||
|
'operator_id' => $this->data['operator_id'],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
// return ProductionPlan::firstOrNew([
|
||||||
|
// // Update existing records, matching them by `$this->data['column_name']`
|
||||||
|
// 'email' => $this->data['email'],
|
||||||
|
// ]);
|
||||||
|
|
||||||
|
// return new ProductionPlan();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getCompletedNotificationBody(Import $import): string
|
public static function getCompletedNotificationBody(Import $import): string
|
||||||
{
|
{
|
||||||
$body = 'Your production plan import has completed and '.number_format($import->successful_rows).' '.str('row')->plural($import->successful_rows).' imported.';
|
$body = 'Your production plan import has completed and ' . number_format($import->successful_rows) . ' ' . str('row')->plural($import->successful_rows) . ' imported.';
|
||||||
|
|
||||||
if ($failedRowsCount = $import->getFailedRowsCount()) {
|
if ($failedRowsCount = $import->getFailedRowsCount()) {
|
||||||
$body .= ' '.number_format($failedRowsCount).' '.str('row')->plural($failedRowsCount).' failed to import.';
|
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to import.';
|
||||||
}
|
}
|
||||||
|
|
||||||
return $body;
|
return $body;
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -82,9 +82,6 @@ class ItemResource extends Resource
|
|||||||
Forms\Components\TextInput::make('category')
|
Forms\Components\TextInput::make('category')
|
||||||
->label('Category')
|
->label('Category')
|
||||||
->placeholder('Scan the Category'),
|
->placeholder('Scan the Category'),
|
||||||
Forms\Components\TextInput::make('category')
|
|
||||||
->label('Category')
|
|
||||||
->placeholder('Scan the Category'),
|
|
||||||
Forms\Components\TextInput::make('code')
|
Forms\Components\TextInput::make('code')
|
||||||
->required()
|
->required()
|
||||||
->placeholder('Scan the valid code')
|
->placeholder('Scan the valid code')
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -6,8 +6,8 @@ use AlperenErsoy\FilamentExport\Actions\FilamentExportBulkAction;
|
|||||||
use App\Filament\Exports\ProductionPlanExporter;
|
use App\Filament\Exports\ProductionPlanExporter;
|
||||||
use App\Filament\Imports\ProductionPlanImporter;
|
use App\Filament\Imports\ProductionPlanImporter;
|
||||||
use App\Filament\Resources\ProductionPlanResource\Pages;
|
use App\Filament\Resources\ProductionPlanResource\Pages;
|
||||||
|
use App\Filament\Resources\ProductionPlanResource\RelationManagers;
|
||||||
use App\Models\Block;
|
use App\Models\Block;
|
||||||
use App\Models\Item;
|
|
||||||
use App\Models\Line;
|
use App\Models\Line;
|
||||||
use App\Models\Plant;
|
use App\Models\Plant;
|
||||||
use App\Models\ProductionPlan;
|
use App\Models\ProductionPlan;
|
||||||
@@ -16,18 +16,19 @@ use Carbon\Carbon;
|
|||||||
use Filament\Facades\Filament;
|
use Filament\Facades\Filament;
|
||||||
use Filament\Forms;
|
use Filament\Forms;
|
||||||
use Filament\Forms\Components\DateTimePicker;
|
use Filament\Forms\Components\DateTimePicker;
|
||||||
use Filament\Forms\Components\Section;
|
|
||||||
use Filament\Forms\Components\Select;
|
|
||||||
use Filament\Forms\Form;
|
use Filament\Forms\Form;
|
||||||
use Filament\Forms\Get;
|
use Filament\Forms\Get;
|
||||||
use Filament\Resources\Resource;
|
use Filament\Resources\Resource;
|
||||||
use Filament\Tables;
|
use Filament\Tables;
|
||||||
use Filament\Tables\Actions\ExportAction;
|
|
||||||
use Filament\Tables\Actions\ImportAction;
|
use Filament\Tables\Actions\ImportAction;
|
||||||
use Filament\Tables\Filters\Filter;
|
|
||||||
use Filament\Tables\Table;
|
use Filament\Tables\Table;
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||||
|
use Filament\Forms\Components\Section;
|
||||||
|
use Filament\Forms\Components\Select;
|
||||||
|
use Filament\Tables\Actions\ExportAction;
|
||||||
|
use Filament\Tables\Filters\Filter;
|
||||||
|
use Illuminate\Support\Facades\Request;
|
||||||
|
|
||||||
class ProductionPlanResource extends Resource
|
class ProductionPlanResource extends Resource
|
||||||
{
|
{
|
||||||
@@ -54,22 +55,22 @@ class ProductionPlanResource extends Resource
|
|||||||
->reactive()
|
->reactive()
|
||||||
->options(function (callable $get) {
|
->options(function (callable $get) {
|
||||||
$userHas = Filament::auth()->user()->plant_id;
|
$userHas = Filament::auth()->user()->plant_id;
|
||||||
|
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
|
||||||
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
|
|
||||||
})
|
})
|
||||||
->default(function () {
|
->default(function () {
|
||||||
return optional(ProductionPlan::latest()->first())->plant_id;
|
return optional(ProductionPlan::latest()->first())->plant_id;
|
||||||
})
|
})
|
||||||
->disabled(fn (Get $get) => ! empty($get('id')))
|
->disabled(fn (Get $get) => !empty($get('id')))
|
||||||
// ->afterStateUpdated(fn ($set) => $set('block_name', null))
|
// ->afterStateUpdated(fn ($set) => $set('block_name', null))
|
||||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||||
$plantId = $get('plant_id');
|
$plantId = $get('plant_id');
|
||||||
$set('block_name', null);
|
$set('block_name', null);
|
||||||
if (! $plantId) {
|
if (!$plantId) {
|
||||||
$set('ppPlantError', 'Please select a plant first.');
|
$set('ppPlantError', 'Please select a plant first.');
|
||||||
|
|
||||||
return;
|
return;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
$set('ppPlantError', null);
|
$set('ppPlantError', null);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -78,6 +79,102 @@ class ProductionPlanResource extends Resource
|
|||||||
])
|
])
|
||||||
->hint(fn ($get) => $get('ppPlantError') ? $get('ppPlantError') : null)
|
->hint(fn ($get) => $get('ppPlantError') ? $get('ppPlantError') : null)
|
||||||
->hintColor('danger'),
|
->hintColor('danger'),
|
||||||
|
Forms\Components\Select::make('block_name')
|
||||||
|
->required()
|
||||||
|
// ->nullable()
|
||||||
|
->label('Block')
|
||||||
|
->options(function (callable $get) {
|
||||||
|
if (!$get('plant_id')) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
return Block::where('plant_id', $get('plant_id'))
|
||||||
|
->pluck('name', 'id')
|
||||||
|
->toArray();
|
||||||
|
})
|
||||||
|
->reactive()
|
||||||
|
->default(function () {
|
||||||
|
$latestShiftId = optional(ProductionPlan::latest()->first())->shift_id;
|
||||||
|
return optional(Shift::where('id', $latestShiftId)->first())->block_id;
|
||||||
|
})
|
||||||
|
//->afterStateUpdated(fn ($set) => $set('shift_id', null))
|
||||||
|
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||||
|
if($get('id'))
|
||||||
|
{
|
||||||
|
$getShift = ProductionPlan::where('id', $get('id'))->first();
|
||||||
|
$getBlock = Shift::where('id', $getShift->shift_id)->first();
|
||||||
|
if($getBlock->block_id)
|
||||||
|
{
|
||||||
|
$set('block_name', $getBlock->block_id);
|
||||||
|
$set('ppBlockError', null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$blockId = $get('block_name');
|
||||||
|
$set('shift_id', null);
|
||||||
|
|
||||||
|
if (!$blockId) {
|
||||||
|
$set('ppBlockError', 'Please select a block first.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$set('ppBlockError', null);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
->extraAttributes(fn ($get) => [
|
||||||
|
'class' => $get('ppBlockError') ? 'border-red-500' : '',
|
||||||
|
])
|
||||||
|
->hint(fn ($get) => $get('ppBlockError') ? $get('ppBlockError') : null)
|
||||||
|
->hintColor('danger'),
|
||||||
|
Forms\Components\Select::make('shift_id')
|
||||||
|
->relationship('shift', 'name')
|
||||||
|
->required()
|
||||||
|
// ->nullable()
|
||||||
|
->autofocus(true)
|
||||||
|
->options(function (callable $get) {
|
||||||
|
if (!$get('plant_id') || !$get('block_name')) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
return Shift::where('plant_id', $get('plant_id'))
|
||||||
|
->where('block_id', $get('block_name'))
|
||||||
|
->pluck('name', 'id')
|
||||||
|
->toArray();
|
||||||
|
})
|
||||||
|
->reactive()
|
||||||
|
->default(function () {
|
||||||
|
return optional(ProductionPlan::latest()->first())->shift_id;
|
||||||
|
})
|
||||||
|
// ->afterStateUpdated(fn ($set) => $set('line_id', null))
|
||||||
|
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||||
|
if($get('id'))
|
||||||
|
{
|
||||||
|
$getShift = ProductionPlan::where('id', $get('id'))->first();
|
||||||
|
if($getShift->shift_id)
|
||||||
|
{
|
||||||
|
$set('shift_id', $getShift->shift_id);
|
||||||
|
$set('ppShiftError', null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$curShiftId = $get('shift_id');
|
||||||
|
$set('line_id', null);
|
||||||
|
|
||||||
|
if (!$curShiftId) {
|
||||||
|
$set('ppShiftError', 'Please select a shift first.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$set('ppShiftError', null);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
->extraAttributes(fn ($get) => [
|
||||||
|
'class' => $get('ppShiftError') ? 'border-red-500' : '',
|
||||||
|
])
|
||||||
|
->hint(fn ($get) => $get('ppShiftError') ? $get('ppShiftError') : null)
|
||||||
|
->hintColor('danger'),
|
||||||
Forms\Components\Select::make('line_id')
|
Forms\Components\Select::make('line_id')
|
||||||
->relationship('line', 'name')
|
->relationship('line', 'name')
|
||||||
->required()
|
->required()
|
||||||
@@ -88,7 +185,7 @@ class ProductionPlanResource extends Resource
|
|||||||
// ->toArray() // Convert collection to array
|
// ->toArray() // Convert collection to array
|
||||||
// )
|
// )
|
||||||
->options(function (callable $get) {
|
->options(function (callable $get) {
|
||||||
if (! $get('plant_id')) {
|
if (!$get('plant_id') || !$get('block_name') || !$get('shift_id')) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,257 +197,248 @@ class ProductionPlanResource extends Resource
|
|||||||
// ->default(function () {
|
// ->default(function () {
|
||||||
// return optional(ProductionPlan::latest()->first())->line_id;
|
// return optional(ProductionPlan::latest()->first())->line_id;
|
||||||
// })
|
// })
|
||||||
// ->afterStateUpdated(function ($state, callable $set, callable $get) {
|
|
||||||
// if ($get('id')) {
|
|
||||||
// $getShift = ProductionPlan::where('id', $get('id'))->first();
|
|
||||||
// if ($getShift->line_id) {
|
|
||||||
// $set('line_id', $getShift->line_id);
|
|
||||||
// $set('ppLineError', null);
|
|
||||||
// }
|
|
||||||
// } else {
|
|
||||||
// $currentDT = Carbon::now()->toDateTimeString();
|
|
||||||
// $set('created_at', $currentDT);
|
|
||||||
// $set('update_date', null);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// $lineId = $get('line_id');
|
|
||||||
// // $set('plan_quantity', null);
|
|
||||||
|
|
||||||
// if (! $lineId) {
|
|
||||||
// $set('ppLineError', 'Please select a line first.');
|
|
||||||
|
|
||||||
// return;
|
|
||||||
// } else {
|
|
||||||
// $isUpdate = ! empty($get('id'));
|
|
||||||
// if (! $isUpdate) {
|
|
||||||
// $exists = ProductionPlan::where('plant_id', $get('plant_id'))
|
|
||||||
// ->where('shift_id', $get('shift_id'))
|
|
||||||
// ->where('line_id', $get('line_id'))
|
|
||||||
// ->whereDate('created_at', today())
|
|
||||||
// ->latest()
|
|
||||||
// ->exists();
|
|
||||||
|
|
||||||
// if ($exists) {
|
|
||||||
// $set('line_id', null);
|
|
||||||
// $set('ppLineError', 'Production plan already updated.');
|
|
||||||
|
|
||||||
// return;
|
|
||||||
// } else {
|
|
||||||
// $existShifts = ProductionPlan::where('plant_id', $get('plant_id'))
|
|
||||||
// ->where('shift_id', $get('shift_id'))
|
|
||||||
// ->where('line_id', $get('line_id'))
|
|
||||||
// ->whereDate('created_at', Carbon::yesterday())
|
|
||||||
// ->latest()
|
|
||||||
// ->exists();
|
|
||||||
|
|
||||||
// if ($existShifts) { // if ($existShifts->count() > 0)
|
|
||||||
// // $currentDate = date('Y-m-d');
|
|
||||||
// $yesterday = date('Y-m-d', strtotime('-1 days'));
|
|
||||||
|
|
||||||
// $shiftId = Shift::where('id', $get('shift_id'))
|
|
||||||
// ->first();
|
|
||||||
|
|
||||||
// [$hRs, $miNs] = explode('.', $shiftId->duration) + [0, 0];
|
|
||||||
// $hRs = (int) $hRs;
|
|
||||||
// // $miNs = (int) $miNs;-*/
|
|
||||||
|
|
||||||
// $totalMinutes = $hRs * 60 + $miNs;
|
|
||||||
|
|
||||||
// $from_dt = $yesterday.' '.$shiftId->start_time;
|
|
||||||
|
|
||||||
// $to_dt = date('Y-m-d H:i:s', strtotime($from_dt." + $totalMinutes minutes"));
|
|
||||||
|
|
||||||
// $currentDateTime = date('Y-m-d H:i:s');
|
|
||||||
|
|
||||||
// // Check if current date time is within the range
|
|
||||||
// if ($currentDateTime >= $from_dt && $currentDateTime < $to_dt) {
|
|
||||||
// // echo "Choosed a valid shift...";
|
|
||||||
|
|
||||||
// $set('line_id', null);
|
|
||||||
// $set('ppLineError', 'Production plan already updated.');
|
|
||||||
|
|
||||||
// // $set('ppLineError', 'Valid (From: '.$from_dt.', To: '.$to_dt.')');
|
|
||||||
// return;
|
|
||||||
// } else {
|
|
||||||
// $currentDate = date('Y-m-d');
|
|
||||||
|
|
||||||
// $shiftId = Shift::where('id', $get('shift_id'))
|
|
||||||
// ->first();
|
|
||||||
|
|
||||||
// [$hRs, $miNs] = explode('.', $shiftId->duration) + [0, 0];
|
|
||||||
// $hRs = (int) $hRs;
|
|
||||||
// // $miNs = (int) $miNs;-*/
|
|
||||||
|
|
||||||
// $totalMinutes = $hRs * 60 + $miNs;
|
|
||||||
|
|
||||||
// $from_dt = $currentDate.' '.$shiftId->start_time;
|
|
||||||
|
|
||||||
// $to_dt = date('Y-m-d H:i:s', strtotime($from_dt." + $totalMinutes minutes"));
|
|
||||||
|
|
||||||
// $currentDateTime = date('Y-m-d H:i:s');
|
|
||||||
|
|
||||||
// // Check if current date time is within the range
|
|
||||||
// if (! ($currentDateTime >= $from_dt && $currentDateTime < $to_dt)) {
|
|
||||||
// // echo "Choosed a valid shift...";
|
|
||||||
|
|
||||||
// $set('line_id', null);
|
|
||||||
// $set('ppLineError', 'Choosed a invalid shift.');
|
|
||||||
|
|
||||||
// // $set('ppLineError', 'Valid (From: '.$from_dt.', To: '.$to_dt.')');
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// $set('ppLineError', null);
|
|
||||||
|
|
||||||
// return;
|
|
||||||
// } else {
|
|
||||||
// // $currentDate = date('Y-m-d');
|
|
||||||
// $yesterday = date('Y-m-d', strtotime('-1 days'));
|
|
||||||
|
|
||||||
// $shiftId = Shift::where('id', $get('shift_id'))
|
|
||||||
// ->first();
|
|
||||||
|
|
||||||
// [$hRs, $miNs] = explode('.', $shiftId->duration) + [0, 0];
|
|
||||||
// $hRs = (int) $hRs;
|
|
||||||
// // $miNs = (int) $miNs;-*/
|
|
||||||
|
|
||||||
// $totalMinutes = $hRs * 60 + $miNs;
|
|
||||||
|
|
||||||
// $from_dt = $yesterday.' '.$shiftId->start_time;
|
|
||||||
|
|
||||||
// $to_dt = date('Y-m-d H:i:s', strtotime($from_dt." + $totalMinutes minutes"));
|
|
||||||
|
|
||||||
// $currentDateTime = date('Y-m-d H:i:s');
|
|
||||||
|
|
||||||
// // Check if current date time is within the range
|
|
||||||
// if ($currentDateTime >= $from_dt && $currentDateTime < $to_dt) {
|
|
||||||
// // echo "Choosed a valid shift...";
|
|
||||||
|
|
||||||
// // here i'm updating created as yesterday
|
|
||||||
// $set('created_at', $from_dt);
|
|
||||||
// $set('update_date', '1');
|
|
||||||
|
|
||||||
// $set('ppLineError', null);
|
|
||||||
|
|
||||||
// // $set('ppLineError', 'Valid (From: '.$from_dt.', To: '.$to_dt.')');
|
|
||||||
// return;
|
|
||||||
// } else {
|
|
||||||
// $currentDate = date('Y-m-d');
|
|
||||||
|
|
||||||
// $shiftId = Shift::where('id', $get('shift_id'))
|
|
||||||
// ->first();
|
|
||||||
|
|
||||||
// [$hRs, $miNs] = explode('.', $shiftId->duration) + [0, 0];
|
|
||||||
// $hRs = (int) $hRs;
|
|
||||||
// // $miNs = (int) $miNs;-*/
|
|
||||||
|
|
||||||
// $totalMinutes = $hRs * 60 + $miNs;
|
|
||||||
|
|
||||||
// $from_dt = $currentDate.' '.$shiftId->start_time;
|
|
||||||
|
|
||||||
// $to_dt = date('Y-m-d H:i:s', strtotime($from_dt." + $totalMinutes minutes"));
|
|
||||||
|
|
||||||
// $currentDateTime = date('Y-m-d H:i:s');
|
|
||||||
|
|
||||||
// // Check if current date time is within the range
|
|
||||||
// if (! ($currentDateTime >= $from_dt && $currentDateTime < $to_dt)) {
|
|
||||||
// // echo "Choosed a valid shift...";
|
|
||||||
|
|
||||||
// $set('line_id', null);
|
|
||||||
// $set('ppLineError', 'Choosed a invalid shift.');
|
|
||||||
|
|
||||||
// // $set('ppLineError', 'Valid (From: '.$from_dt.', To: '.$to_dt.')');
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// $set('ppLineError', null);
|
|
||||||
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // $exists = ProductionPlan::where('plant_id', $get('plant_id'))
|
|
||||||
// // //->where('shift_id', $get('shift_id'))
|
|
||||||
// // ->where('line_id', $get('line_id'))
|
|
||||||
// // ->whereDate('created_at', today())
|
|
||||||
// // ->latest() // Orders by created_at DESC
|
|
||||||
// // ->first();
|
|
||||||
|
|
||||||
// // if ($exists)
|
|
||||||
// // {
|
|
||||||
// // $existingShifts = ProductionPlan::where('plant_id', $get('plant_id'))
|
|
||||||
// // //->where('shift_id', $get('shift_id'))
|
|
||||||
// // ->where('line_id', $get('line_id'))
|
|
||||||
// // // ->whereDate('created_at', today())
|
|
||||||
// // ->whereDate('created_at', today())
|
|
||||||
// // ->get();
|
|
||||||
|
|
||||||
// // foreach ($existingShifts as $shift) {
|
|
||||||
// // $curShiftId = $shift->shift_id;
|
|
||||||
|
|
||||||
// // $currentDate = date('Y-m-d');
|
|
||||||
|
|
||||||
// // $shiftId = \App\Models\Shift::where('id', $curShiftId)
|
|
||||||
// // ->first();
|
|
||||||
|
|
||||||
// // [$hRs, $miNs] = explode('.', $shiftId->duration) + [0, 0];
|
|
||||||
// // $hRs = (int) $hRs;
|
|
||||||
// // // $miNs = (int) $miNs;-*/
|
|
||||||
|
|
||||||
// // $totalMinutes = $hRs * 60 + $miNs;
|
|
||||||
|
|
||||||
// // $from_dt = $currentDate . ' ' . $shiftId->start_time;
|
|
||||||
|
|
||||||
// // $to_dt = date('Y-m-d H:i:s', strtotime($from_dt . " + $totalMinutes minutes"));
|
|
||||||
|
|
||||||
// // $currentDateTime = date('Y-m-d H:i:s');
|
|
||||||
|
|
||||||
// // // Check if current date time is within the range
|
|
||||||
// // if ($currentDateTime >= $from_dt && $currentDateTime < $to_dt) {
|
|
||||||
// // //echo "Choosed a valid shift...";
|
|
||||||
// // // $set('ppLineError', 'Valid (From: '.$from_dt.', To: '.$to_dt.')');
|
|
||||||
|
|
||||||
// // $set('line_id', null);
|
|
||||||
// // $set('ppLineError', 'Production plan already updated.');
|
|
||||||
// // return;
|
|
||||||
// // }
|
|
||||||
// // // else {
|
|
||||||
// // // $set('ppLineError', 'Choosed a invalid shift...');
|
|
||||||
// // // return;
|
|
||||||
// // // }
|
|
||||||
// // }
|
|
||||||
// // $set('ppLineError', null);
|
|
||||||
// // return;
|
|
||||||
// // }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// $set('ppLineError', null);
|
|
||||||
// }
|
|
||||||
// })
|
|
||||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||||
$set('item_id', null);
|
if($get('id'))
|
||||||
$set('plan_quantity', null);
|
{
|
||||||
|
$getShift = ProductionPlan::where('id', $get('id'))->first();
|
||||||
|
if($getShift->line_id)
|
||||||
|
{
|
||||||
|
$set('line_id', $getShift->line_id);
|
||||||
|
$set('ppLineError', null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$currentDT = Carbon::now()->toDateTimeString();
|
||||||
|
$set('created_at', $currentDT);
|
||||||
|
$set('update_date', null);
|
||||||
|
}
|
||||||
|
|
||||||
|
$lineId = $get('line_id');
|
||||||
|
// $set('plan_quantity', null);
|
||||||
|
|
||||||
|
if (!$lineId) {
|
||||||
|
$set('ppLineError', 'Please select a line first.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$isUpdate = !empty($get('id'));
|
||||||
|
if (!$isUpdate)
|
||||||
|
{
|
||||||
|
$exists = ProductionPlan::where('plant_id', $get('plant_id'))
|
||||||
|
->where('shift_id', $get('shift_id'))
|
||||||
|
->where('line_id', $get('line_id'))
|
||||||
|
->whereDate('created_at', today())
|
||||||
|
->latest()
|
||||||
|
->exists();
|
||||||
|
|
||||||
|
if ($exists)
|
||||||
|
{
|
||||||
|
$set('line_id', null);
|
||||||
|
$set('ppLineError', 'Production plan already updated.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$existShifts = ProductionPlan::where('plant_id', $get('plant_id'))
|
||||||
|
->where('shift_id', $get('shift_id'))
|
||||||
|
->where('line_id', $get('line_id'))
|
||||||
|
->whereDate('created_at', Carbon::yesterday())
|
||||||
|
->latest()
|
||||||
|
->exists();
|
||||||
|
|
||||||
|
if ($existShifts) //if ($existShifts->count() > 0)
|
||||||
|
{
|
||||||
|
//$currentDate = date('Y-m-d');
|
||||||
|
$yesterday = date('Y-m-d', strtotime('-1 days'));
|
||||||
|
|
||||||
|
$shiftId = Shift::where('id', $get('shift_id'))
|
||||||
|
->first();
|
||||||
|
|
||||||
|
[$hRs, $miNs] = explode('.', $shiftId->duration) + [0, 0];
|
||||||
|
$hRs = (int) $hRs;
|
||||||
|
// $miNs = (int) $miNs;-*/
|
||||||
|
|
||||||
|
$totalMinutes = $hRs * 60 + $miNs;
|
||||||
|
|
||||||
|
$from_dt = $yesterday . ' ' . $shiftId->start_time;
|
||||||
|
|
||||||
|
$to_dt = date('Y-m-d H:i:s', strtotime($from_dt . " + $totalMinutes minutes"));
|
||||||
|
|
||||||
|
$currentDateTime = date('Y-m-d H:i:s');
|
||||||
|
|
||||||
|
// Check if current date time is within the range
|
||||||
|
if ($currentDateTime >= $from_dt && $currentDateTime < $to_dt) {
|
||||||
|
//echo "Choosed a valid shift...";
|
||||||
|
|
||||||
|
$set('line_id', null);
|
||||||
|
$set('ppLineError', 'Production plan already updated.');
|
||||||
|
// $set('ppLineError', 'Valid (From: '.$from_dt.', To: '.$to_dt.')');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$currentDate = date('Y-m-d');
|
||||||
|
|
||||||
|
$shiftId = Shift::where('id', $get('shift_id'))
|
||||||
|
->first();
|
||||||
|
|
||||||
|
[$hRs, $miNs] = explode('.', $shiftId->duration) + [0, 0];
|
||||||
|
$hRs = (int) $hRs;
|
||||||
|
// $miNs = (int) $miNs;-*/
|
||||||
|
|
||||||
|
$totalMinutes = $hRs * 60 + $miNs;
|
||||||
|
|
||||||
|
$from_dt = $currentDate . ' ' . $shiftId->start_time;
|
||||||
|
|
||||||
|
$to_dt = date('Y-m-d H:i:s', strtotime($from_dt . " + $totalMinutes minutes"));
|
||||||
|
|
||||||
|
$currentDateTime = date('Y-m-d H:i:s');
|
||||||
|
|
||||||
|
// Check if current date time is within the range
|
||||||
|
if (!($currentDateTime >= $from_dt && $currentDateTime < $to_dt)) {
|
||||||
|
//echo "Choosed a valid shift...";
|
||||||
|
|
||||||
|
$set('line_id', null);
|
||||||
|
$set('ppLineError', 'Choosed a invalid shift.');
|
||||||
|
// $set('ppLineError', 'Valid (From: '.$from_dt.', To: '.$to_dt.')');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$set('ppLineError', null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//$currentDate = date('Y-m-d');
|
||||||
|
$yesterday = date('Y-m-d', strtotime('-1 days'));
|
||||||
|
|
||||||
|
$shiftId = Shift::where('id', $get('shift_id'))
|
||||||
|
->first();
|
||||||
|
|
||||||
|
[$hRs, $miNs] = explode('.', $shiftId->duration) + [0, 0];
|
||||||
|
$hRs = (int) $hRs;
|
||||||
|
// $miNs = (int) $miNs;-*/
|
||||||
|
|
||||||
|
$totalMinutes = $hRs * 60 + $miNs;
|
||||||
|
|
||||||
|
$from_dt = $yesterday . ' ' . $shiftId->start_time;
|
||||||
|
|
||||||
|
$to_dt = date('Y-m-d H:i:s', strtotime($from_dt . " + $totalMinutes minutes"));
|
||||||
|
|
||||||
|
$currentDateTime = date('Y-m-d H:i:s');
|
||||||
|
|
||||||
|
// Check if current date time is within the range
|
||||||
|
if ($currentDateTime >= $from_dt && $currentDateTime < $to_dt) {
|
||||||
|
//echo "Choosed a valid shift...";
|
||||||
|
|
||||||
|
// here i'm updating created as yesterday
|
||||||
|
$set('created_at', $from_dt);
|
||||||
|
$set('update_date', '1');
|
||||||
|
|
||||||
|
$set('ppLineError', null);
|
||||||
|
// $set('ppLineError', 'Valid (From: '.$from_dt.', To: '.$to_dt.')');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$currentDate = date('Y-m-d');
|
||||||
|
|
||||||
|
$shiftId = Shift::where('id', $get('shift_id'))
|
||||||
|
->first();
|
||||||
|
|
||||||
|
[$hRs, $miNs] = explode('.', $shiftId->duration) + [0, 0];
|
||||||
|
$hRs = (int) $hRs;
|
||||||
|
// $miNs = (int) $miNs;-*/
|
||||||
|
|
||||||
|
$totalMinutes = $hRs * 60 + $miNs;
|
||||||
|
|
||||||
|
$from_dt = $currentDate . ' ' . $shiftId->start_time;
|
||||||
|
|
||||||
|
$to_dt = date('Y-m-d H:i:s', strtotime($from_dt . " + $totalMinutes minutes"));
|
||||||
|
|
||||||
|
$currentDateTime = date('Y-m-d H:i:s');
|
||||||
|
|
||||||
|
// Check if current date time is within the range
|
||||||
|
if (!($currentDateTime >= $from_dt && $currentDateTime < $to_dt)) {
|
||||||
|
//echo "Choosed a valid shift...";
|
||||||
|
|
||||||
|
$set('line_id', null);
|
||||||
|
$set('ppLineError', 'Choosed a invalid shift.');
|
||||||
|
// $set('ppLineError', 'Valid (From: '.$from_dt.', To: '.$to_dt.')');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$set('ppLineError', null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// $exists = ProductionPlan::where('plant_id', $get('plant_id'))
|
||||||
|
// //->where('shift_id', $get('shift_id'))
|
||||||
|
// ->where('line_id', $get('line_id'))
|
||||||
|
// ->whereDate('created_at', today())
|
||||||
|
// ->latest() // Orders by created_at DESC
|
||||||
|
// ->first();
|
||||||
|
|
||||||
|
// if ($exists)
|
||||||
|
// {
|
||||||
|
// $existingShifts = ProductionPlan::where('plant_id', $get('plant_id'))
|
||||||
|
// //->where('shift_id', $get('shift_id'))
|
||||||
|
// ->where('line_id', $get('line_id'))
|
||||||
|
// // ->whereDate('created_at', today())
|
||||||
|
// ->whereDate('created_at', today())
|
||||||
|
// ->get();
|
||||||
|
|
||||||
|
// foreach ($existingShifts as $shift) {
|
||||||
|
// $curShiftId = $shift->shift_id;
|
||||||
|
|
||||||
|
// $currentDate = date('Y-m-d');
|
||||||
|
|
||||||
|
// $shiftId = \App\Models\Shift::where('id', $curShiftId)
|
||||||
|
// ->first();
|
||||||
|
|
||||||
|
// [$hRs, $miNs] = explode('.', $shiftId->duration) + [0, 0];
|
||||||
|
// $hRs = (int) $hRs;
|
||||||
|
// // $miNs = (int) $miNs;-*/
|
||||||
|
|
||||||
|
// $totalMinutes = $hRs * 60 + $miNs;
|
||||||
|
|
||||||
|
// $from_dt = $currentDate . ' ' . $shiftId->start_time;
|
||||||
|
|
||||||
|
// $to_dt = date('Y-m-d H:i:s', strtotime($from_dt . " + $totalMinutes minutes"));
|
||||||
|
|
||||||
|
// $currentDateTime = date('Y-m-d H:i:s');
|
||||||
|
|
||||||
|
// // Check if current date time is within the range
|
||||||
|
// if ($currentDateTime >= $from_dt && $currentDateTime < $to_dt) {
|
||||||
|
// //echo "Choosed a valid shift...";
|
||||||
|
// // $set('ppLineError', 'Valid (From: '.$from_dt.', To: '.$to_dt.')');
|
||||||
|
|
||||||
|
// $set('line_id', null);
|
||||||
|
// $set('ppLineError', 'Production plan already updated.');
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
// // else {
|
||||||
|
// // $set('ppLineError', 'Choosed a invalid shift...');
|
||||||
|
// // return;
|
||||||
|
// // }
|
||||||
|
// }
|
||||||
|
// $set('ppLineError', null);
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$set('ppLineError', null);
|
||||||
|
}
|
||||||
})
|
})
|
||||||
->extraAttributes(fn ($get) => [
|
->extraAttributes(fn ($get) => [
|
||||||
'class' => $get('ppLineError') ? 'border-red-500' : '',
|
'class' => $get('ppLineError') ? 'border-red-500' : '',
|
||||||
])
|
])
|
||||||
->hint(fn ($get) => $get('ppLineError') ? $get('ppLineError') : null)
|
->hint(fn ($get) => $get('ppLineError') ? $get('ppLineError') : null)
|
||||||
->hintColor('danger'),
|
->hintColor('danger'),
|
||||||
Forms\Components\Select::make('item_id')
|
|
||||||
->label('Item')
|
|
||||||
->reactive()
|
|
||||||
->searchable()
|
|
||||||
->required()
|
|
||||||
->options(function (callable $get) {
|
|
||||||
if (! $get('plant_id')) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
return Item::where('plant_id', $get('plant_id'))
|
|
||||||
->pluck('code', 'id')
|
|
||||||
->toArray();
|
|
||||||
}),
|
|
||||||
Forms\Components\TextInput::make('plan_quantity')
|
Forms\Components\TextInput::make('plan_quantity')
|
||||||
->required()
|
->required()
|
||||||
->integer()
|
->integer()
|
||||||
@@ -361,18 +449,21 @@ class ProductionPlanResource extends Resource
|
|||||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||||
$planQuan = $get('plan_quantity');
|
$planQuan = $get('plan_quantity');
|
||||||
|
|
||||||
if (! $get('update_date')) {
|
if(!$get('update_date') )
|
||||||
if (! $get('id')) {
|
{
|
||||||
|
if(!$get('id'))
|
||||||
|
{
|
||||||
$currentDT = Carbon::now()->toDateTimeString();
|
$currentDT = Carbon::now()->toDateTimeString();
|
||||||
$set('created_at', $currentDT);
|
$set('created_at', $currentDT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! $planQuan) {
|
if (!$planQuan) {
|
||||||
$set('ppPlanQuanError', 'Scan the valid plan quantity.');
|
$set('ppPlanQuanError', 'Scan the valid plan quantity.');
|
||||||
|
|
||||||
return;
|
return;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
$set('ppPlanQuanError', null);
|
$set('ppPlanQuanError', null);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -381,19 +472,29 @@ class ProductionPlanResource extends Resource
|
|||||||
])
|
])
|
||||||
->hint(fn ($get) => $get('ppPlanQuanError') ? $get('ppPlanQuanError') : null)
|
->hint(fn ($get) => $get('ppPlanQuanError') ? $get('ppPlanQuanError') : null)
|
||||||
->hintColor('danger'),
|
->hintColor('danger'),
|
||||||
// Forms\Components\TextInput::make('production_quantity')
|
Forms\Components\TextInput::make('production_quantity')
|
||||||
// ->required()
|
->required()
|
||||||
// ->integer()
|
->integer()
|
||||||
// ->label('Production Quantity')
|
->label('Production Quantity')
|
||||||
// ->readOnly(fn (callable $get) => ! $get('id'))
|
->readOnly(fn (callable $get) => !$get('id'))
|
||||||
// ->default(0),
|
->default(0),
|
||||||
Forms\Components\TextInput::make('id')
|
Forms\Components\TextInput::make('id')
|
||||||
->hidden()
|
->hidden()
|
||||||
->readOnly(),
|
->readOnly(),
|
||||||
|
Forms\Components\TextInput::make('update_date')
|
||||||
|
->hidden()
|
||||||
|
->reactive()
|
||||||
|
->readOnly(),
|
||||||
|
Forms\Components\DateTimePicker::make('created_at')
|
||||||
|
->label('Created DateTime')
|
||||||
|
->hidden()
|
||||||
|
->reactive()
|
||||||
|
->required()
|
||||||
|
->readOnly(),
|
||||||
Forms\Components\Hidden::make('operator_id')
|
Forms\Components\Hidden::make('operator_id')
|
||||||
->default(Filament::auth()->user()->name),
|
->default(Filament::auth()->user()->name),
|
||||||
])
|
])
|
||||||
->columns(4),
|
->columns(2),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -428,55 +529,34 @@ class ProductionPlanResource extends Resource
|
|||||||
$paginator = $livewire->getTableRecords();
|
$paginator = $livewire->getTableRecords();
|
||||||
$perPage = method_exists($paginator, 'perPage') ? $paginator->perPage() : 10;
|
$perPage = method_exists($paginator, 'perPage') ? $paginator->perPage() : 10;
|
||||||
$currentPage = method_exists($paginator, 'currentPage') ? $paginator->currentPage() : 1;
|
$currentPage = method_exists($paginator, 'currentPage') ? $paginator->currentPage() : 1;
|
||||||
|
|
||||||
return ($currentPage - 1) * $perPage + $rowLoop->iteration;
|
return ($currentPage - 1) * $perPage + $rowLoop->iteration;
|
||||||
}),
|
}),
|
||||||
Tables\Columns\TextColumn::make('plant.name')
|
|
||||||
->label('Plant')
|
|
||||||
->alignCenter()
|
|
||||||
->sortable()
|
|
||||||
->searchable(),
|
|
||||||
Tables\Columns\TextColumn::make('line.name')
|
|
||||||
->label('Plant')
|
|
||||||
->alignCenter()
|
|
||||||
->sortable()
|
|
||||||
->searchable(),
|
|
||||||
Tables\Columns\TextColumn::make('item.code')
|
|
||||||
->label('Item')
|
|
||||||
->alignCenter()
|
|
||||||
->sortable()
|
|
||||||
->searchable(),
|
|
||||||
Tables\Columns\TextColumn::make('plan_quantity')
|
Tables\Columns\TextColumn::make('plan_quantity')
|
||||||
->label('Plan Quantity')
|
->label('Plan Quantity')
|
||||||
->alignCenter()
|
->alignCenter()
|
||||||
->numeric()
|
->numeric()
|
||||||
->sortable()
|
->sortable(),
|
||||||
->searchable(),
|
|
||||||
Tables\Columns\TextColumn::make('working_days')
|
|
||||||
->label('Working Days')
|
|
||||||
->alignCenter()
|
|
||||||
->numeric()
|
|
||||||
->sortable()
|
|
||||||
->searchable(),
|
|
||||||
Tables\Columns\TextColumn::make('production_quantity')
|
Tables\Columns\TextColumn::make('production_quantity')
|
||||||
->label('Production Quantity')
|
->label('Production Quantity')
|
||||||
->alignCenter()
|
->alignCenter()
|
||||||
->numeric()
|
->numeric()
|
||||||
->sortable()
|
->sortable(),
|
||||||
->searchable(),
|
Tables\Columns\TextColumn::make('line.name')
|
||||||
// Tables\Columns\TextColumn::make('line.name')
|
->label('Line')
|
||||||
// ->label('Line')
|
->alignCenter()
|
||||||
// ->alignCenter()
|
->sortable(),// ->searchable(),
|
||||||
// ->sortable(), // ->searchable(),
|
Tables\Columns\TextColumn::make('shift.block.name')
|
||||||
// Tables\Columns\TextColumn::make('shift.block.name')
|
->label('Block')
|
||||||
// ->label('Block')
|
->alignCenter()
|
||||||
// ->alignCenter()
|
->sortable(),
|
||||||
// ->sortable(),
|
Tables\Columns\TextColumn::make('shift.name')
|
||||||
// Tables\Columns\TextColumn::make('shift.name')
|
->label('Shift')
|
||||||
// ->label('Shift')
|
->alignCenter()
|
||||||
// ->alignCenter()
|
->sortable(),// ->searchable(),
|
||||||
// ->sortable(), // ->searchable(),
|
Tables\Columns\TextColumn::make('plant.name')
|
||||||
|
->label('Plant')
|
||||||
|
->alignCenter()
|
||||||
|
->sortable(),// ->searchable(),
|
||||||
Tables\Columns\TextColumn::make('created_at')
|
Tables\Columns\TextColumn::make('created_at')
|
||||||
->label('Created At')
|
->label('Created At')
|
||||||
->dateTime()
|
->dateTime()
|
||||||
@@ -504,7 +584,7 @@ class ProductionPlanResource extends Resource
|
|||||||
Filter::make('advanced_filters')
|
Filter::make('advanced_filters')
|
||||||
->label('Advanced Filters')
|
->label('Advanced Filters')
|
||||||
->form([
|
->form([
|
||||||
// plant
|
//plant
|
||||||
Select::make('Plant')
|
Select::make('Plant')
|
||||||
->label('Select Plant')
|
->label('Select Plant')
|
||||||
->nullable()
|
->nullable()
|
||||||
@@ -513,8 +593,7 @@ class ProductionPlanResource extends Resource
|
|||||||
// })
|
// })
|
||||||
->options(function (callable $get) {
|
->options(function (callable $get) {
|
||||||
$userHas = Filament::auth()->user()->plant_id;
|
$userHas = Filament::auth()->user()->plant_id;
|
||||||
|
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
|
||||||
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
|
|
||||||
})
|
})
|
||||||
->reactive()
|
->reactive()
|
||||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||||
@@ -523,33 +602,31 @@ class ProductionPlanResource extends Resource
|
|||||||
$set('Shift', null);
|
$set('Shift', null);
|
||||||
}),
|
}),
|
||||||
|
|
||||||
// line
|
//line
|
||||||
Select::make('Line')
|
Select::make('Line')
|
||||||
->label('Select line')
|
->label('Select line')
|
||||||
->nullable()
|
->nullable()
|
||||||
->options(function (callable $get) {
|
->options(function (callable $get) {
|
||||||
$plantId = $get('Plant');
|
$plantId = $get('Plant');
|
||||||
|
|
||||||
if (! $plantId) {
|
if (!$plantId ) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
return Line::where('plant_id', $plantId)
|
return Line::where('plant_id', $plantId)
|
||||||
->pluck('name', 'id');
|
->pluck('name', 'id');
|
||||||
})
|
})
|
||||||
->reactive(),
|
->reactive(),
|
||||||
|
|
||||||
// block
|
//block
|
||||||
Select::make('Block')
|
Select::make('Block')
|
||||||
->label('Select Block')
|
->label('Select Block')
|
||||||
->nullable()
|
->nullable()
|
||||||
->options(function (callable $get) {
|
->options(function (callable $get) {
|
||||||
$plantId = $get('Plant');
|
$plantId = $get('Plant');
|
||||||
|
|
||||||
if (! $plantId) {
|
if (!$plantId ) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
return Block::where('plant_id', $get('Plant'))->pluck('name', 'id');
|
return Block::where('plant_id', $get('Plant'))->pluck('name', 'id');
|
||||||
})
|
})
|
||||||
->reactive()
|
->reactive()
|
||||||
@@ -557,7 +634,7 @@ class ProductionPlanResource extends Resource
|
|||||||
$set('Shift', null);
|
$set('Shift', null);
|
||||||
}),
|
}),
|
||||||
|
|
||||||
// shift
|
//shift
|
||||||
Select::make('Shift')
|
Select::make('Shift')
|
||||||
->label('Select Shift')
|
->label('Select Shift')
|
||||||
->nullable()
|
->nullable()
|
||||||
@@ -565,7 +642,7 @@ class ProductionPlanResource extends Resource
|
|||||||
$plantId = $get('Plant');
|
$plantId = $get('Plant');
|
||||||
$blockId = $get('Block');
|
$blockId = $get('Block');
|
||||||
|
|
||||||
if (! $plantId || ! $blockId) {
|
if (!$plantId || !$blockId) {
|
||||||
return []; // Return empty if plant or block is not selected
|
return []; // Return empty if plant or block is not selected
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -592,66 +669,52 @@ class ProductionPlanResource extends Resource
|
|||||||
return $query->whereRaw('1 = 0');
|
return $query->whereRaw('1 = 0');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! empty($data['Plant'])) {// if ($plant = $data['Plant'] ?? null) {
|
if ($plant = $data['Plant'] ?? null) {
|
||||||
$query->where('plant_id', $data['Plant']);
|
$query->where('plant_id', $plant);
|
||||||
} else {
|
|
||||||
$userHas = Filament::auth()->user()->plant_id;
|
|
||||||
|
|
||||||
if ($userHas && strlen($userHas) > 0) {
|
|
||||||
return $query->whereRaw('1 = 0');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! empty($data['Shift'])) {// if ($shift = $data['Shift'] ?? null) {
|
if ($shift = $data['Shift'] ?? null) {
|
||||||
$query->where('shift_id', $data['Shift']);
|
$query->where('shift_id', $shift);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($line = $data['Line'] ?? null) {
|
||||||
if (! empty($data['Line'])) {// if ($line = $data['Line'] ?? null) {
|
$query->where('line_id', $line);
|
||||||
$query->where('line_id', $data['Line']);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! empty($data['created_from'])) {// if ($from = $data['created_from'] ?? null) {
|
if ($from = $data['created_from'] ?? null) {
|
||||||
$query->where('created_at', '>=', $data['created_from']);
|
$query->where('created_at', '>=', $from);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! empty($data['created_to'])) {// if ($to = $data['created_to'] ?? null) {
|
if ($to = $data['created_to'] ?? null) {
|
||||||
$query->where('created_at', '<=', $data['created_to']);
|
$query->where('created_at', '<=', $to);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $query;
|
return $query;
|
||||||
})
|
})
|
||||||
->indicateUsing(function (array $data) {
|
->indicateUsing(function (array $data) {
|
||||||
$indicators = [];
|
$indicators = [];
|
||||||
|
|
||||||
if (! empty($data['Plant'])) {
|
if (!empty($data['Plant'])) {
|
||||||
$indicators[] = 'Plant: '.Plant::where('id', $data['Plant'])->value('name');
|
$indicators[] = 'Plant: ' . Plant::where('id', $data['Plant'])->value('name');
|
||||||
} else {
|
|
||||||
$userHas = Filament::auth()->user()->plant_id;
|
|
||||||
|
|
||||||
if ($userHas && strlen($userHas) > 0) {
|
|
||||||
return 'Plant: Choose plant to filter records.';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! empty($data['Shift'])) {
|
if (!empty($data['Shift'])) {
|
||||||
$indicators[] = 'Shift: '.Shift::where('id', $data['Shift'])->value('name');
|
$indicators[] = 'Shift: ' . Shift::where('id', $data['Shift'])->value('name');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! empty($data['Line'])) {
|
if (!empty($data['Line'])) {
|
||||||
$indicators[] = 'Line: '.Line::where('id', $data['Line'])->value('name');
|
$indicators[] = 'Line: ' . Line::where('id', $data['Line'])->value('name');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! empty($data['created_from'])) {
|
if (!empty($data['created_from'])) {
|
||||||
$indicators[] = 'From: '.$data['created_from'];
|
$indicators[] = 'From: ' . $data['created_from'];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! empty($data['created_to'])) {
|
if (!empty($data['created_to'])) {
|
||||||
$indicators[] = 'To: '.$data['created_to'];
|
$indicators[] = 'To: ' . $data['created_to'];
|
||||||
}
|
}
|
||||||
|
|
||||||
return $indicators;
|
return $indicators;
|
||||||
}),
|
})
|
||||||
])
|
])
|
||||||
->filtersFormMaxHeight('280px')
|
->filtersFormMaxHeight('280px')
|
||||||
->actions([
|
->actions([
|
||||||
@@ -663,7 +726,7 @@ class ProductionPlanResource extends Resource
|
|||||||
Tables\Actions\DeleteBulkAction::make(),
|
Tables\Actions\DeleteBulkAction::make(),
|
||||||
Tables\Actions\ForceDeleteBulkAction::make(),
|
Tables\Actions\ForceDeleteBulkAction::make(),
|
||||||
Tables\Actions\RestoreBulkAction::make(),
|
Tables\Actions\RestoreBulkAction::make(),
|
||||||
FilamentExportBulkAction::make('export'),
|
FilamentExportBulkAction::make('export')
|
||||||
]),
|
]),
|
||||||
])
|
])
|
||||||
->headerActions([
|
->headerActions([
|
||||||
@@ -671,14 +734,14 @@ class ProductionPlanResource extends Resource
|
|||||||
->label('Import Production Plans')
|
->label('Import Production Plans')
|
||||||
->color('warning')
|
->color('warning')
|
||||||
->importer(ProductionPlanImporter::class)
|
->importer(ProductionPlanImporter::class)
|
||||||
->visible(function () {
|
->visible(function() {
|
||||||
return Filament::auth()->user()->can('view import production plan');
|
return Filament::auth()->user()->can('view import production plan');
|
||||||
}),
|
}),
|
||||||
ExportAction::make()
|
ExportAction::make()
|
||||||
->label('Export Production Plans')
|
->label('Export Production Plans')
|
||||||
->color('warning')
|
->color('warning')
|
||||||
->exporter(ProductionPlanExporter::class)
|
->exporter(ProductionPlanExporter::class)
|
||||||
->visible(function () {
|
->visible(function() {
|
||||||
return Filament::auth()->user()->can('view export production plan');
|
return Filament::auth()->user()->can('view export production plan');
|
||||||
}),
|
}),
|
||||||
]);
|
]);
|
||||||
|
|||||||
@@ -12,13 +12,11 @@ class Item extends Model
|
|||||||
|
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'plant_id',
|
'plant_id',
|
||||||
'line_id',
|
|
||||||
'category',
|
'category',
|
||||||
'code',
|
'code',
|
||||||
'description',
|
'description',
|
||||||
'hourly_quantity',
|
'hourly_quantity',
|
||||||
'uom',
|
'uom',
|
||||||
'line_capacity',
|
|
||||||
];
|
];
|
||||||
|
|
||||||
public function plant(): BelongsTo
|
public function plant(): BelongsTo
|
||||||
@@ -26,11 +24,6 @@ class Item extends Model
|
|||||||
return $this->belongsTo(Plant::class);
|
return $this->belongsTo(Plant::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function line(): BelongsTo
|
|
||||||
{
|
|
||||||
return $this->belongsTo(Line::class);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function stickerMasters()
|
public function stickerMasters()
|
||||||
{
|
{
|
||||||
return $this->hasMany(StickerMaster::class, 'item_id', 'id');
|
return $this->hasMany(StickerMaster::class, 'item_id', 'id');
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ class Line extends Model
|
|||||||
|
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
"plant_id",
|
"plant_id",
|
||||||
"block_id",
|
|
||||||
"name",
|
"name",
|
||||||
"type",
|
"type",
|
||||||
"group_work_center",
|
"group_work_center",
|
||||||
@@ -35,11 +34,6 @@ class Line extends Model
|
|||||||
return $this->belongsTo(Plant::class);
|
return $this->belongsTo(Plant::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function block(): BelongsTo
|
|
||||||
{
|
|
||||||
return $this->belongsTo(Block::class);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testingPanelReadings()
|
public function testingPanelReadings()
|
||||||
{
|
{
|
||||||
return $this->hasMany(TestingPanelReading::class);
|
return $this->hasMany(TestingPanelReading::class);
|
||||||
|
|||||||
@@ -12,15 +12,12 @@ class ProductionPlan extends Model
|
|||||||
|
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
"plant_id",
|
"plant_id",
|
||||||
"item_id",
|
|
||||||
"shift_id",
|
"shift_id",
|
||||||
"created_at",
|
"created_at",
|
||||||
"line_id",
|
"line_id",
|
||||||
"plan_quantity",
|
"plan_quantity",
|
||||||
"production_quantity",
|
"production_quantity",
|
||||||
"operator_id",
|
"operator_id",
|
||||||
"working_days",
|
|
||||||
"leave_dates",
|
|
||||||
];
|
];
|
||||||
|
|
||||||
public function plant(): BelongsTo
|
public function plant(): BelongsTo
|
||||||
@@ -37,9 +34,4 @@ class ProductionPlan extends Model
|
|||||||
{
|
{
|
||||||
return $this->belongsTo(Line::class);
|
return $this->belongsTo(Line::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function item(): BelongsTo
|
|
||||||
{
|
|
||||||
return $this->belongsTo(Item::class);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ class ProductionQuantity extends Model
|
|||||||
|
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
"plant_id",
|
"plant_id",
|
||||||
"machine_id",
|
|
||||||
"shift_id",
|
"shift_id",
|
||||||
"line_id",
|
"line_id",
|
||||||
"item_id",
|
"item_id",
|
||||||
@@ -51,11 +50,6 @@ class ProductionQuantity extends Model
|
|||||||
return $this->belongsTo(Item::class);
|
return $this->belongsTo(Item::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function machine(): BelongsTo
|
|
||||||
{
|
|
||||||
return $this->belongsTo(Machine::class);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected static function booted()
|
protected static function booted()
|
||||||
{
|
{
|
||||||
static::created(function ($productionQuantity) {
|
static::created(function ($productionQuantity) {
|
||||||
|
|||||||
@@ -45,7 +45,7 @@
|
|||||||
</div> --}}
|
</div> --}}
|
||||||
<div class="flex gap-6 -mt-6">
|
<div class="flex gap-6 -mt-6">
|
||||||
<!-- Scan QR Code -->
|
<!-- Scan QR Code -->
|
||||||
<div class="w-full">
|
<div class="w-1/2">
|
||||||
<label for="qr-scan-input" class="block text-sm font-medium text-gray-700 mb-2">
|
<label for="qr-scan-input" class="block text-sm font-medium text-gray-700 mb-2">
|
||||||
SCAN QR CODE
|
SCAN QR CODE
|
||||||
</label>
|
</label>
|
||||||
@@ -60,7 +60,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Last Scanned QR -->
|
<!-- Last Scanned QR -->
|
||||||
{{-- <div class="w-1/2">
|
<div class="w-1/2">
|
||||||
<label for="recent-qr-input" class="block text-sm font-medium text-gray-700 mb-2">
|
<label for="recent-qr-input" class="block text-sm font-medium text-gray-700 mb-2">
|
||||||
LAST SCANNED QR
|
LAST SCANNED QR
|
||||||
</label>
|
</label>
|
||||||
@@ -71,7 +71,7 @@
|
|||||||
readonly
|
readonly
|
||||||
wire:model="recent_qr"
|
wire:model="recent_qr"
|
||||||
/>
|
/>
|
||||||
</div> --}}
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user