added db transaction to jobs
This commit is contained in:
@ -8,6 +8,8 @@ use App\Models\Banking\Transaction;
|
||||
|
||||
class CreateReconciliation extends Job
|
||||
{
|
||||
protected $reconciliation;
|
||||
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
@ -27,32 +29,34 @@ class CreateReconciliation extends Job
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$reconcile = $this->request->get('reconcile');
|
||||
$transactions = $this->request->get('transactions');
|
||||
\DB::transaction(function () {
|
||||
$reconcile = $this->request->get('reconcile');
|
||||
$transactions = $this->request->get('transactions');
|
||||
|
||||
$reconciliation = Reconciliation::create([
|
||||
'company_id' => $this->request['company_id'],
|
||||
'account_id' => $this->request->get('account_id'),
|
||||
'started_at' => $this->request->get('started_at'),
|
||||
'ended_at' => $this->request->get('ended_at'),
|
||||
'closing_balance' => $this->request->get('closing_balance'),
|
||||
'reconciled' => $reconcile ? 1 : 0,
|
||||
]);
|
||||
$this->reconciliation = Reconciliation::create([
|
||||
'company_id' => $this->request['company_id'],
|
||||
'account_id' => $this->request->get('account_id'),
|
||||
'started_at' => $this->request->get('started_at'),
|
||||
'ended_at' => $this->request->get('ended_at'),
|
||||
'closing_balance' => $this->request->get('closing_balance'),
|
||||
'reconciled' => $reconcile ? 1 : 0,
|
||||
]);
|
||||
|
||||
if ($transactions) {
|
||||
foreach ($transactions as $key => $value) {
|
||||
if (empty($value)) {
|
||||
continue;
|
||||
if ($transactions) {
|
||||
foreach ($transactions as $key => $value) {
|
||||
if (empty($value)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$t = explode('_', $key);
|
||||
|
||||
$transaction = Transaction::find($t[1]);
|
||||
$transaction->reconciled = 1;
|
||||
$transaction->save();
|
||||
}
|
||||
|
||||
$t = explode('_', $key);
|
||||
|
||||
$transaction = Transaction::find($t[1]);
|
||||
$transaction->reconciled = 1;
|
||||
$transaction->save();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return $reconciliation;
|
||||
return $this->reconciliation;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user