akaunting/app/Jobs/Document/CreateDocumentHistory.php

47 lines
1.3 KiB
PHP
Raw Normal View History

2020-12-24 01:28:38 +03:00
<?php
namespace App\Jobs\Document;
use App\Abstracts\Job;
2021-09-07 10:33:34 +03:00
use App\Interfaces\Job\HasOwner;
use App\Interfaces\Job\HasSource;
2021-09-06 11:53:57 +03:00
use App\Interfaces\Job\ShouldCreate;
use App\Models\Document\Document;
2020-12-24 01:28:38 +03:00
use App\Models\Document\DocumentHistory;
2021-09-07 10:33:34 +03:00
class CreateDocumentHistory extends Job implements HasOwner, HasSource, ShouldCreate
2020-12-24 01:28:38 +03:00
{
protected $document;
protected $notify;
protected $description;
2021-09-06 11:53:57 +03:00
public function __construct(Document $document, $notify = 0, $description = null)
2020-12-24 01:28:38 +03:00
{
$this->document = $document;
$this->notify = $notify;
$this->description = $description;
2021-09-06 11:53:57 +03:00
parent::__construct($document, $notify, $description);
2020-12-24 01:28:38 +03:00
}
2021-09-06 11:53:57 +03:00
public function handle(): DocumentHistory
2020-12-24 01:28:38 +03:00
{
$description = $this->description ?: trans_choice('general.payments', 1);
$document_history = DocumentHistory::create([
'company_id' => $this->document->company_id,
'type' => $this->document->type,
'document_id' => $this->document->id,
'status' => $this->document->status,
'notify' => $this->notify,
'description' => $description,
2021-09-07 10:33:34 +03:00
'created_from' => source_name(),
'created_by' => user_id(),
2020-12-24 01:28:38 +03:00
]);
return $document_history;
}
}