7264dccffa
Schema: - suppliers: name, contact, phone/email/website, pay_terms, delivery_days, rating (1-5), discount_pct, categories (JSON), is_active, notes - parts: name, article (UNIQUE per tenant), brand, category, qty/unit/min_qty, buy_price/sell_price, location (rack/bin), barcode, preferred_supplier_id, is_active. Index pe (company_id, category) și (company_id, is_active). - purchases: număr unique per tenant + an, supplier_id, status workflow (draft/ordered/received/cancelled), order/expected/received/paid_at, total - purchase_items: name, article, qty, unit, buy_price, total auto, received bool; link opțional la part_id - wo_parts + part_id: linkare opțională la catalog (alter migration) Modele cu logică: - Part::adjustStock($delta) — modifică qty cu validare ≥ 0 - Part::isLow() / isOut() helpers - Purchase::markReceived() — atomic: marchează items ca received + creste qty pe pieces din catalog (DB::transaction) - WorkOrderPart::updating event — la trecerea status='installed' decrementează stoc auto. La revenire (ex: storno) incrementează la loc. - PurchaseItem::saving — total = qty * buy_price; recalc parent total Filament resources (group Depozit): - SupplierResource: form 3 secțiuni, rating ★★★★★, TagsInput pentru categorii - PartResource: form 4 secțiuni, badge nav cu nr. piese sub stoc minim, filtre low_stock + out_of_stock, coloană qty colorată după stoc - PurchaseResource: form antet + RelationManager Items. Action 'Recepționează' care apelează markReceived() — un click = stoc actualizat WorkOrder PartsRelationManager updated: - Selector din catalog (Part::active) cu stoc afișat - Auto-fill name/article/brand/unit/buy_price/sell_price din piesa selectată - Helper text: la status='installed' se scade din stoc Widget low-stock: - TableWidget pe dashboard tenant, listează piesele cu qty <= min_qty - Span full, sortat după qty (cele mai critice sus) Seed: - 2 furnizori (AutoParts Moldova SRL ★5, Inter Cars Moldova ★4) - 5 piese demo: Ulei Shell, Filtru Mann, Plăcuțe Brembo, Antigel (qty=0!), Bujii NGK - 1 achiziție recepționată (P-26-0001) cu 2 articole linked la catalog Total Filament tenant routes: 63 (de la 31).
122 lines
5.0 KiB
PHP
122 lines
5.0 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Tenant\Resources;
|
|
|
|
use App\Filament\Tenant\Resources\PurchaseResource\Pages;
|
|
use App\Filament\Tenant\Resources\PurchaseResource\RelationManagers;
|
|
use App\Models\Tenant\Purchase;
|
|
use App\Models\Tenant\Supplier;
|
|
use Filament\Actions;
|
|
use Filament\Forms;
|
|
use Filament\Notifications\Notification;
|
|
use Filament\Resources\Resource;
|
|
use Filament\Schemas;
|
|
use Filament\Schemas\Schema;
|
|
use Filament\Tables;
|
|
use Filament\Tables\Table;
|
|
|
|
class PurchaseResource extends Resource
|
|
{
|
|
protected static ?string $model = Purchase::class;
|
|
|
|
protected static string|\BackedEnum|null $navigationIcon = 'heroicon-o-shopping-cart';
|
|
|
|
protected static ?string $navigationLabel = 'Achiziții';
|
|
|
|
protected static string|\UnitEnum|null $navigationGroup = 'Depozit';
|
|
|
|
protected static ?string $modelLabel = 'achiziție';
|
|
|
|
protected static ?string $pluralModelLabel = 'achiziții';
|
|
|
|
protected static ?int $navigationSort = 43;
|
|
|
|
public static function form(Schema $schema): Schema
|
|
{
|
|
return $schema->components([
|
|
Schemas\Components\Section::make('Antet')
|
|
->columns(3)
|
|
->schema([
|
|
Forms\Components\TextInput::make('number')->label('Nr.')->disabled()->dehydrated(false)->placeholder('Generat automat'),
|
|
Forms\Components\Select::make('supplier_id')
|
|
->label('Furnizor')
|
|
->options(fn () => Supplier::where('is_active', true)->pluck('name', 'id'))
|
|
->searchable()
|
|
->required(),
|
|
Forms\Components\Select::make('status')
|
|
->options(Purchase::STATUSES)
|
|
->default('draft')
|
|
->required(),
|
|
Forms\Components\DatePicker::make('order_date')->label('Data comandă')->default(today())->required(),
|
|
Forms\Components\DatePicker::make('expected_at')->label('Așteptată'),
|
|
Forms\Components\DatePicker::make('received_at')->label('Recepționată'),
|
|
Forms\Components\DatePicker::make('paid_at')->label('Plătită')->columnSpanFull(),
|
|
]),
|
|
Forms\Components\Textarea::make('notes')->label('Observații')->columnSpanFull()->rows(2),
|
|
]);
|
|
}
|
|
|
|
public static function table(Table $table): Table
|
|
{
|
|
return $table
|
|
->columns([
|
|
Tables\Columns\TextColumn::make('number')->label('Nr.')->searchable()->sortable(),
|
|
Tables\Columns\TextColumn::make('supplier.name')->label('Furnizor')->searchable(),
|
|
Tables\Columns\TextColumn::make('order_date')->label('Comandată')->date('d.m.Y'),
|
|
Tables\Columns\TextColumn::make('expected_at')->label('Așteptată')->date('d.m.Y')->placeholder('—'),
|
|
Tables\Columns\TextColumn::make('received_at')->label('Recepționată')->date('d.m.Y')->placeholder('—'),
|
|
Tables\Columns\TextColumn::make('status')
|
|
->formatStateUsing(fn ($s) => Purchase::STATUSES[$s] ?? $s)
|
|
->badge()
|
|
->colors([
|
|
'gray' => ['draft'],
|
|
'warning' => ['ordered'],
|
|
'success' => ['received'],
|
|
'danger' => ['cancelled'],
|
|
]),
|
|
Tables\Columns\TextColumn::make('total')->money('MDL')->alignRight(),
|
|
])
|
|
->filters([
|
|
Tables\Filters\SelectFilter::make('status')->options(Purchase::STATUSES),
|
|
Tables\Filters\SelectFilter::make('supplier_id')
|
|
->label('Furnizor')
|
|
->options(fn () => Supplier::pluck('name', 'id')),
|
|
])
|
|
->actions([
|
|
Actions\Action::make('receive')
|
|
->label('Recepționează')
|
|
->icon('heroicon-m-check-circle')
|
|
->color('success')
|
|
->visible(fn (Purchase $r) => $r->status !== 'received' && $r->status !== 'cancelled')
|
|
->requiresConfirmation()
|
|
->modalDescription('Se va incrementa stocul pieselor legate.')
|
|
->action(function (Purchase $r) {
|
|
$r->markReceived();
|
|
Notification::make()
|
|
->title('Recepționat — stoc actualizat')
|
|
->success()
|
|
->send();
|
|
}),
|
|
Actions\EditAction::make(),
|
|
Actions\DeleteAction::make(),
|
|
])
|
|
->defaultSort('order_date', 'desc');
|
|
}
|
|
|
|
public static function getRelations(): array
|
|
{
|
|
return [
|
|
RelationManagers\ItemsRelationManager::class,
|
|
];
|
|
}
|
|
|
|
public static function getPages(): array
|
|
{
|
|
return [
|
|
'index' => Pages\ListPurchases::route('/'),
|
|
'create' => Pages\CreatePurchase::route('/create'),
|
|
'edit' => Pages\EditPurchase::route('/{record}/edit'),
|
|
];
|
|
}
|
|
}
|