diff --git a/app/Http/Controllers/User/UserController.php b/app/Http/Controllers/User/UserController.php index 7b838c7..e4daa62 100644 --- a/app/Http/Controllers/User/UserController.php +++ b/app/Http/Controllers/User/UserController.php @@ -123,20 +123,54 @@ class UserController extends Controller } // New page: list of ThankCards received by the current user - public function receivedCards(Request $request): View + public function receivedCards(Request $request) { $selectedMonth = $request->input('month', Carbon::now()->format('Y-m')); $user = Auth::user(); - $data = $this->userService->getReceivedPageData($user, $selectedMonth); + + if ($request->ajax() || $request->wantsJson()) { + $offset = (int) $request->input('offset', 0); + $limit = 12; + $data = $this->userService->getReceivedPageData($user, $selectedMonth, $limit, $offset); + + $html = view('user.partials.received_cards_feed', ['cards' => $data['cards']])->render(); + return response()->json([ + 'success' => true, + 'html' => $html, + 'hasMore' => $data['hasMore'], + 'totalCards' => $data['totalCards'], + 'totalSenders' => $data['totalSenders'] + ]); + } + + $data = $this->userService->getReceivedPageData($user, $selectedMonth, 12, 0); + $data['selectedMonth'] = $selectedMonth; return view('user.received', $data); } // New page: list of ThankCards sent by the current user - public function sentCards(Request $request): View + public function sentCards(Request $request) { $selectedMonth = $request->input('month', Carbon::now()->format('Y-m')); $user = Auth::user(); - $data = $this->userService->getSentPageData($user, $selectedMonth); + + if ($request->ajax() || $request->wantsJson()) { + $offset = (int) $request->input('offset', 0); + $limit = 12; + $data = $this->userService->getSentPageData($user, $selectedMonth, $limit, $offset); + + $html = view('user.partials.sent_cards_feed', ['cards' => $data['cards']])->render(); + return response()->json([ + 'success' => true, + 'html' => $html, + 'hasMore' => $data['hasMore'], + 'totalCards' => $data['totalCards'], + 'totalReceivers' => $data['totalReceivers'] + ]); + } + + $data = $this->userService->getSentPageData($user, $selectedMonth, 12, 0); + $data['selectedMonth'] = $selectedMonth; return view('user.sent', $data); } diff --git a/app/Services/User/UserService.php b/app/Services/User/UserService.php index d7dd5cf..ee8876f 100644 --- a/app/Services/User/UserService.php +++ b/app/Services/User/UserService.php @@ -257,6 +257,7 @@ class UserService implements UserServiceInterface ->whereBetween('date', [$start, $end]) ->where('received', '>', 0) ->skip($offset + $limit) + ->take(1) ->exists(); return [ @@ -293,6 +294,7 @@ class UserService implements UserServiceInterface ->whereBetween('date', [$start, $end]) ->where('sent', '>', 0) ->skip($offset + $limit) + ->take(1) ->exists(); return [ diff --git a/resources/views/user/partials/received_cards_feed.blade.php b/resources/views/user/partials/received_cards_feed.blade.php new file mode 100644 index 0000000..b77135f --- /dev/null +++ b/resources/views/user/partials/received_cards_feed.blade.php @@ -0,0 +1,41 @@ +@foreach ($cards as $c) +
+
+
+ + 💜 Từ + + + {{ $c->received }} Thẻ + +
+
+
+ @if($c->senderUser) + + @else +
+ {{ strtoupper(substr($c->sender ?? 'U', 0, 1)) }} +
+ @endif +
+
+

+ {{ $c->senderUser ? $c->senderUser->name : ($c->sender ?? '---') }} +

+

+ MSNV: {{ $c->senderUser ? $c->senderUser->msnv : ($c->sender ?? '---') }} +

+

+ {{ $c->senderUser ? $c->senderUser->mail : '---' }} +

+
+
+
+ +
+ Ngày nhận: + {{ \Carbon\Carbon::parse($c->date)->format('d/m/Y') }} +
+
+@endforeach diff --git a/resources/views/user/partials/sent_cards_feed.blade.php b/resources/views/user/partials/sent_cards_feed.blade.php new file mode 100644 index 0000000..e42ce54 --- /dev/null +++ b/resources/views/user/partials/sent_cards_feed.blade.php @@ -0,0 +1,41 @@ +@foreach ($cards as $c) +
+
+
+ + 💌 Gửi tới + + + {{ $c->sent }} Thẻ + +
+
+
+ @if($c->receiverUser) + + @else +
+ {{ strtoupper(substr($c->receiver ?? 'U', 0, 1)) }} +
+ @endif +
+
+

