akaunting/app/Jobs/Document/CancelDocument.php

33 lines
616 B
PHP
Raw Normal View History

2020-12-24 01:28:38 +03:00
<?php
namespace App\Jobs\Document;
use App\Abstracts\Job;
use App\Models\Document\Document;
class CancelDocument extends Job
{
2021-09-06 11:53:57 +03:00
protected $model;
public function __construct(Document $model)
2020-12-24 01:28:38 +03:00
{
2021-09-06 11:53:57 +03:00
$this->model = $model;
parent::__construct($model);
2020-12-24 01:28:38 +03:00
}
2021-09-06 11:53:57 +03:00
public function handle(): Document
2020-12-24 01:28:38 +03:00
{
\DB::transaction(function () {
2021-09-06 11:53:57 +03:00
$this->deleteRelationships($this->model, [
2020-12-24 01:28:38 +03:00
'transactions', 'recurring'
]);
2021-09-06 11:53:57 +03:00
$this->model->status = 'cancelled';
$this->model->save();
2020-12-24 01:28:38 +03:00
});
2021-09-06 11:53:57 +03:00
return $this->model;
2020-12-24 01:28:38 +03:00
}
}