fix: 区分 OA 审批应付金额与实际付款

This commit is contained in:
yueyang 2026-11-12 09:25:52 +08:00
parent ad6ce5ddf4
commit 474866b5f8
5 changed files with 105 additions and 6 deletions

View File

@ -246,6 +246,57 @@ class DingProcessDetailMirrorRepository
->forPage($page, $perPage)
->get()
->all();
$businessIds = array_map(
static fn (object $row): string => (string) $row->business_id,
$data,
);
if ($businessIds !== []) {
$purposes = [];
$purposeRows = $this->connection->table('ding_process_detail_mirror')
->where('source_scope', $this->scope())
->whereIn('business_id', $businessIds)
->whereNotNull('purpose')
->where('purpose', '!=', '')
->orderBy('business_id')
->orderBy('line_no')
->get(['business_id', 'purpose']);
foreach ($purposeRows as $purposeRow) {
$businessId = (string) $purposeRow->business_id;
$purpose = trim((string) $purposeRow->purpose);
if ($purpose !== '' && ! in_array($purpose, $purposes[$businessId] ?? [], true)) {
$purposes[$businessId][] = $purpose;
}
}
$paymentTotals = [];
if ($this->structuredPaymentsEnabled()) {
$paymentTotals = $this->connection->table('ding_process_payment_mirror')
->where('source_scope', $this->scope())
->whereIn('business_id', $businessIds)
->select('business_id')
->selectRaw('SUM(COALESCE(amount, 0)) as payment_amount_total')
->groupBy('business_id')
->pluck('payment_amount_total', 'business_id')
->all();
} else {
$paymentTotals = $this->connection->table('ding_process_detail_mirror')
->where('source_scope', $this->scope())
->whereIn('business_id', $businessIds)
->select('business_id')
->selectRaw('SUM(COALESCE(bank_amount, 0)) as payment_amount_total')
->groupBy('business_id')
->pluck('payment_amount_total', 'business_id')
->all();
}
foreach ($data as $row) {
$businessId = (string) $row->business_id;
$row->purpose = implode(';', $purposes[$businessId] ?? []);
$row->payment_amount_total = (float) ($paymentTotals[$businessId] ?? 0);
}
}
$state = $this->state();
$staleAfterMinutes = max(
15,

View File

@ -680,7 +680,7 @@
}
.process-details-table.is-approval-summary {
min-width: 42rem;
min-width: 68rem;
table-layout: fixed;
}
@ -1299,8 +1299,14 @@
</b>
</a>
@endif
<div class="item"><span>金额合计</span><b>{{ $money($summary['amount_total'] ?? null) }}</b></div>
<div class="item"><span>{{ $paymentSummaryLabel }}</span><b>{{ $money($summary['bank_amount_total'] ?? null) }}</b></div>
<div class="item">
<span>{{ $approvalSummaryMode ? '应付金额合计' : '金额合计' }}</span>
<b>{{ $money($summary['amount_total'] ?? null) }}</b>
</div>
<div class="item">
<span>{{ $approvalSummaryMode ? '实际付款合计' : $paymentSummaryLabel }}</span>
<b>{{ $money($summary['bank_amount_total'] ?? null) }}</b>
</div>
</div>
<details class="process-details-note-disclosure">
@ -1309,6 +1315,12 @@
统计与口径说明
</summary>
<div class="process-details-note-content">
@if ($approvalSummaryMode)
<p>
应付金额按审批费用明细汇总;实际付款按审批表单中的结构化付款明细汇总。
未产生付款记录的审批,其实际付款按 0 元展示,因此应付金额与实际付款金额不要求相等。
</p>
@else
<p>
金额合计按审批费用明细汇总,付款明细合计按审批表单中的结构化付款明细汇总,不等同于出纳已确认付款;
打款日期以审批单为准:审批单在所选期间有打款记录时,整张审批单的明细和付款金额都计入汇总;
@ -1319,6 +1331,7 @@
已完成流程不重复回查,其他时间直接显示最近镜像,已等待按实际小时显示。当前展示的是当前账号权限范围内可读取的钉钉OA审批流程;
审批中的金额和行项目仍可能随流程变化。企业级全量数据待领导开通 OA 权限后切换。
</p>
@endif
</div>
</details>
@ -1329,7 +1342,9 @@
@if ($approvalSummaryMode)
<tr>
<th>审批编号</th>
<th class="num">总金额</th>
<th>用途</th>
<th class="num">应付金额</th>
<th class="num">实际付款</th>
<th>已等待</th>
</tr>
@else
@ -1363,7 +1378,9 @@
@if ($approvalSummaryMode)
<tr>
<td>{{ $row->business_id }}</td>
<td class="wide" title="{{ $row->purpose ?? '' }}">{{ $text($row->purpose ?? null) }}</td>
<td class="num">{{ $money($row->amount_total ?? null) }}</td>
<td class="num">{{ $money($row->payment_amount_total ?? null) }}</td>
<td>{{ $waitText($row->current_task_started_at ?? null) }}</td>
</tr>
@else
@ -1397,7 +1414,7 @@
@endif
@empty
<tr>
<td colspan="{{ $approvalSummaryMode ? 3 : 21 }}" class="process-details-empty">
<td colspan="{{ $approvalSummaryMode ? 5 : 21 }}" class="process-details-empty">
当前筛选条件没有OA流程数据。可以调整月份、单据类型、状态或关键词后重试。
</td>
</tr>

