feat: enhance printResults function to filter and display FBA/FBM leads with detailed profit calculations
This commit is contained in:
@@ -51,18 +51,56 @@ function buildRow(r: AnalysisResult) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function printResults(results: AnalysisResult[]): void {
|
export function printResults(results: AnalysisResult[]): void {
|
||||||
const rows = results.map((r) => {
|
const rows = results
|
||||||
const row = buildRow(r);
|
.filter((r) => r.verdict.verdict === "FBA" || r.verdict.verdict === "FBM")
|
||||||
return {
|
.map((r) => {
|
||||||
...row,
|
const sellingPrice =
|
||||||
Name: row.Name.slice(0, 40),
|
r.product.keepa?.currentPrice ??
|
||||||
Category: String(row.Category).slice(0, 20),
|
r.product.record.sellingPriceFromSheet ??
|
||||||
Reasoning: row.Reasoning.slice(0, 60),
|
r.product.spApi.estimatedSalePrice;
|
||||||
};
|
const referralFee =
|
||||||
});
|
sellingPrice != null
|
||||||
|
? sellingPrice * (r.product.spApi.referralFeePercent / 100)
|
||||||
|
: null;
|
||||||
|
const fulfillmentFee =
|
||||||
|
r.verdict.verdict === "FBA"
|
||||||
|
? r.product.spApi.fbaFee
|
||||||
|
: r.product.spApi.fbmFee;
|
||||||
|
const netProfit =
|
||||||
|
sellingPrice != null
|
||||||
|
? Math.round(
|
||||||
|
(sellingPrice -
|
||||||
|
r.product.record.unitCost -
|
||||||
|
fulfillmentFee -
|
||||||
|
(referralFee ?? 0)) *
|
||||||
|
100,
|
||||||
|
) / 100
|
||||||
|
: "";
|
||||||
|
|
||||||
|
return {
|
||||||
|
ASIN: r.product.record.asin,
|
||||||
|
Name: r.product.record.name.slice(0, 40),
|
||||||
|
Category: String(
|
||||||
|
r.product.record.category ??
|
||||||
|
r.product.keepa?.categoryTree?.join(" > ") ??
|
||||||
|
"",
|
||||||
|
).slice(0, 20),
|
||||||
|
"Unit Cost": r.product.record.unitCost,
|
||||||
|
"Selling Price": sellingPrice ?? "",
|
||||||
|
"Net Profit": netProfit,
|
||||||
|
"Monthly Sold": r.product.keepa?.monthlySold ?? "",
|
||||||
|
"Sold 90 Day": r.product.keepa?.salesRankDrops90 ?? "",
|
||||||
|
Confidence: r.verdict.confidence,
|
||||||
|
Reasoning: r.verdict.reasoning.slice(0, 60),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
console.log("\n=== Analysis Results ===\n");
|
console.log("\n=== Analysis Results ===\n");
|
||||||
console.table(rows);
|
if (rows.length === 0) {
|
||||||
|
console.log("No FBA/FBM leads found.");
|
||||||
|
} else {
|
||||||
|
console.table(rows);
|
||||||
|
}
|
||||||
|
|
||||||
const summary = {
|
const summary = {
|
||||||
FBA: results.filter((r) => r.verdict.verdict === "FBA").length,
|
FBA: results.filter((r) => r.verdict.verdict === "FBA").length,
|
||||||
|
|||||||
Reference in New Issue
Block a user