get('params'), $this->params); $service = SourceReportService::make(); $currentMetrics = $service->getSourceReportData($params); $fluctuations = []; if ($params['comparePeriod']) { // Only the date window moves — every other param (advanced filters // included) is reused, so the comparison period is measured over the // same segment of orders and the fluctuations compare like with like. $params['startDate'] = $params['comparePeriod'][0]; $params['endDate'] = $params['comparePeriod'][1]; $previousMetrics = $service->getSourceReportData($params); $fluctuations = $service->calculateFluctuations( $currentMetrics, $previousMetrics ); } return [ 'sourceReportData' => $currentMetrics, 'fluctuations' => $fluctuations, ]; } }