fix: 管理费用按整张已打款审批汇总 #818
@ -299,15 +299,21 @@ class ManagementExpensesPageData
|
||||
'Y-m-d',
|
||||
$filters['paid_month'] . '-01',
|
||||
)->startOfDay();
|
||||
$query->where(
|
||||
'd.paid_at',
|
||||
'>=',
|
||||
$monthStart->toDateString(),
|
||||
)->where(
|
||||
'd.paid_at',
|
||||
'<',
|
||||
$monthStart->copy()->addMonthNoOverflow()->toDateString(),
|
||||
);
|
||||
$monthEnd = $monthStart->copy()->addMonthNoOverflow()->toDateString();
|
||||
$query->whereExists(function (Builder $paidApproval) use ($monthStart, $monthEnd): void {
|
||||
$paidApproval
|
||||
->selectRaw('1')
|
||||
->from('ding_process_detail_mirror as paid_detail')
|
||||
->whereColumn('paid_detail.business_id', 'd.business_id')
|
||||
->where('paid_detail.status', '已完成')
|
||||
->where('paid_detail.cashier_status', 'completed')
|
||||
->where(function (Builder $paymentSource): void {
|
||||
$paymentSource->whereNull('paid_detail.payment_source_state')
|
||||
->orWhere('paid_detail.payment_source_state', '<>', 'not_applicable');
|
||||
})
|
||||
->where('paid_detail.paid_at', '>=', $monthStart->toDateString())
|
||||
->where('paid_detail.paid_at', '<', $monthEnd);
|
||||
});
|
||||
}
|
||||
|
||||
if (($filters['expense_category'] ?? '') !== '') {
|
||||
|
||||
@ -511,7 +511,8 @@
|
||||
<h2>{{ $pageTitle ?? '管理费用' }}</h2>
|
||||
<p>
|
||||
数据源为 OA 流程中审批已完成、涉及付款且出纳已打款的明细。科目规则来自“流程科目映射”,
|
||||
默认展示上个月打款的数据;不涉及付款或出纳未打款的审批不计入汇总,
|
||||
默认展示上个月打款的数据;打款月份命中审批单后,整张审批单的明细都计入汇总;
|
||||
不涉及付款或出纳未打款的审批不计入汇总,
|
||||
二级汇总区分进费比、不进费比和未映射科目,
|
||||
点击二级可查看三级和明细模板。
|
||||
</p>
|
||||
|
||||
@ -61,7 +61,7 @@ class ManagementExpensesPageDataTest extends TestCase
|
||||
static fn (array $row): string => $row['expense_category'] . '|' . $row['second_level'],
|
||||
);
|
||||
$this->assertSame(120.0, $groups['管理费用|办公费']['amount_total']);
|
||||
$this->assertSame(1, $groups['管理费用|办公费']['approval_count']);
|
||||
$this->assertSame(2, $groups['管理费用|办公费']['approval_count']);
|
||||
$this->assertSame(200.0, $groups['销售费用|技术服务费']['in_fee_ratio_amount']);
|
||||
$this->assertSame(0.0, $groups['销售费用|技术服务费']['non_fee_ratio_amount']);
|
||||
$this->assertSame(200.0, $groups['销售费用|技术服务费']['amount_total']);
|
||||
@ -101,7 +101,7 @@ class ManagementExpensesPageDataTest extends TestCase
|
||||
array_values(ManagementExpensesPageData::DETAIL_COLUMNS),
|
||||
);
|
||||
$this->assertSame(
|
||||
['5602.04', '5602.04'],
|
||||
['202609251200000000008', '202610011200000000001'],
|
||||
array_column($data['rows'], 'business_id'),
|
||||
);
|
||||
$this->assertSame('不进费比', $data['rows'][0]['fee_ratio']);
|
||||
@ -121,6 +121,51 @@ class ManagementExpensesPageDataTest extends TestCase
|
||||
$this->assertSame(50.0, $data['rows'][0]['amount']);
|
||||
}
|
||||
|
||||
public function test_paid_month_includes_all_lines_from_a_paid_approval(): void
|
||||
{
|
||||
$businessId = '202610201200000000001';
|
||||
$first = $this->row(
|
||||
$businessId,
|
||||
'5602.04',
|
||||
1,
|
||||
10,
|
||||
'已完成',
|
||||
'completed',
|
||||
'present',
|
||||
'2026-10-20 10:00:00',
|
||||
'2026-10-20 00:00',
|
||||
);
|
||||
$second = $this->row(
|
||||
$businessId,
|
||||
'5602.04',
|
||||
2,
|
||||
15,
|
||||
'已完成',
|
||||
'completed',
|
||||
'present',
|
||||
'2026-10-20 10:00:00',
|
||||
null,
|
||||
);
|
||||
DB::connection('business_mirror')
|
||||
->table('ding_process_detail_mirror')
|
||||
->insert([$first, $second]);
|
||||
|
||||
$data = $this->pageData->details(Request::create(
|
||||
'/1/workspace/financial-operations/management-expenses/details',
|
||||
'GET',
|
||||
['business_id' => $businessId],
|
||||
));
|
||||
|
||||
$this->assertSame(2, $data['pagination']['total']);
|
||||
$this->assertSame(2, $data['summary']['row_count']);
|
||||
$this->assertSame(1, $data['summary']['approval_count']);
|
||||
$this->assertSame(25.0, $data['summary']['amount_total']);
|
||||
$this->assertSame(
|
||||
[$businessId, $businessId],
|
||||
array_column($data['rows'], 'business_id'),
|
||||
);
|
||||
}
|
||||
|
||||
public function test_workbook_mapping_snapshot_is_complete_and_unique(): void
|
||||
{
|
||||
$mapping = json_decode(
|
||||
@ -225,34 +270,35 @@ class ManagementExpensesPageDataTest extends TestCase
|
||||
],
|
||||
]);
|
||||
DB::connection('business_mirror')->table('ding_process_detail_mirror')->insert([
|
||||
$this->row('5602.04', 1, 100, '已完成', 'completed', 'present', '2026-10-01 10:00:00', '2026-10-10'),
|
||||
$this->row('5601.05.03', 1, 200, '已完成', 'completed', 'present', '2026-10-02 10:00:00', '2026-10-11'),
|
||||
$this->row('5601.05.03', 1, 300, '审批中', 'completed', 'present', '2026-10-03 10:00:00', '2026-10-12'),
|
||||
$this->row('5602.04', 1, 400, '审批中', 'pending', 'present', '2026-10-04 10:00:00', '2026-10-13'),
|
||||
$this->row('9999.99', 1, 50, '已完成', 'completed', 'present', '2026-10-05 10:00:00', '2026-10-14'),
|
||||
$this->row('5601.05.03', 1, 70, '已完成', 'not_applicable', 'not_applicable', '2026-10-06 10:00:00', '2026-10-15'),
|
||||
$this->row('5602.04', 1, 25, '已完成', null, 'present', '2026-10-07 10:00:00', '2026-10-16'),
|
||||
$this->row('5602.04', 1, 20, '已完成', 'completed', 'present', '2026-09-25 10:00:00', '2026-10-20'),
|
||||
$this->row('5602.04', 1, 30, '已完成', 'completed', 'present', '2026-10-28 10:00:00', '2026-09-30'),
|
||||
$this->row('202610011200000000001', '5602.04', 1, 100, '已完成', 'completed', 'present', '2026-10-01 10:00:00', '2026-10-10'),
|
||||
$this->row('202610021200000000002', '5601.05.03', 1, 200, '已完成', 'completed', 'present', '2026-10-02 10:00:00', '2026-10-11'),
|
||||
$this->row('202610031200000000003', '5601.05.03', 1, 300, '审批中', 'completed', 'present', '2026-10-03 10:00:00', '2026-10-12'),
|
||||
$this->row('202610041200000000004', '5602.04', 1, 400, '审批中', 'pending', 'present', '2026-10-04 10:00:00', '2026-10-13'),
|
||||
$this->row('202610051200000000005', '9999.99', 1, 50, '已完成', 'completed', 'present', '2026-10-05 10:00:00', '2026-10-14'),
|
||||
$this->row('202610061200000000006', '5601.05.03', 1, 70, '已完成', 'not_applicable', 'not_applicable', '2026-10-06 10:00:00', '2026-10-15'),
|
||||
$this->row('202610071200000000007', '5602.04', 1, 25, '已完成', null, 'present', '2026-10-07 10:00:00', '2026-10-16'),
|
||||
$this->row('202609251200000000008', '5602.04', 1, 20, '已完成', 'completed', 'present', '2026-09-25 10:00:00', '2026-10-20'),
|
||||
$this->row('202610281200000000009', '5602.04', 1, 30, '已完成', 'completed', 'present', '2026-10-28 10:00:00', '2026-09-30'),
|
||||
]);
|
||||
}
|
||||
|
||||
/** @return array<string,mixed> */
|
||||
private function row(
|
||||
string $businessId,
|
||||
string $accountCode,
|
||||
int $lineNo,
|
||||
float $amount,
|
||||
string $status,
|
||||
?string $cashierStatus,
|
||||
string $paymentSourceState,
|
||||
string $approvalFinishedAt,
|
||||
string $paidAt,
|
||||
?string $paidAt,
|
||||
): array {
|
||||
return [
|
||||
'business_id' => $businessId,
|
||||
'process_instance_id' => 'process-' . $businessId,
|
||||
'line_no' => $lineNo,
|
||||
'account_code' => $businessId,
|
||||
'account_code' => $accountCode,
|
||||
'account_name' => '流程科目',
|
||||
'originator_department' => '财务中心',
|
||||
'originator_name' => '测试申请人',
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user