£
Ft³
–
kg
–
lb
{
const quotedItems = Object.values(locations).flat()
.filter((item) => {
return item.total > 0;
});
let rows = "";
rows += "Bearded Bros Quote, Totals: ";
rows += ", £" + quotedItems.reduce((n, {total, cost}) => n + (total * cost), 0);
rows += ", " + quotedItems.reduce((n, {total, volume}) => n + (total * (volume)), 0) + " Ft³";
rows += ", " + quotedItems.reduce((n, {total, kg}) => n + (total * (kg)), 0) + " kg";
rows += ", " + quotedItems.reduce((n, {total, lb}) => n + (total * (lb)), 0) + " lb";
rows += ", " + quotedItems.reduce((n, {total}) => n + (total * (1)), 0) + " items";
rows += `\n\n`;
if (quotedItems.length > 0) {
rows += quotedItems
.map((item, i) => {
let line = "";
if (i === 0) line += Object.keys(item).join(", ")+ "\n";
line += Object.values(item).map((v) => `${v}`.replaceAll(",", "")).join(", ");
return line;
})
.join("\n");
} else {
rows += "No items have been selected!";
}
const dwnld = document.createElement("a");
dwnld.setAttribute("href", "data:text/plain;charset=utf-8," + encodeURIComponent(rows));
dwnld.setAttribute("download", (quoteName.replace(/\W/g, "")) + " - quote.csv");
dwnld.style.display = "none";
document.body.appendChild(dwnld);
dwnld.click();
document.body.removeChild(dwnld);
console.log(rows);
}'>Download quote as CSV