2020-03-03 10:51:05 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Services\Credit;
|
|
|
|
|
|
|
|
use App\Events\Credit\CreditWasMarkedSent;
|
|
|
|
use App\Models\Credit;
|
|
|
|
|
|
|
|
class MarkSent
|
|
|
|
{
|
|
|
|
private $client;
|
|
|
|
|
2020-03-04 00:51:50 +01:00
|
|
|
private $credit;
|
|
|
|
|
|
|
|
public function __construct($client, $credit)
|
2020-03-03 10:51:05 +01:00
|
|
|
{
|
|
|
|
$this->client = $client;
|
2020-03-04 00:51:50 +01:00
|
|
|
$this->credit = $credit;
|
2020-03-03 10:51:05 +01:00
|
|
|
}
|
|
|
|
|
2020-03-04 00:51:50 +01:00
|
|
|
public function run()
|
2020-03-03 10:51:05 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
/* Return immediately if status is not draft */
|
2020-03-04 00:51:50 +01:00
|
|
|
if ($this->credit->status_id != Credit::STATUS_DRAFT) {
|
|
|
|
return $this->credit;
|
2020-03-03 10:51:05 +01:00
|
|
|
}
|
|
|
|
|
2020-03-04 00:51:50 +01:00
|
|
|
$this->credit->markInvitationsSent();
|
2020-03-03 10:51:05 +01:00
|
|
|
|
2020-03-04 00:51:50 +01:00
|
|
|
event(new CreditWasMarkedSent($this->credit, $this->credit->company));
|
2020-03-03 10:51:05 +01:00
|
|
|
|
2020-05-19 00:22:18 +02:00
|
|
|
$this->credit
|
|
|
|
->service()
|
|
|
|
->setStatus(Credit::STATUS_SENT)
|
|
|
|
->applyNumber()
|
|
|
|
->save();
|
2020-03-03 10:51:05 +01:00
|
|
|
|
2020-03-04 00:51:50 +01:00
|
|
|
return $this->credit;
|
2020-03-03 10:51:05 +01:00
|
|
|
}
|
|
|
|
}
|