out of stock notification
This commit is contained in:
parent
aee5be5b01
commit
83d9fc703c
@ -203,4 +203,27 @@ class Users extends Controller
|
||||
// Redirect to invoices
|
||||
return redirect('incomes/invoices');
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark items out of stock notifications are read and redirect to items page.
|
||||
*
|
||||
* @param User $user
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function readItemsOutOfStock(User $user)
|
||||
{
|
||||
// Mark item notifications as read
|
||||
foreach ($user->unreadNotifications as $notification) {
|
||||
// Not an item notification
|
||||
if ($notification->getAttribute('type') != 'App\Notifications\Item\Item') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$notification->markAsRead();
|
||||
}
|
||||
|
||||
// Redirect to items
|
||||
return redirect('items/items');
|
||||
}
|
||||
}
|
||||
|
@ -153,6 +153,10 @@ class Bills extends Controller
|
||||
$item_object = Item::find($item['item_id']);
|
||||
|
||||
$item_sku = $item_object->sku;
|
||||
|
||||
// Increase stock (item bought)
|
||||
$item_object->quantity++;
|
||||
$item_object->save();
|
||||
}
|
||||
|
||||
$tax = $tax_id = 0;
|
||||
|
@ -21,6 +21,7 @@ use App\Models\Setting\Category;
|
||||
use App\Models\Setting\Currency;
|
||||
use App\Models\Setting\Tax;
|
||||
use App\Notifications\Income\Invoice as Notification;
|
||||
use App\Notifications\Item\Item as ItemNotification;
|
||||
use App\Traits\Currencies;
|
||||
use App\Traits\DateTime;
|
||||
use App\Traits\Uploads;
|
||||
@ -161,6 +162,21 @@ class Invoices extends Controller
|
||||
$item_object = Item::find($item['item_id']);
|
||||
|
||||
$item_sku = $item_object->sku;
|
||||
|
||||
// Decrease stock (item sold)
|
||||
$item_object->quantity--;
|
||||
$item_object->save();
|
||||
|
||||
// Notify users if out of stock
|
||||
if ($item_object->quantity == 0) {
|
||||
foreach ($item_object->company->users as $user) {
|
||||
if (!$user->can('read-notifications')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$user->notify(new ItemNotification($item_object));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$tax = $tax_id = 0;
|
||||
|
@ -20,6 +20,7 @@ class Header
|
||||
|
||||
$bills = [];
|
||||
$invoices = [];
|
||||
$items = [];
|
||||
$notifications = 0;
|
||||
$company = null;
|
||||
|
||||
@ -47,6 +48,10 @@ class Header
|
||||
$invoices[$data['invoice_id']] = $data['amount'];
|
||||
$notifications++;
|
||||
break;
|
||||
case 'App\Notifications\Item\Item':
|
||||
$items[$data['item_id']] = $data['name'];
|
||||
$notifications++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -57,6 +62,7 @@ class Header
|
||||
'notifications' => $notifications,
|
||||
'bills' => $bills,
|
||||
'invoices' => $invoices,
|
||||
'items' => $items,
|
||||
'company' => $company,
|
||||
'updates' => $updates,
|
||||
]);
|
||||
|
64
app/Notifications/Item/Item.php
Normal file
64
app/Notifications/Item/Item.php
Normal file
@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace App\Notifications\Item;
|
||||
|
||||
use Illuminate\Notifications\Notification;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
|
||||
class Item extends Notification
|
||||
{
|
||||
/**
|
||||
* The item model.
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
public $item;
|
||||
|
||||
/**
|
||||
* Create a notification instance.
|
||||
*
|
||||
* @param object $item
|
||||
*/
|
||||
public function __construct($item)
|
||||
{
|
||||
$this->item = $item;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the notification's channels.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
* @return array|string
|
||||
*/
|
||||
public function via($notifiable)
|
||||
{
|
||||
return ['mail', 'database'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the mail representation of the notification.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
* @return \Illuminate\Notifications\Messages\MailMessage
|
||||
*/
|
||||
public function toMail($notifiable)
|
||||
{
|
||||
return (new MailMessage)
|
||||
->line(trans('items.notification.message', ['name' => $this->item->name]))
|
||||
->action(trans('items.notification.button'), url('items/items', $this->item->id, true));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the array representation of the notification.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($notifiable)
|
||||
{
|
||||
return [
|
||||
'item_id' => $this->item->id,
|
||||
'name' => $this->item->name,
|
||||
];
|
||||
}
|
||||
}
|
@ -8,6 +8,7 @@ return [
|
||||
'counter' => '{0} You have no notification|{1} You have :count notification|[2,*] You have :count notifications',
|
||||
'overdue_invoices' => '{1} :count overdue invoice|[2,*] :count overdue invoices',
|
||||
'upcoming_bills' => '{1} :count upcoming bill|[2,*] :count upcoming bills',
|
||||
'items_stock' => '{1} :count item out of stock|[2,*] :count items out of stock',
|
||||
'view_all' => 'View All'
|
||||
],
|
||||
|
||||
|
@ -7,4 +7,9 @@ return [
|
||||
'purchase_price' => 'Purchase Price',
|
||||
'sku' => 'SKU',
|
||||
|
||||
'notification' => [
|
||||
'message' => 'You are receiving this email because the :name is running out of stock.',
|
||||
'button' => 'View Now',
|
||||
],
|
||||
|
||||
];
|
||||
|
@ -116,6 +116,13 @@
|
||||
</a>
|
||||
</li>
|
||||
@endif
|
||||
@if (count($items))
|
||||
<li>
|
||||
<a href="{{ url('auth/users/' . $user->id . '/read-items') }}">
|
||||
<i class="fa fa-cubes text-red"></i> {{ trans_choice('header.notifications.items_stock', count($items), ['count' => count($items)]) }}
|
||||
</a>
|
||||
</li>
|
||||
@endif
|
||||
</ul>
|
||||
</li>
|
||||
<li class="footer"><a href="#">{{ trans('header.notifications.view_all') }}</a></li>
|
||||
|
@ -31,6 +31,7 @@ Route::group(['middleware' => 'language'], function () {
|
||||
Route::get('logout', 'Auth\Login@destroy')->name('logout');
|
||||
Route::get('users/{user}/read-bills', 'Auth\Users@readUpcomingBills');
|
||||
Route::get('users/{user}/read-invoices', 'Auth\Users@readOverdueInvoices');
|
||||
Route::get('users/{user}/read-items', 'Auth\Users@readItemsOutOfStock');
|
||||
Route::resource('users', 'Auth\Users');
|
||||
Route::resource('roles', 'Auth\Roles');
|
||||
Route::resource('permissions', 'Auth\Permissions');
|
||||
|
Loading…
x
Reference in New Issue
Block a user