| 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\SourceReportService; |
| 9 |
|
| 10 |
class SourceReportController extends Controller |
| 11 |
{ |
| 12 |
protected $params = [ |
| 13 |
'orderTypes', |
| 14 |
'paymentStatus', |
| 15 |
]; |
| 16 |
|
| 17 |
public function index(Request $request): array |
| 18 |
{ |
| 19 |
$params = ReportHelper::processParams($request->get('params'), $this->params); |
| 20 |
|
| 21 |
$service = SourceReportService::make(); |
| 22 |
|
| 23 |
$currentMetrics = $service->getSourceReportData($params); |
| 24 |
|
| 25 |
$fluctuations = []; |
| 26 |
|
| 27 |
if ($params['comparePeriod']) { |
| 28 |
$params['startDate'] = $params['comparePeriod'][0]; |
| 29 |
$params['endDate'] = $params['comparePeriod'][1]; |
| 30 |
|
| 31 |
$previousMetrics = $service->getSourceReportData($params); |
| 32 |
|
| 33 |
$fluctuations = $service->calculateFluctuations( |
| 34 |
$currentMetrics, $previousMetrics |
| 35 |
); |
| 36 |
} |
| 37 |
|
| 38 |
return [ |
| 39 |
'sourceReportData' => $currentMetrics, |
| 40 |
'fluctuations' => $fluctuations, |
| 41 |
]; |
| 42 |
} |
| 43 |
} |
| 44 |
|