2020-05-19 00:22:18 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
2020-05-19 00:22:18 +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-05-19 00:22:18 +02:00
|
|
|
*
|
2021-06-16 08:58:16 +02:00
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
2020-05-19 00:22:18 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Mail\Admin;
|
|
|
|
|
2021-03-31 03:55:33 +02:00
|
|
|
use App\Mail\Engine\PaymentEmailEngine;
|
2023-02-17 22:36:51 +01:00
|
|
|
use App\Models\Payment;
|
2021-06-29 11:46:40 +02:00
|
|
|
use App\Utils\Ninja;
|
2020-05-19 00:22:18 +02:00
|
|
|
use App\Utils\Number;
|
2021-06-29 11:46:40 +02:00
|
|
|
use Illuminate\Support\Facades\App;
|
2020-10-28 11:10:49 +01:00
|
|
|
use stdClass;
|
2020-05-19 00:22:18 +02:00
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
class EntityPaidObject
|
2020-05-19 00:22:18 +02:00
|
|
|
{
|
2020-09-06 11:38:10 +02:00
|
|
|
public $invitation;
|
2020-05-19 00:22:18 +02:00
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
public $entity;
|
2020-05-19 00:22:18 +02:00
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
public $contact;
|
2020-05-19 00:22:18 +02:00
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
public $company;
|
2020-05-19 00:22:18 +02:00
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
public $settings;
|
2020-05-19 00:22:18 +02:00
|
|
|
|
2023-06-07 08:25:41 +02:00
|
|
|
public function __construct(public Payment $payment, protected bool $use_react_url)
|
2020-05-19 00:22:18 +02:00
|
|
|
{
|
|
|
|
$this->payment = $payment;
|
|
|
|
$this->company = $payment->company;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function build()
|
|
|
|
{
|
2021-06-29 11:46:40 +02:00
|
|
|
App::forgetInstance('translator');
|
|
|
|
/* Init a new copy of the translator*/
|
|
|
|
$t = app('translator');
|
|
|
|
/* Set the locale*/
|
|
|
|
App::setLocale($this->company->getLocale());
|
|
|
|
/* Set customized translations _NOW_ */
|
|
|
|
$t->replace(Ninja::transformTranslations($this->company->settings));
|
|
|
|
|
2024-01-14 05:05:00 +01:00
|
|
|
$mail_obj = new stdClass();
|
2020-09-06 11:38:10 +02:00
|
|
|
$mail_obj->amount = $this->getAmount();
|
|
|
|
$mail_obj->subject = $this->getSubject();
|
|
|
|
$mail_obj->data = $this->getData();
|
|
|
|
$mail_obj->markdown = 'email.admin.generic';
|
|
|
|
$mail_obj->tag = $this->company->company_key;
|
2024-01-29 07:45:22 +01:00
|
|
|
$mail_obj->text_view = 'email.template.text';
|
2020-09-06 11:38:10 +02:00
|
|
|
|
|
|
|
return $mail_obj;
|
2020-05-19 00:22:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private function getAmount()
|
|
|
|
{
|
2020-09-06 11:38:10 +02:00
|
|
|
return Number::formatMoney($this->payment->amount, $this->payment->client);
|
2020-05-19 00:22:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private function getSubject()
|
|
|
|
{
|
|
|
|
return
|
|
|
|
ctrans(
|
|
|
|
'texts.notification_payment_paid_subject',
|
|
|
|
['client' => $this->payment->client->present()->name()]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getData()
|
|
|
|
{
|
|
|
|
$settings = $this->payment->client->getMergedSettings();
|
|
|
|
|
|
|
|
$amount = Number::formatMoney($this->payment->amount, $this->payment->client);
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2020-05-19 00:22:18 +02:00
|
|
|
$invoice_texts = ctrans('texts.invoice_number_short');
|
|
|
|
|
|
|
|
foreach ($this->payment->invoices as $invoice) {
|
2020-09-06 11:38:10 +02:00
|
|
|
$invoice_texts .= $invoice->number.',';
|
2020-05-19 00:22:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$invoice_texts = substr($invoice_texts, 0, -1);
|
2024-01-29 07:45:22 +01:00
|
|
|
$content = ctrans(
|
2024-02-13 05:25:18 +01:00
|
|
|
'texts.notification_payment_paid',
|
|
|
|
['amount' => $amount,
|
2022-06-21 11:57:17 +02:00
|
|
|
'client' => $this->payment->client->present()->name(),
|
|
|
|
'invoice' => $invoice_texts,
|
|
|
|
]
|
2024-01-29 07:45:22 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
$data = [
|
|
|
|
'title' => ctrans(
|
|
|
|
'texts.notification_payment_paid_subject',
|
|
|
|
['client' => $this->payment->client->present()->name()]
|
2020-05-19 00:22:18 +02:00
|
|
|
),
|
2024-01-29 07:45:22 +01:00
|
|
|
'content' => $content,
|
2023-06-07 08:25:41 +02:00
|
|
|
'url' => $this->payment->portalUrl($this->use_react_url),
|
2020-05-19 00:22:18 +02:00
|
|
|
'button' => ctrans('texts.view_payment'),
|
|
|
|
'signature' => $settings->email_signature,
|
|
|
|
'logo' => $this->company->present()->logo(),
|
2020-09-19 04:05:54 +02:00
|
|
|
'settings' => $settings,
|
2020-10-20 01:37:33 +02:00
|
|
|
'whitelabel' => $this->company->account->isPaid() ? true : false,
|
2024-01-29 07:45:22 +01:00
|
|
|
'text_body' => $content,
|
2024-02-13 07:10:36 +01:00
|
|
|
'template' => $this->company->account->isPremium() ? 'email.template.admin_premium' : 'email.template.admin',
|
2020-05-19 00:22:18 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
2021-03-31 03:55:33 +02:00
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
}
|