2022-06-08 06:25:44 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
|
|
|
*
|
|
|
|
* @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)
|
2022-06-08 06:25:44 +02:00
|
|
|
*
|
|
|
|
|
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Mail\Admin;
|
|
|
|
|
|
|
|
use App\Models\Product;
|
|
|
|
use App\Utils\Ninja;
|
|
|
|
use Illuminate\Support\Facades\App;
|
|
|
|
use stdClass;
|
|
|
|
|
|
|
|
class InventoryNotificationObject
|
|
|
|
{
|
2023-06-07 08:25:41 +02:00
|
|
|
public function __construct(protected Product $product, public string $notification_level, protected bool $use_react_url)
|
2022-06-08 06:25:44 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public function build()
|
|
|
|
{
|
|
|
|
App::forgetInstance('translator');
|
|
|
|
/* Init a new copy of the translator*/
|
|
|
|
$t = app('translator');
|
|
|
|
/* Set the locale*/
|
2023-06-07 08:25:41 +02:00
|
|
|
App::setLocale($this->product->company->getLocale());
|
2022-06-08 06:25:44 +02:00
|
|
|
/* Set customized translations _NOW_ */
|
2023-06-07 08:25:41 +02:00
|
|
|
$t->replace(Ninja::transformTranslations($this->product->company->settings));
|
2022-06-08 06:25:44 +02:00
|
|
|
|
2024-01-14 05:05:00 +01:00
|
|
|
$mail_obj = new stdClass();
|
2022-06-08 06:25:44 +02:00
|
|
|
$mail_obj->amount = $this->getAmount();
|
|
|
|
$mail_obj->subject = $this->getSubject();
|
|
|
|
$mail_obj->data = $this->getData();
|
|
|
|
$mail_obj->markdown = 'email.admin.generic';
|
2023-06-07 08:25:41 +02:00
|
|
|
$mail_obj->tag = $this->product->company->company_key;
|
2024-01-29 07:45:22 +01:00
|
|
|
$mail_obj->text_view = 'email.template.text';
|
2022-06-08 06:25:44 +02:00
|
|
|
return $mail_obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getAmount()
|
|
|
|
{
|
|
|
|
return $this->product->in_stock_quantity;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getSubject()
|
|
|
|
{
|
|
|
|
return
|
|
|
|
ctrans(
|
|
|
|
'texts.inventory_notification_subject',
|
2022-06-21 11:57:17 +02:00
|
|
|
['product' => $this->product->product_key.': '.$this->product->notes]
|
2022-06-08 06:25:44 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getData()
|
|
|
|
{
|
2024-01-29 07:45:22 +01:00
|
|
|
$content = ctrans(
|
2024-02-13 05:25:18 +01:00
|
|
|
'texts.inventory_notification_body',
|
|
|
|
['amount' => $this->getAmount(),
|
2022-06-21 11:57:17 +02:00
|
|
|
'product' => $this->product->product_key.': '.$this->product->notes,
|
|
|
|
]
|
2024-01-29 07:45:22 +01:00
|
|
|
);
|
2024-02-13 05:25:18 +01:00
|
|
|
|
2024-01-29 07:45:22 +01:00
|
|
|
$data = [
|
|
|
|
'title' => $this->getSubject(),
|
|
|
|
'content' => $content,
|
2023-06-07 08:25:41 +02:00
|
|
|
'url' => $this->product->portalUrl($this->use_react_url),
|
2023-11-13 01:17:46 +01:00
|
|
|
'button' => ctrans('texts.view'),
|
2023-06-07 08:25:41 +02:00
|
|
|
'signature' => $this->product->company->settings->email_signature,
|
|
|
|
'logo' => $this->product->company->present()->logo(),
|
|
|
|
'settings' => $this->product->company->settings,
|
|
|
|
'whitelabel' => $this->product->company->account->isPaid() ? true : false,
|
2024-01-29 07:45:22 +01:00
|
|
|
'text_body' => $content,
|
2024-02-14 22:31:08 +01:00
|
|
|
'template' => $this->product->company->account->isPremium() ? 'email.template.admin_premium' : 'email.template.admin',
|
2022-06-08 06:25:44 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
}
|