Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 19 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| TotalFlyCutsSpotlightAction | |
0.00% |
0 / 19 |
|
0.00% |
0 / 1 |
42 | |
0.00% |
0 / 1 |
| execute | |
0.00% |
0 / 19 |
|
0.00% |
0 / 1 |
42 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Actions\AccountCenter\Reporting; |
| 4 | |
| 5 | use App\DTO\AccountCenter\Reporting\ReportingRequestDTO; |
| 6 | use Carbon\Carbon; |
| 7 | |
| 8 | class TotalFlyCutsSpotlightAction extends AccountCenterReporting |
| 9 | { |
| 10 | public function execute(ReportingRequestDTO $filter) |
| 11 | { |
| 12 | $query = $this->getFilteredQuery($filter); |
| 13 | |
| 14 | $flycut_usages = $query->get(); |
| 15 | |
| 16 | $firstDate = !empty($filter->fromDate) ? Carbon::parse($filter->fromDate)->startOfDay() : null; |
| 17 | $lastDate = !empty($filter->toDate) ? Carbon::parse($filter->toDate)->endOfDay() : null; |
| 18 | |
| 19 | if (!$firstDate) { |
| 20 | $firstDate = $flycut_usages->min("created_at"); |
| 21 | } |
| 22 | |
| 23 | if (!$lastDate) { |
| 24 | $lastDate = $flycut_usages->max("created_at"); |
| 25 | } |
| 26 | |
| 27 | $months = $lastDate->diffInMonths($firstDate); |
| 28 | $chart = $this->buildLineChartData2($flycut_usages, $months); |
| 29 | $total = $flycut_usages->sum("flycut_count"); |
| 30 | $userIds = $query->distinct("user_id")->get(); |
| 31 | $total_users = count($userIds); |
| 32 | $average = $total_users > 0 ? $total / $total_users : 0; |
| 33 | |
| 34 | return [ |
| 35 | "chart" => $chart, |
| 36 | "total" => number_format($total, 0, ".", ","), |
| 37 | "average" => round($average, 0) |
| 38 | ]; |
| 39 | } |
| 40 | } |