Skip to content

Commit 56106f0

Browse files
Refatoração de campos do banco, nome de tabela, nome da model, criação de serviço para atualização de iventario.
1 parent 603804a commit 56106f0

33 files changed

+693
-296
lines changed

app/Enums/Products/CategoryProductEnum.php

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,38 @@
77
enum CategoryProductEnum: string implements HasLabel
88
{
99
// Wallace (Retidado os espaços em branco para economizar tamanho de arquivo)
10-
case HARD_DISK = 'hard_disk';
11-
case MEMORY = 'memory';
12-
case PROCESSATOR = 'processator';
13-
case SSD = 'ssd';
14-
case VIDEO_CARD = 'video_card';
10+
case PROCESSOR = 'processor';
11+
case MOTHERBOARD = 'motherboard';
12+
case SSD = 'SSD';
13+
case NVME = 'NVME';
14+
case GRAPHICS_CARD = 'graphic_card';
15+
case POWER_SUPPLY = 'power_supply';
16+
case COOLING = 'cooling';
1517
case HEADPHONES = 'headphones';
18+
case MEMORY = 'memory';
19+
case HARD_DISK = 'hard_disk';
20+
case KEYBOARD = 'keyboard';
21+
case MOUSE = 'mouse';
22+
case MONITOR = 'monitor';
23+
case SOFTWARE = 'software';
1624

1725
public function getLabel(): string
1826
{
1927
return match ($this) {
20-
self::HARD_DISK => 'HD',
21-
self::MEMORY => 'Memória',
22-
self::PROCESSATOR => 'Processador',
28+
self::PROCESSOR => 'Processador',
29+
self::MOTHERBOARD => 'Placa Mãe',
2330
self::SSD => 'SSD',
24-
self::VIDEO_CARD => 'Placa de Vídeo',
25-
self::HEADPHONES => 'Fones',
31+
self::NVME => 'NVME',
32+
self::GRAPHICS_CARD => 'Placa de Vídeo',
33+
self::POWER_SUPPLY => 'Fonte de Alimentação',
34+
self::COOLING => 'Cooling',
35+
self::HEADPHONES => 'Fones de Ouvido',
36+
self::MEMORY => 'Memoria',
37+
self::HARD_DISK => 'Disco Rigido',
38+
self::KEYBOARD => 'Teclado',
39+
self::MOUSE => 'Mouse',
40+
self::MONITOR => 'Monitor',
41+
self::SOFTWARE => 'Software',
2642
};
2743
}
2844
}

app/Enums/Products/ManufacturerProductEnum.php

