1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-22 01:11:34 +02:00
invoiceninja/app/Services/Credit/MarkSent.php

51 lines
1.1 KiB
PHP
Raw Normal View History

2020-03-03 10:51:05 +01:00
<?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
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
2020-03-03 10:51:05 +01:00
namespace App\Services\Credit;
use App\Events\Credit\CreditWasMarkedSent;
use App\Models\Credit;
2020-07-08 14:02:16 +02:00
use App\Utils\Ninja;
2020-03-03 10:51:05 +01:00
class MarkSent
{
private $client;
private $credit;
public function __construct($client, $credit)
2020-03-03 10:51:05 +01:00
{
$this->client = $client;
$this->credit = $credit;
2020-03-03 10:51:05 +01:00
}
public function run()
2020-03-03 10:51:05 +01:00
{
/* Return immediately if status is not draft */
if ($this->credit->status_id != Credit::STATUS_DRAFT) {
return $this->credit;
2020-03-03 10:51:05 +01:00
}
$this->credit->markInvitationsSent();
2020-03-03 10:51:05 +01:00
2020-07-08 14:02:16 +02:00
event(new CreditWasMarkedSent($this->credit, $this->credit->company, Ninja::eventVars()));
2020-03-03 10:51:05 +01:00
$this->credit
->service()
->setStatus(Credit::STATUS_SENT)
->applyNumber()
->save();
2020-03-03 10:51:05 +01:00
return $this->credit;
2020-03-03 10:51:05 +01:00
}
}