|
|
@@ -169,6 +169,13 @@ class Reports extends Component
|
|
|
|
|
|
$incomeRecords = DB::table('records')
|
|
|
->join('records_rows', 'records.id', '=', 'records_rows.record_id')
|
|
|
+ ->join('causals', function ($join) {
|
|
|
+ $join->on('causals.id', '=', 'records_rows.causal_id')
|
|
|
+ ->where(function ($query) {
|
|
|
+ $query->where('causals.no_reports', 0)
|
|
|
+ ->orWhereNull('causals.no_reports');
|
|
|
+ });
|
|
|
+ })
|
|
|
->whereBetween('records.date', [$dateRange['start'], $dateRange['end']])
|
|
|
->where('records.type', 'IN')
|
|
|
->select(DB::raw('MONTH(records.date) as month_num'), DB::raw('SUM(records_rows.amount) as total'))
|
|
|
@@ -177,6 +184,13 @@ class Reports extends Component
|
|
|
|
|
|
$expenseRecords = DB::table('records')
|
|
|
->join('records_rows', 'records.id', '=', 'records_rows.record_id')
|
|
|
+ ->join('causals', function ($join) {
|
|
|
+ $join->on('causals.id', '=', 'records_rows.causal_id')
|
|
|
+ ->where(function ($query) {
|
|
|
+ $query->where('causals.no_reports', 0)
|
|
|
+ ->orWhereNull('causals.no_reports');
|
|
|
+ });
|
|
|
+ })
|
|
|
->whereBetween('records.date', [$dateRange['start'], $dateRange['end']])
|
|
|
->where('records.type', 'OUT')
|
|
|
->select(DB::raw('MONTH(records.date) as month_num'), DB::raw('SUM(records_rows.amount) as total'))
|
|
|
@@ -216,13 +230,20 @@ class Reports extends Component
|
|
|
]
|
|
|
];
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public function getYearlyTotals()
|
|
|
{
|
|
|
Log::info('=== getyearlyTotals called ===');
|
|
|
|
|
|
$incomeRecords = DB::table('records')
|
|
|
->join('records_rows', 'records.id', '=', 'records_rows.record_id')
|
|
|
+ ->join('causals', function ($join) {
|
|
|
+ $join->on('causals.id', '=', 'records_rows.causal_id')
|
|
|
+ ->where(function ($query) {
|
|
|
+ $query->where('causals.no_reports', 0)
|
|
|
+ ->orWhereNull('causals.no_reports');
|
|
|
+ });
|
|
|
+ })
|
|
|
->where('records.type', 'IN')
|
|
|
->selectRaw("
|
|
|
CASE
|
|
|
@@ -237,6 +258,13 @@ class Reports extends Component
|
|
|
|
|
|
$expenseRecords = DB::table('records')
|
|
|
->join('records_rows', 'records.id', '=', 'records_rows.record_id')
|
|
|
+ ->join('causals', function ($join) {
|
|
|
+ $join->on('causals.id', '=', 'records_rows.causal_id')
|
|
|
+ ->where(function ($query) {
|
|
|
+ $query->where('causals.no_reports', 0)
|
|
|
+ ->orWhereNull('causals.no_reports');
|
|
|
+ });
|
|
|
+ })
|
|
|
->where('records.type', 'OUT')
|
|
|
->selectRaw("
|
|
|
CASE
|
|
|
@@ -248,21 +276,21 @@ class Reports extends Component
|
|
|
")
|
|
|
->groupBy('year_num')
|
|
|
->get();
|
|
|
-
|
|
|
+
|
|
|
// Mappa anno/totale
|
|
|
$incomeByYear = $incomeRecords->pluck('total', 'year_num');
|
|
|
$expenseByYear = $expenseRecords->pluck('total', 'year_num');
|
|
|
|
|
|
// Unione di tutti gli anni presenti ordinati
|
|
|
$allYears = $incomeByYear->keys()
|
|
|
- ->merge($expenseByYear->keys())
|
|
|
- ->unique()
|
|
|
- ->sort()
|
|
|
- ->values();
|
|
|
+ ->merge($expenseByYear->keys())
|
|
|
+ ->unique()
|
|
|
+ ->sort()
|
|
|
+ ->values();
|
|
|
|
|
|
// Allineo i dati dei due array, se non presente l'anno: default 0
|
|
|
- $incomeData = $allYears->map(fn ($y) => (float) ($incomeByYear[$y] ?? 0))->toArray();
|
|
|
- $expenseData = $allYears->map(fn ($y) => (float) ($expenseByYear[$y] ?? 0))->toArray();
|
|
|
+ $incomeData = $allYears->map(fn($y) => (float) ($incomeByYear[$y] ?? 0))->toArray();
|
|
|
+ $expenseData = $allYears->map(fn($y) => (float) ($expenseByYear[$y] ?? 0))->toArray();
|
|
|
|
|
|
|
|
|
return [
|
|
|
@@ -415,7 +443,7 @@ class Reports extends Component
|
|
|
Log::info('Processing course: ' . $course->name . ' (ID: ' . $course->id . ')' . $course);
|
|
|
|
|
|
$levelName = is_object($course->level) ? $course->level->name : 'No Level';
|
|
|
- $typeName = '';//$course->getFormattedTypeField();
|
|
|
+ $typeName = ''; //$course->getFormattedTypeField();
|
|
|
$frequencyName = is_object($course->frequency) ? $course->frequency->name : 'No Frequency';
|
|
|
$year = $course->year ?? '';
|
|
|
|
|
|
@@ -563,8 +591,7 @@ class Reports extends Component
|
|
|
if ($member_course->months) {
|
|
|
$monthsData = json_decode($member_course->months, true);
|
|
|
|
|
|
- if (is_array($monthsData) && count($monthsData) > 0)
|
|
|
- {
|
|
|
+ if (is_array($monthsData) && count($monthsData) > 0) {
|
|
|
|
|
|
|
|
|
|
|
|
@@ -577,7 +604,7 @@ class Reports extends Component
|
|
|
$monthlyData[$monthNumber]['total'] += $pricePerMonth;
|
|
|
$monthlyData[$monthNumber]['participants']++;
|
|
|
$hasData = true;
|
|
|
-
|
|
|
+
|
|
|
//if (!is_null($rate->record_id) && $rate->record_id !== '') {
|
|
|
if ($month["status"] == 1) {
|
|
|
$monthlyData[$monthNumber]['participants']--;
|
|
|
@@ -637,7 +664,7 @@ class Reports extends Component
|
|
|
];
|
|
|
}
|
|
|
|
|
|
- $daIncassareData = array_map(function($tot, $inc) {
|
|
|
+ $daIncassareData = array_map(function ($tot, $inc) {
|
|
|
return $tot - $inc;
|
|
|
}, $totalData, $earnedData);
|
|
|
|
|
|
@@ -683,7 +710,14 @@ class Reports extends Component
|
|
|
->whereRaw('YEAR(expire_date) <= ?', [$endYear])
|
|
|
->get();
|
|
|
|
|
|
- $cardTypes = $memberCards->pluck('card.name')->unique()->filter()->sort()->values();
|
|
|
+ $cardTypes = $memberCards->pluck('card.name')->unique()->filter()->sort()->values()->toArray();
|
|
|
+ usort($cardTypes, function($a, $b) {
|
|
|
+ if ($a == $b) return 0;
|
|
|
+ if ($a == "UISP") return 1;
|
|
|
+ if ($b == "UISP") return 1;
|
|
|
+
|
|
|
+ return strcmp($a, $b);
|
|
|
+ });
|
|
|
|
|
|
$seasonCounts = [];
|
|
|
$seasonCardCounts = [];
|
|
|
@@ -756,6 +790,7 @@ class Reports extends Component
|
|
|
'tension' => 0.3,
|
|
|
'fill' => true
|
|
|
];
|
|
|
+ if ($cardType != "UISP") $cardTypeDatasets[$cardType]["hidden"] = true;
|
|
|
}
|
|
|
|
|
|
foreach ($seasonCounts as $seasonPeriod => $members) {
|
|
|
@@ -781,7 +816,8 @@ class Reports extends Component
|
|
|
'pointRadius' => 6,
|
|
|
'tension' => 0.3,
|
|
|
'fill' => true,
|
|
|
- 'type' => 'line'
|
|
|
+ 'type' => 'line',
|
|
|
+ 'hidden' => true
|
|
|
]
|
|
|
];
|
|
|
foreach ($cardTypeDatasets as $dataset) {
|