第3项:旧界面与 React 共用对账、回收及基础业务规则
This commit is contained in:
1 parent
54c05879d5
commit
389952f31c
65 files changed
+2265
-3800
No files matched your search
@@ -37,92 +37,8 @@ function dailyFundsMatches(entry = dailyFundsEntry) {
|
||||
function dailyFundsMoney(value) {
|
||||
return value == null ? '待确认' : '¥' + yuan(value);
|
||||
}
|
||||
function validateReimbursement(row) {
|
||||
if (
|
||||
!row ||
|
||||
typeof row.id !== 'string' ||
|
||||
!row.id ||
|
||||
!validOrderDate(row.date) ||
|
||||
!Object.hasOwn(reimbursementStatusNames, row.status) ||
|
||||
!Number.isSafeInteger(row.revision) ||
|
||||
row.revision < 1 ||
|
||||
typeof row.canEdit !== 'boolean' ||
|
||||
typeof row.canApprove !== 'boolean' ||
|
||||
!Array.isArray(row.items) ||
|
||||
!row.items.length ||
|
||||
row.items.length > 60 ||
|
||||
!row.items.every(
|
||||
item => typeof item.name === 'string' && item.name && Number.isSafeInteger(item.amount) && item.amount > 0,
|
||||
) ||
|
||||
!Number.isSafeInteger(row.total) ||
|
||||
row.items.reduce((sum, item) => sum + item.amount, 0) !== row.total
|
||||
)
|
||||
throw new Error('报销单未完整返回,请重新读取。');
|
||||
return row;
|
||||
}
|
||||
function validateDailyFunds(data, range) {
|
||||
if (data?.team) {
|
||||
if (data.date !== range.date || data.from !== range.from || !Array.isArray(data.reimbursements))
|
||||
throw new Error('团队日期或报销资料未完整返回,请重新读取。');
|
||||
validateTeamFunds(data.team);
|
||||
data.reimbursements.forEach(validateReimbursement);
|
||||
return data;
|
||||
}
|
||||
const money = value => Number.isSafeInteger(value),
|
||||
nullable = value => value === null || money(value);
|
||||
if (
|
||||
!data ||
|
||||
data.date !== range.date ||
|
||||
data.from !== range.from ||
|
||||
typeof data.readOnly !== 'boolean' ||
|
||||
typeof data.ready !== 'boolean' ||
|
||||
!['receipt', 'refund', 'net'].every(key => money(data.ownerReceipts?.[key])) ||
|
||||
data.ownerReceipts.net !== data.ownerReceipts.receipt - data.ownerReceipts.refund ||
|
||||
!money(data.approvedReimbursements) ||
|
||||
!nullable(data.actualOutlay) ||
|
||||
!nullable(data.transferAmount) ||
|
||||
data.transfersNotDeducted !== true ||
|
||||
!Array.isArray(data.reimbursements) ||
|
||||
!Array.isArray(data.days) ||
|
||||
!Array.isArray(data.missingDates) ||
|
||||
!Array.isArray(data.staleDates) ||
|
||||
!Number.isSafeInteger(data.pendingCount) ||
|
||||
data.pendingCount < 0 ||
|
||||
typeof data.sources?.revision !== 'string' ||
|
||||
!money(data.sources.total) ||
|
||||
!Array.isArray(data.sources.items) ||
|
||||
!data.sources.items.every(
|
||||
item =>
|
||||
item &&
|
||||
typeof item.id === 'string' &&
|
||||
validOrderDate(item.date) &&
|
||||
money(item.amount) &&
|
||||
item.payer === 'owner' &&
|
||||
typeof item.name === 'string',
|
||||
) ||
|
||||
data.sources.items.reduce((sum, item) => sum + item.amount, 0) !== data.sources.total
|
||||
)
|
||||
throw new Error('转账核对资料未完整返回,请重新读取。');
|
||||
data.reimbursements.forEach(validateReimbursement);
|
||||
if (
|
||||
data.confirmation &&
|
||||
(!money(data.confirmation.amount) ||
|
||||
data.confirmation.amount < 0 ||
|
||||
!Number.isSafeInteger(data.confirmation.revision) ||
|
||||
typeof data.confirmation.sourceRevision !== 'string' ||
|
||||
typeof data.confirmation.stale !== 'boolean')
|
||||
)
|
||||
throw new Error('实际支出确认资料未完整返回,请重新读取。');
|
||||
if (
|
||||
(data.ready &&
|
||||
(data.actualOutlay == null ||
|
||||
data.transferAmount !== data.ownerReceipts.net - data.actualOutlay + data.approvedReimbursements)) ||
|
||||
(!data.ready && data.transferAmount !== null)
|
||||
)
|
||||
throw new Error('转账合计与分项不一致,请重新读取。');
|
||||
if (!range.month && range.from === range.date && data.ready && (!data.confirmation || data.confirmation.stale))
|
||||
throw new Error('当天支出尚未有效确认,请重新读取。');
|
||||
return data;
|
||||
return currentReportRules().validateDailyFunds(data, range);
|
||||
}
|
||||
function preserveDailyFundsDrafts() {
|
||||
const outlay = $('#daily-outlay-form');
|
||||
@@ -272,20 +188,8 @@ function reimbursementRowsHTML(data, readOnly) {
|
||||
return `<div class="reimbursement-records">${data.reimbursements.map(row => `<article class="reimbursement-record" data-id="${e(row.id)}"><div class="reimbursement-record-heading"><strong>${e(row.date)} · ¥${yuan(row.total)}</strong><span class="badge${row.status === 'rejected' ? ' danger' : row.status === 'pending' ? ' warn' : ''}">${e(reimbursementStatusNames[row.status])}</span></div><p class="small muted">${e(row.requester_name || '提交人未提供')}提交${row.payer ? ' · ' + e(teamMemberName(row.payer)) + '实际付款' : ''}${row.reviewer_name ? ' · ' + e(row.reviewer_name) + '复核' : ''}</p>${reimbursementItemsHTML(row)}${row.note ? `<p class="small reimbursement-note">备注:${e(row.note)}</p>` : ''}${row.review_note ? `<p class="small ${row.status === 'rejected' ? 'danger-text' : 'muted'} reimbursement-note">${row.status === 'rejected' ? '驳回原因' : '复核备注'}:${e(row.review_note)}</p>` : ''}${!readOnly ? `<div class="actions">${row.canEdit && row.status !== 'approved' ? button(row.status === 'rejected' ? '修改后重新提交' : '修改报销单', 'reimbursement-edit', '', `data-id="${e(row.id)}"`) : ''}${dailyFundsOwner() && row.canApprove && row.status === 'pending' ? button('复核通过', 'reimbursement-approve', 'primary', `data-id="${e(row.id)}"`) + button('驳回', 'reimbursement-reject', '', `data-id="${e(row.id)}"`) : ''}</div>` : ''}</article>`).join('') || '<p class="small muted">所选日期暂无报销单。</p>'}</div>`;
|
||||
}
|
||||
function reimbursementDraftTotal(items) {
|
||||
let total = 0,
|
||||
complete = true;
|
||||
const amounts = [];
|
||||
for (const item of items) {
|
||||
try {
|
||||
const amount = LedgerCalc.cents(item.amount);
|
||||
if (!amount) complete = false;
|
||||
total += amount;
|
||||
amounts.push('¥' + yuan(amount));
|
||||
} catch {
|
||||
complete = false;
|
||||
}
|
||||
}
|
||||
return { total, complete, formula: amounts.join(' + ') };
|
||||
const { total, complete, amounts } = ReportRules.reimbursementAmounts(items, LedgerCalc.cents);
|
||||
return { total, complete, formula: amounts.map(amount => '¥' + yuan(amount)).join(' + ') };
|
||||
}
|
||||
function reimbursementEditorHTML(entry) {
|
||||
const draftKey = reimbursementEditors.get(entry.key),
|
||||
@@ -750,18 +654,7 @@ function dailyFundsInput(target) {
|
||||
}
|
||||
}
|
||||
function validateDailyReimbursements(data) {
|
||||
if (
|
||||
!data ||
|
||||
!Array.isArray(data.requests) ||
|
||||
!Number.isSafeInteger(data.total) ||
|
||||
!Number.isSafeInteger(data.offset) ||
|
||||
!Number.isSafeInteger(data.limit) ||
|
||||
typeof data.hasMore !== 'boolean' ||
|
||||
!['pending', 'approved', 'rejected'].every(key => Number.isSafeInteger(data.counts?.[key]))
|
||||
)
|
||||
throw new Error('全日期报销列表未完整返回,请重新读取。');
|
||||
data.requests.forEach(validateReimbursement);
|
||||
return data;
|
||||
return currentReportRules().validateDailyReimbursements(data);
|
||||
}
|
||||
async function openDailyReimbursements() {
|
||||
dailyReimbursementsOffset = 0;
|
||||
|
||||
Reference in new issue
Block a user