1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-13 06:32:40 +01:00
invoiceninja/app/Services/Payment/SendEmail.php

49 lines
1.4 KiB
PHP
Raw Normal View History

<?php
2020-07-01 03:06:40 +02:00
/**
* Invoice Ninja (https://invoiceninja.com).
2020-07-01 03:06:40 +02:00
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
2023-01-28 23:21:40 +01:00
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
2020-07-01 03:06:40 +02:00
*
2021-06-16 08:58:16 +02:00
* @license https://www.elastic.co/licensing/elastic-license
2020-07-01 03:06:40 +02:00
*/
namespace App\Services\Payment;
2023-03-17 07:36:49 +01:00
use App\Utils\Ninja;
2023-02-22 10:23:09 +01:00
use App\Models\Payment;
use App\Models\ClientContact;
use App\Jobs\Payment\EmailPayment;
2023-03-17 07:36:49 +01:00
use App\Events\Payment\PaymentWasEmailed;
class SendEmail
{
2023-02-22 10:23:09 +01:00
public function __construct(public Payment $payment, public ?ClientContact $contact)
{}
/**
* Builds the correct template to send.
2020-10-28 11:10:49 +01:00
* @return void
*/
public function run()
{
2023-02-16 02:36:09 +01:00
$this->payment->load('company', 'client.contacts', 'invoices');
2021-10-08 07:23:00 +02:00
2023-02-22 10:23:09 +01:00
if(!$this->contact)
$this->contact = $this->payment->client->contacts()->first();
2022-08-04 08:22:48 +02:00
2023-02-22 10:13:50 +01:00
// $this->payment->invoices->sortByDesc('id')->first(function ($invoice) {
// $invoice->invitations->each(function ($invitation) {
// if (!$invitation->contact->trashed() && $invitation->contact->email) {
2023-02-22 10:23:09 +01:00
EmailPayment::dispatch($this->payment, $this->payment->company, $this->contact);
2023-03-17 07:36:49 +01:00
event(new PaymentWasEmailed($this->payment, $this->payment->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null)));
2023-02-22 10:13:50 +01:00
// }
// });
// });
2023-02-22 12:27:52 +01:00
}
}