fix: 合同付款预警优化
This commit is contained in:
1 parent
83e0bad22f
commit
fe5191b38a
15 files changed
+304
-97
No files matched your search
@@ -3,38 +3,60 @@
|
||||
* 用途:合同付款节点的到期/逾期判定,以及台账级“按节点聚合的付款状态”推导。
|
||||
* 依赖:contract-payment.api 的 PaymentNode 类型、浏览器 Date。
|
||||
* 逻辑:付款节点到期/逾期以节点 due_date 为准;台账状态按节点聚合,供列表页一行一眼看是否逾期。
|
||||
* 阶段格子的已逾期/即将到期/未到期也走这里,验收款和质保款与预付款、出货款共用同一比较。
|
||||
*/
|
||||
|
||||
import type { PaymentNode } from '../api/contract-payment.api';
|
||||
|
||||
/**
|
||||
* 把 YYYY-MM-DD 归一成 UTC 零点,供到期比较。
|
||||
* 核心逻辑:缺省取当前 UTC 日历日;测试传入 todayIso 时固定业务日,避免用例随真实日期漂移。
|
||||
* @param todayIso - 可选业务日。
|
||||
* @returns 可用于相减的日期;无法解析时返回 Invalid Date。
|
||||
*/
|
||||
function calendarDay(todayIso?: string): Date {
|
||||
const iso = todayIso || new Date().toISOString().slice(0, 10);
|
||||
return new Date(`${iso}T00:00:00Z`);
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算到期日相对业务日的天数。
|
||||
* 核心逻辑:两日都按 UTC 零点取值,负数表示已过期。
|
||||
* @param due - 到期日期(YYYY-MM-DD)。
|
||||
* @param todayIso - 可选业务日。
|
||||
* @returns 相差天数;日期无效时返回 null。
|
||||
*/
|
||||
function daysUntil(due: string, todayIso?: string): number | null {
|
||||
const target = new Date(`${due}T00:00:00Z`);
|
||||
const today = calendarDay(todayIso);
|
||||
if (Number.isNaN(target.getTime()) || Number.isNaN(today.getTime())) return null;
|
||||
return Math.round((target.getTime() - today.getTime()) / 86400000);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断某个日期是否临近到期(含今天起 7 天内)。
|
||||
* 核心逻辑:与 isNodeOverdue 共用 UTC 日期归一;范围内(0..7 天)判定为临近到期。
|
||||
* @param due - 到期日期(YYYY-MM-DD)。
|
||||
* @param todayIso - 可选业务日,缺省为当前 UTC 日历日。
|
||||
* @returns 是否临近到期。
|
||||
*/
|
||||
export function isNodeNearDue(due?: string | null): boolean {
|
||||
export function isNodeNearDue(due?: string | null, todayIso?: string): boolean {
|
||||
if (!due) return false;
|
||||
const target = new Date(`${due}T00:00:00Z`);
|
||||
if (Number.isNaN(target.getTime())) return false;
|
||||
const today = new Date(`${new Date().toISOString().slice(0, 10)}T00:00:00Z`);
|
||||
const days = Math.round((target.getTime() - today.getTime()) / 86400000);
|
||||
return days >= 0 && days <= 7;
|
||||
const days = daysUntil(due, todayIso);
|
||||
return days !== null && days >= 0 && days <= 7;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断某个日期是否已逾期(早于今天)。
|
||||
* 核心逻辑:与 isNodeNearDue 共用 UTC 日期归一;due_date 早于今天即判定为逾期。
|
||||
* @param due - 到期日期(YYYY-MM-DD)。
|
||||
* @param todayIso - 可选业务日,缺省为当前 UTC 日历日。
|
||||
* @returns 是否已逾期。
|
||||
*/
|
||||
export function isNodeOverdue(due?: string | null): boolean {
|
||||
export function isNodeOverdue(due?: string | null, todayIso?: string): boolean {
|
||||
if (!due) return false;
|
||||
const target = new Date(`${due}T00:00:00Z`);
|
||||
if (Number.isNaN(target.getTime())) return false;
|
||||
const today = new Date(`${new Date().toISOString().slice(0, 10)}T00:00:00Z`);
|
||||
const days = Math.round((target.getTime() - today.getTime()) / 86400000);
|
||||
return days < 0;
|
||||
const days = daysUntil(due, todayIso);
|
||||
return days !== null && days < 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -48,6 +70,43 @@ export function nodeDueReference(node: Pick<PaymentNode, 'due_date' | 'anchor_da
|
||||
return node.due_date || node.anchor_date || null;
|
||||
}
|
||||
|
||||
/** 台账阶段格子的状态:空格、已付、缺日期、已逾期、即将到期、未到期。 */
|
||||
export type LedgerStageCellKind = 'absent' | 'paid' | 'missing_date' | 'overdue' | 'due' | 'active';
|
||||
|
||||
/**
|
||||
* 判断台账里一个付款阶段格子该显示哪种状态。
|
||||
* 核心逻辑:无节点、不适用或金额比例都是 0 视为空格。只有预付款和出货款在已付时返回 paid。
|
||||
* 其余未付阶段没有日期依据则返回 missing_date;有日期则按业务日比较已逾期、7 日内即将到期或未到期。
|
||||
* 验收款、质保款与预付款、出货款共用这套日期比较,不因没有付款回写而省略已逾期。
|
||||
* @param node - 付款节点;该阶段不存在时传 null。
|
||||
* @param nodeType - 阶段类型,用来区分能否标已付。
|
||||
* @param todayIso - 可选业务日 YYYY-MM-DD。
|
||||
* @returns 格子状态种类。
|
||||
*/
|
||||
export function classifyLedgerStageCell(
|
||||
node: Pick<PaymentNode, 'status' | 'percentage' | 'amount' | 'due_date' | 'anchor_date'> | null | undefined,
|
||||
nodeType: string,
|
||||
todayIso?: string,
|
||||
): LedgerStageCellKind {
|
||||
if (!node) return 'absent';
|
||||
const status = String(node.status || '').trim().toLowerCase();
|
||||
const percentValue = Number(node.percentage);
|
||||
const amountValue = Number(node.amount);
|
||||
const absent = status === 'not_applicable' || (
|
||||
status !== 'paid'
|
||||
&& Number.isFinite(percentValue)
|
||||
&& percentValue === 0
|
||||
&& (node.amount == null || node.amount === '' || amountValue === 0)
|
||||
);
|
||||
if (absent) return 'absent';
|
||||
if ((nodeType === 'prepayment' || nodeType === 'shipment') && status === 'paid') return 'paid';
|
||||
const basis = nodeDueReference(node);
|
||||
if (!basis) return 'missing_date';
|
||||
if (isNodeOverdue(basis, todayIso)) return 'overdue';
|
||||
if (isNodeNearDue(basis, todayIso)) return 'due';
|
||||
return 'active';
|
||||
}
|
||||
|
||||
/** 台账级付款状态编码:未到期 / 即将到期 / 已逾期 / 已完成 / 待补充。 */
|
||||
export type ContractNodeStatusCode = 'active' | 'due' | 'overdue' | 'completed' | 'needs_completion';
|
||||
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
用途:合同付款预警台账列表、汇总卡与本周待发送摘要。
|
||||
依赖:contract-payment.api、PaginationBar、统一消息提示。
|
||||
逻辑:Chat Tab 以 embedded 嵌入时隐藏页头;点行通过 open-detail 交给父级下钻详情;关键词可搜合同号、流程号、采购单号、供应商和申请人。
|
||||
四阶段列只显示阶段名。预付款、出货款按 ERP 付款事实标已付或逾期/即将到期/未到期;验收款、质保款只展示金额比例和日期依据。
|
||||
四阶段列只显示阶段名。预付款、出货款按 ERP 付款事实标已付;未付时与验收款、质保款一样按日期依据标已逾期、即将到期或未到期。
|
||||
验收款、质保款没有付款回写,不标已付。没有日期依据时按阶段说明原因,例如验收单未归档、质保到期日未定。
|
||||
嵌入布局为上半汇总卡/搜索与底部分页固定,仅表格区域双向滚动;汇总卡采用紧凑尺寸以留出小屏列表高度。
|
||||
-->
|
||||
<script setup lang="ts">
|
||||
@@ -23,7 +24,7 @@ import {
|
||||
type LedgerSummary,
|
||||
} from '../api/contract-payment.api';
|
||||
import { displayCurrency } from '../utils/currency';
|
||||
import { aggregateContractNodeStatus, isNodeNearDue, isNodeOverdue, nodeDueReference, type ContractNodeStatusCode } from '../utils/paymentStatus';
|
||||
import { aggregateContractNodeStatus, classifyLedgerStageCell, nodeDueReference, type ContractNodeStatusCode } from '../utils/paymentStatus';
|
||||
|
||||
const props = withDefaults(defineProps<{
|
||||
embedded?: boolean;
|
||||
@@ -61,44 +62,41 @@ const displayPercentage = (percentage?: string | null): string => {
|
||||
const stageTypes = ['prepayment', 'shipment', 'acceptance', 'warranty'] as const;
|
||||
type StagePayTone = '' | 'paid' | 'overdue' | 'due' | 'normal';
|
||||
/**
|
||||
* 组装一个付款阶段格子:金额比例、日期,以及预付款/出货款的付款状态。
|
||||
* 核心逻辑:预付款、出货款有 ERP 付款事实。已付显示付款日;未付按日期依据标已逾期、即将到期或未到期,日期仍是依据日。
|
||||
* 验收款、质保款没有付款回写,不标已付或未付。没有日期依据时显示待补充日期。
|
||||
* 人工复核标成无此阶段,或比例和金额都是 0 的阶段,显示为横线,不参与这一格的状态。
|
||||
* 组装一个付款阶段格子:金额比例、日期,以及这一格的状态。
|
||||
* 核心逻辑:状态种类交给 classifyLedgerStageCell。预付款、出货款已付显示付款日。
|
||||
* 未付的四个阶段都按日期依据标已逾期、即将到期或未到期。验收款、质保款不标已付。
|
||||
* 没有日期依据时按阶段写明原因,悬停可看说明。无此阶段或金额比例都是 0 时显示横线。
|
||||
* @param item - 合同台账行。
|
||||
* @param name - 付款节点类型。
|
||||
* @returns 金额比例、日期文本、是否待补充,以及状态标签和色调。
|
||||
* @returns 金额比例、日期文本、悬停说明、是否缺日期,以及状态标签和色调。
|
||||
*/
|
||||
const paymentCell = (item: ContractPaymentContract, name: string) => {
|
||||
const node = stage(item, name);
|
||||
const empty = { amountRatio: '—', dateText: '', missingDate: false, payLabel: '', payTone: '' as StagePayTone };
|
||||
if (!node) return empty;
|
||||
const status = String(node.status || '').trim().toLowerCase();
|
||||
const percentValue = Number(node.percentage);
|
||||
const amountValue = Number(node.amount);
|
||||
const absent = status === 'not_applicable' || (
|
||||
status !== 'paid'
|
||||
&& Number.isFinite(percentValue)
|
||||
&& percentValue === 0
|
||||
&& (node.amount == null || node.amount === '' || amountValue === 0)
|
||||
);
|
||||
if (absent) return empty;
|
||||
const empty = { amountRatio: '—', dateText: '', dateTitle: '', missingDate: false, payLabel: '', payTone: '' as StagePayTone };
|
||||
const kind = classifyLedgerStageCell(node, name);
|
||||
if (!node || kind === 'absent') return empty;
|
||||
const amountRatio = node.amount || node.percentage ? `${node.amount || '—'} / ${displayPercentage(node.percentage)}%` : '—';
|
||||
const basis = nodeDueReference(node) || '';
|
||||
const payable = name === 'prepayment' || name === 'shipment';
|
||||
const paid = String(node.status || '').trim().toLowerCase() === 'paid';
|
||||
if (payable && paid) {
|
||||
return { amountRatio, dateText: node.paid_at || '—', missingDate: false, payLabel: t('admin.contractPayment.stagePaid'), payTone: 'paid' as StagePayTone };
|
||||
if (kind === 'paid') {
|
||||
return { amountRatio, dateText: node.paid_at || '—', dateTitle: '', missingDate: false, payLabel: t('admin.contractPayment.stagePaid'), payTone: 'paid' as StagePayTone };
|
||||
}
|
||||
if (!basis) return { amountRatio, dateText: '', missingDate: true, payLabel: '', payTone: '' as StagePayTone };
|
||||
if (!payable) return { amountRatio, dateText: basis, missingDate: false, payLabel: '', payTone: '' as StagePayTone };
|
||||
if (isNodeOverdue(basis)) {
|
||||
return { amountRatio, dateText: basis, missingDate: false, payLabel: t('admin.contractPayment.statusOverdue'), payTone: 'overdue' as StagePayTone };
|
||||
if (kind === 'missing_date') {
|
||||
return {
|
||||
amountRatio,
|
||||
dateText: t(`admin.contractPayment.dateMissing.${name}`),
|
||||
dateTitle: t(`admin.contractPayment.dateMissingHint.${name}`),
|
||||
missingDate: true,
|
||||
payLabel: '',
|
||||
payTone: '' as StagePayTone,
|
||||
};
|
||||
}
|
||||
if (isNodeNearDue(basis)) {
|
||||
return { amountRatio, dateText: basis, missingDate: false, payLabel: t('admin.contractPayment.statusUpcoming'), payTone: 'due' as StagePayTone };
|
||||
const dated = { amountRatio, dateText: nodeDueReference(node) || '', dateTitle: '', missingDate: false };
|
||||
if (kind === 'overdue') {
|
||||
return { ...dated, payLabel: t('admin.contractPayment.statusOverdue'), payTone: 'overdue' as StagePayTone };
|
||||
}
|
||||
return { amountRatio, dateText: basis, missingDate: false, payLabel: t('admin.contractPayment.statusActive'), payTone: 'normal' as StagePayTone };
|
||||
if (kind === 'due') {
|
||||
return { ...dated, payLabel: t('admin.contractPayment.statusUpcoming'), payTone: 'due' as StagePayTone };
|
||||
}
|
||||
return { ...dated, payLabel: t('admin.contractPayment.statusActive'), payTone: 'normal' as StagePayTone };
|
||||
};
|
||||
/**
|
||||
* 按付款节点聚合台账状态:未到期 / 即将到期 / 已逾期 / 已完成 / 待补充。
|
||||
@@ -267,7 +265,7 @@ onMounted(() => void load());
|
||||
<tr v-for="item in contracts" :key="item.id" class="contract-ledger-row" @click="openContractDetail(item.id)">
|
||||
<td class="contract-identify"><strong>{{ t('admin.contractPayment.contractPrefix') }}:{{ item.contract_no || t('admin.contractPayment.contractNoPending') }}</strong><span>{{ t('admin.contractPayment.purchaseOrder') }}:{{ item.purchase_order_no || '—' }}</span><span>{{ item.supplier_name || '—' }}</span></td>
|
||||
<td class="contract-money">{{ item.total_amount || '—' }}<span v-if="displayCurrency(item.currency)"> {{ displayCurrency(item.currency) }}</span></td>
|
||||
<td v-for="nodeType in stageTypes" :key="nodeType" class="contract-payment-cell"><template v-if="paymentCell(item, nodeType).amountRatio !== '—'"><strong>{{ paymentCell(item, nodeType).amountRatio }}</strong><span :class="{ 'contract-date-pending': paymentCell(item, nodeType).missingDate }">{{ paymentCell(item, nodeType).dateText || t('admin.contractPayment.datePending') }}</span><span v-if="paymentCell(item, nodeType).payLabel" class="stage-pay-tag" :class="paymentCell(item, nodeType).payTone">{{ paymentCell(item, nodeType).payLabel }}</span></template><span v-else>—</span></td>
|
||||
<td v-for="nodeType in stageTypes" :key="nodeType" class="contract-payment-cell"><template v-if="paymentCell(item, nodeType).amountRatio !== '—'"><strong>{{ paymentCell(item, nodeType).amountRatio }}</strong><span :class="{ 'contract-date-pending': paymentCell(item, nodeType).missingDate }" :title="paymentCell(item, nodeType).dateTitle || undefined">{{ paymentCell(item, nodeType).dateText }}</span><span v-if="paymentCell(item, nodeType).payLabel" class="stage-pay-tag" :class="paymentCell(item, nodeType).payTone">{{ paymentCell(item, nodeType).payLabel }}</span></template><span v-else>—</span></td>
|
||||
<td class="contract-applicant">{{ item.applicant_name || '—' }}</td>
|
||||
<td><span class="contract-status" :class="displayStatus(item).tone">{{ displayStatus(item).label }}</span></td>
|
||||
</tr>
|
||||
|
||||
Reference in new issue
Block a user