Add purchase date picker and sells feature
- Purchase form now includes a date picker (defaults to today) - New Sell model, CRUD endpoints (/sells), and stats integration - AddSell and SellList components added to dashboard - Portfolio chart updated to reflect sells over time Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -42,12 +42,13 @@ function priceOn(date, priceMap, currentPrice, isToday, sortedPurchases) {
|
||||
return fallback;
|
||||
}
|
||||
|
||||
export default function PortfolioChart({ purchases, stats, btcHistory }) {
|
||||
export default function PortfolioChart({ purchases, sells, stats, btcHistory }) {
|
||||
const chartRef = useRef(null);
|
||||
|
||||
if (!purchases || purchases.length === 0) return null;
|
||||
|
||||
const sorted = [...purchases].sort((a, b) => new Date(a.created_at) - new Date(b.created_at));
|
||||
const sortedSells = [...(sells || [])].sort((a, b) => new Date(a.created_at) - new Date(b.created_at));
|
||||
const today = new Date();
|
||||
today.setHours(0, 0, 0, 0);
|
||||
|
||||
@@ -89,6 +90,14 @@ export default function PortfolioChart({ purchases, stats, btcHistory }) {
|
||||
cumInvested += p.amount_eur;
|
||||
}
|
||||
});
|
||||
sortedSells.forEach(s => {
|
||||
const sDate = new Date(s.created_at);
|
||||
sDate.setHours(0, 0, 0, 0);
|
||||
if (sDate <= date) {
|
||||
cumBtc -= s.btc_amount;
|
||||
cumInvested -= s.btc_amount * s.price_eur;
|
||||
}
|
||||
});
|
||||
|
||||
if (cumBtc === 0) return; // no purchases yet at this date
|
||||
|
||||
|
||||
Reference in New Issue
Block a user