feat(admin): implement smart pricing, rounding rules, formula margins and bulk price adjustment
Deploy Canina / deploy (push) Successful in 45s
E2E Playwright Tests / Run Full E2E & Security Suites (push) Failing after 6s

This commit is contained in:
parsa aghaei committed 2026-09-02 10:05:41 +03:30
1 parent 382ebc0ce6
commit ac15ece619
21 files changed
+17219 -14083

No files matched your search

+43
View File
@@ -0,0 +1,43 @@
export type RoundingMode = 'UP' | 'DOWN' | 'NEAREST';
export interface PricingSettings {
roundingStep: number;
roundingMode: RoundingMode;
defaultRetailMarginPercent: number;
defaultWholesaleMarginPercent: number;
}
export const DEFAULT_PRICING_SETTINGS: PricingSettings = {
roundingStep: 5000,
roundingMode: 'UP',
defaultRetailMarginPercent: 30,
defaultWholesaleMarginPercent: 15,
};
export function applyRounding(
price: number,
step: number = 5000,
mode: RoundingMode = 'UP',
): number {
if (isNaN(price) || price <= 0) return 0;
if (!step || step <= 1) return Math.round(price);
if (mode === 'UP') {
return Math.ceil(price / step) * step;
} else if (mode === 'DOWN') {
return Math.floor(price / step) * step;
} else {
return Math.round(price / step) * step;
}
}
export function calculateSellingPrice(
buyPrice: number,
marginPercent: number,
step: number = 5000,
mode: RoundingMode = 'UP',
): number {
if (isNaN(buyPrice) || buyPrice <= 0) return 0;
const rawPrice = buyPrice * (1 + (marginPercent || 0) / 100);
return applyRounding(rawPrice, step, mode);
}