| | |
| | | const n = Number(v); |
| | | return Number.isFinite(n) ? n : 0; |
| | | }; |
| | | const toTime = (v) => { |
| | | const t = new Date(v).getTime(); |
| | | return Number.isFinite(t) ? t : -Infinity; |
| | | }; |
| | | const toId = (v) => { |
| | | const n = Number(v); |
| | | return Number.isFinite(n) ? n : -Infinity; |
| | | }; |
| | | |
| | | // 以当前右侧表格展示的数据为准(分页 slice 后的数据) |
| | | const rows = originalTableDataSon.value || []; |
| | |
| | | ); |
| | | |
| | | const paymentTotal = rows.reduce((sum, r) => sum + toNum(r?.paymentAmount), 0); |
| | | const latestRowByContract = new Map(); |
| | | for (const r of rows) { |
| | | const contractNo = r?.purchaseContractNumber; |
| | | if (!contractNo) continue; |
| | | const existed = latestRowByContract.get(contractNo); |
| | | const currentTime = toTime(r?.paymentDate); |
| | | const existedTime = toTime(existed?.paymentDate); |
| | | const shouldReplace = |
| | | !existed || |
| | | currentTime > existedTime || |
| | | (currentTime === existedTime && toId(r?.id) > toId(existed?.id)); |
| | | if (shouldReplace) { |
| | | latestRowByContract.set(contractNo, r); |
| | | } |
| | | } |
| | | const payableTotal = Array.from(latestRowByContract.values()).reduce( |
| | | (sum, r) => sum + toNum(r?.payableAmount), |
| | | 0 |
| | | ); |
| | | |
| | | const columns = param?.columns || []; |
| | | const summary = columns.map((col, idx) => { |
| | |
| | | const prop = col?.property ?? col?.prop; |
| | | if (prop === "invoiceAmount") return invoiceTotal.toFixed(2); |
| | | if (prop === "paymentAmount") return paymentTotal.toFixed(2); |
| | | if (prop === "payableAmount") return payableTotal.toFixed(2); |
| | | return ""; |
| | | }); |
| | | |
| | | if (summary.length > 0) { |
| | | summary[summary.length - 1] = |
| | | rows.length > 0 ? toNum(rows[rows.length - 1]?.payableAmount).toFixed(2) : "0.00"; |
| | | } |
| | | |
| | | return summary; |
| | | }; |