| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentCart\App\Http\Controllers\Reports; |
| 4 |
|
| 5 |
use FluentCart\App\Helpers\Status; |
| 6 |
use FluentCart\App\Http\Controllers\Controller; |
| 7 |
use FluentCart\App\Services\Report\RefundReportService; |
| 8 |
use FluentCart\Framework\Http\Request\Request; |
| 9 |
use FluentCart\App\Services\DateTime\DateTime; |
| 10 |
use FluentCart\App\Services\Report\ReportHelper; |
| 11 |
|
| 12 |
class RefundReportController extends Controller |
| 13 |
{ |
| 14 |
protected $params = [ |
| 15 |
'orderTypes', |
| 16 |
'paymentStatus', |
| 17 |
]; |
| 18 |
|
| 19 |
public function getRefundChart(Request $request): array |
| 20 |
{ |
| 21 |
$params = ReportHelper::processParams($request->get('params'), $this->params); |
| 22 |
|
| 23 |
$service = RefundReportService::make(); |
| 24 |
|
| 25 |
$currentMetrics = $service->getRefundData($params); |
| 26 |
|
| 27 |
$fluctuations = []; |
| 28 |
$previousMetrics = ['grouped' => [], 'summary' => []]; |
| 29 |
|
| 30 |
if ($params['comparePeriod']) { |
| 31 |
$params['startDate'] = $params['comparePeriod'][0]; |
| 32 |
$params['endDate'] = $params['comparePeriod'][1]; |
| 33 |
|
| 34 |
$previousMetrics = $service->getRefundData($params); |
| 35 |
|
| 36 |
$fluctuations = $service->calculateFluctuations( |
| 37 |
$currentMetrics['summary'], $previousMetrics['summary'] |
| 38 |
); |
| 39 |
} |
| 40 |
|
| 41 |
return [ |
| 42 |
'summary' => $currentMetrics['summary'], |
| 43 |
'previousSummary' => $previousMetrics['summary'], |
| 44 |
'chartData' => $currentMetrics['grouped'], |
| 45 |
'fluctuations' => $fluctuations, |
| 46 |
'previousMetrics' => $previousMetrics['grouped'], |
| 47 |
]; |
| 48 |
} |
| 49 |
|
| 50 |
public function getWeeksBetweenRefund(Request $request): array |
| 51 |
{ |
| 52 |
$params = ReportHelper::processParams($request->get('params'), $this->params); |
| 53 |
|
| 54 |
$service = RefundReportService::make(); |
| 55 |
|
| 56 |
return [ |
| 57 |
'data' => $service->weeksBetweenRefund($params) |
| 58 |
]; |
| 59 |
} |
| 60 |
|
| 61 |
public function getRefundDataByGroup(Request $request): array |
| 62 |
{ |
| 63 |
$params = ReportHelper::processParams($request->get('params'), $this->params); |
| 64 |
|
| 65 |
$service = RefundReportService::make(); |
| 66 |
|
| 67 |
return [ |
| 68 |
'data' => $service->getRefundDataGroupedBy($params) |
| 69 |
]; |
| 70 |
} |
| 71 |
} |
| 72 |
|