diff --git a/app/Services/Credit/ApplyNumber.php b/app/Services/Credit/ApplyNumber.php index ba4e0fa4d820..3e9753aa6c6f 100644 --- a/app/Services/Credit/ApplyNumber.php +++ b/app/Services/Credit/ApplyNumber.php @@ -20,23 +20,27 @@ class ApplyNumber extends AbstractService { use GeneratesCounter; - private $customer; + private $client; - public function __construct(Client $client) + private $credit; + + public function __construct(Client $client, Credit $credit) { $this->client = $client; + + $this->credit = $credit; } - public function run($credit) + public function run() { - if ($credit->number != '') { - return $credit; + if ($this->credit->number != '') { + return $this->credit; } - $credit->number = $this->getNextCreditNumber($this->client); + $this->credit->number = $this->getNextCreditNumber($this->client); - return $credit; + return $this->credit; } } diff --git a/app/Services/Credit/CreateInvitations.php b/app/Services/Credit/CreateInvitations.php index 56b7249523d5..1504a4b765ce 100644 --- a/app/Services/Credit/CreateInvitations.php +++ b/app/Services/Credit/CreateInvitations.php @@ -1,31 +1,35 @@ credit = $credit; } - public function run($credit) + public function run() { - $contacts = $credit->client->contacts; + $contacts = $this->credit->client->contacts; - $contacts->each(function ($contact) use($credit){ - $invitation = CreditInvitation::whereCompanyId($credit->account_id) + $contacts->each(function ($contact){ + $invitation = CreditInvitation::whereCompanyId($this->credit->company_id) ->whereClientContactId($contact->id) - ->whereCreditId($credit->id) + ->whereCreditId($this->credit->id) ->first(); if (!$invitation) { - $ii = CreditInvitationFactory::create($credit->company_id, $credit->user_id); - $ii->credit_id = $credit->id; + $ii = CreditInvitationFactory::create($this->credit->company_id, $this->credit->user_id); + $ii->credit_id = $this->credit->id; $ii->client_contact_id = $contact->id; $ii->save(); } elseif ($invitation && !$contact->send_email) { diff --git a/app/Services/Credit/CreditService.php b/app/Services/Credit/CreditService.php index 5f783238bc72..5a3a2a6ccc6e 100644 --- a/app/Services/Credit/CreditService.php +++ b/app/Services/Credit/CreditService.php @@ -16,9 +16,7 @@ class CreditService public function getCreditPdf($contact) { - $get_invoice_pdf = new GetCreditPdf(); - - return $get_invoice_pdf($this->credit, $contact); + return (new GetCreditPdf($this->credit, $contact))->run(); } /** @@ -27,18 +25,14 @@ class CreditService */ public function applyNumber() { - $apply_number = new ApplyNumber($this->credit->customer); - - $this->credit = $apply_number($this->credit); + $this->credit = (new ApplyNumber($this->credit->client, $this->credit))->run(); return $this; } public function createInvitations() { - $create_invitation = new CreateInvitations(); - - $this->invoice = $create_invitation($this->invoice); + $this->credit = (new CreateInvitations($this->credit))->run(); return $this; } diff --git a/app/Services/Credit/GetCreditPdf.php b/app/Services/Credit/GetCreditPdf.php index 9d3c11a58f40..ee0f66cee043 100644 --- a/app/Services/Credit/GetCreditPdf.php +++ b/app/Services/Credit/GetCreditPdf.php @@ -9,23 +9,29 @@ use Illuminate\Support\Facades\Storage; class GetCreditPdf extends AbstractService { - public function __construct() + private $credit; + + private $contact; + + public function __construct(Credit $credit, ClientContact $contact = null) { + $this->credit = $credit; + $this->contact = $contact; } - public function __invoke($credit, $contact = null) + public function run() { - if (!$contact) { - $contact = $credit->client->primary_contact()->first(); + if (!$this->contact) { + $this->contact = $this->credit->client->primary_contact()->first(); } - $path = 'public/' . $credit->client->id . '/credits/'; - $file_path = $path . $credit->number . '.pdf'; + $path = 'public/' . $this->credit->client->id . '/credits/'; + $file_path = $path . $this->credit->number . '.pdf'; $disk = config('filesystems.default'); $file = Storage::disk($disk)->exists($file_path); if (!$file) { - $file_path = CreateInvoicePdf::dispatchNow($this, $credit->company, $contact); + $file_path = CreateInvoicePdf::dispatchNow($this->credit, $this->credit->company, $this->contact); } return Storage::disk($disk)->url($file_path); diff --git a/tests/MockAccountData.php b/tests/MockAccountData.php index fba5d66133ca..1bd28eca6fe5 100644 --- a/tests/MockAccountData.php +++ b/tests/MockAccountData.php @@ -97,7 +97,6 @@ trait MockAccountData $settings = CompanySettings::defaults(); - $settings->name = 'The Best Company Name'; $settings->company_logo = 'https://www.invoiceninja.com/wp-content/uploads/2019/01/InvoiceNinja-Logo-Round-300x300.png'; $settings->website = 'www.invoiceninja.com'; $settings->address1 = 'Address 1';