Compare commits
52 Commits
a09adf0ea5
...
renovate/a
| Author | SHA1 | Date | |
|---|---|---|---|
| e501e91673 | |||
| 8a0e7d6878 | |||
|
|
81d2f4bd2c | ||
| d1031d8a6e | |||
|
|
c3d4a97277 | ||
| fa06c2c6cb | |||
|
|
d243f53f2f | ||
| e06a458fc0 | |||
|
|
878e12eff5 | ||
| 36dd07817b | |||
|
|
cddc8a1b70 | ||
| 51a20219db | |||
|
|
95217ce722 | ||
| dc564f9c28 | |||
|
|
9ba54dabf1 | ||
|
|
3c4a4bf136 | ||
|
|
0e651e8bcc | ||
| bab5b879e6 | |||
|
|
c3a4985f45 | ||
| a09264a053 | |||
|
|
95c27d6821 | ||
| 82f776ef41 | |||
|
|
8fedc01efd | ||
| 952b9a01a5 | |||
|
|
4abdd1b81e | ||
| 2b8a3a2838 | |||
|
|
10c2abb881 | ||
|
|
934447d0b2 | ||
| 4acb66c464 | |||
|
|
b4acea8144 | ||
| ea64aea9ce | |||
|
|
9e59f3d0fb | ||
| 72e6621cc0 | |||
|
|
e6bf48055f | ||
| 2c49e6b272 | |||
|
|
c3fa25090d | ||
| d6ec50c20e | |||
|
|
14da244965 | ||
| 19382d0644 | |||
|
|
8d1e1e6e53 | ||
|
|
58e6e9df56 | ||
|
|
bec1a17970 | ||
| 408e426545 | |||
|
|
3c971e2ce7 | ||
|
|
7793477c2d | ||
|
|
8204043122 | ||
|
|
fd1c3a8094 | ||
|
|
8f34ec0d86 | ||
| 62b338be22 | |||
|
|
5ba59e10bd | ||
| c407f9c6c2 | |||
|
|
b9812cbe32 |
61
app/Exports/ProductionPlanExport.php
Normal file
61
app/Exports/ProductionPlanExport.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?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 . ' - Line Capacity';
|
||||
$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'] ?? '',
|
||||
];
|
||||
|
||||
foreach ($this->dates as $date) {
|
||||
$mapped[] = $row['daily_line_capacity'][$date] ?? '-';
|
||||
$mapped[] = $row['daily_target_dynamic'][$date] ?? '-';
|
||||
$mapped[] = $row['produced_quantity'][$date] ?? '-';
|
||||
}
|
||||
return $mapped;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -36,12 +36,14 @@ class CharacteristicValueExporter extends Exporter
|
||||
->label('COIL NUMBER'),
|
||||
ExportColumn::make('status')
|
||||
->label('STATUS'),
|
||||
ExportColumn::make('observed_value')
|
||||
->label('OBSERVED VALUE'),
|
||||
ExportColumn::make('created_at')
|
||||
->label('CREATED AT'),
|
||||
ExportColumn::make('updated_at')
|
||||
->label('UPDATED AT'),
|
||||
ExportColumn::make('created_by')
|
||||
->label('CREATED BY'),
|
||||
ExportColumn::make('updated_at')
|
||||
->label('UPDATED AT'),
|
||||
ExportColumn::make('updated_by')
|
||||
->label('UPDATED BY'),
|
||||
ExportColumn::make('deleted_at')
|
||||
|
||||
@@ -24,6 +24,8 @@ class ProcessOrderExporter extends Exporter
|
||||
}),
|
||||
ExportColumn::make('plant.code')
|
||||
->label('PLANT CODE'),
|
||||
ExportColumn::make('line.name')
|
||||
->label('LINE NAME'),
|
||||
ExportColumn::make('item.code')
|
||||
->label('ITEM CODE'),
|
||||
ExportColumn::make('process_order')
|
||||
@@ -37,13 +39,17 @@ class ProcessOrderExporter extends Exporter
|
||||
ExportColumn::make('sfg_number')
|
||||
->label('SFG NUMBER'),
|
||||
ExportColumn::make('machine_name')
|
||||
->label('MACHINE ID'),
|
||||
->label('MACHINE NAME'),
|
||||
ExportColumn::make('scrap_quantity')
|
||||
->label('SCRAP QUANTITY'),
|
||||
ExportColumn::make('rework_status')
|
||||
->label('REWORK STATUS'),
|
||||
ExportColumn::make('created_at')
|
||||
->label('CREATED AT'),
|
||||
ExportColumn::make('updated_at')
|
||||
->label('UPDATED AT'),
|
||||
ExportColumn::make('created_by')
|
||||
->label('CREATED BY'),
|
||||
ExportColumn::make('updated_at')
|
||||
->label('UPDATED AT'),
|
||||
ExportColumn::make('updated_by')
|
||||
->label('UPDATED BY'),
|
||||
ExportColumn::make('deleted_at')
|
||||
|
||||
@@ -29,7 +29,7 @@ class ProductCharacteristicsMasterExporter extends Exporter
|
||||
ExportColumn::make('line.name')
|
||||
->label('LINE NAME'), // machine.workGroupMaster.name
|
||||
ExportColumn::make('machine.workGroupMaster.name')
|
||||
->label('WORK GROUP MASTER'),
|
||||
->label('GROUP WORK CENTER'),
|
||||
ExportColumn::make('machine.work_center')
|
||||
->label('WORK CENTER'),
|
||||
ExportColumn::make('characteristics_type')
|
||||
|
||||
@@ -8,10 +8,14 @@ use App\Models\Line;
|
||||
use App\Models\Machine;
|
||||
use App\Models\Plant;
|
||||
use App\Models\ProcessOrder;
|
||||
use App\Models\ProductCharacteristicsMaster;
|
||||
use App\Models\User;
|
||||
use Carbon\Carbon;
|
||||
use Filament\Actions\Imports\Exceptions\RowImportFailedException;
|
||||
use Filament\Actions\Imports\ImportColumn;
|
||||
use Filament\Actions\Imports\Importer;
|
||||
use Filament\Actions\Imports\Models\Import;
|
||||
use Filament\Facades\Filament;
|
||||
use Str;
|
||||
|
||||
class CharacteristicValueImporter extends Importer
|
||||
@@ -64,11 +68,28 @@ class CharacteristicValueImporter extends Importer
|
||||
->exampleHeader('Status')
|
||||
->example('Ok')
|
||||
->label('Status'),
|
||||
ImportColumn::make('observed_value')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Observed Value')
|
||||
->example('RAW01234')
|
||||
->label('Observed Value'),
|
||||
ImportColumn::make('created_by')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Created By')
|
||||
->example('RAW01234')
|
||||
->label('Created By'),
|
||||
ImportColumn::make('created_at')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Created DateTime')
|
||||
->example('01-01-2025 08:00:00')
|
||||
->label('Created DateTime')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('updated_at')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Updated DateTime')
|
||||
->example('01-01-2025 08:00:00')
|
||||
->label('Updated DateTime')
|
||||
->rules(['required']),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -82,30 +103,39 @@ class CharacteristicValueImporter extends Importer
|
||||
$warnMsg = [];
|
||||
$plantId = null;
|
||||
$itemId = null;
|
||||
$LineId = null;
|
||||
$lineId = null;
|
||||
$machineId = null;
|
||||
$itemAgainstPlant = null;
|
||||
// $itemAgainstPlant = null;
|
||||
|
||||
$plantCode = $this->data['plant'];
|
||||
$processOrder = trim($this->data['process_order'] ?? '');
|
||||
$iCode = trim($this->data['item']);
|
||||
$workCenter = trim($this->data['machine']);
|
||||
$lineName = trim($this->data['line']);
|
||||
$coilNo = trim($this->data['coil_number']);
|
||||
$obserVal = trim($this->data['observed_value']);
|
||||
$status = trim($this->data['status']);
|
||||
$createdBy = trim($this->data['created_by']);
|
||||
$coilNo = trim($this->data['coil_number']);
|
||||
|
||||
if ($plantCode == null || $plantCode == '') {
|
||||
$warnMsg[] = 'Plant code cannot be empty';
|
||||
} elseif ($iCode == null || $iCode == '') {
|
||||
} elseif ($iCode == null || $iCode == '') {// process_order
|
||||
$warnMsg[] = 'Item code cannot be empty';
|
||||
} elseif ($processOrder == null || $processOrder == '') {//
|
||||
$warnMsg[] = 'Process Order cannot be empty';
|
||||
} elseif ($workCenter == null || $workCenter == '') {
|
||||
$warnMsg[] = 'Work center cannot be empty';
|
||||
} elseif ($lineName == null || $lineName == '') {
|
||||
$warnMsg[] = 'Line cannot be empty';
|
||||
$warnMsg[] = 'Line name cannot be empty';
|
||||
} elseif ($coilNo == null || $coilNo == '') {
|
||||
$warnMsg[] = 'Coil number cannot be empty';
|
||||
} elseif ($obserVal == null || $obserVal == '') {
|
||||
$warnMsg[] = 'Observed value cannot be empty';
|
||||
} elseif ($status == null || $status == '') {
|
||||
$warnMsg[] = 'Status cannot be empty';
|
||||
}
|
||||
|
||||
if (Str::length($plantCode) < 4 || ! is_numeric($plantCode) || ! preg_match('/^[1-9]\d{3,}$/', $plantCode)) {
|
||||
if (Str::length($plantCode) > 0 && (Str::length($plantCode) < 4 || ! is_numeric($plantCode) || ! preg_match('/^[1-9]\d{3,}$/', $plantCode))) {
|
||||
$warnMsg[] = 'Invalid plant code found';
|
||||
} else {
|
||||
$plant = Plant::where('code', $plantCode)->first();
|
||||
@@ -116,7 +146,7 @@ class CharacteristicValueImporter extends Importer
|
||||
}
|
||||
}
|
||||
|
||||
if (Str::length($iCode) < 6 || ! ctype_alnum($iCode)) {
|
||||
if (Str::length($iCode) > 0 && (Str::length($iCode) < 6 || ! ctype_alnum($iCode))) {
|
||||
$warnMsg[] = 'Invalid item code found';
|
||||
} else {
|
||||
$itemCode = Item::where('code', $iCode)->first();
|
||||
@@ -124,11 +154,11 @@ class CharacteristicValueImporter extends Importer
|
||||
$warnMsg[] = 'Item code not found';
|
||||
} else {
|
||||
if ($plantId) {
|
||||
$itemAgainstPlant = Item::where('code', $iCode)->where('plant_id', $plantId)->first();
|
||||
if (! $itemAgainstPlant) {
|
||||
$itemCode = Item::where('code', $iCode)->where('plant_id', $plantId)->first();
|
||||
if (! $itemCode) {
|
||||
$warnMsg[] = 'Item code not found for the given plant';
|
||||
} else {
|
||||
$itemId = $itemAgainstPlant->id;
|
||||
$itemId = $itemCode->id;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -143,7 +173,7 @@ class CharacteristicValueImporter extends Importer
|
||||
if (! $lineAgainstPlant) {
|
||||
$warnMsg[] = 'Line name not found for the given plant';
|
||||
} else {
|
||||
$LineId = $lineAgainstPlant->id;
|
||||
$lineId = $lineAgainstPlant->id;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -163,9 +193,9 @@ class CharacteristicValueImporter extends Importer
|
||||
// $MachineId = $workCenterAgainstPlant->id;
|
||||
// }
|
||||
|
||||
if ($plantId != null && $LineId != null) {
|
||||
if ($plantId != null && $lineId != null) {
|
||||
$machineAgaPlantLine = Machine::where('plant_id', $plantId)
|
||||
->where('line_id', $LineId)
|
||||
->where('line_id', $lineId)
|
||||
->where('work_center', $workCenter)
|
||||
->first();
|
||||
|
||||
@@ -176,34 +206,66 @@ class CharacteristicValueImporter extends Importer
|
||||
}
|
||||
}
|
||||
|
||||
if ($processOrder == null || $processOrder == '') {
|
||||
$warnMsg[] = 'Process Order cannot be empty';
|
||||
}
|
||||
|
||||
if ($coilNo == null || $coilNo == '') {
|
||||
$warnMsg[] = 'Coil No cannot be empty';
|
||||
} elseif (! is_numeric($coilNo)) {
|
||||
if (Str::length($coilNo) > 0 && ! is_numeric($coilNo)) {
|
||||
$warnMsg[] = 'Coil number should contain only numeric values!';
|
||||
}
|
||||
|
||||
if ($status == null || $status == '' || ! $status) {
|
||||
$warnMsg[] = 'Status cannot be empty';
|
||||
} elseif (! in_array($status, ['Ok', 'NotOk'], true)) {
|
||||
if (Str::length($obserVal) > 0 && ! is_numeric($obserVal)) {
|
||||
$warnMsg[] = 'Observed value should contain only numeric values!';
|
||||
}
|
||||
|
||||
if (Str::length($status) > 0 && ! in_array($status, ['Ok', 'NotOk'], true)) {
|
||||
$warnMsg[] = "Status must be either 'Ok' or 'NotOk'!";
|
||||
}
|
||||
// else {
|
||||
// if (Str::length($status) <= 0 || ! is_numeric($status) || ! preg_match('/^\d+(\.\d+)?$/', $status)
|
||||
// ) {
|
||||
// $status = 'NotOk';
|
||||
// } else {
|
||||
// $specVal = ProductCharacteristicsMaster::where('plant_id', $plantId)->where('item_id', $itemId)->where('line_id', $lineId)->where('machine_id', $machineId)->first();
|
||||
// if (! $specVal) {
|
||||
// $status = 'NotOk';
|
||||
// }
|
||||
|
||||
// $lowLimit = $specVal?->lower ?? 0;
|
||||
// $uppLimit = $specVal?->upper ?? 0;
|
||||
|
||||
// if (Str::length($lowLimit) <= 0 || ! is_numeric($lowLimit) || ! preg_match('/^\d+(\.\d+)?$/', $lowLimit)
|
||||
// ) {
|
||||
// $status = 'NotOk';
|
||||
// } elseif (Str::length($uppLimit) <= 0 || ! is_numeric($uppLimit) || ! preg_match('/^\d+(\.\d+)?$/', $uppLimit)
|
||||
// ) {
|
||||
// $status = 'NotOk';
|
||||
// }
|
||||
|
||||
// if (($lowLimit == 0 && $uppLimit == 0) || ($uppLimit == 0)) {
|
||||
// $status = 'NotOk';
|
||||
// }
|
||||
|
||||
// if ($lowLimit > $obserVal || $uppLimit < $obserVal) {
|
||||
// $status = 'NotOk';
|
||||
// }
|
||||
// $status = 'Ok';
|
||||
// }
|
||||
// }
|
||||
|
||||
if ($createdBy == null || $createdBy == '' || ! $createdBy) {
|
||||
$warnMsg[] = 'Created By cannot be empty';
|
||||
}
|
||||
|
||||
// $existing = CharacteristicValue::where('plant_id', $plantId)
|
||||
// ->where('process_order', $processOrder)
|
||||
// ->where('coil_number', $coilNo)
|
||||
// ->first();
|
||||
if ($plantId) {
|
||||
$user = User::where('name', $createdBy)->first();
|
||||
|
||||
// if ($existing) {
|
||||
// $warnMsg[] = "Process order '{$processOrder}' with coil number '{$coilNo}' already exist for the plant code '{$plantCode}'!";
|
||||
// }
|
||||
$userPlant = User::where('name', $createdBy)->where('plant_id', $plantId)->first();
|
||||
|
||||
if (! $user) {
|
||||
$warnMsg[] = 'Created By user name not found!';
|
||||
} elseif (! $userPlant && ! $user->hasRole('Super Admin')) {
|
||||
$warnMsg[] = "Created By user '{$createdBy}' not found for Plant '{$plantCode}'!";
|
||||
} elseif (! $user->hasRole(['Super Admin', 'Process Quality Manager', 'Process Manager', 'Process Supervisor', 'Process Employee'])) {
|
||||
$warnMsg[] = 'Created By user does not have rights!';
|
||||
}
|
||||
}
|
||||
|
||||
if ($plantId && $processOrder) {
|
||||
$existing = CharacteristicValue::where('plant_id', $plantId)
|
||||
@@ -216,31 +278,81 @@ class CharacteristicValueImporter extends Importer
|
||||
}
|
||||
}
|
||||
|
||||
if ($plant && $itemCode && $processOrder != '') {
|
||||
if ($plant && $itemCode && $processOrder != '' && $processOrder != null) {
|
||||
|
||||
$existingOrder = ProcessOrder::where('plant_id', $plant->id)
|
||||
$existingOrder = ProcessOrder::where('plant_id', $plantId)
|
||||
->where('process_order', $processOrder)
|
||||
->first();
|
||||
|
||||
if ($existingOrder && $existingOrder->item_id !== ($itemCode->id ?? null)) {
|
||||
if ($existingOrder && $existingOrder->item_id !== ($itemId ?? null)) {
|
||||
$warnMsg[] = 'Same Process Order already exists for this Plant with a different Item Code';
|
||||
}
|
||||
}
|
||||
|
||||
$updatedBy = Filament::auth()->user()->name; // ?? 'Admin'
|
||||
if (! $updatedBy) {
|
||||
$warnMsg[] = 'Invalid updated by user name found';
|
||||
}
|
||||
|
||||
$fromDate = $this->data['created_at'];
|
||||
$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) {
|
||||
// $warnMsg[] = "Date format mismatch with format: $format";
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($formats as $format) {
|
||||
try {
|
||||
$tdateTime = Carbon::createFromFormat($format, $toDate);
|
||||
break;
|
||||
} catch (\Exception $e) {
|
||||
// $warnMsg[] = "Date format mismatch with format: $format";
|
||||
}
|
||||
}
|
||||
|
||||
if (! isset($fdateTime)) {
|
||||
$warnMsg[] = "Invalid 'Created DateTime' format. Expected DD-MM-YYYY HH:MM:SS";
|
||||
}
|
||||
if (! isset($tdateTime)) {
|
||||
$warnMsg[] = "Invalid 'Updated DateTime' format. Expected DD-MM-YYYY HH:MM:SS";
|
||||
}
|
||||
|
||||
if (isset($fdateTime) && isset($tdateTime)) {
|
||||
if ($fdateTime->greaterThan($tdateTime)) {
|
||||
$warnMsg[] = "'Created DataTime' is greater than 'Updated DateTime'.";
|
||||
}
|
||||
}
|
||||
|
||||
if (! empty($warnMsg)) {
|
||||
throw new RowImportFailedException(implode(', ', $warnMsg));
|
||||
}
|
||||
|
||||
return CharacteristicValue::create([
|
||||
return CharacteristicValue::updateOrCreate([
|
||||
'plant_id' => $plantId,
|
||||
'item_id' => $itemId,
|
||||
'line_id' => $LineId,
|
||||
'machine_id' => $machineId,
|
||||
'process_order' => trim($this->data['process_order']),
|
||||
'coil_number' => trim($this->data['coil_number']),
|
||||
'status' => trim($this->data['status']),
|
||||
'created_by' => trim($this->data['created_by']),
|
||||
]);
|
||||
'process_order' => $processOrder,
|
||||
'coil_number' => $coilNo,
|
||||
],
|
||||
[
|
||||
'item_id' => $itemId,
|
||||
'line_id' => $lineId,
|
||||
'machine_id' => $machineId,
|
||||
'status' => $status,
|
||||
'observed_value' => $obserVal,
|
||||
'created_by' => $createdBy,
|
||||
'updated_by' => $updatedBy,
|
||||
'created_at' => $fdateTime->format('Y-m-d H:i:s'),
|
||||
'updated_at' => $tdateTime->format('Y-m-d H:i:s'),
|
||||
]);
|
||||
|
||||
// return null;
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Filament\Imports;
|
||||
|
||||
use App\Models\Item;
|
||||
use App\Models\Line;
|
||||
use App\Models\Plant;
|
||||
use App\Models\ProcessOrder;
|
||||
use App\Models\User;
|
||||
@@ -27,6 +28,11 @@ class ProcessOrderImporter extends Importer
|
||||
->label('PLANT CODE')
|
||||
->relationship(resolveUsing: 'code')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('line')
|
||||
->exampleHeader('LINE NAME')
|
||||
->example(' Polywrapped line')
|
||||
->label('LINE NAME')
|
||||
->relationship(resolveUsing: 'name'),
|
||||
ImportColumn::make('item')
|
||||
->requiredMapping()
|
||||
->exampleHeader('ITEM CODE')
|
||||
@@ -35,20 +41,57 @@ class ProcessOrderImporter extends Importer
|
||||
->relationship(resolveUsing: 'code')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('process_order')
|
||||
->requiredMapping()
|
||||
->exampleHeader('PROCESS ORDER')
|
||||
->example('202500123456')
|
||||
->label('PROCESS ORDER')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('coil_number')
|
||||
->exampleHeader('COIL NUMBER')
|
||||
->example('01')
|
||||
->label('COIL NUMBER'),
|
||||
ImportColumn::make('order_quantity')
|
||||
->requiredMapping()
|
||||
->exampleHeader('ORDER QUANTITY')
|
||||
->example('100')
|
||||
->label('ORDER QUANTITY')
|
||||
->rules(['required']),
|
||||
// ImportColumn::make('created_by')
|
||||
// ->exampleHeader('CREATED BY')
|
||||
// ->example('RAW01234')
|
||||
// ->label('CREATED BY')
|
||||
// ->rules(['required']),
|
||||
ImportColumn::make('received_quantity')
|
||||
->exampleHeader('RECEIVED QUANTITY')
|
||||
->example('01')
|
||||
->label('RECEIVED QUANTITY'),
|
||||
ImportColumn::make('sfg_number')
|
||||
->exampleHeader('SFG NUMBER')
|
||||
->example('200000220613-72')
|
||||
->label('SFG NUMBER'),
|
||||
ImportColumn::make('machine_name')
|
||||
->exampleHeader('MACHINE NAME')
|
||||
->example('WMIWRM13 - 2-L2')
|
||||
->label('MACHINE NAME'),
|
||||
ImportColumn::make('scrap_quantity')
|
||||
->exampleHeader('SCRAP QUANTITY')
|
||||
->example('0')
|
||||
->label('SCRAP QUANTITY'),
|
||||
ImportColumn::make('rework_status')
|
||||
->exampleHeader('REWORK STATUS')
|
||||
->example('0')
|
||||
->label('REWORK STATUS'),
|
||||
ImportColumn::make('created_at')
|
||||
->exampleHeader('CREATED AT')
|
||||
->example('2026-02-20 13:00:00')
|
||||
->label('CREATED AT'),
|
||||
ImportColumn::make('updated_at')
|
||||
->exampleHeader('UPDATED AT')
|
||||
->example('2026-02-20 13:00:00')
|
||||
->label('UPDATED AT'),
|
||||
ImportColumn::make('created_by')
|
||||
->exampleHeader('CREATED BY')
|
||||
->example('RAW01234')
|
||||
->label('CREATED BY'),
|
||||
ImportColumn::make('updated_by')
|
||||
->exampleHeader('UPDATED BY')
|
||||
->example('RAW01234')
|
||||
->label('UPDATED BY'),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -57,10 +100,56 @@ class ProcessOrderImporter extends Importer
|
||||
$warnMsg = [];
|
||||
$plantCod = $this->data['plant'];
|
||||
$plant = null;
|
||||
$plantId = null;
|
||||
$itemId = null;
|
||||
$iCode = trim($this->data['item']);
|
||||
$lineName = trim($this->data['line']);
|
||||
$processOrder = trim($this->data['process_order'] ?? '');
|
||||
$user = Filament::auth()->user();
|
||||
$operatorName = $user->name;
|
||||
$coilNo = trim($this->data['coil_number'] ?? '');
|
||||
$sfgNo = trim($this->data['sfg_number'] ?? '');
|
||||
$machineName = trim($this->data['machine_name'] ?? '');
|
||||
$orderQuan = trim($this->data['order_quantity'] ?? '');
|
||||
$scrapQuan = trim($this->data['scrap_quantity'] ?? '');
|
||||
$reworkStatus = trim($this->data['rework_status'] ?? '');
|
||||
$recQuan = trim($this->data['received_quantity'] ?? '');
|
||||
$createdAt = trim($this->data['created_at'] ?? '');
|
||||
$createdBy = trim($this->data['created_by'] ?? '');
|
||||
$updatedAt = trim($this->data['updated_at'] ?? '');
|
||||
$updatedBy = trim($this->data['updated_by'] ?? '');
|
||||
// $user = Filament::auth()->user();
|
||||
// $operatorName = $user->name;
|
||||
|
||||
if ($plantCod == null || $plantCod == '') {
|
||||
$warnMsg[] = 'Plant code cannot be empty';
|
||||
}
|
||||
if ($iCode == null || $iCode == '') {
|
||||
$warnMsg[] = 'Item code cannot be empty';
|
||||
}
|
||||
if ($processOrder == null || $processOrder == '') {
|
||||
$warnMsg[] = 'Process order cannot be empty';
|
||||
}
|
||||
if ($orderQuan == null || $orderQuan == '') {
|
||||
$warnMsg[] = 'Order quantity cannot be empty';
|
||||
} elseif ($orderQuan == 0 || $orderQuan == '0') {
|
||||
$warnMsg[] = 'Order quantity cannot be zero';
|
||||
}
|
||||
if ($coilNo == null || $coilNo == '') {
|
||||
$coilNo = '0';
|
||||
}
|
||||
if ($scrapQuan == null || $scrapQuan == '') {
|
||||
$scrapQuan = 0;
|
||||
}
|
||||
if ($recQuan == null || $recQuan == '') {
|
||||
$recQuan = 0;
|
||||
}
|
||||
if ($reworkStatus == null || $reworkStatus = '') {
|
||||
$reworkStatus = 0;
|
||||
}
|
||||
|
||||
if ($createdBy == null || $createdBy == '') {
|
||||
$createdBy = Filament::auth()->user()?->name;
|
||||
$updatedBy = $createdBy;
|
||||
}
|
||||
|
||||
if (Str::length($plantCod) < 4 || ! is_numeric($plantCod) || ! preg_match('/^[1-9]\d{3,}$/', $plantCod)) {
|
||||
$warnMsg[] = 'Invalid plant code found';
|
||||
@@ -68,6 +157,8 @@ class ProcessOrderImporter extends Importer
|
||||
$plant = Plant::where('code', $plantCod)->first();
|
||||
if (! $plant) {
|
||||
$warnMsg[] = 'Plant not found';
|
||||
} else {
|
||||
$plantId = $plant->id;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,43 +167,169 @@ class ProcessOrderImporter extends Importer
|
||||
} else {
|
||||
$itemCode = Item::where('code', $iCode)->first();
|
||||
if (! $itemCode) {
|
||||
$warnMsg[] = 'Item Code not found';
|
||||
$warnMsg[] = 'Item code not found';
|
||||
} else {
|
||||
if ($plantId) {
|
||||
$itemCode = Item::where('code', $iCode)->where('plant_id', $plantId)->first();
|
||||
if (! $itemCode) {
|
||||
$warnMsg[] = 'Item code not found for the given plant';
|
||||
} else {
|
||||
$itemId = $itemCode->id;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($processOrder == '') {
|
||||
$warnMsg[] = 'Process Order cannot be empty';
|
||||
}
|
||||
|
||||
// $user = User::where('name', $this->data['created_by'])->first();
|
||||
// if (! $user) {
|
||||
// $warnMsg[] = 'User not found';
|
||||
// }
|
||||
|
||||
if ($plant && $itemCode && $processOrder != '') {
|
||||
|
||||
$existingOrder = ProcessOrder::where('plant_id', $plant->id)
|
||||
$existingOrder = ProcessOrder::where('plant_id', $plantId)
|
||||
->where('process_order', $processOrder)
|
||||
->first();
|
||||
|
||||
if ($existingOrder && $existingOrder->item_id !== ($itemCode->id ?? null)) {
|
||||
if ($existingOrder && $existingOrder->item_id !== ($itemId ?? null)) {
|
||||
$warnMsg[] = 'Same Process Order already exists for this Plant with a different Item Code';
|
||||
}
|
||||
}
|
||||
|
||||
if ($lineName != null && $lineName != '') {
|
||||
$lineExists = Line::where('name', $lineName)->first();
|
||||
if (! $lineExists) {
|
||||
$warnMsg[] = 'Line name not found';
|
||||
} else {
|
||||
if ($plantId) {
|
||||
$lineAgainstPlant = Line::where('name', $lineName)->where('plant_id', $plantId)->first();
|
||||
if (! $lineAgainstPlant) {
|
||||
$warnMsg[] = 'Line name not found for the given plant';
|
||||
} else {
|
||||
$lineId = $lineAgainstPlant->id;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$lineId = null;
|
||||
}
|
||||
|
||||
if ($createdBy != null && $createdBy != '') {
|
||||
if ($plantId) {
|
||||
$user = User::where('name', $createdBy)->first();
|
||||
|
||||
$userPlant = User::where('name', $createdBy)->where('plant_id', $plantId)->first();
|
||||
|
||||
if (! $user) {
|
||||
$warnMsg[] = 'Created By user name not found!';
|
||||
} elseif (! $userPlant && ! $user->hasRole('Super Admin')) {
|
||||
$warnMsg[] = "Created By user '{$createdBy}' not found for Plant '{$plantCod}'!";
|
||||
} elseif (! $user->hasRole(['Super Admin', 'Process Quality Manager', 'Process Manager', 'Process Supervisor', 'Process Employee'])) {
|
||||
$warnMsg[] = 'Created By user does not have rights!';
|
||||
}
|
||||
}
|
||||
$updatedBy = Filament::auth()->user()?->name;
|
||||
}
|
||||
|
||||
if (! empty($warnMsg)) {
|
||||
throw new RowImportFailedException(implode(', ', $warnMsg));
|
||||
}
|
||||
|
||||
return ProcessOrder::create([
|
||||
'plant_id' => $plant->id,
|
||||
'item_id' => $itemCode->id,
|
||||
'process_order' => trim($this->data['process_order']),
|
||||
'coil_number' => '0',
|
||||
'order_quantity' => 0,
|
||||
'received_quantity' => 0,
|
||||
'created_by' => $operatorName,
|
||||
]);
|
||||
if ($lineName != null && $lineName != '') {
|
||||
$existingCoil = ProcessOrder::where('plant_id', $plantId)
|
||||
->where('process_order', $processOrder)
|
||||
->where('line_id', $lineId)
|
||||
->where('coil_number', $coilNo)
|
||||
->first();
|
||||
|
||||
if (! $existingCoil) {
|
||||
ProcessOrder::Create(
|
||||
[
|
||||
'plant_id' => $plantId,
|
||||
'line_id' => $lineId,
|
||||
'process_order' => $processOrder,
|
||||
'item_id' => $itemId,
|
||||
'coil_number' => $coilNo,
|
||||
'order_quantity' => $orderQuan,
|
||||
'received_quantity' => $recQuan,
|
||||
'scrap_quantity' => $scrapQuan,
|
||||
'sfg_number' => $sfgNo,
|
||||
'machine_name' => $machineName,
|
||||
'rework_status' => $reworkStatus,
|
||||
'created_at' => $createdAt,
|
||||
'updated_at' => $updatedAt,
|
||||
'created_by' => $createdBy,
|
||||
'updated_by' => $updatedBy,
|
||||
]
|
||||
);
|
||||
} else {
|
||||
ProcessOrder::where('plant_id', $plantId)
|
||||
->where('process_order', $processOrder)
|
||||
->where('line_id', $lineId)
|
||||
->where('coil_number', $coilNo)
|
||||
->update([
|
||||
// 'order_quantity' => $orderQty,
|
||||
'received_quantity' => $recQuan,
|
||||
'scrap_quantity' => $scrapQuan,
|
||||
// 'sfg_number' => $sfgNo,
|
||||
// 'machine_name' => $machineId,
|
||||
'rework_status' => $reworkStatus,
|
||||
'updated_by' => $updatedBy,
|
||||
'updated_at' => $updatedAt,
|
||||
]);
|
||||
}
|
||||
|
||||
} elseif ($lineName == null || $lineName == '') {
|
||||
$existing = ProcessOrder::where('plant_id', $plantId)
|
||||
->where('process_order', $processOrder)
|
||||
->where('coil_number', $coilNo)
|
||||
->first();
|
||||
|
||||
if (! $existing && $coilNo == '0' || $coilNo == 0) {
|
||||
ProcessOrder::create([
|
||||
'plant_id' => $plantId,
|
||||
'item_id' => $itemId,
|
||||
'process_order' => $processOrder,
|
||||
'coil_number' => '0',
|
||||
'order_quantity' => $orderQuan,
|
||||
'received_quantity' => 0,
|
||||
'scrap_quantity' => 0,
|
||||
'created_by' => $createdBy,
|
||||
'updated_by' => $updatedBy,
|
||||
]);
|
||||
} elseif (! $existing) {
|
||||
ProcessOrder::Create(
|
||||
[
|
||||
'plant_id' => $plantId,
|
||||
'line_id' => $lineId,
|
||||
'process_order' => $processOrder,
|
||||
'item_id' => $itemId,
|
||||
'coil_number' => $coilNo,
|
||||
'order_quantity' => $orderQuan,
|
||||
'received_quantity' => $recQuan,
|
||||
'scrap_quantity' => $scrapQuan ?? 0,
|
||||
'sfg_number' => $sfgNo,
|
||||
'machine_name' => $machineName,
|
||||
'rework_status' => $reworkStatus,
|
||||
'created_at' => $createdAt,
|
||||
'updated_at' => $updatedAt,
|
||||
'created_by' => $createdBy,
|
||||
'updated_by' => $updatedBy,
|
||||
]
|
||||
);
|
||||
} else {// $coilNo = '0'
|
||||
ProcessOrder::where('plant_id', $plantId)
|
||||
->where('process_order', $processOrder)
|
||||
->where('coil_number', $coilNo)
|
||||
->update([
|
||||
// 'order_quantity' => $orderQty,
|
||||
'received_quantity' => $recQuan,
|
||||
'scrap_quantity' => $scrapQuan,
|
||||
// 'sfg_number' => $sfgNo,
|
||||
// 'machine_name' => $machineId,
|
||||
'rework_status' => $reworkStatus,
|
||||
'updated_by' => $updatedBy,
|
||||
'updated_at' => $updatedAt,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
// return new ProcessOrder();
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ use Filament\Actions\Imports\Exceptions\RowImportFailedException;
|
||||
use Filament\Actions\Imports\ImportColumn;
|
||||
use Filament\Actions\Imports\Importer;
|
||||
use Filament\Actions\Imports\Models\Import;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Filament\Facades\Filament;
|
||||
use Str;
|
||||
|
||||
class ProductCharacteristicsMasterImporter extends Importer
|
||||
@@ -75,7 +75,7 @@ class ProductCharacteristicsMasterImporter extends Importer
|
||||
->rules(['required']),
|
||||
ImportColumn::make('lower')
|
||||
->exampleHeader('Lower')
|
||||
->example('-0.2')
|
||||
->example('0')
|
||||
->label('Lower')
|
||||
->rules(['numeric']),
|
||||
ImportColumn::make('middle')
|
||||
@@ -86,7 +86,7 @@ class ProductCharacteristicsMasterImporter extends Importer
|
||||
->rules(['numeric']),
|
||||
ImportColumn::make('upper')
|
||||
->exampleHeader('Upper')
|
||||
->example('0.2')
|
||||
->example('2')
|
||||
->label('Upper')
|
||||
->rules(['numeric']),
|
||||
ImportColumn::make('created_by')
|
||||
@@ -103,7 +103,12 @@ class ProductCharacteristicsMasterImporter extends Importer
|
||||
|
||||
$warnMsg = [];
|
||||
$plantCod = $this->data['plant'];
|
||||
$plant = null;
|
||||
$updatedBy = Filament::auth()->user()->name; // ?? 'Admin'
|
||||
$lower = null;
|
||||
$middle = null;
|
||||
$upper = null;
|
||||
$plantId = null;
|
||||
$name = trim($this->data['name']);
|
||||
if (Str::length($plantCod) < 4 || ! is_numeric($plantCod) || ! preg_match('/^[1-9]\d{3,}$/', $plantCod)) {
|
||||
$warnMsg[] = 'Invalid plant code found';
|
||||
} else {
|
||||
@@ -111,13 +116,14 @@ class ProductCharacteristicsMasterImporter extends Importer
|
||||
if (! $plant) {
|
||||
$warnMsg[] = 'Plant not found';
|
||||
} else {
|
||||
$plantId = $plant->id;
|
||||
$itemExists = Item::where('code', $this->data['item'])->first();
|
||||
if (! $itemExists) {
|
||||
$warnMsg[] = 'Item not found';
|
||||
}
|
||||
|
||||
$itemAgainstPlant = Item::where('code', $this->data['item'])
|
||||
->where('plant_id', $plant->id)
|
||||
->where('plant_id', $plantId)
|
||||
->first();
|
||||
if (! $itemAgainstPlant) {
|
||||
$warnMsg[] = 'Item code not found for the given plant';
|
||||
@@ -131,7 +137,7 @@ class ProductCharacteristicsMasterImporter extends Importer
|
||||
}
|
||||
|
||||
$lineAgainstPlant = Line::where('name', $this->data['line'])
|
||||
->where('plant_id', $plant->id)
|
||||
->where('plant_id', $plantId)
|
||||
->first();
|
||||
|
||||
if (! $lineAgainstPlant) {
|
||||
@@ -140,7 +146,7 @@ class ProductCharacteristicsMasterImporter extends Importer
|
||||
$LineId = $lineAgainstPlant->id;
|
||||
}
|
||||
|
||||
$WorkgroupMaster = WorkGroupMaster::where('name', $this->data['work_group_master_id'])->where('plant_id', $plant->id)->first();
|
||||
$WorkgroupMaster = WorkGroupMaster::where('name', $this->data['work_group_master_id'])->where('plant_id', $plantId)->first();
|
||||
if (! $WorkgroupMaster) {
|
||||
$warnMsg[] = 'Work Group Master value not found';
|
||||
} else {
|
||||
@@ -148,7 +154,7 @@ class ProductCharacteristicsMasterImporter extends Importer
|
||||
$workGroupMasterId = $WorkgroupMaster->id;
|
||||
|
||||
// 2. Now check if this WorkGroupMaster id exists in ANY of the 10 columns
|
||||
$existsInLine = Line::where('plant_id', $plant->id)
|
||||
$existsInLine = Line::where('plant_id', $plantId)
|
||||
->where(function ($q) use ($workGroupMasterId) {
|
||||
for ($i = 1; $i <= 10; $i++) {
|
||||
$q->orWhere("work_group{$i}_id", $workGroupMasterId);
|
||||
@@ -171,7 +177,7 @@ class ProductCharacteristicsMasterImporter extends Importer
|
||||
}
|
||||
|
||||
$machineAgainstPlant = Machine::where('work_center', $this->data['machine'])
|
||||
->where('plant_id', $plant->id)
|
||||
->where('plant_id', $plantId)
|
||||
->first();
|
||||
|
||||
if (! $machineAgainstPlant) {
|
||||
@@ -180,15 +186,24 @@ class ProductCharacteristicsMasterImporter extends Importer
|
||||
$machineId = $machineAgainstPlant->id;
|
||||
}
|
||||
|
||||
if ($name == null || $name == '') {
|
||||
$warnMsg[] = "Name can't be empty";
|
||||
}
|
||||
|
||||
$user = User::where('name', $this->data['created_by'])->first();
|
||||
if (! $user) {
|
||||
$warnMsg[] = 'Operator ID not found';
|
||||
}
|
||||
|
||||
$updatedBy = Filament::auth()->user()->name; // ?? 'Admin'
|
||||
if (! $updatedBy) {
|
||||
$warnMsg[] = 'Invalid updated by user name found';
|
||||
}
|
||||
|
||||
if (($this->data['inspection_type'] ?? null) == 'Value') {
|
||||
$upper = $this->data['upper'] ?? null;
|
||||
$lower = $this->data['lower'] ?? null;
|
||||
$middle = $this->data['middle'] ?? null;
|
||||
$upper = $this->data['upper'] ?? null;
|
||||
|
||||
if (is_null($upper) || is_null($lower) || is_null($middle)) {
|
||||
$warnMsg[] = "For 'Value' inspection type, Upper, Lower, and Middle values are required.";
|
||||
@@ -203,64 +218,55 @@ class ProductCharacteristicsMasterImporter extends Importer
|
||||
|
||||
if (! empty($warnMsg)) {
|
||||
throw new RowImportFailedException(implode(', ', $warnMsg));
|
||||
} else {
|
||||
$record = ProductCharacteristicsMaster::firstOrNew([
|
||||
'plant_id' => $plant->id,
|
||||
}
|
||||
|
||||
// $record = ProductCharacteristicsMaster::firstOrNew([
|
||||
// 'plant_id' => $plantId,
|
||||
// 'item_id' => $itemId,
|
||||
// 'line_id' => $LineId,
|
||||
// 'work_group_master_id' => $workGroupMasterId,
|
||||
// 'machine_id' => $machineId,
|
||||
// ]);
|
||||
// // If record is new, fill all fields
|
||||
// if (! $record->exists) {
|
||||
// $record->name = $name;
|
||||
// $record->characteristics_type = $this->data['characteristics_type'];
|
||||
// $record->inspection_type = $this->data['inspection_type'];
|
||||
// $record->lower = $this->data['lower'] ?? null;
|
||||
// $record->upper = $this->data['upper'] ?? null;
|
||||
// $record->middle = $this->data['middle'] ?? null;
|
||||
// $record->created_by = $this->data['created_by'] ?? null;
|
||||
// $record->updated_by = $updatedBy ?? null;
|
||||
// } else {
|
||||
// // Record exists → update only updated_by and updated_at
|
||||
// $record->updated_by = $updatedBy ?? null;
|
||||
// $record->touch();
|
||||
// }
|
||||
// $record->save();
|
||||
|
||||
ProductCharacteristicsMaster::updateOrCreate(
|
||||
[
|
||||
'plant_id' => $plantId,
|
||||
'item_id' => $itemId,
|
||||
'line_id' => $LineId,
|
||||
'work_group_master_id' => $workGroupMasterId,
|
||||
'machine_id' => $machineId,
|
||||
],
|
||||
[
|
||||
'name' => $name,
|
||||
'characteristics_type' => $this->data['characteristics_type'],
|
||||
'inspection_type' => $this->data['inspection_type'],
|
||||
'lower' => $lower,
|
||||
'middle' => $middle,
|
||||
'upper' => $upper,
|
||||
// 'created_by' => user ?? $this->data['created_by'],
|
||||
'created_by' => $this->data['created_by'] ?? null,
|
||||
'updated_by' => $updatedBy ?? null,
|
||||
]);
|
||||
|
||||
$currentUser = Auth::check() ? Auth::user()->name : ($this->data['created_by'] ?? 'System');
|
||||
|
||||
// If record is new, fill all fields
|
||||
if (! $record->exists) {
|
||||
$record->name = $this->data['name'];
|
||||
$record->characteristics_type = $this->data['characteristics_type'];
|
||||
$record->inspection_type = $this->data['inspection_type'];
|
||||
$record->upper = $this->data['upper'] ?? null;
|
||||
$record->lower = $this->data['lower'] ?? null;
|
||||
$record->middle = $this->data['middle'] ?? null;
|
||||
$record->created_by = $currentUser;
|
||||
} else {
|
||||
// Record exists → update only updated_by and updated_at
|
||||
$record->updated_by = $currentUser;
|
||||
$record->touch();
|
||||
}
|
||||
|
||||
$record->save();
|
||||
|
||||
return null;
|
||||
}
|
||||
// else
|
||||
// {
|
||||
// ProductCharacteristicsMaster::updateOrCreate(
|
||||
// [
|
||||
// 'plant_id' => $plant->id,
|
||||
// 'item_id' => $itemId,
|
||||
// 'line_id' => $LineId,
|
||||
// 'work_group_master_id' => $workGroupMasterId,
|
||||
// 'machine_id'=> $machineId,
|
||||
|
||||
// ],
|
||||
// [
|
||||
// 'name' => $this->data['name'],
|
||||
// 'characteristics_type' => $this->data['characteristics_type'],
|
||||
// 'inspection_type' => $this->data['inspection_type'],
|
||||
// 'upper' => $this->data['upper'] ?? null,
|
||||
// 'lower' => $this->data['lower'] ?? null,
|
||||
// 'middle' => $this->data['middle'] ?? null,
|
||||
// //'created_by' => user ?? $this->data['created_by'],
|
||||
// 'created_by' => Auth::check() ? Auth::user()->name :($this->data['created_by'] ?? null)
|
||||
// ]
|
||||
// );
|
||||
|
||||
// return null;
|
||||
// }
|
||||
return null;
|
||||
|
||||
// return new WorkGroupMaster();
|
||||
|
||||
// return new ProductCharacteristicsMaster();
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Filament\Imports;
|
||||
|
||||
use App\Models\Block;
|
||||
use App\Models\Item;
|
||||
use App\Models\Line;
|
||||
use App\Models\Plant;
|
||||
use App\Models\ProductionPlan;
|
||||
@@ -23,11 +24,33 @@ class ProductionPlanImporter extends Importer
|
||||
public static function getColumns(): array
|
||||
{
|
||||
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()
|
||||
->exampleHeader('Created DateTime')
|
||||
->example(['01-01-2025 08:00:00', '01-01-2025 19:30:00'])
|
||||
->label('Created DateTime')
|
||||
->exampleHeader('Plant Code')
|
||||
->example(['1000', '1000'])
|
||||
->label('Plant Code')
|
||||
->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']),
|
||||
ImportColumn::make('plan_quantity')
|
||||
->requiredMapping()
|
||||
@@ -36,52 +59,40 @@ class ProductionPlanImporter extends Importer
|
||||
->label('Plan Quantity')
|
||||
->numeric()
|
||||
->rules(['required', 'integer']),
|
||||
ImportColumn::make('production_quantity')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Production Quantity')
|
||||
->example(['0', '0'])
|
||||
->label('Production Quantity')
|
||||
->numeric()
|
||||
->rules(['required', 'integer']),
|
||||
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('block_reference')
|
||||
->requiredMapping() // Or optionalMapping() if not always present
|
||||
->exampleHeader('Block Name')
|
||||
->example(['Block A', 'Block A'])
|
||||
->label('Block Name')
|
||||
->rules(['required']), // Or remove if not required
|
||||
ImportColumn::make('shift')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Shift Name') // ID
|
||||
->example(['Day', 'Night']) // '2', '7'
|
||||
->label('Shift Name') // ID
|
||||
->relationship(resolveUsing: 'name')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('plant')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Plant Code')
|
||||
->example(['1000', '1000'])
|
||||
->label('Plant Code')
|
||||
->relationship(resolveUsing: 'code')
|
||||
->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']),
|
||||
// ImportColumn::make('production_quantity')
|
||||
// ->requiredMapping()
|
||||
// ->exampleHeader('Production Quantity')
|
||||
// ->example(['0', '0'])
|
||||
// ->label('Production Quantity')
|
||||
// ->numeric()
|
||||
// ->rules(['required', 'integer']),
|
||||
|
||||
// ImportColumn::make('block_reference')
|
||||
// ->requiredMapping() // Or optionalMapping() if not always present
|
||||
// ->exampleHeader('Block Name')
|
||||
// ->example(['Block A', 'Block A'])
|
||||
// ->label('Block Name')
|
||||
// ->rules(['required']), // Or remove if not required
|
||||
// ImportColumn::make('shift')
|
||||
// ->requiredMapping()
|
||||
// ->exampleHeader('Shift Name') // ID
|
||||
// ->example(['Day', 'Night']) // '2', '7'
|
||||
// ->label('Shift Name') // ID
|
||||
// ->relationship(resolveUsing: 'name')
|
||||
// ->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']),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -89,6 +100,7 @@ class ProductionPlanImporter extends Importer
|
||||
{
|
||||
$warnMsg = [];
|
||||
$plantCod = $this->data['plant'];
|
||||
$itemCod = $this->data['item'];
|
||||
$plant = null;
|
||||
$line = null;
|
||||
$block = null;
|
||||
@@ -103,113 +115,52 @@ class ProductionPlanImporter extends Importer
|
||||
$warnMsg[] = 'Plant not found';
|
||||
} else {
|
||||
$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';
|
||||
} elseif ($plant) {
|
||||
$shift = Shift::where('name', $this->data['shift'])->where('plant_id', $plant->id)->where('block_id', $block->id)->first();
|
||||
if (Str::length($itemCod) < 6 || ! is_numeric($itemCod)) {
|
||||
$warnMsg[] = 'Invalid item code found';
|
||||
} else {
|
||||
$item = Item::where('code', $itemCod)->first();
|
||||
}
|
||||
|
||||
// $shift = Shift::where('id', $this->data['shift'])->where('plant_id', $plant->id)->first();
|
||||
if (! $shift) {
|
||||
$warnMsg[] = 'Shift not found';
|
||||
if (! $item) {
|
||||
$warnMsg[] = 'Item not found';
|
||||
}
|
||||
|
||||
$plantId = $plant->id;
|
||||
|
||||
$itemAgaPlant = Item::where('plant_id', $plantId)->where('code', $itemCod)->first();
|
||||
|
||||
if(!$itemAgaPlant){
|
||||
$warnMsg[] = 'Item not found against plant code';
|
||||
}
|
||||
|
||||
$user = Filament::auth()->user();
|
||||
|
||||
$operatorName = $user->name;
|
||||
|
||||
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';
|
||||
}
|
||||
|
||||
$fromDate = $this->data['created_at'];
|
||||
$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";
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($formats as $format) {
|
||||
try {
|
||||
$tdateTime = Carbon::createFromFormat($format, $toDate);
|
||||
break;
|
||||
} catch (\Exception $e) {
|
||||
// Optionally collect warning messages
|
||||
// $warnMsg[] = "Date format mismatch with format: $format";
|
||||
}
|
||||
}
|
||||
|
||||
$fDateOnly = '';
|
||||
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";
|
||||
}
|
||||
|
||||
if (isset($fdateTime) && isset($tdateTime)) {
|
||||
if ($fdateTime->greaterThan($tdateTime)) {
|
||||
$warnMsg[] = "'Created DataTime' is greater than 'Updated DateTime'.";
|
||||
}
|
||||
}
|
||||
|
||||
// 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";
|
||||
// }
|
||||
|
||||
$user = User::where('name', $this->data['operator_id'])->first();
|
||||
if (! $user) {
|
||||
$warnMsg[] = 'Operator ID not found';
|
||||
}
|
||||
|
||||
if (! empty($warnMsg)) {
|
||||
throw new RowImportFailedException(implode(', ', $warnMsg));
|
||||
} else { // if (empty($warnMsg))
|
||||
} else {
|
||||
$productionPlan = ProductionPlan::where('plant_id', $plant->id)
|
||||
->where('shift_id', $shift->id)
|
||||
->where('line_id', $line->id)
|
||||
->whereDate('created_at', $fDateOnly)
|
||||
// ->where('plan_quantity', $productionQuantity->plan_quantity)
|
||||
->where('item_id', $itemAgaPlant->id)
|
||||
->latest()
|
||||
->first();
|
||||
|
||||
if ($productionPlan) {
|
||||
// if($productionPlan->production_quantity)
|
||||
// {
|
||||
// throw new RowImportFailedException("{$productionPlan->created_at}, {$productionPlan->production_quantity}");
|
||||
// }
|
||||
// $warnMsg[] = "Production plan already exist on '{$fDateOnly}'!";
|
||||
|
||||
$productionPlan->update([
|
||||
'plan_quantity' => $this->data['plan_quantity'],
|
||||
// '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'],
|
||||
'operator_id' => $operatorName,
|
||||
]);
|
||||
$productionPlan->save();
|
||||
|
||||
@@ -220,21 +171,15 @@ class ProductionPlanImporter extends Importer
|
||||
ProductionPlan::updateOrCreate([
|
||||
'plant_id' => $plant->id,
|
||||
'line_id' => $line->id,
|
||||
'shift_id' => $shift->id,
|
||||
'item_id' => $itemAgaPlant->id,
|
||||
// 'shift_id' => $shift->id,
|
||||
'plan_quantity' => $this->data['plan_quantity'],
|
||||
'production_quantity' => $this->data['production_quantity'],
|
||||
'created_at' => $fdateTime->format('Y-m-d H:i:s'), // $this->data['created_at'],
|
||||
'updated_at' => $tdateTime->format('Y-m-d H:i:s'), // $this->data['updated_at'],
|
||||
'operator_id' => $this->data['operator_id'],
|
||||
'created_at' =>now(),
|
||||
'updated_at' => now(),
|
||||
'operator_id' => $operatorName,
|
||||
]);
|
||||
|
||||
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
|
||||
|
||||
@@ -205,7 +205,7 @@ class StickerMasterImporter extends Importer
|
||||
} else {
|
||||
$itemId = $item->id;
|
||||
|
||||
if (! $laserPart1) {
|
||||
if (! $laserPart1 && ! (Str::length($laserPart2) == 1 && is_numeric($laserPart2))) {
|
||||
$laserPart1 = $laserPart2;
|
||||
$laserPart2 = null;
|
||||
}
|
||||
|
||||
171
app/Filament/Pages/ProductionCalender.php
Normal file
171
app/Filament/Pages/ProductionCalender.php
Normal file
@@ -0,0 +1,171 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Pages;
|
||||
|
||||
use App\Models\CustomerPoMaster;
|
||||
use App\Models\Plant;
|
||||
use App\Models\ProductionPlan;
|
||||
use App\Models\WireMasterPacking;
|
||||
use Filament\Facades\Filament;
|
||||
use Filament\Pages\Page;
|
||||
use Filament\Forms\Concerns\InteractsWithForms;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Forms\Components\Section;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\DatePicker;
|
||||
use Filament\Forms\Components\Grid;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\ViewField;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Forms\Components\Actions\Action;
|
||||
use Filament\Forms\Components\Hidden;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class ProductionCalender extends Page
|
||||
{
|
||||
protected static ?string $navigationIcon = 'heroicon-o-document-text';
|
||||
|
||||
protected static string $view = 'filament.pages.production-calender';
|
||||
|
||||
protected static ?string $navigationGroup = 'Production';
|
||||
|
||||
use InteractsWithForms;
|
||||
|
||||
protected $listeners = ['setWorkingDays'];
|
||||
|
||||
public $pId;
|
||||
|
||||
public array $filters = [];
|
||||
|
||||
public function setWorkingDays($days = null)
|
||||
{
|
||||
$this->form->fill([
|
||||
'working_days' => $days ?? 0,
|
||||
]);
|
||||
}
|
||||
|
||||
public function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->statePath('filters')
|
||||
->schema([
|
||||
Section::make('')
|
||||
->schema([
|
||||
Select::make('plant_id')
|
||||
->label('Plant')
|
||||
->reactive()
|
||||
//->options(Plant::pluck('name', 'id'))
|
||||
->options(function (callable $get) {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
|
||||
})
|
||||
->columnSpan(['default' => 10, 'sm' => 7])
|
||||
->required()
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
$set('working_days', null);
|
||||
}),
|
||||
TextInput::make('working_days')
|
||||
->label('No. of Working Days')
|
||||
->numeric()
|
||||
->readOnly()
|
||||
->columnSpan(['default' => 10, 'sm' => 2])
|
||||
->required()
|
||||
->minValue(0)
|
||||
->maxValue(31)
|
||||
->placeholder('Enter working days')
|
||||
->id('working_days'),
|
||||
|
||||
Hidden::make('month')
|
||||
->label('Month')
|
||||
->id('month'),
|
||||
|
||||
Hidden::make('year')
|
||||
->label('Year')
|
||||
->id('year'),
|
||||
|
||||
Hidden::make('selected_dates')
|
||||
->label('Selected Dates')
|
||||
->id('selected_dates'),
|
||||
|
||||
ViewField::make('save')
|
||||
->view('forms.save')
|
||||
->columnSpan(['default' => 10, 'sm' => 1]),
|
||||
|
||||
ViewField::make('calendar')
|
||||
->view('forms.calendar')
|
||||
->columnspan(10),
|
||||
])
|
||||
->columns(10)
|
||||
]);
|
||||
}
|
||||
|
||||
public function saveWorkingDays(){
|
||||
$plantId = $this->filters['plant_id'] ?? null;
|
||||
$workingDays = $this->filters['working_days'] ?? null;
|
||||
$month = $this->filters['month'] ?? null;
|
||||
$year = $this->filters['year'] ?? null;
|
||||
$dates = $this->filters['selected_dates'] ?? null;
|
||||
|
||||
if (!$plantId) {
|
||||
Notification::make()
|
||||
->title('Unknown Plant')
|
||||
->body("Please select a plant first!")
|
||||
->danger()
|
||||
->send();
|
||||
return;
|
||||
}
|
||||
else if (!$workingDays) {
|
||||
Notification::make()
|
||||
->title('Unknown Working Days')
|
||||
->body("Working days can't be empty!")
|
||||
->danger()
|
||||
->send();
|
||||
return;
|
||||
}
|
||||
else if (!$month) {
|
||||
Notification::make()
|
||||
->title('Unknown Month')
|
||||
->body("month can't be empty!")
|
||||
->danger()
|
||||
->send();
|
||||
return;
|
||||
}
|
||||
else if (!$year) {
|
||||
Notification::make()
|
||||
->title('Unknown Year')
|
||||
->body("Year can't be empty!")
|
||||
->danger()
|
||||
->send();
|
||||
return;
|
||||
}
|
||||
|
||||
$updated = ProductionPlan::where('plant_id', $plantId)
|
||||
->whereMonth('created_at', $month)
|
||||
->whereYear('created_at', $year)
|
||||
->update([
|
||||
'working_days' => $workingDays,
|
||||
'leave_dates' => $dates,
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
|
||||
if ($updated) {
|
||||
Notification::make()
|
||||
->title('Success')
|
||||
->body("Working days updated successfully!")
|
||||
->success()
|
||||
->send();
|
||||
} else {
|
||||
Notification::make()
|
||||
->title('No Records Updated')
|
||||
->body("No production plans found for this plant and month.")
|
||||
->warning()
|
||||
->send();
|
||||
}
|
||||
}
|
||||
|
||||
public static function canAccess(): bool
|
||||
{
|
||||
return Auth::check() && Auth::user()->can('view production calender page');
|
||||
}
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
191
app/Filament/Pages/ProductionTarget.php
Normal file
191
app/Filament/Pages/ProductionTarget.php
Normal file
@@ -0,0 +1,191 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Pages;
|
||||
|
||||
use App\Models\Plant;
|
||||
use Filament\Facades\Filament;
|
||||
use Filament\Forms\Components\DatePicker;
|
||||
use Filament\Pages\Page;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Forms\Components\Section;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Notifications\Notification;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class ProductionTarget extends Page
|
||||
{
|
||||
protected static ?string $navigationIcon = 'heroicon-o-document-text';
|
||||
|
||||
protected static string $view = 'filament.pages.production-target';
|
||||
|
||||
protected static ?string $navigationGroup = 'Production';
|
||||
|
||||
public array $filters = [];
|
||||
|
||||
|
||||
public function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->statePath('filters')
|
||||
->schema([
|
||||
Section::make('')
|
||||
->schema([
|
||||
Select::make('plant_id')
|
||||
->label('Plant')
|
||||
->relationship('plant', 'name')
|
||||
->reactive()
|
||||
// ->searchable()
|
||||
->options(function (callable $get) {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
|
||||
})
|
||||
->required()
|
||||
->afterStateUpdated(function ($state, callable $get, $set) {
|
||||
// dd($state);
|
||||
$set('line_id', null);
|
||||
$set('year', null);
|
||||
$set('month', null);
|
||||
$this->dispatch('loadData',$state, '', '', '');
|
||||
}),
|
||||
Select::make('line_id')
|
||||
->label('Line')
|
||||
->required()
|
||||
->relationship('line', 'name')
|
||||
// ->searchable()
|
||||
->columnSpan(1)
|
||||
->options(function (callable $get) {
|
||||
if (!$get('plant_id')) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return \App\Models\Line::where('plant_id', $get('plant_id'))
|
||||
->pluck('name', 'id')
|
||||
->toArray();
|
||||
})
|
||||
->reactive()
|
||||
->afterStateUpdated(function ($state, callable $get, $set) {
|
||||
$plantId = $get('plant_id');
|
||||
|
||||
|
||||
$set('year', null);
|
||||
$set('month', null);
|
||||
$this->dispatch('loadData',$plantId, $state, '', '');
|
||||
}),
|
||||
Select::make('year')
|
||||
->label('Year')
|
||||
->reactive()
|
||||
// ->searchable()
|
||||
->options([
|
||||
'2025' => '2025',
|
||||
'2026' => '2026',
|
||||
'2027' => '2027',
|
||||
'2028' => '2028',
|
||||
'2029' => '2029',
|
||||
'2030' => '2030',
|
||||
'2031' => '2031',
|
||||
'2032' => '2032',
|
||||
'2033' => '2033',
|
||||
'2034' => '2034',
|
||||
'2035' => '2035',
|
||||
'2036' => '2036',
|
||||
'2037' => '2037',
|
||||
'2038' => '2038',
|
||||
'2039' => '2039',
|
||||
'2040' => '2040',
|
||||
])
|
||||
->required()
|
||||
->afterStateUpdated(function ($state, callable $get, $set) {
|
||||
$set('month', null);
|
||||
$plantId = $get('plant_id');
|
||||
$lineId = $get('line_id');
|
||||
$this->dispatch('loadData',$plantId, $lineId, $state, '');
|
||||
}),
|
||||
|
||||
Select::make('month')
|
||||
->label('Month')
|
||||
->reactive()
|
||||
// ->searchable()
|
||||
->options([
|
||||
'01' => 'January',
|
||||
'02' => 'February',
|
||||
'03' => 'March',
|
||||
'04' => 'April',
|
||||
'05' => 'May',
|
||||
'06' => 'June',
|
||||
'07' => 'July',
|
||||
'08' => 'August',
|
||||
'09' => 'September',
|
||||
'10' => 'October',
|
||||
'11' => 'November',
|
||||
'12' => 'December',
|
||||
])
|
||||
->required()
|
||||
->afterStateUpdated(function ($state, callable $get) {
|
||||
|
||||
$plantId = $get('plant_id');
|
||||
$lineId = $get('line_id');
|
||||
// $month = $get('month');
|
||||
$year = $get('year');
|
||||
|
||||
$month = (int) $get('month');
|
||||
|
||||
if (!$month) {
|
||||
return;
|
||||
}
|
||||
$this->dispatch('loadData', $plantId, $lineId, $month, $year);
|
||||
}),
|
||||
|
||||
])
|
||||
->columns(4)
|
||||
]);
|
||||
}
|
||||
|
||||
public function export(){
|
||||
|
||||
$plantId = $this->filters['plant_id'] ?? null;
|
||||
$lineId = $this->filters['line_id'] ?? null;
|
||||
$year = $this->filters['year'] ?? null;
|
||||
$month = $this->filters['month'] ?? null;
|
||||
|
||||
if (! $plantId) {
|
||||
Notification::make()
|
||||
->title('Plant')
|
||||
->body("please select plant to export data..!")
|
||||
->danger()
|
||||
->send();
|
||||
return;
|
||||
}
|
||||
else if (! $lineId) {
|
||||
Notification::make()
|
||||
->title('Line')
|
||||
->body("please select line to export data..!")
|
||||
->danger()
|
||||
->send();
|
||||
return;
|
||||
}
|
||||
else if (! $year) {
|
||||
Notification::make()
|
||||
->title('Year')
|
||||
->body("please select year to export data..!")
|
||||
->danger()
|
||||
->send();
|
||||
return;
|
||||
}
|
||||
else if (! $month) {
|
||||
Notification::make()
|
||||
->title('Month')
|
||||
->body("please select month to export data..!")
|
||||
->danger()
|
||||
->send();
|
||||
return;
|
||||
}
|
||||
|
||||
$this->dispatch('loadData1' ,$plantId, $lineId, $year, $month);
|
||||
}
|
||||
|
||||
public static function canAccess(): bool
|
||||
{
|
||||
return Auth::check() && Auth::user()->can('view production target page');
|
||||
}
|
||||
}
|
||||
@@ -49,6 +49,11 @@ class CharacteristicValueResource extends Resource
|
||||
|
||||
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
|
||||
})
|
||||
->default(function () {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
return ($userHas && strlen($userHas) > 0) ? $userHas : optional(CharacteristicValue::latest()->first())->plant_id;
|
||||
})
|
||||
->reactive()
|
||||
->afterStateUpdated(function ($state, $set, callable $get) {
|
||||
$plantId = $get('plant_id');
|
||||
@@ -412,7 +417,6 @@ class CharacteristicValueResource extends Resource
|
||||
// Tables\Filters\TrashedFilter::make(),
|
||||
// ])
|
||||
->filters([
|
||||
|
||||
Tables\Filters\TrashedFilter::make(),
|
||||
Filter::make('advanced_filters')
|
||||
->label('Advanced Filters')
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace App\Filament\Resources;
|
||||
use App\Filament\Exports\LineExporter;
|
||||
use App\Filament\Imports\LineImporter;
|
||||
use App\Filament\Resources\LineResource\Pages;
|
||||
use App\Models\Block;
|
||||
use App\Models\Line;
|
||||
use App\Models\Plant;
|
||||
use App\Models\WorkGroupMaster;
|
||||
@@ -71,6 +72,38 @@ class LineResource extends Resource
|
||||
])
|
||||
->hint(fn ($get) => $get('lPlantError') ? $get('lPlantError') : null)
|
||||
->hintColor('danger'),
|
||||
Forms\Components\Select::make('block_id')
|
||||
->label('Block')
|
||||
->relationship('block', 'name')
|
||||
// ->required()
|
||||
// ->nullable(),
|
||||
->reactive()
|
||||
->options(function (callable $get) {
|
||||
if (! $get('plant_id')) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return Block::where('plant_id', $get('plant_id'))
|
||||
->pluck('name', 'id')
|
||||
->toArray();
|
||||
})
|
||||
->default(function () {
|
||||
return optional(Block::latest()->first())->plant_id;
|
||||
})
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
$blockId = $get('block_id');
|
||||
if (! $blockId) {
|
||||
$set('lblockError', 'Please select a Block first.');
|
||||
return;
|
||||
} else {
|
||||
$set('lblockError', null);
|
||||
}
|
||||
})
|
||||
->extraAttributes(fn ($get) => [
|
||||
'class' => $get('lblockError') ? 'border-red-500' : '',
|
||||
])
|
||||
->hint(fn ($get) => $get('lblockError') ? $get('lblockError') : null)
|
||||
->hintColor('danger'),
|
||||
Forms\Components\TextInput::make('name')
|
||||
->required()
|
||||
->placeholder('Scan the valid name')
|
||||
@@ -1012,6 +1045,11 @@ class LineResource extends Resource
|
||||
->alignCenter()
|
||||
->sortable()
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('block.name')
|
||||
->label('Block')
|
||||
->alignCenter()
|
||||
->sortable()
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('name')
|
||||
->label('Line')
|
||||
->alignCenter()
|
||||
|
||||
@@ -9,6 +9,7 @@ use App\Models\Item;
|
||||
use App\Models\Line;
|
||||
use App\Models\Plant;
|
||||
use App\Models\ProcessOrder;
|
||||
use Closure;
|
||||
use Filament\Facades\Filament;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Components\Actions\Action;
|
||||
@@ -27,6 +28,7 @@ use Filament\Tables\Filters\Filter;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Livewire\Features\SupportFileUploads\TemporaryUploadedFile;
|
||||
use Smalot\PdfParser\Parser;
|
||||
use Storage;
|
||||
@@ -56,16 +58,31 @@ class ProcessOrderResource extends Resource
|
||||
|
||||
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
|
||||
})
|
||||
->default(function () {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
return ($userHas && strlen($userHas) > 0) ? $userHas : optional(ProcessOrder::latest()->first())->plant_id;
|
||||
})
|
||||
->reactive()
|
||||
->afterStateUpdated(function ($state, $set, callable $get, $livewire) {
|
||||
$plantId = $get('plant_id');
|
||||
$set('coil_number', null);
|
||||
$set('item_id', null);
|
||||
$set('line_id', null);
|
||||
$set('item_description', null);
|
||||
$set('item_uom', null);
|
||||
$set('process_order', null);
|
||||
$set('coil_number', '0');
|
||||
$set('order_quantity', '0');
|
||||
$set('received_quantity', '0');
|
||||
$set('scrap_quantity', '0');
|
||||
$set('sfg_number', null);
|
||||
$set('machine_name', null);
|
||||
if (! $plantId) {
|
||||
$set('poPlantError', 'Please select a plant first.');
|
||||
$set('coilNumberError', null);
|
||||
$set('sfgNumberError', null);
|
||||
} else {
|
||||
$set('poPlantError', null);
|
||||
}
|
||||
$set('updated_by', Filament::auth()->user()?->name);
|
||||
})
|
||||
@@ -92,8 +109,10 @@ class ProcessOrderResource extends Resource
|
||||
$set('item_description', null);
|
||||
$set('item_uom', null);
|
||||
$set('process_order', null);
|
||||
$set('order_quantity', null);
|
||||
$set('received_quantity', null);
|
||||
$set('coil_number', '0');
|
||||
$set('order_quantity', '0');
|
||||
$set('received_quantity', '0');
|
||||
$set('scrap_quantity', '0');
|
||||
$set('sfg_number', null);
|
||||
$set('machine_name', null);
|
||||
$set('updated_by', Filament::auth()->user()?->name);
|
||||
@@ -116,7 +135,13 @@ class ProcessOrderResource extends Resource
|
||||
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
|
||||
$plantId = $get('plant_id');
|
||||
$itemId = $get('item_id');
|
||||
// dd($plantId);
|
||||
$set('process_order', null);
|
||||
$set('coil_number', '0');
|
||||
$set('order_quantity', '0');
|
||||
$set('received_quantity', '0');
|
||||
$set('scrap_quantity', '0');
|
||||
$set('sfg_number', null);
|
||||
$set('machine_name', null);
|
||||
|
||||
if ($plantId && $itemId) {
|
||||
// Get the item code using item_id
|
||||
@@ -144,6 +169,7 @@ class ProcessOrderResource extends Resource
|
||||
|
||||
Forms\Components\TextInput::make('item_description')
|
||||
->label('Description')
|
||||
->readOnly()
|
||||
->required()
|
||||
->reactive()
|
||||
->afterStateHydrated(function ($component, $state, Get $get, Set $set) {
|
||||
@@ -184,21 +210,42 @@ class ProcessOrderResource extends Resource
|
||||
->reactive()
|
||||
->numeric()
|
||||
->length(12)
|
||||
->readOnly(fn ($get) => ($get('plant_id') == null || $get('item_id') == null || $get('line_id') == null))
|
||||
->afterStateUpdated(function ($state, $set, callable $get, $livewire) {
|
||||
$plantId = $get('plant_id');
|
||||
$set('coil_number', null);
|
||||
$set('coil_number', '0');
|
||||
$set('order_quantity', '0');
|
||||
$set('received_quantity', '0');
|
||||
$set('scrap_quantity', '0');
|
||||
$set('sfg_number', null);
|
||||
$set('machine_name', null);
|
||||
if (! $plantId) {
|
||||
$set('poPlantError', 'Please select a plant first.');
|
||||
$set('process_order', null);
|
||||
$set('coilNumberError', null);
|
||||
$set('sfgNumberError', null);
|
||||
// if (! $plantId) {
|
||||
// $set('poPlantError', 'Please select a plant first.');
|
||||
// $set('process_order', null);
|
||||
// $set('coilNumberError', null);
|
||||
// $set('sfgNumberError', null);
|
||||
|
||||
// return;
|
||||
// }
|
||||
|
||||
$itemId = $get('item_id');
|
||||
$processOrder = trim($get('process_order'));
|
||||
if (! $itemId || ! $processOrder) {
|
||||
return;
|
||||
}
|
||||
|
||||
$orderExist = ProcessOrder::where('plant_id', $plantId)
|
||||
->where('process_order', $processOrder)
|
||||
->where('item_id', $itemId)->latest()->first();
|
||||
// ->value('order_quantity') ?? 0;
|
||||
|
||||
if ($orderExist) {
|
||||
$set('order_quantity', $orderExist->order_quantity ?? 0);
|
||||
}
|
||||
$set('updated_by', Filament::auth()->user()?->name);
|
||||
})
|
||||
->rule(function (callable $get) {
|
||||
return function (string $attribute, $value, \Closure $fail) use ($get) {
|
||||
return function (string $attribute, $value, Closure $fail) use ($get) {
|
||||
|
||||
$plantId = $get('plant_id');
|
||||
$itemId = $get('item_id');
|
||||
@@ -229,54 +276,99 @@ class ProcessOrderResource extends Resource
|
||||
Forms\Components\TextInput::make('coil_number')
|
||||
->label('Coil Number')
|
||||
->default('0')
|
||||
->required()
|
||||
->reactive()
|
||||
->numeric()
|
||||
->readOnly(fn ($get) => ($get('process_order') == null))
|
||||
->afterStateUpdated(function ($state, $set, callable $get, $livewire) {
|
||||
$plantId = $get('plant_id');
|
||||
$processOrder = $get('process_order');
|
||||
$coilNo = $get('coil_number');
|
||||
// $coilNo = $get('coil_number');
|
||||
if (! $plantId) {
|
||||
$set('poPlantError', 'Please select a plant first.');
|
||||
$set('coil_number', null);
|
||||
$set('sfg_number', null);
|
||||
$set('machine_name', null);
|
||||
$set('coilNumberError', null);
|
||||
$set('sfgNumberError', null);
|
||||
$set('coil_number', '0');
|
||||
} elseif (! $processOrder) {
|
||||
$set('coil_number', null);
|
||||
$set('sfg_number', null);
|
||||
$set('machine_name', null);
|
||||
$set('poPlantError', null);
|
||||
$set('coilNumberError', null);
|
||||
$set('sfgNumberError', null);
|
||||
} elseif ($coilNo || $coilNo == '0') {
|
||||
$existing = ProcessOrder::where('plant_id', $plantId)
|
||||
->where('process_order', $processOrder)
|
||||
->where('coil_number', $coilNo)
|
||||
->first();
|
||||
|
||||
if ($existing) {
|
||||
$set('poPlantError', null);
|
||||
$set('coil_number', null);
|
||||
$set('coilNumberError', "Duplicate Coil : '{$coilNo}' found!");
|
||||
} else {
|
||||
$set('poPlantError', null);
|
||||
$set('coilNumberError', null);
|
||||
}
|
||||
$set('coil_number', '0');
|
||||
}
|
||||
$set('received_quantity', '0');
|
||||
$set('scrap_quantity', '0');
|
||||
$set('sfg_number', null);
|
||||
$set('machine_name', null);
|
||||
$set('coilNumberError', null);
|
||||
$set('sfgNumberError', null);
|
||||
// elseif ($coilNo || $coilNo == 0) {
|
||||
// $existing = ProcessOrder::where('plant_id', $plantId)
|
||||
// ->where('process_order', $processOrder)
|
||||
// ->where('coil_number', $coilNo)
|
||||
// ->first();
|
||||
|
||||
// if ($existing) {
|
||||
// $set('poPlantError', null);
|
||||
// $set('coil_number', '0');
|
||||
// $set('coilNumberError', "Duplicate Coil : '{$coilNo}' found!");
|
||||
// } else {
|
||||
// $set('poPlantError', null);
|
||||
// $set('coilNumberError', null);
|
||||
// }
|
||||
// }
|
||||
$set('updated_by', Filament::auth()->user()?->name);
|
||||
})
|
||||
->rules([
|
||||
function (callable $get) {
|
||||
return Rule::unique('process_orders', 'coil_number')
|
||||
->where('plant_id', $get('plant_id'))
|
||||
->where('process_order', $get('process_order'))
|
||||
->ignore($get('id'));
|
||||
},
|
||||
function (callable $get): Closure {
|
||||
return function (string $attribute, $value, Closure $fail) use ($get) {
|
||||
$rework = $get('rework_status');
|
||||
if ($value && Str::contains($value, '.') && $rework == 0) {
|
||||
$fail("Rework status should be 'Yes' for rework coil number '{$value}'!");
|
||||
}
|
||||
};
|
||||
},
|
||||
])
|
||||
// ->rule(function (callable $get) {
|
||||
// return Rule::unique('process_orders', 'coil_number')
|
||||
// ->where('plant_id', $get('plant_id'))
|
||||
// ->where('process_order', $get('process_order'))
|
||||
// ->ignore($get('id'));
|
||||
// })
|
||||
->extraAttributes(fn ($get) => [
|
||||
'class' => $get('coilNumberError') ? 'border-red-500' : '',
|
||||
])
|
||||
->hint(fn ($get) => $get('coilNumberError') ? $get('coilNumberError') : null)
|
||||
->hintColor('danger')
|
||||
->required(),
|
||||
->hintColor('danger'),
|
||||
Forms\Components\TextInput::make('order_quantity')
|
||||
->label('Order Quantity')
|
||||
->default('1.000')
|
||||
->required()
|
||||
->reactive()
|
||||
->numeric()
|
||||
->readOnly(fn ($get) => ($get('process_order') == null))
|
||||
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
|
||||
$plantId = $get('plant_id');
|
||||
$itemId = $get('item_id');
|
||||
$processOrder = trim($get('process_order'));
|
||||
$set('received_quantity', '0');
|
||||
$set('scrap_quantity', '0');
|
||||
if (! $plantId || ! $itemId || ! $processOrder) {
|
||||
$set('order_quantity', '0');
|
||||
}
|
||||
|
||||
$query = ProcessOrder::where('plant_id', $plantId)
|
||||
->where('process_order', $processOrder)
|
||||
->where('item_id', $itemId);
|
||||
|
||||
$orderExist = $query->latest()->first(); // Latest record (reuse base query)
|
||||
|
||||
if ($query->count() == 1 && $orderExist && ! $get('id')) {
|
||||
$set('order_quantity', $orderExist->order_quantity ?? 0);
|
||||
} elseif ($query->count() > 1 && $orderExist) {
|
||||
$set('order_quantity', $orderExist->order_quantity ?? 0);
|
||||
}
|
||||
$set('updated_by', Filament::auth()->user()?->name);
|
||||
}),
|
||||
Forms\Components\TextInput::make('received_quantity')
|
||||
@@ -284,19 +376,44 @@ class ProcessOrderResource extends Resource
|
||||
->default('0.000')
|
||||
->required()
|
||||
->reactive()
|
||||
->numeric()
|
||||
->readOnly(fn ($get) => ($get('process_order') == null))
|
||||
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
|
||||
$set('scrap_quantity', '0');
|
||||
$set('updated_by', Filament::auth()->user()?->name);
|
||||
}),
|
||||
Forms\Components\TextInput::make('scrap_quantity')
|
||||
->label('Scrap Quantity')
|
||||
->default('0.000')
|
||||
->required()
|
||||
->readOnly(fn ($get) => ($get('rework_status') == 0 || $get('process_order') == null))
|
||||
->reactive()
|
||||
->numeric()
|
||||
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
|
||||
$rework = $get('rework_status');
|
||||
if ($rework == 0) {
|
||||
$set('scrap_quantity', '0');
|
||||
}
|
||||
$set('updated_by', Filament::auth()->user()?->name);
|
||||
})
|
||||
->rule(function (callable $get) {
|
||||
return function (string $attribute, $value, Closure $fail) use ($get) {
|
||||
|
||||
$rework = $get('rework_status');
|
||||
$scrapQty = $value;
|
||||
// $currentId = $get('id'); // current editing record id
|
||||
|
||||
if ($rework == 0 && $scrapQty != 0) {
|
||||
$fail("Scrap Quanity value should be '0'!");
|
||||
|
||||
return;
|
||||
}
|
||||
};
|
||||
}),
|
||||
Forms\Components\TextInput::make('sfg_number')
|
||||
->label('SFG Number')
|
||||
->reactive()
|
||||
->readOnly(fn ($get) => ($get('process_order') == null))
|
||||
->afterStateUpdated(function ($state, $set, callable $get, $livewire) {
|
||||
$plantId = $get('plant_id');
|
||||
$sfgNo = $get('sfg_number');
|
||||
@@ -330,6 +447,7 @@ class ProcessOrderResource extends Resource
|
||||
Forms\Components\TextInput::make('machine_name')
|
||||
->label('Machine ID')
|
||||
->reactive()
|
||||
->readOnly(fn ($get) => ($get('process_order') == null))
|
||||
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
|
||||
$set('updated_by', Filament::auth()->user()?->name);
|
||||
}),
|
||||
@@ -340,11 +458,55 @@ class ProcessOrderResource extends Resource
|
||||
->options([0 => 'No', 1 => 'Yes'])
|
||||
->reactive()
|
||||
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
|
||||
// if ($get('id') && $get('rework_status') == 1) {
|
||||
// $set('rework_status', 1);
|
||||
// }
|
||||
if ($state == 0) {
|
||||
$set('scrap_quantity', '0');
|
||||
}
|
||||
$set('updated_by', Filament::auth()->user()?->name);
|
||||
})
|
||||
->rule(function (callable $get, callable $set) {
|
||||
return function (string $attribute, $value, Closure $fail) use ($get, $set) {
|
||||
$plantId = $get('plant_id');
|
||||
$lineId = $get('line_id');
|
||||
$processOrder = trim($get('process_order'));
|
||||
$coilNo = trim($get('coil_number'));
|
||||
$status = $value;
|
||||
// $currentId = $get('id'); // current editing record id
|
||||
|
||||
if (! $plantId || ! $lineId || ! $processOrder || Str::length($coilNo) <= 0) {
|
||||
$set('rework_status', 0);
|
||||
|
||||
return;
|
||||
} elseif ($status == 0) {
|
||||
$existingCoil = ProcessOrder::where('plant_id', $plantId)
|
||||
->where('line_id', $lineId)
|
||||
->where('process_order', $processOrder)
|
||||
->where('coil_number', $coilNo)
|
||||
->first();
|
||||
|
||||
if ($existingCoil && $existingCoil->rework_status == 1 && $get('id')) {
|
||||
$fail("Rework coil number '{$coilNo}' exist against plant and process order!");
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (Str::length($coilNo) > 0 && ($status == 1 || Str::contains($coilNo, '.'))) {
|
||||
$coilMain = explode('.', $coilNo)[0]; // 333
|
||||
|
||||
$existingCoil = ProcessOrder::where('plant_id', $plantId)
|
||||
->where('line_id', $lineId)
|
||||
->where('process_order', $processOrder)
|
||||
->where('coil_number', $coilMain)
|
||||
->first();
|
||||
|
||||
if (! $existingCoil) {
|
||||
$fail("Coil number '{$coilMain}' not exist against plant and process order!");
|
||||
} elseif ($existingCoil->rework_status == 0 && ! $get('id')) {
|
||||
$fail("Rework coil number '{$coilMain}' not exist against plant and process order!");
|
||||
}
|
||||
}
|
||||
};
|
||||
})
|
||||
->visible(function () {
|
||||
return Filament::auth()->user()->hasRole('Super Admin'); // || Filament::auth()->user()->can('update process order rework status')
|
||||
})
|
||||
|
||||
@@ -49,6 +49,11 @@ class ProductCharacteristicsMasterResource extends Resource
|
||||
|
||||
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
|
||||
})
|
||||
->default(function () {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
return ($userHas && strlen($userHas) > 0) ? $userHas : optional(ProductCharacteristicsMaster::latest()->first())->plant_id;
|
||||
})
|
||||
->afterStateUpdated(function ($state, callable $set) {
|
||||
$set('updated_by', Filament::auth()->user()?->name);
|
||||
})
|
||||
|
||||
@@ -7,6 +7,7 @@ use App\Filament\Exports\ProductionPlanExporter;
|
||||
use App\Filament\Imports\ProductionPlanImporter;
|
||||
use App\Filament\Resources\ProductionPlanResource\Pages;
|
||||
use App\Models\Block;
|
||||
use App\Models\Item;
|
||||
use App\Models\Line;
|
||||
use App\Models\Plant;
|
||||
use App\Models\ProductionPlan;
|
||||
@@ -77,97 +78,6 @@ class ProductionPlanResource extends Resource
|
||||
])
|
||||
->hint(fn ($get) => $get('ppPlantError') ? $get('ppPlantError') : null)
|
||||
->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')
|
||||
->relationship('line', 'name')
|
||||
->required()
|
||||
@@ -178,7 +88,7 @@ class ProductionPlanResource extends Resource
|
||||
// ->toArray() // Convert collection to array
|
||||
// )
|
||||
->options(function (callable $get) {
|
||||
if (! $get('plant_id') || ! $get('block_name') || ! $get('shift_id')) {
|
||||
if (! $get('plant_id')) {
|
||||
return [];
|
||||
}
|
||||
|
||||
@@ -190,239 +100,257 @@ class ProductionPlanResource extends Resource
|
||||
// ->default(function () {
|
||||
// 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) {
|
||||
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);
|
||||
}
|
||||
$set('item_id', null);
|
||||
$set('plan_quantity', null);
|
||||
})
|
||||
->extraAttributes(fn ($get) => [
|
||||
'class' => $get('ppLineError') ? 'border-red-500' : '',
|
||||
])
|
||||
->hint(fn ($get) => $get('ppLineError') ? $get('ppLineError') : null)
|
||||
->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')
|
||||
->required()
|
||||
->integer()
|
||||
@@ -453,29 +381,19 @@ class ProductionPlanResource extends Resource
|
||||
])
|
||||
->hint(fn ($get) => $get('ppPlanQuanError') ? $get('ppPlanQuanError') : null)
|
||||
->hintColor('danger'),
|
||||
Forms\Components\TextInput::make('production_quantity')
|
||||
->required()
|
||||
->integer()
|
||||
->label('Production Quantity')
|
||||
->readOnly(fn (callable $get) => ! $get('id'))
|
||||
->default(0),
|
||||
// Forms\Components\TextInput::make('production_quantity')
|
||||
// ->required()
|
||||
// ->integer()
|
||||
// ->label('Production Quantity')
|
||||
// ->readOnly(fn (callable $get) => ! $get('id'))
|
||||
// ->default(0),
|
||||
Forms\Components\TextInput::make('id')
|
||||
->hidden()
|
||||
->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')
|
||||
->default(Filament::auth()->user()->name),
|
||||
])
|
||||
->columns(2),
|
||||
->columns(4),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -513,32 +431,52 @@ class ProductionPlanResource extends Resource
|
||||
|
||||
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')
|
||||
->label('Plan Quantity')
|
||||
->alignCenter()
|
||||
->numeric()
|
||||
->sortable(),
|
||||
->sortable()
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('working_days')
|
||||
->label('Working Days')
|
||||
->alignCenter()
|
||||
->numeric()
|
||||
->sortable()
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('production_quantity')
|
||||
->label('Production Quantity')
|
||||
->alignCenter()
|
||||
->numeric()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('line.name')
|
||||
->label('Line')
|
||||
->alignCenter()
|
||||
->sortable(), // ->searchable(),
|
||||
Tables\Columns\TextColumn::make('shift.block.name')
|
||||
->label('Block')
|
||||
->alignCenter()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('shift.name')
|
||||
->label('Shift')
|
||||
->alignCenter()
|
||||
->sortable(), // ->searchable(),
|
||||
Tables\Columns\TextColumn::make('plant.name')
|
||||
->label('Plant')
|
||||
->alignCenter()
|
||||
->sortable(), // ->searchable(),
|
||||
->sortable()
|
||||
->searchable(),
|
||||
// Tables\Columns\TextColumn::make('line.name')
|
||||
// ->label('Line')
|
||||
// ->alignCenter()
|
||||
// ->sortable(), // ->searchable(),
|
||||
// Tables\Columns\TextColumn::make('shift.block.name')
|
||||
// ->label('Block')
|
||||
// ->alignCenter()
|
||||
// ->sortable(),
|
||||
// Tables\Columns\TextColumn::make('shift.name')
|
||||
// ->label('Shift')
|
||||
// ->alignCenter()
|
||||
// ->sortable(), // ->searchable(),
|
||||
|
||||
Tables\Columns\TextColumn::make('created_at')
|
||||
->label('Created At')
|
||||
->dateTime()
|
||||
|
||||
@@ -264,7 +264,7 @@ class StickerMasterResource extends Resource
|
||||
->label('Laser Part Validation 2')
|
||||
->nullable()
|
||||
->reactive()
|
||||
->readOnly(fn (callable $get) => empty($get('laser_part_validation1')))
|
||||
// ->readOnly(fn (callable $get) => empty($get('laser_part_validation1')))
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
$set('updated_by', Filament::auth()->user()?->name);
|
||||
}),
|
||||
@@ -625,11 +625,13 @@ class StickerMasterResource extends Resource
|
||||
Tables\Columns\TextColumn::make('laser_part_validation1')
|
||||
->label('Laser Part Validation 1')
|
||||
->default('-')
|
||||
->alignCenter(),
|
||||
->alignCenter()
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('laser_part_validation2')
|
||||
->label('Laser Part Validation 2')
|
||||
->default('-')
|
||||
->alignCenter(),
|
||||
->alignCenter()
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('panel_box_code')
|
||||
->label('Panel Box Code')
|
||||
->default('-')
|
||||
|
||||
310
app/Livewire/ProductionTargetPlan.php
Normal file
310
app/Livewire/ProductionTargetPlan.php
Normal file
@@ -0,0 +1,310 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire;
|
||||
|
||||
use App\Exports\ProductionPlanExport;
|
||||
use App\Models\ProductionPlan;
|
||||
use App\Models\ProductionQuantity;
|
||||
use Livewire\Component;
|
||||
use Carbon\Carbon;
|
||||
use DB;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
|
||||
class ProductionTargetPlan extends Component
|
||||
{
|
||||
|
||||
public $plantId, $lineId, $month, $year;
|
||||
|
||||
public $records = [];
|
||||
|
||||
public $dates = [];
|
||||
|
||||
public $leaveDates = [];
|
||||
|
||||
public $productionPlanDates = '';
|
||||
|
||||
|
||||
protected $listeners = [
|
||||
'loadData' => 'loadProductionData',
|
||||
'loadData1' => 'exportProductionData',
|
||||
];
|
||||
|
||||
public function getMonthDates($month, $year)
|
||||
{
|
||||
$start = Carbon::createFromDate($year, $month, 1);
|
||||
$days = $start->daysInMonth;
|
||||
|
||||
$dates = [];
|
||||
|
||||
for ($i = 1; $i <= $days; $i++) {
|
||||
$dates[] = Carbon::createFromDate($year, $month, $i)
|
||||
->format('Y-m-d');
|
||||
}
|
||||
|
||||
return $dates;
|
||||
}
|
||||
|
||||
// public function loadProductionData($plantId, $lineId, $month, $year){
|
||||
|
||||
// if (!$plantId || !$lineId || !$month || !$year) {
|
||||
// $this->records = [];
|
||||
// $this->dates = [];
|
||||
// $this->leaveDates = [];
|
||||
// return;
|
||||
// }
|
||||
|
||||
// $this->dates = $this->getMonthDates($month, $year);
|
||||
|
||||
// $data = 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.created_at',
|
||||
// 'production_plans.operator_id',
|
||||
// 'plants.name as plant',
|
||||
// 'items.code as item_code',
|
||||
// 'items.description as item_description',
|
||||
// 'lines.name as line_name',
|
||||
// 'production_plans.leave_dates'
|
||||
// )
|
||||
// ->first();
|
||||
|
||||
// if ($data && $data->leave_dates) {
|
||||
// $this->leaveDates = array_map('trim', explode(',', $data->leave_dates));
|
||||
// }
|
||||
|
||||
// $producedData = ProductionQuantity::selectRaw("
|
||||
// plant_id,
|
||||
// line_id,
|
||||
// item_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)
|
||||
// ->groupBy('plant_id', 'line_id', 'item_id', DB::raw('DATE(created_at)'))
|
||||
// ->get()
|
||||
// ->groupBy(function ($row) {
|
||||
// return $row->plant_id . '_' . $row->line_id . '_' . $row->item_id;
|
||||
// })
|
||||
// ->map(function ($group) {
|
||||
// return $group->keyBy('prod_date');
|
||||
// });
|
||||
|
||||
// $this->records = 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',
|
||||
// 'items.code as item_code',
|
||||
// 'items.description as item_description',
|
||||
// 'lines.name as line_name',
|
||||
// 'plants.name as plant_name'
|
||||
// )
|
||||
// ->get()
|
||||
// ->map(function ($row) use ($producedData) {
|
||||
|
||||
// $row = $row->toArray();
|
||||
|
||||
// $remainingQty = $row['plan_quantity'];
|
||||
// // $remainingDays = $row['working_days'];
|
||||
// $remainingDays = (int) ($row['working_days'] ?? 0);
|
||||
|
||||
// $row['daily_target_dynamic'] = [];
|
||||
// $row['produced_quantity'] = [];
|
||||
|
||||
// $key = $row['plant_id'].'_'.$row['line_id'].'_'.$row['item_id'];
|
||||
|
||||
// foreach ($this->dates as $date) {
|
||||
|
||||
// // Skip leave dates
|
||||
// if (in_array($date, $this->leaveDates)) {
|
||||
// $row['daily_target_dynamic'][$date] = '-';
|
||||
// $row['produced_quantity'][$date] = '-';
|
||||
// continue;
|
||||
// }
|
||||
|
||||
// $todayTarget = $remainingDays > 0
|
||||
// ? round($remainingQty / $remainingDays, 2)
|
||||
// : 0;
|
||||
|
||||
// //$todayTarget = $remainingDays > 0
|
||||
// // ? $remainingQty / $remainingDays
|
||||
// // : 0;
|
||||
|
||||
// $producedQty = isset($producedData[$key][$date])
|
||||
// ? $producedData[$key][$date]->total_qty
|
||||
// : 0;
|
||||
|
||||
// $row['daily_target_dynamic'][$date] = $todayTarget;
|
||||
// $row['produced_quantity'][$date] = $producedQty;
|
||||
|
||||
// // Carry forward pending
|
||||
// $remainingQty -= $producedQty;
|
||||
// if ($remainingQty < 0) {
|
||||
// $remainingQty = 0;
|
||||
// }
|
||||
|
||||
// if ($remainingDays > 0) {
|
||||
// $remainingDays--;
|
||||
// }
|
||||
|
||||
// // $remainingDays--;
|
||||
// }
|
||||
|
||||
// return $row;
|
||||
// })
|
||||
// ->toArray();
|
||||
// }
|
||||
|
||||
|
||||
|
||||
public function loadProductionData($plantId, $lineId, $month, $year)
|
||||
{
|
||||
if (!$plantId || !$lineId || !$month || !$year) {
|
||||
$this->records = [];
|
||||
$this->dates = [];
|
||||
$this->leaveDates = [];
|
||||
return;
|
||||
}
|
||||
|
||||
$dates = $this->getMonthDates($month, $year);
|
||||
$this->dates = $dates;
|
||||
|
||||
$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.description as item_description',
|
||||
'lines.name as line_name',
|
||||
'lines.line_capacity as line_capacity',
|
||||
'plants.name as plant_name'
|
||||
)
|
||||
->get();
|
||||
|
||||
$leaveDates = [];
|
||||
|
||||
if ($plans->isNotEmpty() && $plans[0]->leave_dates) {
|
||||
$leaveDates = array_map('trim', explode(',', $plans[0]->leave_dates));
|
||||
}
|
||||
|
||||
$this->leaveDates = $leaveDates;
|
||||
|
||||
$producedData = ProductionQuantity::selectRaw("
|
||||
plant_id,
|
||||
line_id,
|
||||
item_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)
|
||||
->groupBy('plant_id', 'line_id', 'item_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'));
|
||||
|
||||
|
||||
$records = [];
|
||||
|
||||
foreach ($plans as $plan) {
|
||||
|
||||
$row = $plan->toArray();
|
||||
|
||||
$remainingQty = (float) $row['plan_quantity'];
|
||||
$remainingDays = (int) ($row['working_days'] ?? 0);
|
||||
|
||||
$lineCapacity = (float) ($row['line_capacity'] ?? 0);
|
||||
$dailyLineCapacity = (float) ($row['line_capacity'] ?? 0);
|
||||
|
||||
|
||||
$row['daily_line_capacity'] = [];
|
||||
$row['daily_target_dynamic'] = [];
|
||||
$row['produced_quantity'] = [];
|
||||
|
||||
$key = $row['plant_id'].'_'.$row['line_id'].'_'.$row['item_id'];
|
||||
|
||||
foreach ($dates as $date) {
|
||||
|
||||
// Skip leave dates fast
|
||||
if (isset($leaveDates) && in_array($date, $leaveDates)) {
|
||||
$row['daily_line_capacity'][$date] = '-';
|
||||
$row['daily_target_dynamic'][$date] = '-';
|
||||
$row['produced_quantity'][$date] = '-';
|
||||
continue;
|
||||
}
|
||||
|
||||
$todayTarget = $remainingDays > 0
|
||||
? round($remainingQty / $remainingDays, 2)
|
||||
: 0;
|
||||
|
||||
$producedQty = $producedData[$key][$date]->total_qty ?? 0;
|
||||
|
||||
$row['daily_target_dynamic'][$date] = $todayTarget;
|
||||
$row['produced_quantity'][$date] = $producedQty;
|
||||
$row['daily_line_capacity'][$date] = $dailyLineCapacity;
|
||||
|
||||
// Carry forward remaining qty
|
||||
$remainingQty = max(0, $remainingQty - $producedQty);
|
||||
|
||||
if ($remainingDays > 0) {
|
||||
$remainingDays--;
|
||||
}
|
||||
}
|
||||
|
||||
$records[] = $row;
|
||||
}
|
||||
|
||||
$this->records = $records;
|
||||
}
|
||||
|
||||
|
||||
public function exportProductionData()
|
||||
{
|
||||
return Excel::download(
|
||||
new ProductionPlanExport($this->records, $this->dates),
|
||||
'production_plan_data.xlsx'
|
||||
);
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
// return view('livewire.production-target-plan');
|
||||
return view('livewire.production-target-plan', [
|
||||
'records' => $this->records,
|
||||
'dates' => $this->dates,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,7 @@ class Item extends Model
|
||||
|
||||
protected $fillable = [
|
||||
'plant_id',
|
||||
'line_id',
|
||||
'category',
|
||||
'code',
|
||||
'description',
|
||||
@@ -19,11 +20,16 @@ class Item extends Model
|
||||
'uom',
|
||||
];
|
||||
|
||||
public function plant(): BelongsTo
|
||||
public function plant()
|
||||
{
|
||||
return $this->belongsTo(Plant::class);
|
||||
}
|
||||
|
||||
public function item()
|
||||
{
|
||||
return $this->belongsTo(Item::class, 'item_id', 'id');
|
||||
}
|
||||
|
||||
public function stickerMasters()
|
||||
{
|
||||
return $this->hasMany(StickerMaster::class, 'item_id', 'id');
|
||||
|
||||
@@ -3,30 +3,32 @@
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Line extends Model
|
||||
{
|
||||
use SoftDeletes;
|
||||
|
||||
protected $fillable = [
|
||||
"plant_id",
|
||||
"name",
|
||||
"type",
|
||||
"group_work_center",
|
||||
"no_of_operation",
|
||||
"work_group1_id",
|
||||
"work_group2_id",
|
||||
"work_group3_id",
|
||||
"work_group4_id",
|
||||
"work_group5_id",
|
||||
"work_group6_id",
|
||||
"work_group7_id",
|
||||
"work_group8_id",
|
||||
"work_group9_id",
|
||||
"work_group10_id",
|
||||
'plant_id',
|
||||
'block_id',
|
||||
'name',
|
||||
'type',
|
||||
'line_capacity',
|
||||
'group_work_center',
|
||||
'no_of_operation',
|
||||
'work_group1_id',
|
||||
'work_group2_id',
|
||||
'work_group3_id',
|
||||
'work_group4_id',
|
||||
'work_group5_id',
|
||||
'work_group6_id',
|
||||
'work_group7_id',
|
||||
'work_group8_id',
|
||||
'work_group9_id',
|
||||
'work_group10_id',
|
||||
];
|
||||
|
||||
public function plant(): BelongsTo
|
||||
@@ -34,6 +36,11 @@ class Line extends Model
|
||||
return $this->belongsTo(Plant::class);
|
||||
}
|
||||
|
||||
public function block(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Block::class);
|
||||
}
|
||||
|
||||
public function testingPanelReadings()
|
||||
{
|
||||
return $this->hasMany(TestingPanelReading::class);
|
||||
|
||||
@@ -16,9 +16,12 @@ class ProductionPlan extends Model
|
||||
protected $fillable = [
|
||||
'plant_id',
|
||||
'shift_id',
|
||||
'item_id',
|
||||
'line_id',
|
||||
'plan_quantity',
|
||||
'production_quantity',
|
||||
'working_days',
|
||||
'leave_dates',
|
||||
'operator_id',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
@@ -39,6 +42,11 @@ class ProductionPlan extends Model
|
||||
return $this->belongsTo(Line::class);
|
||||
}
|
||||
|
||||
public function item(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Item::class);
|
||||
}
|
||||
|
||||
public function prunable(): Builder
|
||||
{
|
||||
return static::where('created_at', '<=', now()->subMonthsNoOverflow(6));
|
||||
|
||||
@@ -22,6 +22,7 @@ class ProductionQuantity extends Model
|
||||
'shift_id',
|
||||
'line_id',
|
||||
'item_id',
|
||||
'machine_id',
|
||||
'serial_number',
|
||||
'production_order',
|
||||
'operator_id',
|
||||
@@ -53,6 +54,11 @@ class ProductionQuantity extends Model
|
||||
return $this->belongsTo(Item::class);
|
||||
}
|
||||
|
||||
public function machine(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Machine::class);
|
||||
}
|
||||
|
||||
protected static function booted()
|
||||
{
|
||||
static::created(function ($productionQuantity) {
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
"require": {
|
||||
"php": "^8.2",
|
||||
"alperenersoy/filament-export": "^3.0",
|
||||
"althinect/filament-spatie-roles-permissions": "^2.3",
|
||||
"althinect/filament-spatie-roles-permissions": "^3.0",
|
||||
"erag/laravel-pwa": "^1.9",
|
||||
"filament/filament": "^3.3",
|
||||
"intervention/image": "^3.11",
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
$sql = <<<'SQL'
|
||||
ALTER TABLE production_plans
|
||||
ADD COLUMN item_id BIGINT DEFAULT NULL,
|
||||
ADD CONSTRAINT production_plans_item_id_fkey
|
||||
FOREIGN KEY (item_id) REFERENCES items(id);
|
||||
SQL;
|
||||
|
||||
DB::statement($sql);
|
||||
|
||||
$sql1 = <<<'SQL'
|
||||
ALTER TABLE production_plans
|
||||
ADD COLUMN working_days TEXT DEFAULT NULL
|
||||
SQL;
|
||||
|
||||
DB::statement($sql1);
|
||||
|
||||
$sql2 = <<<'SQL'
|
||||
ALTER TABLE production_plans
|
||||
ADD COLUMN leave_dates TEXT DEFAULT NULL
|
||||
SQL;
|
||||
|
||||
DB::statement($sql2);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
// Schema::table('production_plans', function (Blueprint $table) {
|
||||
// //
|
||||
// });
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
$sql = <<<'SQL'
|
||||
ALTER TABLE lines
|
||||
ADD COLUMN block_id BIGINT DEFAULT NULL,
|
||||
ADD CONSTRAINT lines_block_id_fkey
|
||||
FOREIGN KEY (block_id) REFERENCES blocks(id);
|
||||
SQL;
|
||||
|
||||
DB::statement($sql);
|
||||
|
||||
$sql1 = <<<'SQL'
|
||||
ALTER TABLE lines
|
||||
ADD COLUMN line_capacity TEXT DEFAULT NULL
|
||||
SQL;
|
||||
|
||||
DB::statement($sql1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
// Schema::table('lines', function (Blueprint $table) {
|
||||
// //
|
||||
// });
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
$sql1 = <<<'SQL'
|
||||
ALTER TABLE items
|
||||
ADD COLUMN line_id BIGINT DEFAULT NULL,
|
||||
ADD CONSTRAINT items_line_id_fkey
|
||||
FOREIGN KEY (line_id) REFERENCES lines(id);
|
||||
SQL;
|
||||
|
||||
DB::statement($sql1);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
// Schema::table('items', function (Blueprint $table) {
|
||||
// //
|
||||
// });
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
$sql = <<<'SQL'
|
||||
ALTER TABLE production_quantities
|
||||
ADD COLUMN machine_id BIGINT DEFAULT NULL,
|
||||
ADD CONSTRAINT production_quantities_machine_id_fkey
|
||||
FOREIGN KEY (machine_id) REFERENCES machines(id);
|
||||
SQL;
|
||||
|
||||
DB::statement($sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
// Schema::table('production_quantities', function (Blueprint $table) {
|
||||
// //
|
||||
// });
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
DB::statement("
|
||||
ALTER TABLE production_plans
|
||||
ALTER COLUMN shift_id DROP NOT NULL
|
||||
");
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
// Schema::table('production_plans', function (Blueprint $table) {
|
||||
// //
|
||||
// });
|
||||
}
|
||||
};
|
||||
@@ -189,5 +189,8 @@ class PermissionSeeder extends Seeder
|
||||
|
||||
Permission::updateOrCreate(['name' => 'view import characteristic approver master']);
|
||||
Permission::updateOrCreate(['name' => 'view export characteristic approver master']);
|
||||
|
||||
Permission::updateOrCreate(['name' => 'view production calender page']);
|
||||
Permission::updateOrCreate(['name' => 'view production target page']);
|
||||
}
|
||||
}
|
||||
|
||||
13
resources/views/filament/pages/production-calender.blade.php
Normal file
13
resources/views/filament/pages/production-calender.blade.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<x-filament-panels::page>
|
||||
|
||||
<div class="space-y-4">
|
||||
|
||||
{{-- Render the Select form fields --}}
|
||||
<div class="space-y-4">
|
||||
{{ $this->form }}
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
</x-filament-panels::page>
|
||||
@@ -7,6 +7,8 @@
|
||||
{{ $this->form }}
|
||||
</div>
|
||||
|
||||
{{-- <livewire:notification-sound /> --}}
|
||||
|
||||
{{-- <input
|
||||
type="text"
|
||||
id="qr-scan-input"
|
||||
@@ -15,7 +17,7 @@
|
||||
autocomplete="off"
|
||||
autofocus
|
||||
/> --}}
|
||||
<div class="mb-4">
|
||||
{{-- <div class="mb-4">
|
||||
<label for="qr-scan-input" class="block text-sm font-medium text-gray-700 mb-2">
|
||||
SCAN QR CODE
|
||||
</label>
|
||||
@@ -27,11 +29,64 @@
|
||||
autocomplete="off"
|
||||
autofocus
|
||||
/>
|
||||
</div>
|
||||
</div> --}}
|
||||
{{-- <div class="mb-4">
|
||||
<label for="qr-scan-input" class="block text-sm font-medium text-gray-700 mb-2">
|
||||
SCAN QR CODE
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
id="qr-scan-input"
|
||||
class="border border-gray-300 rounded px-4 py-2 text-sm w-1/2"
|
||||
placeholder="Scan QR Code & Press Enter"
|
||||
autocomplete="off"
|
||||
autofocus
|
||||
/>
|
||||
</div> --}}
|
||||
<div class="flex gap-6 -mt-6">
|
||||
<!-- Scan QR Code -->
|
||||
<div class="w-full">
|
||||
<label for="qr-scan-input" class="block text-sm font-medium text-gray-700 mb-2">
|
||||
SCAN QR CODE
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
id="qr-scan-input"
|
||||
class="border border-gray-300 rounded px-4 py-2 text-sm w-full"
|
||||
placeholder="Scan QR Code & Press Enter"
|
||||
autocomplete="off"
|
||||
autofocus
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- Last Scanned QR -->
|
||||
{{-- <div class="w-1/2">
|
||||
<label for="recent-qr-input" class="block text-sm font-medium text-gray-700 mb-2">
|
||||
LAST SCANNED QR
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
id="recent-qr-input"
|
||||
class="border border-gray-300 rounded px-4 py-2 text-sm w-full bg-white-100 text-black"
|
||||
readonly
|
||||
wire:model="recent_qr"
|
||||
/>
|
||||
</div> --}}
|
||||
</div>
|
||||
|
||||
|
||||
@push('scripts')
|
||||
<script>
|
||||
|
||||
window.addEventListener('focus-production-order', () => {
|
||||
const wrapper = document.getElementById('production_order');
|
||||
const input = wrapper?.querySelector('input,textarea');
|
||||
if (input) {
|
||||
input.focus();
|
||||
input.select();
|
||||
}
|
||||
});
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
const scanInput = document.getElementById('qr-scan-input');
|
||||
if (!scanInput) return;
|
||||
@@ -48,6 +103,7 @@
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
</script>
|
||||
@endpush
|
||||
|
||||
19
resources/views/filament/pages/production-target.blade.php
Normal file
19
resources/views/filament/pages/production-target.blade.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<x-filament-panels::page>
|
||||
<div class="space-y-4">
|
||||
|
||||
{{-- Render the Select form fields --}}
|
||||
<div class="space-y-4">
|
||||
{{ $this->form }}
|
||||
</div>
|
||||
<x-filament::button
|
||||
wire:click="export"
|
||||
color="primary"
|
||||
class="mt-4"
|
||||
>
|
||||
Export
|
||||
</x-filament::button>
|
||||
<div class="bg-white shadow rounded-xl p-4 mt-6">
|
||||
<livewire:production-target-plan />
|
||||
</div>
|
||||
</div>
|
||||
</x-filament-panels::page>
|
||||
121
resources/views/forms/calendar.blade.php
Normal file
121
resources/views/forms/calendar.blade.php
Normal file
@@ -0,0 +1,121 @@
|
||||
<!-- <select id="yearSelect">
|
||||
<option value="">Select Year</option>
|
||||
</select> -->
|
||||
|
||||
|
||||
<div id="calendar" wire:ignore></div>
|
||||
|
||||
|
||||
<!-- <input type="text" name="working_days" placeholder="Working Days"> -->
|
||||
|
||||
<link href="https://cdn.jsdelivr.net/npm/fullcalendar@6.1.8/index.global.min.css" rel="stylesheet">
|
||||
<script src="https://cdn.jsdelivr.net/npm/fullcalendar@6.1.8/index.global.min.js"></script>
|
||||
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
|
||||
let selectedDates = [];
|
||||
let calendarEl = document.getElementById('calendar');
|
||||
|
||||
var calendar = new FullCalendar.Calendar(calendarEl, {
|
||||
initialView: 'dayGridMonth',
|
||||
height: 600,
|
||||
showNonCurrentDates: true,
|
||||
|
||||
datesSet: function(info) {
|
||||
// Clear previous month selections
|
||||
selectedDates = [];
|
||||
|
||||
// Remove background events
|
||||
calendar.removeAllEvents();
|
||||
|
||||
// Recalculate working days for new month
|
||||
updateWorkingDays(info.view.currentStart);
|
||||
},
|
||||
|
||||
dateClick: function(info) {
|
||||
|
||||
let viewMonth = calendar.view.currentStart.getMonth();
|
||||
let clickedMonth = info.date.getMonth();
|
||||
|
||||
if (viewMonth != clickedMonth) return;
|
||||
|
||||
let dateStr = info.dateStr;
|
||||
|
||||
if (selectedDates.includes(dateStr)) {
|
||||
selectedDates = selectedDates.filter(d => d !== dateStr);
|
||||
|
||||
calendar.getEvents().forEach(event => {
|
||||
if (event.startStr == dateStr) event.remove();
|
||||
});
|
||||
|
||||
} else {
|
||||
selectedDates.push(dateStr);
|
||||
|
||||
calendar.addEvent({
|
||||
start: dateStr,
|
||||
display: 'background',
|
||||
color: '#f03f17'
|
||||
});
|
||||
}
|
||||
|
||||
updateWorkingDays(info.date);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// function updateWorkingDays(date) {
|
||||
// let totalDays = new Date(
|
||||
// date.getFullYear(),
|
||||
// date.getMonth()+1,
|
||||
// 0
|
||||
// ).getDate();
|
||||
|
||||
// let workingDays = totalDays - selectedDates.length;
|
||||
// // document.querySelector('input[name="working_days"]').value = workingDays;
|
||||
|
||||
// const input = document.querySelector('#working_days');
|
||||
|
||||
// input.value = workingDays;
|
||||
|
||||
// input.dispatchEvent(new Event('input'));
|
||||
|
||||
// const monthInput = document.querySelector('#month');
|
||||
// monthInput.value = date.getMonth() + 1; // 1–12 month number
|
||||
// monthInput.dispatchEvent(new Event('input'));
|
||||
|
||||
// const yearInput = document.querySelector('#year');
|
||||
// yearInput.value = date.getFullYear();
|
||||
// yearInput.dispatchEvent(new Event('input'));
|
||||
|
||||
// const selectedDatesInput = document.querySelector('#selected_dates');
|
||||
// selectedDatesInput.value = selectedDates.join(',');
|
||||
// selectedDatesInput.dispatchEvent(new Event('input'));
|
||||
|
||||
// }
|
||||
|
||||
function updateWorkingDays(date) {
|
||||
let totalDays = new Date(
|
||||
date.getFullYear(),
|
||||
date.getMonth() + 1,
|
||||
0
|
||||
).getDate();
|
||||
|
||||
let workingDays = totalDays - selectedDates.length;
|
||||
|
||||
// Set values only
|
||||
document.querySelector('#working_days').value = workingDays;
|
||||
document.querySelector('#month').value = date.getMonth() + 1;
|
||||
document.querySelector('#year').value = date.getFullYear();
|
||||
document.querySelector('#selected_dates').value = selectedDates.join(',');
|
||||
|
||||
// Trigger only ONE update (important)
|
||||
document
|
||||
.querySelector('#selected_dates')
|
||||
.dispatchEvent(new Event('input'));
|
||||
}
|
||||
|
||||
|
||||
calendar.render();
|
||||
});
|
||||
</script>
|
||||
9
resources/views/forms/save.php
Normal file
9
resources/views/forms/save.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<div class="flex space-x-2 items-center">
|
||||
<button
|
||||
type="button"
|
||||
class="inline-flex items-center px-3 py-1 bg-primary-600 text-white rounded hover:bg-primary-700"
|
||||
wire:click="saveWorkingDays"
|
||||
>
|
||||
Save
|
||||
</button>
|
||||
</div>
|
||||
86
resources/views/livewire/production-target-plan.blade.php
Normal file
86
resources/views/livewire/production-target-plan.blade.php
Normal file
@@ -0,0 +1,86 @@
|
||||
<div class="p-4">
|
||||
<h2 class="text-lg font-bold mb-4 text-gray-700 uppercase tracking-wider">
|
||||
PRODUCTION PLAN TABLE:
|
||||
</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-s font-semibold uppercase text-gray-700">
|
||||
<tr>
|
||||
<th class="border px-4 py-2" rowspan="3">No</th>
|
||||
<th class="border px-4 py-2 whitespace-nowrap" rowspan="3">Plant</th>
|
||||
<th class="border px-4 py-2 whitespace-nowrap" rowspan="3">Line</th>
|
||||
<th class="border px-4 py-2 whitespace-nowrap" rowspan="3">Item Code</th>
|
||||
|
||||
<th class="border px-4 py-2 whitespace-nowrap" colspan="{{ count($dates) * 3 }}" class="text-center">
|
||||
Production Plan Dates
|
||||
</th>
|
||||
</tr>
|
||||
<tr>
|
||||
@foreach($dates as $date)
|
||||
{{-- <th colspan="3" class="text-center">
|
||||
{{ $date }}
|
||||
</th> --}}
|
||||
<th colspan="3" class="text-center border-r-4 border-gray-400">
|
||||
{{ $date }}
|
||||
</th>
|
||||
@endforeach
|
||||
</tr>
|
||||
<tr>
|
||||
@foreach($dates as $date)
|
||||
<th class="border px-4 py-2 whitespace-nowrap">Line Capacity</th>
|
||||
<th class="border px-4 py-2 whitespace-nowrap">Target Plan</th>
|
||||
<th class="border px-4 py-2 whitespace-nowrap border-r-4 border-gray-400">
|
||||
Produced Quantity
|
||||
</th>
|
||||
|
||||
{{-- <th class="border px-4 py-2 whitespace-nowrap">Produced Quantity</th> --}}
|
||||
@endforeach
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody class="divide-y divide-gray-100">
|
||||
@forelse ($records as $index => $record)
|
||||
<tr class="hover:bg-gray-50">
|
||||
<td class="border px-4 py-2">{{ $index + 1 }}</td>
|
||||
<td class="border px-4 py-2 whitespace-nowrap">{{ $record['plant_name'] }}</td>
|
||||
<td class="border px-4 py-2 whitespace-nowrap">{{ $record['line_name'] }}</td>
|
||||
<td class="border px-4 py-2 whitespace-nowrap">{{ $record['item_code'] }}</td>
|
||||
|
||||
{{-- @foreach($dates as $date)
|
||||
<td class="border px-4 py-2 whitespace-nowrap">{{ $record['target_plan'][$date] ?? '-' }}</td>
|
||||
<td class="border px-4 py-2 whitespace-nowrap">{{ $record['production_plan'][$date] ?? '-' }}</td>
|
||||
@endforeach --}}
|
||||
|
||||
@foreach($dates as $date)
|
||||
@if(in_array($date, $leaveDates))
|
||||
<td class="border px-4 py-2 whitespace-nowrap">-</td>
|
||||
<td class="border px-4 py-2 whitespace-nowrap">-</td>
|
||||
<td class="border px-4 py-2 whitespace-nowrap">-</td>
|
||||
@else
|
||||
{{-- <td class="border px-4 py-2 whitespace-nowrap">{{ $record['daily_target'] ?? '-' }}</td> --}}
|
||||
<td class="border px-4 py-2 whitespace-nowrap">
|
||||
{{ $record['daily_line_capacity'][$date] ?? '-' }}
|
||||
</td>
|
||||
<td class="border px-4 py-2 whitespace-nowrap">
|
||||
{{ $record['daily_target_dynamic'][$date] ?? '-' }}
|
||||
</td>
|
||||
<td class="border px-4 py-2 whitespace-nowrap">
|
||||
{{ $record['produced_quantity'][$date] ?? '-' }}
|
||||
</td>
|
||||
{{-- <td class="border px-4 py-2 whitespace-nowrap">{{ $record['produced_quantity'] ?? '-' }}</td> --}}
|
||||
@endif
|
||||
@endforeach
|
||||
</tr>
|
||||
@empty
|
||||
<tr>
|
||||
<td colspan="10" class="px-4 py-4 text-center text-gray-500">
|
||||
No production plan data found.
|
||||
</td>
|
||||
</tr>
|
||||
@endforelse
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user