Merge pull request 'ranjith-dev' (#972) from ranjith-dev into master
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 17s
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 17s
Reviewed-on: #972
This commit was merged in pull request #972.
This commit is contained in:
68
app/Filament/Exports/SparePackingExporter.php
Normal file
68
app/Filament/Exports/SparePackingExporter.php
Normal file
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Exports;
|
||||
|
||||
use App\Models\SparePacking;
|
||||
use Filament\Actions\Exports\ExportColumn;
|
||||
use Filament\Actions\Exports\Exporter;
|
||||
use Filament\Actions\Exports\Models\Export;
|
||||
|
||||
class SparePackingExporter extends Exporter
|
||||
{
|
||||
protected static ?string $model = SparePacking::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.code')
|
||||
->label('PLANT CODE'),
|
||||
ExportColumn::make('item.code')
|
||||
->label('ITEM CODE'),
|
||||
ExportColumn::make('saleOrder.sale_order_number')
|
||||
->label('SALE ORDER NUMBER'),
|
||||
ExportColumn::make('saleOrder.supplier_name')
|
||||
->label('SUPPLIER NAME'),
|
||||
ExportColumn::make('spare_packing_number')
|
||||
->label('SPARE PACKING NUMBER'),
|
||||
ExportColumn::make('document_number')
|
||||
->label('DOCUMENT NUMBER'),
|
||||
ExportColumn::make('quantity')
|
||||
->label('QUANTITY'),
|
||||
ExportColumn::make('spare_packing_status')
|
||||
->label('SPARE PACKING STATUS'),
|
||||
ExportColumn::make('created_at')
|
||||
->label('CREATED AT'),
|
||||
ExportColumn::make('updated_at')
|
||||
->label('UPDATED AT'),
|
||||
ExportColumn::make('scanned_at')
|
||||
->label('SCANNED AT'),
|
||||
ExportColumn::make('created_by')
|
||||
->label('CREATED BY'),
|
||||
ExportColumn::make('updated_by')
|
||||
->label('UPDATED BY'),
|
||||
ExportColumn::make('scanned_by')
|
||||
->label('SCANNED BY'),
|
||||
ExportColumn::make('deleted_at')
|
||||
->label('DELETED AT')
|
||||
->enabledByDefault(false),
|
||||
];
|
||||
}
|
||||
|
||||
public static function getCompletedNotificationBody(Export $export): string
|
||||
{
|
||||
$body = 'Your spare packing 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;
|
||||
}
|
||||
}
|
||||
63
app/Filament/Imports/SparePackingImporter.php
Normal file
63
app/Filament/Imports/SparePackingImporter.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Imports;
|
||||
|
||||
use App\Models\SparePacking;
|
||||
use Filament\Actions\Imports\ImportColumn;
|
||||
use Filament\Actions\Imports\Importer;
|
||||
use Filament\Actions\Imports\Models\Import;
|
||||
|
||||
class SparePackingImporter extends Importer
|
||||
{
|
||||
protected static ?string $model = SparePacking::class;
|
||||
|
||||
public static function getColumns(): array
|
||||
{
|
||||
return [
|
||||
ImportColumn::make('plant')
|
||||
->requiredMapping()
|
||||
->relationship()
|
||||
->rules(['required']),
|
||||
ImportColumn::make('item')
|
||||
->requiredMapping()
|
||||
->relationship()
|
||||
->rules(['required']),
|
||||
ImportColumn::make('sale_order_master_id')
|
||||
->requiredMapping()
|
||||
->numeric()
|
||||
->rules(['required', 'integer']),
|
||||
ImportColumn::make('spare_packing_number'),
|
||||
ImportColumn::make('document_number'),
|
||||
ImportColumn::make('batch_number'),
|
||||
ImportColumn::make('quantity'),
|
||||
ImportColumn::make('spare_packing_status'),
|
||||
ImportColumn::make('scanned_at')
|
||||
->requiredMapping()
|
||||
->rules(['required', 'datetime']),
|
||||
ImportColumn::make('created_by'),
|
||||
ImportColumn::make('updated_by'),
|
||||
ImportColumn::make('scanned_by'),
|
||||
];
|
||||
}
|
||||
|
||||
public function resolveRecord(): ?SparePacking
|
||||
{
|
||||
// return SparePacking::firstOrNew([
|
||||
// // Update existing records, matching them by `$this->data['column_name']`
|
||||
// 'email' => $this->data['email'],
|
||||
// ]);
|
||||
|
||||
return new SparePacking();
|
||||
}
|
||||
|
||||
public static function getCompletedNotificationBody(Import $import): string
|
||||
{
|
||||
$body = 'Your spare packing 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;
|
||||
}
|
||||
}
|
||||
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(),
|
||||
];
|
||||
}
|
||||
}
|
||||
55
app/Livewire/SparePackData.php
Normal file
55
app/Livewire/SparePackData.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire;
|
||||
|
||||
use App\Models\SparePacking;
|
||||
use Livewire\Component;
|
||||
|
||||
class SparePackData extends Component
|
||||
{
|
||||
|
||||
public $plantId;
|
||||
|
||||
public $sparePackNo;
|
||||
|
||||
public $snoCount = 0;
|
||||
|
||||
public $records = [];
|
||||
|
||||
protected $listeners = [
|
||||
'loadData' => 'loadSparePackingData',
|
||||
];
|
||||
|
||||
public function loadSparePackingData($sparePackNo, $plantId)
|
||||
{
|
||||
$this->plantId = $plantId;
|
||||
$this->sparePackNo = $sparePackNo;
|
||||
$this->records = [];
|
||||
|
||||
$this->records = SparePacking::query()
|
||||
->where('plant_id', $this->plantId)
|
||||
->where('spare_packing_number', $this->sparePackNo)
|
||||
->orderBy('scanned_at')
|
||||
->get()
|
||||
->map(function ($record) {
|
||||
return [
|
||||
'created_at' => $record->created_at,
|
||||
'created_by' => $record->created_by ?? '',
|
||||
'spare_packing_number' => $record->spare_packing_number,
|
||||
'item_code' => $record->item?->code ?? '',
|
||||
'item_description' => $record->item?->description ?? '',
|
||||
'document_number' => $record->document_number,
|
||||
'quantity' => $record->quantity,
|
||||
'scanned_at' => $record->scanned_at,
|
||||
'scanned_by' => $record->scanned_by ?? '',
|
||||
];
|
||||
})
|
||||
->toArray();
|
||||
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.spare-pack-data');
|
||||
}
|
||||
}
|
||||
44
app/Models/SparePacking.php
Normal file
44
app/Models/SparePacking.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class SparePacking extends Model
|
||||
{
|
||||
use SoftDeletes;
|
||||
|
||||
protected $fillable = [
|
||||
'plant_id',
|
||||
'item_id',
|
||||
'sale_order_master_id',
|
||||
'spare_packing_number',
|
||||
'document_number',
|
||||
'batch_number',
|
||||
'quantity',
|
||||
'spare_packing_status',
|
||||
'created_at',
|
||||
'created_by',
|
||||
'updated_at',
|
||||
'updated_by',
|
||||
'scanned_at',
|
||||
'scanned_by',
|
||||
|
||||
];
|
||||
|
||||
public function plant(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Plant::class);
|
||||
}
|
||||
public function item(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Item::class, 'item_id');
|
||||
}
|
||||
|
||||
public function saleOrder(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(SaleOrderMaster::class, 'sale_order_master_id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?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 spare_packings (
|
||||
id BIGINT GENERATED always AS IDENTITY PRIMARY KEY,
|
||||
|
||||
plant_id BIGINT NOT NULL,
|
||||
item_id BIGINT NOT NULL,
|
||||
sale_order_master_id BIGINT NOT NULL,
|
||||
spare_packing_number TEXT DEFAULT NULL,
|
||||
document_number TEXT DEFAULT NULL,
|
||||
batch_number TEXT DEFAULT NULL,
|
||||
|
||||
quantity TEXT DEFAULT NULL,
|
||||
spare_packing_status TEXT DEFAULT NULL,
|
||||
|
||||
created_at TIMESTAMP NOT NULL DEFAULT NOW(),
|
||||
updated_at TIMESTAMP NOT NULL DEFAULT NOW(),
|
||||
scanned_at TIMESTAMP NOT NULL DEFAULT NOW(),
|
||||
created_by TEXT DEFAULT NULL,
|
||||
updated_by TEXT DEFAULT NULL,
|
||||
scanned_by TEXT DEFAULT NULL,
|
||||
deleted_at TIMESTAMP,
|
||||
|
||||
FOREIGN KEY (plant_id) REFERENCES plants(id),
|
||||
FOREIGN KEY (sale_order_master_id) REFERENCES sale_order_masters(id),
|
||||
FOREIGN KEY (item_id) REFERENCES items(id)
|
||||
);
|
||||
SQL;
|
||||
DB::statement($sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('spare_packings');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,32 @@
|
||||
|
||||
|
||||
<x-filament::page>
|
||||
|
||||
<div class="filament-form space-y-6">
|
||||
{{ $this->form }}
|
||||
</div>
|
||||
|
||||
<div class="bg-white shadow rounded-xl p-4">
|
||||
<livewire:spare-pack-data />
|
||||
</div>
|
||||
|
||||
<div class="filament-actions mt-6">
|
||||
<x-filament::actions>
|
||||
@foreach ($this->getFormActions() as $action)
|
||||
{{ $action }}
|
||||
@endforeach
|
||||
</x-filament::actions>
|
||||
</div>
|
||||
|
||||
@push('scripts')
|
||||
<script>
|
||||
window.addEventListener('open-pdf', event => {
|
||||
const url = event.detail.url;
|
||||
const win = window.open(url, '_blank');
|
||||
if (!win || win.closed || typeof win.closed == 'undefined') {
|
||||
alert('Popup blocked. Please allow popups for this site.');
|
||||
}
|
||||
});
|
||||
</script>
|
||||
@endpush
|
||||
</x-filament::page>
|
||||
@@ -0,0 +1,19 @@
|
||||
<div class="flex flex-col items-start space-y-1">
|
||||
<div class="flex items-center">
|
||||
<input
|
||||
type="checkbox"
|
||||
id="is_completed"
|
||||
wire:model.defer="data.is_completed"
|
||||
class="focus:outline-none focus:ring-0 focus:border-transparent border-gray-300"
|
||||
>
|
||||
<label for="is_completed" style="margin-left:2mm;" class="whitespace-nowrap mb-0">
|
||||
Is Completed!
|
||||
</label>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
wire:click="markAsComplete"
|
||||
class="px-2 py-1 border border-primary-500 text-primary-600 rounded hover:bg-primary-50 hover:border-primary-700 transition text-sm"
|
||||
>
|
||||
Save Pallet
|
||||
</button>
|
||||
47
resources/views/livewire/spare-pack-data.blade.php
Normal file
47
resources/views/livewire/spare-pack-data.blade.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<div class="p-4">
|
||||
<h2 class="text-lg font-bold mb-4 text-gray-700 uppercase tracking-wider">
|
||||
SPARE PACKING DATA 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">No</th>
|
||||
<th class="border px-4 py-2">Created Datetime</th>
|
||||
<th class="border px-4 py-2 whitespace-nowrap">Created By</th>
|
||||
<th class="border px-4 py-2 whitespace-nowrap">S PACKING No</th>
|
||||
<th class="border px-4 py-2 whitespace-nowrap">Item Code</th>
|
||||
<th class="border px-4 py-2">Description</th>
|
||||
<th class="border px-4 py-2">Doc No</th>
|
||||
<th class="border px-4 py-2">Quantity</th>
|
||||
<th class="border px-4 py-2">Scanned Datetime</th>
|
||||
<th class="border px-4 py-2 whitespace-nowrap">Scanned By</th>
|
||||
</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['created_at'] ?? '-' }}</td>
|
||||
<td class="border px-4 py-2 whitespace-nowrap">{{ $record['created_by'] ?? '-' }}</td>
|
||||
<td class="border px-4 py-2 whitespace-nowrap">{{ $record['spare_packing_number'] ?? '-' }}</td>
|
||||
<td class="border px-4 py-2">{{ $record['item_code'] ?? '-' }}</td>
|
||||
<td class="border px-4 py-2 whitespace-nowrap">{{ $record['item_description'] ?? '-' }}</td>
|
||||
<td class="border px-4 py-2 whitespace-nowrap">{{ $record['document_number'] ?? '-' }}</td>
|
||||
<td class="border px-4 py-2">{{ $record['quantity'] ?? '-' }}</td>
|
||||
<td class="border px-4 py-2 whitespace-nowrap">{{ $record['scanned_at'] ?? '-' }}</td>
|
||||
<td class="border px-4 py-2">{{ $record['scanned_by'] ?? '-' }}</td>
|
||||
</tr>
|
||||
@empty
|
||||
<tr>
|
||||
<td colspan="10" class="px-4 py-4 text-center text-gray-500">
|
||||
No spare packing records found.
|
||||
</td>
|
||||
</tr>
|
||||
@endforelse
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user