feat(admin): implement smart pricing, rounding rules, formula margins and bulk price adjustment
This commit is contained in:
1 parent
382ebc0ce6
commit
ac15ece619
21 files changed
+17219
-14083
No files matched your search
@@ -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);
|
||||
}
|
||||
Reference in new issue
Block a user