From b39f2f4ba5e78e69e1fb4d4a0cb49416845752b5 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Mon, 31 Oct 2016 09:06:55 +0200 Subject: [PATCH] Ensure invoice always has an invitation --- app/Services/InvoiceService.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/Services/InvoiceService.php b/app/Services/InvoiceService.php index 0d6bb9822c43..82bbfe35d662 100644 --- a/app/Services/InvoiceService.php +++ b/app/Services/InvoiceService.php @@ -86,11 +86,16 @@ class InvoiceService extends BaseService $sendInvoiceIds = []; foreach ($client->contacts as $contact) { - if ($contact->send_invoice || count($client->contacts) == 1) { + if ($contact->send_invoice) { $sendInvoiceIds[] = $contact->id; } } + // if no contacts are selected auto-select the first to enusre there's an invitation + if ( ! count($sendInvoiceIds)) { + $sendInvoiceIds[] = $client->contacts[0]->id; + } + foreach ($client->contacts as $contact) { $invitation = Invitation::scope()->whereContactId($contact->id)->whereInvoiceId($invoice->id)->first();