diff --git a/app/Http/Controllers/Customer/CartController.php b/app/Http/Controllers/Customer/CartController.php index 8f808b0..e4dfa93 100644 --- a/app/Http/Controllers/Customer/CartController.php +++ b/app/Http/Controllers/Customer/CartController.php @@ -49,7 +49,7 @@ class CartController extends Controller $operator = $request->param ?? 'add'; //delete, sub, add $customer = $request->user('customer'); - if (! $customer->allow_transaction) { + if (!$customer->allow_transaction) { $customer->carts()->delete(); return redirect()->back() diff --git a/app/Http/Middleware/HandleInertiaRequests.php b/app/Http/Middleware/HandleInertiaRequests.php index 2bdafef..823644a 100644 --- a/app/Http/Middleware/HandleInertiaRequests.php +++ b/app/Http/Middleware/HandleInertiaRequests.php @@ -45,6 +45,8 @@ class HandleInertiaRequests extends Middleware 'count_unread_notifications' => $notifications->where('is_read', Notification::UNREAD)->count(), 'deposit_notifications' => $notifications->where('type', Notification::TYPE_DEPOSIT) ->where('is_read', Notification::UNREAD)->limit(10)->get(), + 'stock_notifications' => $notifications->where('type', Notification::TYPE_VOUCHER_STOCK) + ->where('is_read', Notification::UNREAD)->limit(10)->get(), ]); } } diff --git a/app/Models/Notification.php b/app/Models/Notification.php index 9447627..19e4dfc 100644 --- a/app/Models/Notification.php +++ b/app/Models/Notification.php @@ -9,6 +9,8 @@ class Notification extends Model { const TYPE_DEPOSIT = 'deposit'; + const TYPE_VOUCHER_STOCK = 'voucher_stock'; + const UNREAD = 0; const READ = 1; diff --git a/app/Models/Voucher.php b/app/Models/Voucher.php index 4496abc..8063a28 100644 --- a/app/Models/Voucher.php +++ b/app/Models/Voucher.php @@ -2,6 +2,7 @@ namespace App\Models; +use App\Events\NotificationEvent; use App\Services\GeneralService; use Illuminate\Database\Eloquent\Casts\Attribute; @@ -173,9 +174,24 @@ class Voucher extends Model $treshold = $this->locationProfile->min_stock; if ($count <= $treshold) { - Notification::create([ + $notification = Notification::create([ 'entity_type' => User::class, - 'description' => 'stok voucher '.$this->locationProfile->name.'tersisa : '.$count, + 'description' => 'stok voucher ' . $this->locationProfile->name . ' tersisa : ' . $count, + 'url' => route('voucher.profile', $this->locationProfile->location_id), + 'type' => Notification::TYPE_VOUCHER_STOCK, + ]); + + NotificationEvent::dispatch([ + 'id' => $notification->id, + 'description' => $notification->description, + 'url' => $notification->url, + 'type' => Notification::TYPE_VOUCHER_STOCK, + 'format_created_at' => now()->translatedFormat('d F Y H:i:s'), + 'stock_notifications' => Notification::where('entity_type', User::class) + ->where('type', Notification::TYPE_VOUCHER_STOCK) + ->where('is_read', Notification::UNREAD)->limit(10) + ->orderBy('created_at', 'desc') + ->get(), ]); } } diff --git a/resources/assets/warning.mp3 b/resources/assets/warning.mp3 new file mode 100644 index 0000000..b15e525 Binary files /dev/null and b/resources/assets/warning.mp3 differ diff --git a/resources/js/Layouts/AuthenticatedLayout.jsx b/resources/js/Layouts/AuthenticatedLayout.jsx index 06d8e7e..8d65d51 100644 --- a/resources/js/Layouts/AuthenticatedLayout.jsx +++ b/resources/js/Layouts/AuthenticatedLayout.jsx @@ -10,6 +10,7 @@ import Dropdown from '@/Components/Defaults/Dropdown' import SidebarNav from './Partials/SidebarNav' import NotificationContent from './Partials/NotificationContent' import NotificationDeposit from './Partials/NotificationDeposit' +import NotificationStock from './Partials/NotificationStock' const customTheme = { button: { @@ -63,6 +64,9 @@ export default function Authenticated({