out of stock notification
This commit is contained in:
@ -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;
|
||||
|
Reference in New Issue
Block a user