2020-02-11 20:57:25 +00:00
|
|
|
<?php
|
2020-07-01 11:06:40 +10:00
|
|
|
/**
|
2020-09-06 19:38:10 +10:00
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
2020-07-01 11:06:40 +10:00
|
|
|
*
|
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
|
*
|
2021-01-04 08:54:54 +11:00
|
|
|
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
2020-07-01 11:06:40 +10:00
|
|
|
*
|
2021-06-16 16:58:16 +10:00
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
2020-07-01 11:06:40 +10:00
|
|
|
*/
|
|
|
|
|
|
2020-02-11 20:57:25 +00:00
|
|
|
namespace App\Services\Quote;
|
|
|
|
|
|
|
|
|
|
use App\Events\Quote\QuoteWasMarkedSent;
|
|
|
|
|
use App\Models\Quote;
|
2020-07-08 22:02:16 +10:00
|
|
|
use App\Utils\Ninja;
|
2021-04-01 19:07:32 +11:00
|
|
|
use Carbon\Carbon;
|
2020-02-11 20:57:25 +00:00
|
|
|
|
|
|
|
|
class MarkSent
|
|
|
|
|
{
|
|
|
|
|
private $client;
|
|
|
|
|
|
2020-03-10 23:54:20 +11:00
|
|
|
private $quote;
|
|
|
|
|
|
|
|
|
|
public function __construct($client, $quote)
|
2020-02-11 20:57:25 +00:00
|
|
|
{
|
|
|
|
|
$this->client = $client;
|
2020-03-10 23:54:20 +11:00
|
|
|
$this->quote = $quote;
|
2020-02-11 20:57:25 +00:00
|
|
|
}
|
|
|
|
|
|
2020-03-10 23:54:20 +11:00
|
|
|
public function run()
|
2020-02-11 20:57:25 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
|
|
/* Return immediately if status is not draft */
|
2020-03-10 23:54:20 +11:00
|
|
|
if ($this->quote->status_id != Quote::STATUS_DRAFT) {
|
2020-04-16 18:41:25 +10:00
|
|
|
return $this->quote;
|
2020-02-11 20:57:25 +00:00
|
|
|
}
|
|
|
|
|
|
2020-03-10 23:54:20 +11:00
|
|
|
$this->quote->markInvitationsSent();
|
2020-02-11 20:57:25 +00:00
|
|
|
|
2021-04-01 19:07:32 +11:00
|
|
|
if ($this->quote->due_date != '' || $this->quote->client->getSetting('valid_until') == '') {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
$this->quote->due_date = Carbon::parse($this->quote->date)->addDays($this->quote->client->getSetting('valid_until'));
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-13 09:52:17 +10:00
|
|
|
event(new QuoteWasMarkedSent($this->quote, $this->quote->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null)));
|
2020-02-11 20:57:25 +00:00
|
|
|
|
2020-05-19 08:22:18 +10:00
|
|
|
$this->quote
|
|
|
|
|
->service()
|
|
|
|
|
->setStatus(Quote::STATUS_SENT)
|
|
|
|
|
->applyNumber()
|
2021-03-10 21:00:18 +11:00
|
|
|
->deletePdf()
|
2020-05-19 08:22:18 +10:00
|
|
|
->save();
|
2020-02-11 20:57:25 +00:00
|
|
|
|
2020-03-10 23:54:20 +11:00
|
|
|
return $this->quote;
|
2020-02-11 20:57:25 +00:00
|
|
|
}
|
|
|
|
|
}
|