feat: TASK-113 - add CSV/Excel B2B wholesale price list export capability
This commit is contained in:
1 parent
201aebd2f5
commit
7e17f6840c
8 files changed
+151
-154
No files matched your search
@@ -15,7 +15,8 @@ import {
|
||||
CheckCircle2,
|
||||
Lock,
|
||||
Percent,
|
||||
X
|
||||
X,
|
||||
Download
|
||||
} from "lucide-react";
|
||||
import SafeImage from "./SafeImage";
|
||||
import { toPersian } from "../lib/utils";
|
||||
@@ -75,6 +76,25 @@ export default function B2BPortal({ onClose }: { onClose: () => void }) {
|
||||
return sum;
|
||||
}, 0);
|
||||
|
||||
const exportToCSV = () => {
|
||||
const headers = ["کد کالا", "نام محصول", "دستهبندی", "قیمت تکفروشی (تومان)", "قیمت عمده (تومان)"];
|
||||
const rows = products.map(p => {
|
||||
const base = p.priceValue || 0;
|
||||
const wholesale = Math.round(base * 0.7);
|
||||
return [`"${p.artNo}"`, `"${p.name}"`, `"${p.category}"`, base, wholesale];
|
||||
});
|
||||
|
||||
const csvContent = "\uFEFF" + [headers.join(","), ...rows.map(e => e.join(","))].join("\n");
|
||||
const blob = new Blob([csvContent], { type: "text/csv;charset=utf-8;" });
|
||||
const url = URL.createObjectURL(blob);
|
||||
const link = document.createElement("a");
|
||||
link.setAttribute("href", url);
|
||||
link.setAttribute("download", `Canina_B2B_PriceList_${new Date().toISOString().slice(0, 10)}.csv`);
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
document.body.removeChild(link);
|
||||
};
|
||||
|
||||
return (
|
||||
<motion.div
|
||||
initial={{ opacity: 0 }}
|
||||
@@ -108,10 +128,16 @@ export default function B2BPortal({ onClose }: { onClose: () => void }) {
|
||||
</div>
|
||||
|
||||
<div className="mt-auto space-y-4">
|
||||
<div className="p-4 bg-white/10 rounded-2xl flex items-center gap-3">
|
||||
<FileText className="w-5 h-5 text-blue-300" />
|
||||
<span className="text-xs font-bold">دریافت لیست قیمت PDF</span>
|
||||
</div>
|
||||
<button
|
||||
onClick={exportToCSV}
|
||||
className="w-full p-4 bg-white/10 hover:bg-white/20 rounded-2xl flex items-center gap-3 transition-colors text-right"
|
||||
>
|
||||
<Download className="w-5 h-5 text-blue-300" />
|
||||
<div>
|
||||
<span className="text-xs font-black block">دانلود لیست قیمت (اکسل)</span>
|
||||
<span className="text-[10px] text-white/60 block">خروجی CSV آماده چاپ</span>
|
||||
</div>
|
||||
</button>
|
||||
<div className="p-4 bg-white/10 rounded-2xl flex items-center gap-3">
|
||||
<Package className="w-5 h-5 text-blue-300" />
|
||||
<span className="text-xs font-bold">پیگیری محمولات قبلی</span>
|
||||
|
||||
Reference in new issue
Block a user