View File

@ -203,6 +203,8 @@ class ProcessDetailsPageTest extends FeatureTestCase
'business_id' => $businessId,
'status' => '审批中',
'amount_total' => 500.00,
'payment_amount_total' => 200.00,
'purpose' => '办公用品采购;交通费',
'current_task_started_at' => \Modules\EcommerceFinance\Support\OaProcessTime::now()
->subMinutes(90)
->startOfMinute()
@ -234,9 +236,13 @@ class ProcessDetailsPageTest extends FeatureTestCase
->assertSee('审批汇总')
->assertSee($businessId)
->assertSee('<th>审批编号</th>', false)
->assertSee('<th class="num">总金额</th>', false)
->assertSee('<th>用途</th>', false)
->assertSee('<th class="num">应付金额</th>', false)
->assertSee('<th class="num">实际付款</th>', false)
->assertSee('<th>已等待</th>', false)
->assertSee('办公用品采购;交通费')
->assertSee('500.00')
->assertSee('200.00')
->assertSee('1小时')
->assertDontSee('发起人部门')
->assertDontSee('付款明细金额')

View File

@ -74,6 +74,7 @@ class DingProcessDetailMirrorRepositoryTest extends TestCase
$this->assertSame(4, $result['summary']['rows']);
$this->assertSame(2, $result['summary']['approvals']);
$this->assertEqualsWithDelta(650.5, $result['summary']['amount_total'], 0.001);
$this->assertEqualsWithDelta(350.5, $result['summary']['bank_amount_total'], 0.001);
$rows = collect($result['data'])->keyBy('business_id');
$this->assertEqualsWithDelta(
@ -86,6 +87,24 @@ class DingProcessDetailMirrorRepositoryTest extends TestCase
(float) $rows['202602031200000000002']->amount_total,
0.001,
);
$this->assertSame(
'办公用品采购;交通费',
(string) $rows['202601011200000000001']->purpose,
);
$this->assertSame(
'供应商货款',
(string) $rows['202602031200000000002']->purpose,
);
$this->assertEqualsWithDelta(
150.5,
(float) $rows['202601011200000000001']->payment_amount_total,
0.001,
);
$this->assertEqualsWithDelta(
200,
(float) $rows['202602031200000000002']->payment_amount_total,
0.001,
);
$this->assertSame(
'2026-02-03 09:00:00',
(string) $rows['202602031200000000002']->current_task_started_at,

View File

@ -46,6 +46,12 @@ class ProcessDetailsPageDataTest extends TestCase
$this->assertStringContainsString('data-oa-refresh-button', $content);
$this->assertStringContainsString('$approvalSummaryUrl', $content);
$this->assertStringContainsString('查看按审批编号去重的审批汇总', $content);
$this->assertStringContainsString('应付金额合计', $content);
$this->assertStringContainsString('实际付款合计', $content);
$this->assertStringContainsString('应付金额与实际付款金额不要求相等', $content);
$this->assertStringContainsString('<th>用途</th>', $content);
$this->assertStringContainsString('<th class="num">应付金额</th>', $content);
$this->assertStringContainsString('<th class="num">实际付款</th>', $content);
$this->assertStringNotContainsString('process-details-approval-link', $content);
$this->assertStringNotContainsString(
"route('business.process-details.detail'",