- Introduced StockMutation model and service to handle stock changes. - Created migration for stock_mutations table. - Implemented stock mutation recording in various services (CuttingService, OrderService, PurchaseService, RestockService, RetailStockService). - Added StockHistoryController to manage stock history views. - Developed frontend components for displaying stock history and actions. - Updated routes to include stock history access with appropriate permissions. - Enhanced ProductVariant and RawMaterialPrice models to support stock mutations. - Added RowHistoryAction button for accessing stock history in product and raw material tables.
37 lines
1.0 KiB
PHP
37 lines
1.0 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Manage;
|
|
|
|
use App\Models\StockMutation;
|
|
use App\Models\User;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class StockMutationService
|
|
{
|
|
public function record(
|
|
Model $stockable,
|
|
string $type,
|
|
float|int $quantity,
|
|
float|int $stockBefore,
|
|
float|int $stockAfter,
|
|
?Model $source = null,
|
|
?string $stockQuality = null,
|
|
?string $description = null,
|
|
?User $user = null,
|
|
): StockMutation {
|
|
return StockMutation::create([
|
|
'stockable_type' => $stockable->getMorphClass(),
|
|
'stockable_id' => $stockable->id,
|
|
'type' => $type,
|
|
'source_type' => $source?->getMorphClass(),
|
|
'source_id' => $source?->id,
|
|
'quantity' => $quantity,
|
|
'stock_before' => $stockBefore,
|
|
'stock_after' => $stockAfter,
|
|
'stock_quality' => $stockQuality,
|
|
'description' => $description,
|
|
'user_id' => $user?->id ?? auth()->id(),
|
|
]);
|
|
}
|
|
}
|