Skip to content

Commit

Permalink
Merge pull request #190 from cesar99144/feature-supplier
Browse files Browse the repository at this point in the history
Feature supplier
  • Loading branch information
icarojobs authored Sep 3, 2024
2 parents 66f7feb + 0dcbff4 commit 0c2752e
Show file tree
Hide file tree
Showing 10 changed files with 397 additions and 1 deletion.
19 changes: 18 additions & 1 deletion app/Filament/Resources/ProductTransactionResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
use App\Enums\ProductTransactionTypeEnum;
use App\Filament\Resources\ProductTransactionResource\Pages;
use App\Models\ProductTransaction;
use Closure;
use Filament\Forms;
use Filament\Forms\Components\Hidden;
use Filament\Forms\Form;
use Filament\Forms\Get;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Table;
Expand Down Expand Up @@ -52,7 +55,16 @@ public static function form(Form $form): Form
->required()
->label('Tipo de Movimentação')
->options(ProductTransactionTypeEnum::class)
->inline(),
->inline()
->reactive(),

Forms\Components\Select::make('supplier_id')
->label('Fornecedor')
->relationship('supplier', 'registered_name')
->searchable()
->preload()
->reactive()
->hidden(fn ($get) => $get('type') !== 'buy'),

Forms\Components\Placeholder::make('description')
->label('Descrição')
Expand All @@ -71,6 +83,7 @@ public static function table(Table $table): Table
->sortable(),

Tables\Columns\TextColumn::make('description')
->wrap()
->label('Descrição')
->searchable(),

Expand All @@ -84,6 +97,10 @@ public static function table(Table $table): Table
->numeric()
->sortable(),

Tables\Columns\TextColumn::make('supplier.registered_name')
->label('Fornecedor')
->sortable(),

Tables\Columns\TextColumn::make('created_at')
->label('Criado em')
->dateTime('d/m/Y H:i:s')
Expand Down
120 changes: 120 additions & 0 deletions app/Filament/Resources/SupplierResource.php
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 app/Filament/Resources/SupplierResource/Pages/CreateSupplier.php
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 app/Filament/Resources/SupplierResource/Pages/EditSupplier.php
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 app/Filament/Resources/SupplierResource/Pages/ListSuppliers.php
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(),
];
}
}
4 changes: 4 additions & 0 deletions app/Models/ProductTransaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ public function product(): BelongsTo
{
return $this->belongsTo(Product::class);
}
public function supplier(): BelongsTo
{
return $this->belongsTo(Supplier::class)->where('status', 1);
}

public function scopeApplyFirstQueryScopeGetSale($query)
{
Expand Down
19 changes: 19 additions & 0 deletions app/Models/Supplier.php
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),
);
}
}
108 changes: 108 additions & 0 deletions app/Policies/SupplierPolicy.php
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');
}
}
Loading

0 comments on commit 0c2752e

Please sign in to comment.