将账本业务页面、表单与审批迁移到 React,并加入旧版对照验收
This commit is contained in:
1 parent
f1a4e69f0d
commit
00dd683116
107 files changed
+31755
-191
No files matched your search
@@ -0,0 +1,937 @@
|
||||
import { Calc as LedgerCalc } from '../../shared';
|
||||
import { reportValidation } from './validation';
|
||||
export function reportData({ state, session, reportMonth, reportMember }) {
|
||||
function reportDownloadText(r) {
|
||||
if (teamMode() && typeof reportTeamDownloadText === 'function') return reportTeamDownloadText(r);
|
||||
const s = r.summary,
|
||||
receipts = r.receiptsByOrderDate,
|
||||
people = teamDataKeys(r.payerCosts).map(key => r.payerCosts[key]),
|
||||
missing = people.reduce((sum, c) => sum + c.missingCount, 0),
|
||||
pending = people.reduce((sum, c) => sum + c.pendingCount, 0);
|
||||
const costs = people.flatMap(c => [
|
||||
`${c.name}支出成本:货品成本 ${reportCostAmount(c.goods, c.missingCount)};已付费用 ¥${yuan(c.paidFees)}${c.items.some(item => item.kind === 'afterSale') ? '(其中售后 ¥' + yuan(reportAfterSaleAmount(c)) + ')' : ''};支出合计 ${reportCostAmount(c.total, c.missingCount + c.pendingCount)}`,
|
||||
reportPayerHints(c),
|
||||
`${c.name}逐项明细(货品成本为 0 的分项省略,已核实为 0 的费用保留):`,
|
||||
...reportCostItems(c).map(
|
||||
item =>
|
||||
`${item.date} / ${reportCostIdentity(item)} / ${item.name} / ${item.source}${item.calculation ? ' / ' + reportCostFormula(item) : ''} / ${reportCostItemAmount(item)}${item.kind === 'pending' ? '(未计入实际成本与合计)' : ''}`,
|
||||
),
|
||||
'',
|
||||
]);
|
||||
const orders = r.orderRows.map(
|
||||
row =>
|
||||
`${row.date} / ${row.kind === 'afterSale' ? '售后 · ' + row.project + ' / 客户 ' + row.customer + ' / ' + afterSalePayerName(row) + '支付' : row.paper_number || row.number} / ${label[row.status] || row.status} / 销售净额 ${reportRowAmount(row, 'sale')} / 货品成本 ${reportRowAmount(row, 'goods')} / 已付费用 ${reportRowAmount(row, 'paidFees')} / 成本合计 ${reportRowAmount(row, 'totalCost')} / 净利润 ${reportRowAmount(row, 'profit')}${row.costHint ? ' / ' + row.costHint : ''}`,
|
||||
);
|
||||
return [
|
||||
`${shopBrandName()}新账 · ${reportPeriod(r)} 对账报告`,
|
||||
'口径:普通订单按开单日期、售后按记录日期;锁价收付款按实际发生日期,销售与完整利润按交付日期。原锁料费不会重复计入交付日实际支出。',
|
||||
`销售订单:${s.orderCount} 单;售后 ${s.afterSaleCount || 0} 笔;完成 ${s.completedCount} 单;退货 ${s.returnedCount} 单;取消 ${s.cancelledCount} 单;旧草稿 ${s.draftCount} 单(未计金额)`,
|
||||
`销售净额:${reportSummaryAmount(s, 'sale')}`,
|
||||
`累计实收:¥${yuan(receipts.receipt)}`,
|
||||
`累计实退:¥${yuan(receipts.refund)}`,
|
||||
`客户收款净额:¥${yuan(receipts.net)}`,
|
||||
`订单耗用货品成本:${reportCostAmount(r.goods, s.missingCosts)}`,
|
||||
`订单已付费用:¥${yuan(r.expense)}${s.afterSaleCount ? '(其中售后 ¥' + yuan(people.reduce((sum, c) => sum + reportAfterSaleAmount(c), 0)) + ')' : ''}`,
|
||||
`各人实际货品支出:${reportCostAmount(r.outlayGoods ?? r.goods, missing)}`,
|
||||
`各人实际费用支出:¥${yuan(r.outlayExpense ?? r.expense)}`,
|
||||
`各人实际支出合计:${reportCostAmount(r.outlayTotal ?? r.goods + r.expense, missing + pending)}`,
|
||||
`本期净利润${s.unknownProfitCount ? '(已核算部分)' : ''}:${reportSummaryAmount(s, 'profit')}${s.unknownProfitCount ? ';' + s.unknownProfitCount + ' 单利润待补齐' : ''}`,
|
||||
'',
|
||||
...reportDailyProfitsText(r),
|
||||
...reportOwnershipReceiptsText(r),
|
||||
...(typeof dailyFundsDownloadText === 'function' ? dailyFundsDownloadText(r) : []),
|
||||
...reportRecipientReceiptsText(r),
|
||||
'按收款账户核对(普通订单累计收付+同期锁价实际收付)',
|
||||
...reportActiveAccounts(r).map(
|
||||
a =>
|
||||
`${accountDisplayName(a.account)}:实收 ¥${yuan(a.receipt)},实退 ¥${yuan(a.refund)},净额 ¥${yuan(a.net)}`,
|
||||
),
|
||||
'',
|
||||
teamMode() ? '各人支出成本(未入账费用不计合计)' : '双方支出成本(未入账费用不计合计)',
|
||||
...costs,
|
||||
...priceLockActivityText(r.priceLockActivity),
|
||||
...(r.materialPoolActivity?.purchases?.length
|
||||
? [
|
||||
'本期实际购料(已计入各人实际支出,不再加总)',
|
||||
...r.materialPoolActivity.purchases.map(
|
||||
item =>
|
||||
`${item.date} / ${grams(item.mg)}g / ¥${yuan(item.amount)} / ${materialPayerName(item.payer)} / ${item.note || ''}`,
|
||||
),
|
||||
'',
|
||||
]
|
||||
: []),
|
||||
'订单与售后净额明细(订单按开单日期、售后按售后日期)',
|
||||
...orders,
|
||||
'',
|
||||
`${r.date} 账面库存(按所选日及此前流水计算,月汇总仍显示所选日)`,
|
||||
...r.inventory.map(
|
||||
i =>
|
||||
`${pocketLabel(i.pocket)}:${grams(i.mg)}g${i.countUnit === 'pair' || pocketCountsEnabled(i.pocket) ? ' / ' + stockCountText(i.count) : ''}`,
|
||||
),
|
||||
'',
|
||||
'截至现在的全局未结事项(不受日期筛选)',
|
||||
`客户待收款:¥${yuan(r.customerBalance)}`,
|
||||
`订单与剩余料款待结净额:${materialReportMoney(r.settlementDue)}`,
|
||||
...r.unsettled.map(
|
||||
o =>
|
||||
`${o.number}:货款待结 ${materialReportMoney(o.costDue)},利润待结 ${materialReportMoney(o.profitDue)},${teamMemberName('owner')}直收净额 ¥${yuan(o.ownerDirect)},总待结 ${materialReportMoney(o.total)}`,
|
||||
),
|
||||
'',
|
||||
'当前待处理(所有订单,不受日期筛选)',
|
||||
...r.warnings.map(w => `${w.number || ''} ${w.message}`),
|
||||
'',
|
||||
...(r.materialPoolSettlement?.pools?.length
|
||||
? [
|
||||
'剩余料款与' +
|
||||
teamMemberName('assistant') +
|
||||
'结算(正数' +
|
||||
teamMemberName('assistant') +
|
||||
'交' +
|
||||
teamMemberName('owner') +
|
||||
',负数' +
|
||||
teamMemberName('owner') +
|
||||
'转回助理)',
|
||||
...r.materialPoolSettlement.pools.map(
|
||||
item =>
|
||||
`${item.date}:${teamMemberName('assistant')}剩余料款 ${materialReportMoney(item.assistantInventoryCredit)},实际已交净额 ¥${yuan(item.transferred)},待结 ${materialReportMoney(item.settlementDue)}`,
|
||||
),
|
||||
'',
|
||||
]
|
||||
: []),
|
||||
'收款由经办人登记,不代表支付平台自动核验。各人实际付款与订单耗用成本分别核对;退货冲回耗用成本,锁价实际进货付款保留。净利润不含房租、工资、水电。',
|
||||
].join('\n');
|
||||
}
|
||||
|
||||
function shopBrandName() {
|
||||
return state?.shopSettings?.storeName || state?.printing?.store || session?.brand?.storeName || '珠宝台账';
|
||||
}
|
||||
|
||||
function teamMemberOptions(assistantFirst = false, { historical = false, selected = '' } = {}) {
|
||||
let keys = (historical ? teamMemberKeys() : activeTeamMemberKeys()).filter(
|
||||
member => teamMode() || member !== 'assistant2',
|
||||
);
|
||||
if (assistantFirst)
|
||||
keys = [...keys.filter(member => member !== 'owner'), ...keys.filter(member => member === 'owner')];
|
||||
const options = keys.map(member => [
|
||||
member,
|
||||
teamMemberName(member) + (historical && !teamMemberEnabled(member) ? '(已停用)' : ''),
|
||||
]);
|
||||
if (selected && teamMemberKeys().includes(selected) && !keys.includes(selected))
|
||||
options.push([selected, teamMemberName(selected) + '(已停用 · 原记录)']);
|
||||
return options;
|
||||
}
|
||||
|
||||
function currentMember() {
|
||||
return state?.user?.member || session?.user?.member || (state?.user?.role === 'owner' ? 'owner' : 'assistant');
|
||||
}
|
||||
|
||||
function teamMode() {
|
||||
return !!(state?.user?.member || state?.members?.some(member => member.member === 'assistant2'));
|
||||
}
|
||||
|
||||
function validOrderDate(value) {
|
||||
if (!/^\d{4}-\d{2}-\d{2}$/.test(value || '')) return false;
|
||||
const date = new Date(value + 'T12:00:00Z');
|
||||
return !Number.isNaN(date.getTime()) && date.toISOString().slice(0, 10) === value;
|
||||
}
|
||||
|
||||
function dailyFundsMoney(value) {
|
||||
return value == null ? '待确认' : '¥' + yuan(value);
|
||||
}
|
||||
|
||||
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(' + '),
|
||||
};
|
||||
}
|
||||
|
||||
function teamDataKeys(data) {
|
||||
return [...assistantMemberKeys(), 'owner'].filter(member => data && Object.hasOwn(data, member));
|
||||
}
|
||||
|
||||
function reportSummaryAmount(summary, key) {
|
||||
const missing = summary.unknownCounts?.[key] || 0;
|
||||
return missing && summary.knownCounts?.[key] === 0 && !summary[key] && !summary.afterSaleCount
|
||||
? '待补齐'
|
||||
: (missing ? '已知 ' : '') + '¥' + yuan(summary[key]);
|
||||
}
|
||||
|
||||
const yuan = n =>
|
||||
n == null
|
||||
? '待补'
|
||||
: (n / 100).toLocaleString('zh-CN', {
|
||||
minimumFractionDigits: 2,
|
||||
maximumFractionDigits: 2,
|
||||
});
|
||||
|
||||
function reportPeriod(range) {
|
||||
return range.from === range.date ? range.date : range.from + ' 至 ' + range.date;
|
||||
}
|
||||
|
||||
function reportActiveAccounts(r) {
|
||||
const recorded = new Set(
|
||||
teamDataKeys(r.recipientReceipts).flatMap(key => r.recipientReceipts[key].items.map(item => item.account)),
|
||||
);
|
||||
return r.accounts.filter(
|
||||
account =>
|
||||
account.receipt !== 0 ||
|
||||
account.refund !== 0 ||
|
||||
account.net !== 0 ||
|
||||
account.entryCount > 0 ||
|
||||
recorded.has(account.account),
|
||||
);
|
||||
}
|
||||
|
||||
function accountDisplayName(value) {
|
||||
const account = accountIdentity(value);
|
||||
return account ? teamMemberName(account.member) + account.channel : value;
|
||||
}
|
||||
|
||||
function reportDailyProfitAmount(value, known, profit = false) {
|
||||
return value === null ? (profit ? '待核算(已核算 ¥' : '待补齐(已知 ¥') + yuan(known) + ')' : '¥' + yuan(value);
|
||||
}
|
||||
|
||||
function reportTeamDownloadText(report) {
|
||||
const summary = report.summary,
|
||||
receipts = report.receiptsByOrderDate;
|
||||
return [
|
||||
shopBrandName() + '三人账 · ' + reportPeriod(report),
|
||||
'利润留在店里,按订单归属分别记业绩。经营款各自管理;未导入真实期初经营款。',
|
||||
...peopleCountReportLines(report.peopleCount),
|
||||
'销售净额:' + reportSummaryAmount(summary, 'sale'),
|
||||
'本期净利润:' + reportSummaryAmount(summary, 'profit'),
|
||||
'本期实收:¥' + yuan(receipts.receipt) + ';本期实退:¥' + yuan(receipts.refund),
|
||||
...reportDailyProfitsText(report),
|
||||
...reportOwnershipReceiptsText(report),
|
||||
...dailyFundsDownloadText(report),
|
||||
...reportRecipientReceiptsText(report),
|
||||
'按实际付款人核对成本',
|
||||
...teamDataKeys(report.payerCosts).flatMap(member => {
|
||||
const row = report.payerCosts[member];
|
||||
return [
|
||||
teamMemberName(member) +
|
||||
':实际货品支出 ' +
|
||||
reportCostAmount(row.goods, row.missingCount) +
|
||||
';已付费用 ¥' +
|
||||
yuan(row.paidFees),
|
||||
...reportCostItems(row).map(
|
||||
item =>
|
||||
item.date + ' / ' + reportCostIdentity(item) + ' / ' + item.name + ' / ' + reportCostItemAmount(item),
|
||||
),
|
||||
];
|
||||
}),
|
||||
'订单与售后',
|
||||
...report.orderRows.map(
|
||||
row =>
|
||||
row.date +
|
||||
' / ' +
|
||||
(row.paper_number || row.number || row.project) +
|
||||
' / ' +
|
||||
(row.customer || '未填客户') +
|
||||
' / ' +
|
||||
teamMemberName(row.member) +
|
||||
' / 销售 ' +
|
||||
reportRowAmount(row, 'sale') +
|
||||
' / 净利润 ' +
|
||||
reportRowAmount(row, 'profit'),
|
||||
),
|
||||
'历史两人结算不计入团队新债务。',
|
||||
].join('\n');
|
||||
}
|
||||
|
||||
function reportCostAmount(value, partial = 0) {
|
||||
return partial && value === 0 ? '待补齐' : (partial ? '已知 ' : '') + '¥' + yuan(value);
|
||||
}
|
||||
|
||||
function reportAfterSaleAmount(cost) {
|
||||
return cost.items.filter(item => item.kind === 'afterSale').reduce((sum, item) => sum + item.amount, 0);
|
||||
}
|
||||
|
||||
function reportPayerHints(cost) {
|
||||
return [
|
||||
cost.missingCount ? cost.missingCount + ' 项成本待补齐' : '',
|
||||
cost.pendingCount ? cost.pendingCount + ' 项费用未入账,不计合计' : '',
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join(';');
|
||||
}
|
||||
|
||||
function reportCostItems(cost) {
|
||||
return cost.items.filter(item => item.kind !== 'goods' || item.amount !== 0);
|
||||
}
|
||||
|
||||
function reportCostIdentity(item) {
|
||||
if (item.materialPoolId) return item.materialPoolId + ' 购料';
|
||||
return item.kind === 'afterSale'
|
||||
? '售后 · ' + (item.customer || '未填客户')
|
||||
: (item.price_lock_id ? '锁价 · ' : '') +
|
||||
(item.paper_number || item.number || '锁价记录') +
|
||||
(item.customer ? ' · ' + item.customer : '');
|
||||
}
|
||||
|
||||
function reportCostFormula(item) {
|
||||
const c = item.calculation;
|
||||
if (!c) return '';
|
||||
return (
|
||||
grams(c.quantity) +
|
||||
'g × ' +
|
||||
(c.rate == null
|
||||
? item.component === 'material'
|
||||
? '每克料价待补齐'
|
||||
: '每克工费待补齐'
|
||||
: yuan(c.rate) + '元/克') +
|
||||
(item.amount == null ? '' : ' = ' + yuan(item.amount) + '元')
|
||||
);
|
||||
}
|
||||
|
||||
function reportCostItemAmount(item) {
|
||||
if (item.kind === 'pending')
|
||||
return '未入账' + (item.amount == null ? '(金额待补)' : '(登记 ¥' + yuan(item.amount) + ')');
|
||||
return item.amount == null ? '待补齐' : '¥' + yuan(item.amount);
|
||||
}
|
||||
|
||||
function afterSalePayerName(row) {
|
||||
return row.costItems?.[0]?.payer ? teamMemberName(row.costItems[0].payer) : '付款人待补';
|
||||
}
|
||||
|
||||
const label = {
|
||||
draft: '旧草稿',
|
||||
confirmed: '旧单待补齐',
|
||||
delivered: '已完成',
|
||||
returned: '已退货',
|
||||
cancelled: '已取消',
|
||||
after_sale: '售后',
|
||||
recovery: '回收',
|
||||
};
|
||||
|
||||
function reportRowAmount(row, key) {
|
||||
if (row.status === 'draft') return '未开单';
|
||||
if (key === 'goods') {
|
||||
const c = reportRowCost(row);
|
||||
return reportCostAmount(c.goods, c.missing);
|
||||
}
|
||||
if (key === 'paidFees') return '¥' + yuan(reportRowCost(row).paidFees);
|
||||
if (row[key] != null) return '¥' + yuan(row[key]);
|
||||
return row.known?.[key] ? '已知 ¥' + yuan(row.known[key]) + '(待补齐)' : '待补齐';
|
||||
}
|
||||
|
||||
function reportDailyProfitsText(r) {
|
||||
const table = r.dailyProfits,
|
||||
rowText = row =>
|
||||
`销售净额 ¥${yuan(row.sales)} / 成本 ${reportDailyProfitAmount(row.totalCost, row.knownTotalCost)} / 利润 ${reportDailyProfitAmount(row.profit, row.knownProfit, true)}`;
|
||||
return [
|
||||
'每日利润表(按日期与订单归属人;普通订单按开单日、锁价成单按交付日、售后按记录日)',
|
||||
...(table.rows.length
|
||||
? table.rows.map(row => `${row.date} / ${row.name} / ${rowText(row)}`)
|
||||
: ['所选范围暂无订单或售后记录。']),
|
||||
`所选范围合计:${rowText(table.summary)}`,
|
||||
'',
|
||||
];
|
||||
}
|
||||
|
||||
function reportOwnershipReceiptsText(r) {
|
||||
return [
|
||||
'按订单归属核对净收入(收款减退款,已含他人代收,尚未扣成本与费用)',
|
||||
...reportOwnershipKeys(r).flatMap(key => {
|
||||
const person = r.ownershipReceipts[key];
|
||||
return [
|
||||
`${person.name}所属订单净收入:¥${yuan(person.net)};实收 ¥${yuan(person.receipt)};实退 ¥${yuan(person.refund)}`,
|
||||
...person.accounts.map(
|
||||
account =>
|
||||
`${account.recipient === person.member ? '本人收款' : '他人代收'} / ${accountDisplayName(account.account)}:实收 ¥${yuan(account.receipt)},实退 ¥${yuan(account.refund)},净额 ¥${yuan(account.net)}`,
|
||||
),
|
||||
...reportOwnershipBusinessText(r.ownershipBusiness[key]),
|
||||
'',
|
||||
];
|
||||
}),
|
||||
];
|
||||
}
|
||||
|
||||
function dailyFundsDownloadText(report) {
|
||||
const range = {
|
||||
date: report.date,
|
||||
from: report.from,
|
||||
month: reportMonth,
|
||||
},
|
||||
data = report.dailyFunds;
|
||||
if (data?.team)
|
||||
return [
|
||||
'每日报销单(按报销日期归集,已批准报销不在当日订单往来重复相加)',
|
||||
...data.reimbursements.flatMap(row => [
|
||||
`${row.date} / ${row.requester_name} / ${reimbursementStatusNames[row.status]} / 合计 ¥${yuan(row.total)}`,
|
||||
...row.items.map(item => `${item.name}:¥${yuan(item.amount)}`),
|
||||
]),
|
||||
'',
|
||||
];
|
||||
if (!data || data.rangeUnsupported) return ['每天转账核对', '尚未取得完整转账资料,不输出应转金额。', ''];
|
||||
try {
|
||||
validateDailyFunds(data, range);
|
||||
} catch {
|
||||
return ['每天转账核对', '资料未完整返回,不输出应转金额。', ''];
|
||||
}
|
||||
const result = [
|
||||
'每天转账核对(应转合计,未扣已转)',
|
||||
`${teamMemberName('owner')}实收 ¥${yuan(data.ownerReceipts.receipt)} − 实退 ¥${yuan(data.ownerReceipts.refund)} = 净收款 ¥${yuan(data.ownerReceipts.net)}`,
|
||||
];
|
||||
if (data.ready)
|
||||
result.push(
|
||||
`${teamMemberName('owner')}净收款 ¥${yuan(data.ownerReceipts.net)} − 确认完整对外支出 ¥${yuan(data.actualOutlay)} + 已批准报销 ¥${yuan(data.approvedReimbursements)} = 应转合计 ¥${yuan(data.transferAmount)}`,
|
||||
data.transferAmount > 0
|
||||
? '方向:' + teamMemberName('owner') + '转' + teamMemberName('assistant')
|
||||
: data.transferAmount < 0
|
||||
? '方向:' + teamMemberName('assistant') + '转' + teamMemberName('owner')
|
||||
: '方向:无需转款',
|
||||
);
|
||||
else
|
||||
result.push(
|
||||
'当天完整支出尚未全部确认,暂不输出完整应转合计。',
|
||||
...(data.missingDates.length ? ['待确认日期:' + data.missingDates.join('、')] : []),
|
||||
...(data.staleDates.length ? ['来源变动待重新确认:' + data.staleDates.join('、')] : []),
|
||||
);
|
||||
result.push('不要与旧按单/剩料待结重复相加;报销与确认不扣订单利润。', '已批准报销项目(按报销日期归集)');
|
||||
const approved = data.reimbursements.filter(row => row.status === 'approved');
|
||||
result.push(
|
||||
...(approved.length
|
||||
? approved.flatMap(row => [
|
||||
`${row.date} / ${row.requester_name} / 合计 ¥${yuan(row.total)} / ${row.reviewer_name || teamMemberName('owner')}复核`,
|
||||
...row.items.map(item => `${item.name}:¥${yuan(item.amount)}`),
|
||||
])
|
||||
: ['本期暂无已批准报销。']),
|
||||
'',
|
||||
);
|
||||
return result;
|
||||
}
|
||||
|
||||
function reportRecipientReceiptsText(r) {
|
||||
return [
|
||||
'按收款人汇总(普通订单按开单日归集当前收付,锁价按实际收付日归集;负数为冲回)',
|
||||
...teamDataKeys(r.recipientReceipts).flatMap(key => {
|
||||
const person = r.recipientReceipts[key];
|
||||
return [
|
||||
`${person.name}总收款:¥${yuan(person.receipt)};退款 ¥${yuan(person.refund)};净收款 ¥${yuan(person.net)}`,
|
||||
...['receipt', 'refund'].flatMap(kind => {
|
||||
const items = person.items.filter(item => item.kind === kind),
|
||||
name = kind === 'receipt' ? '收款' : '退款';
|
||||
return [
|
||||
`${person.name}${name}明细(日期为实际${name}日):`,
|
||||
...(items.length
|
||||
? items.map(
|
||||
item =>
|
||||
`${item.date} / ${reportReceiptBasis(item)} / ${item.paper_number || item.number || (item.price_lock_id ? '锁价记录' : '订单记录')} / 客户 ${item.customer || '未填客户称呼'} / ${accountDisplayName(item.account)} / ${reportReceiptLabel(item)} ¥${yuan(item.amount)}${item.reference || item.note ? ' / ' + (item.reference || item.note) : ''}`,
|
||||
)
|
||||
: ['所选范围没有' + person.name + name + '记录。']),
|
||||
`${name}明细合计:¥${yuan(person[kind])}`,
|
||||
];
|
||||
}),
|
||||
'',
|
||||
];
|
||||
}),
|
||||
];
|
||||
}
|
||||
|
||||
function priceLockActivityText(activity) {
|
||||
if (!activity?.summary?.eventCount) return [];
|
||||
const s = activity.summary;
|
||||
return [
|
||||
'锁价实际收付(按实际发生日期,不重复计原锁付款;待交付不计销售和利润)',
|
||||
`客户实收 ¥${yuan(s.receipt)};客户实退 ¥${yuan(s.refund)};${teamMemberName('owner')}实际支出 ¥${yuan(s.ownerOutlay)};${teamMemberName('assistant')}实际支出 ¥${yuan(s.assistantOutlay)}`,
|
||||
...priceLockActivityRows(activity).map(
|
||||
item =>
|
||||
`${item.date} / ${item.number || '锁价记录'} / ${item.customer} / ${item.activityType} / ${item.activityName} / ${item.who} / ${item.amount == null ? '待补齐' : '¥' + yuan(item.amount)}`,
|
||||
),
|
||||
'',
|
||||
];
|
||||
}
|
||||
|
||||
const grams = n => (n / 1000).toFixed(3);
|
||||
|
||||
const materialPayerName = payer => (payer ? teamMemberName(payer) : '待补');
|
||||
|
||||
function pocketLabel(key) {
|
||||
return state?.pocketCatalog?.find(row => row.key === key)?.name || String(key ?? '');
|
||||
}
|
||||
|
||||
function pocketCountsEnabled(key) {
|
||||
return !!key && state?.pocketCatalog?.some(row => row.key === key && row.countUnit === 'pair') === true;
|
||||
}
|
||||
|
||||
function stockCountText(value, { signed = false, unknown = '未记录对数' } = {}) {
|
||||
return Number.isSafeInteger(value) ? (signed && value > 0 ? '+' : '') + value + '对' : unknown;
|
||||
}
|
||||
|
||||
function materialReportMoney(value) {
|
||||
return value == null ? '料费待补' : '¥' + yuan(value);
|
||||
}
|
||||
|
||||
function teamMemberName(member) {
|
||||
return (
|
||||
state?.shopSettings?.members?.find(row => row.member === member)?.label ||
|
||||
state?.members?.find(row => row.member === member)?.label ||
|
||||
session?.loginOptions?.find(row => row.member === member)?.label ||
|
||||
{
|
||||
owner: '麦麦',
|
||||
assistant: '娜娜',
|
||||
assistant2: '小昊',
|
||||
}[member] ||
|
||||
'待确认'
|
||||
);
|
||||
}
|
||||
|
||||
const reimbursementStatusNames = {
|
||||
pending: '待店主复核',
|
||||
approved: '已批准',
|
||||
rejected: '已驳回',
|
||||
};
|
||||
|
||||
function dailyFundsOwner() {
|
||||
return state?.user?.role === 'owner';
|
||||
}
|
||||
|
||||
function teamMemberKeys() {
|
||||
return teamMemberCatalog().map(row => row.member);
|
||||
}
|
||||
|
||||
function activeTeamMemberKeys() {
|
||||
return teamMemberKeys().filter(teamMemberEnabled);
|
||||
}
|
||||
|
||||
function teamMemberEnabled(member) {
|
||||
return (
|
||||
teamMemberCatalog().find(row => row.member === member)?.enabled !== false && teamMemberKeys().includes(member)
|
||||
);
|
||||
}
|
||||
|
||||
function assistantMemberKeys() {
|
||||
return teamMemberKeys().filter(member => member !== 'owner');
|
||||
}
|
||||
|
||||
function reportOwnershipKeys(r) {
|
||||
const keys = teamDataKeys(r.ownershipReceipts);
|
||||
return state.user.role === 'owner' && !reportMember
|
||||
? keys.filter(key => {
|
||||
const person = r.ownershipReceipts[key];
|
||||
return (
|
||||
person.items.length ||
|
||||
person.receipt !== 0 ||
|
||||
person.refund !== 0 ||
|
||||
person.net !== 0 ||
|
||||
r.ownershipBusiness[key].recordCount ||
|
||||
r.ownershipBusiness[key].currentAccount.days.length
|
||||
);
|
||||
})
|
||||
: keys;
|
||||
}
|
||||
|
||||
function accountIdentity(value) {
|
||||
const text = String(value ?? '');
|
||||
for (const member of teamMemberKeys()) {
|
||||
const prefixes = member === 'assistant' ? ['助理', '助理1'] : [memberAccountPrefix(member)];
|
||||
for (const prefix of prefixes)
|
||||
if (text === prefix)
|
||||
return {
|
||||
member,
|
||||
prefix,
|
||||
channel: '',
|
||||
};
|
||||
else if (text.startsWith(prefix) && ['微信', '支付宝', '现金', '信用卡'].includes(text.slice(prefix.length)))
|
||||
return {
|
||||
member,
|
||||
prefix,
|
||||
channel: text.slice(prefix.length),
|
||||
};
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function priceLockActivityRows(activity) {
|
||||
if (!activity) return [];
|
||||
return [...(activity.customerCash || []), ...(activity.orderPayments || [])]
|
||||
.map(item => ({
|
||||
...item,
|
||||
activityType: item.kind === 'receipt' ? '客户收款' : '客户退款',
|
||||
who: accountDisplayName(item.account),
|
||||
activityName: item.product || '客户收退款',
|
||||
}))
|
||||
.concat(
|
||||
(activity.materialOutlays || []).map(item => ({
|
||||
...item,
|
||||
activityType: item.source === 'extra' ? '补重料费付款' : '原锁料费付款',
|
||||
who: priceLockPayerName(item.payer),
|
||||
activityName: (item.product || '黄金') + ' · ' + grams(item.quantity) + 'g × ' + yuan(item.rate) + '元/克',
|
||||
})),
|
||||
(activity.deliveryGoodsOutlays || []).map(item => ({
|
||||
...item,
|
||||
activityType: '交付货品支出',
|
||||
who: priceLockPayerName(item.payer),
|
||||
activityName: item.name,
|
||||
})),
|
||||
(activity.directOutlays || []).map(item => ({
|
||||
...item,
|
||||
activityType: '实际费用',
|
||||
who: priceLockPayerName(item.payer),
|
||||
activityName: item.note,
|
||||
})),
|
||||
)
|
||||
.sort((a, b) => a.date.localeCompare(b.date));
|
||||
}
|
||||
|
||||
const materialPurchasePayer = purchase => purchase.payer ?? purchase.actualpayer ?? purchase.actualPayer;
|
||||
|
||||
function peopleCountReportLines(count) {
|
||||
const period = count?.from !== count?.date;
|
||||
return peopleParts(true).map(
|
||||
([part, name]) =>
|
||||
`${peopleCountDisplayName(name, period)}:${peopleCountText(count, part)}${period ? '(期末 ' + (count?.date || '未知') + ';开始日前最近记录 ' + (count?.[part]?.baselineDate || '暂无') + ')' : ''}`,
|
||||
);
|
||||
}
|
||||
|
||||
function reportRowCost(row) {
|
||||
const goods = (row.costItems || []).filter(item => item.kind === 'goods');
|
||||
return {
|
||||
goods: goods.reduce((sum, item) => sum + (item.amount ?? 0), 0),
|
||||
missing: goods.filter(item => item.amount == null).length,
|
||||
paidFees: (row.costItems || [])
|
||||
.filter(item => ['paid', 'afterSale'].includes(item.kind))
|
||||
.reduce((sum, item) => sum + item.amount, 0),
|
||||
};
|
||||
}
|
||||
|
||||
function reportOwnershipBusinessText(business) {
|
||||
return [
|
||||
`所属订单总成本:${reportBusinessAmount(business.totalCost, business.knownTotalCost)};本人付款 ${reportBusinessAmount(business.selfCost, business.knownSelfCost)};他人付款 ${reportBusinessAmount(business.otherCost, business.knownOtherCost)}`,
|
||||
...reportPoolMaterialText(business),
|
||||
...reportOwnerAdvancesText(business),
|
||||
...teamMemberKeys()
|
||||
.filter(key => key !== business.member)
|
||||
.map(key => business.costByPayer[key])
|
||||
.filter(payer => payer.knownTotalCost || payer.totalCost === null)
|
||||
.map(payer => `${payer.name}付款:${reportBusinessAmount(payer.totalCost, payer.knownTotalCost)}`),
|
||||
`本期利润:${business.equation.complete && !business.incomplete && business.profit !== null ? '¥' + yuan(business.profit) : '待核算,完整利润暂不显示'}`,
|
||||
...business.difference.reasons.map(reason => reason.text),
|
||||
...reportCurrentAccountText(business),
|
||||
];
|
||||
}
|
||||
|
||||
function reportReceiptBasis(item) {
|
||||
return item.order_after_sale
|
||||
? '订单售后 · 按实际收付日'
|
||||
: item.price_lock_id
|
||||
? '锁价 · 按实际收付日'
|
||||
: '普通订单 · 开单 ' + (item.order_date || '日期未提供');
|
||||
}
|
||||
|
||||
function reportReceiptLabel(item) {
|
||||
return (item.kind === 'receipt' ? '收款' : '退款') + (item.amount < 0 ? '冲回' : '');
|
||||
}
|
||||
|
||||
function teamMemberCatalog() {
|
||||
const rows = state?.members?.length
|
||||
? state.members
|
||||
: state?.shopSettings?.members?.length
|
||||
? state.shopSettings.members
|
||||
: legacyTeamMembers;
|
||||
return rows.filter(row => row && typeof row.member === 'string');
|
||||
}
|
||||
|
||||
function memberAccountPrefix(member) {
|
||||
return (
|
||||
{
|
||||
owner: '麦麦',
|
||||
assistant: '助理',
|
||||
assistant2: '助理2',
|
||||
}[member] || member
|
||||
);
|
||||
}
|
||||
|
||||
const priceLockPayerName = payer => (payer ? teamMemberName(payer) : '待补');
|
||||
|
||||
function peopleParts(historical = false) {
|
||||
const keys = assistantMemberKeys().filter(member => historical || teamMemberEnabled(member)),
|
||||
parts = keys.map(member => [member === 'assistant' ? 'assistant1' : member, teamMemberName(member) + '人数']);
|
||||
return state?.user?.role === 'assistant' && teamMode()
|
||||
? parts.filter(([key]) => peoplePartMember(key) === currentMember())
|
||||
: parts;
|
||||
}
|
||||
|
||||
function peopleCountDisplayName(name, period = false) {
|
||||
return name.replace('人数', period ? '结束日总人数' : '当日总人数');
|
||||
}
|
||||
|
||||
function peopleCountText(count, part = null) {
|
||||
const value = part ? count?.[part] : count;
|
||||
if (!value || !Object.hasOwn(value, 'endTotal') || !Object.hasOwn(value, 'netChange')) return '尚未取得总人数';
|
||||
const period = count.from !== count.date,
|
||||
total = value.endTotal === null ? (period ? '结束日未记录' : '当日未记录') : value.endTotal + ' 人(已记录)';
|
||||
const baseline = value.baselineDate,
|
||||
comparison = '较上次记录' + (baseline ? '(' + baseline + ')' : '');
|
||||
return (
|
||||
total +
|
||||
' · ' +
|
||||
(period
|
||||
? '本期净增 ' +
|
||||
(value.netChange === null
|
||||
? '未知(' + peopleCountUnknownReason(value.netChangeReason, true) + ')'
|
||||
: peopleCountSignedText(value.netChange)) +
|
||||
(baseline ? '(基准 ' + baseline + ')' : '')
|
||||
: value.netChange === null
|
||||
? value.endTotal !== null && value.netChangeReason === 'missing-previous'
|
||||
? '首次记录(暂无上次记录)'
|
||||
: comparison + '变化未知(' + peopleCountUnknownReason(value.netChangeReason) + ')'
|
||||
: comparison + peopleCountDeltaText(value.netChange))
|
||||
);
|
||||
}
|
||||
|
||||
function reportBusinessAmount(value, known) {
|
||||
return (value === null ? '已知 ' : '') + '¥' + yuan(value === null ? known : value);
|
||||
}
|
||||
|
||||
function reportPoolMaterialText(business) {
|
||||
const pool = business.poolMaterial;
|
||||
if (!pool?.days.length) return [];
|
||||
const owner = pool.byPayer.owner;
|
||||
return [
|
||||
`已用料合计:${grams(pool.mg)}g`,
|
||||
`料池已用料费:${reportBusinessAmount(pool.amount, pool.knownAmount)}(已计入总成本;当日往来只取${teamMemberName('owner')}垫付部分,公式中计入一次)`,
|
||||
...pool.days.map(day => `${day.date} 料池(已用 ${grams(day.mg)}g):${reportPoolMaterialFormula(day)}`),
|
||||
...(reportPoolMaterialPendingNote(pool) ? [reportPoolMaterialPendingNote(pool)] : []),
|
||||
`其中${teamMemberName('owner')}垫付:${reportBusinessAmount(owner.amount, owner.knownAmount)}`,
|
||||
`其他成本:${reportBusinessAmount(pool.otherCosts.amount, pool.otherCosts.knownAmount)}(其余商品成本、工费与费用)`,
|
||||
'料费按未四舍五入均价逐单核算,显示料价相乘可能有分币差。',
|
||||
...(pool.hasPriceLocks ? ['锁价已用料费在交付日的当日往来中列示,不重复记实际采购支出。'] : []),
|
||||
];
|
||||
}
|
||||
|
||||
function reportOwnerAdvancesText(business) {
|
||||
const advances = business.ownerAdvances,
|
||||
label = business.member === 'owner' ? teamMemberName('owner') + '付款明细' : teamMemberName('owner') + '垫付明细';
|
||||
return [
|
||||
label + '(按所属订单开单日/售后记录日逐日核对,不累计历史;预估未付不计实付)',
|
||||
...(advances.days.length
|
||||
? advances.days.flatMap(day => [
|
||||
`${day.date} ${business.member === 'owner' ? '付款' : '垫付'}小计:${reportOwnerAdvanceAmount(day.amount, day.knownAmount)}`,
|
||||
...(day.items.some(item => item.poolMaterial) ? [reportOwnerAdvanceFormula(business, day)] : []),
|
||||
...day.items.map(
|
||||
item =>
|
||||
`${item.date} / ${item.customer || '未填客户'} / ${item.paperNumber || item.number} / ${item.name} / ${reportOwnerAdvanceItemAmount(item)}`,
|
||||
),
|
||||
])
|
||||
: [
|
||||
advances.from === advances.date
|
||||
? advances.date + ' 当日已登记垫付 ¥0.00,无明细。'
|
||||
: '所选月份暂无已登记明细。',
|
||||
]),
|
||||
];
|
||||
}
|
||||
|
||||
function reportCurrentAccountText(business) {
|
||||
if (business.member === 'owner') return [];
|
||||
return [
|
||||
'当日往来账(逐日核对,不含历史余额,未扣实际转账)',
|
||||
...reportCurrentAccountDays(business).flatMap(day => [
|
||||
`${day.date} / ${reportCurrentAccountDirection(business, day)}${day.amount === null ? '' : ' ¥' + yuan(Math.abs(day.amount))}`,
|
||||
reportCurrentAccountFormula(day),
|
||||
...(day.incomplete ? ['成本或利润尚未补齐,暂不显示完整应转金额;预估未付项目不计垫付。'] : []),
|
||||
]),
|
||||
];
|
||||
}
|
||||
|
||||
const legacyTeamMembers = [
|
||||
{
|
||||
member: 'owner',
|
||||
label: '麦麦',
|
||||
},
|
||||
{
|
||||
member: 'assistant',
|
||||
label: '娜娜',
|
||||
},
|
||||
{
|
||||
member: 'assistant2',
|
||||
label: '小昊',
|
||||
},
|
||||
];
|
||||
|
||||
function reportOwnerAdvanceAmount(value, known) {
|
||||
return value === null ? '待补(已知 ¥' + yuan(known) + ')' : '¥' + yuan(value);
|
||||
}
|
||||
|
||||
function reportOwnerAdvanceFormula(business, day) {
|
||||
return `${business.member === 'owner' ? teamMemberName('owner') + '付款合计' : teamMemberName('owner') + '垫付合计'}:料池料费 ${reportOwnerAdvanceAmount(day.poolAmount, day.knownPoolAmount)} + 其他成本 ${reportOwnerAdvanceAmount(day.otherAmount, day.knownOtherAmount)} = ${reportOwnerAdvanceAmount(day.amount, day.knownAmount)}`;
|
||||
}
|
||||
|
||||
function reportOwnerAdvanceItemAmount(item) {
|
||||
if (item.status === 'pending')
|
||||
return (
|
||||
'待核对' +
|
||||
(item.estimatedAmount === null ? '(金额待补)' : '(预估 ¥' + yuan(item.estimatedAmount) + ')') +
|
||||
',未计垫付'
|
||||
);
|
||||
return item.amount === null ? '待补齐' : '¥' + yuan(item.amount);
|
||||
}
|
||||
|
||||
function reportCurrentAccountDays(business) {
|
||||
const account = business.currentAccount;
|
||||
return account.days.length
|
||||
? account.days
|
||||
: account.from === account.date
|
||||
? [
|
||||
{
|
||||
date: account.date,
|
||||
materialCost: 0,
|
||||
knownMaterialCost: 0,
|
||||
otherCost: 0,
|
||||
knownOtherCost: 0,
|
||||
profit: 0,
|
||||
knownProfit: 0,
|
||||
ownerNetReceipts: 0,
|
||||
amount: 0,
|
||||
incomplete: false,
|
||||
},
|
||||
]
|
||||
: [];
|
||||
}
|
||||
|
||||
function reportCurrentAccountDirection(business, day) {
|
||||
return day.amount === null
|
||||
? '应转金额待核算'
|
||||
: day.amount > 0
|
||||
? business.name + ('应转' + teamMemberName('owner'))
|
||||
: day.amount < 0
|
||||
? teamMemberName('owner') + '应转' + business.name
|
||||
: '当日无需转款';
|
||||
}
|
||||
|
||||
function reportCurrentAccountFormula(day) {
|
||||
return `${teamMemberName('owner')}垫付已用料费 ${reportOwnerAdvanceAmount(day.materialCost, day.knownMaterialCost)} + ${teamMemberName('owner')}垫付其他订单成本 ${reportOwnerAdvanceAmount(day.otherCost, day.knownOtherCost)} + 本人当日订单净利润 ${reportDailyProfitAmount(day.profit, day.knownProfit, true)} − ${teamMemberName('owner')}代收净额 ¥${yuan(day.ownerNetReceipts)} = ${day.amount === null ? '待核算' : '¥' + yuan(day.amount)}`;
|
||||
}
|
||||
|
||||
function peoplePartMember(part) {
|
||||
return part === 'assistant1' ? 'assistant' : part;
|
||||
}
|
||||
|
||||
function peopleCountUnknownReason(reason, period = false) {
|
||||
return (
|
||||
{
|
||||
'missing-current': period ? '结束日未记录' : '当日未记录',
|
||||
'missing-previous': period ? '开始日前暂无记录' : '暂无上次记录',
|
||||
'missing-both': period ? '结束日未记录,开始日前暂无记录' : '当日未记录,暂无上次记录',
|
||||
}[reason] || '缺少人数记录'
|
||||
);
|
||||
}
|
||||
|
||||
function peopleCountSignedText(value) {
|
||||
return (value > 0 ? '+' : '') + value + ' 人';
|
||||
}
|
||||
|
||||
function peopleCountDeltaText(value) {
|
||||
return value > 0 ? '新增 ' + value + ' 人' : value < 0 ? '减少 ' + Math.abs(value) + ' 人' : '无变化(0 人)';
|
||||
}
|
||||
|
||||
function reportPoolMaterialFormula(day) {
|
||||
if (day.sources)
|
||||
return (
|
||||
day.sources
|
||||
.map(
|
||||
source =>
|
||||
`${reportPoolMaterialSourceLabel(source)} ${grams(source.mg)}g × ${source.averageRate === null ? '待补料价' : '¥' + yuan(source.averageRate) + '/g'}`,
|
||||
)
|
||||
.join(' + ') +
|
||||
` = ${day.amount === null ? '料费待补(已知 ¥' + yuan(day.knownAmount) + ')' : '¥' + yuan(day.amount)}`
|
||||
);
|
||||
return `${grams(day.mg)}g × ${day.averageRate === null ? '待补料价' : '¥' + yuan(day.averageRate) + '/g'} = ${day.amount === null ? '料费待补(已知 ¥' + yuan(day.knownAmount) + ')' : '¥' + yuan(day.amount)}`;
|
||||
}
|
||||
|
||||
function reportPoolMaterialPendingNote(pool) {
|
||||
return pool.days.some(
|
||||
day => day.sources && day.sources.reduce((total, source) => total + source.knownAmount, 0) > day.knownAmount,
|
||||
)
|
||||
? '部分来源已可核对,料费待补的订单尚未计入已知料费。'
|
||||
: '';
|
||||
}
|
||||
|
||||
function reportPoolMaterialSourceLabel(source) {
|
||||
return (
|
||||
(source.kind === 'personal_recovery' ? teamMemberName(source.member) + '个人回收料' : '公共料') +
|
||||
(source.priceLocked ? '(含锁价原料)' : '')
|
||||
);
|
||||
}
|
||||
const { validateDailyFunds, validateReport, validateDailyReimbursements } = reportValidation({
|
||||
teamDataKeys,
|
||||
validOrderDate,
|
||||
teamMode,
|
||||
currentMember,
|
||||
teamMemberKeys,
|
||||
reimbursementStatusNames,
|
||||
state,
|
||||
reportMember,
|
||||
});
|
||||
return {
|
||||
validateReport,
|
||||
validateDailyFunds,
|
||||
validateDailyReimbursements,
|
||||
reportDownloadText,
|
||||
shopBrandName,
|
||||
teamMemberOptions,
|
||||
currentMember,
|
||||
teamMode,
|
||||
validOrderDate,
|
||||
dailyFundsMoney,
|
||||
reimbursementDraftTotal,
|
||||
reportSummaryAmount,
|
||||
yuan,
|
||||
reportPeriod,
|
||||
reportActiveAccounts,
|
||||
accountDisplayName,
|
||||
reportDailyProfitAmount,
|
||||
reimbursementStatusNames,
|
||||
teamMemberName,
|
||||
dailyFundsOwner,
|
||||
reportOwnershipKeys,
|
||||
teamDataKeys,
|
||||
reportPayerHints,
|
||||
reportCostAmount,
|
||||
reportAfterSaleAmount,
|
||||
priceLockActivityRows,
|
||||
grams,
|
||||
materialPayerName,
|
||||
materialPurchasePayer,
|
||||
afterSalePayerName,
|
||||
reportRowAmount,
|
||||
pocketLabel,
|
||||
materialReportMoney,
|
||||
reportReceiptBasis,
|
||||
reportReceiptLabel,
|
||||
reportCostItems,
|
||||
reportCostFormula,
|
||||
reportCostItemAmount,
|
||||
label,
|
||||
pocketCountsEnabled,
|
||||
stockCountText,
|
||||
teamMemberKeys,
|
||||
reportBusinessAmount,
|
||||
reportOwnerAdvanceAmount,
|
||||
reportOwnerAdvanceFormula,
|
||||
reportOwnerAdvanceItemAmount,
|
||||
reportCurrentAccountDays,
|
||||
reportCurrentAccountDirection,
|
||||
reportCurrentAccountFormula,
|
||||
reportPoolMaterialPendingNote,
|
||||
reportCostIdentity,
|
||||
reportPoolMaterialFormula,
|
||||
reportPoolMaterialSourceLabel,
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user