Ensure invoice always has an invitation

This commit is contained in:
Hillel Coren 2016-10-31 09:06:55 +02:00
parent e6266b3b10
commit b39f2f4ba5

View File

@ -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();