mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 21:22:58 +01:00
7dd6f814ac
* Change '__invoke' to 'run' for Invoice services * Change '__invoke' to 'run' for Quote services
52 lines
1.2 KiB
PHP
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;
|
|
|
|
}
|
|
}
|