2019-11-16 07:21:14 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Jobs\Banking;
|
|
|
|
|
|
|
|
|
|
use App\Abstracts\Job;
|
2023-08-23 08:43:17 +00:00
|
|
|
use App\Events\Banking\TransactionDeleting;
|
|
|
|
|
use App\Events\Banking\TransactionDeleted;
|
2021-09-06 08:53:57 +00:00
|
|
|
use App\Interfaces\Job\ShouldDelete;
|
2019-11-16 07:21:14 +00:00
|
|
|
|
2021-09-06 08:53:57 +00:00
|
|
|
class DeleteTransaction 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
|
|
|
{
|
|
|
|
|
$this->authorize();
|
|
|
|
|
|
2023-08-23 08:43:17 +00:00
|
|
|
event(new TransactionDeleting($this->model));
|
|
|
|
|
|
2020-06-26 10:40:19 +00:00
|
|
|
\DB::transaction(function () {
|
2023-10-03 08:06:08 +00:00
|
|
|
$this->deleteRelationships($this->model, ['recurring', 'taxes']);
|
|
|
|
|
|
2021-09-06 08:53:57 +00:00
|
|
|
$this->model->delete();
|
2020-06-26 10:40:19 +00:00
|
|
|
});
|
2019-11-16 07:21:14 +00:00
|
|
|
|
2023-08-23 08:43:17 +00:00
|
|
|
event(new TransactionDeleted($this->model));
|
|
|
|
|
|
2019-11-16 07:21:14 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Determine if this action is applicable.
|
|
|
|
|
*/
|
2021-09-06 08:53:57 +00:00
|
|
|
public function authorize(): void
|
2019-11-16 07:21:14 +00:00
|
|
|
{
|
2021-09-06 08:53:57 +00:00
|
|
|
if ($this->model->reconciled) {
|
2020-03-13 11:55:50 +00:00
|
|
|
$message = trans('messages.warning.reconciled_tran');
|
|
|
|
|
|
|
|
|
|
throw new \Exception($message);
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-20 22:07:55 +00:00
|
|
|
if ($this->model->isTransferTransaction()) {
|
2019-11-16 07:21:14 +00:00
|
|
|
throw new \Exception('Unauthorized');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|