Added spare packing resource pages
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 13s
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 13s
This commit is contained in:
340
app/Filament/Resources/SparePackingResource.php
Normal file
340
app/Filament/Resources/SparePackingResource.php
Normal file
@@ -0,0 +1,340 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use App\Filament\Resources\SparePackingResource\Pages;
|
||||
use App\Filament\Resources\SparePackingResource\RelationManagers;
|
||||
use App\Models\Plant;
|
||||
use App\Models\SaleOrderMaster;
|
||||
use App\Models\SparePacking;
|
||||
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\Forms\Components\Section;
|
||||
use Filament\Tables\Actions\ExportAction;
|
||||
use Filament\Tables\Actions\ImportAction;
|
||||
use App\Filament\Exports\SparePackingExporter;
|
||||
use App\Filament\Imports\SparePackingImporter;
|
||||
|
||||
class SparePackingResource extends Resource
|
||||
{
|
||||
protected static ?string $model = SparePacking::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
|
||||
|
||||
protected static ?string $navigationGroup = 'Spare Packing';
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
Section::make('')
|
||||
->schema([
|
||||
Forms\Components\Select::make('plant_id')
|
||||
->label('Plant')
|
||||
->reactive()
|
||||
->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();
|
||||
})
|
||||
->required(),
|
||||
Forms\Components\Select::make('sale_order_master_id')
|
||||
->label('Sale Order Number')
|
||||
->reactive()
|
||||
->searchable()
|
||||
->options(function (callable $get) {
|
||||
$plantId = $get('plant_id');
|
||||
if (empty($plantId)) {
|
||||
return [];
|
||||
}
|
||||
return SaleOrderMaster::where('plant_id', $plantId)->distinct()->pluck('sale_order_number', 'sale_order_number');
|
||||
|
||||
})
|
||||
->required()
|
||||
->afterStateUpdated(function ($state, callable $set) {
|
||||
$set('spare_packing_number', null);
|
||||
}),
|
||||
Forms\Components\TextInput::make('spare_packing_number')
|
||||
->label('Scan Spare Packing No')
|
||||
->reactive()
|
||||
->required()
|
||||
->readonly()
|
||||
->extraAttributes([
|
||||
'x-data' => '{ value: "" }',
|
||||
'x-model' => 'value',
|
||||
'x-on:keydown.enter.prevent' => '$wire.processPalletNo()',
|
||||
])
|
||||
->suffixAction(fn ($get, $set) => Forms\Components\Actions\Action::make('addWirePackNo')
|
||||
->label('')
|
||||
->button()
|
||||
->icon('heroicon-o-plus')
|
||||
->color('primary')
|
||||
->extraAttributes([
|
||||
'class' => 'p-1 w-7 h-7',
|
||||
])
|
||||
->action(function ($get, $set, $livewire) {
|
||||
|
||||
$plantId = $get('plant_id');
|
||||
|
||||
session(['pallet_clicked_time' => now()->toDateTimeString()]);
|
||||
session(['pallet_created_by' => Filament::auth()->user()->name]);
|
||||
|
||||
$year = now()->format('y');
|
||||
$month = now()->format('m');
|
||||
$prefix = "SP-{$year}{$month}";
|
||||
|
||||
$lastPallet = SparePacking::where('spare_packing_number', 'like', "{$prefix}%")
|
||||
->orderByDesc('spare_packing_number')
|
||||
->first();
|
||||
|
||||
if ($lastPallet) {
|
||||
$lastNumber = (int) substr(
|
||||
$lastPallet->spare_packing_number,
|
||||
strlen($prefix)
|
||||
);
|
||||
|
||||
$newNumber = $lastNumber + 1;
|
||||
|
||||
$newNumber = $newNumber < 1000
|
||||
? str_pad($newNumber, 3, '0', STR_PAD_LEFT)
|
||||
: (string) $newNumber;
|
||||
} else {
|
||||
$newNumber = '001';
|
||||
}
|
||||
|
||||
$newPalletNumber = "{$prefix}{$newNumber}";
|
||||
|
||||
$set('spare_packing_number', $newPalletNumber);
|
||||
$set('plant_id', $plantId);
|
||||
|
||||
// $livewire->redirectToQrPdf($newPalletNumber);
|
||||
})
|
||||
),
|
||||
Forms\Components\TextInput::make('document_number')
|
||||
->label('Document No')
|
||||
->reactive()
|
||||
->readOnly(fn (callable $get) => ! $get('spare_packing_number'))
|
||||
->extraAttributes([
|
||||
'x-on:keydown.enter.prevent' => '$wire.processDocNo()',
|
||||
]),
|
||||
Forms\Components\TextInput::make('removeDoc_number')
|
||||
->label('Remove Document No')
|
||||
->reactive()
|
||||
->minLength(9)
|
||||
->readOnly(fn (callable $get) => ! $get('spare_packing_number') || $get('document_number'))
|
||||
->extraAttributes([
|
||||
'x-data' => '{ value: "" }',
|
||||
'x-model' => 'value',
|
||||
'x-on:keydown.enter.prevent' => '$wire.processRemoveDocNo()',
|
||||
]),
|
||||
Forms\Components\TextInput::make('Sno_quantity')
|
||||
->label('SNo. Quantity')
|
||||
->readOnly()
|
||||
->default('0'),
|
||||
Forms\Components\Select::make('pending_pallet_list')
|
||||
->label('Pending Pallet List')
|
||||
->reactive()
|
||||
->afterStateUpdated(function ($state, callable $set) {
|
||||
$set('spare_packing_number', $state);
|
||||
$set('pallet_number_locked', false);
|
||||
})
|
||||
->options(function ($get) {
|
||||
|
||||
$plantId = $get('plant_id');
|
||||
$saleOrder = $get('sale_order_master_id');
|
||||
|
||||
if (!$plantId || !$saleOrder) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$saleOrderIds = SaleOrderMaster::where('plant_id', $plantId)
|
||||
->where('sale_order_number', $saleOrder)
|
||||
->pluck('id');
|
||||
|
||||
return SparePacking::query()
|
||||
->where('plant_id', $plantId)
|
||||
->whereIn('sale_order_master_id', $saleOrderIds)
|
||||
->where(function ($query) {
|
||||
$query->whereNull('spare_packing_status')
|
||||
->orWhere('spare_packing_status', '');
|
||||
})
|
||||
->whereNotNull('spare_packing_number')
|
||||
->orderBy('spare_packing_number', 'asc')
|
||||
->pluck('spare_packing_number')
|
||||
->unique()
|
||||
->mapWithKeys(fn ($number) => [$number => $number])
|
||||
->toArray();
|
||||
}),
|
||||
Forms\Components\View::make('forms.components.save-spare-packing-button'),
|
||||
Forms\Components\Hidden::make('created_by')
|
||||
->label('Created By'),
|
||||
Forms\Components\Hidden::make('updated_by')
|
||||
->label('Updated By'),
|
||||
])
|
||||
->columns(6),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('No.')
|
||||
->label('No.')
|
||||
->alignCenter()
|
||||
->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')
|
||||
->alignCenter()
|
||||
->searchable()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('item.code')
|
||||
->label('Item')
|
||||
->alignCenter()
|
||||
->searchable()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('item.description')
|
||||
->label('Description')
|
||||
->alignCenter()
|
||||
->searchable()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('saleOrder.sale_order_number')
|
||||
->label('Sale Order No')
|
||||
->alignCenter()
|
||||
->searchable()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('saleOrder.supplier_name')
|
||||
->label('Supplier Name')
|
||||
->alignCenter()
|
||||
->searchable()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('spare_packing_number')
|
||||
->label('Spare Packing Number')
|
||||
->alignCenter()
|
||||
->searchable()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('document_number')
|
||||
->label('Document Number')
|
||||
->alignCenter()
|
||||
->searchable()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('quantity')
|
||||
->label('Quantity')
|
||||
->alignCenter()
|
||||
->searchable()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('spare_packing_status')
|
||||
->label('Spare Packing Status')
|
||||
->alignCenter()
|
||||
->searchable()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('created_at')
|
||||
->label('Created At')
|
||||
->dateTime()
|
||||
->alignCenter()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('created_by')
|
||||
->label('Created By')
|
||||
->alignCenter()
|
||||
->searchable()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('updated_at')
|
||||
->label('Updated At')
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
Tables\Columns\TextColumn::make('updated_by')
|
||||
->label('Updated By')
|
||||
->alignCenter()
|
||||
->searchable()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
Tables\Columns\TextColumn::make('scanned_at')
|
||||
->label('Scanned At')
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->alignCenter()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
Tables\Columns\TextColumn::make('scanned_by')
|
||||
->label('Scanned By')
|
||||
->alignCenter()
|
||||
->searchable()
|
||||
->sortable()
|
||||
->alignCenter()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
Tables\Columns\TextColumn::make('deleted_at')
|
||||
->label('Deleted At')
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
])
|
||||
->filters([
|
||||
Tables\Filters\TrashedFilter::make(),
|
||||
])
|
||||
->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 Spare Packing')
|
||||
->color('warning')
|
||||
->importer(SparePackingImporter::class)
|
||||
->visible(function () {
|
||||
return Filament::auth()->user()->can('view import spare packing');
|
||||
}),
|
||||
ExportAction::make()
|
||||
->label('Export Spare Packing')
|
||||
->color('warning')
|
||||
->exporter(SparePackingExporter::class)
|
||||
->visible(function () {
|
||||
return Filament::auth()->user()->can('view export spare packing');
|
||||
}),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListSparePackings::route('/'),
|
||||
'create' => Pages\CreateSparePacking::route('/create'),
|
||||
'view' => Pages\ViewSparePacking::route('/{record}'),
|
||||
'edit' => Pages\EditSparePacking::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
|
||||
public static function getEloquentQuery(): Builder
|
||||
{
|
||||
return parent::getEloquentQuery()
|
||||
->withoutGlobalScopes([
|
||||
SoftDeletingScope::class,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,845 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\SparePackingResource\Pages;
|
||||
|
||||
use App\Filament\Resources\SparePackingResource;
|
||||
use App\Models\Item;
|
||||
use App\Models\Plant;
|
||||
use App\Models\SaleOrderMaster;
|
||||
use Filament\Actions;
|
||||
use Filament\Facades\Filament;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
use App\Models\SparePacking;
|
||||
|
||||
class CreateSparePacking extends CreateRecord
|
||||
{
|
||||
|
||||
public $docNo;
|
||||
|
||||
public $saleOrder;
|
||||
|
||||
public $plantId;
|
||||
|
||||
public $count = 0;
|
||||
|
||||
public $snoCount = 0;
|
||||
|
||||
public $pendingPallet;
|
||||
|
||||
public array $importedSaleOrderList = [];
|
||||
|
||||
protected static string $resource = SparePackingResource::class;
|
||||
|
||||
protected static string $view = 'filament.resources.spare-packing-resource.create-spare-packing';
|
||||
|
||||
protected $listeners = [
|
||||
'updateSnoQuantity' => 'handleUpdateSnoQuantity',
|
||||
];
|
||||
|
||||
public function handleUpdateSnoQuantity($newValue)
|
||||
{
|
||||
$this->form->fill([
|
||||
'Sno_quantity' => $newValue,
|
||||
]);
|
||||
}
|
||||
|
||||
public function processDocNo(){
|
||||
|
||||
$plantId = $this->form->getState()['plant_id'];
|
||||
|
||||
$plantId = trim($plantId) ?? null;
|
||||
|
||||
$docNo = trim($this->form->getState()['document_number'])?? null;
|
||||
|
||||
$saleOrder = trim($this->form->getState()['sale_order_master_id'])?? null;
|
||||
|
||||
$sparePackNo = trim($this->form->getState()['spare_packing_number'])?? null;
|
||||
|
||||
$sparePackNo = trim($sparePackNo) ?? null;
|
||||
|
||||
$user = Filament::auth()->user();
|
||||
|
||||
$operatorName = $user->name;
|
||||
|
||||
if (empty($docNo) || $docNo == '')
|
||||
{
|
||||
Notification::make()
|
||||
->title("Document Number can't be empty")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->form->fill([
|
||||
'document_number' => null,
|
||||
'plant_id' => $plantId,
|
||||
'sale_order_master_id' => $saleOrder,
|
||||
'spare_packing_number' => $sparePackNo,
|
||||
'Sno_quantity' => 0,
|
||||
'created_by' => $operatorName,
|
||||
'scanned_by' => $operatorName,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
// $pattern = '/^([^|]+)\|([^|]+)\|([^|]+)\|(\d+(\.\d+)?)(kg)?$/i';
|
||||
|
||||
// $pattern = '/^([^|]+)\|([^|]+)\|([^|]+)\|(\d+(\.\d+)?)$/i';
|
||||
|
||||
$pattern = '/^([^|]+)\|([^|]+)\|(\d+(\.\d+)?)$/i';
|
||||
|
||||
if (!preg_match($pattern, $docNo, $matches))
|
||||
{
|
||||
Notification::make()
|
||||
->title("Scan Valid Qr code ")
|
||||
->body("Expected Format : (MaterialCode|Document Number|Quantity)")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->form->fill([
|
||||
'document_number' => null,
|
||||
'plant_id' => $plantId,
|
||||
'sale_order_master_id' => $saleOrder,
|
||||
'spare_packing_number' => $sparePackNo,
|
||||
'Sno_quantity' => 0,
|
||||
'created_by' => $operatorName,
|
||||
'scanned_by' => $operatorName,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
$materialCode = $matches[1];
|
||||
$docNo = $matches[2];
|
||||
$weight = $matches[3];
|
||||
|
||||
$icode = Item::where('code', $materialCode)->first();
|
||||
|
||||
if(!$icode)
|
||||
{
|
||||
Notification::make()
|
||||
->title("Unknown Item Code")
|
||||
->body("Item Code not found '$materialCode'")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->form->fill([
|
||||
'document_number' => null,
|
||||
'plant_id' => $plantId,
|
||||
'sale_order_master_id' => $saleOrder,
|
||||
'spare_packing_number' => $sparePackNo,
|
||||
'Sno_quantity' => 0,
|
||||
'created_by' => $operatorName,
|
||||
'scanned_by' => $operatorName,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
$icodeAgaPlant = Item::where('code', $materialCode)->where('plant_id', $plantId)->first();
|
||||
|
||||
$plantCode = Plant::where('id', $plantId)->first();
|
||||
|
||||
$plantcode = $plantCode->code;
|
||||
|
||||
$itemId = $icodeAgaPlant->id;
|
||||
|
||||
if(!$icodeAgaPlant)
|
||||
{
|
||||
Notification::make()
|
||||
->title("Unknown Item Code")
|
||||
->body("Item Code not found '$materialCode' against Plant Code '$plantcode'")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->form->fill([
|
||||
'document_number' => null,
|
||||
'plant_id' => $plantId,
|
||||
'sale_order_master_id' => $saleOrder,
|
||||
'spare_packing_number' => $sparePackNo,
|
||||
'Sno_quantity' => 0,
|
||||
'created_by' => $operatorName,
|
||||
'scanned_by' => $operatorName,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
$icodeAgaCPoPlant = SaleOrderMaster::where('item_id', $itemId)->where('plant_id', $plantId)->first();
|
||||
|
||||
if(!$icodeAgaCPoPlant)
|
||||
{
|
||||
Notification::make()
|
||||
->title("Unknown Item Code in Customer PO")
|
||||
->body("Item Code '$materialCode' not found in any active Customer PO against Plant Code '$plantcode'")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->form->fill([
|
||||
'document_number' => null,
|
||||
'plant_id' => $plantId,
|
||||
'sale_order_master_id' => $saleOrder,
|
||||
'spare_packing_number' => $sparePackNo,
|
||||
'Sno_quantity' => 0,
|
||||
'created_by' => $operatorName,
|
||||
'scanned_by' => $operatorName,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
$processOrderAgaPlant = SparePacking::where('document_number', $docNo)->where('plant_id', $plantId)->first();
|
||||
|
||||
if($processOrderAgaPlant)
|
||||
{
|
||||
Notification::make()
|
||||
->title("Duplicate Document Number")
|
||||
->body("Duplicate document number found '$docNo' against Plant Code '$plantcode'")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->form->fill([
|
||||
'document_number' => null,
|
||||
'plant_id' => $plantId,
|
||||
'sale_order_master_id' => $saleOrder,
|
||||
'spare_packing_number' => $sparePackNo,
|
||||
'Sno_quantity' => 0,
|
||||
'created_by' => $operatorName,
|
||||
'scanned_by' => $operatorName,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
$saleOrderRecord = SaleOrderMaster::where('sale_order_number', $saleOrder)
|
||||
->where('plant_id', $plantId)
|
||||
->where('item_id', $itemId)
|
||||
->first();
|
||||
|
||||
if(!$saleOrderRecord)
|
||||
{
|
||||
Notification::make()
|
||||
->title("Sale Order Not Found")
|
||||
->body("Sale Order '$saleOrder' for Item '$materialCode' not found against Plant '$plantcode'")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->form->fill([
|
||||
'document_number' => null,
|
||||
'plant_id' => $plantId,
|
||||
'sale_order_master_id' => $saleOrder,
|
||||
'spare_packing_number' => $sparePackNo,
|
||||
'Sno_quantity' => 0,
|
||||
'created_by' => $operatorName,
|
||||
'scanned_by' => $operatorName,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
$alreadyScannedQty = SparePacking::where('sale_order_master_id', $saleOrderRecord->id)
|
||||
->where('plant_id', $plantId)
|
||||
->where('item_id', $itemId)
|
||||
->selectRaw('SUM(CAST(quantity AS NUMERIC)) as total_weight')
|
||||
->value('total_weight');
|
||||
|
||||
$totalQty = round((float)$alreadyScannedQty + (float)$weight, 3);
|
||||
|
||||
|
||||
if($totalQty > round((float)$saleOrderRecord->quantity, 3))
|
||||
{
|
||||
|
||||
Notification::make()
|
||||
->title("Scanned Quantity Exceeds Sale Order Quantity")
|
||||
->body("Scanned quantity '$weight' and already scanned quantity '$alreadyScannedQty' exceeds allowed quantity '{$saleOrderRecord->quantity}' for Sale Order '$saleOrderRecord->sale_order_number' and Item '$materialCode'")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->form->fill([
|
||||
'document_number' => null,
|
||||
'plant_id' => $plantId,
|
||||
'sale_order_master_id' => $saleOrder,
|
||||
'item_id' => $itemId,
|
||||
'spare_packing_number' => $sparePackNo,
|
||||
'Sno_quantity' => 0,
|
||||
'created_by' => $operatorName,
|
||||
'scanned_by' => $operatorName,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
$existingPallet = SparePacking::where('plant_id', $plantId)
|
||||
->where('spare_packing_number', $sparePackNo)
|
||||
->first();
|
||||
|
||||
$count = SparePacking::where('plant_id', $plantId)
|
||||
->where('spare_packing_number', $sparePackNo)
|
||||
->count('spare_packing_number');
|
||||
|
||||
$createdAt = $existingPallet ? $existingPallet->created_at : $clickedAt ?? now();
|
||||
|
||||
$createdBy = $existingPallet ? $existingPallet->created_by : $clickedBy ?? $operatorName;
|
||||
|
||||
$record = SparePacking::create([
|
||||
'plant_id' => $plantId,
|
||||
'item_id' => $itemId,
|
||||
'spare_packing_number' => $sparePackNo,
|
||||
'document_number' => $docNo,
|
||||
'sale_order_master_id' => $saleOrderRecord->id,
|
||||
'quantity' => $weight,
|
||||
'created_by' => $createdBy,
|
||||
'scanned_by' => $operatorName,
|
||||
'created_at' => $createdAt,
|
||||
'scanned_at' => now(),
|
||||
'updated_by' => $operatorName,
|
||||
]);
|
||||
|
||||
if ($record)
|
||||
{
|
||||
|
||||
$this->snoCount = SparePacking::where('plant_id', $plantId)
|
||||
->where('spare_packing_number', $sparePackNo)
|
||||
->count();
|
||||
|
||||
$this->dispatch('loadData', $sparePackNo, $plantId);
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
'sale_order_master_id' => $saleOrder,
|
||||
'item_id' => $itemId,
|
||||
'spare_packing_number' => $sparePackNo,
|
||||
'document_number' => null,
|
||||
// 'pending_pallet_list' => $pendingPallet,
|
||||
'Sno_quantity' => $this->snoCount,
|
||||
'created_by' => $operatorName,
|
||||
'scanned_by' => $operatorName,
|
||||
]);
|
||||
}
|
||||
else
|
||||
{
|
||||
Notification::make()
|
||||
->title("Failed to insert scanned serial number '$docNo' into wire master table!")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', $sparePackNo, $plantId);
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
'sale_order_master_id' => $saleOrder,
|
||||
'item_id' => $itemId,
|
||||
'spare_packing_number' => $sparePackNo,
|
||||
'document_number' => null,
|
||||
// 'pending_pallet_list' => $pendingPallet,
|
||||
'Sno_quantity' => $count,
|
||||
'scanned_by' => $operatorName,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
Notification::make()
|
||||
->title('Error: Serial not inserted.')
|
||||
->body("Something went wrong while inserting document number '{$docNo}' into pallet table!\nScan the new document number to proceed...")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', $sparePackNo, $plantId);
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
'sale_order_master_id' => $saleOrder,
|
||||
'spare_packing_number' => $sparePackNo,
|
||||
'document_number' => null,
|
||||
// 'pending_pallet_list' => $pendingPallet,
|
||||
'Sno_quantity' => $count,
|
||||
'created_by' => $operatorName,
|
||||
'scanned_by' => $operatorName,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
$this->dispatch('loadData', $sparePackNo, $plantId);
|
||||
|
||||
}
|
||||
|
||||
public function markAsComplete()
|
||||
{
|
||||
|
||||
$plantId = $this->form->getState()['plant_id'];
|
||||
|
||||
$plantId = trim($plantId) ?? null;
|
||||
|
||||
$pendingPallet = $this->form->getState()['pending_pallet_list'];
|
||||
|
||||
$palletNumber = trim($this->form->getState()['spare_packing_number'])?? null;
|
||||
|
||||
$palletNumber = trim($palletNumber) ?? null;
|
||||
|
||||
$processOrder = trim($this->form->getState()['document_number'])?? null;
|
||||
|
||||
$processOrder = trim($processOrder) ?? null;
|
||||
|
||||
$user = Filament::auth()->user();
|
||||
|
||||
$operatorName = $user->name;
|
||||
|
||||
$isCompleted = $this->data['is_completed'] ?? false;
|
||||
|
||||
// $this->pendingPallet = $this->form->getState()['pending_pallet_list'];
|
||||
|
||||
if (! ($this->data['is_completed'] ?? false)) {
|
||||
Notification::make()
|
||||
->title('Completion required')
|
||||
->body('Please check the "Is Completed" checkbox to finish master packing.')
|
||||
->warning()
|
||||
->duration(3000)
|
||||
->send();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$palletExist = SparePacking::where('spare_packing_number', $palletNumber)
|
||||
->where('plant_id', $plantId)
|
||||
->first();
|
||||
|
||||
if (!$palletExist)
|
||||
{
|
||||
Notification::make()
|
||||
->title("Pallet number '$palletNumber' does not have process orders to save!<br>Add the valid process order into pallet number to proceed...")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', $palletNumber, $plantId);
|
||||
$this->form->fill([
|
||||
'document_number' => null,
|
||||
'plant_id' => $plantId,
|
||||
'spare_packing_number' => $palletNumber,
|
||||
'pending_pallet_list' => $pendingPallet,
|
||||
'Sno_quantity' => 0,
|
||||
'created_by' => $operatorName,
|
||||
'scanned_by' => $operatorName,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
$allCompleted = SparePacking::where('plant_id', $plantId)
|
||||
->where('spare_packing_number', $palletNumber)
|
||||
->where('spare_packing_status', '=','Completed')
|
||||
->first();
|
||||
|
||||
if ($allCompleted)
|
||||
{
|
||||
Notification::make()
|
||||
->title("Spare Packing pallet number '$palletNumber' already completed the master packing!<br>Generate the new Spare Packing Pallet number or choose from pending pallet list!")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', '', $plantId);
|
||||
$this->form->fill([
|
||||
'document_number' => null,
|
||||
'plant_id' => $plantId,
|
||||
'spare_packing_number' => null,
|
||||
'pending_pallet_list' => null,//$pendingPallet
|
||||
'Sno_quantity' => 0,
|
||||
'created_by' => $operatorName,
|
||||
'scanned_by' => $operatorName,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
// $count = PalletValidation::where('plant_id', $plantId)
|
||||
// ->where('pallet_number', $palletNumber)
|
||||
// ->count('pallet_number');
|
||||
|
||||
if (!$isCompleted)
|
||||
{
|
||||
$updated = SparePacking::where('spare_packing_number', $palletNumber)
|
||||
->where('plant_id', $plantId)
|
||||
->update([
|
||||
'updated_at' => now(),
|
||||
'updated_by' => $operatorName,
|
||||
]);
|
||||
|
||||
if ($updated > 0)
|
||||
{
|
||||
Notification::make()
|
||||
->title("Pallet number '$palletNumber' records saved successfully!")
|
||||
->success()
|
||||
->duration(800)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', '', $plantId);
|
||||
$this->form->fill([
|
||||
'document_number' => null,
|
||||
'plant_id' => $plantId,
|
||||
'spare_packing_number' => null,//$palletNumber
|
||||
'pending_pallet_list' => null,//$pendingPallet
|
||||
'Sno_quantity' => 0,//$count,
|
||||
'created_by' => $operatorName,
|
||||
'scanned_by' => $operatorName,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$updated = SparePacking::where('spare_packing_number', $palletNumber)
|
||||
->where('plant_id', $plantId)
|
||||
->update([
|
||||
'spare_packing_status' => 'Completed',
|
||||
'updated_at' => now(),
|
||||
'updated_by' => $operatorName,
|
||||
]);
|
||||
|
||||
if ($updated > 0)
|
||||
{
|
||||
Notification::make()
|
||||
->title("Pallet number '$palletNumber' completed the master packing successfully!")
|
||||
->success()
|
||||
->duration(800)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', '', $plantId);
|
||||
$this->form->fill([
|
||||
'document_number' => null,
|
||||
'plant_id' => $plantId,
|
||||
'spare_packing_number' => null,//$palletNumber
|
||||
'pending_pallet_list' => null,//$pendingPallet
|
||||
'Sno_quantity' => 0,//$count
|
||||
'created_by' => $operatorName,
|
||||
'scanned_by' => $operatorName,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function processPalletNo()
|
||||
{
|
||||
$plantId = $this->form->getState()['plant_id'];
|
||||
|
||||
$plantId = trim($plantId) ?? null;
|
||||
|
||||
$pendingPallet = $this->form->getState()['pending_pallet_list'];
|
||||
|
||||
$palletNumber = trim($this->form->getState()['spare_packing_number']) ?? null;
|
||||
|
||||
$saleOrder = trim($this->form->getState()['sale_order_master_id'])?? null;
|
||||
|
||||
$palletNumber = trim($palletNumber) ?? null;
|
||||
|
||||
$docNo = trim($this->form->getState()['document_number']) ?? null;
|
||||
|
||||
$docNo = trim($docNo) ?? null;
|
||||
|
||||
$user = Filament::auth()->user();
|
||||
|
||||
$operatorName = $user->name;
|
||||
|
||||
//$this->dispatch('loadData', $palletNumber, $plantId);
|
||||
$this->form->fill([
|
||||
'serial_number' => null,
|
||||
'plant_id' => $plantId,
|
||||
'sale_order_master_id' => $saleOrder,
|
||||
'pallet_number' => $palletNumber,
|
||||
'pending_pallet_list' => $pendingPallet,
|
||||
'Sno_quantity' => 0,
|
||||
'created_by' => $operatorName,
|
||||
'scanned_by' => $operatorName,
|
||||
]);
|
||||
|
||||
if (!$palletNumber)
|
||||
{
|
||||
Notification::make()
|
||||
->title('Pallet number is required.')
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', '', $plantId);
|
||||
$this->form->fill([
|
||||
'document_number' => null,
|
||||
'plant_id' => $plantId,
|
||||
'sale_order_master_id' => $saleOrder,
|
||||
'spare_packing_number' => $palletNumber,
|
||||
'pending_pallet_list' => $pendingPallet,
|
||||
'Sno_quantity' => 0,
|
||||
'created_by' => $operatorName,
|
||||
'scanned_by' => $operatorName,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
if (strlen($palletNumber) < 10)
|
||||
{
|
||||
Notification::make()
|
||||
->title("Pallet number '$palletNumber' must be at least 10 digits.")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadLocator' ,'',$plantId);
|
||||
$this->form->fill([
|
||||
'serial_number' => null,
|
||||
'plant_id' => $plantId,
|
||||
'sale_order_master_id' => $saleOrder,
|
||||
'spare_packing_number' => $palletNumber,
|
||||
'pending_pallet_list' => $pendingPallet,
|
||||
'Sno_quantity' => 0,
|
||||
'created_by' => $operatorName,
|
||||
'scanned_by' => $operatorName,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
$count = SparePacking::where('plant_id', $plantId)
|
||||
->where('spare_packing_number', $palletNumber)
|
||||
->count('spare_packing_number');
|
||||
|
||||
$palletNotCompleted = SparePacking::where('plant_id', $plantId)
|
||||
->where('spare_packing_number', $palletNumber)
|
||||
->where('spare_packing_status', '=','')
|
||||
->orWhere('spare_packing_status', '=',null)
|
||||
->first();
|
||||
|
||||
if (!$palletNotCompleted)
|
||||
{
|
||||
Notification::make()
|
||||
->title("Pallet number not found $palletNumber!")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', $palletNumber, $plantId);
|
||||
$this->form->fill([
|
||||
'document_number' => null,
|
||||
'plant_id' => $plantId,
|
||||
'sale_order_master_id' => $saleOrder,
|
||||
'spare_packing_number' => $palletNumber,
|
||||
'pending_pallet_list' => $pendingPallet,
|
||||
'Sno_quantity' => $count,
|
||||
'created_by' => $operatorName,
|
||||
'scanned_by' => $operatorName,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
$this->form->fill([
|
||||
'document_number' => null,
|
||||
'plant_id' => $plantId,
|
||||
'sale_order_master_id' => $saleOrder,
|
||||
'spare_packing_number' => $palletNumber,
|
||||
'pending_pallet_list' => $pendingPallet,
|
||||
'Sno_quantity' => $count,
|
||||
'created_by' => $operatorName,
|
||||
'scanned_by' => $operatorName,
|
||||
]);
|
||||
|
||||
$this->dispatch('loadData', $palletNumber, $plantId);
|
||||
|
||||
}
|
||||
|
||||
public function processRemoveDocNo()
|
||||
{
|
||||
$plantId = $this->form->getState()['plant_id'];
|
||||
|
||||
$plantId = trim($plantId) ?? null;
|
||||
|
||||
$pendingPallet = $this->form->getState()['pending_pallet_list'];
|
||||
|
||||
$palletNumber = trim($this->form->getState()['spare_packing_number']) ?? null;
|
||||
|
||||
$customerPo = trim($this->form->getState()['sale_order_master_id'])?? null;
|
||||
|
||||
$palletNumber = trim($palletNumber) ?? null;
|
||||
|
||||
$docNo = trim($this->form->getState()['removeDoc_number']) ?? null;
|
||||
|
||||
$docNo = trim($docNo) ?? null;
|
||||
|
||||
$user = Filament::auth()->user();
|
||||
|
||||
$operatorName = $user->name;
|
||||
|
||||
if (!$palletNumber)
|
||||
{
|
||||
Notification::make()
|
||||
->title('Spare Pallet number is required to remove.')
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
return;
|
||||
}
|
||||
|
||||
$pattern = '/^([^|]+)\|([^|]+)\|(\d+(\.\d+)?)$/i';
|
||||
|
||||
if (!preg_match($pattern, $docNo, $matches))
|
||||
{
|
||||
Notification::make()
|
||||
->title("Scan Valid Qr code ")
|
||||
->body("Expected Format : (MaterialCode|Document Number|Quantity)")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->form->fill([
|
||||
'document_number' => null,
|
||||
'plant_id' => $plantId,
|
||||
'sale_order_master_id' => $customerPo,
|
||||
'spare_packing_number' => $palletNumber,
|
||||
'Sno_quantity' => 0,
|
||||
'created_by' => $operatorName,
|
||||
'scanned_by' => $operatorName,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
$materialCode = $matches[1];
|
||||
$docNo = $matches[2];
|
||||
$weight = $matches[3];
|
||||
|
||||
$count = SparePacking::where('plant_id', $plantId)
|
||||
->where('spare_packing_number', $palletNumber)
|
||||
->count('spare_packing_number');
|
||||
|
||||
if (!$docNo)
|
||||
{
|
||||
Notification::make()
|
||||
->title('Document number is required to remove.')
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', $palletNumber, $plantId);
|
||||
$this->form->fill([
|
||||
'document_number' => null,
|
||||
'plant_id' => $plantId,
|
||||
'sale_order_master_id' => $customerPo,
|
||||
'spare_packing_number' => $palletNumber,
|
||||
'pending_pallet_list' => $pendingPallet,
|
||||
'Sno_quantity' => $count,
|
||||
'created_by' => $operatorName,
|
||||
'scanned_by' => $operatorName,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
$processOrderexist = SparePacking::where('plant_id', $plantId)
|
||||
->where('document_number', $docNo)
|
||||
->first();
|
||||
if (!$processOrderexist)
|
||||
{
|
||||
Notification::make()
|
||||
->title('Document number not exists in pallet table.')
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', $palletNumber, $plantId);
|
||||
$this->form->fill([
|
||||
'document_number' => null,
|
||||
'plant_id' => $plantId,
|
||||
'sale_order_master_id' => $customerPo,
|
||||
'spare_packing_number' => $palletNumber,
|
||||
'pending_pallet_list' => $pendingPallet,
|
||||
'Sno_quantity' => $count,
|
||||
'created_by' => $operatorName,
|
||||
'scanned_by' => $operatorName,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
$palletExist = SparePacking::where('plant_id', $plantId)
|
||||
->where('document_number', $docNo)
|
||||
->where('spare_packing_number', '!=', '')
|
||||
->where('spare_packing_number', '!=', null)
|
||||
->first();
|
||||
|
||||
if ($palletExist && $palletExist->spare_packing_number != $palletNumber)
|
||||
{
|
||||
Notification::make()
|
||||
->title("Scanned document number exist in pallet number '$palletExist->spare_packing_number'.<br>Scan the valid exist document number to remove!")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', $palletNumber, $plantId);
|
||||
$this->form->fill([
|
||||
'document_number' => null,
|
||||
'plant_id' => $plantId,
|
||||
'sale_order_master_id' => $customerPo,
|
||||
'spare_packing_number' => $palletNumber,
|
||||
'pending_pallet_list' => $pendingPallet,
|
||||
'Sno_quantity' => $count,
|
||||
'created_by' => $operatorName,
|
||||
'scanned_by' => $operatorName,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
$deleted = SparePacking::where('plant_id', $plantId)
|
||||
->where('spare_packing_number', $palletNumber)
|
||||
->where('document_number', $docNo)
|
||||
->forceDelete();
|
||||
|
||||
if ($deleted)
|
||||
{
|
||||
Notification::make()
|
||||
->title("Scanned document number '$docNo' successfully removed from pallet table!<br>Scan the next exist document number to remove...")
|
||||
->success()
|
||||
->duration(600)
|
||||
->send();
|
||||
|
||||
$this->snoCount = SparePacking::where('plant_id', $plantId)
|
||||
->where('spare_packing_number', $palletNumber)
|
||||
->count();
|
||||
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
'sale_order_master_id' => $customerPo,
|
||||
'spare_packing_number' => $palletNumber,
|
||||
'removeDoc_number' => null,
|
||||
'pending_pallet_list' => $this->pendingPallet,
|
||||
'Sno_quantity' => $this->snoCount,
|
||||
'created_by' => $operatorName,
|
||||
'scanned_by' => $operatorName,
|
||||
]);
|
||||
|
||||
$this->dispatch('loadData', $palletNumber, $plantId);
|
||||
}
|
||||
else
|
||||
{
|
||||
Notification::make()
|
||||
->title("Failed to remove scanned document number '$docNo' from master pallet!")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', $palletNumber, $plantId);
|
||||
$this->form->fill([
|
||||
'document_number' => null,
|
||||
'plant_id' => $plantId,
|
||||
'sale_order_master_id' => $customerPo,
|
||||
'spare_packing_number' => $palletNumber,
|
||||
'pending_pallet_list' => $pendingPallet,
|
||||
'Sno_quantity' => $count,
|
||||
'created_by' => $operatorName,
|
||||
'scanned_by' => $operatorName,
|
||||
]);
|
||||
}
|
||||
|
||||
//$this->dispatch('removeSno', $serialNumber, $palletNumber, $plantId);
|
||||
}
|
||||
|
||||
public function getFormActions(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\SparePackingResource\Pages;
|
||||
|
||||
use App\Filament\Resources\SparePackingResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditSparePacking extends EditRecord
|
||||
{
|
||||
protected static string $resource = SparePackingResource::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\SparePackingResource\Pages;
|
||||
|
||||
use App\Filament\Resources\SparePackingResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListSparePackings extends ListRecords
|
||||
{
|
||||
protected static string $resource = SparePackingResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\SparePackingResource\Pages;
|
||||
|
||||
use App\Filament\Resources\SparePackingResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ViewRecord;
|
||||
|
||||
class ViewSparePacking extends ViewRecord
|
||||
{
|
||||
protected static string $resource = SparePackingResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\EditAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user