Added production order resource pages
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,186 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\ProductionOrderResource\Pages;
|
||||
|
||||
use App\Filament\Resources\ProductionOrderResource;
|
||||
use App\Models\ProductionOrder;
|
||||
use Filament\Facades\Filament;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateProductionOrder extends CreateRecord
|
||||
{
|
||||
protected static string $resource = ProductionOrderResource::class;
|
||||
|
||||
public function saveProductionOrder()
|
||||
{
|
||||
$plantId = trim($this->form->getState()['plant_id'] ?? '') ?? null;
|
||||
|
||||
$itemId = trim($this->form->getState()['item_id'] ?? '') ?? null;
|
||||
|
||||
$quantity = trim($this->form->getState()['quantity'] ?? '') ?? null;
|
||||
|
||||
$startDate = trim($this->form->getState()['start_date'] ?? '') ?? null;
|
||||
|
||||
$endDate = trim($this->form->getState()['end_date'] ?? '') ?? null;
|
||||
|
||||
$pOrder = trim($this->form->getState()['production_order'] ?? '') ?? null;
|
||||
|
||||
$fSerNo = trim($this->form->getState()['from_serial_number'] ?? '') ?? null;
|
||||
|
||||
$tSerNo = trim($this->form->getState()['to_serial_number'] ?? '') ?? null;
|
||||
|
||||
$operatorName = Filament::auth()->user()?->name;
|
||||
|
||||
if (empty($plantId)) {
|
||||
Notification::make()
|
||||
->title('Plant name cannot be empty!')
|
||||
->danger()
|
||||
->send();
|
||||
|
||||
return;
|
||||
} elseif (empty($itemId)) {
|
||||
Notification::make()
|
||||
->title('Item code cannot be empty!')
|
||||
->danger()
|
||||
->send();
|
||||
|
||||
return;
|
||||
} elseif (empty($quantity)) {
|
||||
Notification::make()
|
||||
->title('Quantity cannot be empty!')
|
||||
->danger()
|
||||
->send();
|
||||
|
||||
return;
|
||||
} elseif (empty($startDate)) {
|
||||
Notification::make()
|
||||
->title('Please choose a Start Date!')
|
||||
->danger()
|
||||
->send();
|
||||
|
||||
return;
|
||||
} elseif (empty($endDate)) {
|
||||
Notification::make()
|
||||
->title('Please choose a End Date!')
|
||||
->danger()
|
||||
->send();
|
||||
|
||||
return;
|
||||
} elseif (empty($pOrder)) {
|
||||
Notification::make()
|
||||
->title('Production order cannot be empty!')
|
||||
->danger()
|
||||
->send();
|
||||
|
||||
return;
|
||||
} elseif (empty($fSerNo)) {
|
||||
Notification::make()
|
||||
->title('From serial number cannot be empty!')
|
||||
->danger()
|
||||
->send();
|
||||
|
||||
return;
|
||||
} elseif (empty($tSerNo)) {
|
||||
Notification::make()
|
||||
->title('To serial number cannot be empty!')
|
||||
->danger()
|
||||
->send();
|
||||
|
||||
return;
|
||||
} elseif (empty($operatorName)) {
|
||||
Notification::make()
|
||||
->title('Operator Name cannot be empty!')
|
||||
->danger()
|
||||
->send();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$dupProd = ProductionOrder::where('plant_id', $plantId)->where('production_order', $pOrder)->first();
|
||||
if ($dupProd) {
|
||||
Notification::make()
|
||||
->title("Production Order '{$pOrder}' already exists in database!")
|
||||
->danger()
|
||||
->send();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$insert = ProductionOrder::create([
|
||||
'plant_id' => $plantId ?? null,
|
||||
'item_id' => $itemId ?? null,
|
||||
'quantity' => $quantity ?? null,
|
||||
'start_date' => $startDate ?? null,
|
||||
'end_date' => $endDate ?? null,
|
||||
'production_order' => $pOrder ?? null,
|
||||
'from_serial_number' => $fSerNo ?? null,
|
||||
'to_serial_number' => $tSerNo ?? null,
|
||||
'created_by' => $operatorName ?? null,
|
||||
]);
|
||||
|
||||
if ($insert) {
|
||||
Notification::make()
|
||||
->title("Production Order '{$pOrder}' saved successfully.")
|
||||
->success()
|
||||
->send();
|
||||
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
'item_id' => $itemId,
|
||||
'quantity' => $quantity,
|
||||
'start_date' => $startDate,
|
||||
'end_date' => $endDate,
|
||||
'production_order' => $pOrder,
|
||||
'from_serial_number' => $fSerNo,
|
||||
'to_serial_number' => $tSerNo,
|
||||
'show_extra_fields' => true,
|
||||
]);
|
||||
|
||||
return;
|
||||
|
||||
} else {
|
||||
Notification::make()
|
||||
->title("Failed to save Production Order '{$pOrder}'!")
|
||||
->danger()
|
||||
->send();
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
'item_id' => $itemId,
|
||||
'quantity' => null,
|
||||
'start_date' => null,
|
||||
'end_date' => null,
|
||||
'production_order' => null,
|
||||
'from_serial_number' => null,
|
||||
'to_serial_number' => null,
|
||||
]);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public function printProductionOrder()
|
||||
{
|
||||
$pOrder = $this->form->getState()['production_order'];
|
||||
|
||||
$pOrder = trim($pOrder) ?? null;
|
||||
|
||||
$pOrderExists = ProductionOrder::where('production_order', $pOrder)->first();
|
||||
|
||||
if (! $pOrderExists) {
|
||||
Notification::make()
|
||||
->title("Production Order '{$pOrder}' does not exist to get print")
|
||||
->danger()
|
||||
->send();
|
||||
|
||||
return;
|
||||
} else {
|
||||
return redirect()->route('production-orders.print', ['production_order' => $pOrder]);
|
||||
}
|
||||
}
|
||||
|
||||
protected function getFormActions(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\ProductionOrderResource\Pages;
|
||||
|
||||
use App\Filament\Resources\ProductionOrderResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditProductionOrder extends EditRecord
|
||||
{
|
||||
protected static string $resource = ProductionOrderResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\ViewAction::make(),
|
||||
Actions\DeleteAction::make(),
|
||||
Actions\ForceDeleteAction::make(),
|
||||
Actions\RestoreAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\ProductionOrderResource\Pages;
|
||||
|
||||
use App\Filament\Resources\ProductionOrderResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListProductionOrders extends ListRecords
|
||||
{
|
||||
protected static string $resource = ProductionOrderResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\ProductionOrderResource\Pages;
|
||||
|
||||
use App\Filament\Resources\ProductionOrderResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ViewRecord;
|
||||
|
||||
class ViewProductionOrder extends ViewRecord
|
||||
{
|
||||
protected static string $resource = ProductionOrderResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\EditAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user