invoiceninja/app/Services/Credit/CreateInvitations.php
David Bomba f57339f185
Fixes and Refactors for Invoice Emails. (#3339)
* Working on emailing invoices

* Working on emailing and displaying email

* Working on emailing and displaying email

* Email invoices

* Fixes for html emails

* Ensure valid client prior to store

* Ensure client exists when storing an entity

* Update variable name send -> send_email for client_contacts

* Mailable download files

* Extend timeouts of password protected routes when a protected route is hit

* Add default portal design to company settings

* Minor fixes

* Fixes for Tests

* Fixes for invoicing emails

* Refactors for InvoiceEmail

* Implement abstractservice

* Refactors for services

* Refactors for emails

* Fixes for Invoice Emails
2020-02-17 20:37:44 +11:00

39 lines
1013 B
PHP

<?php
namespace App\Services\Credit;
use App\Factory\CreditInvitationFactory;
use App\Models\CreditInvitation;
use App\Services\AbstractService;
class CreateInvitations extends AbstractService
{
public function __construct()
{
}
public function run($credit)
{
$contacts = $credit->client->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->company_id, $credit->user_id);
$ii->credit_id = $credit->id;
$ii->client_contact_id = $contact->id;
$ii->save();
} elseif ($invitation && !$contact->send_email) {
$invitation->delete();
}
});
return $credit;
}
}