1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-11 05:32:39 +01:00
invoiceninja/app/Services/Payment/SendEmail.php
2023-03-17 17:36:49 +11:00

49 lines
1.4 KiB
PHP

<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Services\Payment;
use App\Utils\Ninja;
use App\Models\Payment;
use App\Models\ClientContact;
use App\Jobs\Payment\EmailPayment;
use App\Events\Payment\PaymentWasEmailed;
class SendEmail
{
public function __construct(public Payment $payment, public ?ClientContact $contact)
{}
/**
* Builds the correct template to send.
* @return void
*/
public function run()
{
$this->payment->load('company', 'client.contacts', 'invoices');
if(!$this->contact)
$this->contact = $this->payment->client->contacts()->first();
// $this->payment->invoices->sortByDesc('id')->first(function ($invoice) {
// $invoice->invitations->each(function ($invitation) {
// if (!$invitation->contact->trashed() && $invitation->contact->email) {
EmailPayment::dispatch($this->payment, $this->payment->company, $this->contact);
event(new PaymentWasEmailed($this->payment, $this->payment->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null)));
// }
// });
// });
}
}