fix(pricing): persist pricing_config on applyGlobalMargins and fix nullish coalescing in settings
This commit is contained in:
1 parent
0da7cf14e8
commit
2a501637cb
14 files changed
+7089
-7010
No files matched your search
@@ -64,10 +64,10 @@ export default function FinancialSettingsPage() {
|
||||
if (resPricing.data?.success && resPricing.data.data) {
|
||||
const p = resPricing.data.data;
|
||||
setPricing({
|
||||
roundingStep: Number(p.roundingStep || 5000),
|
||||
roundingStep: Number(p.roundingStep ?? 5000),
|
||||
roundingMode: p.roundingMode || 'UP',
|
||||
defaultRetailMarginPercent: Number(p.defaultRetailMarginPercent || 30),
|
||||
defaultWholesaleMarginPercent: Number(p.defaultWholesaleMarginPercent || 15),
|
||||
defaultRetailMarginPercent: Number(p.defaultRetailMarginPercent ?? 30),
|
||||
defaultWholesaleMarginPercent: Number(p.defaultWholesaleMarginPercent ?? 15),
|
||||
});
|
||||
}
|
||||
})
|
||||
|
||||
@@ -523,16 +523,20 @@ export default function Products() {
|
||||
const pricingRes = await api.get('/admin/pricing/settings');
|
||||
if (pricingRes.data?.data) {
|
||||
const p = pricingRes.data.data;
|
||||
const effStep = Number(p.roundingStep ?? 5000);
|
||||
const effMode = p.roundingMode || 'UP';
|
||||
const effRetail = Number(p.defaultRetailMarginPercent ?? 30);
|
||||
const effWholesale = Number(p.defaultWholesaleMarginPercent ?? 15);
|
||||
setPricingSettings({
|
||||
roundingStep: Number(p.roundingStep || 5000),
|
||||
roundingMode: p.roundingMode || 'UP',
|
||||
defaultRetailMarginPercent: Number(p.defaultRetailMarginPercent || 30),
|
||||
defaultWholesaleMarginPercent: Number(p.defaultWholesaleMarginPercent || 15),
|
||||
roundingStep: effStep,
|
||||
roundingMode: effMode,
|
||||
defaultRetailMarginPercent: effRetail,
|
||||
defaultWholesaleMarginPercent: effWholesale,
|
||||
});
|
||||
setGlobalMarginForm(prev => ({
|
||||
...prev,
|
||||
retailMarginPercent: Number(p.defaultRetailMarginPercent || 30),
|
||||
wholesaleMarginPercent: Number(p.defaultWholesaleMarginPercent || 15),
|
||||
retailMarginPercent: effRetail,
|
||||
wholesaleMarginPercent: effWholesale,
|
||||
}));
|
||||
}
|
||||
} catch (err) {
|
||||
@@ -566,7 +570,15 @@ export default function Products() {
|
||||
roundingMode: pricingSettings.roundingMode,
|
||||
});
|
||||
const data = res.data?.data || res.data;
|
||||
toast.success(data?.message || 'درصد سود با موفقیت بر روی محصولات اعمال شد');
|
||||
if (data?.defaultRetailMarginPercent !== undefined) {
|
||||
setPricingSettings({
|
||||
roundingStep: Number(data.roundingStep ?? 5000),
|
||||
roundingMode: data.roundingMode || 'UP',
|
||||
defaultRetailMarginPercent: Number(data.defaultRetailMarginPercent ?? 30),
|
||||
defaultWholesaleMarginPercent: Number(data.defaultWholesaleMarginPercent ?? 15),
|
||||
});
|
||||
}
|
||||
toast.success(res.data?.message || data?.message || 'درصد سود با موفقیت بر روی محصولات اعمال شد');
|
||||
setIsBulkPriceModalOpen(false);
|
||||
await fetchData();
|
||||
} catch (err: any) {
|
||||
@@ -750,7 +762,15 @@ export default function Products() {
|
||||
variant="outline"
|
||||
size="sm"
|
||||
startIcon={Calculator}
|
||||
onClick={() => setIsBulkPriceModalOpen(true)}
|
||||
onClick={() => {
|
||||
setGlobalMarginForm({
|
||||
scope: 'ALL',
|
||||
categoryIds: [],
|
||||
retailMarginPercent: pricingSettings.defaultRetailMarginPercent,
|
||||
wholesaleMarginPercent: pricingSettings.defaultWholesaleMarginPercent,
|
||||
});
|
||||
setIsBulkPriceModalOpen(true);
|
||||
}}
|
||||
className="border-purple-200 text-purple-700 hover:bg-purple-50 font-bold"
|
||||
>
|
||||
مدیریت گروهی قیمتها
|
||||
|
||||
Reference in new issue
Block a user