akaunting/app/Jobs/Banking/DeleteTransaction.php
2021-09-06 11:53:57 +03:00

39 lines
830 B
PHP

<?php
namespace App\Jobs\Banking;
use App\Abstracts\Job;
use App\Interfaces\Job\ShouldDelete;
use App\Models\Setting\Category;
class DeleteTransaction extends Job implements ShouldDelete
{
public function handle(): bool
{
$this->authorize();
\DB::transaction(function () {
$this->model->recurring()->delete();
$this->model->delete();
});
return true;
}
/**
* Determine if this action is applicable.
*/
public function authorize(): void
{
if ($this->model->reconciled) {
$message = trans('messages.warning.reconciled_tran');
throw new \Exception($message);
}
if ($this->model->category->id == Category::transfer()) {
throw new \Exception('Unauthorized');
}
}
}