Fixes for admin URLs

This commit is contained in:
David Bomba 2023-06-07 16:25:41 +10:00
parent baaa39c1fa
commit 055596cfe6
13 changed files with 47 additions and 62 deletions

View File

@ -144,12 +144,12 @@ class AdjustProductInventory implements ShouldQueue
private function notifyStocklevels(Product $product, string $notification_level) private function notifyStocklevels(Product $product, string $notification_level)
{ {
$nmo = new NinjaMailerObject; $nmo = new NinjaMailerObject;
$nmo->mailable = new NinjaMailer((new InventoryNotificationObject($product, $notification_level))->build());
$nmo->company = $this->company; $nmo->company = $this->company;
$nmo->settings = $this->company->settings; $nmo->settings = $this->company->settings;
$this->company->company_users->each(function ($cu) use ($product, $nmo) { $this->company->company_users->each(function ($cu) use ($product, $nmo, $notification_level) {
if ($this->checkNotificationExists($cu, $product, ['inventory_all', 'inventory_user', 'inventory_threshold_all', 'inventory_threshold_user'])) { if ($this->checkNotificationExists($cu, $product, ['inventory_all', 'inventory_user', 'inventory_threshold_all', 'inventory_threshold_user'])) {
$nmo->mailable = new NinjaMailer((new InventoryNotificationObject($product, $notification_level, $cu->portalType()))->build());
$nmo->to_user = $cu->user; $nmo->to_user = $cu->user;
NinjaMailerJob::dispatch($nmo); NinjaMailerJob::dispatch($nmo);
} }

View File

@ -92,7 +92,7 @@ class PaymentFailedMailer implements ShouldQueue
if (($key = array_search('mail', $methods)) !== false) { if (($key = array_search('mail', $methods)) !== false) {
unset($methods[$key]); unset($methods[$key]);
$mail_obj = (new PaymentFailureObject($this->client, $this->error, $this->company, $amount, $this->payment_hash))->build(); $mail_obj = (new PaymentFailureObject($this->client, $this->error, $this->company, $amount, $this->payment_hash, $company_user->portalType()))->build();
$nmo = new NinjaMailerObject; $nmo = new NinjaMailerObject;
$nmo->mailable = new NinjaMailer($mail_obj); $nmo->mailable = new NinjaMailer($mail_obj);

View File

@ -64,7 +64,7 @@ class InvoiceEmailedNotification implements ShouldQueue
unset($methods[$key]); unset($methods[$key]);
$nmo = new NinjaMailerObject; $nmo = new NinjaMailerObject;
$nmo->mailable = new NinjaMailer((new EntitySentObject($event->invitation, 'invoice', $event->template))->build()); $nmo->mailable = new NinjaMailer((new EntitySentObject($event->invitation, 'invoice', $event->template, $company_user->portalType()))->build());
$nmo->company = $invoice->company; $nmo->company = $invoice->company;
$nmo->settings = $invoice->company->settings; $nmo->settings = $invoice->company->settings;
$nmo->to_user = $user; $nmo->to_user = $user;

View File

@ -76,7 +76,7 @@ class PaymentNotification implements ShouldQueue
unset($methods[$key]); unset($methods[$key]);
$nmo = new NinjaMailerObject; $nmo = new NinjaMailerObject;
$nmo->mailable = new NinjaMailer((new EntityPaidObject($payment))->build()); $nmo->mailable = new NinjaMailer((new EntityPaidObject($payment, $company_user->portalType()))->build());
$nmo->company = $event->company; $nmo->company = $event->company;
$nmo->settings = $event->company->settings; $nmo->settings = $event->company->settings;
$nmo->to_user = $user; $nmo->to_user = $user;
@ -108,7 +108,7 @@ class PaymentNotification implements ShouldQueue
unset($methods[$key]); unset($methods[$key]);
$nmo = new NinjaMailerObject; $nmo = new NinjaMailerObject;
$nmo->mailable = new NinjaMailer((new EntityPaidObject($payment))->build()); $nmo->mailable = new NinjaMailer((new EntityPaidObject($payment, $company_user->portalType()))->build());
$nmo->company = $event->company; $nmo->company = $event->company;
$nmo->settings = $event->company->settings; $nmo->settings = $event->company->settings;
$nmo->to_user = $user; $nmo->to_user = $user;
@ -161,11 +161,12 @@ class PaymentNotification implements ShouldQueue
} }
/** /**
* @param $data * @param string $url
*/ */
private function sendAnalytics($data) private function sendAnalytics($url)
{ {
$data = utf8_encode($data); $data = mb_convert_encoding($url, 'UTF-8');
// $data = utf8_encode($data);
$curl = curl_init(); $curl = curl_init();
$opts = [ $opts = [

View File

@ -62,7 +62,7 @@ class PurchaseOrderEmailedNotification implements ShouldQueue
unset($methods[$key]); unset($methods[$key]);
$nmo = new NinjaMailerObject; $nmo = new NinjaMailerObject;
$nmo->mailable = new NinjaMailer((new EntitySentObject($event->invitation, 'purchase_order', 'purchase_order'))->build()); $nmo->mailable = new NinjaMailer((new EntitySentObject($event->invitation, 'purchase_order', 'purchase_order', $company_user->portalType()))->build());
$nmo->company = $purchase_order->company; $nmo->company = $purchase_order->company;
$nmo->settings = $purchase_order->company->settings; $nmo->settings = $purchase_order->company->settings;
$nmo->to_user = $user; $nmo->to_user = $user;

View File

@ -54,7 +54,7 @@ class QuoteEmailedNotification implements ShouldQueue
unset($methods[$key]); unset($methods[$key]);
$nmo = new NinjaMailerObject; $nmo = new NinjaMailerObject;
$nmo->mailable = new NinjaMailer((new EntitySentObject($event->invitation, 'quote', $event->template))->build()); $nmo->mailable = new NinjaMailer((new EntitySentObject($event->invitation, 'quote', $event->template, $company_user->portalType()))->build());
$nmo->company = $quote->company; $nmo->company = $quote->company;
$nmo->settings = $quote->company->settings; $nmo->settings = $quote->company->settings;
$nmo->to_user = $user; $nmo->to_user = $user;

View File

@ -30,7 +30,7 @@ class EntityPaidObject
public $settings; public $settings;
public function __construct(public Payment $payment) public function __construct(public Payment $payment, protected bool $use_react_url)
{ {
$this->payment = $payment; $this->payment = $payment;
$this->company = $payment->company; $this->company = $payment->company;
@ -98,7 +98,7 @@ class EntityPaidObject
'invoice' => $invoice_texts, 'invoice' => $invoice_texts,
] ]
), ),
'url' => config('ninja.app_url'), 'url' => $this->payment->portalUrl($this->use_react_url),
'button' => ctrans('texts.view_payment'), 'button' => ctrans('texts.view_payment'),
'signature' => $settings->email_signature, 'signature' => $settings->email_signature,
'logo' => $this->company->present()->logo(), 'logo' => $this->company->present()->logo(),
@ -117,4 +117,5 @@ class EntityPaidObject
return $signature; return $signature;
} }
} }

View File

@ -12,7 +12,6 @@
namespace App\Mail\Admin; namespace App\Mail\Admin;
use App\Models\Company;
use App\Models\Product; use App\Models\Product;
use App\Utils\Ninja; use App\Utils\Ninja;
use Illuminate\Support\Facades\App; use Illuminate\Support\Facades\App;
@ -20,19 +19,9 @@ use stdClass;
class InventoryNotificationObject class InventoryNotificationObject
{ {
public Product $product;
public function __construct(protected Product $product, public string $notification_level, protected bool $use_react_url)
public Company $company;
public $settings;
public string $notification_level;
public function __construct(Product $product, string $notification_level)
{ {
$this->product = $product;
$this->company = $product->company;
$this->settings = $this->company->settings;
} }
public function build() public function build()
@ -41,16 +30,16 @@ class InventoryNotificationObject
/* Init a new copy of the translator*/ /* Init a new copy of the translator*/
$t = app('translator'); $t = app('translator');
/* Set the locale*/ /* Set the locale*/
App::setLocale($this->company->getLocale()); App::setLocale($this->product->company->getLocale());
/* Set customized translations _NOW_ */ /* Set customized translations _NOW_ */
$t->replace(Ninja::transformTranslations($this->company->settings)); $t->replace(Ninja::transformTranslations($this->product->company->settings));
$mail_obj = new stdClass; $mail_obj = new stdClass;
$mail_obj->amount = $this->getAmount(); $mail_obj->amount = $this->getAmount();
$mail_obj->subject = $this->getSubject(); $mail_obj->subject = $this->getSubject();
$mail_obj->data = $this->getData(); $mail_obj->data = $this->getData();
$mail_obj->markdown = 'email.admin.generic'; $mail_obj->markdown = 'email.admin.generic';
$mail_obj->tag = $this->company->company_key; $mail_obj->tag = $this->product->company->company_key;
return $mail_obj; return $mail_obj;
} }
@ -79,12 +68,12 @@ class InventoryNotificationObject
'product' => $this->product->product_key.': '.$this->product->notes, 'product' => $this->product->product_key.': '.$this->product->notes,
] ]
), ),
'url' => config('ninja.app_url'), 'url' => $this->product->portalUrl($this->use_react_url),
'button' => ctrans('texts.login'), 'button' => $this->use_react_url ? ctrans('texts.product_library') : ctrans('ninja.app_url'),
'signature' => $this->settings->email_signature, 'signature' => $this->product->company->settings->email_signature,
'logo' => $this->company->present()->logo(), 'logo' => $this->product->company->present()->logo(),
'settings' => $this->settings, 'settings' => $this->product->company->settings,
'whitelabel' => $this->company->account->isPaid() ? true : false, 'whitelabel' => $this->product->company->account->isPaid() ? true : false,
]; ];
return $data; return $data;

