| 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\DefaultReportService; |
| 9 |
|
| 10 |
class DefaultReportController extends Controller |
| 11 |
{ |
| 12 |
protected $params = [ |
| 13 |
'orderTypes', |
| 14 |
'paymentStatus', |
| 15 |
]; |
| 16 |
|
| 17 |
public function getTopSoldProducts(Request $request): array |
| 18 |
{ |
| 19 |
$params = ReportHelper::processParams($request->get('params'), $this->params); |
| 20 |
|
| 21 |
$service = DefaultReportService::make(); |
| 22 |
|
| 23 |
return $service->fetchTopSoldProducts($params); |
| 24 |
} |
| 25 |
|
| 26 |
public function getTopSoldVariants(Request $request): array |
| 27 |
{ |
| 28 |
$params = ReportHelper::processParams($request->get('params'), $this->params); |
| 29 |
|
| 30 |
$service = DefaultReportService::make(); |
| 31 |
|
| 32 |
return $service->fetchTopSoldVariants($params); |
| 33 |
} |
| 34 |
|
| 35 |
public function getSalesReport(Request $request) |
| 36 |
{ |
| 37 |
$params = ReportHelper::processParams($request->get('params'), $this->params); |
| 38 |
|
| 39 |
$service = DefaultReportService::make([]); |
| 40 |
|
| 41 |
$currentMetrics = $service->getAllGraphMetricsSeparate($params); |
| 42 |
|
| 43 |
$fluctuations = []; |
| 44 |
$previousMetrics = ['summary' => []]; |
| 45 |
|
| 46 |
if ($params['comparePeriod']) { |
| 47 |
$params['startDate'] = $params['comparePeriod'][0]; |
| 48 |
$params['endDate'] = $params['comparePeriod'][1]; |
| 49 |
$previousMetrics = $service->getAllGraphMetricsSeparate($params); |
| 50 |
|
| 51 |
$fluctuations = $service->calculateFluctuations( |
| 52 |
$currentMetrics['summary'], $previousMetrics['summary'] |
| 53 |
); |
| 54 |
} |
| 55 |
|
| 56 |
return [ |
| 57 |
'graphs' => $currentMetrics['metrics'], |
| 58 |
'summaryData' => $currentMetrics['summary'], |
| 59 |
'previousSummary' => $previousMetrics['summary'], |
| 60 |
'fluctuations' => $fluctuations, |
| 61 |
]; |
| 62 |
} |
| 63 |
} |
| 64 |
|