59 lines
1.2 KiB
PHP
59 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Repos\Order\Loan;
|
|
|
|
use App\Models\Branch\Branch;
|
|
use App\Repos\Order\OrderRepo;
|
|
use Closure;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class LoanOrderRepo
|
|
{
|
|
/**
|
|
* Satisfiable values
|
|
*
|
|
* @return array<string|null, string>
|
|
*/
|
|
public static function satisfiableValues(): array
|
|
{
|
|
return [
|
|
null => '-',
|
|
'satisfiable' => __('Satisfiable'),
|
|
'insufficient' => __('Insufficient'),
|
|
'unknown' => __('Unknown'),
|
|
];
|
|
}
|
|
|
|
/**
|
|
* When model is being created
|
|
*/
|
|
public static function creating(): Closure
|
|
{
|
|
return function (mixed $model) {
|
|
$model->status = $model->status ?: OrderRepo::defaultStatus();
|
|
};
|
|
}
|
|
|
|
/**
|
|
* When model is created
|
|
*/
|
|
public static function created(): Closure
|
|
{
|
|
return function ($model) {
|
|
$model->update(['unique_id' => static::fillUniqueId($model)]);
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Fill unique id
|
|
*/
|
|
public static function fillUniqueId(mixed $model): string
|
|
{
|
|
return sprintf(
|
|
'TB%s-%s',
|
|
Branch::find($model->branch_id)->unique_code ?? uniqid(),
|
|
$model->id,
|
|
);
|
|
}
|
|
}
|