2020-02-11 21:57:25 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Services\Quote;
|
|
|
|
|
|
|
|
use App\Events\Quote\QuoteWasMarkedSent;
|
|
|
|
use App\Models\Quote;
|
|
|
|
|
|
|
|
class MarkSent
|
|
|
|
{
|
|
|
|
private $client;
|
|
|
|
|
2020-03-10 13:54:20 +01:00
|
|
|
private $quote;
|
|
|
|
|
|
|
|
public function __construct($client, $quote)
|
2020-02-11 21:57:25 +01:00
|
|
|
{
|
|
|
|
$this->client = $client;
|
2020-03-10 13:54:20 +01:00
|
|
|
$this->quote = $quote;
|
2020-02-11 21:57:25 +01:00
|
|
|
}
|
|
|
|
|
2020-03-10 13:54:20 +01:00
|
|
|
public function run()
|
2020-02-11 21:57:25 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
/* Return immediately if status is not draft */
|
2020-03-10 13:54:20 +01:00
|
|
|
if ($this->quote->status_id != Quote::STATUS_DRAFT) {
|
2020-02-11 21:57:25 +01:00
|
|
|
return $quote;
|
|
|
|
}
|
|
|
|
|
2020-03-10 13:54:20 +01:00
|
|
|
$this->quote->markInvitationsSent();
|
2020-02-11 21:57:25 +01:00
|
|
|
|
2020-03-10 13:54:20 +01:00
|
|
|
event(new QuoteWasMarkedSent($this->quote, $this->quote->company));
|
2020-02-11 21:57:25 +01:00
|
|
|
|
2020-03-10 13:54:20 +01:00
|
|
|
$this->quote->service()->setStatus(Quote::STATUS_SENT)->applyNumber()->save();
|
2020-02-11 21:57:25 +01:00
|
|
|
|
2020-03-10 13:54:20 +01:00
|
|
|
return $this->quote;
|
2020-02-11 21:57:25 +01:00
|
|
|
}
|
|
|
|
}
|