Merge pull request 'ranjith-dev' (#872) from ranjith-dev into master
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled

Reviewed-on: #872
This commit was merged in pull request #872.
This commit is contained in:
2026-08-04 09:24:52 +00:00
10 changed files with 566 additions and 0 deletions

View File

@@ -0,0 +1,62 @@
<?php
namespace App\Filament\Exports;
use App\Models\StickerStructureDetail;
use Filament\Actions\Exports\ExportColumn;
use Filament\Actions\Exports\Exporter;
use Filament\Actions\Exports\Models\Export;
class StickerStructureDetailExporter extends Exporter
{
protected static ?string $model = StickerStructureDetail::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('sticker_id')
->label('STICKER ID'),
ExportColumn::make('sticker_width')
->label('STICKER WIDTH'),
ExportColumn::make('sticker_height')
->label('STICKER HEIGHT'),
ExportColumn::make('sticker_lmargin')
->label('STICKER LEFT MARGIN'),
ExportColumn::make('sticker_rmargin')
->label('STICKER RIGHT MARGIN'),
ExportColumn::make('sticker_tmargin')
->label('STICKER TOP MARGIN'),
ExportColumn::make('sticker_bmargin')
->label('STICKER BOTTOM MARGIN'),
ExportColumn::make('created_at')
->label('CREATED AT'),
ExportColumn::make('updated_at')
->label('UPDATED AT'),
ExportColumn::make('created_by')
->label('CREATED BY'),
ExportColumn::make('updated_by')
->label('UPDATED BY'),
ExportColumn::make('deleted_at')
->label('DELETED AT')
->enabledByDefault(false),
];
}
public static function getCompletedNotificationBody(Export $export): string
{
$body = 'Your sticker structure detail 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;
}
}

View File

@@ -0,0 +1,49 @@
<?php
namespace App\Filament\Imports;
use App\Models\StickerStructureDetail;
use Filament\Actions\Imports\ImportColumn;
use Filament\Actions\Imports\Importer;
use Filament\Actions\Imports\Models\Import;
class StickerStructureDetailImporter extends Importer
{
protected static ?string $model = StickerStructureDetail::class;
public static function getColumns(): array
{
return [
ImportColumn::make('sticker_id'),
ImportColumn::make('sticker_width'),
ImportColumn::make('sticker_height'),
ImportColumn::make('sticker_lmargin'),
ImportColumn::make('sticker_rmargin'),
ImportColumn::make('sticker_tmargin'),
ImportColumn::make('sticker_bmargin'),
ImportColumn::make('created_by'),
ImportColumn::make('updated_by'),
];
}
public function resolveRecord(): ?StickerStructureDetail
{
// return StickerStructureDetail::firstOrNew([
// // Update existing records, matching them by `$this->data['column_name']`
// 'email' => $this->data['email'],
// ]);
return new StickerStructureDetail();
}
public static function getCompletedNotificationBody(Import $import): string
{
$body = 'Your sticker structure detail 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;
}
}

View File

