shish пре 6 часа
родитељ
комит
f4eeef2bf9

+ 9 - 2
app-ghs/controllers/StatCgController.php

@@ -23,7 +23,11 @@ class StatCgController extends BaseController
         $respond = StatCgClass::statCg($mainId);
         $respond = StatCgClass::statCg($mainId);
         $list = $respond['itemList'] ?? [];
         $list = $respond['itemList'] ?? [];
         $staffCg = $respond['staffCg'] ?? [];
         $staffCg = $respond['staffCg'] ?? [];
-        util::success(['list' => $list, 'staffCg' => $staffCg]);
+        util::success([
+            'list' => $list,
+            'staffCg' => $staffCg,
+            'nextDayDeduct' => $respond['nextDayDeduct'] ?? '0.00',
+        ]);
     }
     }
 
 
 
 
@@ -40,7 +44,10 @@ class StatCgController extends BaseController
         $mainId = $this->mainId;
         $mainId = $this->mainId;
         $respond = StatCgClass::statCgYj($mainId);
         $respond = StatCgClass::statCgYj($mainId);
         $staffCg = $respond['staffCg'] ?? [];
         $staffCg = $respond['staffCg'] ?? [];
-        util::success(['staffCg' => $staffCg]);
+        util::success([
+            'staffCg' => $staffCg,
+            'nextDayDeduct' => $respond['nextDayDeduct'] ?? '0.00',
+        ]);
     }
     }
 
 
 }
 }

+ 8 - 1
app-ghs/controllers/StatCgGhsController.php

@@ -145,6 +145,7 @@ class StatCgGhsController extends BaseController
         }
         }
 
 
         // 隔天售后:按通过日扣供货商金额;无当日入库也建负行(笔数不减)
         // 隔天售后:按通过日扣供货商金额;无当日入库也建负行(笔数不减)
+        $nextDayDeduct = CgPurchaseNextDayClass::sumAmountByMainAndTime($mainId, $currentStartTime, $currentEndTime);
         $nextMap = CgPurchaseNextDayClass::sumAmountGroupByGhs($mainId, $currentStartTime, $currentEndTime);
         $nextMap = CgPurchaseNextDayClass::sumAmountGroupByGhs($mainId, $currentStartTime, $currentEndTime);
         foreach ($nextMap as $ghsId => $amt) {
         foreach ($nextMap as $ghsId => $amt) {
             if (bccomp((string)$amt, '0', 2) <= 0) {
             if (bccomp((string)$amt, '0', 2) <= 0) {
@@ -193,7 +194,12 @@ class StatCgGhsController extends BaseController
             }
             }
         }
         }
         if (!empty($list)) {
         if (!empty($list)) {
-            $list = array_values($list);
+            // 去掉订单数与金额都为 0 的行,避免全零供货商淹没隔天负金额行
+            $list = array_values(array_filter($list, function ($row) {
+                $num = bcadd((string)($row['num'] ?? '0'), '0', 2);
+                $act = bcadd((string)($row['actPrice'] ?? '0'), '0', 2);
+                return bccomp($num, '0', 2) != 0 || bccomp($act, '0', 2) != 0;
+            }));
         }
         }
         if ($export == 1) {
         if ($export == 1) {
             if (empty($list)) {
             if (empty($list)) {
@@ -215,6 +221,7 @@ class StatCgGhsController extends BaseController
             'totalTkPrice' => $totalTkPrice,
             'totalTkPrice' => $totalTkPrice,
             //增加项
             //增加项
             'totalOnlyTkPrice' => $totalOnlyTkPrice,
             'totalOnlyTkPrice' => $totalOnlyTkPrice,
+            'nextDayDeduct' => $nextDayDeduct,
         ]);
         ]);
         //[['amount','ghsId','ghsName','num','py']]
         //[['amount','ghsId','ghsName','num','py']]
     }
     }

+ 21 - 0
biz-ghs/cg/classes/CgPurchaseNextDayClass.php

@@ -196,6 +196,27 @@ class CgPurchaseNextDayClass
         return "IFNULL(NULLIF({$alias}.passTime,'0000-00-00 00:00:00'), {$alias}.addTime)";
         return "IFNULL(NULLIF({$alias}.passTime,'0000-00-00 00:00:00'), {$alias}.addTime)";
     }
     }
 
 
