1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-15 23:52:33 +01:00
invoiceninja/app/Mail/Admin/InventoryNotificationObject.php

85 lines
2.6 KiB
PHP
Raw Normal View History

2022-06-08 06:25:44 +02:00
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
2024-04-12 06:15:41 +02:00
* @copyright Copyright (c) 2024. 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;
$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',
['product' => $this->product->product_key.': '.$this->product->notes]
2022-06-08 06:25:44 +02:00
);
}
private function getData()
{
$content = ctrans(
2024-02-13 05:25:18 +01:00
'texts.inventory_notification_body',
['amount' => $this->getAmount(),
'product' => $this->product->product_key.': '.$this->product->notes,
]
);
2024-02-13 05:25:18 +01:00
$data = [
'title' => $this->getSubject(),
'content' => $content,
2023-06-07 08:25:41 +02:00
'url' => $this->product->portalUrl($this->use_react_url),
'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,
'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;
}
}