diff --git a/backend/src/products/products.service.ts b/backend/src/products/products.service.ts index efd7fc51..d7c051dd 100644 --- a/backend/src/products/products.service.ts +++ b/backend/src/products/products.service.ts @@ -91,12 +91,16 @@ export class ProductsService { const isWholesaleOrAdmin = userRole === 'User_Wholesale' || userRole === 'User_Partner' || userRole === 'ADMIN' || userRole === 'SuperAdmin'; + const isAdmin = userRole === 'ADMIN' || userRole === 'SuperAdmin'; + const data = rawProducts.map((p) => { + // Remove buyPrice for all non-admins + const { buyPrice, ...withoutBuyPrice } = p; if (!isWholesaleOrAdmin) { - const { wholesalePrice, ...rest } = p; - return rest; + const { wholesalePrice, ...publicProduct } = withoutBuyPrice; + return publicProduct; } - return p; + return isAdmin ? p : withoutBuyPrice; }); return { @@ -126,11 +130,14 @@ export class ProductsService { if (!product) return null; const isWholesaleOrAdmin = userRole === 'User_Wholesale' || userRole === 'User_Partner' || userRole === 'ADMIN' || userRole === 'SuperAdmin'; + const isAdmin = userRole === 'ADMIN' || userRole === 'SuperAdmin'; + + const { buyPrice, ...withoutBuyPrice } = product; if (!isWholesaleOrAdmin) { - const { wholesalePrice, ...rest } = product; - return rest; + const { wholesalePrice, ...publicProduct } = withoutBuyPrice; + return publicProduct; } - return product; + return isAdmin ? product : withoutBuyPrice; } async getActiveFilters() { diff --git a/frontend/admin-panel/src/pages/Products.tsx b/frontend/admin-panel/src/pages/Products.tsx index 6c2c8e99..2973e351 100644 --- a/frontend/admin-panel/src/pages/Products.tsx +++ b/frontend/admin-panel/src/pages/Products.tsx @@ -27,6 +27,7 @@ export interface Product { categoryId?: string; priceValue?: number; wholesalePrice?: number; + buyPrice?: number; priceDisplay?: string; unit?: string; packageSize?: number; @@ -111,8 +112,11 @@ export default function Products() { description: '', shortDescription: '', categoryId: '', + buyPrice: '' as number | string, priceValue: 0, wholesalePrice: '' as number | string, + priceValueMarginPercent: '' as number | string, + wholesaleMarginPercent: '' as number | string, priceDisplay: '', unit: '', packageSize: 0, @@ -170,6 +174,13 @@ export default function Products() { setMediaImageError(false); if (product) { setEditingProduct(product); + const bPrice = product.buyPrice ? Number(product.buyPrice) : ''; + const pPrice = Number(product.priceValue || 0); + const wPrice = product.wholesalePrice ? Number(product.wholesalePrice) : ''; + + const pMargin = bPrice && pPrice ? Math.round(((pPrice - Number(bPrice)) / Number(bPrice)) * 100) : ''; + const wMargin = bPrice && wPrice ? Math.round(((wPrice - Number(bPrice)) / Number(bPrice)) * 100) : ''; + setFormData({ artNo: product.artNo, nameFa: product.nameFa || '', @@ -178,8 +189,11 @@ export default function Products() { description: product.description || '', shortDescription: product.shortDescription || '', categoryId: product.categoryId || '', - priceValue: Number(product.priceValue), - wholesalePrice: product.wholesalePrice ? Number(product.wholesalePrice) : '', + buyPrice: bPrice, + priceValue: pPrice, + wholesalePrice: wPrice, + priceValueMarginPercent: pMargin, + wholesaleMarginPercent: wMargin, priceDisplay: product.priceDisplay || '', unit: product.unit || '', packageSize: Number(product.packageSize), @@ -201,7 +215,8 @@ export default function Products() { setEditingProduct(null); setFormData({ artNo: '', nameFa: '', nameEn: '', scientificTagline: '', description: '', shortDescription: '', categoryId: '', - priceValue: 0, wholesalePrice: '', priceDisplay: '', unit: '', packageSize: 0, dosageLogic: '', suitableFor: 'سگ و گربه', + buyPrice: '', priceValue: 0, wholesalePrice: '', priceValueMarginPercent: '', wholesaleMarginPercent: '', + priceDisplay: '', unit: '', packageSize: 0, dosageLogic: '', suitableFor: 'سگ و گربه', imageUrl: '', metaTitle: '', metaDescription: '', keywords: '', canonicalUrl: '', slug: '', images: [], podcastUrl: '', videoUrl: '', pdfUrl: '', symptoms: [] @@ -217,6 +232,8 @@ export default function Products() { const derivedSlug = formData.slug.trim() || slugify(formData.nameEn); const finalPayload = { ...formData, + buyPrice: formData.buyPrice ? Number(formData.buyPrice) : 0, + wholesalePrice: formData.wholesalePrice ? Number(formData.wholesalePrice) : null, slug: derivedSlug, metaTitle: formData.metaTitle.trim() || `${formData.nameFa || 'نام محصول'} | خرید و قیمت مکمل کانینا`, metaDescription: formData.metaDescription.trim() || formData.shortDescription || 'خرید آنلاین مکمل اصل کانینا آلمان با بالاترین کیفیت بالینی...', @@ -635,54 +652,199 @@ export default function Products() { {/* Pricing Tab */}
امنیت و حریم خصوصی قیمت خرید (سود و زیان)
++ قیمت خرید و درصدهای سود به هیچ عنوان در پاسخهای API عمومی فرانتاند سایت منتشر نمیشوند و فقط جهت محاسبات حسابداری و گزارشگیری سود/زیان در پنل ادمین استفاده میشوند. +
+