2020-02-03 11:33:07 +01:00
|
|
|
<?php
|
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
2020-02-03 11:33:07 +01:00
|
|
|
*
|
|
|
|
* @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;
|
|
|
|
|
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;
|
2020-02-03 11:33:07 +01:00
|
|
|
use App\Models\Invoice;
|
2020-02-17 10:37:44 +01:00
|
|
|
use App\Services\AbstractService;
|
2020-07-08 14:02:16 +02:00
|
|
|
use App\Utils\Ninja;
|
2020-02-03 11:33:07 +01:00
|
|
|
|
2020-02-17 10:37:44 +01:00
|
|
|
class MarkSent extends AbstractService
|
2020-02-03 11:33:07 +01:00
|
|
|
{
|
2020-07-23 05:55:11 +02:00
|
|
|
public $client;
|
2020-02-03 11:33:07 +01:00
|
|
|
|
2020-07-23 05:55:11 +02:00
|
|
|
public $invoice;
|
2020-02-17 10:37:44 +01:00
|
|
|
|
2020-07-23 05:55:11 +02:00
|
|
|
public function __construct(Client $client, Invoice $invoice)
|
2020-02-03 11:33:07 +01:00
|
|
|
{
|
|
|
|
$this->client = $client;
|
2020-02-17 10:37:44 +01:00
|
|
|
$this->invoice = $invoice;
|
2020-02-03 11:33:07 +01:00
|
|
|
}
|
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
public function run()
|
|
|
|
{
|
2020-02-03 11:33:07 +01:00
|
|
|
|
|
|
|
/* Return immediately if status is not draft */
|
2020-02-17 10:37:44 +01:00
|
|
|
if ($this->invoice->status_id != Invoice::STATUS_DRAFT) {
|
|
|
|
return $this->invoice;
|
2020-02-03 11:33:07 +01:00
|
|
|
}
|
|
|
|
|
2020-12-13 01:04:56 +01:00
|
|
|
info("in mark sent");
|
|
|
|
info($this->invoice->balance);
|
|
|
|
|
2020-02-17 10:37:44 +01:00
|
|
|
$this->invoice->markInvitationsSent();
|
2020-02-03 11:33:07 +01:00
|
|
|
|
2020-02-17 10:37:44 +01:00
|
|
|
$this->invoice->setReminder();
|
2020-02-03 11:33:07 +01:00
|
|
|
|
2020-04-15 02:30:52 +02:00
|
|
|
$this->invoice
|
|
|
|
->service()
|
|
|
|
->setStatus(Invoice::STATUS_SENT)
|
|
|
|
->applyNumber()
|
2020-05-28 06:18:34 +02:00
|
|
|
->setDueDate()
|
2020-11-15 09:24:57 +01:00
|
|
|
->updateBalance($this->invoice->amount)
|
2020-04-15 02:30:52 +02:00
|
|
|
->save();
|
2020-02-03 11:33:07 +01:00
|
|
|
|
2020-12-13 01:04:56 +01:00
|
|
|
info($this->invoice->balance);
|
|
|
|
|
2020-02-26 04:26:07 +01:00
|
|
|
$this->client->service()->updateBalance($this->invoice->balance)->save();
|
|
|
|
|
2020-12-13 01:04:56 +01:00
|
|
|
info($this->client->balance);
|
|
|
|
|
2020-02-20 22:05:01 +01:00
|
|
|
$this->invoice->ledger()->updateInvoiceBalance($this->invoice->balance);
|
|
|
|
|
2020-08-12 03:45:40 +02:00
|
|
|
event(new InvoiceWasUpdated($this->invoice, $this->invoice->company, Ninja::eventVars()));
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2020-06-06 03:07:31 +02:00
|
|
|
return $this->invoice->fresh();
|
2020-03-21 06:37:30 +01:00
|
|
|
}
|
2020-02-03 11:33:07 +01:00
|
|
|
}
|