@@ -0,0 +1,207 @@
<?php
namespace App\Filament\Resources;
use App\Filament\Exports\StickerStructureDetailExporter;
use App\Filament\Imports\StickerStructureDetailImporter;
use App\Filament\Resources\StickerStructureDetailResource\Pages;
use App\Filament\Resources\StickerStructureDetailResource\RelationManagers;
use App\Models\ItemCharacteristic;
use App\Models\StickerStructureDetail;
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\Actions\Action;
use Illuminate\Support\HtmlString;
use Filament\Forms\Components\Html;
use Filament\Forms\Get;
use Filament\Tables\Actions\ExportAction;
use Filament\Tables\Actions\ImportAction;
class StickerStructureDetailResource extends Resource
{
protected static ?string $model = StickerStructureDetail::class;
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
protected static ?string $navigationGroup = 'Customized Sticker Printing';
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\TextInput::make('sticker_id')
->label('Sticker ID')
->reactive()
->required()
->afterStateUpdated(function ($state, callable $set) {
//\Log::info('Sticker ID typed:', ['sticker_id' => $state]);
$set('sticker_id_live', $state);
}),
Forms\Components\TextInput::make('sticker_width')
->label('Sticker Width')
->required(),
Forms\Components\TextInput::make('sticker_height')
->label('Sticker Height')
->required(),
Forms\Components\TextInput::make('sticker_lmargin')
->label('Sticker Left Margin')
->required(),
Forms\Components\TextInput::make('sticker_rmargin')
->label('Sticker Right Margin')
->required(),
Forms\Components\TextInput::make('sticker_tmargin')
->label('Sticker Top Margin')
->required(),
Forms\Components\TextInput::make('sticker_bmargin')
->label('Sticker Bottom Margin')
->required(),
Forms\Components\Hidden::make('created_by')
->label('Created By')
->default(Filament::auth()->user()?->name),
Forms\Components\Hidden::make('updated_by')
->label('Updated By')
->default(Filament::auth()->user()?->name),
Forms\Components\Hidden::make('sticker_id_live')
->default(fn ($get) => $get('sticker_id'))
->reactive()
->afterStateUpdated(function ($state, callable $set) {
$set('sticker_id_live', $state);
}),
Forms\Components\ViewField::make('generate_template')
->view('fields.generate-template')
->reactive()
//->key(fn ($get) => 'generate-template' . ($get('sticker_id_live') ?? 'empty'))
->key(fn (Get $get) =>
'generate-template-' .
($get('sticker_id_live') ?? 'empty') . '-' .
($get('plant_id') ?? 'empty') . '-' .
($get('item_characteristic_id') ?? 'empty')
)
// ->viewData(fn (Get $get) => [
// 'sticker_id' => $get('sticker_id_live') ?? 'empty',
// ]),
->viewData(fn (Get $get) => [
'sticker_id' => $get('sticker_id_live') ?? 'empty',
'plant_id' => $get('plant_id') ?? 'empty',
'item_characteristic_id' => $get('item_characteristic_id') ?? 'empty',
])
]);
}
public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('No.')
->label('No.')
->getStateUsing(function ($record, $livewire, $column, $rowLoop) {
$paginator = $livewire->getTableRecords();
$perPage = method_exists($paginator, 'perPage') ? $paginator->perPage() : 10;
$currentPage = method_exists($paginator, 'currentPage') ? $paginator->currentPage() : 1;
return ($currentPage - 1) * $perPage + $rowLoop->iteration;
}),
Tables\Columns\TextColumn::make('sticker_id')
->label('Sticker ID')
->alignCenter(),
Tables\Columns\TextColumn::make('sticker_width')
->label('Sticker Width')
->alignCenter(),
Tables\Columns\TextColumn::make('sticker_height')
->label('Sticker Height')
->alignCenter(),
Tables\Columns\TextColumn::make('sticker_lmargin')
->label('Sticker Left Margin')
->alignCenter(),
Tables\Columns\TextColumn::make('sticker_rmargin')
->label('Sticker Right Margin')
->alignCenter(),
Tables\Columns\TextColumn::make('sticker_tmargin')
->label('Sticker Top Margin')
->alignCenter(),
Tables\Columns\TextColumn::make('sticker_bmargin')
->label('Sticker Bottom Margin')
->alignCenter(),
Tables\Columns\TextColumn::make('created_at')
->label('Created At')
->alignCenter()
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
Tables\Columns\TextColumn::make('updated_at')
->label('Updated At')
->alignCenter()
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
Tables\Columns\TextColumn::make('deleted_at')
->label('Deleted At')
->alignCenter()
->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 Sticker Structure Details')
->color('warning')
->importer(StickerStructureDetailImporter::class)
->visible(function() {
return Filament::auth()->user()->can('view import sticker structure details');
}),
ExportAction::make()
->label('Export Sticker Structure Details')
->color('warning')
->exporter(StickerStructureDetailExporter::class)
->visible(function() {
return Filament::auth()->user()->can('view export sticker structure details');
}),
]);
}
public static function getRelations(): array
{
return [
//
];
}
public static function getPages(): array
{
return [
'index' => Pages\ListStickerStructureDetails::route('/'),
'create' => Pages\CreateStickerStructureDetail::route('/create'),
'view' => Pages\ViewStickerStructureDetail::route('/{record}'),
'edit' => Pages\EditStickerStructureDetail::route('/{record}/edit'),
];
}
public static function getEloquentQuery(): Builder
{
return parent::getEloquentQuery()
->withoutGlobalScopes([
SoftDeletingScope::class,
]);
}
}

View File

@@ -0,0 +1,12 @@
<?php
namespace App\Filament\Resources\StickerStructureDetailResource\Pages;
use App\Filament\Resources\StickerStructureDetailResource;
use Filament\Actions;
use Filament\Resources\Pages\CreateRecord;
class CreateStickerStructureDetail extends CreateRecord
{
protected static string $resource = StickerStructureDetailResource::class;
}

View File

@@ -0,0 +1,22 @@
<?php
namespace App\Filament\Resources\StickerStructureDetailResource\Pages;
use App\Filament\Resources\StickerStructureDetailResource;
use Filament\Actions;
use Filament\Resources\Pages\EditRecord;
class EditStickerStructureDetail extends EditRecord
{
protected static string $resource = StickerStructureDetailResource::class;
protected function getHeaderActions(): array
{
return [
Actions\ViewAction::make(),
Actions\DeleteAction::make(),
Actions\ForceDeleteAction::make(),
Actions\RestoreAction::make(),
];
}
}

