瀏覽代碼

Summary - totals

Samson Mutunga 1 年之前
父節點
當前提交
c58a876cc5

+ 25 - 1
app/Http/Controllers/AdminController.php

@@ -179,10 +179,34 @@ class AdminController extends Controller
         $orders = $orders->orderBy('created_at', 'DESC');
 
         $clonedOrdersQuery = clone $orders;
+        $ordersSummary = $this->getOrdersQuickSummary($clonedOrdersQuery);
 
         $orders = $orders->paginate(30);
 
-        return view('app.my-account.admin.orders.index', compact('orders', 'filters'));
+        return view('app.my-account.admin.orders.index', compact('orders', 'filters', 'ordersSummary'));
+    }
+
+    private function getOrdersQuickSummary($storeOrderQuery){
+        $qryClone = clone $storeOrderQuery;
+
+        $records = $storeOrderQuery->get();
+        $ordersTotalAmount = 0;
+        foreach($records as $record){
+            $ordersTotalAmount = $ordersTotalAmount + $record->total();
+        }
+
+        $ids = $qryClone->pluck('id')->toArray();
+        $trxs = FinancialTransaction::whereIn('order_id', $ids)->where('charge_or_refund', 'CHARGE')->get();
+        $totalAmountCharged = 0;
+        foreach($trxs as $trx){
+            $totalAmountCharged = $totalAmountCharged + floatval($trx->amount);
+        }
+
+        $summary = [
+            'orders_total_amount' => $ordersTotalAmount,
+            'total_amount_charged' => $totalAmountCharged,
+        ];
+        return $summary;
     }
 
     public function orderDashboard(StoreOrder $order)

+ 9 - 0
resources/views/app/my-account/admin/orders/partials/table.blade.php

@@ -4,6 +4,15 @@
             <b>{{ $rows->total() }}</b> records
         </div>
     </div>
+    <div>
+        @if(@$ordersSummary)
+        <div class="d-flex align-items-start">
+            @foreach($ordersSummary as $k=>$v)
+                <div class="ms-2"><b>{{ toHumanReadable($k) }}: </b> ${{ displayAmount('', $v) }}</div>
+            @endforeach
+        </div>
+        @endif
+   </div>
 </div>