feat: 管理费用明细增加店铺与金额下钻
This commit is contained in:
parent
46f62575ff
commit
2873d33e4b
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
private function connection(): string
|
||||
{
|
||||
return (string) config('upstream_mirrors.connection', 'business_mirror');
|
||||
}
|
||||
|
||||
public function up(): void
|
||||
{
|
||||
if (app()->environment('testing')
|
||||
|| (string) config('system_database.mode', 'bootstrap') === 'bootstrap') {
|
||||
return;
|
||||
}
|
||||
|
||||
$schema = Schema::connection($this->connection());
|
||||
if (! $schema->hasTable('ding_process_detail_mirror')
|
||||
|| $schema->hasColumn('ding_process_detail_mirror', 'store_name')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$schema->table('ding_process_detail_mirror', function (Blueprint $table): void {
|
||||
$table->string('store_name', 500)->nullable()->after('account_name');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
if (app()->environment('testing')
|
||||
|| (string) config('system_database.mode', 'bootstrap') === 'bootstrap') {
|
||||
return;
|
||||
}
|
||||
|
||||
$schema = Schema::connection($this->connection());
|
||||
if ($schema->hasTable('ding_process_detail_mirror')
|
||||
&& $schema->hasColumn('ding_process_detail_mirror', 'store_name')) {
|
||||
$schema->table('ding_process_detail_mirror', function (Blueprint $table): void {
|
||||
$table->dropColumn('store_name');
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -33,7 +33,7 @@
|
||||
| 已接入待首次同步 | 店铺营销账户余额的京东账户读取 `js_data_middle_platform.dbo.jd_jzt_finance_records` 镜像 `jsm_jd_jzt_finance_records`;按 `id` 稳定断点、`updated_at` 重叠增量,页面不直连上游。 |
|
||||
| 本次接入 | 普通商品资料的工作平台采购价格接入 `jiansun.dbo.pm_priceAdjustment`(镜像 `js_pm_price_adjustment`):按 `skuCode` 关联 `jst_sku.sku_id`,取 `effectTime` 不晚于当前时间的最新 `purchasePrice`,并在页面和导出中标记“工作平台价格”;源表没有可靠更新时间,按 `Id` 稳定键追加,首次全量完成前只显示普通商品自身采购价。 |
|
||||
| 待有效凭据后首次同步 | 普通商品当前成本价、商品类型和更新时间继续读取 `operations_replica.rpt.jst_sku`;`rpt.fys_skuCostPriceUpdate` 是一 SKU 一行的旧快照,不能充当变价历史。完整成本价变更仍读取聚水潭经典开放平台“商品操作日志查询”接口 `worklog.query`,只镜像操作内容含“采购价”的记录到 `jushuitan_cost_price_history_rows`;经典接口必须在服务器私有配置中使用同一应用的 `JUSHUITAN_PARTNER_ID / JUSHUITAN_PARTNER_KEY / JUSHUITAN_TOKEN`,不得把新开放平台的 App Key / App Secret / Access Token 混用。页面在首次同步完成前明确显示待同步或失败,不把 0 条解释为真实无历史。 |
|
||||
| 本次接入 | 流程明细读取 `operations_replica/rpt.ding_Workflow + rpt.ding_WorkflowScheme` 的结构化审批主表、费用明细和付款明细,写入 `ding_process_detail_mirror`、`ding_process_payment_mirror` 与付款按明细行分摊的 `ding_process_payment_line_mirror`;主表的 `originatorDeptName` 作为发起人部门单独保留。禁止先把明细表和付款表铺平成 CSV 后逐行求和;付款明细必须按“对应序号”关联到代表明细行,但合计始终读取独立付款事实。管理费用按分摊后的付款月份统计,跨月分笔付款不会把整张审批重复计入多月。每个纳入范围的源审批至少保留一条页面记录,没有费用金额的审批以空金额显示,不静默隐藏。首次全量先运行 `business-mirror:sync-ding-process-details --full --dry-run` 校验,再使用 `business-mirror:sync-ding-process-details --full` 发布;日常通过 `updateAt/createAt` 48 小时重叠增量同步。当前纳入日常报销、应付、线上代发、种菜、快递面单、固定资产、日常物品、样品、一次性采买、板材、工资、外贸费用和种菜充值等 14 个财务流程;发现新的明细流程编码时全量同步报错并保留上一版。 |
|
||||
| 本次接入 | 流程明细读取 `operations_replica/rpt.ding_Workflow + rpt.ding_WorkflowScheme` 的结构化审批主表、费用明细和付款明细,写入 `ding_process_detail_mirror`、`ding_process_payment_mirror` 与付款按明细行分摊的 `ding_process_payment_line_mirror`;主表的 `originatorDeptName` 作为发起人部门单独保留,费用明细行的“店铺”字段规范化写入 `store_name`。禁止先把明细表和付款表铺平成 CSV 后逐行求和;付款明细必须按“对应序号”关联到代表明细行,但合计始终读取独立付款事实。管理费用按分摊后的付款月份统计,跨月分笔付款不会把整张审批重复计入多月。每个纳入范围的源审批至少保留一条页面记录,没有费用金额的审批以空金额显示,不静默隐藏。首次全量先运行 `business-mirror:sync-ding-process-details --full --dry-run` 校验,再使用 `business-mirror:sync-ding-process-details --full` 发布;日常通过 `updateAt/createAt` 48 小时重叠增量同步。当前纳入日常报销、应付、线上代发、种菜、快递面单、固定资产、日常物品、样品、一次性采买、板材、工资、外贸费用和种菜充值等 14 个财务流程;发现新的明细流程编码时全量同步报错并保留上一版。 |
|
||||
| 本次接入 | 财务经营报表 › 管理费用使用 `oa_process_account_mapping` 保存流程科目映射;当前快照包含原工作簿 191 个科目和补充的 `5601.11.01 货代费`、`1221.07 种菜备用金`、`5602.11.03.19 AI阿里云软件费`,共 194 个科目,其中 37 个进费比科目和 126 个分摊规则。页面按打款时间提供整月选择并默认展示上个月 OA 流程中审批状态为“已完成”、涉及付款且出纳已打款的明细,不涉及付款或出纳未打款的数据不进入汇总,按费用大类和二级汇总进费比/不进费比/未映射金额,点击二级查看三级汇总与 9 列明细模板。审批完成时间写入 `ding_process_detail_mirror.approval_finished_at`,页面月份筛选使用 `ding_process_detail_mirror.paid_at`;钉钉副本把费用明细表保存为未命名字段时,按配置中的金额列识别包含该列的未命名表格组件,避免只抓到付款明细而漏掉费用科目和金额。明细行没有科目时,使用同一审批表单表头的 `科目编码 / 科目名称` 回填;行级科目始终优先。 |
|
||||
|
||||
流程明细另设独立定时任务,避免与每分钟科目映射消费争用同一上游目录时被静默跳过。正式发布脚本会覆盖安装 `/etc/cron.d/caiwu-ding-process-details`:每 5 分钟尝试运行 `business-mirror:sync-ding-process-details`,页面定向刷新和一周一次的全量校准与增量同步共用 `/run/caiwu-oa-process.lock`,只在这些 OA 镜像任务之间排队,不再被店铺对账、商品同步等无关任务占用的全局上游锁阻塞;`scripts/install-ding-process-sync-cron.ps1` 仅作为手工修复入口。任务时间和镜像状态统一使用平台固定时区,审批等待时长按实际小时展示。OA 页面每小时最多把一次当前页“审批中”的审批编号写入定向刷新队列,由每分钟检查一次的批处理命令消费;其他时间直接展示最近镜像,已完成流程不进入即时刷新链路,仍由常规增量和每周全量校准处理付款等后续变化。进行中审批的钉钉接口按配置并发读取(默认 5 个、上限 10 个),单个审批失败不会丢弃同批成功结果。增量同步除跟进审批主表更新时间外,还以 `ding_WorkflowScheme` 的数字 `id` 高水位发现后补表单行,避免付款明细等新组件写入后主审批 `updateAt` 不变而被漏掉;原地改写同一组件仍由每周全量校准兜底。付款状态只按钉钉“出纳打款”节点判断,分为“出纳状态待同步 / 出纳未开始 / 出纳待打款 / 出纳退回 / 出纳已打款 / 流程终止 / 不涉及付款”。金额差异不参与付款状态判断,另以“付款差额 = 费用合计 − 已付款合计”展示。不能因为金额存在少量差异就覆盖出纳节点事实,也不能因为出纳已通过就隐藏金额差异。
|
||||
|
||||
@ -27,4 +27,22 @@ class ManagementExpenses extends Controller
|
||||
->header('Cache-Control', 'no-store');
|
||||
}
|
||||
}
|
||||
|
||||
public function storeSummary(Request $request, ManagementExpensesPageData $pageData): JsonResponse
|
||||
{
|
||||
try {
|
||||
return response()
|
||||
->json(['success' => true, ...$pageData->storeSummary($request)])
|
||||
->header('Cache-Control', 'no-store');
|
||||
} catch (Throwable $exception) {
|
||||
report($exception);
|
||||
|
||||
return response()
|
||||
->json([
|
||||
'success' => false,
|
||||
'message' => '店铺汇总暂时无法读取,请稍后重试。',
|
||||
], 503)
|
||||
->header('Cache-Control', 'no-store');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1111,6 +1111,7 @@ class DingProcessDetailMirrorSynchronizer
|
||||
$title,
|
||||
'',
|
||||
'',
|
||||
$this->storeName([], $fields),
|
||||
$originator,
|
||||
$documentType,
|
||||
$status,
|
||||
@ -1291,6 +1292,7 @@ class DingProcessDetailMirrorSynchronizer
|
||||
}
|
||||
$accountCode = trim((string) ($row['科目编码'] ?? ''));
|
||||
$accountName = trim((string) ($row['科目名称'] ?? ''));
|
||||
$storeName = $this->storeName($row, $fields);
|
||||
if ($accountCode === '') {
|
||||
$accountCode = trim((string) $this->scalarValue($fields['科目编码'] ?? null));
|
||||
}
|
||||
@ -1313,6 +1315,7 @@ class DingProcessDetailMirrorSynchronizer
|
||||
$this->purpose($row) ?: (string) ($workflow['title'] ?? ''),
|
||||
$accountCode,
|
||||
$accountName,
|
||||
$storeName,
|
||||
$originator,
|
||||
$documentType,
|
||||
$status,
|
||||
@ -1354,7 +1357,7 @@ class DingProcessDetailMirrorSynchronizer
|
||||
if ($officialRow === null) {
|
||||
continue;
|
||||
}
|
||||
foreach (['科目编码', '科目名称'] as $field) {
|
||||
foreach (['科目编码', '科目名称', '店铺', '店铺名称'] as $field) {
|
||||
if (trim((string) ($row[$field] ?? '')) === ''
|
||||
&& trim((string) ($officialRow[$field] ?? '')) !== '') {
|
||||
$row[$field] = (string) $officialRow[$field];
|
||||
@ -2066,6 +2069,7 @@ class DingProcessDetailMirrorSynchronizer
|
||||
string $purpose,
|
||||
string $accountCode,
|
||||
string $accountName,
|
||||
string $storeName,
|
||||
string $originator,
|
||||
string $documentType,
|
||||
string $status,
|
||||
@ -2108,6 +2112,7 @@ class DingProcessDetailMirrorSynchronizer
|
||||
'purpose' => $purpose,
|
||||
'account_code' => mb_substr($accountCode, 0, 64),
|
||||
'account_name' => mb_substr($accountName, 0, 255),
|
||||
'store_name' => mb_substr($storeName, 0, 500),
|
||||
'amount' => $amountCents === null ? null : $this->moneyString($amountCents),
|
||||
'amount_cents' => $amountCents ?? 0,
|
||||
'bank_account_code' => null,
|
||||
@ -2276,6 +2281,62 @@ class DingProcessDetailMirrorSynchronizer
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Store names are commonly nested JSON arrays in DingTalk table cells.
|
||||
*
|
||||
* @param array<string,string> $row
|
||||
* @param array<string,mixed> $fields
|
||||
*/
|
||||
private function storeName(array $row, array $fields): string
|
||||
{
|
||||
foreach (['店铺', '店铺名称', '店铺名', 'store_name'] as $field) {
|
||||
$value = $row[$field] ?? null;
|
||||
if ($value === null || trim((string) $value) === '') {
|
||||
$value = $fields[$field] ?? null;
|
||||
}
|
||||
$normalized = $this->normalizeStoreValue($value);
|
||||
if ($normalized !== '') {
|
||||
return mb_substr($normalized, 0, 500);
|
||||
}
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
private function normalizeStoreValue(mixed $value): string
|
||||
{
|
||||
if (is_string($value) && preg_match('/^\s*[\[{]/', $value) === 1) {
|
||||
$decoded = json_decode($value, true);
|
||||
if (json_last_error() === JSON_ERROR_NONE) {
|
||||
$value = $decoded;
|
||||
}
|
||||
}
|
||||
|
||||
$names = [];
|
||||
$collect = function (mixed $candidate) use (&$collect, &$names): void {
|
||||
if (is_array($candidate)) {
|
||||
if (array_key_exists('value', $candidate)
|
||||
&& ! is_array($candidate['value'])
|
||||
&& trim((string) $candidate['value']) !== '') {
|
||||
$names[] = trim((string) $candidate['value']);
|
||||
|
||||
return;
|
||||
}
|
||||
foreach ($candidate as $item) {
|
||||
$collect($item);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
if (is_scalar($candidate) && trim((string) $candidate) !== '') {
|
||||
$names[] = trim((string) $candidate);
|
||||
}
|
||||
};
|
||||
$collect($value);
|
||||
|
||||
return implode('、', array_values(array_unique($names)));
|
||||
}
|
||||
|
||||
/** @param array<string,mixed> $process */
|
||||
private function documentType(array $process, string $title): string
|
||||
{
|
||||
|
||||
@ -24,6 +24,7 @@ class ManagementExpensesPageData
|
||||
public const DETAIL_COLUMNS = [
|
||||
'business_id' => '审批编号',
|
||||
'originator_department' => '部门',
|
||||
'store_name' => '店铺',
|
||||
'purpose' => '用途',
|
||||
'expense_category' => '分类',
|
||||
'second_level' => '二级',
|
||||
@ -84,6 +85,10 @@ class ManagementExpensesPageData
|
||||
'business.financial-operations.management-expenses.details',
|
||||
['company_id' => company_id() ?: 1],
|
||||
),
|
||||
'storeSummaryUrl' => route(
|
||||
'business.financial-operations.management-expenses.store-summary',
|
||||
['company_id' => company_id() ?: 1],
|
||||
),
|
||||
'error' => null,
|
||||
];
|
||||
} catch (Throwable $exception) {
|
||||
@ -108,6 +113,10 @@ class ManagementExpensesPageData
|
||||
'business.financial-operations.management-expenses.details',
|
||||
['company_id' => company_id() ?: 1],
|
||||
),
|
||||
'storeSummaryUrl' => route(
|
||||
'business.financial-operations.management-expenses.store-summary',
|
||||
['company_id' => company_id() ?: 1],
|
||||
),
|
||||
'error' => '管理费用数据暂时无法读取,请稍后重试。',
|
||||
];
|
||||
}
|
||||
@ -123,6 +132,32 @@ class ManagementExpensesPageData
|
||||
return $this->detailResult($filters, $page, $perPage);
|
||||
}
|
||||
|
||||
/** @return array{rows:list<array<string,int|float|string>>,total:float} */
|
||||
public function storeSummary(Request $request): array
|
||||
{
|
||||
$filters = $this->filters($request);
|
||||
$storeExpression = "COALESCE(NULLIF(d.store_name, ''), '未填写店铺')";
|
||||
$rows = $this->baseQuery($filters)
|
||||
->selectRaw("{$storeExpression} AS store_name")
|
||||
->selectRaw($this->amountSplitExpression())
|
||||
->groupByRaw($storeExpression)
|
||||
->orderByRaw('SUM(COALESCE(paid_line.paid_amount, 0)) DESC')
|
||||
->orderBy('store_name')
|
||||
->get()
|
||||
->map(static fn (object $row): array => [
|
||||
'store_name' => (string) $row->store_name,
|
||||
'amount' => round((float) $row->amount_total, 2),
|
||||
'row_count' => (int) $row->row_count,
|
||||
'approval_count' => (int) $row->approval_count,
|
||||
])
|
||||
->all();
|
||||
|
||||
return [
|
||||
'rows' => $rows,
|
||||
'total' => round(array_sum(array_column($rows, 'amount')), 2),
|
||||
];
|
||||
}
|
||||
|
||||
/** @return array<string,string> */
|
||||
public static function filters(Request $request): array
|
||||
{
|
||||
@ -220,6 +255,7 @@ class ManagementExpensesPageData
|
||||
->select([
|
||||
'd.business_id',
|
||||
'd.originator_department',
|
||||
'd.store_name',
|
||||
'd.purpose',
|
||||
'd.line_no',
|
||||
'd.process_instance_id',
|
||||
@ -238,6 +274,7 @@ class ManagementExpensesPageData
|
||||
->map(static fn (object $row): array => [
|
||||
'business_id' => (string) $row->business_id,
|
||||
'originator_department' => (string) ($row->originator_department ?? ''),
|
||||
'store_name' => (string) ($row->store_name ?? ''),
|
||||
'purpose' => (string) ($row->purpose ?? ''),
|
||||
'expense_category' => (string) $row->expense_category,
|
||||
'second_level' => (string) $row->second_level,
|
||||
|
||||
@ -8,6 +8,10 @@
|
||||
$options ??= [];
|
||||
$perPageOptions ??= \Modules\EcommerceFinance\View\ManagementExpensesPageData::PER_PAGE_OPTIONS;
|
||||
$detailColumns ??= \Modules\EcommerceFinance\View\ManagementExpensesPageData::DETAIL_COLUMNS;
|
||||
$storeSummaryUrl ??= route(
|
||||
'business.financial-operations.management-expenses.store-summary',
|
||||
['company_id' => company_id() ?: 1],
|
||||
);
|
||||
@endphp
|
||||
|
||||
<style>
|
||||
@ -462,6 +466,10 @@
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.me-store-dialog {
|
||||
width: min(52rem, calc(100vw - 2rem));
|
||||
}
|
||||
|
||||
@media (max-width: 1000px) {
|
||||
.me-filter {
|
||||
grid-template-columns: repeat(6, minmax(0, 1fr));
|
||||
@ -570,7 +578,16 @@
|
||||
<td class="num">{{ $wan($summaryRow['in_fee_ratio_amount']) }}</td>
|
||||
<td class="num">{{ $wan($summaryRow['non_fee_ratio_amount']) }}</td>
|
||||
<td class="num">{{ $wan($summaryRow['unmapped_amount']) }}</td>
|
||||
<td class="num">{{ $wan($summaryRow['amount_total']) }}</td>
|
||||
<td class="num">
|
||||
<button
|
||||
type="button"
|
||||
class="me-open-group"
|
||||
data-me-open-stores
|
||||
data-category="{{ $summaryRow['expense_category'] }}"
|
||||
data-second-level="{{ $summaryRow['second_level'] }}"
|
||||
title="查看二级店铺金额"
|
||||
>{{ $wan($summaryRow['amount_total']) }}</button>
|
||||
</td>
|
||||
<td>
|
||||
<button
|
||||
type="button"
|
||||
@ -692,6 +709,7 @@
|
||||
<tr>
|
||||
<td>{{ $row['business_id'] }}</td>
|
||||
<td>{{ $row['originator_department'] ?: '-' }}</td>
|
||||
<td>{{ $row['store_name'] ?: '-' }}</td>
|
||||
<td>{{ $row['purpose'] ?: '-' }}</td>
|
||||
<td>{{ $row['expense_category'] }}</td>
|
||||
<td>{{ $row['second_level'] }}</td>
|
||||
@ -705,7 +723,7 @@
|
||||
<td>{{ $row['allocation'] }}</td>
|
||||
</tr>
|
||||
@empty
|
||||
<tr><td colspan="9" class="me-empty">当前筛选条件没有符合汇总口径的 OA 流程明细。</td></tr>
|
||||
<tr><td colspan="{{ count($detailColumns) }}" class="me-empty">当前筛选条件没有符合汇总口径的 OA 流程明细。</td></tr>
|
||||
@endforelse
|
||||
</tbody>
|
||||
</table>
|
||||
@ -796,6 +814,32 @@
|
||||
</div>
|
||||
</dialog>
|
||||
|
||||
<dialog class="me-dialog me-store-dialog" id="management-expenses-store-dialog" aria-labelledby="management-expenses-store-title">
|
||||
<div class="me-dialog__head">
|
||||
<div class="me-dialog__title">
|
||||
<strong id="management-expenses-store-title">店铺金额</strong>
|
||||
<span id="management-expenses-store-subtitle">按店铺汇总当前已打款明细</span>
|
||||
</div>
|
||||
<button type="button" class="me-dialog__close" id="management-expenses-store-close" aria-label="关闭店铺汇总">×</button>
|
||||
</div>
|
||||
<div class="me-dialog__body">
|
||||
<div class="me-dialog__status" id="management-expenses-store-status"></div>
|
||||
<div style="overflow:auto;">
|
||||
<table class="me-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>店铺</th>
|
||||
<th class="num">已打款金额(元)</th>
|
||||
<th class="num">审批数</th>
|
||||
<th class="num">明细行</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="management-expenses-store-rows"></tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</dialog>
|
||||
|
||||
<script>
|
||||
(() => {
|
||||
const filterForm = document.getElementById('management-expenses-filter');
|
||||
@ -810,6 +854,7 @@
|
||||
const thirdLevelData = @json($thirdLevelSummary, JSON_UNESCAPED_UNICODE);
|
||||
const detailColumns = @json(array_values($detailColumns), JSON_UNESCAPED_UNICODE);
|
||||
const detailsUrl = @json($detailsUrl, JSON_UNESCAPED_SLASHES);
|
||||
const storeSummaryUrl = @json($storeSummaryUrl, JSON_UNESCAPED_SLASHES);
|
||||
const title = document.getElementById('management-expenses-dialog-title');
|
||||
const subtitle = document.getElementById('management-expenses-dialog-subtitle');
|
||||
const total = document.getElementById('management-expenses-dialog-total');
|
||||
@ -819,6 +864,11 @@
|
||||
const detailPage = document.getElementById('management-expenses-detail-page');
|
||||
const prevButton = document.getElementById('management-expenses-detail-prev');
|
||||
const nextButton = document.getElementById('management-expenses-detail-next');
|
||||
const storeDialog = document.getElementById('management-expenses-store-dialog');
|
||||
const storeTitle = document.getElementById('management-expenses-store-title');
|
||||
const storeSubtitle = document.getElementById('management-expenses-store-subtitle');
|
||||
const storeStatus = document.getElementById('management-expenses-store-status');
|
||||
const storeRows = document.getElementById('management-expenses-store-rows');
|
||||
let activeGroup = null;
|
||||
let activeThird = '';
|
||||
let activePage = 1;
|
||||
@ -826,6 +876,7 @@
|
||||
let detailsLoadedKey = '';
|
||||
let detailsController = null;
|
||||
let detailsRequestVersion = 0;
|
||||
let storeController = null;
|
||||
|
||||
const money = (value) => Number(value || 0).toLocaleString('zh-CN', {
|
||||
minimumFractionDigits: 2,
|
||||
@ -850,6 +901,77 @@
|
||||
? `${activeGroup.category}\u0000${activeGroup.secondLevel}\u0000${activeThird}`
|
||||
: '';
|
||||
|
||||
const openStoreSummary = async (category, secondLevel, thirdLevel = '') => {
|
||||
if (!storeDialog) return;
|
||||
storeController?.abort();
|
||||
const controller = new AbortController();
|
||||
storeController = controller;
|
||||
storeTitle.textContent = thirdLevel
|
||||
? `${category} / ${secondLevel} / ${thirdLevel}`
|
||||
: `${category} / ${secondLevel}`;
|
||||
storeSubtitle.textContent = thirdLevel
|
||||
? '按店铺查看该三级科目的已打款金额'
|
||||
: '按店铺查看该二级科目的已打款金额';
|
||||
storeStatus.textContent = '正在读取店铺汇总…';
|
||||
storeRows.replaceChildren();
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
params.delete('page');
|
||||
params.delete('per_page');
|
||||
params.set('expense_category', category);
|
||||
params.set('second_level', secondLevel);
|
||||
if (thirdLevel) {
|
||||
params.set('third_level', thirdLevel);
|
||||
} else {
|
||||
params.delete('third_level');
|
||||
}
|
||||
try {
|
||||
const response = await fetch(storeSummaryUrl + '?' + params.toString(), {
|
||||
headers: { Accept: 'application/json' },
|
||||
credentials: 'same-origin',
|
||||
cache: 'no-store',
|
||||
signal: controller.signal,
|
||||
});
|
||||
if (!response.ok) throw new Error('store summary unavailable');
|
||||
const payload = await response.json();
|
||||
const rows = payload.rows || [];
|
||||
if (!rows.length) {
|
||||
const tr = document.createElement('tr');
|
||||
const td = document.createElement('td');
|
||||
td.colSpan = 4;
|
||||
td.className = 'me-empty';
|
||||
td.textContent = '当前条件没有店铺金额。';
|
||||
tr.appendChild(td);
|
||||
storeRows.appendChild(tr);
|
||||
} else {
|
||||
rows.forEach((row) => {
|
||||
const tr = document.createElement('tr');
|
||||
[
|
||||
row.store_name || '未填写店铺',
|
||||
money(row.amount),
|
||||
Number(row.approval_count || 0).toLocaleString('zh-CN'),
|
||||
Number(row.row_count || 0).toLocaleString('zh-CN'),
|
||||
].forEach((value, index) => {
|
||||
const td = document.createElement('td');
|
||||
if (index > 0) td.className = 'num';
|
||||
td.textContent = value;
|
||||
tr.appendChild(td);
|
||||
});
|
||||
storeRows.appendChild(tr);
|
||||
});
|
||||
}
|
||||
storeStatus.textContent = `店铺合计 ${money(payload.total || 0)} 元`;
|
||||
if (!storeDialog.open) {
|
||||
if (typeof storeDialog.showModal === 'function') storeDialog.showModal();
|
||||
else storeDialog.setAttribute('open', 'open');
|
||||
}
|
||||
} catch (error) {
|
||||
if (error.name === 'AbortError') return;
|
||||
storeStatus.textContent = '店铺汇总读取失败,请稍后重试。';
|
||||
} finally {
|
||||
if (storeController === controller) storeController = null;
|
||||
}
|
||||
};
|
||||
|
||||
const renderThirdLevels = () => {
|
||||
thirdRows.replaceChildren();
|
||||
if (!activeGroup) return;
|
||||
@ -877,8 +999,24 @@
|
||||
moneyWan(row.amount_total),
|
||||
].forEach((value, index) => {
|
||||
const td = document.createElement('td');
|
||||
td.textContent = value;
|
||||
if (index >= 1 && index <= 4) td.className = 'num';
|
||||
if (index === 4) {
|
||||
const button = document.createElement('button');
|
||||
button.type = 'button';
|
||||
button.className = 'me-open-group';
|
||||
button.title = '查看该三级科目的店铺金额';
|
||||
button.textContent = value;
|
||||
button.addEventListener('click', () => {
|
||||
openStoreSummary(
|
||||
row.expense_category,
|
||||
row.second_level,
|
||||
row.third_level,
|
||||
);
|
||||
});
|
||||
td.appendChild(button);
|
||||
} else {
|
||||
td.textContent = value;
|
||||
}
|
||||
tr.appendChild(td);
|
||||
});
|
||||
const action = document.createElement('td');
|
||||
@ -915,6 +1053,7 @@
|
||||
const values = [
|
||||
row.business_id,
|
||||
row.originator_department || '-',
|
||||
row.store_name || '-',
|
||||
row.purpose || '-',
|
||||
row.expense_category,
|
||||
row.second_level,
|
||||
@ -926,7 +1065,7 @@
|
||||
const tr = document.createElement('tr');
|
||||
values.forEach((value, index) => {
|
||||
const td = document.createElement('td');
|
||||
if (index === 6) td.className = 'num';
|
||||
if (index === 7) td.className = 'num';
|
||||
td.textContent = value;
|
||||
tr.appendChild(td);
|
||||
});
|
||||
@ -1021,6 +1160,13 @@
|
||||
|
||||
const secondLevelRows = @json($secondLevelSummary, JSON_UNESCAPED_UNICODE);
|
||||
|
||||
document.querySelectorAll('[data-me-open-stores]').forEach((button) => {
|
||||
button.addEventListener('click', () => openStoreSummary(
|
||||
button.dataset.category,
|
||||
button.dataset.secondLevel,
|
||||
));
|
||||
});
|
||||
|
||||
dialog.querySelectorAll('[data-me-tab]').forEach((tab) => {
|
||||
tab.addEventListener('click', () => {
|
||||
setTab(tab.dataset.meTab);
|
||||
@ -1031,6 +1177,7 @@
|
||||
});
|
||||
});
|
||||
document.getElementById('management-expenses-dialog-close')?.addEventListener('click', () => dialog.close());
|
||||
document.getElementById('management-expenses-store-close')?.addEventListener('click', () => storeDialog?.close());
|
||||
prevButton?.addEventListener('click', () => {
|
||||
if (activePage > 1) {
|
||||
activePage--;
|
||||
|
||||
@ -646,6 +646,13 @@ Route::get(
|
||||
->middleware('business.page:financial-operations,management-expenses')
|
||||
->name('business.financial-operations.management-expenses.details');
|
||||
|
||||
Route::get(
|
||||
'workspace/financial-operations/management-expenses/store-summary',
|
||||
[ManagementExpenses::class, 'storeSummary'],
|
||||
)
|
||||
->middleware('business.page:financial-operations,management-expenses')
|
||||
->name('business.financial-operations.management-expenses.store-summary');
|
||||
|
||||
Route::get('workspace/financial-operations/billing-details/export', 'Business\Pages@exportBillingDetails')
|
||||
->middleware('business.page:financial-operations,billing-details')
|
||||
->name('business.financial-operations.billing-details.export');
|
||||
|
||||
@ -21,6 +21,7 @@ class ManagementExpensesPageTest extends FeatureTestCase
|
||||
[
|
||||
'business_id' => '202610301323000477793',
|
||||
'originator_department' => '财务中心',
|
||||
'store_name' => '天猫-测试店',
|
||||
'purpose' => '测试用途',
|
||||
'expense_category' => '管理费用',
|
||||
'second_level' => '办公费',
|
||||
@ -65,6 +66,10 @@ class ManagementExpensesPageTest extends FeatureTestCase
|
||||
'business.financial-operations.management-expenses.details',
|
||||
['company_id' => company_id() ?: 1],
|
||||
),
|
||||
'storeSummaryUrl' => route(
|
||||
'business.financial-operations.management-expenses.store-summary',
|
||||
['company_id' => company_id() ?: 1],
|
||||
),
|
||||
'error' => null,
|
||||
]);
|
||||
$this->app->instance(ManagementExpensesPageData::class, $service);
|
||||
@ -91,14 +96,16 @@ class ManagementExpensesPageTest extends FeatureTestCase
|
||||
->assertSee('不进费比')
|
||||
->assertSee('是否分摊')
|
||||
->assertSee('办公费用品')
|
||||
->assertSee('天猫-测试店')
|
||||
->assertSee('202610301323000477793')
|
||||
->assertSee('data-me-open-group', false)
|
||||
->assertSee('data-me-open-stores', false)
|
||||
->assertSee('management-expenses-store-dialog', false)
|
||||
->assertSee('detailsLoadedKey', false)
|
||||
->assertSee('dialogBody.scrollTop = 0', false)
|
||||
->assertDontSee('OA 已付款明细模板')
|
||||
->assertDontSee('审批单 / 明细行')
|
||||
->assertDontSee('<th class="num">审批单</th>', false)
|
||||
->assertDontSee('<th class="num">明细行</th>', false);
|
||||
->assertDontSee('<th class="num">审批单</th>', false);
|
||||
}
|
||||
|
||||
public function test_details_endpoint_returns_template_rows(): void
|
||||
@ -109,6 +116,7 @@ class ManagementExpensesPageTest extends FeatureTestCase
|
||||
'rows' => [[
|
||||
'business_id' => '202610301323000477793',
|
||||
'originator_department' => '财务中心',
|
||||
'store_name' => '天猫-测试店',
|
||||
'purpose' => '测试用途',
|
||||
'expense_category' => '管理费用',
|
||||
'second_level' => '办公费',
|
||||
@ -130,7 +138,30 @@ class ManagementExpensesPageTest extends FeatureTestCase
|
||||
->assertOk()
|
||||
->assertJsonPath('success', true)
|
||||
->assertJsonPath('rows.0.business_id', '202610301323000477793')
|
||||
->assertJsonPath('rows.0.store_name', '天猫-测试店')
|
||||
->assertJsonPath('rows.0.fee_ratio', '不进费比')
|
||||
->assertJsonPath('pagination.total', 1);
|
||||
}
|
||||
|
||||
public function test_store_summary_endpoint_returns_store_amounts(): void
|
||||
{
|
||||
$this->user->attachPermission(Permission::where('name', 'read-admin-panel')->firstOrFail());
|
||||
$service = Mockery::mock(ManagementExpensesPageData::class);
|
||||
$service->shouldReceive('storeSummary')->once()->andReturn([
|
||||
'rows' => [[
|
||||
'store_name' => '天猫-测试店',
|
||||
'amount' => 100.0,
|
||||
'row_count' => 1,
|
||||
'approval_count' => 1,
|
||||
]],
|
||||
'total' => 100.0,
|
||||
]);
|
||||
$this->app->instance(ManagementExpensesPageData::class, $service);
|
||||
|
||||
$this->loginAs()->getJson(route('business.financial-operations.management-expenses.store-summary'))
|
||||
->assertOk()
|
||||
->assertJsonPath('success', true)
|
||||
->assertJsonPath('rows.0.store_name', '天猫-测试店')
|
||||
->assertJsonPath('total', 100);
|
||||
}
|
||||
}
|
||||
|
||||
@ -113,6 +113,8 @@ class DingProcessDetailMirrorSynchronizerTest extends TestCase
|
||||
->table('ding_process_detail_mirror')->value('originator_department'));
|
||||
$this->assertSame('2026-05-08 09:00:00', DB::connection('business_mirror')
|
||||
->table('ding_process_detail_mirror')->value('approval_finished_at'));
|
||||
$this->assertSame('天猫-测试店铺', DB::connection('business_mirror')
|
||||
->table('ding_process_detail_mirror')->value('store_name'));
|
||||
|
||||
$summary = app(DingProcessDetailMirrorRepository::class)
|
||||
->paginate(['status' => '已完成'], 1, 50)['summary'];
|
||||
@ -1394,6 +1396,7 @@ class DingProcessDetailMirrorSynchronizerTest extends TestCase
|
||||
['label' => '代发订单金额', 'value' => (string) $amount],
|
||||
['label' => '科目编码', 'value' => '1405.06'],
|
||||
['label' => '科目名称', 'value' => '库存商品_线上代发'],
|
||||
['label' => '店铺', 'value' => '["天猫-测试店铺"]'],
|
||||
],
|
||||
], $amounts);
|
||||
$payment = [[
|
||||
@ -1480,6 +1483,7 @@ class DingProcessDetailMirrorSynchronizerTest extends TestCase
|
||||
$table->text('purpose')->nullable();
|
||||
$table->string('account_code', 64)->nullable();
|
||||
$table->string('account_name', 255)->nullable();
|
||||
$table->string('store_name', 500)->nullable();
|
||||
$table->decimal('amount', 18, 2)->nullable();
|
||||
$table->string('bank_account_code', 255)->nullable();
|
||||
$table->string('bank_account_name', 255)->nullable();
|
||||
|
||||
@ -99,7 +99,7 @@ class ManagementExpensesPageDataTest extends TestCase
|
||||
$this->assertSame(2, $data['pagination']['total']);
|
||||
$this->assertSame(120.0, $data['summary']['amount_total']);
|
||||
$this->assertSame(
|
||||
['审批编号', '部门', '用途', '分类', '二级', '三级', '金额', '是否进费比', '是否分摊'],
|
||||
['审批编号', '部门', '店铺', '用途', '分类', '二级', '三级', '金额', '是否进费比', '是否分摊'],
|
||||
array_values(ManagementExpensesPageData::DETAIL_COLUMNS),
|
||||
);
|
||||
$this->assertSame(
|
||||
@ -108,6 +108,29 @@ class ManagementExpensesPageDataTest extends TestCase
|
||||
);
|
||||
$this->assertSame('不进费比', $data['rows'][0]['fee_ratio']);
|
||||
$this->assertSame('分摊', $data['rows'][0]['allocation']);
|
||||
$this->assertSame('天猫-办公店', $data['rows'][0]['store_name']);
|
||||
}
|
||||
|
||||
public function test_store_summary_groups_current_paid_filter_by_store(): void
|
||||
{
|
||||
$data = $this->pageData->storeSummary(Request::create(
|
||||
'/1/workspace/financial-operations/management-expenses/store-summary',
|
||||
'GET',
|
||||
[
|
||||
'expense_category' => '管理费用',
|
||||
'second_level' => '办公费',
|
||||
'paid_month' => '2026-10',
|
||||
],
|
||||
));
|
||||
|
||||
$this->assertSame(120.0, $data['total']);
|
||||
$this->assertSame(
|
||||
[
|
||||
['store_name' => '天猫-办公店', 'amount' => 100.0, 'row_count' => 1, 'approval_count' => 1],
|
||||
['store_name' => '京东-办公店', 'amount' => 20.0, 'row_count' => 1, 'approval_count' => 1],
|
||||
],
|
||||
$data['rows'],
|
||||
);
|
||||
}
|
||||
|
||||
public function test_unmapped_account_is_visible_instead_of_being_silently_dropped(): void
|
||||
@ -297,6 +320,7 @@ class ManagementExpensesPageDataTest extends TestCase
|
||||
$table->unsignedInteger('line_no');
|
||||
$table->string('account_code', 64)->nullable();
|
||||
$table->string('account_name', 255)->nullable();
|
||||
$table->string('store_name', 500)->nullable();
|
||||
$table->string('originator_department', 255)->nullable();
|
||||
$table->string('originator_name', 100)->nullable();
|
||||
$table->string('status', 20)->nullable();
|
||||
@ -370,14 +394,14 @@ class ManagementExpensesPageDataTest extends TestCase
|
||||
],
|
||||
]);
|
||||
DB::connection('business_mirror')->table('ding_process_detail_mirror')->insert([
|
||||
$this->row('202610011200000000001', '5602.04', 1, 100, '已完成', 'completed', 'present', '2026-10-01 10:00:00', '2026-10-10'),
|
||||
$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('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'),
|
||||
]);
|
||||
DB::connection('business_mirror')->table('ding_process_payment_mirror')->insert([
|
||||
@ -409,6 +433,7 @@ class ManagementExpensesPageDataTest extends TestCase
|
||||
string $paymentSourceState,
|
||||
string $approvalFinishedAt,
|
||||
?string $paidAt,
|
||||
string $storeName = '测试店铺',
|
||||
): array {
|
||||
return [
|
||||
'business_id' => $businessId,
|
||||
@ -416,6 +441,7 @@ class ManagementExpensesPageDataTest extends TestCase
|
||||
'line_no' => $lineNo,
|
||||
'account_code' => $accountCode,
|
||||
'account_name' => '流程科目',
|
||||
'store_name' => $storeName,
|
||||
'originator_department' => '财务中心',
|
||||
'originator_name' => '测试申请人',
|
||||
'status' => $status,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user