Umsetzung der Warenwirtschafts-/Produktmanagement-Erweiterung gemaess Entwicklungsplan V4.0: - AP-00: Regressionsbasis fuer 5.1-Features (ProductPhase51Test) - AP-01: URL-Bugfixes B1/B2 (suppliers/packaging-items, breitere url-Spalten) - AP-04/04.1: iPad-taugliche, vereinheitlichte Tabellen-Aktionen - AP-05: Einstellungen "Allgemein" mit UST-Saetzen (tax_rates) und Lieferzeit-Vorlagen (delivery_times, inkl. Tage-Feld) - AP-06: Lieferanten um Bestellweg, Bestell-Mail/-URL und Lieferzeit erweitert - AP-07/07.1: INCI um Lieferanten-Mehrfachwahl, UST und Lieferzeit erweitert; Lieferanten-Detailansicht im Modal mit pflegbaren INCI-/Verpackungslisten - AP-08: Einkauf um UST-Snapshot, Netto/Brutto-Automatik und Duplizieren erweitert Entwicklungsplan aktualisiert: alle Klaerungspunkte (§5) vom Kunden beantwortet und in die jeweiligen APs eingearbeitet (AP-02/03/09/13/15), neues AP-18 (Hinweise-Doku unter Einstellungen) ergaenzt. Naechster Schritt eindeutig markiert: AP-09 (Produktion auf Hersteller-Rezeptur, kein Fallback, Warnung).
63 lines
1.5 KiB
PHP
63 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Repositories;
|
|
|
|
use App\Models\Supplier;
|
|
|
|
class SupplierRepository
|
|
{
|
|
/**
|
|
* @param array<string, mixed> $data
|
|
*/
|
|
public function create(array $data): Supplier
|
|
{
|
|
$supplier = Supplier::create($this->extractSupplierAttributes($data));
|
|
$this->syncCategories($supplier, $data['supplier_category_ids'] ?? []);
|
|
|
|
return $supplier;
|
|
}
|
|
|
|
/**
|
|
* @param array<string, mixed> $data
|
|
*/
|
|
public function update(Supplier $supplier, array $data): Supplier
|
|
{
|
|
$supplier->update($this->extractSupplierAttributes($data));
|
|
$this->syncCategories($supplier, $data['supplier_category_ids'] ?? []);
|
|
|
|
return $supplier->fresh();
|
|
}
|
|
|
|
/**
|
|
* @param array<int|string>|null $categoryIds
|
|
*/
|
|
public function syncCategories(Supplier $supplier, array $categoryIds): void
|
|
{
|
|
$ids = array_values(array_filter(array_map('intval', $categoryIds)));
|
|
|
|
$supplier->supplierCategories()->sync($ids);
|
|
}
|
|
|
|
/**
|
|
* @param array<string, mixed> $data
|
|
* @return array<string, mixed>
|
|
*/
|
|
protected function extractSupplierAttributes(array $data): array
|
|
{
|
|
return collect($data)->only([
|
|
'name',
|
|
'url',
|
|
'order_method',
|
|
'order_email',
|
|
'order_url',
|
|
'delivery_time',
|
|
'delivery_time_days',
|
|
'contact_person',
|
|
'email',
|
|
'phone',
|
|
'country_id',
|
|
'notes',
|
|
'active',
|
|
])->all();
|
|
}
|
|
}
|