From cda534e99652045ab102f5f38c39e51f65e42c57 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 4 Feb 2020 18:51:44 +1100 Subject: [PATCH] Explicitly call the service() method, rather than obfuscate. (#3281) * Include fix as describe by @michael-hampton here #3280 * Refactor createinvitations away from jobs * Clean up * Fixes for service() refactoring * Fixes for services refactor --- app/Console/Commands/CreateTestData.php | 3 +- app/Http/Controllers/InvoiceController.php | 2 +- app/Jobs/Credit/MarkCreditPaid.php | 81 ------------------- app/Jobs/Credit/StoreCredit.php | 10 +-- app/Jobs/Invoice/ApplyPaymentToInvoice.php | 2 +- app/Jobs/Invoice/CreateInvoiceInvitations.php | 67 --------------- app/Jobs/Invoice/UpdateInvoicePayment.php | 2 +- app/Models/Invoice.php | 50 ------------ app/Repositories/InvoiceRepository.php | 7 +- app/Repositories/PaymentRepository.php | 2 +- app/Services/Invoice/ApplyPayment.php | 10 +-- app/Services/Invoice/CreateInvitations.php | 49 +++++++++++ app/Services/Invoice/InvoiceService.php | 14 +++- app/Services/Invoice/MarkPaid.php | 5 +- app/Services/Invoice/MarkSent.php | 2 +- app/Utils/Traits/Payment/Refundable.php | 6 +- tests/Feature/InvitationTest.php | 1 - tests/Feature/PaymentTest.php | 28 +++---- tests/Integration/CheckRemindersTest.php | 13 ++- tests/Integration/MarkInvoicePaidTest.php | 2 +- tests/Integration/UpdateCompanyLedgerTest.php | 2 +- tests/MockAccountData.php | 3 +- 22 files changed, 106 insertions(+), 255 deletions(-) delete mode 100644 app/Jobs/Credit/MarkCreditPaid.php delete mode 100644 app/Jobs/Invoice/CreateInvoiceInvitations.php create mode 100644 app/Services/Invoice/CreateInvitations.php diff --git a/app/Console/Commands/CreateTestData.php b/app/Console/Commands/CreateTestData.php index bcec391cfa00..7eec8f6d7641 100644 --- a/app/Console/Commands/CreateTestData.php +++ b/app/Console/Commands/CreateTestData.php @@ -12,7 +12,6 @@ use App\Factory\PaymentFactory; use App\Factory\QuoteFactory; use App\Helpers\Invoice\InvoiceSum; use App\Jobs\Company\UpdateCompanyLedgerWithInvoice; -use App\Jobs\Invoice\CreateInvoiceInvitations; use App\Jobs\Invoice\UpdateInvoicePayment; use App\Jobs\Quote\CreateQuoteInvitations; use App\Listeners\Credit\CreateCreditInvitation; @@ -464,7 +463,7 @@ class CreateTestData extends Command $this->invoice_repo->markSent($invoice); - CreateInvoiceInvitations::dispatch($invoice, $invoice->company); + $invoice->service()->createInvitations(); if (rand(0, 1)) { $payment = PaymentFactory::create($client->company->id, $client->user->id); diff --git a/app/Http/Controllers/InvoiceController.php b/app/Http/Controllers/InvoiceController.php index afc7e7f5342f..e51ba98cf552 100644 --- a/app/Http/Controllers/InvoiceController.php +++ b/app/Http/Controllers/InvoiceController.php @@ -618,7 +618,7 @@ class InvoiceController extends BaseController return $this->errorResponse(['message' => 'Invoice cannot be marked as paid'], 400); } - $invoice = $invoice->markPaid(); + $invoice = $invoice->service()->markPaid(); if (!$bulk) { return $this->itemResponse($invoice); diff --git a/app/Jobs/Credit/MarkCreditPaid.php b/app/Jobs/Credit/MarkCreditPaid.php deleted file mode 100644 index 00f3ba7b4518..000000000000 --- a/app/Jobs/Credit/MarkCreditPaid.php +++ /dev/null @@ -1,81 +0,0 @@ -credit = $credit; - $this->company = $company; - } - - /** - * Execute the job. - * - * - * @return void - */ - public function handle() - { - MultiDB::setDB($this->company->db); - - if($this->credit->status_id == Credit::STATUS_DRAFT) - $this->credit->markSent(); - - /* Create Payment */ - $payment = PaymentFactory::create($this->credit->company_id, $this->credit->user_id); - - $payment->amount = $this->credit->balance; - $payment->status_id = Credit::STATUS_COMPLETED; - $payment->client_id = $this->credit->client_id; - $payment->transaction_reference = ctrans('texts.manual_entry'); - /* Create a payment relationship to the invoice entity */ - $payment->save(); - - $payment->credits()->attach($this->credit->id, [ - 'amount' => $payment->amount - ]); - - $this->credit->updateBalance($payment->amount*-1); - - /* Update Credit balance */ - event(new PaymentWasCreated($payment, $payment->company)); - - // UpdateCompanyLedgerWithPayment::dispatchNow($payment, ($payment->amount*-1), $this->company); - - return $this->credit; - } -} diff --git a/app/Jobs/Credit/StoreCredit.php b/app/Jobs/Credit/StoreCredit.php index 87ae46e33d98..0fb0a0442b25 100644 --- a/app/Jobs/Credit/StoreCredit.php +++ b/app/Jobs/Credit/StoreCredit.php @@ -44,13 +44,13 @@ class StoreCredit implements ShouldQueue */ public function handle(CreditRepository $credit_repository): ?Credit { - MultiDB::setDB($this->company->db); + // MultiDB::setDB($this->company->db); - $payment = false; + // $payment = false; - if ($payment) { - PaymentNotification::dispatch($payment, $payment->company); - } + // if ($payment) { + // PaymentNotification::dispatch($payment, $payment->company); + // } return $this->credit; } diff --git a/app/Jobs/Invoice/ApplyPaymentToInvoice.php b/app/Jobs/Invoice/ApplyPaymentToInvoice.php index d5f5094cd432..5cb03fe495e8 100644 --- a/app/Jobs/Invoice/ApplyPaymentToInvoice.php +++ b/app/Jobs/Invoice/ApplyPaymentToInvoice.php @@ -113,7 +113,7 @@ class ApplyPaymentToInvoice implements ShouldQueue $this->invoice->save(); - $this->invoice = $this->invoice->applyNumber()->save(); + $this->invoice = $this->invoice->service()->applyNumber()->save(); return $this->invoice; } diff --git a/app/Jobs/Invoice/CreateInvoiceInvitations.php b/app/Jobs/Invoice/CreateInvoiceInvitations.php deleted file mode 100644 index 87931d3131ff..000000000000 --- a/app/Jobs/Invoice/CreateInvoiceInvitations.php +++ /dev/null @@ -1,67 +0,0 @@ -invoice = $invoice; - $this->company = $company; - } - - public function handle() - { - MultiDB::setDB($this->company->db); - - $contacts = $this->invoice->client->contacts; - - $contacts->each(function ($contact) { - $invitation = InvoiceInvitation::whereCompanyId($this->invoice->company_id) - ->whereClientContactId($contact->id) - ->whereInvoiceId($this->invoice->id) - ->first(); - - if (!$invitation && $contact->send_invoice) { - $ii = InvoiceInvitationFactory::create($this->invoice->company_id, $this->invoice->user_id); - $ii->invoice_id = $this->invoice->id; - $ii->client_contact_id = $contact->id; - $ii->save(); - } elseif ($invitation && !$contact->send_invoice) { - $invitation->delete(); - } - }); - } -} diff --git a/app/Jobs/Invoice/UpdateInvoicePayment.php b/app/Jobs/Invoice/UpdateInvoicePayment.php index b932a1389788..6829e91689af 100644 --- a/app/Jobs/Invoice/UpdateInvoicePayment.php +++ b/app/Jobs/Invoice/UpdateInvoicePayment.php @@ -103,7 +103,7 @@ class UpdateInvoicePayment implements ShouldQueue $invoice->pivot->amount = $invoice->partial; $invoice->pivot->save(); - $invoice->updateBalance($invoice->partial*-1) + $invoice->service()->updateBalance($invoice->partial*-1) ->clearPartial() ->setDueDate() ->setStatus(Invoice::STATUS_PARTIAL) diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index 79a35cb59420..1a44dbce4cf5 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -168,56 +168,6 @@ class Invoice extends BaseModel return new InvoiceService($this); } - public function markPaid() :InvoiceService - { - return $this->service()->markPaid(); - } - - public function applyNumber() :InvoiceService - { - return $this->service()->applyNumber(); - } - - public function applyPayment($payment, $payment_amount) :InvoiceService - { - return $this->service()->applyPayment($payment, $payment_amount); - } - - public function updateBalance($balance_adjustment) :InvoiceService - { - return $this->service()->updateBalance($balance_adjustment); - } - - public function setDueDate() :InvoiceService - { - return $this->service->setDueDate(); - } - - public function setStatus($status) :InvoiceService - { - return $this->service()->setStatus($status); - } - - public function clearPartial() :InvoiceService - { - return $this->service()->clearPartial(); - } - - public function updatePartial($amount) :InvoiceService - { - return $this->service()->updatePartial($amount); - } - - public function markSent() :InvoiceService - { - return $this->service()->markSent(); - } - - public function markViewed() :InvoiceService - { - return $this->service()->markViewed(); - } - /* ---------------- */ /* Settings getters */ /* ---------------- */ diff --git a/app/Repositories/InvoiceRepository.php b/app/Repositories/InvoiceRepository.php index 3fc1aef11763..ee7079651a61 100644 --- a/app/Repositories/InvoiceRepository.php +++ b/app/Repositories/InvoiceRepository.php @@ -16,7 +16,6 @@ use App\Events\Invoice\InvoiceWasUpdated; use App\Factory\InvoiceInvitationFactory; use App\Helpers\Invoice\InvoiceSum; use App\Jobs\Company\UpdateCompanyLedgerWithInvoice; -use App\Jobs\Invoice\CreateInvoiceInvitations; use App\Jobs\Product\UpdateOrCreateProduct; use App\Listeners\Invoice\CreateInvoiceInvitation; use App\Models\ClientContact; @@ -100,7 +99,7 @@ class InvoiceRepository extends BaseRepository /* If no invitations have been created, this is our fail safe to maintain state*/ if ($invoice->invitations->count() == 0) { - CreateInvoiceInvitations::dispatchNow($invoice, $invoice->company); + $invoice->service()->createInvitations(); } $invoice = $invoice->calc()->getInvoice(); @@ -114,7 +113,7 @@ class InvoiceRepository extends BaseRepository UpdateCompanyLedgerWithInvoice::dispatchNow($invoice, ($finished_amount - $starting_amount), $invoice->company); } - $invoice = $invoice->applyNumber()->save(); + $invoice = $invoice->service()->applyNumber()->save(); if ($invoice->company->update_products !== false) { UpdateOrCreateProduct::dispatch($invoice->line_items, $invoice, $invoice->company); @@ -132,6 +131,6 @@ class InvoiceRepository extends BaseRepository */ public function markSent(Invoice $invoice) : ?Invoice { - return $invoice->markSent()->save(); + return $invoice->service()->markSent()->save(); } } diff --git a/app/Repositories/PaymentRepository.php b/app/Repositories/PaymentRepository.php index 54d3b987dfe2..e6e666b05da9 100644 --- a/app/Repositories/PaymentRepository.php +++ b/app/Repositories/PaymentRepository.php @@ -94,7 +94,7 @@ class PaymentRepository extends BaseRepository $invoice = Invoice::whereId($paid_invoice['invoice_id'])->first(); if ($invoice) { - $invoice->applyPayment($payment, $paid_invoice['amount'])->save(); + $invoice->service()->applyPayment($payment, $paid_invoice['amount'])->save(); } } } else { diff --git a/app/Services/Invoice/ApplyPayment.php b/app/Services/Invoice/ApplyPayment.php index 737b93490045..0f4305170b50 100644 --- a/app/Services/Invoice/ApplyPayment.php +++ b/app/Services/Invoice/ApplyPayment.php @@ -44,16 +44,16 @@ class ApplyPayment if ($this->invoice->hasPartial()) { //is partial and amount is exactly the partial amount if ($this->invoice->partial == $payment_amount) { - $this->invoice->clearPartial()->setDueDate()->setStatus(Invoice::STATUS_PARTIAL)->updateBalance($payment_amount*-1); + $this->invoice->service()->clearPartial()->setDueDate()->setStatus(Invoice::STATUS_PARTIAL)->updateBalance($payment_amount*-1); } elseif ($this->invoice->partial > 0 && $this->invoice->partial > $payment_amount) { //partial amount exists, but the amount is less than the partial amount - $this->invoice->updatePartial($payment_amount*-1)->updateBalance($payment_amount*-1); + $this->invoice->service()->updatePartial($payment_amount*-1)->updateBalance($payment_amount*-1); } elseif ($this->invoice->partial > 0 && $this->invoice->partial < $payment_amount) { //partial exists and the amount paid is GREATER than the partial amount - $this->invoice->clearPartial()->setDueDate()->setStatus(Invoice::STATUS_PARTIAL)->updateBalance($payment_amount*-1); + $this->invoice->service()->clearPartial()->setDueDate()->setStatus(Invoice::STATUS_PARTIAL)->updateBalance($payment_amount*-1); } } elseif ($payment_amount == $this->invoice->balance) { //total invoice paid. - $this->invoice->clearPartial()->setStatus(Invoice::STATUS_PAID)->updateBalance($payment_amount*-1); + $this->invoice->service()->clearPartial()->setStatus(Invoice::STATUS_PAID)->updateBalance($payment_amount*-1); } elseif($payment_amount < $this->invoice->balance) { //partial invoice payment made - $this->invoice->clearPartial()->updateBalance($payment_amount*-1); + $this->invoice->service()->clearPartial()->updateBalance($payment_amount*-1); } return $this->invoice; diff --git a/app/Services/Invoice/CreateInvitations.php b/app/Services/Invoice/CreateInvitations.php new file mode 100644 index 000000000000..b1f4731db01c --- /dev/null +++ b/app/Services/Invoice/CreateInvitations.php @@ -0,0 +1,49 @@ +client->contacts; + + $contacts->each(function ($contact) use($invoice){ + $invitation = InvoiceInvitation::whereCompanyId($invoice->company_id) + ->whereClientContactId($contact->id) + ->whereInvoiceId($invoice->id) + ->first(); + + if (!$invitation && $contact->send_invoice) { + $ii = InvoiceInvitationFactory::create($invoice->company_id, $invoice->user_id); + $ii->invoice_id = $invoice->id; + $ii->client_contact_id = $contact->id; + $ii->save(); + } elseif ($invitation && !$contact->send_invoice) { + $invitation->delete(); + } + }); + + return $invoice; + } +} \ No newline at end of file diff --git a/app/Services/Invoice/InvoiceService.php b/app/Services/Invoice/InvoiceService.php index c1da6aca5953..c61e7494e978 100644 --- a/app/Services/Invoice/InvoiceService.php +++ b/app/Services/Invoice/InvoiceService.php @@ -15,6 +15,8 @@ use App\Models\Invoice; use App\Models\Payment; use App\Services\Client\ClientService; use App\Services\Invoice\ApplyNumber; +use App\Services\Invoice\ApplyPayment; +use App\Services\Invoice\CreateInvitations; use App\Services\Invoice\MarkInvoicePaid; use App\Services\Invoice\MarkSent; use App\Services\Invoice\UpdateBalance; @@ -92,6 +94,15 @@ class InvoiceService return $this; } + public function createInvitations() + { + $create_invitation = new CreateInvitations(); + + $this->invoice = $create_invitation($this->invoice); + + return $this; + } + public function markSent() { $mark_sent = new MarkSent($this->invoice->client); @@ -149,9 +160,6 @@ class InvoiceService - - - /** * Saves the invoice * @return Invoice object diff --git a/app/Services/Invoice/MarkPaid.php b/app/Services/Invoice/MarkPaid.php index 22f08d728d48..f1439115e76a 100644 --- a/app/Services/Invoice/MarkPaid.php +++ b/app/Services/Invoice/MarkPaid.php @@ -48,7 +48,10 @@ class MarkPaid 'amount' => $payment->amount ]); - $invoice->updateBalance($payment->amount*-1)->save(); + $invoice->service() + ->updateBalance($payment->amount*-1) + ->setStatus(Invoice::STATUS_PAID) + ->save(); /* Update Invoice balance */ event(new PaymentWasCreated($payment, $payment->company)); diff --git a/app/Services/Invoice/MarkSent.php b/app/Services/Invoice/MarkSent.php index dafd30e7a4dd..33f85eb9fb5c 100644 --- a/app/Services/Invoice/MarkSent.php +++ b/app/Services/Invoice/MarkSent.php @@ -43,7 +43,7 @@ class MarkSent $this->client->updateBalance($invoice->balance)->save(); - $invoice->applyNumber()->save(); + $invoice->service()->applyNumber()->save(); UpdateCompanyLedgerWithInvoice::dispatchNow($invoice, $invoice->balance, $invoice->company); diff --git a/app/Utils/Traits/Payment/Refundable.php b/app/Utils/Traits/Payment/Refundable.php index 1419be64999a..db48d5d104ba 100644 --- a/app/Utils/Traits/Payment/Refundable.php +++ b/app/Utils/Traits/Payment/Refundable.php @@ -225,12 +225,12 @@ trait Refundable { $invoice = Invoice::find($refunded_invoice['invoice_id']); - $invoice->updateBalance($refunded_invoice['amount'])->save(); + $invoice->service()->updateBalance($refunded_invoice['amount'])->save(); if($invoice->amount == $invoice->balance) - $invoice->setStatus(Invoice::STATUS_SENT); + $invoice->service()->setStatus(Invoice::STATUS_SENT); else - $invoice->setStatus(Invoice::STATUS_PARTIAL); + $invoice->service()->setStatus(Invoice::STATUS_PARTIAL); $client = $invoice->client; diff --git a/tests/Feature/InvitationTest.php b/tests/Feature/InvitationTest.php index 657aa75c4587..c8647afa8628 100644 --- a/tests/Feature/InvitationTest.php +++ b/tests/Feature/InvitationTest.php @@ -7,7 +7,6 @@ use App\DataMapper\DefaultSettings; use App\Events\Invoice\InvoiceWasMarkedSent; use App\Factory\InvoiceInvitationFactory; use App\Jobs\Account\CreateAccount; -use App\Listeners\Invoice\CreateInvoiceInvitations; use App\Models\Account; use App\Models\Client; use App\Models\Invoice; diff --git a/tests/Feature/PaymentTest.php b/tests/Feature/PaymentTest.php index 7c5bd1d31af6..f68e9362a78a 100644 --- a/tests/Feature/PaymentTest.php +++ b/tests/Feature/PaymentTest.php @@ -295,8 +295,7 @@ class PaymentTest extends TestCase $this->invoice = $this->invoice_calc->getInvoice(); $this->invoice->save(); - $this->invoice->markSent(); - $this->invoice->save(); + $this->invoice->service()->markSent()->save(); $data = [ @@ -373,7 +372,7 @@ class PaymentTest extends TestCase $this->invoice = $this->invoice_calc->getInvoice(); $this->invoice->save(); - $this->invoice->markSent(); + $this->invoice->service()->markSent()->save(); $this->invoice->is_deleted = false; $this->invoice->save(); @@ -445,8 +444,7 @@ class PaymentTest extends TestCase $this->invoice = $this->invoice_calc->getInvoice(); $this->invoice->save(); - $this->invoice->markSent(); - $this->invoice->save(); + $this->invoice->service()->markSent()->save(); $data = [ @@ -506,8 +504,7 @@ class PaymentTest extends TestCase $this->invoice = $this->invoice_calc->getInvoice(); $this->invoice->save(); - $this->invoice->markSent(); - $this->invoice->save(); + $this->invoice->service()->markSent()->save(); $data = [ @@ -563,8 +560,7 @@ class PaymentTest extends TestCase $this->invoice = $this->invoice_calc->getInvoice(); $this->invoice->save(); - $this->invoice->markSent(); - $this->invoice->save(); + $this->invoice->service()->markSent()->save(); $data = [ @@ -630,8 +626,7 @@ class PaymentTest extends TestCase $this->invoice = $this->invoice_calc->getInvoice(); $this->invoice->save(); - $this->invoice->markSent(); - $this->invoice->save(); + $this->invoice->service()->markSent()->save(); $payment = PaymentFactory::create($this->company->id, $this->user->id); $payment->amount = 10; @@ -690,8 +685,7 @@ class PaymentTest extends TestCase $this->invoice = $this->invoice_calc->getInvoice(); $this->invoice->save(); - $this->invoice->markSent(); - $this->invoice->save(); + $this->invoice->service()->markSent()->save(); $payment = PaymentFactory::create($this->company->id, $this->user->id); $payment->amount = 10; @@ -757,7 +751,7 @@ class PaymentTest extends TestCase $this->invoice = $this->invoice_calc->getInvoice(); $this->invoice->save(); - $this->invoice->markSent(); + $this->invoice->service()->markSent()->save(); $data = [ 'amount' => 15.0, @@ -810,7 +804,7 @@ class PaymentTest extends TestCase $this->invoice = $this->invoice_calc->getInvoice(); $this->invoice->save(); - $this->invoice->markSent(); + $this->invoice->service()->markSent()->save(); $data = [ @@ -870,7 +864,7 @@ class PaymentTest extends TestCase $this->invoice = $this->invoice_calc->getInvoice(); $this->invoice->save(); - $this->invoice->markSent(); + $this->invoice->service()->markSent()->save(); $data = [ 'amount' => 20.0, @@ -914,7 +908,7 @@ class PaymentTest extends TestCase $this->invoice = $this->invoice_calc->getInvoice(); $this->invoice->save(); - $this->invoice->markSent(); + $this->invoice->service()->markSent()->save(); $data = [ diff --git a/tests/Integration/CheckRemindersTest.php b/tests/Integration/CheckRemindersTest.php index 4a17d18bef61..199eeeb1e723 100644 --- a/tests/Integration/CheckRemindersTest.php +++ b/tests/Integration/CheckRemindersTest.php @@ -45,7 +45,7 @@ class CheckRemindersTest extends TestCase $settings->num_days_reminder3 = 1; $this->company->settings = $settings; - $this->invoice->markSent(); + $this->invoice->service()->markSent(); $this->invoice->setReminder($settings); $this->assertEquals(0, Carbon::now()->addDays(7)->diffInDays($this->invoice->next_send_date)); @@ -68,8 +68,7 @@ class CheckRemindersTest extends TestCase $settings->num_days_reminder3 = 1; $this->company->settings = $settings; - $this->invoice->markSent(); - $this->invoice->setStatus(Invoice::STATUS_PAID); + $this->invoice->service()->markSent()->setStatus(Invoice::STATUS_PAID); $this->invoice->setReminder($settings); $this->assertEquals($this->invoice->next_send_date, null); @@ -92,7 +91,7 @@ class CheckRemindersTest extends TestCase $settings->num_days_reminder3 = 1; $this->company->settings = $settings; - $this->invoice->markSent(); + $this->invoice->service()->markSent(); $this->invoice->setReminder($settings); $this->assertEquals(0, Carbon::parse($this->invoice->due_date)->subDays(29)->diffInDays($this->invoice->next_send_date)); @@ -115,7 +114,7 @@ class CheckRemindersTest extends TestCase $settings->num_days_reminder3 = 1; $this->company->settings = $settings; - $this->invoice->markSent(); + $this->invoice->service()->markSent(); $this->invoice->setReminder($settings); $this->assertEquals(0, Carbon::parse($this->invoice->due_date)->addDays(1)->diffInDays($this->invoice->next_send_date)); @@ -138,7 +137,7 @@ class CheckRemindersTest extends TestCase $settings->num_days_reminder3 = 1; $this->company->settings = $settings; - $this->invoice->markSent(); + $this->invoice->service()->markSent(); $this->invoice->setReminder($settings); $this->assertEquals($this->invoice->next_send_date, null); @@ -161,7 +160,7 @@ class CheckRemindersTest extends TestCase $settings->num_days_reminder3 = 0; $this->company->settings = $settings; - $this->invoice->markSent(); + $this->invoice->service()->markSent(); $this->invoice->setReminder($settings); $this->assertEquals($this->invoice->next_send_date, null); diff --git a/tests/Integration/MarkInvoicePaidTest.php b/tests/Integration/MarkInvoicePaidTest.php index 0e5dd7c6931a..fb4359d8e0b4 100644 --- a/tests/Integration/MarkInvoicePaidTest.php +++ b/tests/Integration/MarkInvoicePaidTest.php @@ -42,7 +42,7 @@ class MarkInvoicePaidTest extends TestCase $client = $invoice->client; $client_balance = $client->balance; - $this->invoice->markPaid(); + $this->invoice->service()->markPaid(); $invoice = Invoice::find($this->invoice->id); $client = $invoice->client; diff --git a/tests/Integration/UpdateCompanyLedgerTest.php b/tests/Integration/UpdateCompanyLedgerTest.php index e55c62b0308c..066ac53829f5 100644 --- a/tests/Integration/UpdateCompanyLedgerTest.php +++ b/tests/Integration/UpdateCompanyLedgerTest.php @@ -37,7 +37,7 @@ class UpdateCompanyLedgerTest extends TestCase public function testPaymentIsPresentInLedger() { - $invoice = $this->invoice->markPaid()->save(); + $invoice = $this->invoice->service()->markPaid()->save(); $ledger = CompanyLedger::whereClientId($invoice->client_id) ->whereCompanyId($invoice->company_id) diff --git a/tests/MockAccountData.php b/tests/MockAccountData.php index 5d5c2c621068..d57c59373514 100644 --- a/tests/MockAccountData.php +++ b/tests/MockAccountData.php @@ -23,7 +23,6 @@ use App\Factory\InvoiceItemFactory; use App\Factory\InvoiceToRecurringInvoiceFactory; use App\Helpers\Invoice\InvoiceSum; use App\Jobs\Company\UpdateCompanyLedgerWithInvoice; -use App\Jobs\Invoice\CreateInvoiceInvitations; use App\Models\Client; use App\Models\CompanyGateway; use App\Models\CompanyToken; @@ -179,7 +178,7 @@ trait MockAccountData $this->invoice->save(); - $this->invoice->markSent(); + $this->invoice->service()->markSent(); $this->credit = CreditFactory::create($this->company->id,$this->user->id); $this->credit->client_id = $this->client->id;