Browse Source

按分类显示

shish 1 year ago
parent
commit
d58c517e7e
1 changed files with 12 additions and 1 deletions
  1. 12 1
      app-ghs/controllers/ExpendController.php

+ 12 - 1
app-ghs/controllers/ExpendController.php

@@ -41,6 +41,12 @@ class ExpendController extends BaseController
 
         $list = ExpendClass::getAllByCondition($where, null, '*', null);
         $arr = [];
+        $cat = [];
+        $map = dict::getDict('expendTypeMap');
+        foreach ($map as $id => $name) {
+            $cat[$id] = ['num' => 0, 'amount' => 0, 'name' => $name];
+        }
+
         $totalExpend = 0;
         if (!empty($list)) {
             foreach ($list as $expend) {
@@ -48,6 +54,7 @@ class ExpendController extends BaseController
                 $amount = $expend['amount'] ?? 0;
                 $staffName = $expend['staffName'] ?? '';
                 $bx = $expend['bx'] ?? 0;
+                $type = $expend['type'] ?? 0;
                 $currentAmount = $amount;
                 if ($bx == 0) {
                     $hasAmount = 0;
@@ -72,9 +79,13 @@ class ExpendController extends BaseController
                     $arr[$staffId]['num'] = 1;
                 }
                 $totalExpend = bcadd($totalExpend, $currentAmount, 2);
+                if (isset($cat[$type])) {
+                    $cat[$type]['num']++;
+                    $cat[$type]['amount'] = bcadd($cat[$type]['amount'], $amount, 2);
+                }
             }
         }
-        util::success(['list' => $arr, 'totalExpend' => $totalExpend]);
+        util::success(['list' => $arr, 'totalExpend' => $totalExpend, 'cat' => $cat]);
     }
 
     //报销汇总统计 ssh 20240308