Faza 3.3: Depozit — Furnizori + Catalog piese + Achiziții
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).
This commit is contained in:
@@ -13,6 +13,10 @@ use App\Models\Tenant\Lead;
|
||||
use App\Models\Tenant\Post;
|
||||
use App\Models\Tenant\User;
|
||||
use App\Models\Tenant\Vehicle;
|
||||
use App\Models\Tenant\Part;
|
||||
use App\Models\Tenant\Purchase;
|
||||
use App\Models\Tenant\PurchaseItem;
|
||||
use App\Models\Tenant\Supplier;
|
||||
use App\Models\Tenant\WorkOrder;
|
||||
use App\Models\Tenant\WorkOrderPart;
|
||||
use App\Models\Tenant\WorkOrderWork;
|
||||
@@ -316,6 +320,101 @@ class DatabaseSeeder extends Seeder
|
||||
);
|
||||
$wo->refresh()->recalcTotal();
|
||||
|
||||
// ─── Furnizori demo ───────────────────────────────────────
|
||||
$sup1 = Supplier::firstOrCreate(
|
||||
['company_id' => $psauto->id, 'name' => 'AutoParts Moldova SRL'],
|
||||
[
|
||||
'contact_name' => 'Ion Popescu', 'phone' => '+373 22 123456',
|
||||
'email' => 'sales@autoparts.md', 'website' => 'autoparts.md',
|
||||
'pay_terms' => 'Net 30', 'delivery_days' => 1, 'rating' => 5,
|
||||
'discount_pct' => 10, 'categories' => ['Frâne', 'Filtre', 'Ulei'],
|
||||
'notes' => 'Furnizor principal',
|
||||
]
|
||||
);
|
||||
$sup2 = Supplier::firstOrCreate(
|
||||
['company_id' => $psauto->id, 'name' => 'Inter Cars Moldova'],
|
||||
[
|
||||
'contact_name' => 'Maria Lupu', 'phone' => '+373 22 654321',
|
||||
'email' => 'md@intercars.eu', 'website' => 'intercars.eu',
|
||||
'pay_terms' => 'Net 14', 'delivery_days' => 2, 'rating' => 4,
|
||||
'discount_pct' => 8, 'categories' => ['Toate'],
|
||||
'notes' => 'Catalog european larg',
|
||||
]
|
||||
);
|
||||
|
||||
// ─── Piese demo ───────────────────────────────────────────
|
||||
Part::firstOrCreate(
|
||||
['company_id' => $psauto->id, 'article' => 'SHU5W40'],
|
||||
[
|
||||
'name' => 'Ulei motor Shell Helix Ultra 5W-40 1L', 'brand' => 'Shell',
|
||||
'category' => 'Ulei', 'qty' => 12, 'unit' => 'L', 'min_qty' => 5,
|
||||
'buy_price' => 65, 'sell_price' => 85, 'location' => 'A1-M1',
|
||||
'preferred_supplier_id' => $sup1->id,
|
||||
]
|
||||
);
|
||||
Part::firstOrCreate(
|
||||
['company_id' => $psauto->id, 'article' => 'W81180'],
|
||||
[
|
||||
'name' => 'Filtru ulei Mann W811/80', 'brand' => 'MANN',
|
||||
'category' => 'Filtre', 'qty' => 8, 'unit' => 'buc', 'min_qty' => 3,
|
||||
'buy_price' => 32, 'sell_price' => 45, 'location' => 'A2-M3',
|
||||
'preferred_supplier_id' => $sup1->id,
|
||||
]
|
||||
);
|
||||
Part::firstOrCreate(
|
||||
['company_id' => $psauto->id, 'article' => 'P85020'],
|
||||
[
|
||||
'name' => 'Plăcuțe frână Brembo P85020', 'brand' => 'Brembo',
|
||||
'category' => 'Frâne', 'qty' => 4, 'unit' => 'set', 'min_qty' => 2,
|
||||
'buy_price' => 280, 'sell_price' => 350, 'location' => 'B2-M1',
|
||||
'preferred_supplier_id' => $sup1->id,
|
||||
]
|
||||
);
|
||||
Part::firstOrCreate(
|
||||
['company_id' => $psauto->id, 'article' => 'AF12P'],
|
||||
[
|
||||
'name' => 'Antigel G12+ 1L', 'brand' => 'Bosch',
|
||||
'category' => 'Lichide', 'qty' => 0, 'unit' => 'L', 'min_qty' => 10,
|
||||
'buy_price' => 28, 'sell_price' => 35, 'location' => 'A3-M2',
|
||||
'preferred_supplier_id' => $sup2->id,
|
||||
]
|
||||
);
|
||||
Part::firstOrCreate(
|
||||
['company_id' => $psauto->id, 'article' => 'BKR6E'],
|
||||
[
|
||||
'name' => 'Bujie NGK BKR6E', 'brand' => 'NGK',
|
||||
'category' => 'Electrică', 'qty' => 16, 'unit' => 'buc', 'min_qty' => 4,
|
||||
'buy_price' => 35, 'sell_price' => 45, 'location' => 'C1-M1',
|
||||
'preferred_supplier_id' => $sup2->id,
|
||||
]
|
||||
);
|
||||
|
||||
// ─── Achiziție demo ───────────────────────────────────────
|
||||
$purchase = Purchase::firstOrCreate(
|
||||
['company_id' => $psauto->id, 'number' => 'P-26-0001'],
|
||||
[
|
||||
'supplier_id' => $sup1->id, 'order_date' => today()->subDays(7),
|
||||
'expected_at' => today()->subDays(5), 'received_at' => today()->subDays(5),
|
||||
'paid_at' => today()->subDays(5), 'status' => 'received',
|
||||
'notes' => 'Plan stoc curent',
|
||||
]
|
||||
);
|
||||
$partOil = Part::where('company_id', $psauto->id)->where('article', 'SHU5W40')->first();
|
||||
if ($partOil) {
|
||||
PurchaseItem::firstOrCreate(
|
||||
['company_id' => $psauto->id, 'purchase_id' => $purchase->id, 'part_id' => $partOil->id],
|
||||
['name' => $partOil->name, 'article' => $partOil->article, 'qty' => 12, 'unit' => 'L', 'buy_price' => 65, 'received' => true]
|
||||
);
|
||||
}
|
||||
$partFilter = Part::where('company_id', $psauto->id)->where('article', 'W81180')->first();
|
||||
if ($partFilter) {
|
||||
PurchaseItem::firstOrCreate(
|
||||
['company_id' => $psauto->id, 'purchase_id' => $purchase->id, 'part_id' => $partFilter->id],
|
||||
['name' => $partFilter->name, 'article' => $partFilter->article, 'qty' => 8, 'unit' => 'buc', 'buy_price' => 32, 'received' => true]
|
||||
);
|
||||
}
|
||||
$purchase->refresh()->recalcTotal();
|
||||
|
||||
app(TenantManager::class)->clear();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user