| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentCart\App\Http\Controllers\Reports; |
| 4 |
|
| 5 |
use FluentCart\Framework\Http\Request\Request; |
| 6 |
use FluentCart\App\Http\Controllers\Controller; |
| 7 |
use FluentCart\App\Services\Report\ReportHelper; |
| 8 |
use FluentCart\App\Services\Report\OrderReportService; |
| 9 |
|
| 10 |
class OrderReportController extends Controller |
| 11 |
{ |
| 12 |
protected $params = [ |
| 13 |
'orderTypes', |
| 14 |
'paymentStatus', |
| 15 |
]; |
| 16 |
|
| 17 |
public function getOrderChart(Request $request): array |
| 18 |
{ |
| 19 |
$params = ReportHelper::processParams($request->get('params'), $this->params); |
| 20 |
|
| 21 |
$service = OrderReportService::make(); |
| 22 |
|
| 23 |
$currentMetrics = $service->getOrderLineChart($params); |
| 24 |
|
| 25 |
$fluctuations = []; |
| 26 |
$previousMetrics = ['summary' => []]; |
| 27 |
if ($params['comparePeriod']) { |
| 28 |
$params['startDate'] = $params['comparePeriod'][0]; |
| 29 |
$params['endDate'] = $params['comparePeriod'][1]; |
| 30 |
|
| 31 |
$previousMetrics = $service->getOrderLineChart($params); |
| 32 |
|
| 33 |
$fluctuations = $service->calculateFluctuations( |
| 34 |
$currentMetrics['summary'], $previousMetrics['summary'] |
| 35 |
); |
| 36 |
} |
| 37 |
|
| 38 |
return [ |
| 39 |
'orderChartData' => $currentMetrics['chartData'], |
| 40 |
'summary' => $currentMetrics['summary'], |
| 41 |
'previousSummary' => $previousMetrics['summary'], |
| 42 |
'fluctuations' => $fluctuations, |
| 43 |
// 'previousMetrics' => $previousMetrics['chartData'], |
| 44 |
]; |
| 45 |
} |
| 46 |
|
| 47 |
public function getNewVsReturningCustomer(Request $request) |
| 48 |
{ |
| 49 |
$params = ReportHelper::processParams($request->get('params'), $this->params); |
| 50 |
|
| 51 |
$service = OrderReportService::make(); |
| 52 |
|
| 53 |
return [ |
| 54 |
'newVsReturning' => $service->getNewVsReturningCustomer($params) |
| 55 |
]; |
| 56 |
} |
| 57 |
|
| 58 |
public function getOrderByGroup(Request $request) |
| 59 |
{ |
| 60 |
$params = ReportHelper::processParams($request->get('params'), $this->params); |
| 61 |
|
| 62 |
$data = OrderReportService::make([])->groupBy($params); |
| 63 |
|
| 64 |
return [ |
| 65 |
'data' => $data |
| 66 |
]; |
| 67 |
} |
| 68 |
|
| 69 |
public function getOrderValueDistribution(Request $request) |
| 70 |
{ |
| 71 |
|
| 72 |
$params = ReportHelper::processParams($request->get('params'), $this->params); |
| 73 |
|
| 74 |
$service = OrderReportService::make(); |
| 75 |
|
| 76 |
return [ |
| 77 |
'data' => $service->getOrderValueDistribution($params) |
| 78 |
]; |
| 79 |
} |
| 80 |
|
| 81 |
public function getReportByDayAndHour(Request $request) |
| 82 |
{ |
| 83 |
$params = ReportHelper::processParams($request->get('params'), $this->params); |
| 84 |
|
| 85 |
$service = OrderReportService::make(); |
| 86 |
|
| 87 |
return $service->getReportByDayAndHour($params); |
| 88 |
} |
| 89 |
|
| 90 |
public function getItemCountDistribution(Request $request) |
| 91 |
{ |
| 92 |
$params = ReportHelper::processParams($request->get('params'), $this->params); |
| 93 |
|
| 94 |
$service = OrderReportService::make(); |
| 95 |
|
| 96 |
return [ |
| 97 |
'data' => $service->getItemCountDistribution($params) |
| 98 |
]; |
| 99 |
} |
| 100 |
|
| 101 |
public function getOrderCompletionTime(Request $request) |
| 102 |
{ |
| 103 |
$params = ReportHelper::processParams($request->get('params'), $this->params); |
| 104 |
|
| 105 |
$service = OrderReportService::make(); |
| 106 |
|
| 107 |
return [ |
| 108 |
'data' => $service->getOrderCompletionTime($params) |
| 109 |
]; |
| 110 |
} |
| 111 |
} |