ranjith-dev #853
60
app/Filament/Exports/PanelGrMasterExporter.php
Normal file
60
app/Filament/Exports/PanelGrMasterExporter.php
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Exports;
|
||||||
|
|
||||||
|
use App\Models\PanelGrMaster;
|
||||||
|
use Filament\Actions\Exports\ExportColumn;
|
||||||
|
use Filament\Actions\Exports\Exporter;
|
||||||
|
use Filament\Actions\Exports\Models\Export;
|
||||||
|
|
||||||
|
class PanelGrMasterExporter extends Exporter
|
||||||
|
{
|
||||||
|
protected static ?string $model = PanelGrMaster::class;
|
||||||
|
|
||||||
|
public static function getColumns(): array
|
||||||
|
{
|
||||||
|
static $rowNumber = 0;
|
||||||
|
return [
|
||||||
|
ExportColumn::make('no')
|
||||||
|
->label('NO')
|
||||||
|
->state(function ($record) use (&$rowNumber) {
|
||||||
|
// Increment and return the row number
|
||||||
|
return ++$rowNumber;
|
||||||
|
}),
|
||||||
|
ExportColumn::make('plant.name')
|
||||||
|
->label('PLANT NAME'),
|
||||||
|
ExportColumn::make('item.code')
|
||||||
|
->label('ITEM CODE'),
|
||||||
|
ExportColumn::make('document_number')
|
||||||
|
->label('DOCUMENT NUMBER'),
|
||||||
|
ExportColumn::make('invoice_number')
|
||||||
|
->label('INVOICE NUMBER'),
|
||||||
|
ExportColumn::make('supplier_number')
|
||||||
|
->label('SUPPLIER NUMBER'),
|
||||||
|
ExportColumn::make('quantity')
|
||||||
|
->label('QUANTITY'),
|
||||||
|
ExportColumn::make('created_at')
|
||||||
|
->label('CREATED AT'),
|
||||||
|
ExportColumn::make('updated_at')
|
||||||
|
->label('UPDATED AT'),
|
||||||
|
ExportColumn::make('created_by')
|
||||||
|
->label('CREATED BY'),
|
||||||
|
ExportColumn::make('updated_by')
|
||||||
|
->label('UPDATED BY'),
|
||||||
|
ExportColumn::make('deleted_at')
|
||||||
|
->label('DELETED AT')
|
||||||
|
->enabledByDefault(false),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getCompletedNotificationBody(Export $export): string
|
||||||
|
{
|
||||||
|
$body = 'Your panel gr master export has completed and ' . number_format($export->successful_rows) . ' ' . str('row')->plural($export->successful_rows) . ' exported.';
|
||||||
|
|
||||||
|
if ($failedRowsCount = $export->getFailedRowsCount()) {
|
||||||
|
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to export.';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $body;
|
||||||
|
}
|
||||||
|
}
|
||||||
146
app/Filament/Imports/PanelGrMasterImporter.php
Normal file
146
app/Filament/Imports/PanelGrMasterImporter.php
Normal file
@@ -0,0 +1,146 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Imports;
|
||||||
|
|
||||||
|
use App\Models\Item;
|
||||||
|
use App\Models\PanelGrMaster;
|
||||||
|
use App\Models\Plant;
|
||||||
|
use Filament\Actions\Imports\ImportColumn;
|
||||||
|
use Filament\Actions\Imports\Importer;
|
||||||
|
use Filament\Actions\Imports\Models\Import;
|
||||||
|
use Filament\Facades\Filament;
|
||||||
|
use Str;
|
||||||
|
use Filament\Actions\Imports\Exceptions\RowImportFailedException;
|
||||||
|
|
||||||
|
class PanelGrMasterImporter extends Importer
|
||||||
|
{
|
||||||
|
protected static ?string $model = PanelGrMaster::class;
|
||||||
|
|
||||||
|
public static function getColumns(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
ImportColumn::make('plant')
|
||||||
|
->requiredMapping()
|
||||||
|
->exampleHeader('Plant Code')
|
||||||
|
->example('1000')
|
||||||
|
->label('Plant Code')
|
||||||
|
->relationship(resolveUsing: 'code')
|
||||||
|
->rules(['required']),
|
||||||
|
ImportColumn::make('item')
|
||||||
|
->requiredMapping()
|
||||||
|
->exampleHeader('Item Code')
|
||||||
|
->example('630214')
|
||||||
|
->label('Item Code')
|
||||||
|
->relationship(resolveUsing: 'code')
|
||||||
|
->rules(['required']),
|
||||||
|
ImportColumn::make('document_number')
|
||||||
|
->requiredMapping()
|
||||||
|
->exampleHeader('Document Number')
|
||||||
|
->example('11023567')
|
||||||
|
->label('Document Number')
|
||||||
|
->rules(['required']),
|
||||||
|
ImportColumn::make('invoice_number')
|
||||||
|
->requiredMapping()
|
||||||
|
->exampleHeader('Invoice Number')
|
||||||
|
->example('3RAW0012345')
|
||||||
|
->label('Invoice Number')
|
||||||
|
->rules(['required']),
|
||||||
|
ImportColumn::make('supplier_number')
|
||||||
|
->requiredMapping()
|
||||||
|
->exampleHeader('Supplier Number')
|
||||||
|
->example('154564564')
|
||||||
|
->label('Supplier Number')
|
||||||
|
->rules(['required']),
|
||||||
|
ImportColumn::make('quantity')
|
||||||
|
->requiredMapping()
|
||||||
|
->exampleHeader('Quantity')
|
||||||
|
->example('10')
|
||||||
|
->label('Quantity')
|
||||||
|
->rules(['required']),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function resolveRecord(): ?PanelGrMaster
|
||||||
|
{
|
||||||
|
$warnMsg = [];
|
||||||
|
$plantCod = $this->data['plant'];
|
||||||
|
$plant = null;
|
||||||
|
$item = null;
|
||||||
|
$userName = Filament::auth()->user()?->name;
|
||||||
|
|
||||||
|
if (Str::length($plantCod) < 4 || ! is_numeric($plantCod) || ! preg_match('/^[1-9]\d{3,}$/', $plantCod)) {
|
||||||
|
$warnMsg[] = 'Invalid plant code found';
|
||||||
|
} else {
|
||||||
|
$plant = Plant::where('code', $plantCod)->first();
|
||||||
|
if (! $plant) {
|
||||||
|
$warnMsg[] = 'Plant not found';
|
||||||
|
} else {
|
||||||
|
$item = Item::where('code', $this->data['item'])->where('plant_id', $plant->id)->first();
|
||||||
|
}
|
||||||
|
if (! $item) {
|
||||||
|
$warnMsg[] = 'Item not found';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($this->data['document_number'])) {
|
||||||
|
$warnMsg[] = 'Document Number cannot be empty.';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Str::length($this->data['invoice_number']) < 7 || ! ctype_alnum($this->data['invoice_number'])) {
|
||||||
|
$warnMsg[] = 'Invalid invoice number found';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($this->data['supplier_number'])) {
|
||||||
|
$warnMsg[] = 'Supplier Number cannot be empty.';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($this->data['quantity'])) {
|
||||||
|
$warnMsg[] = 'Quantity cannot be empty.';
|
||||||
|
}
|
||||||
|
elseif (!is_numeric($this->data['quantity'])) {
|
||||||
|
$warnMsg[] = 'Quantity must be a valid number.';
|
||||||
|
} elseif ((float) $this->data['quantity'] <= 0) {
|
||||||
|
$warnMsg[] = 'Quantity must be greater than 0.';
|
||||||
|
}
|
||||||
|
|
||||||
|
$existingRecord = PanelGrMaster::where('document_number', $this->data['document_number'])->where('plant_id', $this->data['plant'])->first();
|
||||||
|
|
||||||
|
if ($existingRecord && $existingRecord->invoice_number != $this->data['invoice_number'])
|
||||||
|
{
|
||||||
|
$warnMsg[] = "Document Number '{$this->data['document_number']}' is already associated with Invoice Number '{$existingRecord->invoice_number}'.";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! empty($warnMsg)) {
|
||||||
|
throw new RowImportFailedException(implode(', ', $warnMsg));
|
||||||
|
}
|
||||||
|
|
||||||
|
PanelGrMaster::updateOrCreate(
|
||||||
|
[
|
||||||
|
'plant_id' => $plant->id,
|
||||||
|
'item_id' => $item->id,
|
||||||
|
'document_number' => $this->data['document_number'],
|
||||||
|
'invoice_number' => $this->data['invoice_number'],
|
||||||
|
'supplier_number' => $this->data['supplier_number'] ?? null,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'quantity' => $this->data['quantity'] ?? null,
|
||||||
|
'updated_by' => $userName,
|
||||||
|
'created_by' => $userName, // Only used when creating
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
return null;
|
||||||
|
// return new PanelGrMaster();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getCompletedNotificationBody(Import $import): string
|
||||||
|
{
|
||||||
|
$body = 'Your panel gr master import has completed and ' . number_format($import->successful_rows) . ' ' . str('row')->plural($import->successful_rows) . ' imported.';
|
||||||
|
|
||||||
|
if ($failedRowsCount = $import->getFailedRowsCount()) {
|
||||||
|
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to import.';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $body;
|
||||||
|
}
|
||||||
|
}
|
||||||
363
app/Filament/Resources/PanelGrMasterResource.php
Normal file
363
app/Filament/Resources/PanelGrMasterResource.php
Normal file
@@ -0,0 +1,363 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources;
|
||||||
|
|
||||||
|
use App\Filament\Exports\PanelGrMasterExporter;
|
||||||
|
use App\Filament\Imports\PanelGrMasterImporter;
|
||||||
|
use App\Filament\Resources\PanelGrMasterResource\Pages;
|
||||||
|
use App\Filament\Resources\PanelGrMasterResource\RelationManagers;
|
||||||
|
use App\Models\Item;
|
||||||
|
use App\Models\PalletValidation;
|
||||||
|
use App\Models\PanelGrMaster;
|
||||||
|
use App\Models\Plant;
|
||||||
|
use Filament\Facades\Filament;
|
||||||
|
use Filament\Forms;
|
||||||
|
use Filament\Forms\Form;
|
||||||
|
use Filament\Resources\Resource;
|
||||||
|
use Filament\Tables;
|
||||||
|
use Filament\Tables\Table;
|
||||||
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
|
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||||
|
use Filament\Tables\Actions\ExportAction;
|
||||||
|
use Filament\Tables\Actions\ImportAction;
|
||||||
|
use Filament\Tables\Filters\Filter;
|
||||||
|
use Filament\Forms\Components\DateTimePicker;
|
||||||
|
use Filament\Forms\Components\Section;
|
||||||
|
use Filament\Forms\Components\Select;
|
||||||
|
use Filament\Forms\Components\TextInput;
|
||||||
|
use Closure;
|
||||||
|
|
||||||
|
class PanelGrMasterResource extends Resource
|
||||||
|
{
|
||||||
|
protected static ?string $model = PanelGrMaster::class;
|
||||||
|
|
||||||
|
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
|
||||||
|
|
||||||
|
protected static ?string $navigationGroup = 'Panel Box';
|
||||||
|
|
||||||
|
public static function form(Form $form): Form
|
||||||
|
{
|
||||||
|
return $form
|
||||||
|
->schema([
|
||||||
|
Forms\Components\Select::make('plant_id')
|
||||||
|
->label('Plant')
|
||||||
|
->reactive()
|
||||||
|
->searchable()
|
||||||
|
->relationship('plant', 'name')
|
||||||
|
->options(function (callable $get) {
|
||||||
|
$userHas = Filament::auth()->user()->plant_id;
|
||||||
|
|
||||||
|
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
|
||||||
|
})
|
||||||
|
->afterStateUpdated(function (callable $set) {
|
||||||
|
$set('item_id', null);
|
||||||
|
$set('document_number', null);
|
||||||
|
$set('invoice_number', null);
|
||||||
|
$set('supplier_number', null);
|
||||||
|
$set('quantity', '1');
|
||||||
|
})
|
||||||
|
->required(),
|
||||||
|
Forms\Components\Select::make('item_id')
|
||||||
|
->label('Item Code')
|
||||||
|
->reactive()
|
||||||
|
->searchable()
|
||||||
|
->options(function (callable $get) {
|
||||||
|
$plantId = $get('plant_id');
|
||||||
|
if (empty($plantId)) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
return Item::where('plant_id', $plantId)->pluck('code', 'id');
|
||||||
|
})
|
||||||
|
->afterStateUpdated(function (callable $set) {
|
||||||
|
$set('document_number', null);
|
||||||
|
$set('invoice_number', null);
|
||||||
|
$set('supplier_number', null);
|
||||||
|
$set('quantity', '1');
|
||||||
|
})
|
||||||
|
->required(),
|
||||||
|
Forms\Components\TextInput::make('document_number')
|
||||||
|
->label('Document Number')
|
||||||
|
->required(),
|
||||||
|
Forms\Components\TextInput::make('invoice_number')
|
||||||
|
->label('Invoice Number')
|
||||||
|
->required(),
|
||||||
|
Forms\Components\TextInput::make('supplier_number')
|
||||||
|
->label('Supplier Number')
|
||||||
|
->required(),
|
||||||
|
Forms\Components\TextInput::make('quantity')
|
||||||
|
->label('Quantity')
|
||||||
|
->numeric()
|
||||||
|
->default(1)
|
||||||
|
->minValue(1)
|
||||||
|
->reactive()
|
||||||
|
->required()
|
||||||
|
->afterStateUpdated(function (callable $set, $state) {
|
||||||
|
if ((float) $state == 0) {
|
||||||
|
$set('quantity', null);
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
Forms\Components\Hidden::make('created_by')
|
||||||
|
->label('Created By')
|
||||||
|
->default(Filament::auth()->user()?->name),
|
||||||
|
Forms\Components\Hidden::make('updated_by')
|
||||||
|
->label('Updated By')
|
||||||
|
->default(Filament::auth()->user()?->name),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function table(Table $table): Table
|
||||||
|
{
|
||||||
|
return $table
|
||||||
|
->columns([
|
||||||
|
Tables\Columns\TextColumn::make('No.')
|
||||||
|
->label('No.')
|
||||||
|
->getStateUsing(function ($record, $livewire, $column, $rowLoop) {
|
||||||
|
$paginator = $livewire->getTableRecords();
|
||||||
|
$perPage = method_exists($paginator, 'perPage') ? $paginator->perPage() : 10;
|
||||||
|
$currentPage = method_exists($paginator, 'currentPage') ? $paginator->currentPage() : 1;
|
||||||
|
|
||||||
|
return ($currentPage - 1) * $perPage + $rowLoop->iteration;
|
||||||
|
}),
|
||||||
|
Tables\Columns\TextColumn::make('plant.name')
|
||||||
|
->label('Plant Name')
|
||||||
|
->searchable()
|
||||||
|
->alignCenter()
|
||||||
|
->sortable(),
|
||||||
|
Tables\Columns\TextColumn::make('item.code')
|
||||||
|
->label('Item Code')
|
||||||
|
->searchable()
|
||||||
|
->alignCenter()
|
||||||
|
->sortable(),
|
||||||
|
Tables\Columns\TextColumn::make('document_number')
|
||||||
|
->label('Document Number')
|
||||||
|
->searchable()
|
||||||
|
->alignCenter()
|
||||||
|
->sortable(),
|
||||||
|
Tables\Columns\TextColumn::make('invoice_number')
|
||||||
|
->label('Invoice Number')
|
||||||
|
->searchable()
|
||||||
|
->alignCenter()
|
||||||
|
->sortable(),
|
||||||
|
Tables\Columns\TextColumn::make('supplier_number')
|
||||||
|
->label('Supplier Number')
|
||||||
|
->searchable()
|
||||||
|
->alignCenter()
|
||||||
|
->sortable(),
|
||||||
|
Tables\Columns\TextColumn::make('quantity')
|
||||||
|
->label('Quantity')
|
||||||
|
->searchable()
|
||||||
|
->alignCenter()
|
||||||
|
->sortable(),
|
||||||
|
Tables\Columns\TextColumn::make('created_at')
|
||||||
|
->dateTime()
|
||||||
|
->alignCenter()
|
||||||
|
->sortable()
|
||||||
|
->toggleable(isToggledHiddenByDefault: true),
|
||||||
|
Tables\Columns\TextColumn::make('updated_at')
|
||||||
|
->dateTime()
|
||||||
|
->alignCenter()
|
||||||
|
->sortable()
|
||||||
|
->toggleable(isToggledHiddenByDefault: true),
|
||||||
|
Tables\Columns\TextColumn::make('deleted_at')
|
||||||
|
->dateTime()
|
||||||
|
->sortable()
|
||||||
|
->toggleable(isToggledHiddenByDefault: true),
|
||||||
|
])
|
||||||
|
->filters([
|
||||||
|
Tables\Filters\TrashedFilter::make(),
|
||||||
|
Filter::make('advanced_filters')
|
||||||
|
->label('Advanced Filters')
|
||||||
|
->form([
|
||||||
|
Select::make('Plant')
|
||||||
|
->label('Select Plant')
|
||||||
|
->nullable()
|
||||||
|
->options(function (callable $get) {
|
||||||
|
$userHas = Filament::auth()->user()->plant_id;
|
||||||
|
|
||||||
|
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
|
||||||
|
})
|
||||||
|
->reactive()
|
||||||
|
->afterStateUpdated(function ($state, callable $set, callable $get): void {
|
||||||
|
$set('scanned_by', null);
|
||||||
|
}),
|
||||||
|
Select::make('item')
|
||||||
|
->label('Search by Item Code')
|
||||||
|
->nullable()
|
||||||
|
->searchable()
|
||||||
|
->reactive()
|
||||||
|
->options(function (callable $get) {
|
||||||
|
$plantId = $get('Plant');
|
||||||
|
|
||||||
|
if (empty($plantId)) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
return Item::whereHas('panelGrMasters', function ($query) use ($plantId) {
|
||||||
|
if ($plantId) {
|
||||||
|
$query->where('plant_id', $plantId);
|
||||||
|
}
|
||||||
|
})->pluck('code', 'id');
|
||||||
|
})
|
||||||
|
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||||
|
$set('process_order', null);
|
||||||
|
}),
|
||||||
|
TextInput::make('document_number')
|
||||||
|
->label('Document Number')
|
||||||
|
->reactive()
|
||||||
|
->placeholder('Enter Document Number')
|
||||||
|
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||||
|
$set('Rework', null);
|
||||||
|
}),
|
||||||
|
TextInput::make('invoice_number')
|
||||||
|
->label('Invoice Number')
|
||||||
|
->reactive()
|
||||||
|
->placeholder('Enter Invoice Number')
|
||||||
|
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||||
|
$set('Rework', null);
|
||||||
|
}),
|
||||||
|
TextInput::make('supplier_number')
|
||||||
|
->label('Supplier Number')
|
||||||
|
->reactive()
|
||||||
|
->placeholder('Enter Supplier Number')
|
||||||
|
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||||
|
$set('Rework', null);
|
||||||
|
}),
|
||||||
|
DateTimePicker::make(name: 'created_from')
|
||||||
|
->label('Created From')
|
||||||
|
->placeholder(placeholder: 'Select From DateTime')
|
||||||
|
->reactive()
|
||||||
|
->native(false),
|
||||||
|
DateTimePicker::make('created_to')
|
||||||
|
->label('Created To')
|
||||||
|
->placeholder(placeholder: 'Select To DateTime')
|
||||||
|
->reactive()
|
||||||
|
->native(false),
|
||||||
|
])
|
||||||
|
->query(function ($query, array $data) {
|
||||||
|
// Hide all records initially if no filters are applied
|
||||||
|
if (empty($data['Plant']) && empty($data['document_number']) && empty($data['invoice_number']) && empty($data['supplier_number']) && empty($data['created_from']) && empty($data['created_to']) && empty($data['created_by'])) {
|
||||||
|
return $query->whereRaw('1 = 0');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! empty($data['Plant'])) { // $plant = $data['Plant'] ?? null
|
||||||
|
$query->where('plant_id', $data['Plant']);
|
||||||
|
} else {
|
||||||
|
$userHas = Filament::auth()->user()->plant_id;
|
||||||
|
|
||||||
|
if ($userHas && strlen($userHas) > 0) {
|
||||||
|
return $query->whereRaw('1 = 0');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! empty($data['document_number'])) {
|
||||||
|
$query->where('document_number', 'like', '%' . $data['document_number'] . '%');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! empty($data['invoice_number'])) {
|
||||||
|
$query->where('invoice_number', 'like', '%' . $data['invoice_number'] . '%');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! empty($data['supplier_number'])) {
|
||||||
|
$query->where('supplier_number', 'like', '%' . $data['supplier_number'] . '%');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! empty($data['created_from'])) {
|
||||||
|
$query->where('created_at', '>=', $data['created_from']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! empty($data['created_to'])) {
|
||||||
|
$query->where('created_at', '<=', $data['created_to']);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
->indicateUsing(function (array $data) {
|
||||||
|
$indicators = [];
|
||||||
|
|
||||||
|
if (! empty($data['Plant'])) {
|
||||||
|
$indicators[] = 'Plant: '.Plant::where('id', $data['Plant'])->value('name');
|
||||||
|
} else {
|
||||||
|
$userHas = Filament::auth()->user()->plant_id;
|
||||||
|
|
||||||
|
if ($userHas && strlen($userHas) > 0) {
|
||||||
|
return 'Plant: Choose plant to filter records.';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! empty($data['document_number'])) {
|
||||||
|
$indicators[] = 'Doc No: '.$data['document_number'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! empty($data['invoice_number'])) {
|
||||||
|
$indicators[] = 'Invoice No: '.$data['invoice_number'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! empty($data['supplier_number'])) {
|
||||||
|
$indicators[] = 'Supplier No: '.$data['supplier_number'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! empty($data['created_from'])) {
|
||||||
|
$indicators[] = 'From: '.$data['created_from'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! empty($data['created_to'])) {
|
||||||
|
$indicators[] = 'To: '.$data['created_to'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $indicators;
|
||||||
|
}),
|
||||||
|
])
|
||||||
|
->filtersFormMaxHeight('280px')
|
||||||
|
->actions([
|
||||||
|
Tables\Actions\ViewAction::make(),
|
||||||
|
Tables\Actions\EditAction::make(),
|
||||||
|
])
|
||||||
|
->bulkActions([
|
||||||
|
Tables\Actions\BulkActionGroup::make([
|
||||||
|
Tables\Actions\DeleteBulkAction::make(),
|
||||||
|
Tables\Actions\ForceDeleteBulkAction::make(),
|
||||||
|
Tables\Actions\RestoreBulkAction::make(),
|
||||||
|
]),
|
||||||
|
])
|
||||||
|
->headerActions([
|
||||||
|
ImportAction::make()
|
||||||
|
->label('Import Panel GR Masters')
|
||||||
|
->color('warning')
|
||||||
|
->importer(PanelGrMasterImporter::class)
|
||||||
|
->visible(function () {
|
||||||
|
return Filament::auth()->user()->can('view import panel gr master');
|
||||||
|
}),
|
||||||
|
ExportAction::make()
|
||||||
|
->label('Export Panel GR Masters')
|
||||||
|
->color('warning')
|
||||||
|
->exporter(PanelGrMasterExporter::class)
|
||||||
|
->visible(function () {
|
||||||
|
return Filament::auth()->user()->can('view export panel gr master');
|
||||||
|
}),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getRelations(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
//
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getPages(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'index' => Pages\ListPanelGrMasters::route('/'),
|
||||||
|
'create' => Pages\CreatePanelGrMaster::route('/create'),
|
||||||
|
'view' => Pages\ViewPanelGrMaster::route('/{record}'),
|
||||||
|
'edit' => Pages\EditPanelGrMaster::route('/{record}/edit'),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getEloquentQuery(): Builder
|
||||||
|
{
|
||||||
|
return parent::getEloquentQuery()
|
||||||
|
->withoutGlobalScopes([
|
||||||
|
SoftDeletingScope::class,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\PanelGrMasterResource\Pages;
|
||||||
|
|
||||||
|
use App\Filament\Resources\PanelGrMasterResource;
|
||||||
|
use App\Models\PanelGrMaster;
|
||||||
|
use Filament\Actions;
|
||||||
|
use Filament\Notifications\Notification;
|
||||||
|
use Filament\Resources\Pages\CreateRecord;
|
||||||
|
use Illuminate\Validation\ValidationException;
|
||||||
|
|
||||||
|
class CreatePanelGrMaster extends CreateRecord
|
||||||
|
{
|
||||||
|
protected static string $resource = PanelGrMasterResource::class;
|
||||||
|
|
||||||
|
protected function mutateFormDataBeforeCreate(array $data): array
|
||||||
|
{
|
||||||
|
$exists = PanelGrMaster::where('plant_id', $data['plant_id'])
|
||||||
|
->where('item_id', $data['item_id'])
|
||||||
|
->where('document_number', $data['document_number'])
|
||||||
|
->where('invoice_number', $data['invoice_number'])
|
||||||
|
->where('supplier_number', $data['supplier_number'])
|
||||||
|
->exists();
|
||||||
|
|
||||||
|
if ($exists) {
|
||||||
|
Notification::make()
|
||||||
|
->title('Duplicate Record')
|
||||||
|
->body('This combination already exists in Master.')
|
||||||
|
->danger()
|
||||||
|
->send();
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'item_id' => 'This combination already exists in Master.',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\PanelGrMasterResource\Pages;
|
||||||
|
|
||||||
|
use App\Filament\Resources\PanelGrMasterResource;
|
||||||
|
use Filament\Actions;
|
||||||
|
use Filament\Resources\Pages\EditRecord;
|
||||||
|
|
||||||
|
class EditPanelGrMaster extends EditRecord
|
||||||
|
{
|
||||||
|
protected static string $resource = PanelGrMasterResource::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\PanelGrMasterResource\Pages;
|
||||||
|
|
||||||
|
use App\Filament\Resources\PanelGrMasterResource;
|
||||||
|
use Filament\Actions;
|
||||||
|
use Filament\Resources\Pages\ListRecords;
|
||||||
|
|
||||||
|
class ListPanelGrMasters extends ListRecords
|
||||||
|
{
|
||||||
|
protected static string $resource = PanelGrMasterResource::class;
|
||||||
|
|
||||||
|
protected function getHeaderActions(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
Actions\CreateAction::make(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\PanelGrMasterResource\Pages;
|
||||||
|
|
||||||
|
use App\Filament\Resources\PanelGrMasterResource;
|
||||||
|
use Filament\Actions;
|
||||||
|
use Filament\Resources\Pages\ViewRecord;
|
||||||
|
|
||||||
|
class ViewPanelGrMaster extends ViewRecord
|
||||||
|
{
|
||||||
|
protected static string $resource = PanelGrMasterResource::class;
|
||||||
|
|
||||||
|
protected function getHeaderActions(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
Actions\EditAction::make(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
33
app/Models/PanelGrMaster.php
Normal file
33
app/Models/PanelGrMaster.php
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
|
|
||||||
|
class PanelGrMaster extends Model
|
||||||
|
{
|
||||||
|
use SoftDeletes;
|
||||||
|
|
||||||
|
protected $fillable = [
|
||||||
|
'plant_id',
|
||||||
|
'item_id',
|
||||||
|
'document_number',
|
||||||
|
'invoice_number',
|
||||||
|
'supplier_number',
|
||||||
|
'quantity',
|
||||||
|
'created_by',
|
||||||
|
'updated_by'
|
||||||
|
];
|
||||||
|
|
||||||
|
public function plant(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(Plant::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function item(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(Item::class);
|
||||||
|
}
|
||||||
|
}
|
||||||
106
app/Policies/PanelGrMasterPolicy.php
Normal file
106
app/Policies/PanelGrMasterPolicy.php
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Policies;
|
||||||
|
|
||||||
|
use Illuminate\Auth\Access\Response;
|
||||||
|
use App\Models\PanelGrMaster;
|
||||||
|
use App\Models\User;
|
||||||
|
|
||||||
|
class PanelGrMasterPolicy
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine whether the user can view any models.
|
||||||
|
*/
|
||||||
|
public function viewAny(User $user): bool
|
||||||
|
{
|
||||||
|
return $user->checkPermissionTo('view-any PanelGrMaster');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine whether the user can view the model.
|
||||||
|
*/
|
||||||
|
public function view(User $user, PanelGrMaster $panelgrmaster): bool
|
||||||
|
{
|
||||||
|
return $user->checkPermissionTo('view PanelGrMaster');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine whether the user can create models.
|
||||||
|
*/
|
||||||
|
public function create(User $user): bool
|
||||||
|
{
|
||||||
|
return $user->checkPermissionTo('create PanelGrMaster');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine whether the user can update the model.
|
||||||
|
*/
|
||||||
|
public function update(User $user, PanelGrMaster $panelgrmaster): bool
|
||||||
|
{
|
||||||
|
return $user->checkPermissionTo('update PanelGrMaster');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine whether the user can delete the model.
|
||||||
|
*/
|
||||||
|
public function delete(User $user, PanelGrMaster $panelgrmaster): bool
|
||||||
|
{
|
||||||
|
return $user->checkPermissionTo('delete PanelGrMaster');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine whether the user can delete any models.
|
||||||
|
*/
|
||||||
|
public function deleteAny(User $user): bool
|
||||||
|
{
|
||||||
|
return $user->checkPermissionTo('delete-any PanelGrMaster');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine whether the user can restore the model.
|
||||||
|
*/
|
||||||
|
public function restore(User $user, PanelGrMaster $panelgrmaster): bool
|
||||||
|
{
|
||||||
|
return $user->checkPermissionTo('restore PanelGrMaster');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine whether the user can restore any models.
|
||||||
|
*/
|
||||||
|
public function restoreAny(User $user): bool
|
||||||
|
{
|
||||||
|
return $user->checkPermissionTo('restore-any PanelGrMaster');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine whether the user can replicate the model.
|
||||||
|
*/
|
||||||
|
public function replicate(User $user, PanelGrMaster $panelgrmaster): bool
|
||||||
|
{
|
||||||
|
return $user->checkPermissionTo('replicate PanelGrMaster');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine whether the user can reorder the models.
|
||||||
|
*/
|
||||||
|
public function reorder(User $user): bool
|
||||||
|
{
|
||||||
|
return $user->checkPermissionTo('reorder PanelGrMaster');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine whether the user can permanently delete the model.
|
||||||
|
*/
|
||||||
|
public function forceDelete(User $user, PanelGrMaster $panelgrmaster): bool
|
||||||
|
{
|
||||||
|
return $user->checkPermissionTo('force-delete PanelGrMaster');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine whether the user can permanently delete any models.
|
||||||
|
*/
|
||||||
|
public function forceDeleteAny(User $user): bool
|
||||||
|
{
|
||||||
|
return $user->checkPermissionTo('force-delete-any PanelGrMaster');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
<?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'
|
||||||
|
CREATE TABLE panel_gr_masters (
|
||||||
|
id BIGINT GENERATED always AS IDENTITY PRIMARY KEY,
|
||||||
|
|
||||||
|
plant_id BIGINT NOT NULL,
|
||||||
|
item_id BIGINT NOT NULL,
|
||||||
|
|
||||||
|
document_number TEXT DEFAULT NULL,
|
||||||
|
invoice_number TEXT DEFAULT NULL,
|
||||||
|
supplier_number TEXT DEFAULT NULL,
|
||||||
|
quantity TEXT DEFAULT NULL,
|
||||||
|
|
||||||
|
created_at TIMESTAMP NOT NULL DEFAULT NOW(),
|
||||||
|
updated_at TIMESTAMP,
|
||||||
|
deleted_at TIMESTAMP,
|
||||||
|
|
||||||
|
created_by TEXT NULL,
|
||||||
|
updated_by TEXT NULL,
|
||||||
|
|
||||||
|
FOREIGN KEY (plant_id) REFERENCES plants (id),
|
||||||
|
FOREIGN KEY (item_id) REFERENCES items (id)
|
||||||
|
);
|
||||||
|
SQL;
|
||||||
|
|
||||||
|
DB::statement($sql);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('panel_gr_masters');
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user