Ver código fonte

reports - ottimizzazione aggiornamento grafici

ferrari 2 meses atrás
pai
commit
d5f2d7b125
3 arquivos alterados com 36 adições e 28 exclusões
  1. 10 2
      app/Http/Livewire/RecordINOUT.php
  2. 9 26
      app/Http/Livewire/Reports.php
  3. 17 0
      app/helpers.php

+ 10 - 2
app/Http/Livewire/RecordINOUT.php

@@ -178,6 +178,8 @@ class RecordINOUT extends Component
         $this->records_in = [];
         $this->records_out = [];
 
+        $vats = getVatMap();
+
         $exclude_from_records = \App\Models\Member::where('exclude_from_records', true)->pluck('id')->toArray();
 
         if (sizeof($this->datas) > 0) {
@@ -222,7 +224,10 @@ class RecordINOUT extends Component
                     $matching_months = count($matches[0]);
 
                     $amount = $record->amount;
-                    $amount += getVatValue($amount, $record->vat_id);
+                    if (isset($vats[$record->vat_id]) && $vats[$record->vat_id] > 0) {
+                        $vat = $vats[$record->vat_id];
+                        $amount += $amount * $vat;
+                    }
                     $amount *= ($matching_months / $total_months);
 
                     // Aggiungo/aggiorno i dati
@@ -262,7 +267,10 @@ class RecordINOUT extends Component
                     $matching_months = count($matches[0]);
 
                     $amount = $record->amount;
-                    $amount += getVatValue($amount, $record->vat_id);
+                    if (isset($vats[$record->vat_id]) && $vats[$record->vat_id] > 0) {
+                        $vat = $vats[$record->vat_id];
+                        $amount += $amount * $vat;
+                    }
                     $amount *= ($matching_months / $total_months);
 
                     // Aggiungo/aggiorno i dati

+ 9 - 26
app/Http/Livewire/Reports.php

@@ -164,7 +164,7 @@ class Reports extends Component
         $monthIndex = [9 => 0, 10 => 1, 11 => 2, 12 => 3, 1 => 4, 2 => 5, 3 => 6, 4 => 7, 5 => 8, 6 => 9, 7 => 10, 8 => 11];
         $monthNames = ['Set', 'Ott', 'Nov', 'Dic', 'Gen', 'Feb', 'Mar', 'Apr', 'Mag', 'Giu', 'Lug', 'Ago'];
 
-        $vats = $this->getVatMap();
+        $vats = getVatMap();
 
         $incomeData = array_fill(0, 12, 0);
         $expenseData = array_fill(0, 12, 0);
@@ -209,7 +209,7 @@ class Reports extends Component
             $amount = $record->amount;
             if (isset($vats[$record->vat_id]) && $vats[$record->vat_id] > 0) {
                 $vat = $vats[$record->vat_id];
-                $amount += $amount / 100 * $vat;
+                $amount += $amount * $vat;
             }
 
             foreach ($matches[0] as $match) {
@@ -251,7 +251,7 @@ class Reports extends Component
             $amount = $record->amount;
             if (isset($vats[$record->vat_id]) && $vats[$record->vat_id] > 0) {
                 $vat = $vats[$record->vat_id];
-                $amount += $amount / 100 * $vat;
+                $amount += $amount * $vat;
             }
 
             foreach ($matches[0] as $match) {
@@ -291,7 +291,7 @@ class Reports extends Component
         $excluded_causals = \App\Models\Causal::where('no_records', true)->orWhere('money', true)->pluck('id')->toArray();
         $excluded_members = \App\Models\Member::where('exclude_from_records', true)->pluck('id')->toArray();
 
-        $vats = $this->getVatMap();
+        $vats = getVatMap();
 
         $incomeData = [];
         $expenseData = [];
@@ -344,7 +344,7 @@ class Reports extends Component
                 $amount = $record->amount;
                 if (isset($vats[$record->vat_id]) && $vats[$record->vat_id] > 0) {
                     $vat = $vats[$record->vat_id];
-                    $amount += $amount / 100 * $vat;
+                    $amount += $amount * $vat;
                 }
                 $amount *= ($matching_months / $total_months);
 
@@ -381,7 +381,7 @@ class Reports extends Component
                 $amount = $record->amount;
                 if (isset($vats[$record->vat_id]) && $vats[$record->vat_id] > 0) {
                     $vat = $vats[$record->vat_id];
-                    $amount += $amount / 100 * $vat;
+                    $amount += $amount * $vat;
                 }
                 $amount *= ($matching_months / $total_months);
 
@@ -411,7 +411,7 @@ class Reports extends Component
         $dateRange = $this->getSeasonDateRange($this->seasonFilter);
         Log::info('=== getYearlySummary called ===');
 
-        $vats = $this->getVatMap();
+        $vats = getVatMap();
 
         $excluded_causals = \App\Models\Causal::where('no_records', true)->orWhere('money', true)->pluck('id')->toArray();
         $excluded_members = \App\Models\Member::where('exclude_from_records', true)->pluck('id')->toArray();
@@ -457,7 +457,7 @@ class Reports extends Component
             $amount = $record->amount;
             if (isset($vats[$record->vat_id]) && $vats[$record->vat_id] > 0) {
                 $vat = $vats[$record->vat_id];
-                $amount += $amount / 100 * $vat;
+                $amount += $amount * $vat;
             }
             $amount *= ($matching_months / $total_months);
 
@@ -494,7 +494,7 @@ class Reports extends Component
             $amount = $record->amount;
             if (isset($vats[$record->vat_id]) && $vats[$record->vat_id] > 0) {
                 $vat = $vats[$record->vat_id];
-                $amount += $amount / 100 * $vat;
+                $amount += $amount * $vat;
             }
             $amount *= ($matching_months / $total_months);
 
@@ -1004,21 +1004,4 @@ class Reports extends Component
             'datasets' => $datasets
         ];
     }
-
-    function getVatMap()
-    {
-        static $map = null;
-
-        if ($map === null) {
-            $map = [];
-
-            $vats = \App\Models\Vat::select('id', 'value')->get();
-            foreach ($vats as $vat) {
-                $rate = (float)$vat->value;
-                $map[$vat->id] = $rate > 0 ? 1.0 + ($rate / 100.0) : 1.0;
-            }
-        }
-
-        return $map;
-    }
 }

+ 17 - 0
app/helpers.php

@@ -44,6 +44,23 @@ function getVatValue($v, $i)
     return $vat;
 }
 
+function getVatMap()
+{
+    static $map = null;
+
+    if ($map === null) {
+        $map = [];
+
+        $vats = \App\Models\Vat::select('id', 'value')->get();
+        foreach ($vats as $vat) {
+            $rate = (float)$vat->value;
+            $map[$vat->id] = $rate > 0 ? 1.0 + ($rate / 100.0) : 1.0;
+        }
+    }
+
+    return $map;
+}
+
 function mysqlToDate($dt)
 {
     list($date, $hour) = explode(" ", $dt);