2019-11-16 07:21:14 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Jobs\Banking;
|
|
|
|
|
|
|
|
|
|
use App\Abstracts\Job;
|
2021-09-06 08:53:57 +00:00
|
|
|
use App\Interfaces\Job\HasOwner;
|
2021-09-07 07:33:34 +00:00
|
|
|
use App\Interfaces\Job\HasSource;
|
2021-09-06 08:53:57 +00:00
|
|
|
use App\Interfaces\Job\ShouldCreate;
|
2019-11-16 07:21:14 +00:00
|
|
|
use App\Models\Banking\Reconciliation;
|
2020-02-18 14:14:06 +00:00
|
|
|
use App\Models\Banking\Transaction;
|
2019-11-16 07:21:14 +00:00
|
|
|
|
2021-09-07 07:33:34 +00:00
|
|
|
class CreateReconciliation extends Job implements HasOwner, HasSource, ShouldCreate
|
2019-11-16 07:21:14 +00:00
|
|
|
{
|
2021-09-06 08:53:57 +00:00
|
|
|
public function handle(): Reconciliation
|
2019-11-16 07:21:14 +00:00
|
|
|
{
|
2020-06-26 10:40:19 +00:00
|
|
|
\DB::transaction(function () {
|
2021-06-17 15:00:26 +00:00
|
|
|
$reconcile = (int) $this->request->get('reconcile');
|
2020-06-26 10:40:19 +00:00
|
|
|
$transactions = $this->request->get('transactions');
|
|
|
|
|
|
2021-06-17 15:00:26 +00:00
|
|
|
$this->request->merge(['reconciled' => $reconcile]);
|
|
|
|
|
|
2021-09-06 08:53:57 +00:00
|
|
|
$this->model = Reconciliation::create($this->request->all());
|
2020-06-26 10:40:19 +00:00
|
|
|
|
2020-08-10 11:15:15 +00:00
|
|
|
if ($reconcile && $transactions) {
|
2020-06-26 10:40:19 +00:00
|
|
|
foreach ($transactions as $key => $value) {
|
|
|
|
|
if (empty($value)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$t = explode('_', $key);
|
|
|
|
|
|
|
|
|
|
$transaction = Transaction::find($t[1]);
|
|
|
|
|
$transaction->reconciled = 1;
|
|
|
|
|
$transaction->save();
|
2020-02-18 14:14:06 +00:00
|
|
|
}
|
2019-11-16 07:21:14 +00:00
|
|
|
}
|
2020-06-26 10:40:19 +00:00
|
|
|
});
|
2019-11-16 07:21:14 +00:00
|
|
|
|
2021-09-06 08:53:57 +00:00
|
|
|
return $this->model;
|
2019-11-16 07:21:14 +00:00
|
|
|
}
|
|
|
|
|
}
|