From c8bb3ea9995440e6eb8519fce2f4133fc34d62c5 Mon Sep 17 00:00:00 2001 From: sayaliparab Date: Mon, 22 Jul 2024 13:31:54 +0530 Subject: [PATCH] CustomerExcelchanges --- app/Exports/customer_export.php | 6 +++++- app/Exports/customer_export_selected.php | 8 +++++--- app/Models/IamPrincipal.php | 3 ++- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/app/Exports/customer_export.php b/app/Exports/customer_export.php index 56be1e1..da2ceeb 100644 --- a/app/Exports/customer_export.php +++ b/app/Exports/customer_export.php @@ -15,6 +15,7 @@ class customer_export implements FromCollection, WithHeadings public function collection() { $customers = IamPrincipal::where('principal_type_xid', 3) + ->with(['isSubscribed', 'state']) ->select( 'id', 'first_name', @@ -28,6 +29,7 @@ class customer_export implements FromCollection, WithHeadings $serial = 1; return $customers->map(function ($customer) use (&$serial) { + $isSubscribed = $customer->isSubscribed->count() > 0 ? 'Subscribed' : 'Unsubscribed'; return [ 'Sr No.' => $serial++, // Increment serial number 'id' => $customer->id, @@ -35,8 +37,9 @@ class customer_export implements FromCollection, WithHeadings 'last_name' => $customer->last_name, 'email_address' => $customer->email_address, 'date_of_birth' => \Carbon\Carbon::parse($customer->date_of_birth)->format('m/d/Y'), - 'state_xid' => $customer->state->name ?? '', // Access the state name and handle null + 'state_name' => $customer->state->name ?? '', // Access the state name and handle null 'phone_number' => $customer->phone_number, + 'subscription_status' => $isSubscribed, // Add the subscription status ]; }); } @@ -53,6 +56,7 @@ class customer_export implements FromCollection, WithHeadings 'Date of Birth', 'State Name', 'Phone Number', + 'Subscription Status', ]; } } diff --git a/app/Exports/customer_export_selected.php b/app/Exports/customer_export_selected.php index e8d9b69..5a3a6eb 100644 --- a/app/Exports/customer_export_selected.php +++ b/app/Exports/customer_export_selected.php @@ -1,5 +1,4 @@ ids)); $selected_customers = IamPrincipal::whereIn('id', $this->ids) - ->with('state:id,name') // Eager load the state relationship + ->with(['state:id,name', 'isSubscribed']) // Eager load the state and subscription relationships ->orderBy('id', 'desc') ->select( 'id', @@ -41,6 +40,7 @@ class customer_export_selected implements FromCollection, WithHeadings $serial = 1; $mappedCustomers = $selected_customers->map(function ($customer) use (&$serial) { + $isSubscribed = $customer->isSubscribed->isNotEmpty() ? 'Subscribed' : 'Unsubscribed'; return [ 'Sr No.' => $serial++, // Increment serial number 'id' => $customer->id, @@ -50,6 +50,7 @@ class customer_export_selected implements FromCollection, WithHeadings 'date_of_birth' => \Carbon\Carbon::parse($customer->date_of_birth)->format('m/d/Y'), // Format the date 'state_xid' => $customer->state->name ?? '', // Access the state name and handle null 'phone_number' => $customer->phone_number, + 'subscription_status' => $isSubscribed, // Add the subscription status ]; }); @@ -69,7 +70,8 @@ class customer_export_selected implements FromCollection, WithHeadings 'Email Address', 'Date of Birth', 'State Name', - 'Phone Number' + 'Phone Number', + 'Subscription Status' // Add the heading for subscription status ]; } } diff --git a/app/Models/IamPrincipal.php b/app/Models/IamPrincipal.php index 4365666..b260667 100644 --- a/app/Models/IamPrincipal.php +++ b/app/Models/IamPrincipal.php @@ -172,7 +172,8 @@ class IamPrincipal extends Authenticatable implements JWTSubject public function isSubscribed() { - return $this->hasMany(Subscriptions::class, 'iam_principal_xid', 'id'); + return $this->hasMany(Subscriptions::class, 'iam_principal_xid', 'id')->where('is_cancelled_subscription',0); + }