Only one notification per invoice, per product

This commit is contained in:
David Bomba 2023-11-13 11:17:46 +11:00
parent 4691ca29c1
commit 7964069e5b
5 changed files with 8 additions and 16 deletions

View File

@ -19,6 +19,7 @@ use Illuminate\Contracts\Validation\Rule;
class BlackListRule implements Rule
{
private array $blacklist = [
'ckptr.com',
'pretreer.com',
'candassociates.com',
'vusra.com',

View File

@ -31,6 +31,8 @@ class AdjustProductInventory implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, UserNotifies;
private array $notified_products = [];
public function __construct(public Company $company, public Invoice $invoice, public $old_invoice = [])
{
}
@ -56,18 +58,6 @@ class AdjustProductInventory implements ShouldQueue
{
MultiDB::setDb($this->company->db);
// foreach ($this->invoice->line_items as $item) {
// $p = Product::where('product_key', $item->product_key)->where('company_id', $this->company->id)->first();
// if (! $p) {
// continue;
// }
// $p->in_stock_quantity += $item->quantity;
// $p->saveQuietly();
// }
collect($this->invoice->line_items)->filter(function ($item) {
return $item->type_id == '1';
})->each(function ($i) {
@ -147,11 +137,13 @@ class AdjustProductInventory implements ShouldQueue
$nmo->company = $this->company;
$nmo->settings = $this->company->settings;
/** @var \App\Models\CompanyUser $cu */
$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']) && (! in_array($product->id, $this->notified_products))) {
$nmo->mailable = new NinjaMailer((new InventoryNotificationObject($product, $notification_level, $cu->portalType()))->build());
$nmo->to_user = $cu->user;
NinjaMailerJob::dispatch($nmo);
$this->notified_products[] = $product->id;
}
});
}

View File

@ -157,4 +157,4 @@ class SystemMaintenance implements ShouldQueue
}
}
}

View File

@ -69,7 +69,7 @@ class InventoryNotificationObject
]
),
'url' => $this->product->portalUrl($this->use_react_url),
'button' => $this->use_react_url ? ctrans('texts.product_library') : ctrans('ninja.app_url'),
'button' => ctrans('texts.view'),
'signature' => $this->product->company->settings->email_signature,
'logo' => $this->product->company->present()->logo(),
'settings' => $this->product->company->settings,

View File

@ -273,7 +273,6 @@ class EmailDefaults
return $this;
// return $this->email->email_object->cc;
// return [
// ];
}