Znote (recipes)
  Get Znote  

Sales report

Demonstration of sales reporting with graph using integrated results files from a database

 

Sales report

🧑‍💻 See the sales report preparation note to configure your database

Total sales amount by Channel

SELECT 
  channel,
  DATE_FORMAT(sale_date, '%Y-%m') AS month,
  SUM(price) AS total_sales_amount,
  COUNT(*) AS total_sales
FROM 
  Sales
GROUP BY 
  channel, month
ORDER BY month ASC;
// Get data from SQL database and save results into a JSON file
const sql = loadBlock("orders");
const json = await localSalesSQL(sql);
_fs.writeFileSync(__dirname + "/orders-channel.json", JSON.stringify(json));
print("Done");
// Loads and integrates the JSON file with deployment
// This block will be displayed in the report
const json = require("./orders-channel.json");
barChart({
  horizontal:true,
  series: toSeries({data:json, x:"month", y:"total_sales_amount", category:"channel"}),
});

Related recipes