-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #190 from cesar99144/feature-supplier
Feature supplier
- Loading branch information
Showing
10 changed files
with
397 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
<?php | ||
|
||
namespace App\Filament\Resources; | ||
|
||
use App\Filament\Resources\SupplierResource\Pages; | ||
use App\Filament\Resources\SupplierResource\RelationManagers; | ||
use App\Models\Supplier; | ||
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; | ||
|
||
class SupplierResource extends Resource | ||
{ | ||
protected static ?string $model = Supplier::class; | ||
protected static ?string $modelLabel = 'Fornecedores'; | ||
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack'; | ||
protected static ?string $navigationGroup = 'Logística'; | ||
|
||
public static function form(Form $form): Form | ||
{ | ||
return $form | ||
->schema([ | ||
Forms\Components\Section::make() | ||
->columns(2) | ||
->schema([ | ||
Forms\Components\Textarea::make('registered_name') | ||
->label('Razão social') | ||
->required() | ||
->maxLength(255), | ||
Forms\Components\Textarea::make('name_company') | ||
->label('Fantasia') | ||
->required() | ||
->maxLength(255), | ||
Forms\Components\TextInput::make('document') | ||
->label('Cnpj') | ||
->required() | ||
->mask('99.999.999/9999-99'), | ||
Forms\Components\TextInput::make('ie') | ||
->label('Incrição estadual') | ||
->maxLength(14), | ||
Forms\Components\TextInput::make('telephone') | ||
->label('Telefone') | ||
->mask('(99) 99999-9999') | ||
->tel() | ||
->maxLength(120), | ||
Forms\Components\TextInput::make('email') | ||
->email() | ||
->maxLength(254) | ||
]), | ||
]); | ||
} | ||
|
||
public static function table(Table $table): Table | ||
{ | ||
return $table | ||
->columns([ | ||
Tables\Columns\TextColumn::make('document') | ||
->label('Documento') | ||
->searchable(), | ||
Tables\Columns\TextColumn::make('registered_name') | ||
->label('Razão social') | ||
->searchable(), | ||
Tables\Columns\TextColumn::make('name_company') | ||
->label('Fantasia') | ||
->searchable(), | ||
Tables\Columns\TextColumn::make('telephone') | ||
->label('Telefone') | ||
->searchable(), | ||
Tables\Columns\TextColumn::make('email') | ||
->label('Email') | ||
->searchable(), | ||
Tables\Columns\ToggleColumn::make('status') | ||
->sortable(), | ||
Tables\Columns\TextColumn::make('created_at') | ||
->dateTime() | ||
->sortable() | ||
->toggleable(isToggledHiddenByDefault: true), | ||
Tables\Columns\TextColumn::make('updated_at') | ||
->dateTime() | ||
->sortable() | ||
->toggleable(isToggledHiddenByDefault: true), | ||
]) | ||
->filters([ | ||
// | ||
]) | ||
->actions([ | ||
Tables\Actions\EditAction::make(), | ||
]) | ||
->bulkActions([ | ||
Tables\Actions\BulkActionGroup::make([ | ||
Tables\Actions\DeleteBulkAction::make(), | ||
]), | ||
]); | ||
} | ||
|
||
public static function getRelations(): array | ||
{ | ||
return [ | ||
// | ||
]; | ||
} | ||
|
||
public static function getPages(): array | ||
{ | ||
return [ | ||
'index' => Pages\ListSuppliers::route('/'), | ||
'create' => Pages\CreateSupplier::route('/create'), | ||
'edit' => Pages\EditSupplier::route('/{record}/edit'), | ||
]; | ||
} | ||
|
||
public static function getNavigationBadge(): ?string | ||
{ | ||
return (string) static::getModel()::count(); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
app/Filament/Resources/SupplierResource/Pages/CreateSupplier.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
namespace App\Filament\Resources\SupplierResource\Pages; | ||
|
||
use App\Filament\Resources\SupplierResource; | ||
use Filament\Actions; | ||
use Filament\Resources\Pages\CreateRecord; | ||
|
||
class CreateSupplier extends CreateRecord | ||
{ | ||
protected static string $resource = SupplierResource::class; | ||
} |
19 changes: 19 additions & 0 deletions
19
app/Filament/Resources/SupplierResource/Pages/EditSupplier.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace App\Filament\Resources\SupplierResource\Pages; | ||
|
||
use App\Filament\Resources\SupplierResource; | ||
use Filament\Actions; | ||
use Filament\Resources\Pages\EditRecord; | ||
|
||
class EditSupplier extends EditRecord | ||
{ | ||
protected static string $resource = SupplierResource::class; | ||
|
||
protected function getHeaderActions(): array | ||
{ | ||
return [ | ||
Actions\DeleteAction::make(), | ||
]; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
app/Filament/Resources/SupplierResource/Pages/ListSuppliers.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace App\Filament\Resources\SupplierResource\Pages; | ||
|
||
use App\Filament\Resources\SupplierResource; | ||
use Filament\Actions; | ||
use Filament\Resources\Pages\ListRecords; | ||
|
||
class ListSuppliers extends ListRecords | ||
{ | ||
protected static string $resource = SupplierResource::class; | ||
|
||
protected function getHeaderActions(): array | ||
{ | ||
return [ | ||
Actions\CreateAction::make(), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
use Illuminate\Database\Eloquent\Casts\Attribute; | ||
use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class Supplier extends Model | ||
{ | ||
use HasFactory; | ||
|
||
protected function document(): Attribute | ||
{ | ||
return Attribute::make( | ||
set: fn (string $value) => sanitize($value), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
<?php | ||
|
||
namespace App\Policies; | ||
|
||
use App\Models\User; | ||
use App\Models\Supplier; | ||
use Illuminate\Auth\Access\HandlesAuthorization; | ||
|
||
class SupplierPolicy | ||
{ | ||
use HandlesAuthorization; | ||
|
||
/** | ||
* Determine whether the user can view any models. | ||
*/ | ||
public function viewAny(User $user): bool | ||
{ | ||
return $user->can('view_any_supplier'); | ||
} | ||
|
||
/** | ||
* Determine whether the user can view the model. | ||
*/ | ||
public function view(User $user, Supplier $supplier): bool | ||
{ | ||
return $user->can('view_supplier'); | ||
} | ||
|
||
/** | ||
* Determine whether the user can create models. | ||
*/ | ||
public function create(User $user): bool | ||
{ | ||
return $user->can('create_supplier'); | ||
} | ||
|
||
/** | ||
* Determine whether the user can update the model. | ||
*/ | ||
public function update(User $user, Supplier $supplier): bool | ||
{ | ||
return $user->can('update_supplier'); | ||
} | ||
|
||
/** | ||
* Determine whether the user can delete the model. | ||
*/ | ||
public function delete(User $user, Supplier $supplier): bool | ||
{ | ||
return $user->can('delete_supplier'); | ||
} | ||
|
||
/** | ||
* Determine whether the user can bulk delete. | ||
*/ | ||
public function deleteAny(User $user): bool | ||
{ | ||
return $user->can('delete_any_supplier'); | ||
} | ||
|
||
/** | ||
* Determine whether the user can permanently delete. | ||
*/ | ||
public function forceDelete(User $user, Supplier $supplier): bool | ||
{ | ||
return $user->can('force_delete_supplier'); | ||
} | ||
|
||
/** | ||
* Determine whether the user can permanently bulk delete. | ||
*/ | ||
public function forceDeleteAny(User $user): bool | ||
{ | ||
return $user->can('force_delete_any_supplier'); | ||
} | ||
|
||
/** | ||
* Determine whether the user can restore. | ||
*/ | ||
public function restore(User $user, Supplier $supplier): bool | ||
{ | ||
return $user->can('restore_supplier'); | ||
} | ||
|
||
/** | ||
* Determine whether the user can bulk restore. | ||
*/ | ||
public function restoreAny(User $user): bool | ||
{ | ||
return $user->can('restore_any_supplier'); | ||
} | ||
|
||
/** | ||
* Determine whether the user can replicate. | ||
*/ | ||
public function replicate(User $user, Supplier $supplier): bool | ||
{ | ||
return $user->can('replicate_supplier'); | ||
} | ||
|
||
/** | ||
* Determine whether the user can reorder. | ||
*/ | ||
public function reorder(User $user): bool | ||
{ | ||
return $user->can('reorder_supplier'); | ||
} | ||
} |
Oops, something went wrong.