|
|
@@ -428,11 +428,11 @@ class Reports extends Component
|
|
|
];
|
|
|
}
|
|
|
|
|
|
- $memberCourses = \App\Models\MemberCourse::where('course_id', $courseId)
|
|
|
- ->with('member')
|
|
|
- ->get();
|
|
|
+ $rates = \App\Models\Rate::whereHas('member_course', function ($query) use ($courseId) {
|
|
|
+ $query->where('course_id', $courseId);
|
|
|
+ })->with('member_course')->get();
|
|
|
|
|
|
- if ($memberCourses->isEmpty()) {
|
|
|
+ if ($rates->isEmpty()) {
|
|
|
return [
|
|
|
'labels' => [],
|
|
|
'datasets' => [],
|
|
|
@@ -444,24 +444,25 @@ class Reports extends Component
|
|
|
|
|
|
$hasData = false;
|
|
|
|
|
|
- foreach ($memberCourses as $memberCourse) {
|
|
|
- $price = (float)($memberCourse->price ?? 0);
|
|
|
+ foreach ($rates as $rate) {
|
|
|
+ $totalPrice = (float)($rate->price ?? 0);
|
|
|
+
|
|
|
+ if ($rate->months) {
|
|
|
+ $monthsData = json_decode($rate->months, true);
|
|
|
|
|
|
- if ($memberCourse->months) {
|
|
|
- $monthsData = json_decode($memberCourse->months, true);
|
|
|
+ if (is_array($monthsData) && count($monthsData) > 0) {
|
|
|
+ $pricePerMonth = $totalPrice / count($monthsData);
|
|
|
|
|
|
- if (is_array($monthsData)) {
|
|
|
- foreach ($monthsData as $monthData) {
|
|
|
- $month = $monthData['m'] ?? null;
|
|
|
- $status = $monthData['status'] ?? '';
|
|
|
+ foreach ($monthsData as $month) {
|
|
|
+ $monthNumber = (int)$month;
|
|
|
|
|
|
- if ($month !== null && isset($monthlyData[$month])) {
|
|
|
- $monthlyData[$month]['total'] += $price;
|
|
|
- $monthlyData[$month]['participants']++;
|
|
|
+ if (isset($monthlyData[$monthNumber])) {
|
|
|
+ $monthlyData[$monthNumber]['total'] += $pricePerMonth;
|
|
|
+ $monthlyData[$monthNumber]['participants']++;
|
|
|
$hasData = true;
|
|
|
|
|
|
- if ($status === 1) {
|
|
|
- $monthlyData[$month]['earned'] += $price;
|
|
|
+ if (!is_null($rate->record_id) && $rate->record_id !== '') {
|
|
|
+ $monthlyData[$monthNumber]['earned'] += $pricePerMonth;
|
|
|
}
|
|
|
}
|
|
|
}
|