Merge pull request #2946 from EnesSacid-Buker/master
Exists transaction number issue
This commit is contained in:
commit
ccbaa9a50b
@ -5,19 +5,24 @@ namespace App\Jobs\Banking;
|
||||
use App\Abstracts\Job;
|
||||
use App\Interfaces\Job\ShouldUpdate;
|
||||
use App\Models\Document\Document;
|
||||
use App\Traits\Transactions;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class SplitTransaction extends Job implements ShouldUpdate
|
||||
{
|
||||
use Transactions;
|
||||
|
||||
public function handle(): array
|
||||
{
|
||||
$this->checkAmount();
|
||||
|
||||
\DB::transaction(function () {
|
||||
DB::transaction(function () {
|
||||
foreach ($this->request->items as $item) {
|
||||
$transaction = $this->model->duplicate();
|
||||
$transaction->split_id = $this->model->id;
|
||||
$transaction->amount = $item['amount'];
|
||||
$transaction = $this->model->duplicate();
|
||||
$transaction->number = $this->getNextTransactionNumber();
|
||||
$transaction->split_id = $this->model->id;
|
||||
$transaction->amount = $item['amount'];
|
||||
$transaction->save();
|
||||
|
||||
$item['split'] = $transaction;
|
||||
@ -58,7 +63,10 @@ class SplitTransaction extends Job implements ShouldUpdate
|
||||
if ($compare !== 0) {
|
||||
$error_amount = $this->model->amount;
|
||||
|
||||
$message = trans('messages.error.same_amount', ['transaction' => ucfirst(trans_choice('general.' . Str::plural($this->model->type), 1)), 'amount' => money($error_amount, $this->model->currency_code, true)]);
|
||||
$message = trans('messages.error.same_amount', [
|
||||
'transaction' => ucfirst(trans_choice('general.' . Str::plural($this->model->type), 1)),
|
||||
'amount' => money($error_amount, $this->model->currency_code, true)
|
||||
]);
|
||||
|
||||
throw new \Exception($message);
|
||||
}
|
||||
|
@ -234,7 +234,23 @@ trait Transactions
|
||||
$next = setting('transaction' . $suffix . '.number_next');
|
||||
$digit = setting('transaction' . $suffix . '.number_digit');
|
||||
|
||||
return $prefix . str_pad($next, $digit, '0', STR_PAD_LEFT);
|
||||
$get_number = fn($prefix, $next, $digit) => $prefix . str_pad($next, $digit, '0', STR_PAD_LEFT);
|
||||
$number_exists = fn($number) => Transaction::where('number', $number)->exists();
|
||||
|
||||
$transaction_number = $get_number($prefix, $next, $digit);
|
||||
|
||||
if ($number_exists($transaction_number)) {
|
||||
do {
|
||||
$next++;
|
||||
|
||||
$transaction_number = $get_number($prefix, $next, $digit);
|
||||
} while ($number_exists($transaction_number));
|
||||
|
||||
setting(['transaction' . $suffix . '.number_next' => $next]);
|
||||
setting()->save();
|
||||
}
|
||||
|
||||
return $transaction_number;
|
||||
}
|
||||
|
||||
public function increaseNextTransactionNumber($suffix = ''): void
|
||||
|
Loading…
x
Reference in New Issue
Block a user