|
@@ -203,31 +203,132 @@ class Dashboard extends Component
|
|
|
$currentDate = now()->format('Y-m-d');
|
|
$currentDate = now()->format('Y-m-d');
|
|
|
Log::info('Calculating financial stats for month', ['month' => $currentMonth]);
|
|
Log::info('Calculating financial stats for month', ['month' => $currentMonth]);
|
|
|
|
|
|
|
|
- $this->received = \App\Models\Record::where('type', 'IN')
|
|
|
|
|
|
|
+ // excluded members
|
|
|
|
|
+ $excluded_members = \App\Models\Member::where('exclude_from_records', true)->pluck('id')->toArray();
|
|
|
|
|
+ // excluded payment method
|
|
|
|
|
+ $excluded_payment_methods = \App\Models\PaymentMethod::where('money', true)->pluck('id')->toArray();
|
|
|
|
|
+ // excluded causals
|
|
|
|
|
+ $excluded_causals = \App\Models\Causal::orWhereIn('name', [
|
|
|
|
|
+ 'Corrispettivo fiscale giornaliero',
|
|
|
|
|
+ 'CFG',
|
|
|
|
|
+ ])->orWhere('hidden', 1)->orWhere('enabled', 0)->pluck('id')->toArray();
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ // Incassato
|
|
|
|
|
+ $this->received = 0;
|
|
|
|
|
+ $records_in = \App\Models\Record::with('rows')->where('type', 'IN')
|
|
|
->whereRaw('DATE_FORMAT(date, "%Y-%m") = ?', [$currentMonth])
|
|
->whereRaw('DATE_FORMAT(date, "%Y-%m") = ?', [$currentMonth])
|
|
|
->where(function ($query) {
|
|
->where(function ($query) {
|
|
|
$query->where('deleted', false)->orWhere('deleted', null);
|
|
$query->where('deleted', false)->orWhere('deleted', null);
|
|
|
- })
|
|
|
|
|
- ->sum('amount') ?? 0;
|
|
|
|
|
|
|
+ })->get();
|
|
|
|
|
+ foreach ($records_in as $record) {
|
|
|
|
|
+ if (in_array($record->payment_method_id, $excluded_payment_methods)) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- $this->paid = \App\Models\Record::where('type', 'OUT')
|
|
|
|
|
- ->whereRaw('DATE_FORMAT(date, "%Y-%m") = ?', [$currentMonth])
|
|
|
|
|
- ->where('data_pagamento', '<=', $currentDate)
|
|
|
|
|
|
|
+ if (in_array($record->member_id, $excluded_members)) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ foreach ($record->rows as $row) {
|
|
|
|
|
+ if ($row->causal_id) {
|
|
|
|
|
+ $causal = \App\Models\Causal::find($row->causal_id);
|
|
|
|
|
+
|
|
|
|
|
+ if (!$causal || (isset($causal->hidden) && $causal->hidden)) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (in_array($row->causal_id, $excluded_causals)) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $this->received += $row->amount;
|
|
|
|
|
+ if ($row->vat_id > 0) {
|
|
|
|
|
+ $this->received += getVatValue($row->amount, $row->vat_id);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ // END - Incassato
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ // Pagato
|
|
|
|
|
+ $this->paid = 0;
|
|
|
|
|
+ $records_out = \App\Models\Record::with('rows')->where('type', 'OUT')
|
|
|
|
|
+ ->whereRaw('DATE_FORMAT(data_pagamento, "%Y-%m") = ?', [$currentMonth])
|
|
|
->where(function ($query) {
|
|
->where(function ($query) {
|
|
|
$query->where('deleted', false)->orWhere('deleted', null);
|
|
$query->where('deleted', false)->orWhere('deleted', null);
|
|
|
- })
|
|
|
|
|
- ->sum('amount') ?? 0;
|
|
|
|
|
|
|
+ })->get();
|
|
|
|
|
+ foreach ($records_out as $record) {
|
|
|
|
|
+ if (in_array($record->payment_method_id, $excluded_payment_methods)) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- $this->toPay = \App\Models\Record::where('type', 'OUT')
|
|
|
|
|
- ->whereRaw('DATE_FORMAT(date, "%Y-%m") = ?', [$currentMonth])
|
|
|
|
|
- ->where(function ($query) use($currentDate) {
|
|
|
|
|
|
|
+ if (in_array($record->member_id, $excluded_members)) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ foreach ($record->rows as $row) {
|
|
|
|
|
+ if ($row->causal_id) {
|
|
|
|
|
+ $causal = \App\Models\Causal::find($row->causal_id);
|
|
|
|
|
+
|
|
|
|
|
+ if (!$causal || (isset($causal->hidden) && $causal->hidden)) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (in_array($row->causal_id, $excluded_causals)) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $this->paid += $row->amount;
|
|
|
|
|
+ if ($row->vat_id > 0) {
|
|
|
|
|
+ $this->paid += getVatValue($row->amount, $row->vat_id);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ // END - Pagato
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ // Da pagare
|
|
|
|
|
+ $this->toPay = 0;
|
|
|
|
|
+ $records_toPay = \App\Models\Record::with('rows')->where('type', 'OUT')
|
|
|
|
|
+ ->where(function ($query) use ($currentDate) {
|
|
|
$query->where('data_pagamento', '>', $currentDate)
|
|
$query->where('data_pagamento', '>', $currentDate)
|
|
|
->orWhereNull('data_pagamento');
|
|
->orWhereNull('data_pagamento');
|
|
|
})
|
|
})
|
|
|
->where(function ($query) {
|
|
->where(function ($query) {
|
|
|
$query->where('deleted', false)->orWhere('deleted', null);
|
|
$query->where('deleted', false)->orWhere('deleted', null);
|
|
|
- })
|
|
|
|
|
- ->sum('amount') ?? 0;
|
|
|
|
|
|
|
+ })->get();
|
|
|
|
|
+ foreach ($records_toPay as $record) {
|
|
|
|
|
+ if (in_array($record->payment_method_id, $excluded_payment_methods)) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (in_array($record->member_id, $excluded_members)) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ foreach ($record->rows as $row) {
|
|
|
|
|
+ if ($row->causal_id) {
|
|
|
|
|
+ $causal = \App\Models\Causal::find($row->causal_id);
|
|
|
|
|
+
|
|
|
|
|
+ if (!$causal || (isset($causal->hidden) && $causal->hidden)) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (in_array($row->causal_id, $excluded_causals)) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $this->toPay += $row->amount;
|
|
|
|
|
+ if ($row->vat_id > 0) {
|
|
|
|
|
+ $this->toPay += getVatValue($row->amount, $row->vat_id);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ // END - Da pagare
|
|
|
|
|
|
|
|
$endTime = microtime(true);
|
|
$endTime = microtime(true);
|
|
|
Log::info('Financial stats loaded successfully', [
|
|
Log::info('Financial stats loaded successfully', [
|