diff --git a/app/Http/Controllers/Admin/ManageCustomerController.php b/app/Http/Controllers/Admin/ManageCustomerController.php index 449f541..e56993e 100644 --- a/app/Http/Controllers/Admin/ManageCustomerController.php +++ b/app/Http/Controllers/Admin/ManageCustomerController.php @@ -16,6 +16,7 @@ use App\Exports\CustomerExportSelected; use App\Models\ManageRestaurant; use App\Models\ManageState; use App\Models\RedeemRestaurant; +use App\Models\Subscriptions; use Illuminate\Support\Facades\Validator; use Illuminate\Validation\Rule; use Barryvdh\DomPDF\PDF as DomPDFPDF; @@ -34,21 +35,31 @@ class ManageCustomerController extends Controller Created at : 28 May 2024 Use : To Get User Page. */ - public function index() - { - try { - // Eager load the state relationship for all customers - $customers = IamPrincipal::where('principal_type_xid', 3) - ->with('state') - ->orderBy('created_at', 'desc') - ->get(); + public function index() + { + try { + $customers = IamPrincipal::with(['isSubscribed', 'state']) + ->where('principal_type_xid', 3) + ->orderBy('created_at', 'desc') + ->get(); - return view('Admin.pages.manage_users.manage_customer.customer', compact('customers')); - } catch (Exception $e) { - Log::error("Manage Voucher Page Not Load " . $e->getMessage()); - return jsonResponseWithErrorMessage(__('auth.something_went_wrong'), 500); + $dateTime = now(); + $formattedDateTime = $dateTime->format('Y-m-d H:i:s'); + + foreach ($customers as $customer) { + $customer->is_subscribed = $customer->isSubscribed->contains(function ($subscription) use ($formattedDateTime) { + return $subscription->subscription_status == 'active' && $subscription->next_payment_date >= $formattedDateTime; + }); + } + + return view('Admin.pages.manage_users.manage_customer.customer', compact('customers')); + } catch (Exception $e) { + Log::error("Manage Voucher Page Not Load " . $e->getMessage()); + return jsonResponseWithErrorMessage(__('auth.something_went_wrong'), 500); + } } - } + + /* Created By : Sayali Parab Created at : 28 May 2024 @@ -56,13 +67,14 @@ class ManageCustomerController extends Controller */ public function view_customer($id) { - - try { - $customers_data = IamPrincipal::with('state', 'contactMessages')->findOrFail($id); + $customers_data = IamPrincipal::with('state', 'contactMessages','isSubscribed')->findOrFail($id); if ($customers_data->contactMessages->isEmpty()) { Log::info('No contact messages found for customer with ID: ' . $id); } + if ($customers_data->isSubscribed->isEmpty()) { + Log::info('No payment history found for customer with ID: ' . $id); + } // return $customers_data; return view('Admin.pages.manage_users.manage_customer.view_customer_details', compact('customers_data')); } catch (Exception $e) { diff --git a/app/Models/IamPrincipal.php b/app/Models/IamPrincipal.php index 8b4590f..d701557 100644 --- a/app/Models/IamPrincipal.php +++ b/app/Models/IamPrincipal.php @@ -192,4 +192,9 @@ class IamPrincipal extends Authenticatable implements JWTSubject { return $this->hasMany(ManageContactus::class, 'principal_xid', 'id'); } + + public function isSubscribed() + { + return $this->hasMany(Subscriptions::class, 'iam_principal_xid', 'id'); + } } diff --git a/resources/views/Admin/pages/manage_users/manage_customer/customer.blade.php b/resources/views/Admin/pages/manage_users/manage_customer/customer.blade.php index d958231..50e1a2e 100644 --- a/resources/views/Admin/pages/manage_users/manage_customer/customer.blade.php +++ b/resources/views/Admin/pages/manage_users/manage_customer/customer.blade.php @@ -1,186 +1,187 @@ @extends('Admin.layouts.master') @section('content') -@php -$currentPage = 'manage-customer'; -@endphp - + /* Ensuring the table does not overflow */ + table { + width: 100%; + overflow-x: auto; + } + -
-
-
-
-
-
-
Manage Customers
-
-
+
+
+
+
+
+
+
Manage Customers
+
+
+
-
-
-
-
- @csrf - +
+
+ + @csrf + - - - -
-
+ + + + + - - - - + + - - - - - + - - - + + + + + - - - + + + - - @foreach ($customers as $customer) - - - - - + + - - + + @foreach ($customers as $customer) + + + + + + - - - + + + - - - - + + + - - - - + - + - - - - @endforeach - + + + + @endforeach + -
+
-
Sr noFirst NameLast NameSr noFirst NameUser IDEmail IdRedeemed RestaurantDate of birthPhone NumberLast NameSubscribe/UnsubscribeLocationUser IDEmail IdRedeemed RestaurantDate of birthPhone NumberAction
Subscribe/UnsubscribeLocation
-
- -
-
{{ $loop->iteration }}{{ $customer->first_name }} + Action
{{ $customer->last_name }}
+
+ +
+
{{ $loop->iteration }}{{ $customer->first_name }} + + {{ $customer->last_name }}{{ $customer->id }}{{ $customer->email_address }} - View - {{ $customer->id }}{{ $customer->email_address }} + View + {{ \Carbon\Carbon::parse($customer->date_of_birth)->format('m/d/Y') }}{{ $customer->phone_number }} -
- - +
{{ \Carbon\Carbon::parse($customer->date_of_birth)->format('m/d/Y') }}{{ $customer->phone_number }} + @if ($customer['is_subscribed']) + Subscribed + @else + Unsubscribed + @endif + {{ $customer->state ? $customer->state->name : 'No state assigned' }}{{ $customer->state ? $customer->state->name : 'No state assigned' }} - - View - - - Edit - - - - -
+ + View + + + Edit + + + + +
- +
+ + +
-
-
-