业绩明细收入统一按科目映射表判桶
账单明细页已优先使用科目映射表,但业绩同步的收入仍优先取旧总账备注表,导致两套口径冲突。改为收入、优惠、冲减、退款统一使用当前科目映射表,旧表仅在当前映射缺失时兜底。
This commit is contained in:
parent
e0abc6732b
commit
a88c6e8826
@ -343,9 +343,6 @@ class SyncStoreReceiptOrderMatches extends Command
|
||||
$plantingRows = 0;
|
||||
$remarkMap = app(AccountLedgerRemarkMap::class);
|
||||
$tabPlatform = $remarkMap->defaultPlatform($platform);
|
||||
$ledgerMap = $remarkMap->map();
|
||||
$incomeOverlapRows = 0;
|
||||
$incomeOverlapTotal = 0.0;
|
||||
/** @var array<string,int> $promoRowsByKey 门店+订单 维度的优惠/冲减账单行数(用于统计未挂单行数) */
|
||||
$promoRowsByKey = [];
|
||||
// 本月账单里真正命中「优惠收入 / 冲减收入 / 退款」的行数(重建后自检用:
|
||||
@ -354,9 +351,8 @@ class SyncStoreReceiptOrderMatches extends Command
|
||||
foreach ($bills as $bill) {
|
||||
$storeName = (string) ($bill->store_name ?? '');
|
||||
$billItem = (string) ($bill->bill_item ?? '');
|
||||
// 收入金额沿用「总账备注映射」白名单口径,保证既有数字不变;
|
||||
// 优惠 / 冲减两列按新口径(科目映射表的财务备注优先)取数。
|
||||
$legacyRemark = $ledgerMap[$remarkMap->platform($storeName, $tabPlatform) ?? ''][$billItem] ?? null;
|
||||
// 收入 / 优惠 / 冲减 / 退款统一按科目映射表的当前财务备注判桶;
|
||||
// 只有当前科目映射表没有规则时,remark() 才回落到旧总账备注表。
|
||||
$remark = $remarkMap->remark(
|
||||
$storeName,
|
||||
$tabPlatform,
|
||||
@ -367,15 +363,10 @@ class SyncStoreReceiptOrderMatches extends Command
|
||||
$isPromoRemark = in_array($remark, self::DISCOUNT_REMARKS, true)
|
||||
|| in_array($remark, self::OFFSET_REMARKS, true);
|
||||
$isRefundRemark = in_array($remark, self::REFUND_REMARKS, true);
|
||||
$isIncomeRemark = in_array($legacyRemark, self::LEDGER_REMARKS, true);
|
||||
$isIncomeRemark = in_array($remark, self::LEDGER_REMARKS, true);
|
||||
if ($isPromoRemark || $isRefundRemark) {
|
||||
$moneyRemarkRows++;
|
||||
}
|
||||
if ($isIncomeRemark && ($isPromoRemark || $isRefundRemark)) {
|
||||
// 已经在收入金额里的行:不重复计入优惠/冲减列,单独提示金额。
|
||||
$incomeOverlapRows++;
|
||||
$incomeOverlapTotal += (float) $bill->{$amountColumn};
|
||||
}
|
||||
$bucket = match (true) {
|
||||
$isIncomeRemark => 'income',
|
||||
$isRefundRemark => 'refund',
|
||||
@ -467,7 +458,6 @@ class SyncStoreReceiptOrderMatches extends Command
|
||||
$bills,
|
||||
$groups,
|
||||
$remarkMap,
|
||||
$ledgerMap,
|
||||
$tabPlatform,
|
||||
$orderColumn,
|
||||
$timeColumn,
|
||||
@ -496,14 +486,6 @@ class SyncStoreReceiptOrderMatches extends Command
|
||||
number_format($unattachedRows) . ' 行',
|
||||
number_format(($discountTotal + $offsetTotal) - ($attachedDiscount + $attachedOffset), 2),
|
||||
));
|
||||
if ($incomeOverlapRows > 0) {
|
||||
$this->line(sprintf(
|
||||
' 提示:%d 笔(%s 元)按旧口径已计入收入金额,未重复计入优惠/冲减列。',
|
||||
$incomeOverlapRows,
|
||||
number_format($incomeOverlapTotal, 2),
|
||||
));
|
||||
}
|
||||
|
||||
if ((bool) $this->option('amounts-only')) {
|
||||
return $this->backfillPromoAmounts($month, $source, $groups, $promoOnlyGroups, $reportMonth);
|
||||
}
|
||||
@ -1109,14 +1091,12 @@ class SyncStoreReceiptOrderMatches extends Command
|
||||
*
|
||||
* @param iterable<int,mixed> $bills
|
||||
* @param array<string,array<string,mixed>> $groups 已有收款行(已按 payment_count 过滤)
|
||||
* @param array<string,string> $ledgerMap
|
||||
* @return array<string,array<string,mixed>>
|
||||
*/
|
||||
private function promoOnlyGroups(
|
||||
iterable $bills,
|
||||
array $groups,
|
||||
AccountLedgerRemarkMap $remarkMap,
|
||||
array $ledgerMap,
|
||||
?string $tabPlatform,
|
||||
string $orderColumn,
|
||||
string $timeColumn,
|
||||
@ -1142,12 +1122,6 @@ class SyncStoreReceiptOrderMatches extends Command
|
||||
continue;
|
||||
}
|
||||
|
||||
// 已经算进「收入金额」白名单的行不重复补。
|
||||
$legacy = $ledgerMap[$remarkMap->platform($storeName, $tabPlatform) ?? ''][$billItem] ?? null;
|
||||
if (in_array($legacy, self::LEDGER_REMARKS, true)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$rawNo = trim((string) ($bill->{$orderColumn} ?? ''));
|
||||
$core = self::cleanOrderNo($rawNo);
|
||||
$realStore = $realStoreColumn !== '' ? (string) ($bill->{$realStoreColumn} ?? '') : '';
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user