Lines changed: 0 additions & 37 deletions
This file was deleted.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace App\Enums\Products;
4+
5+
use Filament\Support\Contracts\HasLabel;
6+
7+
enum MovimentProductEnum: string implements HasLabel
8+
{
9+
case IN = 'in';
10+
case OUT = 'out';
11+
public function getLabel(): ?string
12+
{
13+
return match ($this) {
14+
self::IN => 'Entrada',
15+
self::OUT => 'Saída',
16+
17+
};
18+
}
19+
}
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
<?php
2+
3+
namespace App\Filament\Admin\Resources;
4+
5+
use Filament\Forms;
6+
use Filament\Tables;
7+
use Filament\Forms\Form;
8+
use App\Models\Inventory;
9+
use Filament\Tables\Table;
10+
use App\Models\Manufacturer;
11+
use Filament\Resources\Resource;
12+
use Filament\Forms\Components\Select;
13+
use Filament\Forms\Components\Fieldset;
14+
use Filament\Forms\Components\Textarea;
15+
use Filament\Tables\Columns\TextColumn;
16+
use Filament\Forms\Components\TextInput;
17+
use Filament\Forms\Components\DatePicker;
18+
use Illuminate\Database\Eloquent\Builder;
19+
use Leandrocfe\FilamentPtbrFormFields\Money;
20+
use Illuminate\Database\Eloquent\SoftDeletingScope;
21+
use App\Filament\Admin\Resources\InventoryResource\Pages;
22+
use App\Filament\Admin\Resources\InventoryResource\RelationManagers;
23+
24+
class InventoryResource extends Resource
25+
{
26+
protected static ?string $model = Inventory::class;
27+
28+
protected static ?string $navigationIcon = 'fas-truck-moving';
29+
protected static ?string $navigationGroup = 'Produtos';
30+
protected static ?string $navigationLabel = 'Estoque';
31+
protected static ?string $modelLabel = 'Estoque';
32+
protected static ?string $modelLabelPlural = "Estoque";
33+
protected static ?int $navigationSort = 3;
34+
35+
public static function form(Form $form): Form
36+
{
37+
return $form
38+
->schema([
39+
40+
Fieldset::make('Foto')
41+
->schema([
42+
Select::make('product_id')
43+
->relationship('product', 'name')
44+
->label('Produto')
45+
->searchable()
46+
->preload()
47+
->required(),
48+
TextInput::make('quantity')
49+
->label('Quantidade')
50+
->required()
51+
->numeric()
52+
->default(0),
53+
Money::make('unit_price')
54+
->label('Valor Unitário')
55+
->default('0,00')
56+
->required(),
57+
58+
DatePicker::make('puchase_date')
59+
->required()
60+
->label('Data da Compra'),
61+
])->columns(4),
62+
63+
Fieldset::make('Descrição Opcional')
64+
->schema([
65+
Textarea::make('reason')
66+
->label('Descrição')
67+
->columnSpanFull(),
68+
])->columns(1),
69+
]);
70+
}
71+
72+
public static function table(Table $table): Table
73+
{
74+
return $table
75+
->columns([
76+
Tables\Columns\TextColumn::make('product.name')
77+
->label('Produto')
78+
->searchable()
79+
->sortable(),
80+
81+
Tables\Columns\TextColumn::make('quantity')
82+
->label('Quantidade em Estoque')
83+
->numeric()
84+
->alignCenter()
85+
->sortable(),
86+
87+
Tables\Columns\TextColumn::make('unit_price')
88+
->label('Valor Unitário')
89+
->numeric()
90+
->alignCenter()
91+
->money('BRL')
92+
->sortable(),
93+
94+
Tables\Columns\TextColumn::make('stock_value')
95+
->label('Valor em Estoque')
96+
->numeric()
97+
->alignCenter()
98+
->getStateUsing(function ($record) {
99+
// Calcula o valor do estoque multiplicando a quantidade pelo preço unitário
100+
return $record->quantity * $record->unit_price;
101+
})
102+
->money('BRL')
103+
->sortable(),
104+
105+
Tables\Columns\TextColumn::make('puchase_date')
106+
->label('Data da Compra')
107+
->alignCenter()
108+
->date('d/m/Y')
109+
->sortable(),
110+
111+
Tables\Columns\TextColumn::make('created_at')
112+
->dateTime()
113+
->sortable()
114+
->toggleable(isToggledHiddenByDefault: true),
115+
116+
Tables\Columns\TextColumn::make('updated_at')
117+
->dateTime()
118+
->sortable()
119+
->toggleable(isToggledHiddenByDefault: true),
120+
])
121+
->filters([
122+
//
123+
])
124+
->actions([
125+
Tables\Actions\ViewAction::make(),
126+
Tables\Actions\EditAction::make(),
127+
])
128+
->bulkActions([
129+
Tables\Actions\BulkActionGroup::make([
130+
Tables\Actions\DeleteBulkAction::make(),
131+
]),
132+
]);
133+
}
134+
135+
public static function getRelations(): array
136+
{
137+
return [
138+
//
139+
];
140+
}
141+
142+
public static function getPages(): array
143+
{
144+
return [
145+
'index' => Pages\ListInventory::route('/'),
146+
'create' => Pages\CreateInventory::route('/create'),
147+
'view' => Pages\ViewInventory::route('/{record}'),
148+
'edit' => Pages\EditInventory::route('/{record}/edit'),
149+
];
150+
}
151+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
namespace App\Filament\Admin\Resources\InventoryResource\Pages;
4+
5+
use Filament\Actions;
6+
use App\Models\Product;
7+
use Filament\Resources\Pages\CreateRecord;
8+
use App\Enums\Products\MovimentProductEnum;
9+
use App\Filament\Admin\Resources\InventoryResource;
10+
use App\Services\Inventory\InventoryTransactionService;
11+
12+
class CreateInventory extends CreateRecord
13+
{
14+
protected static string $resource = InventoryResource::class;
15+
16+
protected function afterCreate(): void
17+
{
18+
// $this->record é o objeto Inventory recém-criado
19+
$inventory = $this->record;
20+
21+
// Carregar o objeto Product associado ao Inventory
22+
$product = $inventory->product; // Assumindo que você tenha um relacionamento 'product' no modelo Inventory
23+
24+
// Verifique se o produto foi encontrado
25+
if ($product) {
26+
27+
$purchase_price = $product->price;
28+
// Garantir que a data de compra seja convertida para string (formato Y-m-d)
29+
$purchaseDate = $product->purchase_date
30+
? $product->purchase_date->toDateString() // Se existir, formate a data
31+
: now()->toDateString(); // Se não, use a data atual como padrão
32+
33+
// Agora, passamos o objeto Product e os outros valores para o serviço
34+
$inventoryTransactionService = new InventoryTransactionService();
35+
36+
// Chame o serviço para registrar a transação
37+
$inventoryTransactionService->recordTransaction(
38+
$product, // Passando o objeto Product
39+
MovimentProductEnum::IN->value, // Tipo de movimento (entrada)
40+
$purchase_price, // Preço de compra (garantido como int)
41+
$purchaseDate, // Data de compra (garantido como string no formato Y-m-d)
42+
$inventory->id // Passando o ID do inventory recém-criado
43+
);
44+
}
45+
}
46+
}

app/Filament/Admin/Resources/IventoryResource/Pages/EditIventory.php renamed to app/Filament/Admin/Resources/InventoryResource/Pages/EditInventory.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<?php
22

3-
namespace App\Filament\Admin\Resources\IventoryResource\Pages;
3+
namespace App\Filament\Admin\Resources\InventoryResource\Pages;
44

5-
use App\Filament\Admin\Resources\IventoryResource;
5+
use App\Filament\Admin\Resources\InventoryResource;
66
use Filament\Actions;
77
use Filament\Resources\Pages\EditRecord;
88

9-
class EditIventory extends EditRecord
9+
class EditInventory extends EditRecord
1010
{
11-
protected static string $resource = IventoryResource::class;
11+
protected static string $resource = InventoryResource::class;
1212

1313
protected function getHeaderActions(): array
1414
{
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace App\Filament\Admin\Resources\InventoryResource\Pages;
4+
5+
use App\Filament\Admin\Resources\InventoryResource;
6+
use Filament\Actions;
7+
use Filament\Resources\Pages\ListRecords;
8+
9+
class ListInventory extends ListRecords
10+
{
11+
protected static string $resource = InventoryResource::class;
12+
13+
protected function getHeaderActions(): array
14+
{
15+
return [
16+
Actions\CreateAction::make(),
17+
];
18+
}
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace App\Filament\Admin\Resources\InventoryResource\Pages;
4+
5+
use Filament\Actions;
6+
use Filament\Resources\Pages\ViewRecord;
7+
use App\Filament\Admin\Resources\InventoryResource;
8+
9+
class ViewInventory extends ViewRecord
10+
{
11+
protected static string $resource = InventoryResource::class;
12+
13+
protected function getHeaderActions(): array
14+
{
15+
return [
16+
Actions\EditAction::make(),
17+
];
18+
}
19+
}

0 commit comments

Comments
 (0)