2019-11-16 10:21:14 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Jobs\Banking;
|
|
|
|
|
|
|
|
use App\Abstracts\Job;
|
|
|
|
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
|
|
|
|
|
|
|
class CreateReconciliation extends Job
|
|
|
|
{
|
2020-06-26 13:40:19 +03:00
|
|
|
protected $reconciliation;
|
|
|
|
|
2019-11-16 10:21:14 +03:00
|
|
|
protected $request;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new job instance.
|
|
|
|
*
|
|
|
|
* @param $request
|
|
|
|
*/
|
|
|
|
public function __construct($request)
|
|
|
|
{
|
|
|
|
$this->request = $this->getRequestInstance($request);
|
2021-06-17 10:59:07 +03:00
|
|
|
$this->request->merge(['created_by' => user_id()]);
|
2019-11-16 10:21:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute the job.
|
|
|
|
*
|
|
|
|
* @return Reconciliation
|
|
|
|
*/
|
|
|
|
public function handle()
|
|
|
|
{
|
2020-06-26 13:40:19 +03:00
|
|
|
\DB::transaction(function () {
|
|
|
|
$reconcile = $this->request->get('reconcile');
|
|
|
|
$transactions = $this->request->get('transactions');
|
|
|
|
|
|
|
|
$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,
|
|
|
|
]);
|
|
|
|
|
2020-08-10 14:15:15 +03:00
|
|
|
if ($reconcile && $transactions) {
|
2020-06-26 13:40:19 +03: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 17:14:06 +03:00
|
|
|
}
|
2019-11-16 10:21:14 +03:00
|
|
|
}
|
2020-06-26 13:40:19 +03:00
|
|
|
});
|
2019-11-16 10:21:14 +03:00
|
|
|
|
2020-06-26 13:40:19 +03:00
|
|
|
return $this->reconciliation;
|
2019-11-16 10:21:14 +03:00
|
|
|
}
|
|
|
|
}
|