1865 lines
70 KiB
TypeScript
1865 lines
70 KiB
TypeScript
import type { ReactNode } from 'react';
|
||
import type * as T from './contracts';
|
||
import { Children } from 'react';
|
||
import { reportData } from './reportData';
|
||
const withKeys = Children.toArray;
|
||
const fallback = (rows: ReactNode[], empty: ReactNode) => (rows.length ? rows : empty);
|
||
const e = (value: unknown) => (value == null ? '' : String(value));
|
||
export function reportPresentation({
|
||
state,
|
||
session,
|
||
reportMonth,
|
||
reportMember,
|
||
onAction,
|
||
dailyFundsLoading = false,
|
||
}: T.ReportContext & { onAction: (data: T.ReportAction) => void; dailyFundsLoading?: boolean }) {
|
||
const model = reportData({ state, session, reportMonth, reportMember });
|
||
const {
|
||
reportSummaryAmount,
|
||
yuan,
|
||
reportPeriod,
|
||
reportActiveAccounts,
|
||
accountDisplayName,
|
||
teamMode,
|
||
reportDailyProfitAmount,
|
||
reimbursementStatusNames,
|
||
teamMemberName,
|
||
dailyFundsOwner,
|
||
dailyFundsMoney,
|
||
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,
|
||
} = model;
|
||
function renderReportContent(r: T.Report, range: T.Range) {
|
||
const s = r.summary,
|
||
receipts = r.receiptsByOrderDate,
|
||
profitMissing = s.unknownProfitCount || 0;
|
||
const countHints = [
|
||
`销售 ${s.orderCount} 单`,
|
||
`售后 ${s.afterSaleCount || 0} 笔`,
|
||
`${s.completedCount} 单完成`,
|
||
s.returnedCount ? `${s.returnedCount} 单退货` : '',
|
||
s.cancelledCount ? `${s.cancelledCount} 单取消` : '',
|
||
s.draftCount ? `${s.draftCount} 单旧草稿未计金额` : '',
|
||
]
|
||
.filter(Boolean)
|
||
.join(' · ');
|
||
const close = r.close,
|
||
closeStatus = reportMonth
|
||
? '月汇总显示月初至所选日的订单与售后;单日核对快照请取消“汇总当月”后保存。'
|
||
: close
|
||
? `${close.date} 已由${close.actor}保存快照。${close.stale ? close.staleReason || '之后有补录,请重新核对。' : '快照保留,不等于支付平台账单已核实。'}`
|
||
: '尚未保存所选日对账快照(含当日售后)。';
|
||
const top = (
|
||
<>
|
||
{renderReportOwnershipReceipts(r, range)}
|
||
<div className="cards report-cards">
|
||
{card('所选' + (reportMonth ? '月' : '日') + '销售净额', reportSummaryAmount(s, 'sale'), countHints)}
|
||
{card('本期实收', '¥' + yuan(receipts.receipt), '普通订单累计收款+本期锁价实收')}
|
||
{card('本期实退', '¥' + yuan(receipts.refund), '普通订单累计退款+本期锁价实退')}
|
||
{card(
|
||
'本期净利润' + (profitMissing ? '(已核算部分)' : ''),
|
||
reportSummaryAmount(s, 'profit'),
|
||
profitMissing
|
||
? profitMissing +
|
||
' 单利润待补齐' +
|
||
(r.pendingMaterialCount ? ',其中 ' + r.pendingMaterialCount + ' 单料费待补' : '')
|
||
: '销售净额 − 订单耗用成本 − 实际费用(含售后)',
|
||
true,
|
||
)}
|
||
</div>
|
||
<div className="report-primary">
|
||
<section className="panel report-accounts">
|
||
<h2>按收款账户核对</h2>
|
||
<p className="small muted">{reportPeriod(range)}普通订单当前收付,加上同期锁价实际收付。</p>
|
||
<div className="table-wrap">
|
||
<table aria-label="按收款账户核对">
|
||
<thead>
|
||
<tr>
|
||
<th>账户</th>
|
||
<th className="number">实收</th>
|
||
<th className="number">实退</th>
|
||
<th className="number">净额</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
{fallback(
|
||
withKeys(
|
||
reportActiveAccounts(r).map(a => (
|
||
<tr>
|
||
<td>{accountDisplayName(a.account)}</td>
|
||
<td className="number">¥{yuan(a.receipt)}</td>
|
||
<td className="number">¥{yuan(a.refund)}</td>
|
||
<td className="number">¥{yuan(a.net)}</td>
|
||
</tr>
|
||
)),
|
||
),
|
||
<tr>
|
||
<td colSpan={4} className="muted">
|
||
所选范围没有收退款活动账户。
|
||
</td>
|
||
</tr>,
|
||
)}
|
||
</tbody>
|
||
<tfoot>
|
||
<tr>
|
||
<td>合计</td>
|
||
<td className="number">¥{yuan(receipts.receipt)}</td>
|
||
<td className="number">¥{yuan(receipts.refund)}</td>
|
||
<td className="number">¥{yuan(receipts.net)}</td>
|
||
</tr>
|
||
</tfoot>
|
||
</table>
|
||
</div>
|
||
<p className="small muted report-cost-note">
|
||
请按这些订单的收退款记录与微信、支付宝、现金、信用卡核对;系统尚未接入支付平台账单。
|
||
</p>
|
||
</section>
|
||
{renderReportPayerCosts(r)}
|
||
</div>
|
||
</>
|
||
);
|
||
const rest = (
|
||
<>
|
||
<>
|
||
<>
|
||
<>
|
||
<>
|
||
{renderPriceLockActivity(r.priceLockActivity)}
|
||
{renderMaterialPoolActivity(r.materialPoolActivity)}
|
||
</>
|
||
{renderReportOrderNet(r, range)}
|
||
</>
|
||
{renderReportGlobal(r)}
|
||
</>
|
||
<section className="panel">
|
||
<div className="panel-title">
|
||
<h2>需要查看 {r.warnings.length} 项</h2>
|
||
<span className="small muted">截至现在所有订单,不受日期筛选</span>
|
||
</div>
|
||
{r.warnings.length ? (
|
||
<ul>
|
||
{withKeys(
|
||
r.warnings.map(w => (
|
||
<li>
|
||
{w.id ? (
|
||
<button
|
||
className="link-button"
|
||
data-action="open-order"
|
||
data-id={w.id}
|
||
onClick={event => onAction(event.currentTarget.dataset)}
|
||
>
|
||
{w.number}
|
||
</button>
|
||
) : (
|
||
''
|
||
)}
|
||
{w.message}
|
||
</li>
|
||
)),
|
||
)}
|
||
</ul>
|
||
) : (
|
||
<p className="ok">系统内未发现待补成本、待退款和待复核项。实际到账仍需核对。</p>
|
||
)}
|
||
<div className="form-actions">
|
||
<div className={'small ' + (close?.stale ? 'danger-text' : 'muted')}>{closeStatus}</div>
|
||
<div className="actions">
|
||
<button
|
||
type="button"
|
||
data-action="download-report"
|
||
className=""
|
||
onClick={event => onAction(event.currentTarget.dataset)}
|
||
>
|
||
{'下载对账报告'}
|
||
</button>
|
||
{state.user.role === 'owner' && !reportMonth ? (
|
||
<button
|
||
type="button"
|
||
data-action="close-day"
|
||
className="primary"
|
||
onClick={event => onAction(event.currentTarget.dataset)}
|
||
>
|
||
{'保存核对快照'}
|
||
</button>
|
||
) : (
|
||
''
|
||
)}
|
||
</div>
|
||
</div>
|
||
</section>
|
||
</>
|
||
{teamMode() ? (
|
||
''
|
||
) : (
|
||
<>
|
||
{renderReportUnsettled(r)}
|
||
{renderMaterialPoolGlobalSettlement(r.materialPoolSettlement)}
|
||
</>
|
||
)}
|
||
</>
|
||
);
|
||
return (
|
||
<>
|
||
{top}
|
||
{rest}
|
||
</>
|
||
);
|
||
}
|
||
|
||
function renderReportDailyProfits(r: T.Report) {
|
||
const table = r.dailyProfits,
|
||
amounts = (row: T.Profit) => (
|
||
<>
|
||
<td className="number">¥{yuan(row.sales)}</td>
|
||
<td className="number">{reportDailyProfitAmount(row.totalCost, row.knownTotalCost)}</td>
|
||
<td className={'number' + ((row.profit ?? row.knownProfit) < 0 ? ' danger-text' : '')}>
|
||
{reportDailyProfitAmount(row.profit, row.knownProfit, true)}
|
||
</td>
|
||
</>
|
||
);
|
||
return (
|
||
<section className="panel report-daily-profits" aria-label="每日利润表">
|
||
<h2>每日利润表</h2>
|
||
<p className="small muted">
|
||
{reportPeriod(table)} · 按日期、订单归属人核对。勾选“汇总当月”可查看当月逐日利润。
|
||
</p>
|
||
<div className="table-wrap">
|
||
<table aria-label="每日利润明细">
|
||
<thead>
|
||
<tr>
|
||
<th scope="col">日期</th>
|
||
<th scope="col">归属人</th>
|
||
<th scope="col" className="number">
|
||
销售净额
|
||
</th>
|
||
<th scope="col" className="number">
|
||
成本
|
||
</th>
|
||
<th scope="col" className="number">
|
||
利润
|
||
</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
{fallback(
|
||
withKeys(
|
||
table.rows.map(row => (
|
||
<tr data-date={row.date} data-member={row.member}>
|
||
<td>{row.date}</td>
|
||
<td>
|
||
{row.name}
|
||
<small className="muted">
|
||
销售 {row.orderCount} 单{row.afterSaleCount ? ' · 售后 ' + row.afterSaleCount + ' 笔' : ''}
|
||
{row.draftCount ? ' · 旧草稿 ' + row.draftCount + ' 单未计金额' : ''}
|
||
</small>
|
||
</td>
|
||
{amounts(row)}
|
||
</tr>
|
||
)),
|
||
),
|
||
<tr>
|
||
<td colSpan={5} className="muted">
|
||
所选范围暂无订单或售后记录。
|
||
</td>
|
||
</tr>,
|
||
)}
|
||
</tbody>
|
||
<tfoot>
|
||
<tr>
|
||
<td colSpan={2}>所选范围合计</td>
|
||
{amounts(table.summary)}
|
||
</tr>
|
||
</tfoot>
|
||
</table>
|
||
</div>
|
||
<p className="small muted report-daily-profit-note">
|
||
普通订单按开单日、锁价成单按交付日、售后按记录日归集。成本含实际耗用料费和费用;退货、作废沿原账冲回。
|
||
{table.summary.unknownProfitCount ? '待核算项目不按0计作完整利润,括号内仅为已核算部分。' : ''}
|
||
</p>
|
||
</section>
|
||
);
|
||
}
|
||
|
||
function renderReimbursementRows(data: T.DailyFunds, readOnly: boolean) {
|
||
return (
|
||
<div className="reimbursement-records">
|
||
{fallback(
|
||
withKeys(
|
||
data.reimbursements.map(row => (
|
||
<article className="reimbursement-record" data-id={row.id}>
|
||
<div className="reimbursement-record-heading">
|
||
<strong>
|
||
{row.date} · ¥{yuan(row.total)}
|
||
</strong>
|
||
<span
|
||
className={
|
||
'badge' + (row.status === 'rejected' ? ' danger' : row.status === 'pending' ? ' warn' : '')
|
||
}
|
||
>
|
||
{reimbursementStatusNames[row.status]}
|
||
</span>
|
||
</div>
|
||
<p className="small muted">
|
||
{row.requester_name || '提交人未提供'}提交
|
||
{row.payer ? ' · ' + teamMemberName(row.payer) + '实际付款' : ''}
|
||
{row.reviewer_name ? ' · ' + row.reviewer_name + '复核' : ''}
|
||
</p>
|
||
{renderReimbursementItems(row)}
|
||
{row.note ? <p className="small reimbursement-note">备注:{row.note}</p> : ''}
|
||
{row.review_note ? (
|
||
<p
|
||
className={'small ' + (row.status === 'rejected' ? 'danger-text' : 'muted') + ' reimbursement-note'}
|
||
>
|
||
{row.status === 'rejected' ? '驳回原因' : '复核备注'}:{row.review_note}
|
||
</p>
|
||
) : (
|
||
''
|
||
)}
|
||
{!readOnly ? (
|
||
<div className="actions">
|
||
{row.canEdit && row.status !== 'approved' ? (
|
||
<button
|
||
type="button"
|
||
data-action="reimbursement-edit"
|
||
className=""
|
||
data-id={row.id}
|
||
onClick={event => onAction(event.currentTarget.dataset)}
|
||
>
|
||
{row.status === 'rejected' ? '修改后重新提交' : '修改报销单'}
|
||
</button>
|
||
) : (
|
||
''
|
||
)}
|
||
{dailyFundsOwner() && row.canApprove && row.status === 'pending' ? (
|
||
<>
|
||
<button
|
||
type="button"
|
||
data-action="reimbursement-approve"
|
||
className="primary"
|
||
data-id={row.id}
|
||
onClick={event => onAction(event.currentTarget.dataset)}
|
||
>
|
||
{'复核通过'}
|
||
</button>
|
||
<button
|
||
type="button"
|
||
data-action="reimbursement-reject"
|
||
className=""
|
||
data-id={row.id}
|
||
onClick={event => onAction(event.currentTarget.dataset)}
|
||
>
|
||
{'驳回'}
|
||
</button>
|
||
</>
|
||
) : (
|
||
''
|
||
)}
|
||
</div>
|
||
) : (
|
||
''
|
||
)}
|
||
</article>
|
||
)),
|
||
),
|
||
<p className="small muted">所选日期暂无报销单。</p>,
|
||
)}
|
||
</div>
|
||
);
|
||
}
|
||
|
||
function renderDailyFundsMonth(data: T.DailyFunds) {
|
||
return (
|
||
<>
|
||
<p className="small muted">月汇总只读。按每张报销单的报销日期归集,跨日批准仍回到原日期。</p>
|
||
{data.missingDates.length ? (
|
||
<p className="small danger-text">待确认日期:{data.missingDates.map(e).join('、')}</p>
|
||
) : (
|
||
''
|
||
)}
|
||
{data.staleDates.length ? (
|
||
<p className="small danger-text">来源变动待重新确认:{data.staleDates.map(e).join('、')}</p>
|
||
) : (
|
||
''
|
||
)}
|
||
<div className="table-wrap">
|
||
<table className="daily-funds-month-table" aria-label="每日转账核对汇总">
|
||
<thead>
|
||
<tr>
|
||
<th>日期</th>
|
||
<th className="number">{teamMemberName('owner')}净收款</th>
|
||
<th className="number">确认支出</th>
|
||
<th className="number">批准报销</th>
|
||
<th className="number">应转合计</th>
|
||
<th>状态</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
{fallback(
|
||
withKeys(
|
||
data.days.map(day => (
|
||
<tr>
|
||
<td>
|
||
<button
|
||
type="button"
|
||
data-action="daily-funds-open-date"
|
||
className="link-button"
|
||
data-date={day.date}
|
||
onClick={event => onAction(event.currentTarget.dataset)}
|
||
>
|
||
{day.date}
|
||
</button>
|
||
</td>
|
||
<td className="number">¥{yuan(day.ownerReceipts.net)}</td>
|
||
<td className="number">{dailyFundsMoney(day.actualOutlay)}</td>
|
||
<td className="number">¥{yuan(day.approvedReimbursements)}</td>
|
||
<td className="number">{day.ready ? dailyFundsMoney(day.transferAmount) : '待确认'}</td>
|
||
<td>{day.ready ? '已确认' : day.confirmation?.stale ? '需重新确认' : '待确认'}</td>
|
||
</tr>
|
||
)),
|
||
),
|
||
<tr>
|
||
<td colSpan={6} className="muted">
|
||
所选范围暂无需核对的记录。可切换单日确认。
|
||
</td>
|
||
</tr>,
|
||
)}
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
</>
|
||
);
|
||
}
|
||
|
||
function renderDailyFundsSources(data: T.DailyFunds) {
|
||
return (
|
||
<details className="daily-funds-sources">
|
||
<summary>
|
||
已记录付款参考 ¥{yuan(data.sources.total)}{' '}
|
||
<span className="small muted">{data.sources.items.length} 笔,可能不完整</span>
|
||
</summary>
|
||
<p className="small muted">
|
||
只列{teamMemberName('owner')}
|
||
按真实付款日期记录的费用、日购料和锁价采购等;不把普通订单耗用成本当作当天付款。完整总额以店主核实为准。
|
||
</p>
|
||
<div className="table-wrap">
|
||
<table aria-label={'' + teamMemberName('owner') + '已记录实际付款参考'}>
|
||
<thead>
|
||
<tr>
|
||
<th>付款日期</th>
|
||
<th>项目/说明</th>
|
||
<th className="number">金额</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
{fallback(
|
||
withKeys(
|
||
data.sources.items.map(item => (
|
||
<tr>
|
||
<td>{item.date}</td>
|
||
<td>
|
||
{item.name}
|
||
{item.note ? <div className="small muted">{item.note}</div> : ''}
|
||
</td>
|
||
<td className="number">¥{yuan(item.amount)}</td>
|
||
</tr>
|
||
)),
|
||
),
|
||
<tr>
|
||
<td colSpan={3} className="muted">
|
||
暂无已记录付款;这不代表当天完整支出一定为 0。
|
||
</td>
|
||
</tr>,
|
||
)}
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
</details>
|
||
);
|
||
}
|
||
|
||
function renderDailyTransferResult(data: T.DailyFunds, month = false) {
|
||
const ready = data.ready && !dailyFundsLoading;
|
||
const direction =
|
||
(data.transferAmount ?? 0) > 0
|
||
? teamMemberName('owner') + '转' + teamMemberName('assistant')
|
||
: (data.transferAmount ?? 0) < 0
|
||
? teamMemberName('assistant') + '转' + teamMemberName('owner')
|
||
: '无需转款';
|
||
return (
|
||
<>
|
||
<div className="daily-transfer-parts">
|
||
<div>
|
||
<span>{teamMemberName('owner')}净收款</span>
|
||
<strong>¥{yuan(data.ownerReceipts.net)}</strong>
|
||
<small>
|
||
实收 ¥{yuan(data.ownerReceipts.receipt)} − 实退 ¥{yuan(data.ownerReceipts.refund)}
|
||
</small>
|
||
</div>
|
||
<div>
|
||
<span>确认的完整对外支出</span>
|
||
<strong>{dailyFundsMoney(ready ? data.actualOutlay : null)}</strong>
|
||
<small>
|
||
{ready ? '店主已核实' : data.confirmation?.stale ? '来源变动,需重新确认' : '由店主核对后确认'}
|
||
</small>
|
||
</div>
|
||
<div>
|
||
<span>已批准报销</span>
|
||
<strong>¥{yuan(data.approvedReimbursements)}</strong>
|
||
<small>按报销日期归集</small>
|
||
</div>
|
||
</div>
|
||
{ready ? (
|
||
<div className="daily-transfer-result" aria-label={'' + (month ? '本期' : '本日') + '应转合计'}>
|
||
<span>
|
||
{month ? '本期' : '本日'}应转合计 · {direction}
|
||
</span>
|
||
<strong>¥{yuan(Math.abs(data.transferAmount ?? 0))}</strong>
|
||
<p>
|
||
{teamMemberName('owner')}净收款 ¥{yuan(data.ownerReceipts.net)} − 确认对外支出 ¥{yuan(data.actualOutlay)}{' '}
|
||
+ 已批准报销 ¥{yuan(data.approvedReimbursements)} = <b>¥{yuan(data.transferAmount)}</b>
|
||
</p>
|
||
<small>此为{month ? '所选范围' : '所选日'}应转合计,未扣已转;不要与下方旧按单/剩料待结重复相加。</small>
|
||
</div>
|
||
) : (
|
||
<p className="note daily-transfer-unready">
|
||
{dailyFundsLoading
|
||
? '正在重新读取,暂不显示应转合计。'
|
||
: month
|
||
? '还有日期未完成支出确认,暂不显示完整应转合计。'
|
||
: '当天完整支出尚未确认,暂不显示应转合计。'}
|
||
</p>
|
||
)}
|
||
</>
|
||
);
|
||
}
|
||
|
||
function renderReimbursementItems(row: T.Reimbursement) {
|
||
return (
|
||
<ul className="reimbursement-items-read">
|
||
{withKeys(
|
||
row.items.map(item => (
|
||
<li>
|
||
<span>
|
||
{item.name}
|
||
{item.member ? (
|
||
<small className="muted">
|
||
{' '}
|
||
· {teamMemberName(item.member)}承担
|
||
{item.availableAmount == null ? '' : ' · 可用 ¥' + yuan(item.availableAmount)}
|
||
</small>
|
||
) : (
|
||
''
|
||
)}
|
||
</span>
|
||
<b>¥{yuan(item.amount)}</b>
|
||
</li>
|
||
)),
|
||
)}
|
||
</ul>
|
||
);
|
||
}
|
||
|
||
function renderReportOwnershipReceipts(r: T.Report, range: T.Range) {
|
||
const keys = reportOwnershipKeys(r);
|
||
return (
|
||
<section className="report-receipts report-ownership-receipts" aria-label="按订单归属汇总净收入">
|
||
<p className="small muted report-receipt-scope">
|
||
{reportPeriod(range)}:所属订单净收入=收款−退款,已包含他人代收。成本含售后,料池仅计已耗用部分;
|
||
{teamMemberName('owner')}垫付和当日往来逐日核对。
|
||
</p>
|
||
<div className="report-recipient-grid">
|
||
{keys.length ? (
|
||
withKeys(
|
||
keys.map(key => {
|
||
const person = r.ownershipReceipts[key],
|
||
details = {
|
||
...person,
|
||
name: person.name + '所属订单',
|
||
};
|
||
return (
|
||
<article
|
||
className="panel report-recipient report-ownership-recipient"
|
||
data-member={key}
|
||
aria-labelledby={'report-ownership-' + key + '-title'}
|
||
>
|
||
<header className="report-recipient-summary">
|
||
<h2 id={'report-ownership-' + key + '-title'}>{person.name}所属订单净收入</h2>
|
||
<div className="report-recipient-total">¥{yuan(person.net)}</div>
|
||
<p className="report-recipient-net">
|
||
<span>实收 ¥{yuan(person.receipt)}</span>
|
||
<span>实退 ¥{yuan(person.refund)}</span>
|
||
</p>
|
||
</header>
|
||
{person.items.length ? renderReportOwnershipAccounts(person) : ''}
|
||
{renderReportOwnershipBusiness(r.ownershipBusiness[key], range)}
|
||
{person.items.length ? (
|
||
<>
|
||
{renderReportRecipientDetails(details)}
|
||
{person.items.some(item => item.kind === 'refund')
|
||
? renderReportRecipientDetails(details, 'refund')
|
||
: ''}
|
||
</>
|
||
) : (
|
||
<p className="small muted report-ownership-empty">所选范围暂无收退款记录。</p>
|
||
)}
|
||
</article>
|
||
);
|
||
}),
|
||
)
|
||
) : (
|
||
<div className="panel report-ownership-empty">
|
||
<p className="muted">所选范围暂无所属订单收入、成本或当日往来记录。</p>
|
||
</div>
|
||
)}
|
||
</div>
|
||
</section>
|
||
);
|
||
}
|
||
|
||
const card = (title: ReactNode, value: ReactNode, hint: ReactNode = '', emphasis = false) => (
|
||
<div className={'stat ' + (emphasis ? 'emphasis' : '')}>
|
||
<small>{title}</small>
|
||
<strong>{value}</strong>
|
||
<div className="hint">{hint}</div>
|
||
</div>
|
||
);
|
||
|
||
function renderReportPayerCosts(r: T.Report) {
|
||
const 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);
|
||
return (
|
||
<section className="panel report-costs">
|
||
<h2>按付款人核对成本</h2>
|
||
<p className="small muted">
|
||
普通订单按开单日归集;每日购料按实际购买日期归集,订单耗用料费不再计一次支出;锁价料费、工费与费用按实际付款日归集,原锁料费不在交付时重复计入。实际支出可能与本期订单耗用成本不同。转账请以核实后的完整实际支出为准。
|
||
</p>
|
||
<div className="table-wrap">
|
||
<table className="report-payer-table" aria-label={'助理与' + teamMemberName('owner') + '支出成本'}>
|
||
<thead>
|
||
<tr>
|
||
<th>付款人</th>
|
||
<th className="number">货品成本</th>
|
||
<th className="number">已付费用</th>
|
||
<th className="number">支出合计</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
{withKeys(
|
||
people.map(c => (
|
||
<tr>
|
||
<td>
|
||
<strong>{c.name}支出成本</strong>
|
||
{reportPayerHints(c) ? <div className="small danger-text">{reportPayerHints(c)}</div> : ''}
|
||
</td>
|
||
<td className="number">{reportCostAmount(c.goods, c.missingCount)}</td>
|
||
<td className="number">
|
||
¥{yuan(c.paidFees)}
|
||
{reportAfterSaleHint(c)}
|
||
</td>
|
||
<td className="number report-cost-total">
|
||
{reportCostAmount(c.total, c.missingCount + c.pendingCount)}
|
||
</td>
|
||
</tr>
|
||
)),
|
||
)}
|
||
</tbody>
|
||
<tfoot>
|
||
<tr>
|
||
<td>合计</td>
|
||
<td className="number">{reportCostAmount(r.outlayGoods ?? r.goods, missing)}</td>
|
||
<td className="number">
|
||
¥{yuan(r.outlayExpense ?? r.expense)}
|
||
{r.summary.afterSaleCount ? (
|
||
<div className="small muted">
|
||
其中售后 ¥{yuan(people.reduce((sum, c) => sum + reportAfterSaleAmount(c), 0))}
|
||
</div>
|
||
) : (
|
||
''
|
||
)}
|
||
</td>
|
||
<td className="number">{reportCostAmount(r.outlayTotal ?? r.goods + r.expense, missing + pending)}</td>
|
||
</tr>
|
||
</tfoot>
|
||
</table>
|
||
</div>
|
||
{withKeys(people.map(reportCostDetails))}
|
||
<p className="small muted report-cost-note">
|
||
普通订单按开单日期、售后按记录日期归集;每日购料按购买日期、锁价支出按实际付款日。旧草稿与未入账费用不计合计;退货冲回订单耗用成本,锁价已经支付的金料款仍保留。0元货品分项省略,已核实的0元费用保留。
|
||
</p>
|
||
</section>
|
||
);
|
||
}
|
||
|
||
function renderPriceLockActivity(activity: T.PriceActivity | null) {
|
||
if (!activity?.summary?.eventCount) return '';
|
||
const s = activity.summary,
|
||
rows = priceLockActivityRows(activity);
|
||
return (
|
||
<section className="panel lock-activity">
|
||
<h2>锁价实际收付</h2>
|
||
<p className="small muted">
|
||
{activity.from === activity.date ? activity.date : activity.from + ' 至 ' + activity.date}
|
||
实际发生的锁价收退款与支出。此区不随订单搜索或状态筛选变化;每日对账归集这些收付。待交付不计销售和利润;交付日计入完整订单利润,原锁料款不重复记支出。
|
||
</p>
|
||
<div className="lock-activity-summary">
|
||
<span>
|
||
客户实收<strong>¥{yuan(s.receipt)}</strong>
|
||
</span>
|
||
<span>
|
||
客户实退<strong>¥{yuan(s.refund)}</strong>
|
||
</span>
|
||
<span>
|
||
{teamMemberName('owner')}实际支出<strong>¥{yuan(s.ownerOutlay)}</strong>
|
||
</span>
|
||
<span>
|
||
{teamMemberName('assistant')}实际支出<strong>¥{yuan(s.assistantOutlay)}</strong>
|
||
</span>
|
||
</div>
|
||
<details>
|
||
<summary>查看 {rows.length} 项收付记录</summary>
|
||
<div className="table-wrap">
|
||
<table className="lock-activity-table">
|
||
<thead>
|
||
<tr>
|
||
<th>日期/锁价单</th>
|
||
<th>项目/客户</th>
|
||
<th>账户/付款人</th>
|
||
<th className="number">金额</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
{withKeys(
|
||
rows.map(item => (
|
||
<tr>
|
||
<td>
|
||
{item.date}
|
||
<br />
|
||
<button
|
||
className="link-button"
|
||
data-action="open-price-lock"
|
||
data-id={item.price_lock_id}
|
||
onClick={event => onAction(event.currentTarget.dataset)}
|
||
>
|
||
{item.number || '锁价记录'}
|
||
</button>
|
||
</td>
|
||
<td>
|
||
{item.activityType} · {item.activityName}
|
||
<div className="small muted">{item.customer}</div>
|
||
</td>
|
||
<td>{item.who}</td>
|
||
<td className="number">{item.amount == null ? '待补齐' : '¥' + yuan(item.amount)}</td>
|
||
</tr>
|
||
)),
|
||
)}
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
</details>
|
||
</section>
|
||
);
|
||
}
|
||
|
||
function renderMaterialPoolActivity(activity: T.PoolActivity | null) {
|
||
if (!activity?.purchases?.length) return '';
|
||
return (
|
||
<section className="panel material-report-activity">
|
||
<h2>本期实际购料</h2>
|
||
<p className="small muted">
|
||
按实际购买日期计支出,与下方订单耗用成本分别核对;本表金额已包含在上方双方实际支出中。
|
||
</p>
|
||
<div className="table-wrap">
|
||
<table className="material-detail-table">
|
||
<thead>
|
||
<tr>
|
||
<th>购料日期</th>
|
||
<th className="number">购买克重</th>
|
||
<th className="number">实际总价</th>
|
||
<th>付款人</th>
|
||
<th>备注</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
{withKeys(
|
||
activity.purchases.map(item => (
|
||
<tr>
|
||
<td>
|
||
<button
|
||
className="link-button"
|
||
data-action="goto-material-pools"
|
||
data-id={item.pool_id}
|
||
onClick={event => onAction(event.currentTarget.dataset)}
|
||
>
|
||
{item.date}
|
||
</button>
|
||
</td>
|
||
<td className="number">{grams(item.mg)}g</td>
|
||
<td className="number">¥{yuan(item.amount)}</td>
|
||
<td>{materialPayerName(materialPurchasePayer(item))}</td>
|
||
<td>{item.note}</td>
|
||
</tr>
|
||
)),
|
||
)}
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
</section>
|
||
);
|
||
}
|
||
|
||
function renderReportOrderNet(r: T.Report, range: T.Range) {
|
||
const s = r.summary;
|
||
return (
|
||
<section className="panel report-order-net">
|
||
<h2>订单与售后净额明细</h2>
|
||
<p className="small muted">
|
||
{reportPeriod(range)}
|
||
范围内,普通订单按开单日、锁价成单按交付日、售后按记录日期归集。这里显示订单完整耗用成本,与上方实际付款分开核对;旧草稿不计金额。
|
||
</p>
|
||
<div className="table-wrap">
|
||
<table className="report-order-table" aria-label="订单与售后净额明细">
|
||
<thead>
|
||
<tr>
|
||
<th>日期/单号或售后项目</th>
|
||
<th>类型/状态</th>
|
||
<th className="number">销售净额</th>
|
||
<th className="number">货品成本</th>
|
||
<th className="number">已付费用</th>
|
||
<th className="number">成本合计</th>
|
||
<th className="number">订单净利润</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
{fallback(
|
||
withKeys(
|
||
r.orderRows.map(row => (
|
||
<tr>
|
||
<td>
|
||
{row.date}
|
||
<br />
|
||
{orderBookIdentity(row)}
|
||
{row.kind === 'afterSale' ? (
|
||
<div className="small muted">{afterSalePayerName(row)}支付</div>
|
||
) : (
|
||
''
|
||
)}
|
||
{row.costHint ? <div className="small muted">{row.costHint}</div> : ''}
|
||
</td>
|
||
<td>{badge(row)}</td>
|
||
{withKeys(
|
||
(['sale', 'goods', 'paidFees', 'totalCost', 'profit'] as const).map(key => (
|
||
<td className="number">{reportRowAmount(row, key)}</td>
|
||
)),
|
||
)}
|
||
</tr>
|
||
)),
|
||
),
|
||
<tr>
|
||
<td colSpan={7} className="muted">
|
||
所选日期没有订单或售后记录。
|
||
</td>
|
||
</tr>,
|
||
)}
|
||
</tbody>
|
||
<tfoot>
|
||
<tr>
|
||
<td colSpan={2}>
|
||
销售 {s.orderCount} 单 · 售后 {s.afterSaleCount || 0} 笔
|
||
</td>
|
||
<td className="number">{reportSummaryAmount(s, 'sale')}</td>
|
||
<td className="number">{reportCostAmount(r.goods, s.missingCosts)}</td>
|
||
<td className="number">¥{yuan(r.expense)}</td>
|
||
<td className="number">{reportSummaryAmount(s, 'totalCost')}</td>
|
||
<td className="number">{reportSummaryAmount(s, 'profit')}</td>
|
||
</tr>
|
||
</tfoot>
|
||
</table>
|
||
</div>
|
||
</section>
|
||
);
|
||
}
|
||
|
||
function renderReportGlobal(r: T.Report) {
|
||
if (teamMode())
|
||
return (
|
||
<section className="panel">
|
||
<h2>客户待收款与库存</h2>
|
||
<p>
|
||
客户待收款 <strong>¥{yuan(r.customerBalance)}</strong>
|
||
</p>
|
||
<div className="grid three">
|
||
{withKeys(
|
||
r.inventory.map(i => (
|
||
<div>
|
||
{pocketLabel(i.pocket)} <strong>{grams(i.mg)}g</strong>
|
||
{renderInventoryBalanceCount(i)}
|
||
</div>
|
||
)),
|
||
)}
|
||
</div>
|
||
</section>
|
||
);
|
||
return (
|
||
<div className="split report-secondary">
|
||
<section className="panel">
|
||
<h2>截至现在的未结事项</h2>
|
||
<p className="small muted">所有订单的当前未结情况,不受上方日期筛选。</p>
|
||
<p>
|
||
客户待收款:<strong>¥{yuan(r.customerBalance)}</strong>
|
||
</p>
|
||
<p>
|
||
{r.materialPoolSettlement ? '订单与剩余料款' : '所有订单'}待结算净额:
|
||
<strong>
|
||
{r.settlementDue == null
|
||
? '料费待补(已核算部分 ¥' + yuan(r.knownSettlementDue) + ')'
|
||
: '¥' + yuan(r.settlementDue)}
|
||
</strong>
|
||
</p>
|
||
<div className="note">净额仅供总览,不把不同订单的返款与交款互相抵扣。货款按单交,利润月底交。</div>
|
||
</section>
|
||
<section className="panel">
|
||
<h2>{r.date} 账面库存</h2>
|
||
<p className="small muted">
|
||
按所选日及此前的库存流水计算;月汇总仍显示所选日库存。已复核历史值从库存页每日快照查询。
|
||
</p>
|
||
<div className="grid two">
|
||
{withKeys(
|
||
r.inventory.map(i => (
|
||
<div>
|
||
{pocketLabel(i.pocket)} <strong>{grams(i.mg)}g</strong>
|
||
{renderInventoryBalanceCount(i)}
|
||
</div>
|
||
)),
|
||
)}
|
||
</div>
|
||
</section>
|
||
</div>
|
||
);
|
||
}
|
||
|
||
function renderReportUnsettled(r: T.Report) {
|
||
return (
|
||
<section className="panel report-unsettled">
|
||
<h2>逐单交款与返款(截至现在)</h2>
|
||
<p className="small muted">
|
||
所有订单,不受日期筛选。负数表示{teamMemberName('owner')}需转回{teamMemberName('assistant')}。含
|
||
{teamMemberName('owner')}直收款的订单,先复核货款与利润归属。
|
||
</p>
|
||
<div className="table-wrap">
|
||
<table>
|
||
<thead>
|
||
<tr>
|
||
<th>订单</th>
|
||
<th className="number">货款待结</th>
|
||
<th className="number">利润待结</th>
|
||
<th className="number">{teamMemberName('owner')}直收净额</th>
|
||
<th className="number">总待结</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
{fallback(
|
||
withKeys(
|
||
r.unsettled.map(o => (
|
||
<tr>
|
||
<td>
|
||
<button
|
||
className="link-button"
|
||
data-action="open-order"
|
||
data-id={o.id}
|
||
onClick={event => onAction(event.currentTarget.dataset)}
|
||
>
|
||
{o.number}
|
||
</button>
|
||
</td>
|
||
<td className="number">{materialReportMoney(o.costDue)}</td>
|
||
<td className="number">{materialReportMoney(o.profitDue)}</td>
|
||
<td className="number">¥{yuan(o.ownerDirect)}</td>
|
||
<td className="number">{materialReportMoney(o.total)}</td>
|
||
</tr>
|
||
)),
|
||
),
|
||
<tr>
|
||
<td colSpan={5}>目前没有待结款项。</td>
|
||
</tr>,
|
||
)}
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
</section>
|
||
);
|
||
}
|
||
|
||
function renderMaterialPoolGlobalSettlement(value: T.PoolSettlement | null) {
|
||
if (!value?.pools?.length) return '';
|
||
return (
|
||
<section className="panel material-report-settlement">
|
||
<h2>剩余料款与{teamMemberName('assistant')}结算(截至现在)</h2>
|
||
<p className="small muted">
|
||
{teamMemberName('assistant')}垫付的未耗用材料单独核对;耗用后按订单分摊,避免在订单与剩余料款重复结算。
|
||
</p>
|
||
<div className="table-wrap">
|
||
<table className="material-detail-table">
|
||
<thead>
|
||
<tr>
|
||
<th>购料日期</th>
|
||
<th className="number">{teamMemberName('assistant')}垫付的剩余料款</th>
|
||
<th className="number">实际已交净额</th>
|
||
<th className="number">本批料款待结</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
{withKeys(
|
||
value.pools.map(item => (
|
||
<tr>
|
||
<td>
|
||
<button
|
||
className="link-button"
|
||
data-action="goto-material-pools"
|
||
data-id={item.id}
|
||
onClick={event => onAction(event.currentTarget.dataset)}
|
||
>
|
||
{item.date}
|
||
</button>
|
||
</td>
|
||
<td className="number">{materialReportMoney(item.assistantInventoryCredit)}</td>
|
||
<td className="number">¥{yuan(item.transferred)}</td>
|
||
<td className="number">
|
||
{materialReportMoney(item.settlementDue)}
|
||
{(item.settlementDue ?? 0) < 0 ? (
|
||
<>
|
||
<>
|
||
<>
|
||
<>
|
||
<div className="small muted"></div>
|
||
{teamMemberName('owner')}
|
||
</>
|
||
{' → '}
|
||
</>
|
||
{teamMemberName('assistant')}
|
||
</>
|
||
{'</div>'}
|
||
</>
|
||
) : (item.settlementDue ?? 0) > 0 ? (
|
||
<>
|
||
<>
|
||
<>
|
||
<>
|
||
<div className="small muted"></div>
|
||
{teamMemberName('assistant')}
|
||
</>
|
||
{' → '}
|
||
</>
|
||
{teamMemberName('owner')}
|
||
</>
|
||
{'</div>'}
|
||
</>
|
||
) : (
|
||
''
|
||
)}
|
||
</td>
|
||
</tr>
|
||
)),
|
||
)}
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
<p
|
||
className="small muted"
|
||
style={{
|
||
margin: '12px 0 0',
|
||
}}
|
||
>
|
||
正数为{teamMemberName('assistant')}交{teamMemberName('owner')},负数为{teamMemberName('owner')}转回
|
||
{teamMemberName('assistant')};进入对应日期核对并登记实际交款。
|
||
</p>
|
||
</section>
|
||
);
|
||
}
|
||
|
||
function renderReportOwnershipAccounts(person: T.OwnershipReceipts) {
|
||
const ownAccounts = person.accounts.filter(account => account.recipient === person.member),
|
||
otherAccounts = person.accounts.filter(account => account.recipient !== person.member),
|
||
net = (accounts: T.Account[]) => accounts.reduce((total, account) => total + account.net, 0);
|
||
const group = (title: string, rows: T.Account[]) => (
|
||
<section className="report-ownership-account-group">
|
||
<h3>{title}</h3>
|
||
{rows.length ? (
|
||
<ul>
|
||
{withKeys(
|
||
rows.map(account => (
|
||
<li>
|
||
<div>
|
||
<span>{accountDisplayName(account.account)}</span>
|
||
<small>
|
||
实收 ¥{yuan(account.receipt)} · 实退 ¥{yuan(account.refund)}
|
||
</small>
|
||
</div>
|
||
<strong>¥{yuan(account.net)}</strong>
|
||
</li>
|
||
)),
|
||
)}
|
||
</ul>
|
||
) : (
|
||
<p className="small muted">本期暂无记录。</p>
|
||
)}
|
||
</section>
|
||
);
|
||
return (
|
||
<>
|
||
<p className="report-ownership-equation">
|
||
<span>
|
||
本人收款净额 <b>¥{yuan(net(ownAccounts))}</b>
|
||
</span>
|
||
<span aria-hidden="true">+</span>
|
||
<span>
|
||
{otherAccounts.length === 1 ? accountDisplayName(otherAccounts[0].account) + '代收' : '他人代收'}净额{' '}
|
||
<b>¥{yuan(net(otherAccounts))}</b>
|
||
</span>
|
||
<span aria-hidden="true">=</span>
|
||
<strong>¥{yuan(person.net)}</strong>
|
||
</p>
|
||
<div className="report-ownership-accounts">
|
||
{group('本人收款', ownAccounts)}
|
||
{group('他人代收', otherAccounts)}
|
||
</div>
|
||
</>
|
||
);
|
||
}
|
||
|
||
function renderReportOwnershipBusiness(business: T.Business, range: T.Range) {
|
||
return (
|
||
<>
|
||
<>
|
||
<>
|
||
{renderReportOwnershipCost(business)}
|
||
{renderReportOwnerAdvances(business)}
|
||
</>
|
||
{renderReportOwnershipProfit(business, range)}
|
||
</>
|
||
{renderReportOwnershipCurrentAccount(business)}
|
||
</>
|
||
);
|
||
}
|
||
|
||
function renderReportRecipientDetails(person: T.MemberReceipts, kind: 'receipt' | 'refund' = 'receipt') {
|
||
const items = person.items.filter(item => item.kind === kind),
|
||
name = kind === 'receipt' ? '收款' : '退款';
|
||
return (
|
||
<details className="report-receipt-detail">
|
||
<summary aria-label={person.name + name + '明细'}>
|
||
{name}明细{' '}
|
||
<span className="small muted">
|
||
{items.length} 笔{items.some(item => item.amount < 0) ? ',含冲回' : ''}
|
||
</span>
|
||
</summary>
|
||
<div className="table-wrap" tabIndex={0} role="region" aria-label={person.name + name + '明细表'}>
|
||
<table className="report-receipt-table" aria-label={person.name + name + '逐笔明细'}>
|
||
<thead>
|
||
<tr>
|
||
<th>实际{name}日/归集口径</th>
|
||
<th>订单/客户</th>
|
||
<th>{name}账户/说明</th>
|
||
<th className="number">金额</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
{fallback(
|
||
withKeys(
|
||
items.map(item => (
|
||
<tr className={item.amount < 0 ? 'report-receipt-reversal' : undefined}>
|
||
<td>
|
||
{item.date}
|
||
<div className="small muted">{reportReceiptBasis(item)}</div>
|
||
</td>
|
||
<td>{renderReportReceiptIdentity(item)}</td>
|
||
<td>
|
||
{accountDisplayName(item.account)}
|
||
<div className={'small' + (item.amount < 0 ? ' danger-text' : ' muted')}>
|
||
{reportReceiptLabel(item)}
|
||
</div>
|
||
{item.reference || item.note ? (
|
||
<div className="small muted report-receipt-note">{item.reference || item.note}</div>
|
||
) : (
|
||
''
|
||
)}
|
||
</td>
|
||
<td className={'number' + (item.amount < 0 ? ' danger-text' : '')}>¥{yuan(item.amount)}</td>
|
||
</tr>
|
||
)),
|
||
),
|
||
<tr>
|
||
<td colSpan={4} className="muted">
|
||
所选范围没有{person.name}
|
||
{name}记录。
|
||
</td>
|
||
</tr>,
|
||
)}
|
||
</tbody>
|
||
<tfoot>
|
||
<tr>
|
||
<td colSpan={3}>{name}明细合计</td>
|
||
<td className="number">¥{yuan(person[kind])}</td>
|
||
</tr>
|
||
</tfoot>
|
||
</table>
|
||
</div>
|
||
</details>
|
||
);
|
||
}
|
||
|
||
function reportAfterSaleHint(cost: T.PayerCosts) {
|
||
return cost.items.some(item => item.kind === 'afterSale') ? (
|
||
<div className="small muted">其中售后 ¥{yuan(reportAfterSaleAmount(cost))}</div>
|
||
) : (
|
||
''
|
||
);
|
||
}
|
||
|
||
function reportCostDetails(cost: T.PayerCosts) {
|
||
const items = reportCostItems(cost);
|
||
return (
|
||
<details className="report-cost-detail">
|
||
<summary>
|
||
{cost.name}逐项明细{' '}
|
||
<span className="small muted">
|
||
{items.length} 项{cost.pendingCount ? ',含未入账项目' : ''}
|
||
</span>
|
||
</summary>
|
||
<div className="table-wrap">
|
||
<table className="report-cost-detail-table" aria-label={'' + cost.name + '支出成本逐项明细'}>
|
||
<thead>
|
||
<tr>
|
||
<th>日期/单号或客户</th>
|
||
<th>成本项目/来源</th>
|
||
<th className="number">金额</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
{fallback(
|
||
withKeys(
|
||
items.map(item => (
|
||
<tr className={item.kind === 'pending' ? 'report-pending-cost' : undefined}>
|
||
<td>
|
||
{item.date}
|
||
<br />
|
||
{materialReportCostLink(item)}
|
||
</td>
|
||
<td>
|
||
{item.name}
|
||
<div className="small muted">{item.source}</div>
|
||
{item.calculation ? <div className="small muted">{reportCostFormula(item)}</div> : ''}
|
||
{item.kind === 'pending' ? <div className="small danger-text">未计入实际成本与合计</div> : ''}
|
||
</td>
|
||
<td className={'number' + (item.amount == null || item.kind === 'pending' ? ' danger-text' : '')}>
|
||
{item.kind === 'pending' ? (
|
||
<>
|
||
{'未入账'}
|
||
{item.amount == null ? (
|
||
<div className="small">金额待补</div>
|
||
) : (
|
||
<>
|
||
<>
|
||
<div className="small muted">登记 ¥</div>
|
||
{yuan(item.amount)}
|
||
</>
|
||
{'</div>'}
|
||
</>
|
||
)}
|
||
</>
|
||
) : (
|
||
reportCostItemAmount(item)
|
||
)}
|
||
</td>
|
||
</tr>
|
||
)),
|
||
),
|
||
<tr>
|
||
<td colSpan={3} className="muted">
|
||
没有需逐项核对的成本。货品成本为 0 的分项已省略。
|
||
</td>
|
||
</tr>,
|
||
)}
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
</details>
|
||
);
|
||
}
|
||
|
||
function orderBookIdentity(row: T.Row, version?: string) {
|
||
if (row.kind === 'orderAfterSale')
|
||
return (
|
||
<button
|
||
className="link-button order-book-link order-book-customer-first"
|
||
data-action="open-order"
|
||
data-id={row.order_id || row.id}
|
||
onClick={event => onAction(event.currentTarget.dataset)}
|
||
>
|
||
<strong className="order-book-customer-name">{row.customer || '未填称呼'}</strong>
|
||
<span className="order-book-secondary muted">订单售后 · {row.paper_number || row.number}</span>
|
||
<span className="small muted">查看原单售后结果</span>
|
||
</button>
|
||
);
|
||
if (row.kind === 'recovery')
|
||
return (
|
||
<>
|
||
<button
|
||
className="link-button order-book-link order-book-customer-first"
|
||
data-action="recovery-open"
|
||
data-id={row.recovery_id || row.id}
|
||
onClick={event => onAction(event.currentTarget.dataset)}
|
||
>
|
||
<span className="order-book-identity-line">
|
||
<strong className="order-book-customer-name">{row.customer || '未填称呼'}</strong>
|
||
<span className="order-book-recovery-badge">回收</span>
|
||
</span>
|
||
<span className="order-book-secondary muted">{row.number}</span>
|
||
<span className="order-book-recovery-payment">回收付款 ¥{yuan(row.cashPayment)}</span>
|
||
</button>
|
||
<button
|
||
type="button"
|
||
data-action="recovery-print"
|
||
className="quiet order-book-recovery-print"
|
||
data-id={row.recovery_id || row.id}
|
||
aria-label={'打印 ' + (row.customer || '客户') + ' 的回收单'}
|
||
onClick={event => onAction(event.currentTarget.dataset)}
|
||
>
|
||
{'打印'}
|
||
</button>
|
||
</>
|
||
);
|
||
if (version !== undefined) {
|
||
const name = <strong className="order-book-customer-name">{row.customer || '未填称呼'}</strong>;
|
||
const customer =
|
||
row.recovery_mode === 'exchange' ? (
|
||
<span className="order-book-identity-line">
|
||
{name}
|
||
<span className="order-book-recovery-badge is-exchange">置换</span>
|
||
</span>
|
||
) : (
|
||
name
|
||
);
|
||
if (row.kind === 'afterSale')
|
||
return (
|
||
<div className="after-sale-identity order-book-customer-first">
|
||
{customer}
|
||
<span className="order-book-secondary muted">售后 · {row.project || row.note}</span>
|
||
{afterSaleEditButton(row)}
|
||
</div>
|
||
);
|
||
return (
|
||
<button
|
||
className="link-button order-book-link order-book-customer-first"
|
||
data-action="open-order"
|
||
data-id={row.id}
|
||
data-order-book-version={version}
|
||
onClick={event => onAction(event.currentTarget.dataset)}
|
||
>
|
||
{customer}
|
||
<span className="order-book-secondary muted">{row.paper_number || row.number}</span>
|
||
</button>
|
||
);
|
||
}
|
||
if (row.kind === 'afterSale')
|
||
return (
|
||
<div className="after-sale-identity">
|
||
<strong>售后 · {row.project || row.note}</strong>
|
||
<span>{row.customer}</span>
|
||
{afterSaleEditButton(row)}
|
||
</div>
|
||
);
|
||
return (
|
||
<button
|
||
className="link-button order-book-link"
|
||
data-action="open-order"
|
||
data-id={row.id}
|
||
data-order-book-version={version}
|
||
onClick={event => onAction(event.currentTarget.dataset)}
|
||
>
|
||
<strong>{row.paper_number || row.number}</strong>
|
||
<span>{row.customer || '未填称呼'}</span>
|
||
</button>
|
||
);
|
||
}
|
||
|
||
const badge = (o: T.Row) => (
|
||
<span className={'order-status ' + (['draft', 'confirmed'].includes(o.status) ? 'danger-text' : 'muted')}>
|
||
{label[o.status] || o.status}
|
||
</span>
|
||
);
|
||
|
||
function renderInventoryBalanceCount(item: T.InventoryBalance) {
|
||
return item?.countUnit === 'pair' || pocketCountsEnabled(item?.pocket) ? (
|
||
<div className="stock-count-number">{stockCountText(item?.count)}</div>
|
||
) : (
|
||
''
|
||
);
|
||
}
|
||
|
||
function renderReportOwnershipCost(business: T.Business) {
|
||
const showPayers = business.knownTotalCost !== 0 || business.totalCost === null,
|
||
others = teamMemberKeys()
|
||
.filter(key => key !== business.member)
|
||
.map(key => business.costByPayer[key])
|
||
.filter(payer => payer.knownTotalCost !== 0 || payer.totalCost === null);
|
||
return (
|
||
<section className="report-business-cost" aria-label={'' + business.name + '所属订单成本'}>
|
||
<div className="report-business-heading">
|
||
<h3>
|
||
所属订单总成本
|
||
{business.afterSaleCount ? <span className="small muted">含售后 {business.afterSaleCount} 笔</span> : ''}
|
||
</h3>
|
||
<strong>{reportBusinessAmount(business.totalCost, business.knownTotalCost)}</strong>
|
||
{business.totalCost === null ? <span className="badge warn">成本待补齐</span> : ''}
|
||
</div>
|
||
{renderReportPoolMaterial(business)}
|
||
{showPayers ? (
|
||
<div className="report-business-paid">
|
||
<span>
|
||
本人付款 <b>{reportBusinessAmount(business.selfCost, business.knownSelfCost)}</b>
|
||
</span>
|
||
<span>
|
||
他人付款 <b>{reportBusinessAmount(business.otherCost, business.knownOtherCost)}</b>
|
||
{others.length ? (
|
||
<small>
|
||
{others
|
||
.map(payer => `${payer.name} ${reportBusinessAmount(payer.totalCost, payer.knownTotalCost)}`)
|
||
.join(';')}
|
||
</small>
|
||
) : (
|
||
''
|
||
)}
|
||
</span>
|
||
</div>
|
||
) : (
|
||
''
|
||
)}
|
||
</section>
|
||
);
|
||
}
|
||
|
||
function renderReportOwnerAdvances(business: T.Business) {
|
||
const advances = business.ownerAdvances,
|
||
single = advances.from === advances.date,
|
||
label = business.member === 'owner' ? teamMemberName('owner') + '付款明细' : teamMemberName('owner') + '垫付明细';
|
||
const days = advances.days.length
|
||
? advances.days
|
||
: single
|
||
? [
|
||
{
|
||
date: advances.date,
|
||
amount: 0,
|
||
knownAmount: 0,
|
||
missingCount: 0,
|
||
pendingCount: 0,
|
||
items: [],
|
||
},
|
||
]
|
||
: [];
|
||
return (
|
||
<details className="report-owner-advances" aria-label={business.name + label}>
|
||
<summary>
|
||
{single ? '当日' : '按日核对'}
|
||
{label}
|
||
</summary>
|
||
<p className="small muted">
|
||
按所属订单开单日、售后记录日归集;仅列所选日期,不累计历史垫付。当日往来另列利润与{teamMemberName('owner')}
|
||
代收,未扣实际转账。
|
||
</p>
|
||
{fallback(
|
||
withKeys(
|
||
days.map(day => (
|
||
<div className="report-owner-advance-day">
|
||
<header>
|
||
<h4>{day.date}</h4>
|
||
<span>
|
||
{day.missingCount ? '已知' : ''}
|
||
{business.member === 'owner' ? '付款' : '垫付'}小计{' '}
|
||
<strong>{reportOwnerAdvanceAmount(day.amount, day.knownAmount)}</strong>
|
||
</span>
|
||
</header>
|
||
{day.items.some(item => item.poolMaterial) ? (
|
||
<p className="report-owner-advance">{reportOwnerAdvanceFormula(business, day)}</p>
|
||
) : (
|
||
''
|
||
)}
|
||
{day.items.length ? (
|
||
<div className="table-wrap">
|
||
<table className="report-owner-advance-table" aria-label={day.date + ' ' + label}>
|
||
<thead>
|
||
<tr>
|
||
<th>日期</th>
|
||
<th>客户/单号</th>
|
||
<th>成本项目</th>
|
||
<th className="number">{teamMemberName('owner')}承担金额</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
{withKeys(
|
||
day.items.map(item => (
|
||
<tr className={item.status === 'recorded' ? undefined : 'report-pending-cost'}>
|
||
<td>{item.date}</td>
|
||
<td>{reportOwnerAdvanceIdentity(item)}</td>
|
||
<td>
|
||
{item.name}
|
||
{item.source ? <small className="muted">{item.source}</small> : ''}
|
||
</td>
|
||
<td className="number">{reportOwnerAdvanceItemAmount(item)}</td>
|
||
</tr>
|
||
)),
|
||
)}
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
) : (
|
||
<>
|
||
<>
|
||
<p className="small muted">当天没有已登记的</p>
|
||
{business.member === 'owner'
|
||
? teamMemberName('owner') + '付款'
|
||
: teamMemberName('owner') + '垫付'}
|
||
</>
|
||
{'明细。</p>'}
|
||
</>
|
||
)}
|
||
{day.pendingCount ? <p className="small muted">待核对项目尚未入账,预估金额不计垫付小计。</p> : ''}
|
||
</div>
|
||
)),
|
||
),
|
||
<>
|
||
<>
|
||
<p className="small muted">所选月份暂无已登记的</p>
|
||
{label}
|
||
</>
|
||
{'。</p>'}
|
||
</>,
|
||
)}
|
||
</details>
|
||
);
|
||
}
|
||
|
||
function renderReportOwnershipProfit(business: T.Business, range: T.Range) {
|
||
const equation = business.equation,
|
||
title = reportMonth || range.from !== range.date ? '本期利润' : '当日利润',
|
||
complete = equation.complete && !business.incomplete && business.totalCost !== null && business.profit !== null,
|
||
revenue = equation.basis === 'netReceipts' ? '所属订单净收入' : '销售净额',
|
||
difference = business.difference;
|
||
return (
|
||
<section className="report-business-profit" aria-label={business.name + title}>
|
||
<h3>{title}</h3>
|
||
{complete ? (
|
||
<p className="report-business-profit-equation">
|
||
<span>
|
||
{revenue} <b>¥{yuan(equation.revenue)}</b>
|
||
</span>
|
||
<span aria-hidden="true">−</span>
|
||
<span>
|
||
订单总成本 <b>¥{yuan(equation.totalCost)}</b>
|
||
</span>
|
||
<span aria-hidden="true">=</span>
|
||
<strong className={(business.profit ?? 0) < 0 ? 'danger-text' : ''}>¥{yuan(business.profit)}</strong>
|
||
</p>
|
||
) : (
|
||
<>
|
||
<strong className="report-business-profit-pending">待核算</strong>
|
||
<p className="small muted">成本或利润资料尚未完整,先核对原单;完整利润暂不显示。</p>
|
||
</>
|
||
)}
|
||
{difference.amount !== 0 || !difference.reconciled ? (
|
||
<div className="report-business-difference">
|
||
<p>
|
||
所属净收款 ¥{yuan(business.netReceipts)},销售净额 ¥{yuan(business.sales)},差额 ¥
|
||
{yuan(difference.amount)}。
|
||
</p>
|
||
{difference.reasons.length ? (
|
||
<ul>{withKeys(difference.reasons.map(reason => <li>{reason.text}</li>))}</ul>
|
||
) : (
|
||
<p>按原账销售与成本核对利润。</p>
|
||
)}
|
||
</div>
|
||
) : (
|
||
''
|
||
)}
|
||
</section>
|
||
);
|
||
}
|
||
|
||
function renderReportOwnershipCurrentAccount(business: T.Business) {
|
||
if (business.member === 'owner') return '';
|
||
const account = business.currentAccount,
|
||
days = reportCurrentAccountDays(business);
|
||
return (
|
||
<section
|
||
className="report-business-settlement report-business-current"
|
||
aria-label={'' + business.name + '当日往来账'}
|
||
>
|
||
<h3>当日往来账</h3>
|
||
<p className="small muted">
|
||
{account.from === account.date ? '仅核对所选单日。' : '按所选范围逐日核对,不将月合计当作日金额。'}
|
||
普通订单按开单日、锁价成单按交付日、售后按记录日归集;锁价代收按实际收付日。此处不含历史余额,也未扣实际转账。
|
||
</p>
|
||
{fallback(
|
||
withKeys(
|
||
days.map(day => (
|
||
<div className="report-current-day" data-date={day.date}>
|
||
<header>
|
||
<h4>{day.date}</h4>
|
||
<span>{reportCurrentAccountDirection(business, day)}</span>
|
||
{day.amount === null ? (
|
||
<strong className="danger-text">待核算</strong>
|
||
) : (
|
||
<strong>¥{yuan(Math.abs(day.amount))}</strong>
|
||
)}
|
||
</header>
|
||
<p className="report-business-balance-equation">{reportCurrentAccountFormula(day)}</p>
|
||
{day.incomplete ? (
|
||
<p className="small danger-text">成本或利润尚未补齐,暂不显示完整应转金额;预估未付项目不计垫付。</p>
|
||
) : (
|
||
''
|
||
)}
|
||
</div>
|
||
)),
|
||
),
|
||
<p className="small muted">所选范围暂无当日往来记录。</p>,
|
||
)}
|
||
</section>
|
||
);
|
||
}
|
||
|
||
function renderReportReceiptIdentity(item: T.ReceiptItem) {
|
||
const number = item.paper_number || item.number || (item.price_lock_id ? '锁价记录' : '订单记录');
|
||
const identity = item.order_id ? (
|
||
<button
|
||
type="button"
|
||
data-action="open-order"
|
||
className="link-button"
|
||
data-id={item.order_id}
|
||
onClick={event => onAction(event.currentTarget.dataset)}
|
||
>
|
||
{number}
|
||
</button>
|
||
) : item.price_lock_id ? (
|
||
<button
|
||
type="button"
|
||
data-action="open-price-lock"
|
||
className="link-button"
|
||
data-id={item.price_lock_id}
|
||
onClick={event => onAction(event.currentTarget.dataset)}
|
||
>
|
||
{number}
|
||
</button>
|
||
) : (
|
||
number
|
||
);
|
||
return (
|
||
<>
|
||
<>
|
||
{identity}
|
||
<div className="small muted">{item.customer || '未填客户称呼'}</div>
|
||
</>
|
||
{item.order_id && item.price_lock_id ? (
|
||
<div className="small">
|
||
<button
|
||
type="button"
|
||
data-action="open-price-lock"
|
||
className="link-button"
|
||
data-id={item.price_lock_id}
|
||
onClick={event => onAction(event.currentTarget.dataset)}
|
||
>
|
||
{'原锁价单'}
|
||
</button>
|
||
</div>
|
||
) : (
|
||
''
|
||
)}
|
||
</>
|
||
);
|
||
}
|
||
|
||
function materialReportCostLink(item: T.CostItem) {
|
||
return item.materialPoolId ? (
|
||
<button
|
||
className="link-button"
|
||
data-action="goto-material-pools"
|
||
data-id={item.materialPoolId}
|
||
onClick={event => onAction(event.currentTarget.dataset)}
|
||
>
|
||
{item.materialPoolId} 购料
|
||
</button>
|
||
) : (
|
||
priceLockCostLink(item)
|
||
);
|
||
}
|
||
|
||
function afterSaleEditButton(row: T.Row) {
|
||
return (
|
||
<button
|
||
type="button"
|
||
data-action="after-sale-edit"
|
||
className="after-sale-edit-button"
|
||
data-id={row.after_sale_id || row.id}
|
||
aria-label={'修改 ' + row.customer + ' 的售后记录'}
|
||
onClick={event => onAction(event.currentTarget.dataset)}
|
||
>
|
||
{'修改'}
|
||
</button>
|
||
);
|
||
}
|
||
|
||
function renderReportPoolMaterial(business: T.Business) {
|
||
const pool = business.poolMaterial;
|
||
if (!pool?.days.length) return '';
|
||
const owner = pool.byPayer.owner;
|
||
return (
|
||
<div className="report-pool-material" aria-label={'' + business.name + '所属订单料池用料'}>
|
||
<div className="report-pool-material-heading">
|
||
<span>已用料合计</span>
|
||
<strong>{grams(pool.mg)}g</strong>
|
||
<span>料池已用料费</span>
|
||
<strong>{reportBusinessAmount(pool.amount, pool.knownAmount)}</strong>
|
||
{pool.missingCount ? <span className="badge warn">料费待补</span> : ''}
|
||
</div>
|
||
<ul>{withKeys(pool.days.map(renderReportPoolMaterialDay))}</ul>
|
||
{reportPoolMaterialPendingNote(pool) ? (
|
||
<p className="small muted">{reportPoolMaterialPendingNote(pool)}</p>
|
||
) : (
|
||
''
|
||
)}
|
||
<p>
|
||
其中{teamMemberName('owner')}垫付 <b>{reportBusinessAmount(owner.amount, owner.knownAmount)}</b>
|
||
</p>
|
||
<p>
|
||
其他成本 <b>{reportBusinessAmount(pool.otherCosts.amount, pool.otherCosts.knownAmount)}</b>
|
||
<small className="muted">(其余商品成本、工费与费用)</small>
|
||
</p>
|
||
<p className="small muted">
|
||
料费已计入总成本;当日往来只取{teamMemberName('owner')}
|
||
垫付部分,公式中计入一次。按未四舍五入均价逐单核算,显示料价相乘可能有分币差。
|
||
{pool.hasPriceLocks ? '锁价已用料费在交付日的当日往来中列示,不重复记实际采购支出。' : ''}
|
||
</p>
|
||
</div>
|
||
);
|
||
}
|
||
|
||
function reportOwnerAdvanceIdentity(item: T.AdvanceItem) {
|
||
return item.kind === 'order' ? (
|
||
<>
|
||
<button
|
||
className="link-button"
|
||
data-action="open-order"
|
||
data-id={item.id}
|
||
onClick={event => onAction(event.currentTarget.dataset)}
|
||
>
|
||
{item.customer || '未填客户'}
|
||
</button>
|
||
<small className="muted">{item.paperNumber || item.number}</small>
|
||
</>
|
||
) : (
|
||
<>
|
||
{item.customer || '未填客户'}
|
||
<small className="muted">售后记录</small>
|
||
</>
|
||
);
|
||
}
|
||
|
||
function priceLockCostLink(item: T.CostItem) {
|
||
if (item.kind === 'afterSale') return reportCostIdentity(item);
|
||
if (item.price_lock_id)
|
||
return (
|
||
<>
|
||
<button
|
||
className="link-button"
|
||
data-action="open-price-lock"
|
||
data-id={item.price_lock_id}
|
||
onClick={event => onAction(event.currentTarget.dataset)}
|
||
>
|
||
{item.number || '锁价记录'}
|
||
</button>
|
||
{item.customer ? <div className="small muted">{item.customer}</div> : ''}
|
||
</>
|
||
);
|
||
return (
|
||
<button
|
||
className="link-button"
|
||
data-action="open-order"
|
||
data-id={item.order_id}
|
||
onClick={event => onAction(event.currentTarget.dataset)}
|
||
>
|
||
{item.paper_number || item.number}
|
||
</button>
|
||
);
|
||
}
|
||
|
||
function renderReportPoolMaterialDay(day: T.PoolDay) {
|
||
if (!day.sources)
|
||
return (
|
||
<li>
|
||
<span>{day.date} 料池</span>
|
||
<strong>{reportPoolMaterialFormula(day)}</strong>
|
||
</li>
|
||
);
|
||
return (
|
||
<li className="report-pool-material-day">
|
||
<div className="report-pool-material-day-total">
|
||
<span>{day.date} 料池</span>
|
||
<b>
|
||
已用 {grams(day.mg)}g · 料费 {reportBusinessAmount(day.amount, day.knownAmount)}
|
||
</b>
|
||
</div>
|
||
<div className="report-pool-material-sources">
|
||
{withKeys(
|
||
day.sources.map(source => (
|
||
<p>
|
||
<span>{reportPoolMaterialSourceLabel(source)}</span>
|
||
<strong>{reportPoolMaterialFormula(source)}</strong>
|
||
</p>
|
||
)),
|
||
)}
|
||
</div>
|
||
</li>
|
||
);
|
||
}
|
||
return {
|
||
...model,
|
||
renderReportContent,
|
||
renderReportDailyProfits,
|
||
renderReimbursementRows,
|
||
renderDailyFundsMonth,
|
||
renderDailyFundsSources,
|
||
renderDailyTransferResult,
|
||
renderReimbursementItems,
|
||
};
|
||
}
|