+    /**
+     * 按时段汇总成功隔天售后总金额(各统计页「隔天扣减」提示用)
+     * @return string
+     */
+    public static function sumAmountByMainAndTime($mainId, $startTime, $endTime)
+    {
+        $passExpr = self::passTimeSqlExpr('r');
+        $sql = "SELECT COALESCE(SUM(r.refundPrice),0) AS total
+            FROM xhGhsCgRefund r
+            WHERE r.mainId=:mainId AND r.status=:status AND r.sameDay=:sameDay
+              AND {$passExpr} BETWEEN :start AND :end";
+        $row = Yii::$app->db->createCommand($sql, [
+            ':mainId' => intval($mainId),
+            ':status' => 1,
+            ':sameDay' => self::SAME_DAY_NO,
+            ':start' => $startTime,
+            ':end' => $endTime,
+        ])->queryOne();
+        return bcadd($row['total'] ?? '0', '0', 2);
+    }
+
     /**
     /**
      * 按供货商汇总隔天售后金额(供货业绩 cgStat 通过日扣减)
      * 按供货商汇总隔天售后金额(供货业绩 cgStat 通过日扣减)
      * @return array ghsId => amount
      * @return array ghsId => amount

+ 17 - 5
biz-ghs/stat/classes/StatCgClass.php

@@ -107,9 +107,15 @@ class StatCgClass extends BaseClass
 
 
         // 隔天售后:按通过日扣花材数量/金额;无当日入库也建负行
         // 隔天售后:按通过日扣花材数量/金额;无当日入库也建负行
         self::applyNextDayAdjustToCgItemRows($arr, $productInfo, $mainId, $currentStartTime, $currentEndTime);
         self::applyNextDayAdjustToCgItemRows($arr, $productInfo, $mainId, $currentStartTime, $currentEndTime);
+        $nextDayDeduct = CgPurchaseNextDayClass::sumAmountByMainAndTime($mainId, $currentStartTime, $currentEndTime);
 
 
         if (!empty($arr)) {
         if (!empty($arr)) {
-            $arr = array_values($arr);
+            // 去掉数量金额都为 0 的行,保留负数行便于看见隔天扣减
+            $arr = array_values(array_filter($arr, function ($row) {
+                $num = bcadd((string)($row['num'] ?? '0'), '0', 2);
+                $amount = bcadd((string)($row['amount'] ?? '0'), '0', 2);
+                return bccomp($num, '0', 2) != 0 || bccomp($amount, '0', 2) != 0;
+            }));
             $arr = arrayUtil::arraySort($arr, $rank);
             $arr = arrayUtil::arraySort($arr, $rank);
         }
         }
         if (!empty($cgData)) {
         if (!empty($cgData)) {
@@ -121,7 +127,7 @@ class StatCgClass extends BaseClass
             self::exportCgItem($arr,$mainId);
             self::exportCgItem($arr,$mainId);
         }
         }
 
 
-        return ['itemList' => $arr, 'staffCg' => $cgData];
+        return ['itemList' => $arr, 'staffCg' => $cgData, 'nextDayDeduct' => $nextDayDeduct];
     }
     }
 
 
     /**
     /**
@@ -282,6 +288,7 @@ class StatCgClass extends BaseClass
         }
         }
 
 
         // 隔天售后:按原单采购人扣金额;无当日入库也建负行(笔数不减)
         // 隔天售后:按原单采购人扣金额;无当日入库也建负行(笔数不减)
+        $nextDayDeduct = CgPurchaseNextDayClass::sumAmountByMainAndTime($mainId, $currentStartTime, $currentEndTime);
         $nextMap = CgPurchaseNextDayClass::sumAmountGroupByCgStaff($mainId, $currentStartTime, $currentEndTime);
         $nextMap = CgPurchaseNextDayClass::sumAmountGroupByCgStaff($mainId, $currentStartTime, $currentEndTime);
         foreach ($nextMap as $sid => $row) {
         foreach ($nextMap as $sid => $row) {
             $amt = $row['amount'] ?? '0';
             $amt = $row['amount'] ?? '0';
@@ -291,7 +298,7 @@ class StatCgClass extends BaseClass
             if (!isset($cgData[$sid])) {
             if (!isset($cgData[$sid])) {
                 $cgData[$sid] = [
                 $cgData[$sid] = [
                     'cgStaffId' => $sid,
                     'cgStaffId' => $sid,
-                    'cgStaffName' => $row['cgStaffName'] ?? '',
+                    'cgStaffName' => $row['cgStaffName'] !== '' ? $row['cgStaffName'] : '未记名',
                     'amount' => '0.00',
                     'amount' => '0.00',
                     'num' => 0,
                     'num' => 0,
                 ];
                 ];
@@ -300,9 +307,14 @@ class StatCgClass extends BaseClass
         }
         }
 
 
         if (!empty($cgData)) {
         if (!empty($cgData)) {
-            $cgData = array_values($cgData);
+            // 去掉订单数与金额都为 0 的行,保留纯隔天负金额行
+            $cgData = array_values(array_filter($cgData, function ($row) {
+                $num = bcadd((string)($row['num'] ?? '0'), '0', 2);
+                $amount = bcadd((string)($row['amount'] ?? '0'), '0', 2);
+                return bccomp($num, '0', 2) != 0 || bccomp($amount, '0', 2) != 0;
+            }));
         }
         }
-        return ['staffCg' => $cgData];
+        return ['staffCg' => $cgData, 'nextDayDeduct' => $nextDayDeduct];
     }
     }
 
 
 }
 }

+ 14 - 1
biz-ghs/stat/classes/StatSaleClass.php

@@ -241,9 +241,13 @@ class StatSaleClass extends BaseClass
         return ['list' => $arr, 'totalAmount' => $totalAmount, 'totalNum' => $totalNum, 'totalCost' => $totalCost, 'totalProfit' => $totalProfit];
         return ['list' => $arr, 'totalAmount' => $totalAmount, 'totalNum' => $totalNum, 'totalCost' => $totalCost, 'totalProfit' => $totalProfit];
     }
     }
 
 
+    /**
+     * 经营利润总表:收入 − 支出。
+     * 采购隔天售后:不改「花材采购」入库口径;通过日单独「采购隔天退货」(退货并退款+仅退款合计)计入收入。
+     */
     public static function profile($mainId)
     public static function profile($mainId)
     {
     {
-        //收入:批发开单、零售开单(含门店、美团和微信客服)、出库
+        //收入:批发开单、零售开单(含门店、美团和微信客服)、出库、采购隔天退货
         //支出:采购、调拨入库、批发退款、零售退款、店租、水电、伙食
         //支出:采购、调拨入库、批发退款、零售退款、店租、水电、伙食
 
 
         $get = Yii::$app->request->get();
         $get = Yii::$app->request->get();
@@ -359,6 +363,13 @@ class StatSaleClass extends BaseClass
             2
             2
         );
         );
 
 
