// Report page (ລາຍງານ)
function ReportPage({ store }) {
const [tab, setTab] = useState('overview'); // overview | small | big | byMonth
const smallIn = sumCurr(store.smallIncome);
const smallOut = sumCurr(store.smallExpense);
const bigIn = sumCurr(store.bigIncome);
const bigOut = sumCurr(store.bigExpense);
const allIn = sumCurr([...store.smallIncome, ...store.bigIncome]);
const allOut = sumCurr([...store.smallExpense, ...store.bigExpense]);
const monthly = useMemo(() => {
const map = {};
const addRow = (r, key) => {
const ym = ymKey(r.date);
if (!ym) return;
if (!map[ym]) map[ym] = {
in: { kip:0,baht:0,usd:0,yuan:0 },
out: { kip:0,baht:0,usd:0,yuan:0 },
};
CURRENCIES.forEach(c => { map[ym][key][c.code] += Number(r[c.code]) || 0; });
};
[...store.smallIncome, ...store.bigIncome].forEach(r => addRow(r, 'in'));
[...store.smallExpense, ...store.bigExpense].forEach(r => addRow(r, 'out'));
return Object.entries(map)
.map(([ym, v]) => ({ ym, ...v }))
.sort((a,b) => a.ym.localeCompare(b.ym));
}, [store]);
const maxBaht = Math.max(1, ...monthly.flatMap(m => [m.in.baht, m.out.baht]));
return (
ລາຍງານ
ລາຍງານການເງິນ
ພາບລວມລາຍຮັບ-ລາຍຈ່າຍ ແຍກຕາມຄັງ ແລະ ລາຍເດືອນ
setTab('overview')}>ພາບລວມ
setTab('small')}>ຄັງນ້ອຍ
setTab('big')}>ຄັງໃຫຍ່
setTab('byMonth')}>ລາຍເດືອນ
{tab === 'overview' && (
<>
ສະຫຼຸບຍອດທັງໝົດ
| ລາຍຮັບ | ລາຍຈ່າຍ | ຄົງເຫຼືອ |
{CURRENCIES.map(c => (
| {c.label} |
{fmt(allIn[c.code])} |
{fmt(allOut[c.code])} |
{fmt(allIn[c.code] - allOut[c.code])} |
))}
ຄັງນ້ອຍ
{store.smallIncome.length + store.smallExpense.length} ທຸລະກຳ
{CURRENCIES.map(c => (
{c.label} · ຄົງເຫຼືອ
= 0 ? 'var(--green)' : 'var(--rose)' }}>
{fmt(smallIn[c.code] - smallOut[c.code])}
))}
ຄັງໃຫຍ່
{store.bigIncome.length + store.bigExpense.length} ທຸລະກຳ
{CURRENCIES.map(c => (
{c.label} · ຄົງເຫຼືອ
= 0 ? 'var(--green)' : 'var(--rose)' }}>
{fmt(bigIn[c.code] - bigOut[c.code])}
))}
>
)}
{tab === 'small' && (
ຄັງນ້ອຍ
ທຸກສະກຸນເງິນ
| ລາຍຮັບ | ລາຍຈ່າຍ | ຄົງເຫຼືອ |
{CURRENCIES.map(c => (
| {c.label} |
{fmt(smallIn[c.code])} |
{fmt(smallOut[c.code])} |
{fmt(smallIn[c.code] - smallOut[c.code])} |
))}
)}
{tab === 'big' && (
ຄັງໃຫຍ່
ທຸກສະກຸນເງິນ
| ລາຍຮັບ | ລາຍຈ່າຍ | ຄົງເຫຼືອ |
{CURRENCIES.map(c => (
| {c.label} |
{fmt(bigIn[c.code])} |
{fmt(bigOut[c.code])} |
{fmt(bigIn[c.code] - bigOut[c.code])} |
))}
)}
{tab === 'byMonth' && (
ປຽບທຽບລາຍເດືອນ
ໜ່ວຍ: ບາດ
{monthly.length === 0 ? (
) : monthly.map(m => (
{ymLabel(m.ym)}
+{fmt(m.in.baht)}
-{fmt(m.out.baht)}
))}
)}
);
}
window.ReportPage = ReportPage;