mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Adjustments for logic for sending payment emails
This commit is contained in:
parent
c8cf4aca42
commit
82888cccff
@ -68,7 +68,7 @@ class EmailPayment implements ShouldQueue
|
||||
$this->payment->load('invoices');
|
||||
|
||||
if (!$this->contact) {
|
||||
$this->contact = $this->payment->client->contacts()->first();
|
||||
$this->contact = $this->payment->client->contacts()->orderBy('is_primary', 'desc')->first();
|
||||
}
|
||||
|
||||
$this->contact->load('client');
|
||||
|
@ -14,22 +14,38 @@ namespace App\Services\Payment;
|
||||
use App\Jobs\Payment\EmailPayment;
|
||||
use App\Models\ClientContact;
|
||||
use App\Models\Payment;
|
||||
use Illuminate\Database\QueryException;
|
||||
|
||||
class SendEmail
|
||||
{
|
||||
public function __construct(public Payment $payment, public ?ClientContact $contact)
|
||||
{
|
||||
}
|
||||
public function __construct(public Payment $payment, public ?ClientContact $contact) {}
|
||||
|
||||
/**
|
||||
* Builds the correct template to send.
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
$this->payment->load('company', 'client.contacts', 'invoices');
|
||||
$this->payment->load('company', 'invoices');
|
||||
|
||||
if (!$this->contact) {
|
||||
$this->contact = $this->payment->client->contacts()->first();
|
||||
|
||||
if($invoice = $this->payment->invoices->first() ?? false) {
|
||||
|
||||
$invitation =
|
||||
$invoice
|
||||
->invitations()
|
||||
->whereHas("contact", function ($q) {
|
||||
$q->where('send_email', true)->orderBy("is_primary", 'ASC');
|
||||
})
|
||||
->first();
|
||||
|
||||
if($invitation) {
|
||||
$this->contact = $invitation->contact;
|
||||
} else {
|
||||
$this->contact = $this->payment->client->contacts()->orderBy('send_email', 'desc')->orderBy('is_primary', 'desc')->first();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
EmailPayment::dispatch($this->payment, $this->payment->company, $this->contact);
|
||||
|
Loading…
x
Reference in New Issue
Block a user