mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-19 04:23:55 +00:00
export booking analytic
This commit is contained in:
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Exports\Services;
|
||||
|
||||
use App\Classes\ValueObjects\Constants\CompanyType;
|
||||
use App\Classes\ValueObjects\Constants\PaymentMethodType;
|
||||
use App\Models\Booking;
|
||||
use App\Models\Company;
|
||||
use App\Models\Transaction;
|
||||
use Maatwebsite\Excel\Concerns\Exportable;
|
||||
use Maatwebsite\Excel\Concerns\FromQuery;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadingRow;
|
||||
use Maatwebsite\Excel\Concerns\WithMapping;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadings;
|
||||
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class ExportsAnalyticBookingTransactions implements FromQuery, WithHeadings, WithHeadingRow, WithMapping, ShouldAutoSize
|
||||
{
|
||||
use Exportable;
|
||||
|
||||
private $request;
|
||||
|
||||
public function __construct(Request $request)
|
||||
{
|
||||
$this->request = $request;
|
||||
}
|
||||
|
||||
public function headings(): array
|
||||
{
|
||||
return [
|
||||
'TransID',
|
||||
'Company ID',
|
||||
'Type Of User',
|
||||
'Group Control / Experiment',
|
||||
'Payment Date',
|
||||
'Completed Purchase OrderDate',
|
||||
'DayTo Closed',
|
||||
'IsCompleted Purchase Order (1 or 0)',
|
||||
'Final Payment',
|
||||
'Discount Amount',
|
||||
'PaymentType',
|
||||
'RowUpdateDate'
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Support\Collection|mixed
|
||||
*/
|
||||
public function query()
|
||||
{
|
||||
return Booking::query();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $booking
|
||||
* @return array
|
||||
*/
|
||||
public function map($booking): array
|
||||
{
|
||||
$companyType = [];
|
||||
$companyType[companyType::COMPANY_BUSINESS] = 'COMPANY_BUSINESS';
|
||||
$companyType[companyType::PERSONAL_BUSINESS] = 'PERSONAL_BUSINESS';
|
||||
|
||||
$payments = $booking->transactions()->where('type', 1)->whereIn('status', [2, 3]);
|
||||
|
||||
$firstPayment = $payments->first();
|
||||
|
||||
$CompletedPurchaseOrders = $booking->transactions()->where('type', 7)->whereIn('status', [1, 2]);
|
||||
|
||||
$FirstCompletedPurchaseOrder = $CompletedPurchaseOrders->first();
|
||||
|
||||
$lastPayment = $booking->transactions()->where('type', 1)->whereIn('status', [2, 3])->orderBy('id', 'desc')->first();
|
||||
|
||||
$paymentMethod = '';
|
||||
foreach ($payments->get() as $payment) {
|
||||
|
||||
if ( $paymentMethod == '' ) {
|
||||
$paymentMethod = $payment->payment_method;
|
||||
} else {
|
||||
if ( $payment->payment_method != $paymentMethod ) {
|
||||
$paymentMethod = 0; // set it to Hybrid
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$paymentmethondArray = PaymentMethodType::PAYMENT_METHODS_ID;
|
||||
$paymentmethondArray[0] = 'Hybrid';
|
||||
|
||||
$paymentMethod == '' ? '' : $paymentMethod = $paymentmethondArray[$paymentMethod];
|
||||
|
||||
return [
|
||||
$booking->id,
|
||||
$booking->company_id,
|
||||
$companyType[$booking->company->type],
|
||||
'',
|
||||
$firstPayment == null ? '' : $firstPayment->created_at,
|
||||
$FirstCompletedPurchaseOrder == null ? '' : $FirstCompletedPurchaseOrder->created_at,
|
||||
'',
|
||||
$CompletedPurchaseOrders->count() > 0 ? '1' : '0',
|
||||
$lastPayment == null ? '' : $lastPayment->amount,
|
||||
'',
|
||||
$paymentMethod,
|
||||
'',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Exports;
|
||||
|
||||
|
||||
use App\Classes\Modules\Exports\Services\ExportsAnalyticBookingTransactions;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Maatwebsite\Excel\Excel;
|
||||
|
||||
class ExportAnalyticToExcelController
|
||||
{
|
||||
|
||||
/**
|
||||
* ExportAnalyticToExcelController constructor.
|
||||
* @param Request $request
|
||||
*/
|
||||
public function __construct(Request $request)
|
||||
{
|
||||
$token = Auth::fromUser(User::find(1));
|
||||
$request->headers->set('Authorization', 'Bearer '.$token);
|
||||
}
|
||||
|
||||
public function bookingData(ExportsAnalyticBookingTransactions $exportsAnalyticBookingTransactions, Request $request){
|
||||
$response = $exportsAnalyticBookingTransactions->download('bookingData.csv', Excel::CSV, ['Content-Type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet']);
|
||||
ob_end_clean();
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
@@ -96,6 +96,7 @@ Route::get('/online_payment/redirect', 'Billplz\CallbackBillplzController@callba
|
||||
|
||||
Route::get('/export/customers/f614e339d7058904a831aad742e24d55', 'Exports\ExportCustomersToExcelController@export');
|
||||
Route::get('/export/transactions/f614e339d7058904a831aad742e24d55', 'Exports\ExportCustomersToExcelController@transactions');
|
||||
Route::get('/export/analytic/booking', 'Exports\ExportAnalyticToExcelController@bookingData');
|
||||
|
||||
Route::get('/products', function (\App\Classes\Modules\Exports\Services\ExportsProducts $exportsProducts) {
|
||||
return $exportsProducts->download('products.csv', Excel::CSV, ['Content-Type' => 'text/csv']);
|
||||
|
||||
Reference in New Issue
Block a user