Recent
This commit is contained in:
@@ -2,43 +2,49 @@
|
||||
|
||||
namespace App\Exports;
|
||||
|
||||
use Maatwebsite\Excel\Concerns\FromCollection;
|
||||
use Maatwebsite\Excel\Concerns\FromArray;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadings;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
class DashboardExportUser implements FromCollection, WithHeadings
|
||||
class DashboardExportUser implements FromArray, WithHeadings
|
||||
{
|
||||
protected $recentTransactions;
|
||||
protected $data;
|
||||
|
||||
public function __construct(array $recentTransactions)
|
||||
public function __construct(array $data)
|
||||
{
|
||||
$this->recentTransactions = $recentTransactions;
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
public function collection()
|
||||
public function array(): array
|
||||
{
|
||||
$serial = 1;
|
||||
$mappedTransactions = collect($this->recentTransactions)->map(function ($transaction) use (&$serial) {
|
||||
return array_map(function ($transaction) {
|
||||
return [
|
||||
'Sr No.' => $serial++, // Increment serial number
|
||||
'Name' => $transaction['subscription']['first_name'] . ' ' . $transaction['subscription']['last_name'],
|
||||
'Customer Id' => $transaction['subscription']['id'],
|
||||
'ID' => $transaction['id'],
|
||||
'Customer Name' => $transaction['iam_principal']['first_name'] . ' ' . $transaction['iam_principal']['last_name'],
|
||||
'Customer ID' => $transaction['iam_principal']['id'],
|
||||
'Amount' => $transaction['amount'],
|
||||
'Payment Details' => $transaction['stripe_customer_id'], // Adjust as needed
|
||||
'Product Name' => $transaction['subscription_product']['product_name'],
|
||||
'Product Details' => $transaction['subscription_product']['product_details'],
|
||||
'Subscription Status' => $transaction['subscription_status'],
|
||||
'Subscription Period Start' => $transaction['current_period_start'],
|
||||
'Subscription Period End' => $transaction['current_period_end'],
|
||||
'Next Payment Date' => $transaction['next_payment_date'],
|
||||
];
|
||||
});
|
||||
|
||||
return new Collection($mappedTransactions);
|
||||
}, $this->data);
|
||||
}
|
||||
|
||||
public function headings(): array
|
||||
{
|
||||
return [
|
||||
'Sr No.',
|
||||
'Name',
|
||||
'Customer Id',
|
||||
'ID',
|
||||
'Customer Name',
|
||||
'Customer ID',
|
||||
'Amount',
|
||||
'Payment Details',
|
||||
'Product Name',
|
||||
'Product Details',
|
||||
'Subscription Status',
|
||||
'Subscription Period Start',
|
||||
'Subscription Period End',
|
||||
'Next Payment Date'
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,13 +13,13 @@ class DashboardSelectedExportUser implements FromCollection, WithHeadings
|
||||
|
||||
public function __construct($ids)
|
||||
{
|
||||
$this->ids = explode(',', $ids);
|
||||
$this->ids = $ids; // Expecting $ids to be an array
|
||||
}
|
||||
|
||||
public function collection()
|
||||
{
|
||||
$selectedTransactions = Subscriptions::whereIn('id', $this->ids)
|
||||
->with('subscription')
|
||||
->with(['iamPrincipal', 'subscriptionProduct'])
|
||||
->get()
|
||||
->toArray();
|
||||
|
||||
@@ -27,13 +27,17 @@ class DashboardSelectedExportUser implements FromCollection, WithHeadings
|
||||
$mappedTransactions = collect($selectedTransactions)->map(function ($transaction) use (&$serial) {
|
||||
return [
|
||||
'Sr No.' => $serial++, // Increment serial number
|
||||
'Name' => $transaction['subscription']['first_name'] . ' ' . $transaction['subscription']['last_name'],
|
||||
'Customer Id' => $transaction['subscription']['id'],
|
||||
'Name' => ($transaction['iam_principal']['first_name'] ?? '') . ' ' . ($transaction['iam_principal']['last_name'] ?? ''),
|
||||
'Customer Id' => $transaction['iam_principal']['id'] ?? '',
|
||||
'Product Name' => $transaction['subscription_product']['product_name'] ?? '',
|
||||
'Product Detail' => $transaction['subscription_product']['product_details'] ?? '',
|
||||
'Amount' => $transaction['amount'],
|
||||
'Payment Details' => $transaction['stripe_customer_id'], // Adjust as needed
|
||||
|
||||
'Payment Details' => $transaction['stripe_customer_id'],
|
||||
'Subscription status' => $transaction['subscription_status'],
|
||||
'Subscription Start Date' => $transaction['current_period_start'],
|
||||
'Subscription End Date' => $transaction['current_period_end'],
|
||||
'Next Payment Date' => $transaction['next_payment_date']
|
||||
];
|
||||
|
||||
});
|
||||
|
||||
return new Collection($mappedTransactions);
|
||||
@@ -45,8 +49,14 @@ class DashboardSelectedExportUser implements FromCollection, WithHeadings
|
||||
'Sr No.',
|
||||
'Name',
|
||||
'Customer Id',
|
||||
'Product Name',
|
||||
'Product Detail',
|
||||
'Amount',
|
||||
'Payment Details',
|
||||
'Subscription status',
|
||||
'Subscription Start Date',
|
||||
'Subscription End Date',
|
||||
'Next Payment Date'
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -164,20 +164,42 @@ class DashboardController extends Controller
|
||||
*/
|
||||
|
||||
|
||||
// public function exportRecentTransactions(Request $request)
|
||||
// {
|
||||
// try {
|
||||
// if ($request->has('all_id')) {
|
||||
// $recentTransaction = Subscriptions::with('subscription')->get()->toArray();
|
||||
// return Excel::download(new DashboardExportUser($recentTransaction), 'recent_transactions.xlsx');
|
||||
// }
|
||||
|
||||
// $ids = $request->input('selected_id');
|
||||
// $fileName = 'selected_customer_transaction_data.xlsx';
|
||||
// return Excel::download(new DashboardSelectedExportUser($ids), $fileName);
|
||||
// } catch (\Exception $e) {
|
||||
// return response()->json(['error' => 'Export failed. Something went wrong.'], 500);
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
public function exportRecentTransactions(Request $request)
|
||||
{
|
||||
try {
|
||||
if ($request->has('all_id')) {
|
||||
$recentTransaction = Subscriptions::with('subscription')->get()->toArray();
|
||||
$recentTransaction = Subscriptions::with(['iamPrincipal', 'subscriptionProduct'])->get()->toArray();
|
||||
return Excel::download(new DashboardExportUser($recentTransaction), 'recent_transactions.xlsx');
|
||||
}
|
||||
|
||||
|
||||
$ids = $request->input('selected_id');
|
||||
if (!is_array($ids)) {
|
||||
$ids = explode(',', $ids);
|
||||
}
|
||||
$fileName = 'selected_customer_transaction_data.xlsx';
|
||||
return Excel::download(new DashboardSelectedExportUser($ids), $fileName);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['error' => 'Export failed. Something went wrong.'], 500);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ use PDF;
|
||||
class ManageCustomerController extends Controller
|
||||
{
|
||||
|
||||
/*
|
||||
/*
|
||||
Created By : Sayali Parab
|
||||
Created at : 28 May 2024
|
||||
Use : To Get User Page.
|
||||
@@ -60,7 +60,7 @@ class ManageCustomerController extends Controller
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
/*
|
||||
Created By : Sayali Parab
|
||||
Created at : 28 May 2024
|
||||
Use : To Get Passport Page.
|
||||
@@ -82,7 +82,7 @@ class ManageCustomerController extends Controller
|
||||
return jsonResponseWithErrorMessage(__('auth.something_went_wrong'), 500);
|
||||
}
|
||||
}
|
||||
/*
|
||||
/*
|
||||
Created By : Sayali Parab
|
||||
Created at : 28 May 2024
|
||||
Use : To Get Customer data.
|
||||
@@ -100,7 +100,7 @@ class ManageCustomerController extends Controller
|
||||
return jsonResponseWithErrorMessage(__('auth.something_went_wrong'), 500);
|
||||
}
|
||||
}
|
||||
/*
|
||||
/*
|
||||
Created By : Sayali Parab
|
||||
Created at : 28 May 2024
|
||||
Use : To Update Customer Form.
|
||||
@@ -213,7 +213,7 @@ class ManageCustomerController extends Controller
|
||||
return response()->json(['success' => false, 'status' => 500, 'message' => __('auth.something_went_wrong')]);
|
||||
}
|
||||
}
|
||||
/*
|
||||
/*
|
||||
Created By : Sayali Parab
|
||||
Created at : 28 May 2024
|
||||
Use : To Get pdf.
|
||||
@@ -234,7 +234,7 @@ class ManageCustomerController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
Created By : Sayali Parab
|
||||
Created at : 28 May 2024
|
||||
Use : To Get Excel.
|
||||
@@ -249,6 +249,7 @@ class ManageCustomerController extends Controller
|
||||
|
||||
$ids = $request->selected_id;
|
||||
|
||||
|
||||
if (empty($ids)) {
|
||||
return response()->json(['error' => 'No IDs provided for export.'], 400);
|
||||
}
|
||||
@@ -271,7 +272,7 @@ class ManageCustomerController extends Controller
|
||||
|
||||
|
||||
|
||||
/*
|
||||
/*
|
||||
Created By : Sayali Parab
|
||||
Created at : 28 May 2024
|
||||
Use : To Deleted Data Restore.
|
||||
|
||||
@@ -47,4 +47,9 @@ class Subscriptions extends Model
|
||||
{
|
||||
return $this->belongsTo(IamPrincipal::class, 'iam_principal_xid', 'id');
|
||||
}
|
||||
}
|
||||
|
||||
public function subscriptionProduct()
|
||||
{
|
||||
return $this->belongsTo(SubscriptionProducts::class, 'subscription_product_xid', 'id');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user