mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-19 12:33:56 +00:00
39 lines
1.1 KiB
PHP
39 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Classes\Modules\Transactions\Services;
|
|
|
|
|
|
use Carbon\Carbon;
|
|
|
|
class GeneratesGroupTransactionBillNumber
|
|
{
|
|
|
|
/** @var ChecksIfGroupTransactionBillNumberExists */
|
|
private $checksIfGroupTransactionBillNumberExists;
|
|
|
|
/**
|
|
* GeneratesGroupTransactionBillNumber constructor.
|
|
* @param ChecksIfGroupTransactionBillNumberExists $checksIfGroupTransactionBillNumberExists
|
|
*/
|
|
public function __construct(ChecksIfGroupTransactionBillNumberExists $checksIfGroupTransactionBillNumberExists)
|
|
{
|
|
$this->checksIfGroupTransactionBillNumberExists = $checksIfGroupTransactionBillNumberExists;
|
|
}
|
|
|
|
/**
|
|
* @param string $prefix
|
|
* @param Carbon|null $date
|
|
* @return string
|
|
*/
|
|
public function execute(string $prefix, ?Carbon $date = null): string {
|
|
if(!$date){
|
|
$date = carbon::now();
|
|
}
|
|
|
|
$billNumber = $prefix.$date->format('Y').$date->format('m').'-'.mt_rand(10000, 99999);
|
|
|
|
return !$this->checksIfGroupTransactionBillNumberExists->execute($billNumber) ? $billNumber : self::execute($prefix);
|
|
|
|
}
|
|
|
|
} |