Added import and export wire master packing
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 19s
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (pull_request) Successful in 17s
Gemini PR Review / Gemini PR Review (pull_request) Failing after 20s
Laravel Pint / pint (pull_request) Successful in 1m53s
Laravel Larastan / larastan (pull_request) Failing after 3m16s
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 19s
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (pull_request) Successful in 17s
Gemini PR Review / Gemini PR Review (pull_request) Failing after 20s
Laravel Pint / pint (pull_request) Successful in 1m53s
Laravel Larastan / larastan (pull_request) Failing after 3m16s
This commit is contained in:
68
app/Filament/Exports/WireMasterPackingExporter.php
Normal file
68
app/Filament/Exports/WireMasterPackingExporter.php
Normal file
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Exports;
|
||||
|
||||
use App\Models\WireMasterPacking;
|
||||
use Filament\Actions\Exports\ExportColumn;
|
||||
use Filament\Actions\Exports\Exporter;
|
||||
use Filament\Actions\Exports\Models\Export;
|
||||
|
||||
class WireMasterPackingExporter extends Exporter
|
||||
{
|
||||
protected static ?string $model = WireMasterPacking::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('customerPo.customer_po')
|
||||
->label('CUSTOMER PO NUMBER'),
|
||||
ExportColumn::make('wire_packing_number')
|
||||
->label('WIRE PACKING NUMBER'),
|
||||
ExportColumn::make('process_order')
|
||||
->label('PROCESS ORDER'),
|
||||
ExportColumn::make('batch_number')
|
||||
->label('BATCH NUMBER'),
|
||||
ExportColumn::make('weight')
|
||||
->label('WEIGHT'),
|
||||
ExportColumn::make('wire_packing_status')
|
||||
->label('WIRE 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 wire master 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;
|
||||
}
|
||||
}
|
||||
96
app/Filament/Imports/WireMasterPackingImporter.php
Normal file
96
app/Filament/Imports/WireMasterPackingImporter.php
Normal file
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Imports;
|
||||
|
||||
use App\Models\WireMasterPacking;
|
||||
use Filament\Actions\Imports\ImportColumn;
|
||||
use Filament\Actions\Imports\Importer;
|
||||
use Filament\Actions\Imports\Models\Import;
|
||||
|
||||
class WireMasterPackingImporter extends Importer
|
||||
{
|
||||
protected static ?string $model = WireMasterPacking::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('customer_po_master_id')
|
||||
->requiredMapping()
|
||||
->exampleHeader('CUSTOMER PO NUMBER')
|
||||
->example('PO12345')
|
||||
->label('CUSTOMER PO NUMBER')
|
||||
->numeric()
|
||||
->rules(['required', 'integer']),
|
||||
ImportColumn::make('wire_packing_number')
|
||||
->exampleHeader('WIRE PACKING NUMBER')
|
||||
->example('WP001')
|
||||
->label('WIRE PACKING NUMBER'),
|
||||
ImportColumn::make('process_order')
|
||||
->exampleHeader('PROCESS ORDER')
|
||||
->example('PO001')
|
||||
->label('PROCESS ORDER'),
|
||||
ImportColumn::make('batch_number')
|
||||
->exampleHeader('BATCH NUMBER')
|
||||
->example('BN001')
|
||||
->label('BATCH NUMBER'),
|
||||
ImportColumn::make('weight')
|
||||
->exampleHeader('WEIGHT')
|
||||
->example('100.5')
|
||||
->label('WEIGHT'),
|
||||
ImportColumn::make('wire_packing_status')
|
||||
->exampleHeader('WIRE PACKING STATUS')
|
||||
->example('Active')
|
||||
->label('WIRE PACKING STATUS'),
|
||||
ImportColumn::make('scanned_at')
|
||||
->requiredMapping()
|
||||
->rules(['required', 'datetime']),
|
||||
ImportColumn::make('created_by')
|
||||
->exampleHeader('CREATED BY')
|
||||
->example('John Doe')
|
||||
->label('CREATED BY'),
|
||||
ImportColumn::make('updated_by')
|
||||
->exampleHeader('UPDATED BY')
|
||||
->example('Jane Smith')
|
||||
->label('UPDATED BY'),
|
||||
ImportColumn::make('scanned_by')
|
||||
->exampleHeader('SCANNED BY')
|
||||
->example('John Doe')
|
||||
->label('SCANNED BY'),
|
||||
];
|
||||
}
|
||||
|
||||
public function resolveRecord(): ?WireMasterPacking
|
||||
{
|
||||
// return WireMasterPacking::firstOrNew([
|
||||
// // Update existing records, matching them by `$this->data['column_name']`
|
||||
// 'email' => $this->data['email'],
|
||||
// ]);
|
||||
|
||||
return new WireMasterPacking();
|
||||
}
|
||||
|
||||
public static function getCompletedNotificationBody(Import $import): string
|
||||
{
|
||||
$body = 'Your wire master 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;
|
||||
}
|
||||
}
|
||||
@@ -23,6 +23,10 @@ use Filament\Tables\Filters\Filter;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\DateTimePicker;
|
||||
use Str;
|
||||
use Filament\Tables\Actions\ExportAction;
|
||||
use Filament\Tables\Actions\ImportAction;
|
||||
use App\Filament\Exports\WireMasterPackingExporter;
|
||||
use App\Filament\Imports\WireMasterPackingImporter;
|
||||
|
||||
class WireMasterPackingResource extends Resource
|
||||
{
|
||||
@@ -63,7 +67,28 @@ class WireMasterPackingResource extends Resource
|
||||
|
||||
return CustomerPoMaster::where('plant_id', $plantId)->pluck('customer_po', 'id');
|
||||
})
|
||||
->required(),
|
||||
->required()
|
||||
->afterStateUpdated(function ($state, callable $set) {
|
||||
if (!$state) {
|
||||
$set('item', null);
|
||||
return;
|
||||
}
|
||||
|
||||
$customerPo = CustomerPoMaster::find($state);
|
||||
|
||||
if ($customerPo && $customerPo->item_id) {
|
||||
$item = Item::find($customerPo->item_id);
|
||||
|
||||
$set('item', $item?->code);
|
||||
} else {
|
||||
$set('item', null);
|
||||
}
|
||||
}),
|
||||
Forms\Components\TextInput::make('item')
|
||||
->label('Item Code')
|
||||
->reactive()
|
||||
->readOnly()
|
||||
->dehydrated(false),
|
||||
Forms\Components\TextInput::make('wire_packing_number')
|
||||
->label('Scan Wire Packing No')
|
||||
->reactive()
|
||||
@@ -468,6 +493,22 @@ class WireMasterPackingResource extends Resource
|
||||
Tables\Actions\ForceDeleteBulkAction::make(),
|
||||
Tables\Actions\RestoreBulkAction::make(),
|
||||
]),
|
||||
])
|
||||
->headerActions([
|
||||
ImportAction::make()
|
||||
->label('Import Wire Packing Master')
|
||||
->color('warning')
|
||||
->importer(WireMasterPackingImporter::class)
|
||||
->visible(function () {
|
||||
return Filament::auth()->user()->can('view import wire packing master');
|
||||
}),
|
||||
ExportAction::make()
|
||||
->label('Export Wire Packing Master')
|
||||
->color('warning')
|
||||
->exporter(WireMasterPackingExporter::class)
|
||||
->visible(function () {
|
||||
return Filament::auth()->user()->can('view export wire packing master');
|
||||
}),
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user