41 lines
990 B
PHP
41 lines
990 B
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class StockActivityLogService
|
|
{
|
|
/**
|
|
* Log stock related activity.
|
|
*/
|
|
public static function log(
|
|
string $logName,
|
|
string $event,
|
|
string $description,
|
|
Model $performedOn,
|
|
Model $outlet,
|
|
int $quantityChange,
|
|
int $previousStock,
|
|
int $newStock,
|
|
array $extraProperties = [],
|
|
?Model $causedBy = null
|
|
): void {
|
|
$causedBy = $causedBy ?: auth()->user();
|
|
|
|
$properties = array_merge([
|
|
'outlet_id' => $outlet->getKey(),
|
|
'quantity_change' => $quantityChange,
|
|
'previous_stock' => $previousStock,
|
|
'new_stock' => $newStock,
|
|
], $extraProperties);
|
|
|
|
activity($logName)
|
|
->performedOn($performedOn)
|
|
->causedBy($causedBy)
|
|
->withProperties($properties)
|
|
->event($event)
|
|
->log($description);
|
|
}
|
|
}
|