mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 21:22:58 +01:00
1e35c90ee6
* refactor send_invoice to generic -> send * Code cleanup * Fixes for tests and multidb
38 lines
951 B
PHP
38 lines
951 B
PHP
<?php
|
|
namespace App\Services\Quote;
|
|
|
|
use App\Factory\QuoteInvitationFactory;
|
|
use App\Models\QuoteInvitation;
|
|
|
|
class CreateInvitations
|
|
{
|
|
|
|
public function __construct()
|
|
{
|
|
}
|
|
|
|
public function run($quote)
|
|
{
|
|
|
|
$contacts = $quote->client->contacts;
|
|
|
|
$contacts->each(function ($contact) use($quote){
|
|
$invitation = QuoteInvitation::whereCompanyId($quote->company_id)
|
|
->whereClientContactId($contact->id)
|
|
->whereQuoteId($quote->id)
|
|
->first();
|
|
|
|
if (!$invitation && $contact->send) {
|
|
$ii = QuoteInvitationFactory::create($quote->company_id, $quote->user_id);
|
|
$ii->quote_id = $quote->id;
|
|
$ii->client_contact_id = $contact->id;
|
|
$ii->save();
|
|
} elseif ($invitation && !$contact->send) {
|
|
$invitation->delete();
|
|
}
|
|
});
|
|
|
|
return $quote;
|
|
}
|
|
}
|