{page}
+{page}
diff --git a/TODO.md b/TODO.md
index 6a82e0f..5ac1453 100644
--- a/TODO.md
+++ b/TODO.md
@@ -18,11 +18,7 @@
- [x] Setting Bonus Coin (memasukan amount bonus coin yang didapat dengan level dan harga voucher) - bonus coin
- [x] Voucher Sales (index: customer, total, jumlah voucher, detail: customer, list voucher, payment)
- [x] Dashboard (gafik hasil penjualan : disorting tanggal, lokasi dan customer)
- [total voucher] [total customer] [total customer verified] [total deposit]
- [total voucher terjual bulan xxx] [jumlah voucher terjual bulan xxx] [total voucher terjual hari ini ] [jumlah voucher terjual hari ini]
- [cart penjualan per tanggal, pilih range tanggal (range default 7), bisa filter by lokasi dan customer]
- [list customer dengan total beli hari ini]
-- [ ] Notification (manual deposit, deposit success, stock voucher, sale)
+- [x] Notification ([x]manual deposit, [x]deposit success, [x]stock voucher, [x]sale)
- [ ] View Customer Coin History
- [ ] Voucher - harga per level
- [ ] Voucher - harga coin
@@ -48,5 +44,5 @@
- [x] Customer View Coin History
- [x] Verified Akun
- [x] Paylater: index paylater, payment cart, deposite repay
+- [x] Notification ([x] purchase success, [x] deposit success)
- [ ] Coin Explorer: list voucher, modal voucher to excange
-- [ ] Notification (purchase success, deposit success)
diff --git a/app/Http/Controllers/Api/NotificationController.php b/app/Http/Controllers/Api/NotificationController.php
new file mode 100644
index 0000000..8e9c15e
--- /dev/null
+++ b/app/Http/Controllers/Api/NotificationController.php
@@ -0,0 +1,19 @@
+id == null) {
+ (new Notification())->mark_all_as_read();
+ return;
+ }
+ $notif->mark_as_read();
+ }
+}
diff --git a/app/Http/Controllers/Customer/CartController.php b/app/Http/Controllers/Customer/CartController.php
index 65302c8..08cdd56 100644
--- a/app/Http/Controllers/Customer/CartController.php
+++ b/app/Http/Controllers/Customer/CartController.php
@@ -155,8 +155,10 @@ class CartController extends Controller
]);
$voucher->update(['is_sold' => Voucher::SOLD]);
+ $voucher->check_stock_notification();
}
}
+ $sale->create_notification();
$bonus = CoinReward::where('customer_level_id', $customer->customer_level_id)
->where('amount_buy', '<=', $total)
diff --git a/app/Http/Controllers/Customer/DepositController.php b/app/Http/Controllers/Customer/DepositController.php
index 06686ed..3c9925c 100644
--- a/app/Http/Controllers/Customer/DepositController.php
+++ b/app/Http/Controllers/Customer/DepositController.php
@@ -65,6 +65,7 @@ class DepositController extends Controller
$deposit->update(['payment_token' => $token]);
}
+ $deposit->create_notification();
DB::commit();
@@ -97,6 +98,8 @@ class DepositController extends Controller
'is_valid' => DepositHistory::STATUS_WAIT_APPROVE,
]);
+ $deposit->create_notification();
+
session()->flash('message', ['type' => 'success', 'message' => 'Upload berhasil, silahkan tunggu untuk approve']);
}
@@ -147,6 +150,8 @@ class DepositController extends Controller
$deposit->update_customer_balance();
$customer = Customer::find($deposit->customer_id);
$customer->repayPaylater($deposit);
+ $deposit->create_notification();
+ $deposit->create_notification_user();
} elseif ($request->transaction_status == 'pending') {
$deposit->fill(['payment_status' => DepositHistory::STATUS_WAIT_PAYMENT]);
} else {
diff --git a/app/Http/Controllers/Customer/HomeController.php b/app/Http/Controllers/Customer/HomeController.php
index 450071d..dad4082 100644
--- a/app/Http/Controllers/Customer/HomeController.php
+++ b/app/Http/Controllers/Customer/HomeController.php
@@ -6,6 +6,7 @@ use App\Http\Controllers\Controller;
use App\Models\Banner;
use App\Models\Info;
use App\Models\Location;
+use App\Models\Notification;
use App\Models\Voucher;
use Illuminate\Http\Request;
@@ -40,4 +41,13 @@ class HomeController extends Controller
'banner' => $banner,
]);
}
+
+ public function notification()
+ {
+ Notification::where('entity_id', auth()->id())->where('is_read', Notification::UNREAD)->update(['is_read' => Notification::READ]);
+
+ return inertia('Index/Notification', [
+ 'notification' => Notification::where('entity_id', auth()->id())->orderBy('updated_at', 'desc')->paginate()
+ ]);
+ }
}
diff --git a/app/Http/Controllers/DepositController.php b/app/Http/Controllers/DepositController.php
index 3c9ee28..cfd2f4f 100644
--- a/app/Http/Controllers/DepositController.php
+++ b/app/Http/Controllers/DepositController.php
@@ -59,6 +59,7 @@ class DepositController extends Controller
$customer = Customer::find($deposit->customer_id);
$customer->repayPaylater($deposit);
+ $deposit->create_notification_user();
}
DB::commit();
diff --git a/app/Http/Controllers/NotificationController.php b/app/Http/Controllers/NotificationController.php
new file mode 100644
index 0000000..77dc325
--- /dev/null
+++ b/app/Http/Controllers/NotificationController.php
@@ -0,0 +1,20 @@
+orderBy('is_read', 'asc')
+ ->orderBy('created_at', 'desc');
+
+ return inertia('Notification/Index', [
+ 'query' => $query->paginate(),
+ ]);
+ }
+}
diff --git a/app/Http/Controllers/VoucherController.php b/app/Http/Controllers/VoucherController.php
index 58eb385..51b2277 100644
--- a/app/Http/Controllers/VoucherController.php
+++ b/app/Http/Controllers/VoucherController.php
@@ -20,6 +20,10 @@ class VoucherController extends Controller
->orWhere('profile', 'like', "%$request->q%");
}
+ if ($request->location_id != '') {
+ $query->where('location_id', $request->location_id);
+ }
+
return inertia('Voucher/Index', [
'query' => $query->paginate(),
]);
diff --git a/app/Http/Middleware/HandleInertiaCustomerRequests.php b/app/Http/Middleware/HandleInertiaCustomerRequests.php
index 4595f7b..9a32b4e 100644
--- a/app/Http/Middleware/HandleInertiaCustomerRequests.php
+++ b/app/Http/Middleware/HandleInertiaCustomerRequests.php
@@ -2,6 +2,7 @@
namespace App\Http\Middleware;
+use App\Models\Notification;
use Illuminate\Http\Request;
use Inertia\Middleware;
@@ -37,6 +38,11 @@ class HandleInertiaCustomerRequests extends Middleware
}
}
+ $notification_count = 0;
+ if (auth('customer')->check()) {
+ $notification_count = Notification::where('entity_id', auth()->id())->where('is_read', Notification::UNREAD)->count();
+ }
+
return array_merge(parent::share($request), [
'app_name' => env('APP_NAME', 'App Name'),
'auth' => [
@@ -45,7 +51,7 @@ class HandleInertiaCustomerRequests extends Middleware
'flash' => [
'message' => fn () => $request->session()->get('message') ?? ['type' => null, 'message' => null],
],
- 'notification_count' => 0,
+ 'notification_count' => $notification_count,
'cart_count' => $cart_count,
]);
}
diff --git a/app/Http/Middleware/HandleInertiaRequests.php b/app/Http/Middleware/HandleInertiaRequests.php
index 592894d..5c113b2 100644
--- a/app/Http/Middleware/HandleInertiaRequests.php
+++ b/app/Http/Middleware/HandleInertiaRequests.php
@@ -2,6 +2,7 @@
namespace App\Http\Middleware;
+use App\Models\Notification;
use Illuminate\Http\Request;
use Inertia\Middleware;
@@ -38,6 +39,8 @@ class HandleInertiaRequests extends Middleware
],
'app_name' => env('APP_NAME', 'App Name'),
'csrf_token' => csrf_token(),
+ 'notifications' => Notification::where('entity_type', \App\Models\User::class)->orderBy('created_at', 'desc')->limit(10)->get(),
+ 'count_unread_notifications' => Notification::where('entity_type', \App\Models\User::class)->where('is_read', Notification::UNREAD)->count(),
]);
}
}
diff --git a/app/Models/DepositHistory.php b/app/Models/DepositHistory.php
index 2766d68..8d12f99 100644
--- a/app/Models/DepositHistory.php
+++ b/app/Models/DepositHistory.php
@@ -105,4 +105,33 @@ class DepositHistory extends Model
$customer = Customer::find($this->customer_id);
$customer->update(['deposit_balance' => $customer->deposit_balance + $this->debit - $this->credit]);
}
+
+ public function create_notification()
+ {
+ if ($this->payment_channel == Setting::PAYMENT_MANUAL) {
+ $status = "";
+ if ($this->is_valid == self::STATUS_WAIT_APPROVE) {
+ $status = " (bukti bayar di upload, membutuhkan konfirmasi)";
+ }
+ Notification::create([
+ 'entity_type' => User::class,
+ 'description' => $this->customer->fullname . ' melakukan deposit manual sebesar : ' . $this->amount . $status,
+ ]);
+ }
+
+ if ($this->payment_channel == Setting::PAYMENT_MIDTRANS) {
+ Notification::create([
+ 'entity_type' => User::class,
+ 'description' => $this->customer->fullname . ' melakukan deposit via midtrans sebesar : ' . $this->amount,
+ ]);
+ }
+ }
+
+ public function create_notification_user()
+ {
+ Notification::create([
+ 'entity_id' => $this->customer_id,
+ 'description' => 'Deposit ' . $this->description . ' sebesar ' . $this->amount . ' sudah sukses diterima',
+ ]);
+ }
}
diff --git a/app/Models/Notification.php b/app/Models/Notification.php
index 8b9a4c5..bef61c6 100644
--- a/app/Models/Notification.php
+++ b/app/Models/Notification.php
@@ -2,12 +2,39 @@
namespace App\Models;
+use Illuminate\Database\Eloquent\Casts\Attribute;
+use Illuminate\Support\Carbon;
+
class Notification extends Model
{
+ const UNREAD = 0;
+ const READ = 1;
+
protected $fillable = [
'entity_type',
'entity_id',
'description',
'is_read',
];
+
+ protected $appends = [
+ 'format_created_at'
+ ];
+
+ public function mark_as_read()
+ {
+ $this->update(['is_read' => self::READ]);
+ }
+
+ public function mark_all_as_read()
+ {
+ Notification::where('is_read', self::UNREAD)->where('entity_type', User::class)->update(['is_read' => self::READ]);
+ }
+
+ public function formatCreatedAt(): Attribute
+ {
+ return Attribute::make(get: function () {
+ return Carbon::parse($this->created_at)->locale('id')->translatedFormat('d F Y H:i:s');
+ });
+ }
}
diff --git a/app/Models/Sale.php b/app/Models/Sale.php
index a6ffbb5..2b9d35c 100644
--- a/app/Models/Sale.php
+++ b/app/Models/Sale.php
@@ -67,4 +67,17 @@ class Sale extends Model
return 'Rp' . number_format($this->amount, 0, ',', '.');
});
}
+
+ public function create_notification()
+ {
+ Notification::create([
+ 'entity_type' => User::class,
+ 'description' => $this->customer->fullname . ' melakukan pembelian ' . $this->items()->count() . ' voucher sebesar ' . $this->display_amount,
+ ]);
+
+ Notification::create([
+ 'entity_id' => auth()->id(),
+ 'description' => 'Transaksi pembelian anda #' . $this->code . ' sebesar ' . $this->display_amount . ' berhasil',
+ ]);
+ }
}
diff --git a/app/Models/Voucher.php b/app/Models/Voucher.php
index 6fd1369..aa39cff 100644
--- a/app/Models/Voucher.php
+++ b/app/Models/Voucher.php
@@ -98,4 +98,21 @@ class Voucher extends Model
return $voucher;
}
+
+ public function check_stock_notification()
+ {
+ $count = Voucher::where([
+ ['is_sold', '=', self::UNSOLD],
+ ['batch_id', '=', $this->batch_id]
+ ])->count();
+
+ $treshold = Setting::getByKey('VOUCHER_STOCK_NOTIFICATION');
+
+ if ($count <= $treshold) {
+ Notification::create([
+ 'entity_type' => User::class,
+ 'description' => "stok voucher " . $this->location->name . " ( " . $this->profile . " ) " . "tersisa : " . $count,
+ ]);
+ }
+ }
}
diff --git a/resources/js/Components/Defaults/Dropdown.jsx b/resources/js/Components/Defaults/Dropdown.jsx
index 085d884..bbd704a 100644
--- a/resources/js/Components/Defaults/Dropdown.jsx
+++ b/resources/js/Components/Defaults/Dropdown.jsx
@@ -1,50 +1,60 @@
-import React, { useState, useContext, Fragment } from 'react';
-import { Link } from '@inertiajs/react';
-import { Transition } from '@headlessui/react';
+import React, { useState, useContext, Fragment } from 'react'
+import { Link } from '@inertiajs/react'
+import { Transition } from '@headlessui/react'
-const DropDownContext = React.createContext();
+const DropDownContext = React.createContext()
const Dropdown = ({ children }) => {
- const [open, setOpen] = useState(false);
+ const [open, setOpen] = useState(false)
const toggleOpen = () => {
- setOpen((previousState) => !previousState);
- };
+ setOpen((previousState) => !previousState)
+ }
return (
{page}
+{page}
+ Deskripsi + | ++ Dibaca + | ++ |
---|---|---|
+ {notification.description} + | ++ {+notification.is_read === 1 + ? 'Sudah dibaca' + : 'Belum dibaca'} + | +
+
+ handleNotification(
+ notification
+ )
+ }
+ >
+ Tandai dibaca
+
+ |
+