2019-11-16 10:21:14 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Jobs\Banking;
|
|
|
|
|
|
|
|
use App\Abstracts\Job;
|
2021-09-06 11:53:57 +03:00
|
|
|
use App\Interfaces\Job\ShouldUpdate;
|
2019-11-16 10:21:14 +03:00
|
|
|
use App\Models\Banking\Reconciliation;
|
2020-02-18 17:14:06 +03:00
|
|
|
use App\Models\Banking\Transaction;
|
2019-11-16 10:21:14 +03:00
|
|
|
|
2021-09-06 11:53:57 +03:00
|
|
|
class UpdateReconciliation extends Job implements ShouldUpdate
|
2019-11-16 10:21:14 +03:00
|
|
|
{
|
2021-09-06 11:53:57 +03:00
|
|
|
public function handle(): Reconciliation
|
2019-11-16 10:21:14 +03:00
|
|
|
{
|
2020-06-26 13:40:19 +03:00
|
|
|
\DB::transaction(function () {
|
2021-06-17 18:00:26 +03:00
|
|
|
$reconcile = (int) $this->request->get('reconcile');
|
2020-06-26 13:40:19 +03:00
|
|
|
$transactions = $this->request->get('transactions');
|
2019-11-16 10:21:14 +03:00
|
|
|
|
2022-09-05 15:58:36 +03:00
|
|
|
$this->model->transactions = $transactions;
|
2021-09-06 11:53:57 +03:00
|
|
|
$this->model->reconciled = $reconcile;
|
|
|
|
$this->model->save();
|
2019-11-16 10:21:14 +03:00
|
|
|
|
2020-06-26 13:40:19 +03:00
|
|
|
if ($transactions) {
|
|
|
|
foreach ($transactions as $key => $value) {
|
2022-09-05 17:03:29 +03:00
|
|
|
$transaction_reconcile = $reconcile;
|
|
|
|
|
|
|
|
if (empty($value) || $value === 'false') {
|
|
|
|
$transaction_reconcile = 0;
|
2020-06-26 13:40:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
$t = explode('_', $key);
|
2019-11-16 10:21:14 +03:00
|
|
|
|
2020-06-26 13:40:19 +03:00
|
|
|
$transaction = Transaction::find($t[1]);
|
2022-09-05 17:03:29 +03:00
|
|
|
$transaction->reconciled = $transaction_reconcile;
|
2020-06-26 13:40:19 +03:00
|
|
|
$transaction->save();
|
|
|
|
}
|
2019-11-16 10:21:14 +03:00
|
|
|
}
|
2020-06-26 13:40:19 +03:00
|
|
|
});
|
2019-11-16 10:21:14 +03:00
|
|
|
|
2021-09-06 11:53:57 +03:00
|
|
|
return $this->model;
|
2019-11-16 10:21:14 +03:00
|
|
|
}
|
|
|
|
}
|