install
This commit is contained in:
57
app/Filament/Clusters/Settings/Branches/BranchResource.php
Normal file
57
app/Filament/Clusters/Settings/Branches/BranchResource.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Clusters\Settings\Branches;
|
||||
|
||||
use App\Filament\Clusters\Settings\Branches\Pages\ManageBranches;
|
||||
use App\Filament\Clusters\Settings\Branches\Schemas\BranchForm;
|
||||
use App\Filament\Clusters\Settings\Branches\Tables\BranchesTable;
|
||||
use App\Filament\Clusters\Settings\SettingsCluster;
|
||||
use App\Modules\Branch\Models\Branch;
|
||||
use BackedEnum;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class BranchResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Branch::class;
|
||||
|
||||
protected static ?string $cluster = SettingsCluster::class;
|
||||
|
||||
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedBuildingOffice2;
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'name';
|
||||
|
||||
public static function getNavigationGroup(): ?string
|
||||
{
|
||||
return __('Branches and provinces');
|
||||
}
|
||||
|
||||
public static function getModelLabel(): string
|
||||
{
|
||||
return __('module.branch::base.branch');
|
||||
}
|
||||
|
||||
public static function getPluralModelLabel(): string
|
||||
{
|
||||
return __('module.branch::base.branches');
|
||||
}
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return BranchForm::configure($schema);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return BranchesTable::configure($table);
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => ManageBranches::route('/'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Clusters\Settings\Branches\Pages;
|
||||
|
||||
use App\Filament\Clusters\Settings\Branches\BranchResource;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Resources\Pages\ManageRecords;
|
||||
|
||||
class ManageBranches extends ManageRecords
|
||||
{
|
||||
protected static string $resource = BranchResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
134
app/Filament/Clusters/Settings/Branches/Schemas/BranchForm.php
Normal file
134
app/Filament/Clusters/Settings/Branches/Schemas/BranchForm.php
Normal file
@@ -0,0 +1,134 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Clusters\Settings\Branches\Schemas;
|
||||
|
||||
use AbdulmajeedJamaan\FilamentTranslatableTabs\TranslatableTabs;
|
||||
use App\Modules\Province\Models\Province;
|
||||
use Filament\Forms\Components\Repeater;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use Filament\Schemas\Components\Section;
|
||||
use Filament\Schemas\Schema;
|
||||
|
||||
class BranchForm
|
||||
{
|
||||
public static function configure(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
Section::make(__('General Information'))
|
||||
->columns(2)
|
||||
->schema([
|
||||
TextInput::make('unique_code')
|
||||
->label(__('Unique code'))
|
||||
->maxLength(255)
|
||||
->unique(ignoreRecord: true)
|
||||
->required(),
|
||||
|
||||
Select::make('region')
|
||||
->label(__('Region'))
|
||||
->options(fn () => regions())
|
||||
->required()
|
||||
->native(false)
|
||||
->searchable()
|
||||
->live()
|
||||
->afterStateUpdated(fn ($state, callable $set) => $set('province_id', null)),
|
||||
|
||||
Select::make('province_id')
|
||||
->label(__('Province'))
|
||||
->relationship('province', 'name')
|
||||
->options(function (callable $get) {
|
||||
$region = $get('region');
|
||||
if (! $region) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return Province::query()
|
||||
->where('region', $region)
|
||||
->where('active', true)
|
||||
->pluck('name', 'id')
|
||||
->toArray();
|
||||
})
|
||||
->searchable()
|
||||
->native(false)
|
||||
->disabled(fn (callable $get): bool => ! $get('region'))
|
||||
->columnSpanFull(),
|
||||
|
||||
Toggle::make('active')
|
||||
->label(__('Active'))
|
||||
->default(true)
|
||||
->required(),
|
||||
|
||||
Repeater::make('phone_numbers')
|
||||
->label(__('Phone numbers'))
|
||||
->simple(
|
||||
TextInput::make('phone')
|
||||
->label(__('Phone Number'))
|
||||
->prefix('+993')
|
||||
->numeric()
|
||||
)
|
||||
->addActionLabel(__('Add phone number'))
|
||||
->defaultItems(0)
|
||||
->columnSpanFull(),
|
||||
]),
|
||||
|
||||
TranslatableTabs::make()
|
||||
->schema([
|
||||
TextInput::make('name')
|
||||
->label(__('Name'))
|
||||
->required()
|
||||
->maxLength(255),
|
||||
|
||||
Textarea::make('address')
|
||||
->label(__('Address'))
|
||||
->rows(3),
|
||||
|
||||
]),
|
||||
|
||||
Section::make(__('Billing Credentials'))
|
||||
->collapsed()
|
||||
->collapsible()
|
||||
->columns(2)
|
||||
->columnSpanFull()
|
||||
->schema([
|
||||
TextInput::make('billing_username')
|
||||
->label(__('Billing Username'))
|
||||
->maxLength(255),
|
||||
|
||||
TextInput::make('billing_password')
|
||||
->label(__('Billing Password'))
|
||||
->password()
|
||||
->maxLength(255),
|
||||
|
||||
TextInput::make('billing_swift_username')
|
||||
->label(__('Billing SWIFT Username'))
|
||||
->maxLength(255),
|
||||
|
||||
TextInput::make('billing_swift_password')
|
||||
->label(__('Billing SWIFT Password'))
|
||||
->password()
|
||||
->maxLength(255),
|
||||
|
||||
TextInput::make('billing_visa_master_username')
|
||||
->label(__('Billing Visa/Master Username'))
|
||||
->maxLength(255),
|
||||
|
||||
TextInput::make('billing_visa_master_password')
|
||||
->label(__('Billing Visa/Master Password'))
|
||||
->password()
|
||||
->maxLength(255),
|
||||
|
||||
TextInput::make('billing_sber_username')
|
||||
->label(__('Billing Sber Username'))
|
||||
->maxLength(255),
|
||||
|
||||
TextInput::make('billing_sber_password')
|
||||
->label(__('Billing Sber Password'))
|
||||
->password()
|
||||
->maxLength(255),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Clusters\Settings\Branches\Tables;
|
||||
|
||||
use App\Modules\Region\Repositories\RegionRepository;
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Tables\Columns\IconColumn;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Filters\SelectFilter;
|
||||
use Filament\Tables\Filters\TernaryFilter;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class BranchesTable
|
||||
{
|
||||
public static function configure(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
TextColumn::make('unique_code')
|
||||
->label(__('Unique code'))
|
||||
->searchable()
|
||||
->sortable(),
|
||||
|
||||
TextColumn::make('name')
|
||||
->label(__('Name'))
|
||||
->searchable()
|
||||
->sortable(),
|
||||
|
||||
TextColumn::make('region')
|
||||
->label(__('Region'))
|
||||
->formatStateUsing(fn (string $state): string => RegionRepository::label($state))
|
||||
->searchable()
|
||||
->sortable(),
|
||||
|
||||
TextColumn::make('province.name')
|
||||
->label(__('Province'))
|
||||
->searchable()
|
||||
->sortable()
|
||||
->toggleable(),
|
||||
|
||||
IconColumn::make('active')
|
||||
->label(__('Active'))
|
||||
->boolean()
|
||||
->sortable(),
|
||||
|
||||
TextColumn::make('created_at')
|
||||
->label(__('Created At'))
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
|
||||
TextColumn::make('updated_at')
|
||||
->label(__('Updated At'))
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
])
|
||||
->filters([
|
||||
SelectFilter::make('region')
|
||||
->label(__('Region'))
|
||||
->options(fn () => regions())
|
||||
->native(false),
|
||||
|
||||
TernaryFilter::make('active')
|
||||
->label(__('Active'))
|
||||
->boolean()
|
||||
->trueLabel(__('Active only'))
|
||||
->falseLabel(__('Inactive only'))
|
||||
->native(false),
|
||||
])
|
||||
->recordActions([
|
||||
EditAction::make(),
|
||||
])
|
||||
->toolbarActions([
|
||||
BulkActionGroup::make([
|
||||
DeleteBulkAction::make(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user