1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-15 23:52:33 +01:00
invoiceninja/app/Services/Invoice/MarkSent.php

61 lines
1.6 KiB
PHP
Raw Normal View History

<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
*
2021-06-16 08:58:16 +02:00
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Services\Invoice;
2020-08-12 03:45:40 +02:00
use App\Events\Invoice\InvoiceWasUpdated;
2020-07-23 05:55:11 +02:00
use App\Models\Client;
use App\Models\Invoice;
use App\Services\AbstractService;
2020-07-08 14:02:16 +02:00
use App\Utils\Ninja;
class MarkSent extends AbstractService
{
2020-07-23 05:55:11 +02:00
public $client;
2020-07-23 05:55:11 +02:00
public $invoice;
2020-07-23 05:55:11 +02:00
public function __construct(Client $client, Invoice $invoice)
{
$this->client = $client;
$this->invoice = $invoice;
}
public function run()
{
/* Return immediately if status is not draft */
if ($this->invoice->status_id != Invoice::STATUS_DRAFT) {
return $this->invoice;
}
$this->invoice->markInvitationsSent();
$this->invoice
->service()
->setStatus(Invoice::STATUS_SENT)
->applyNumber()
->setDueDate()
2020-11-15 09:24:57 +01:00
->updateBalance($this->invoice->amount)
2021-03-10 03:28:35 +01:00
->deletePdf()
2021-05-26 02:35:39 +02:00
->setReminder()
->save();
$this->client->service()->updateBalance($this->invoice->balance)->save();
2021-01-21 05:42:30 +01:00
$this->invoice->ledger()->updateInvoiceBalance($this->invoice->balance, "Invoice {$this->invoice->number} marked as sent.");
event(new InvoiceWasUpdated($this->invoice, $this->invoice->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null)));
2020-06-06 03:07:31 +02:00
return $this->invoice->fresh();
}
}