Akaunting/app/Jobs/Banking/DeleteReconciliation.php

27 lines
699 B
PHP
Raw Normal View History

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\ShouldDelete;
2019-11-16 07:21:14 +00:00
use App\Models\Banking\Transaction;
2021-09-06 08:53:57 +00:00
class DeleteReconciliation extends Job implements ShouldDelete
2019-11-16 07:21:14 +00:00
{
2021-09-06 08:53:57 +00:00
public function handle(): bool
2019-11-16 07:21:14 +00:00
{
2020-06-26 10:40:19 +00:00
\DB::transaction(function () {
2021-09-06 08:53:57 +00:00
$this->model->delete();
2019-11-16 07:21:14 +00:00
2021-09-06 08:53:57 +00:00
Transaction::where('account_id', $this->model->account_id)
2020-08-20 09:55:59 +00:00
->isReconciled()
2021-09-06 08:53:57 +00:00
->whereBetween('paid_at', [$this->model->started_at, $this->model->ended_at])->each(function ($transaction) {
2020-06-26 10:40:19 +00:00
$transaction->reconciled = 0;
$transaction->save();
});
});
2019-11-16 07:21:14 +00:00
return true;
}
}