Luca Parisio vor 1 Jahr
Ursprung
Commit
26e1326c4c
1 geänderte Dateien mit 31 neuen und 10 gelöschten Zeilen
  1. 31 10
      routes/web.php

+ 31 - 10
routes/web.php

@@ -350,6 +350,11 @@ Route::group(['middleware' => 'auth'],function(){
                 ->leftJoin('payment_methods', 'records.payment_method_id', '=', 'payment_methods.id')
                 ->where('records.type', 'IN');
 
+        $y = \App\Models\Record::select('records_rows.amount', 'records.member_id', 'records.corrispettivo_fiscale', 'records.deleted', 'records.financial_movement', 'records_rows.causal_id', \DB::raw('members.first_name as first_name'), \DB::raw('members.last_name as last_name')) // , \DB::raw('SUM(records.id) As total'))
+        ->leftJoin('members', 'records.member_id', '=', 'members.id')
+        ->leftJoin('records_rows', 'records.id', '=', 'records_rows.record_id')
+        ->where('records.type', 'IN');
+
         if (isset($_GET["search"]["value"]))
         {
             $v = str_replace("'", "\'", stripcslashes($_GET["search"]["value"]));
@@ -357,6 +362,10 @@ Route::group(['middleware' => 'auth'],function(){
                 $query->where('first_name', 'like', '%' . $v . '%')
                         ->orWhere('last_name', 'like', '%' . $v . '%');
             });
+            $y = $y->where(function ($query) use ($v) {
+                                $query->where('first_name', 'like', '%' . $v . '%')
+                                        ->orWhere('last_name', 'like', '%' . $v . '%');
+                            });
             //where('first_name', 'like', '%' . $_GET["search"]["value"] . '%');
         }
 
@@ -367,19 +376,23 @@ Route::group(['middleware' => 'auth'],function(){
             if ($_GET["filterCommercial"] == 1)
             {
                 $x = $x->where('commercial', true );
+                $y = $y->where('commercial', true );
             }
             if ($_GET["filterCommercial"] == 2)
             {
                 $x = $x->where('commercial', false);
+                $y = $y->where('commercial', false);
             }
             if ($_GET["filterMember"] > 0)
             {
                 $x = $x->where('member_id', $_GET["filterMember"]);
+                $y = $y->where('member_id', $_GET["filterMember"]);
             }
             if ($_GET["filterPaymentMethod"] != "null")
             {
                 $payments = explode(",", $_GET["filterPaymentMethod"]);
                 $x = $x->whereIn('payment_method_id', $payments);
+                $y = $y->whereIn('payment_method_id', $payments);
             }
             if ($_GET["filterCausals"] != "null")
             {
@@ -387,14 +400,17 @@ Route::group(['middleware' => 'auth'],function(){
                 //$causals = \App\Models\RecordRow::where('causal_id', $_GET["filterCausals"])->pluck('record_id');
                 $causals = \App\Models\RecordRow::whereIn('causal_id', $causals)->pluck('record_id');
                 $x = $x->whereIn('records.id', $causals);
+                $y = $y->whereIn('records.id', $causals);
             }
             if ($_GET["filterFrom"] != '')
             {
                 $x = $x->where('date', '>=', $_GET["filterFrom"]);
+                $y = $y->where('date', '>=', $_GET["filterFrom"]);
             }
             if ($_GET["filterTo"] != '')
             {
                 $x = $x->where('date', '<=', $_GET["filterTo"]);
+                $y = $y->where('date', '<=', $_GET["filterTo"]);
             }
 
         //});
@@ -429,24 +445,29 @@ Route::group(['middleware' => 'auth'],function(){
         $moneysCausal = \App\Models\Causal::where('money', true)->pluck('id')->toArray();
 
         $total = 0;
-        /*
-        foreach($x->get() as $r)
+
+        $causals = [];
+        if ($_GET["filterCausals"] != "null")
+            $causals = explode(",", $_GET["filterCausals"]);
+        
+        foreach($y->get() as $r)
         {
 
             if (!in_array($r->payment_method_id, $moneys))
             {
-                foreach($r->rows as $rr)
+                if ((!in_array($r->member_id, $exclude_from_records) || in_array($r->causal_id, $moneysCausal)) && (!$r->deleted || $r->deleted == null) && (!in_array($r->causal_id, $excludeCausals) || in_array($r->causal_id, $moneysCausal)) && (!$r->financial_movement || $r->financial_movement == null) && (!$r->corrispettivo_fiscale || $r->corrispettivo_fiscale == null))
                 {
-                    if ((!in_array($rr->member_id, $exclude_from_records) || in_array($r->causal_id, $moneysCausal)) && (!$r->deleted || $r->deleted == null) && (!in_array($rr->causal_id, $excludeCausals) || in_array($r->causal_id, $moneysCausal)) && (!$r->financial_movement || $r->financial_movement == null) && (!$r->corrispettivo_fiscale || $r->corrispettivo_fiscale == null))
+                    if (sizeof($causals) == 0 || in_array($r->causal_id, $causals))
                     {
-                        $total += $rr->amount;
-                        if ($rr->vat_id > 0)
-                            $total += getVatValue($rr->amount, $rr->vat_id);
+                        $total += $r->amount;
+                        if ($r->vat_id > 0)
+                            $total += getVatValue($r->amount, $r->vat_id);
                     }
                 }
+                
             }
         }
-        */
+        
         $count = $x->count();
 
 
@@ -493,7 +514,7 @@ Route::group(['middleware' => 'auth'],function(){
                 'causals' => $causals,
                 'payment' => $r->payment_method->name,
                 'status' => $r->deleted ? 'Annullato' : '',
-                'action' => $r->id . "|" . formatPrice($total) . "|" . ($r->deleted ? 'x' : '')
+                'action' => $r->id . "||" . ($r->deleted ? 'x' : '')
             );
 
 
@@ -512,7 +533,7 @@ Route::group(['middleware' => 'auth'],function(){
             'action' => ''
         );*/
 
-        return json_encode(array("data" => $datas,  "recordsTotal" => $count, "recordsFiltered" => $count));
+        return json_encode(array("data" => $datas,  "recordsTotal" => $count, "recordsFiltered" => $count, "totals" => formatPrice($total)));
 
     });