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")}

); } return (
{__("An estimate.", "lotcost")}{" "} {__("LotCost reads no order. A piece counts as sold when it has left your stock, valued at its price today: discounts and later price changes are not seen.", "lotcost")}{" "} {unknown > 0 && sprintf( /* translators: %d: number of pieces */ _n( "%d piece cannot be told: its stock is not counted, or it is gone from your store.", "%d pieces cannot be told: their stock is not counted, or they are gone from your store.", unknown, "lotcost", ), unknown, )}

{__("By source", "lotcost")}

{sources.map((s) => ( ))}
{__("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)}

{__("By lot", "lotcost")}

{items.map(({ lot, recovery }) => ( ))}
{__("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)}
); }