2020-02-15 10:01:15 +01:00
|
|
|
<?php
|
2020-07-01 03:06:40 +02:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2020-02-15 10:01:15 +01:00
|
|
|
|
|
|
|
namespace App\Services\Credit;
|
|
|
|
|
2020-02-26 22:21:12 +01:00
|
|
|
use App\Models\Credit;
|
2020-02-15 10:01:15 +01:00
|
|
|
use App\Events\Payment\PaymentWasCreated;
|
|
|
|
use App\Factory\PaymentFactory;
|
|
|
|
use App\Jobs\Customer\UpdateCustomerBalance;
|
|
|
|
use App\Jobs\Customer\UpdateCustomerPaidToDate;
|
2020-02-17 10:37:44 +01:00
|
|
|
use App\Models\Client;
|
2020-02-15 10:01:15 +01:00
|
|
|
use App\Models\Invoice;
|
|
|
|
use App\Models\Payment;
|
2020-02-17 10:37:44 +01:00
|
|
|
use App\Services\AbstractService;
|
2020-02-15 10:01:15 +01:00
|
|
|
use App\Services\Customer\CustomerService;
|
|
|
|
use App\Services\Payment\PaymentService;
|
2020-02-17 20:07:31 +01:00
|
|
|
use App\Utils\Traits\GeneratesCounter;
|
2020-02-15 10:01:15 +01:00
|
|
|
|
2020-02-17 10:37:44 +01:00
|
|
|
class ApplyNumber extends AbstractService
|
2020-02-15 10:01:15 +01:00
|
|
|
{
|
|
|
|
use GeneratesCounter;
|
|
|
|
|
2020-02-18 21:56:21 +01:00
|
|
|
private $client;
|
2020-02-15 10:01:15 +01:00
|
|
|
|
2020-02-18 21:56:21 +01:00
|
|
|
private $credit;
|
|
|
|
|
|
|
|
public function __construct(Client $client, Credit $credit)
|
2020-02-15 10:01:15 +01:00
|
|
|
{
|
2020-02-17 10:37:44 +01:00
|
|
|
$this->client = $client;
|
2020-02-18 21:56:21 +01:00
|
|
|
|
|
|
|
$this->credit = $credit;
|
2020-02-15 10:01:15 +01:00
|
|
|
}
|
|
|
|
|
2020-02-18 21:56:21 +01:00
|
|
|
public function run()
|
2020-02-15 10:01:15 +01:00
|
|
|
{
|
2020-02-18 21:56:21 +01:00
|
|
|
if ($this->credit->number != '') {
|
|
|
|
return $this->credit;
|
2020-02-15 10:01:15 +01:00
|
|
|
}
|
|
|
|
|
2020-02-18 21:56:21 +01:00
|
|
|
$this->credit->number = $this->getNextCreditNumber($this->client);
|
2020-02-15 10:01:15 +01:00
|
|
|
|
|
|
|
|
2020-02-18 21:56:21 +01:00
|
|
|
return $this->credit;
|
2020-02-15 10:01:15 +01:00
|
|
|
}
|
|
|
|
}
|