+        // 采购隔天售后(退货并退款+仅退款):通过日合计,单列收入,不改花材采购
+        $cgNextDayRefund = CgPurchaseNextDayClass::sumAmountByMainAndTime(
+            $mainId,
+            $currentStartTime,
+            $currentEndTime
+        );
+
         //零售开单
         //零售开单
         $payCodeIncome = 0;
         $payCodeIncome = 0;
         $lsAfterSale = 0;
         $lsAfterSale = 0;
@@ -441,6 +452,8 @@ class StatSaleClass extends BaseClass
             ['name' => '批发', 'id' => 'pf', 'amount' => floatval($pfIncome)],
             ['name' => '批发', 'id' => 'pf', 'amount' => floatval($pfIncome)],
             ['name' => '零售', 'id' => 'ls', 'amount' => floatval($lsIncome)],
             ['name' => '零售', 'id' => 'ls', 'amount' => floatval($lsIncome)],
             ['name' => '调拨出库', 'id' => 'allot', 'amount' => floatval($stockOut)],
             ['name' => '调拨出库', 'id' => 'allot', 'amount' => floatval($stockOut)],
+            // 采购隔天售后冲回(含退货并退款、仅退款);后续若细分再拆行
+            ['name' => '采购隔天退货', 'id' => 'cgNextDay', 'amount' => floatval($cgNextDayRefund)],
         ];
         ];
         $expend = [
         $expend = [
             ['name' => '批发运费', 'id' => 'pfSendCost', 'amount' => floatval($pfSendCost)],
             ['name' => '批发运费', 'id' => 'pfSendCost', 'amount' => floatval($pfSendCost)],