1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-11 13:42:49 +01:00
invoiceninja/app/Services/Quote/MarkSent.php

59 lines
1.5 KiB
PHP
Raw Normal View History

<?php
2020-07-01 03:06:40 +02:00
/**
* Invoice Ninja (https://invoiceninja.com).
2020-07-01 03:06:40 +02:00
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
2023-01-28 23:21:40 +01:00
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
2020-07-01 03:06:40 +02:00
*
2021-06-16 08:58:16 +02:00
* @license https://www.elastic.co/licensing/elastic-license
2020-07-01 03:06:40 +02:00
*/
namespace App\Services\Quote;
2023-10-26 04:57:44 +02:00
use App\Events\Quote\QuoteWasMarkedSent;
2023-07-24 02:42:16 +02:00
use App\Models\Client;
2023-10-26 04:57:44 +02:00
use App\Models\Quote;
use App\Models\Webhook;
2023-10-26 04:57:44 +02:00
use App\Utils\Ninja;
use Carbon\Carbon;
class MarkSent
{
2023-07-24 02:42:16 +02:00
public function __construct(private Client $client, private Quote $quote)
{
}
2024-01-03 12:06:52 +01:00
public function run($first_event = false)
{
/* Return immediately if status is not draft */
if ($this->quote->status_id != Quote::STATUS_DRAFT) {
return $this->quote;
}
$this->quote->markInvitationsSent();
2023-07-24 02:42:16 +02:00
if ($this->quote->due_date != '' || $this->client->getSetting('valid_until') == '') {
} else {
2023-07-24 02:42:16 +02:00
$this->quote->due_date = Carbon::parse($this->quote->date)->addDays($this->client->getSetting('valid_until'));
}
$this->quote
->service()
->setStatus(Quote::STATUS_SENT)
->applyNumber()
->save();
2021-12-17 12:11:36 +01:00
event(new QuoteWasMarkedSent($this->quote, $this->quote->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null)));
2024-01-03 12:06:52 +01:00
if($first_event) {
event('eloquent.updated: App\Models\Quote', $this->quote);
$this->quote->sendEvent(Webhook::EVENT_SENT_QUOTE, "client");
}
return $this->quote;
2024-01-14 05:05:00 +01:00
}
}