mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
* Emails * change to user service * refactor emails * refactor emails * refactor emails * refactor emails * emails * emails * emails * emails * emails * emails * emails * emails * emails * emails * Update EmailPayment.php * Update SendEmail.php * Update SendEmail.php * Update SendEmail.php * Update and rename BuildEmail.php to EmailBuilder.php * Create InvoiceEmail * Create QuoteEmail.php * Rename InvoiceEmail to InvoiceEmail.php * Create PaymentEmail.php * Update SendEmail.php * Update SendEmail.php * Update SendEmail.php * Update SendEmail.php * Update InvoiceEmail.php * Update EmailInvoice.php * Update SendEmail.php * Update TemplateEmail.php * Update EmailBuilder.php * Update InvoiceEmail.php * Update QuoteEmail.php * Update PaymentEmail.php * Update InvoiceEmail.php * Update QuoteEmail.php * Update QuoteInvitation.php * Update EmailQuote.php * Update SendEmail.php * Update SendEmail.php * Update PaymentService.php * Update PaymentEmail.php * Update PaymentEmail.php * Update PaymentEmail.php * Update EmailBuilder.php * Update PaymentEmail.php * Update EmailPayment.php * Update SendEmail.php * Update InvoiceService.php * Update SendEmail.php * Update PaymentService.php * Update SendEmail.php * Update QuoteService.php * Update EmailPayment.php Co-authored-by: David Bomba <turbo124@gmail.com>
38 lines
963 B
PHP
38 lines
963 B
PHP
<?php
|
|
namespace App\Services\Credit;
|
|
|
|
use App\Factory\CreditInvitationFactory;
|
|
use App\Models\CreditInvitation;
|
|
|
|
class CreateInvitations
|
|
{
|
|
|
|
public function __construct()
|
|
{
|
|
}
|
|
|
|
public function __invoke($credit)
|
|
{
|
|
|
|
$contacts = $credit->customer->contacts;
|
|
|
|
$contacts->each(function ($contact) use($credit){
|
|
$invitation = CreditInvitation::whereCompanyId($credit->account_id)
|
|
->whereClientContactId($contact->id)
|
|
->whereCreditId($credit->id)
|
|
->first();
|
|
|
|
if (!$invitation) {
|
|
$ii = CreditInvitationFactory::create($credit->account_id, $credit->user_id);
|
|
$ii->credit_id = $credit->id;
|
|
$ii->client_contact_id = $contact->id;
|
|
$ii->save();
|
|
} elseif ($invitation && !$contact->send_credit) {
|
|
$invitation->delete();
|
|
}
|
|
});
|
|
|
|
return $credit;
|
|
}
|
|
}
|