Merge pull request 'ranjith-dev' (#380) from ranjith-dev into master
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled
Reviewed-on: #380
This commit was merged in pull request #380.
This commit is contained in:
176
app/Filament/Resources/CustomerPoMasterResource.php
Normal file
176
app/Filament/Resources/CustomerPoMasterResource.php
Normal file
@@ -0,0 +1,176 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources;
|
||||||
|
|
||||||
|
use App\Filament\Exports\CustomerPoMasterExporter;
|
||||||
|
use App\Filament\Imports\CustomerPoMasterImporter;
|
||||||
|
use App\Filament\Resources\CustomerPoMasterResource\Pages;
|
||||||
|
use App\Filament\Resources\CustomerPoMasterResource\RelationManagers;
|
||||||
|
use App\Models\CustomerPoMaster;
|
||||||
|
use App\Models\Item;
|
||||||
|
use App\Models\Plant;
|
||||||
|
use Filament\Facades\Filament;
|
||||||
|
use Filament\Forms;
|
||||||
|
use Filament\Forms\Form;
|
||||||
|
use Filament\Resources\Resource;
|
||||||
|
use Filament\Tables;
|
||||||
|
use Filament\Tables\Table;
|
||||||
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
|
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||||
|
use Filament\Tables\Actions\ExportAction;
|
||||||
|
use Filament\Tables\Actions\ImportAction;
|
||||||
|
|
||||||
|
class CustomerPoMasterResource extends Resource
|
||||||
|
{
|
||||||
|
protected static ?string $model = CustomerPoMaster::class;
|
||||||
|
|
||||||
|
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
|
||||||
|
|
||||||
|
public static function form(Form $form): Form
|
||||||
|
{
|
||||||
|
return $form
|
||||||
|
->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('item_id')
|
||||||
|
->label('Item Code')
|
||||||
|
->reactive()
|
||||||
|
->searchable()
|
||||||
|
->options(function (callable $get) {
|
||||||
|
$plantId = $get('plant_id');
|
||||||
|
if (empty($plantId)) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
return Item::where('plant_id', $plantId)->pluck('code', 'id');
|
||||||
|
})
|
||||||
|
->required(),
|
||||||
|
Forms\Components\TextInput::make('customer_po')
|
||||||
|
->label('Customer PO'),
|
||||||
|
Forms\Components\TextInput::make('customer_name')
|
||||||
|
->label('Customer Name'),
|
||||||
|
Forms\Components\TextInput::make('quantity')
|
||||||
|
->label('Quantity'),
|
||||||
|
Forms\Components\Hidden::make('created_by')
|
||||||
|
->label('Created By')
|
||||||
|
->default(Filament::auth()->user()?->name),
|
||||||
|
Forms\Components\Hidden::make('updated_by')
|
||||||
|
->default(Filament::auth()->user()?->name),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function table(Table $table): Table
|
||||||
|
{
|
||||||
|
return $table
|
||||||
|
->columns([
|
||||||
|
Tables\Columns\TextColumn::make('No.')
|
||||||
|
->label('No.')
|
||||||
|
->getStateUsing(function ($record, $livewire, $column, $rowLoop) {
|
||||||
|
$paginator = $livewire->getTableRecords();
|
||||||
|
$perPage = method_exists($paginator, 'perPage') ? $paginator->perPage() : 10;
|
||||||
|
$currentPage = method_exists($paginator, 'currentPage') ? $paginator->currentPage() : 1;
|
||||||
|
|
||||||
|
return ($currentPage - 1) * $perPage + $rowLoop->iteration;
|
||||||
|
}),
|
||||||
|
Tables\Columns\TextColumn::make('plant.name')
|
||||||
|
->label('Plant')
|
||||||
|
->alignCenter()
|
||||||
|
->sortable(),
|
||||||
|
Tables\Columns\TextColumn::make('item.code')
|
||||||
|
->label('Item Code')
|
||||||
|
->searchable()
|
||||||
|
->alignCenter()
|
||||||
|
->sortable(),
|
||||||
|
Tables\Columns\TextColumn::make('customer_po')
|
||||||
|
->label('Customer PO')
|
||||||
|
->searchable()
|
||||||
|
->alignCenter()
|
||||||
|
->sortable(),
|
||||||
|
Tables\Columns\TextColumn::make('customer_name')
|
||||||
|
->label('Customer Name')
|
||||||
|
->searchable()
|
||||||
|
->alignCenter()
|
||||||
|
->sortable(),
|
||||||
|
Tables\Columns\TextColumn::make('quantity')
|
||||||
|
->label('Quantity')
|
||||||
|
->searchable()
|
||||||
|
->alignCenter()
|
||||||
|
->sortable(),
|
||||||
|
Tables\Columns\TextColumn::make('created_at')
|
||||||
|
->dateTime()
|
||||||
|
->sortable()
|
||||||
|
->toggleable(isToggledHiddenByDefault: true),
|
||||||
|
Tables\Columns\TextColumn::make('updated_at')
|
||||||
|
->dateTime()
|
||||||
|
->sortable()
|
||||||
|
->toggleable(isToggledHiddenByDefault: true),
|
||||||
|
Tables\Columns\TextColumn::make('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 Customer PO')
|
||||||
|
->color('warning')
|
||||||
|
->importer(CustomerPoMasterImporter::class)
|
||||||
|
->visible(function () {
|
||||||
|
return Filament::auth()->user()->can('view import customer po master');
|
||||||
|
}),
|
||||||
|
ExportAction::make()
|
||||||
|
->label('Export Customer PO')
|
||||||
|
->color('warning')
|
||||||
|
->exporter(CustomerPoMasterExporter::class)
|
||||||
|
->visible(function () {
|
||||||
|
return Filament::auth()->user()->can('view export customer po master');
|
||||||
|
}),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getRelations(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
//
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getPages(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'index' => Pages\ListCustomerPoMasters::route('/'),
|
||||||
|
'create' => Pages\CreateCustomerPoMaster::route('/create'),
|
||||||
|
'view' => Pages\ViewCustomerPoMaster::route('/{record}'),
|
||||||
|
'edit' => Pages\EditCustomerPoMaster::route('/{record}/edit'),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getEloquentQuery(): Builder
|
||||||
|
{
|
||||||
|
return parent::getEloquentQuery()
|
||||||
|
->withoutGlobalScopes([
|
||||||
|
SoftDeletingScope::class,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\CustomerPoMasterResource\Pages;
|
||||||
|
|
||||||
|
use App\Filament\Resources\CustomerPoMasterResource;
|
||||||
|
use Filament\Actions;
|
||||||
|
use Filament\Resources\Pages\CreateRecord;
|
||||||
|
|
||||||
|
class CreateCustomerPoMaster extends CreateRecord
|
||||||
|
{
|
||||||
|
protected static string $resource = CustomerPoMasterResource::class;
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\CustomerPoMasterResource\Pages;
|
||||||
|
|
||||||
|
use App\Filament\Resources\CustomerPoMasterResource;
|
||||||
|
use Filament\Actions;
|
||||||
|
use Filament\Resources\Pages\EditRecord;
|
||||||
|
|
||||||
|
class EditCustomerPoMaster extends EditRecord
|
||||||
|
{
|
||||||
|
protected static string $resource = CustomerPoMasterResource::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\CustomerPoMasterResource\Pages;
|
||||||
|
|
||||||
|
use App\Filament\Resources\CustomerPoMasterResource;
|
||||||
|
use Filament\Actions;
|
||||||
|
use Filament\Resources\Pages\ListRecords;
|
||||||
|
|
||||||
|
class ListCustomerPoMasters extends ListRecords
|
||||||
|
{
|
||||||
|
protected static string $resource = CustomerPoMasterResource::class;
|
||||||
|
|
||||||
|
protected function getHeaderActions(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
Actions\CreateAction::make(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\CustomerPoMasterResource\Pages;
|
||||||
|
|
||||||
|
use App\Filament\Resources\CustomerPoMasterResource;
|
||||||
|
use Filament\Actions;
|
||||||
|
use Filament\Resources\Pages\ViewRecord;
|
||||||
|
|
||||||
|
class ViewCustomerPoMaster extends ViewRecord
|
||||||
|
{
|
||||||
|
protected static string $resource = CustomerPoMasterResource::class;
|
||||||
|
|
||||||
|
protected function getHeaderActions(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
Actions\EditAction::make(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
33
app/Models/CustomerPoMaster.php
Normal file
33
app/Models/CustomerPoMaster.php
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
|
|
||||||
|
class CustomerPoMaster extends Model
|
||||||
|
{
|
||||||
|
use SoftDeletes;
|
||||||
|
|
||||||
|
protected $fillable = [
|
||||||
|
'plant_id',
|
||||||
|
'item_id',
|
||||||
|
'customer_po',
|
||||||
|
'customer_name',
|
||||||
|
'quantity',
|
||||||
|
'created_at',
|
||||||
|
'updated_at',
|
||||||
|
'created_by',
|
||||||
|
];
|
||||||
|
|
||||||
|
public function plant(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(Plant::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function item(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(Item::class);
|
||||||
|
}
|
||||||
|
}
|
||||||
106
app/Policies/CustomerPoMasterPolicy.php
Normal file
106
app/Policies/CustomerPoMasterPolicy.php
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Policies;
|
||||||
|
|
||||||
|
use Illuminate\Auth\Access\Response;
|
||||||
|
use App\Models\CustomerPoMaster;
|
||||||
|
use App\Models\User;
|
||||||
|
|
||||||
|
class CustomerPoMasterPolicy
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine whether the user can view any models.
|
||||||
|
*/
|
||||||
|
public function viewAny(User $user): bool
|
||||||
|
{
|
||||||
|
return $user->checkPermissionTo('view-any CustomerPoMaster');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine whether the user can view the model.
|
||||||
|
*/
|
||||||
|
public function view(User $user, CustomerPoMaster $customerpomaster): bool
|
||||||
|
{
|
||||||
|
return $user->checkPermissionTo('view CustomerPoMaster');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine whether the user can create models.
|
||||||
|
*/
|
||||||
|
public function create(User $user): bool
|
||||||
|
{
|
||||||
|
return $user->checkPermissionTo('create CustomerPoMaster');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine whether the user can update the model.
|
||||||
|
*/
|
||||||
|
public function update(User $user, CustomerPoMaster $customerpomaster): bool
|
||||||
|
{
|
||||||
|
return $user->checkPermissionTo('update CustomerPoMaster');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine whether the user can delete the model.
|
||||||
|
*/
|
||||||
|
public function delete(User $user, CustomerPoMaster $customerpomaster): bool
|
||||||
|
{
|
||||||
|
return $user->checkPermissionTo('delete CustomerPoMaster');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine whether the user can delete any models.
|
||||||
|
*/
|
||||||
|
public function deleteAny(User $user): bool
|
||||||
|
{
|
||||||
|
return $user->checkPermissionTo('delete-any CustomerPoMaster');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine whether the user can restore the model.
|
||||||
|
*/
|
||||||
|
public function restore(User $user, CustomerPoMaster $customerpomaster): bool
|
||||||
|
{
|
||||||
|
return $user->checkPermissionTo('restore CustomerPoMaster');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine whether the user can restore any models.
|
||||||
|
*/
|
||||||
|
public function restoreAny(User $user): bool
|
||||||
|
{
|
||||||
|
return $user->checkPermissionTo('restore-any CustomerPoMaster');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine whether the user can replicate the model.
|
||||||
|
*/
|
||||||
|
public function replicate(User $user, CustomerPoMaster $customerpomaster): bool
|
||||||
|
{
|
||||||
|
return $user->checkPermissionTo('replicate CustomerPoMaster');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine whether the user can reorder the models.
|
||||||
|
*/
|
||||||
|
public function reorder(User $user): bool
|
||||||
|
{
|
||||||
|
return $user->checkPermissionTo('reorder CustomerPoMaster');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine whether the user can permanently delete the model.
|
||||||
|
*/
|
||||||
|
public function forceDelete(User $user, CustomerPoMaster $customerpomaster): bool
|
||||||
|
{
|
||||||
|
return $user->checkPermissionTo('force-delete CustomerPoMaster');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine whether the user can permanently delete any models.
|
||||||
|
*/
|
||||||
|
public function forceDeleteAny(User $user): bool
|
||||||
|
{
|
||||||
|
return $user->checkPermissionTo('force-delete-any CustomerPoMaster');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
<?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 customer_po_masters (
|
||||||
|
id BIGINT GENERATED always AS IDENTITY PRIMARY KEY,
|
||||||
|
|
||||||
|
plant_id BIGINT NOT NULL,
|
||||||
|
item_id BIGINT NOT NULL,
|
||||||
|
customer_po TEXT DEFAULT NULL,
|
||||||
|
customer_name TEXT DEFAULT NULL,
|
||||||
|
|
||||||
|
quantity 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,
|
||||||
|
|
||||||
|
FOREIGN KEY (plant_id) REFERENCES plants(id),
|
||||||
|
FOREIGN KEY (item_id) REFERENCES items(id)
|
||||||
|
);
|
||||||
|
SQL;
|
||||||
|
DB::statement($sql);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('customer_po_masters');
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user