+ {{ $c->receiverUser ? $c->receiverUser->name : ($c->receiver ?? '---') }} +

+

+ MSNV: {{ $c->receiverUser ? $c->receiverUser->msnv : ($c->receiver ?? '---') }} +

+

+ {{ $c->receiverUser ? $c->receiverUser->mail : '---' }} +

+
+
+
+ +
+ Ngày gửi: + {{ \Carbon\Carbon::parse($c->date)->format('d/m/Y') }} +
+
+@endforeach diff --git a/resources/views/user/received.blade.php b/resources/views/user/received.blade.php index 1885022..eaef51d 100644 --- a/resources/views/user/received.blade.php +++ b/resources/views/user/received.blade.php @@ -10,60 +10,164 @@

Các lời cảm ơn mà đồng nghiệp đã gửi đến bạn.

-
-
- - - + +
+
+
+ + - -
- - -
-
- +
- - @if (!empty($cards) && $cards->count()) -
- @foreach ($cards as $c) -
-
- @if($c->senderUser) - -
-

{{ $c->senderUser->name }}

-

MSNV: {{ $c->senderUser->msnv }}

-

{{ $c->senderUser->mail }}

-
- @else -
- {{ strtoupper(substr($c->sender ?? 'S', 0, 1)) }} -
-
-

Từ: {{ $c->sender ?? '---' }}

-

MSNV: {{ $c->sender ?? '---' }}

-
- @endif -
-
- {{ \Carbon\Carbon::parse($c->date)->format('d/m/Y') }} - - +{{ $c->received }} thẻ - -
-
- @endforeach + +
+
+
+ + + +
+
+

Tổng số thanks nhận trong tháng {{ \Carbon\Carbon::parse($selectedMonth)->format('n/Y') }}

+

{{ $totalCards }}

+
- @else - - @endif + +
+
+ + + +
+
+

Số người đã gửi tới

+

{{ $totalSenders }}

+
+
+
+ + +
+
+ ❤️ +
+

Chưa nhận được Thank Card nào

+

Bạn chưa nhận được Thank Card nào trong tháng này.

+
+ + +
+ @include('user.partials.received_cards_feed', ['cards' => $cards]) +
+ + +
+ +
+
@endsection + +@push('scripts') + +@endpush diff --git a/resources/views/user/sent.blade.php b/resources/views/user/sent.blade.php index ee1f9f7..b4ff75c 100644 --- a/resources/views/user/sent.blade.php +++ b/resources/views/user/sent.blade.php @@ -9,60 +9,168 @@

📨 Thanks đã gửi

Các lời cảm ơn bạn đã gửi tới đồng nghiệp.

-
-
- - - - - -
-
-
- + +
+ +
+ + +
- +
- - @if (!empty($cards) && $cards->count()) -
- @foreach ($cards as $c) -
-
- @if($c->receiverUser) - -
-

{{ $c->receiverUser->name }}

-

MSNV: {{ $c->receiverUser->msnv }}

-

{{ $c->receiverUser->mail }}

-
- @else -
- {{ strtoupper(substr($c->receiver ?? 'R', 0, 1)) }} -
-
-

Tới: {{ $c->receiver ?? '---' }}

-

MSNV: {{ $c->receiver ?? '---' }}

-
- @endif -
-
- {{ \Carbon\Carbon::parse($c->date)->format('d/m/Y') }} - - -{{ $c->sent }} thẻ - -
-
- @endforeach + +
+
+
+ + + +
+
+

Tổng số thanks gửi trong tháng {{ \Carbon\Carbon::parse($selectedMonth)->format('n/Y') }}

+

{{ $totalCards }}

+
- @else - - @endif + +
+
+ + + +
+
+

Số người đã nhận

+

{{ $totalReceivers }}

+
+
+
+ + +
+
+ 💌 +
+

Chưa gửi Thank Card nào

+

Bạn chưa gửi Thank Card nào trong tháng này.

+ + Gửi Thank Card ngay + +
+ + +
+ @include('user.partials.sent_cards_feed', ['cards' => $cards]) +
+ + +
+ +
+
@endsection + +@push('scripts') + +@endpush