baks-dev/products-supply
Laravel/PHP 8.4+ модуль для управления поставками продукции: установка через Composer, установка ассетов, миграции Doctrine для обновления схемы БД, поддержка тестов PHPUnit. Подходит для проектов, где нужен учет и обработка поставок товаров.
composer require baks-dev/products-supply
php artisan baks:assets:install
config/baks/ and database/migrations/.php artisan doctrine:migrations:diff
php artisan doctrine:migrations:migrate
suppliers, products, and supply_logs tables in your database.php artisan tinker
$supplier = \Baks\Supply\Models\Supplier::create([...]);
$product = \Baks\Supply\Models\Product::create([...]);
$supply = \Baks\Supply\Models\Supply::create([...]);
use Baks\Supply\Models\Supplier;
$supplier = Supplier::create([
'name' => 'Acme Corp',
'contact_email' => 'contact@acme.com',
'contract_start_date' => now(),
'contract_end_date' => now()->addYear(),
'risk_score' => 1, // 1-5 scale
]);
use Baks\Supply\Models\Product;
$product = Product::create([
'name' => 'Widget Pro',
'sku' => 'WIDGET-1000',
'supplier_id' => $supplier->id,
]);
use Baks\Supply\Models\Supply;
$supply = Supply::create([
'product_id' => $product->id,
'supplier_id' => $supplier->id,
'quantity' => 100,
'unit_price' => 9.99,
'supply_date' => now(),
'warehouse_id' => 1, // Assuming you have a warehouses table
]);
$currentStock = Supply::where('product_id', $product->id)
->sum('quantity');
php artisan vendor:publish --tag=baks-supply-config
config/baks/supply.php to adjust:
// Create supplier with contract
$supplier = Supplier::create([
'name' => 'Supplier X',
'contract' => [
'start_date' => now(),
'end_date' => now()->addYears(2),
'terms' => 'Standard SLA',
],
]);
// Attach documents (e.g., certificates)
$supplier->documents()->create([
'type' => 'certificate',
'path' => 'storage/certificates/supplier_x.pdf',
'expiry_date' => now()->addYear(),
]);
// Log a delivery delay
$supplier->performanceLogs()->create([
'delay_hours' => 24,
'reason' => 'Logistics strike',
'resolved' => false,
]);
// Auto-update risk score
$supplier->updateRiskScore(); // Triggered by event listener
// Record supply across warehouses
$warehouses = [1, 2, 3]; // IDs
foreach ($warehouses as $warehouseId) {
Supply::create([
'product_id' => $product->id,
'warehouse_id' => $warehouseId,
'quantity' => 50, // Distribute evenly
'supply_date' => now(),
]);
}
// Sync stock levels (e.g., via queue job)
Supply::syncStockLevels();
// Configure threshold in config/baks/supply.php
'low_stock_threshold' => 10,
// Trigger alert (via observer or event)
event(new LowStockAlert($product, $currentStock));
// Check for expiring certificates
$expiredCertificates = SupplierDocument::where('type', 'certificate')
->where('expiry_date', '<', now())
->with('supplier')
->get();
// Notify admins (e.g., via Laravel Notifications)
foreach ($expiredCertificates as $doc) {
Notification::route('mail', $doc->supplier->contact_email)
->notify(new CertificateExpiryNotification($doc));
}
// Log supply chain events
SupplyEvent::create([
'supply_id' => $supply->id,
'action' => 'received',
'user_id' => auth()->id(),
'metadata' => ['notes' => 'Partial shipment'],
]);
AppServiceProvider:
public function register()
{
$this->app->bind(
\Baks\Supply\Contracts\SupplyRepository::class,
\Baks\Supply\Repositories\SupplyRepository::class
);
}
EventServiceProvider:
protected $listen = [
\Baks\Supply\Events\SupplyUpdated::class => [
\App\Listeners\UpdateInventory::class,
\App\Listeners\NotifyLowStock::class,
],
];
php artisan make:command GenerateSupplyReport
public function handle()
{
$report = \Baks\Supply\Services\SupplyReport::generate(
$this->option('start-date'),
$this->option('end-date')
);
// Export to CSV/PDF
}
// routes/api.php
Route::apiResource('suppliers', \Baks\Supply\Http\Controllers\SupplierController::class)
->middleware('auth:api');
nwidart/laravel-graphql) to query supplies:
query {
supplies(filter: { productId: 1 }) {
id
product { name }
quantity
supplyDate
}
}
public function test_supply_creation()
{
$supply = Supply::factory()->create();
$this->assertDatabaseHas('supplies', [
'id' => $supply->id,
'quantity' => 100,
]);
}
public function test_supplier_creation()
{
$response = $this->postJson('/api/suppliers', [
'name' => 'Test Supplier',
'contact_email' => 'test@example.com',
]);
$response->assertCreated();
$this->assertDatabaseHas('suppliers', [
'name' => 'Test Supplier',
]);
}
public function test_migrations()
{
Artisan::call('migrate:fresh');
$this->assertSchemaHasTable('suppliers');
$this->assertSchemaHasColumn('suppliers', 'risk_score');
}
Migration Conflicts
supplies table already exists).laravel-migrations-generator.php artisan doctrine:migrations:diff before applying to preview changes.Doctrine vs. Eloquent
class SupplyService {
public function __construct(private SupplyRepository $repository) {}
public function get
How can I help you explore Laravel packages today?