import { __, _n, sprintf } from "@wordpress/i18n"; import { Notice } from "@wordpress/components"; import { boot } from "../boot"; import { formatCents, formatPercent } from "../engine/format"; import { bySource, recoverLot } from "../engine/recovery"; import type { Store } from "../store"; // How much of what was paid has come back, by where the lots were bought. No order is read: a piece counts as sold when // it has left the stock, valued at its price today, so every figure is an estimate and is labelled so. export function SourcesView({ store }: { store: Store }) { const items = store.costed.map((row) => ({ lot: row.lot, recovery: recoverLot(row) })); const sources = bySource(items); const unknown = items.reduce((sum, i) => sum + i.recovery.unknownPieces, 0); const none = __("No source", "lotcost"); if (items.length === 0) { return (
{__("No lot yet. Record a lot first: this page sums up what has come back, by lot and by where you bought.", "lotcost")}
| {__("Source", "lotcost")} | {__("Lots", "lotcost")} | {__("Paid", "lotcost")} | {__("Back so far", "lotcost")} | {__("Recovered", "lotcost")} | {__("Units sold", "lotcost")} | {__("Still in stock", "lotcost")} |
|---|---|---|---|---|---|---|
| {s.source || none} | {s.lots} | {formatCents(s.totalCents, boot.currency)} | {formatCents(s.revenueCents, boot.currency)} | {formatPercent(s.recoveredPercent)} | {`${s.unitsSold} / ${s.unitsTotal}`} | {formatCents(s.stockValueCents, boot.currency)} |
| {__("Lot", "lotcost")} | {__("Paid", "lotcost")} | {__("Back so far", "lotcost")} | {__("Recovered", "lotcost")} | {__("Pieces sold", "lotcost")} | {__("Profit so far", "lotcost")} |
|---|---|---|---|---|---|
|
{lot.name}
{lot.source || none}
|
{formatCents(recovery.totalCents, boot.currency)} | {formatCents(recovery.revenueCents, boot.currency)} | {formatPercent(recovery.recoveredPercent)} | {`${recovery.soldPieces} / ${recovery.pieces}`} | {formatCents(recovery.profitCents, boot.currency)} |