108 lines
3.3 KiB
PHP
108 lines
3.3 KiB
PHP
<?php
|
|
|
|
namespace App\Exports;
|
|
|
|
use App\Models\Frontend\payment_transaction_master;
|
|
use Maatwebsite\Excel\Concerns\FromCollection;
|
|
use Maatwebsite\Excel\Concerns\WithHeadings;
|
|
|
|
class UsersExport implements FromCollection, WithHeadings {
|
|
|
|
/**
|
|
* @return \Illuminate\Support\Collection
|
|
*/
|
|
|
|
// protected $startDate;
|
|
// protected $endDate;
|
|
// protected $selectedCountry;
|
|
//
|
|
//
|
|
// public function headings(): array {
|
|
// return[
|
|
// 'Sr.no',
|
|
// 'User Name',
|
|
// 'Transaction ID',
|
|
// 'Program Name',
|
|
// 'Start Date',
|
|
// 'End Date',
|
|
// 'Duration',
|
|
// 'Country',
|
|
// 'Currency',
|
|
// 'Amount',
|
|
// 'Payment Date'
|
|
// ];
|
|
// }
|
|
//
|
|
// public function collection() {
|
|
//
|
|
//
|
|
//
|
|
// return payment_transaction_master::leftJoin('iam_principal', 'iam_principal.id', '=', 'payment_transaction_masters.principal_xid')
|
|
// ->join('programs', 'programs.id', '=', 'payment_transaction_masters.programs_xid')
|
|
// ->join('countries', 'countries.id', '=', 'programs.country_xid')
|
|
// ->select('payment_transaction_masters.id', 'iam_principal.first_name as user_name', 'transaction_id', 'programs.program_title as program_title', 'programs.start_date as start_date', 'programs.end_date as end_date', 'payment_transaction_masters.duration', 'countries.name as program_country', 'currency', 'amount', 'payment_transaction_masters.created_at')
|
|
//
|
|
// ->latest()
|
|
// ->get();
|
|
//
|
|
//
|
|
// }
|
|
|
|
|
|
|
|
protected $data;
|
|
|
|
public function __construct($data = null) {
|
|
if ($data instanceof Collection) {
|
|
$this->data = $data;
|
|
} elseif (is_array($data)) {
|
|
$this->data = collect($data);
|
|
} else {
|
|
$this->data = collect(); // Initialize an empty collection
|
|
}
|
|
}
|
|
|
|
public function headings(): array {
|
|
return [
|
|
'Sr.no',
|
|
'User Name',
|
|
'Transaction ID',
|
|
'Program Name',
|
|
'Start Date',
|
|
'End Date',
|
|
'Duration',
|
|
'Country',
|
|
'Currency',
|
|
'Amount',
|
|
'Payment Date'
|
|
];
|
|
}
|
|
|
|
public function collection() {
|
|
if ($this->data->isEmpty()) {
|
|
// Fetch the default data if no filtered data is provided
|
|
return payment_transaction_master::leftJoin('iam_principal', 'iam_principal.id', '=', 'payment_transaction_masters.principal_xid')
|
|
->join('programs', 'programs.id', '=', 'payment_transaction_masters.programs_xid')
|
|
->join('countries', 'countries.id', '=', 'programs.country_xid')
|
|
->select(
|
|
'payment_transaction_masters.id',
|
|
'iam_principal.first_name as user_name',
|
|
'transaction_id',
|
|
'programs.program_title as program_title',
|
|
'programs.start_date as start_date',
|
|
'programs.end_date as end_date',
|
|
'payment_transaction_masters.duration',
|
|
'countries.name as program_country',
|
|
'currency',
|
|
'amount',
|
|
'payment_transaction_masters.created_at'
|
|
)
|
|
->latest('payment_transaction_masters.created_at') // Specify the table for created_at
|
|
->get();
|
|
|
|
}
|
|
|
|
return $this->data;
|
|
}
|
|
}
|