View File

@ -24,17 +24,6 @@ class PaymentFailureObject
{ {
use MakesHash; use MakesHash;
public Client $client;
public string $error;
public Company $company;
public $amount;
public ?PaymentHash $payment_hash;
// private $invoices;
/** /**
* Create a new job instance. * Create a new job instance.
* *
@ -43,19 +32,8 @@ class PaymentFailureObject
* @param $company * @param $company
* @param $amount * @param $amount
*/ */
public function __construct(Client $client, string $error, Company $company, $amount, ?PaymentHash $payment_hash) public function __construct(public Client $client, public string $error, public Company $company, public float $amount, public ?PaymentHash $payment_hash, protected bool $use_react_url)
{ {
$this->client = $client;
$this->error = $error;
$this->company = $company;
$this->amount = $amount;
$this->company = $company;
$this->payment_hash = $payment_hash;
} }
public function build() public function build()
@ -115,8 +93,8 @@ class PaymentFailureObject
'logo' => $this->company->present()->logo(), 'logo' => $this->company->present()->logo(),
'settings' => $this->client->getMergedSettings(), 'settings' => $this->client->getMergedSettings(),
'whitelabel' => $this->company->account->isPaid() ? true : false, 'whitelabel' => $this->company->account->isPaid() ? true : false,
'url' => config('ninja.app_url'), 'url' => $this->client->portalUrl($this->use_react_url),
'button' => ctrans('texts.login'), 'button' => $this->use_react_url ? ctrans('texts.view_client') : ctrans('texts.login'),
'additional_info' => $this->error, 'additional_info' => $this->error,
]; ];

