1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-06 03:02:34 +01:00
invoiceninja/app/Services/Invoice/CreateInvitations.php
David Bomba cda534e996
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
2020-02-04 18:51:44 +11:00

49 lines
1.3 KiB
PHP

<?php
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Services\Invoice;
use App\Factory\InvoiceInvitationFactory;
use App\Models\Invoice;
use App\Models\InvoiceInvitation;
class CreateInvitations
{
public function __construct()
{
}
public function __invoke($invoice)
{
$contacts = $invoice->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;
}
}