CustomerExcelchanges

This commit is contained in:
sayaliparab
2024-07-22 13:31:54 +05:30
parent 84b1dbcaa4
commit c8bb3ea999
3 changed files with 12 additions and 5 deletions

View File

@@ -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',
];
}
}

View File

@@ -1,5 +1,4 @@
<?php
namespace App\Exports;
use Maatwebsite\Excel\Concerns\FromCollection;
@@ -26,7 +25,7 @@ class customer_export_selected implements FromCollection, WithHeadings
Log::info('Fetching data for IDs: ' . implode(',', $this->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
];
}
}

View File

@@ -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);
}