1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 21:22:58 +01:00
invoiceninja/app/Services/Invoice/MarkSent.php
Benjamin Beganović 7dd6f814ac
Change 'Quote' & 'Invoice' service implementation (#3327)
* Change '__invoke' to 'run' for Invoice services

*  Change '__invoke' to 'run' for Quote services
2020-02-14 14:32:22 +11:00

52 lines
1.2 KiB
PHP

<?php
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Services\Invoice;
use App\Events\Invoice\InvoiceWasMarkedSent;
use App\Jobs\Company\UpdateCompanyLedgerWithInvoice;
use App\Models\Invoice;
class MarkSent
{
private $client;
public function __construct($client)
{
$this->client = $client;
}
public function run($invoice)
{
/* Return immediately if status is not draft */
if ($invoice->status_id != Invoice::STATUS_DRAFT) {
return $invoice;
}
$invoice->markInvitationsSent();
$invoice->setReminder();
event(new InvoiceWasMarkedSent($invoice, $invoice->company));
$this->client->service()->updateBalance($invoice->balance)->save();
$invoice->service()->setStatus(Invoice::STATUS_SENT)->applyNumber()->save();
UpdateCompanyLedgerWithInvoice::dispatchNow($invoice, $invoice->balance, $invoice->company);
return $invoice;
}
}