|
|
@@ -44,24 +44,48 @@ class GhsClass extends BaseClass
|
|
|
];
|
|
|
}
|
|
|
|
|
|
- public static function sumTotalOutstandingDebt($shopId, $delStatus = 0)
|
|
|
+ /**
|
|
|
+ * 【用途】批发店采购列表页「总待结」:一次查库同时汇总金额与笔数。
|
|
|
+ * 【口径】仅净 balance 为负(仍有待结金额)的供货商行计入。
|
|
|
+ * @return array{amount:string,num:int}
|
|
|
+ */
|
|
|
+ public static function sumTotalOutstandingDebtStats($shopId, $delStatus = 0)
|
|
|
{
|
|
|
if (empty($shopId)) {
|
|
|
- return '0.00';
|
|
|
+ return ['amount' => '0.00', 'num' => 0];
|
|
|
}
|
|
|
- // 总待结:各行净 balance 为负时的待结金额之和(合并后 debtNum/balance 已为真相源)
|
|
|
$rows = self::getAllByCondition(
|
|
|
['ownShopId' => $shopId, 'delStatus' => $delStatus],
|
|
|
null,
|
|
|
- 'balance,debtAmount,balanceMerged'
|
|
|
+ 'balance,debtAmount,balanceMerged,debtNum'
|
|
|
);
|
|
|
- $total = '0.00';
|
|
|
+ $totalAmount = '0.00';
|
|
|
+ $totalNum = 0;
|
|
|
if (!empty($rows)) {
|
|
|
foreach ($rows as $row) {
|
|
|
- $total = bcadd($total, AccountMoneyClass::getOutstandingDebt($row), 2);
|
|
|
+ $outstanding = AccountMoneyClass::getOutstandingDebt($row);
|
|
|
+ if (bccomp($outstanding, '0', 2) <= 0) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ $totalAmount = bcadd($totalAmount, $outstanding, 2);
|
|
|
+ $totalNum += intval($row['debtNum'] ?? 0);
|
|
|
}
|
|
|
}
|
|
|
- return $total;
|
|
|
+ return ['amount' => $totalAmount, 'num' => $totalNum];
|
|
|
+ }
|
|
|
+
|
|
|
+ /** @deprecated 请用 sumTotalOutstandingDebtStats */
|
|
|
+ public static function sumTotalOutstandingDebt($shopId, $delStatus = 0)
|
|
|
+ {
|
|
|
+ $stats = self::sumTotalOutstandingDebtStats($shopId, $delStatus);
|
|
|
+ return $stats['amount'];
|
|
|
+ }
|
|
|
+
|
|
|
+ /** @deprecated 请用 sumTotalOutstandingDebtStats */
|
|
|
+ public static function sumTotalOutstandingDebtNum($shopId, $delStatus = 0)
|
|
|
+ {
|
|
|
+ $stats = self::sumTotalOutstandingDebtStats($shopId, $delStatus);
|
|
|
+ return $stats['num'];
|
|
|
}
|
|
|
|
|
|
|