View File

@@ -0,0 +1,19 @@
<?php
namespace App\Filament\Resources\StickerStructureDetailResource\Pages;
use App\Filament\Resources\StickerStructureDetailResource;
use Filament\Actions;
use Filament\Resources\Pages\ListRecords;
class ListStickerStructureDetails extends ListRecords
{
protected static string $resource = StickerStructureDetailResource::class;
protected function getHeaderActions(): array
{
return [
Actions\CreateAction::make(),
];
}
}

View File

@@ -0,0 +1,19 @@
<?php
namespace App\Filament\Resources\StickerStructureDetailResource\Pages;
use App\Filament\Resources\StickerStructureDetailResource;
use Filament\Actions;
use Filament\Resources\Pages\ViewRecord;
class ViewStickerStructureDetail extends ViewRecord
{
protected static string $resource = StickerStructureDetailResource::class;
protected function getHeaderActions(): array
{
return [
Actions\EditAction::make(),
];
}
}

View File

@@ -0,0 +1,28 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;
class StickerStructureDetail extends Model
{
use SoftDeletes;
protected $fillable = [
'sticker_id',
'sticker_width',
'sticker_height',
'sticker_lmargin',
'sticker_rmargin',
'sticker_tmargin',
'sticker_bmargin',
'created_at',
'updated_at',
'created_by',
'updated_by'
];
}

View File

@@ -0,0 +1,106 @@
<?php
namespace App\Policies;
use Illuminate\Auth\Access\Response;
use App\Models\StickerStructureDetail;
use App\Models\User;
class StickerStructureDetailPolicy
{
/**
* Determine whether the user can view any models.
*/
public function viewAny(User $user): bool
{
return $user->checkPermissionTo('view-any StickerStructureDetail');
}
/**
* Determine whether the user can view the model.
*/
public function view(User $user, StickerStructureDetail $stickerstructuredetail): bool
{
return $user->checkPermissionTo('view StickerStructureDetail');
}
/**
* Determine whether the user can create models.
*/
public function create(User $user): bool
{
return $user->checkPermissionTo('create StickerStructureDetail');
}
/**
* Determine whether the user can update the model.
*/
public function update(User $user, StickerStructureDetail $stickerstructuredetail): bool
{
return $user->checkPermissionTo('update StickerStructureDetail');
}
/**
* Determine whether the user can delete the model.
*/
public function delete(User $user, StickerStructureDetail $stickerstructuredetail): bool
{
return $user->checkPermissionTo('delete StickerStructureDetail');
}
/**
* Determine whether the user can delete any models.
*/
public function deleteAny(User $user): bool
{
return $user->checkPermissionTo('delete-any StickerStructureDetail');
}
/**
* Determine whether the user can restore the model.
*/
public function restore(User $user, StickerStructureDetail $stickerstructuredetail): bool
{
return $user->checkPermissionTo('restore StickerStructureDetail');
}
/**
* Determine whether the user can restore any models.
*/
public function restoreAny(User $user): bool
{
return $user->checkPermissionTo('restore-any StickerStructureDetail');
}
/**
* Determine whether the user can replicate the model.
*/
public function replicate(User $user, StickerStructureDetail $stickerstructuredetail): bool
{
return $user->checkPermissionTo('replicate StickerStructureDetail');
}
/**
* Determine whether the user can reorder the models.
*/
public function reorder(User $user): bool
{
return $user->checkPermissionTo('reorder StickerStructureDetail');
}
/**
* Determine whether the user can permanently delete the model.
*/
public function forceDelete(User $user, StickerStructureDetail $stickerstructuredetail): bool
{
return $user->checkPermissionTo('force-delete StickerStructureDetail');
}
/**
* Determine whether the user can permanently delete any models.
*/
public function forceDeleteAny(User $user): bool
{
return $user->checkPermissionTo('force-delete-any StickerStructureDetail');
}
}

View File

@@ -0,0 +1,42 @@
<?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 sticker_structure_details (
id BIGINT GENERATED always AS IDENTITY PRIMARY KEY,
sticker_id TEXT DEFAULT NULL,
sticker_width TEXT DEFAULT NULL,
sticker_height TEXT DEFAULT NULL,
sticker_lmargin TEXT DEFAULT NULL,
sticker_rmargin TEXT DEFAULT NULL,
sticker_tmargin TEXT DEFAULT NULL,
sticker_bmargin TEXT DEFAULT NULL,
created_at TIMESTAMP NOT NULL DEFAULT NOW(),
updated_at TIMESTAMP NOT NULL DEFAULT NOW(),
created_by TEXT DEFAULT NULL,
updated_by TEXT DEFAULT NULL,
deleted_at TIMESTAMP
);
SQL;
DB::statement($sql);
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('sticker_structure_details');
}
};