Luca Parisio hai 1 ano
pai
achega
5d2b02fd61
Modificáronse 2 ficheiros con 35 adicións e 14 borrados
  1. 10 2
      resources/views/livewire/records_in.blade.php
  2. 25 12
      routes/web.php

+ 10 - 2
resources/views/livewire/records_in.blade.php

@@ -151,7 +151,7 @@
                 </tfoot>-->
             </table>
 
-            <!--<br><b class="totalDiv"></b>-->
+            <br><b class="totalDiv"></b>
 
         </section>
 
@@ -1129,7 +1129,15 @@
                 scrollX: true,
                 scrollY: 800,*/
                 serverSide: true,
-                ajax: '/get_record_in?filterCommercial=' + filterCommercial + "&filterMember=" + filterMember + "&filterPaymentMethod=" + filterPaymentMethod + "&filterCausals=" + filterCausals + "&filterFrom=" + filterFrom + "&filterTo=" + filterTo,
+                ajax: {
+                    url : '/get_record_in?filterCommercial=' + filterCommercial + "&filterMember=" + filterMember + "&filterPaymentMethod=" + filterPaymentMethod + "&filterCausals=" + filterCausals + "&filterFrom=" + filterFrom + "&filterTo=" + filterTo,
+                    dataSrc: function (json){
+                        if(json.totals){
+                           $(".totalDiv").html('Totale&nbsp;:&nbsp;<b>' + json.totals + '</b>');
+                        }
+                        return json.data;
+                    }
+                },
                 columns: [
                     //{ data: 'id' },
                     {

+ 25 - 12
routes/web.php

@@ -350,6 +350,9 @@ 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.*', \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 +360,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 +374,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 +398,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 +443,23 @@ Route::group(['middleware' => 'auth'],function(){
         $moneysCausal = \App\Models\Causal::where('money', true)->pluck('id')->toArray();
 
         $total = 0;
-        /*
-        foreach($x->get() as $r)
+
+        foreach($y->get() as $r)
         {
 
             if (!in_array($r->payment_method_id, $moneys))
             {
-                foreach($r->rows as $rr)
-                {
-                    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 ((!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))
                     {
-                        $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 +506,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 +525,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)));
 
     });