View File

@ -865,4 +865,9 @@ class Client extends BaseModel implements HasLocalePreference
{ {
return ctrans('texts.client'); return ctrans('texts.client');
} }
public function portalUrl(bool $use_react_url): string
{
return $use_react_url ? config('ninja.react_url'). "/clients/{$this->hashed_id}": config('ninja.app_url');
}
} }

View File

@ -557,4 +557,10 @@ class Payment extends BaseModel
{ {
return ctrans('texts.payment'); return ctrans('texts.payment');
} }
public function portalUrl($use_react_url)
{
return $use_react_url ? config('ninja.react_url')."/payments/{$this->hashed_id}/edit" : config('ninja.app_url');
}
} }

View File

@ -200,4 +200,9 @@ class Product extends BaseModel
return $converter->convert($this->notes); return $converter->convert($this->notes);
} }
public function portalUrl($use_react_url): string
{
return $use_react_url ? config('ninja.react_url') . "/products/{$this->hashed_id}/edit" : config('ninja.app_url');
}
} }

View File

@ -664,7 +664,7 @@ class StripePaymentDriver extends BaseDriver
} }
public function processWebhookRequest(PaymentWebhookRequest $request) public function processWebhookRequest(PaymentWebhookRequest $request)
{ {nlog($request->all());
if ($request->type === 'customer.source.updated') { if ($request->type === 'customer.source.updated') {
$ach = new ACH($this); $ach = new ACH($this);
$ach->updateBankAccount($request->all()); $ach->updateBankAccount($request->all());