mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-19 04:24:12 +00:00
37 lines
965 B
PHP
37 lines
965 B
PHP
<?php
|
|
|
|
namespace App\Classes\Modules\Transactions\Services;
|
|
|
|
|
|
use Carbon\Carbon;
|
|
|
|
class GeneratesTransactionBillNumber
|
|
{
|
|
|
|
/** @var ChecksIfTransactionBillNumberExists */
|
|
private $checksIfTransactionBillNumberExists;
|
|
|
|
/**
|
|
* GeneratesTransactionBillNo constructor.
|
|
* @param ChecksIfTransactionBillNumberExists $checksIfTransactionBillNumberExists
|
|
*/
|
|
public function __construct(ChecksIfTransactionBillNumberExists $checksIfTransactionBillNumberExists)
|
|
{
|
|
$this->checksIfTransactionBillNumberExists = $checksIfTransactionBillNumberExists;
|
|
}
|
|
|
|
|
|
/**
|
|
* @param string $prefix
|
|
* @return string
|
|
*/
|
|
public function execute(string $prefix): string {
|
|
$date = carbon::now();
|
|
|
|
$billNumber = $prefix.$date->format('Y').$date->format('m').'-'.mt_rand(10000, 99999);
|
|
|
|
return !$this->checksIfTransactionBillNumberExists->execute($billNumber) ? $billNumber : self::execute($prefix);
|
|
|
|
}
|
|
|
|
} |