2020-02-15 10:01:15 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Services\Credit;
|
|
|
|
|
|
|
|
use App\Credit;
|
|
|
|
use App\Events\Payment\PaymentWasCreated;
|
|
|
|
use App\Factory\PaymentFactory;
|
2020-02-17 10:37:44 +01:00
|
|
|
use App\Jobs\Company\UpdateCompanyLedgerWithPayment;
|
2020-02-15 10:01:15 +01:00
|
|
|
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;
|
|
|
|
|
|
|
|
private $customer;
|
|
|
|
|
2020-02-17 10:37:44 +01:00
|
|
|
public function __construct(Client $client)
|
2020-02-15 10:01:15 +01:00
|
|
|
{
|
2020-02-17 10:37:44 +01:00
|
|
|
$this->client = $client;
|
2020-02-15 10:01:15 +01:00
|
|
|
}
|
|
|
|
|
2020-02-17 10:37:44 +01:00
|
|
|
public function run($credit)
|
2020-02-15 10:01:15 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
if ($credit->number != '') {
|
|
|
|
return $credit;
|
|
|
|
}
|
|
|
|
|
2020-02-17 10:37:44 +01:00
|
|
|
$credit->number = $this->getNextCreditNumber($this->client);
|
2020-02-15 10:01:15 +01:00
|
|
|
|
|
|
|
|
|
|
|
return $credit;
|
|
|
|
}
|
|
|
|
}
|