Fix #264 Discount change based on preference

This commit is contained in:
karthikalakshmi 2026-03-09 14:42:45 +05:30
parent cc7a002f18
commit 6a07094d7f
2 changed files with 763 additions and 601 deletions

View File

@ -12,6 +12,8 @@ import {
GlobalReorderProductDetails,
PreferenceData,
getConfigType,
changeCombofocus,
changefocusStatusCust,
} from '../../../../../Features/BookingScreen/BookingData/BookingData';
import { ArrowRightOutlined } from '@ant-design/icons';
import { Messages } from '../../../../../Components/Notifications/Messages';
@ -48,13 +50,14 @@ const BSBillingEditQuantity = (props) => {
const formRef = useRef(null);
const detailedFormRef = useRef(null);
const itemDiscountFormRef = useRef(null);
const discountRef = useRef(null);
const quantityInputRef = useRef(null);
const priceChangeInputRef = useRef(null);
const reductionInputRef = useRef(null);
const { setIndex = () => { } } = props;
const { setIndex = () => {} } = props;
const [disableSubmitButton, setDisableSubmitButton] = useState(false);
console.log(disableSubmitButton, "disableSubmitButton")
console.log(disableSubmitButton, 'disableSubmitButton');
const SessionData = useSelector(StoredSessionData);
// const AppId = SessionData?.AppId;
// const CompId = SessionData?.CompId;
@ -68,13 +71,30 @@ const BSBillingEditQuantity = (props) => {
shallowEqual
);
const overAllLimitPreferenece =
preferenceDatas?.[0]?.['SettingDtlDetails']?.find(
(item) => (item.SettingIdName?.toLowerCase() === 'overalllimit') && item?.SettingValue === 'Y');
const itemWiseLimitPreferenece =
preferenceDatas?.[0]?.['SettingDtlDetails']?.find(
(item) => item.SettingIdName?.toLowerCase() === 'itemwiselimit' && item?.SettingValue === 'Y');
const maxQtyLimit = itemWiseLimitPreferenece?.SettingCount || overAllLimitPreferenece?.SettingCount || null;
const overAllLimitPreferenece = preferenceDatas?.[0]?.[
'SettingDtlDetails'
]?.find(
(item) =>
item.SettingIdName?.toLowerCase() === 'overalllimit' &&
item?.SettingValue === 'Y'
);
const itemDiscount = preferenceDatas?.[0]?.['SettingDtlDetails']?.find(
(item) =>
item.SettingIdName?.toLowerCase() === 'itemdiscount' &&
item?.SettingValue === 'Y'
);
const itemWiseLimitPreferenece = preferenceDatas?.[0]?.[
'SettingDtlDetails'
]?.find(
(item) =>
item.SettingIdName?.toLowerCase() === 'itemwiselimit' &&
item?.SettingValue === 'Y'
);
const maxQtyLimit =
itemWiseLimitPreferenece?.SettingCount ||
overAllLimitPreferenece?.SettingCount ||
null;
const preferenceOffer =
preferenceDatas?.[0]?.['SettingDtlDetails']?.find(
(item) => item.SettingIdName === 'Offer'
@ -117,7 +137,7 @@ const BSBillingEditQuantity = (props) => {
price: 'Price',
quantity: 'qty',
Parcel: 'Parcel',
weightAmount: 'weightAmount'
weightAmount: 'weightAmount',
};
const [RadioBtnSelection, setRadioBtnSelection] = useState(() => {
if (props?.shortKeyMethod && SHORTKEY_TO_RADIO[props.shortKeyMethod]) {
@ -142,9 +162,10 @@ const BSBillingEditQuantity = (props) => {
// );
const [PercentageSelection, setPercentageSelection] = useState('Fixed');
const [RadioDetails, setRadioDetails] = useState(false);
const [editedPrice, setEditedPrice] = useState(0);
const [itemDiscountPercentageSelection, setItemDiscountPercentageSelection] = useState('Fixed');
const [itemDiscountPrice, setItemDiscountPrice] = useState(0);
const [editedPrice, setEditedPrice] = useState('');
const [itemDiscountPercentageSelection, setItemDiscountPercentageSelection] =
useState('Fixed');
const [itemDiscountPrice, setItemDiscountPrice] = useState('');
const allowDecimal = preferenceDatas?.[0]?.SettingDtlDetails?.find(
(setting) =>
setting?.SettingIdName?.toLowerCase() === 'decimal' &&
@ -178,8 +199,9 @@ const BSBillingEditQuantity = (props) => {
}
}, []);
useEffect(
() => {
useEffect(() => {
dispatch(changeCombofocus(true));
dispatch(changefocusStatusCust(true));
setEditOpen(props.BSBillingEditQuantity);
setItemData(props.Productdata);
setQuantity(
@ -188,9 +210,7 @@ const BSBillingEditQuantity = (props) => {
: props.Productdata.OrderQty
);
SellingPriceChange(parseFloat(props.Productdata?.SellingPrice || 0));
},
[props.BSBillingEditQuantity, props.Productdata]
);
}, [props.BSBillingEditQuantity, props.Productdata]);
useEffect(() => {
if (preferenceshortcutkey) {
@ -272,7 +292,6 @@ const BSBillingEditQuantity = (props) => {
if (RadioBtnSelection === 'Price' && !RadioDetails) {
setEditedPrice(parseFloat(props.Productdata?.SellingPrice || 0));
}
}, [RadioBtnSelection, RadioDetails]);
const getBookingTypeId = async () => {
@ -315,9 +334,9 @@ const BSBillingEditQuantity = (props) => {
const openRadioDetails = () => {
// setDisableSubmitButton(false);
setRadioDetails(!RadioDetails);
setEditedPrice(0);
// setEditedPrice("");
// Clear ItemDiscount field and reset discount price
setItemDiscountPrice(0);
setItemDiscountPrice('');
itemDiscountFormRef.current?.resetFields();
};
@ -357,7 +376,6 @@ const BSBillingEditQuantity = (props) => {
};
const calculateOverAllQty = (item, filterItems) => {
if (!item) return 0;
const totalUsedQty =
@ -438,8 +456,10 @@ const BSBillingEditQuantity = (props) => {
};
const AddProductQuantity = async () => {
let disCountprice = safeRound(editedPrice) - itemDiscountPrice
let newPrice = safeRound(disCountprice > 0 ? disCountprice : props.Productdata.OrderRate);
let disCountprice = safeRound(editedPrice) - itemDiscountPrice;
let newPrice = safeRound(
disCountprice > 0 ? disCountprice : props.Productdata.OrderRate
);
await dispatch(changeHoldOrderDtl(false));
await dispatch(changePreviousOrderLength(CartOrderDetails?.length));
@ -461,17 +481,32 @@ const BSBillingEditQuantity = (props) => {
);
const editedProduct = CartOrderDetails[editedProductIndex];
if ((overAllLimitPreferenece || itemWiseLimitPreferenece) && maxQtyLimit) {
if (
(overAllLimitPreferenece || itemWiseLimitPreferenece) &&
maxQtyLimit
) {
if (overAllLimitPreferenece) {
const calculatedOverAllQty = calculateOverAllQtyLimit(CartOrderDetails?.filter((_, index) => index !== editedProductIndex));
if ((calculatedOverAllQty + editedQty) > maxQtyLimit) {
setMessageData(`Overall Quantity Limit Exceeds than ${maxQtyLimit}`);
const calculatedOverAllQty = calculateOverAllQtyLimit(
CartOrderDetails?.filter((_, index) => index !== editedProductIndex)
);
if (calculatedOverAllQty + editedQty > maxQtyLimit) {
setMessageData(
`Overall Quantity Limit Exceeds than ${maxQtyLimit}`
);
setMessageType('warning');
return;
}
} else if (itemWiseLimitPreferenece) {
const exceptEditedItemCart = calculateOverAllQtyLimit(CartOrderDetails?.filter((_, index) => index !== editedProductIndex && _.ProdId === editedProduct?.ProdId && _.InwardDtlId === editedProduct?.InwardDtlId));
const totalQtyForItem = ((exceptEditedItemCart || 0) + (editedQty || 0));
const exceptEditedItemCart = calculateOverAllQtyLimit(
CartOrderDetails?.filter(
(_, index) =>
index !== editedProductIndex &&
_.ProdId === editedProduct?.ProdId &&
_.InwardDtlId === editedProduct?.InwardDtlId
)
);
const totalQtyForItem =
(exceptEditedItemCart || 0) + (editedQty || 0);
if (totalQtyForItem > maxQtyLimit) {
setMessageData(`Item Quantity Limit Exceeds than ${maxQtyLimit}`);
setMessageType('warning');
@ -745,7 +780,8 @@ const BSBillingEditQuantity = (props) => {
newPrice,
overrideQty = null
) => {
const editedQty = overrideQty !== null
const editedQty =
overrideQty !== null
? overrideQty
: props?.Productdata?.ScaleType !== 'weight'
? parseInt(Quantity)
@ -3164,10 +3200,12 @@ const BSBillingEditQuantity = (props) => {
const updatedProduct = {
...editedProduct,
OrderQty: fixedQty,
OrderRate: editedPrice > 0 ? safeRound(editedPrice) : editedProduct?.OrderRate,
OrderRate:
editedPrice > 0 ? safeRound(editedPrice) : editedProduct?.OrderRate,
...calculateTaxAmounts({
qty: qty,
rate: editedPrice > 0 ? safeRound(editedPrice) : editedProduct?.OrderRate,
rate:
editedPrice > 0 ? safeRound(editedPrice) : editedProduct?.OrderRate,
taxPercentage: editedProduct?.TaxPercentage,
type: editedProduct?.Type,
product: editedProduct,
@ -3177,26 +3215,23 @@ const BSBillingEditQuantity = (props) => {
...(offerApply && {
Offer: qty * (editedPrice > 0 ? editedPrice : editedProduct?.OrderRate),
}),
...(
!offerApply && itemDiscountPrice > 0
...(!offerApply && itemDiscountPrice > 0
? {
DiscountAmt: safeRound(itemDiscountPrice*fixedQty ),
DiscountType: itemDiscountPercentageSelection === 'Fixed' ? 'F' : 'P',
DiscountAmt: safeRound(itemDiscountPrice * fixedQty),
DiscountType:
itemDiscountPercentageSelection === 'Fixed' ? 'F' : 'P',
DiscountValue:
itemDiscountPercentageSelection === 'Fixed'
? itemDiscountPrice*fixedQty
: (
(itemDiscountPrice*fixedQty /
(newPrice > 0 ? newPrice : editedProduct?.OrderRate)) * 100
)
? itemDiscountPrice * fixedQty
: ((itemDiscountPrice * fixedQty) /
(newPrice > 0 ? newPrice : editedProduct?.OrderRate)) *
100,
}
: {
DiscountAmt: null,
DiscountType: null,
DiscountValue: null
}
)
DiscountValue: null,
}),
};
if (hasOffer) {
@ -3256,7 +3291,6 @@ const BSBillingEditQuantity = (props) => {
OfferMessage: updatedProduct?.OfferMessage || bestOffer?.OfferMessage,
};
console.log(updatedProduct, 'updatedProduct');
const shouldRemove = (c) =>
@ -3301,7 +3335,7 @@ const BSBillingEditQuantity = (props) => {
const { OfferType = null, OfferPrice = 0 } = product;
let totalAmount = qty * rate;
totalAmount = totalAmount - (itemDiscountPrice*qty|| 0);
totalAmount = totalAmount - (itemDiscountPrice * qty || 0);
const taxAmount = (
(totalAmount * taxPercentage) /
(100 + taxPercentage)
@ -3327,6 +3361,8 @@ const BSBillingEditQuantity = (props) => {
const CloseModal = () => {
props.handleEditQuantityCancel();
setClearQuantity(false);
dispatch(changeCombofocus(false));
dispatch(changefocusStatusCust(false));
};
const onComplete = useCallback(() => {
setMessageData(null);
@ -3347,12 +3383,13 @@ const BSBillingEditQuantity = (props) => {
itemDiscountFormRef.current?.resetFields();
};
const ItemDiscountChangefun = (data) => {
const enteredDiscount = parseFloat(data?.target.value);
if (enteredDiscount) {
let roundedrice = safeRound(editedPrice ? editedPrice : 0)
const sellingPrice = parseFloat(roundedrice || props.Productdata?.SellingPrice || 0);
let roundedrice = safeRound(editedPrice ? editedPrice : 0);
const sellingPrice = parseFloat(
roundedrice || props.Productdata?.SellingPrice || 0
);
if (itemDiscountPercentageSelection === 'Fixed') {
if (parseFloat(enteredDiscount) < parseFloat(sellingPrice)) {
setItemDiscountPrice(parseFloat(enteredDiscount));
@ -3364,7 +3401,8 @@ const BSBillingEditQuantity = (props) => {
}
} else {
if (parseFloat(enteredDiscount) < 100) {
let discountAmt = (parseFloat(enteredDiscount) * parseFloat(sellingPrice)) / 100;
let discountAmt =
(parseFloat(enteredDiscount) * parseFloat(sellingPrice)) / 100;
setItemDiscountPrice(parseFloat(discountAmt));
} else {
setMessageType('error');
@ -3379,8 +3417,13 @@ const BSBillingEditQuantity = (props) => {
};
const PriceChangefun = (data) => {
const enteredDiscount = parseFloat(data?.target.value);
// Clear ItemDiscount field and reset discount price
const value = data?.target?.value;
if (value === '') {
setEditedPrice('');
setDisableSubmitButton(false);
formRef.current?.resetFields();
return;
}
setItemDiscountPrice(0);
itemDiscountFormRef.current?.resetFields();
@ -3490,11 +3533,20 @@ const BSBillingEditQuantity = (props) => {
}
} else {
setDisableSubmitButton(false);
setEditedPrice(0);
setEditedPrice('');
formRef.current?.resetFields();
}
};
const SellingPriceChange = (data) => {
if (data === '') {
setEditedPrice('');
setDisableSubmitButton(false);
formRef.current?.setFieldsValue({ SellPrice: '' });
setItemDiscountPrice('');
itemDiscountFormRef.current?.resetFields();
return;
}
if (data) {
const sellingPrice = parseFloat(props.Productdata?.SellingPrice || 0);
const limit = parseFloat(props.Productdata?.DiscountLimit || 0);
@ -3580,16 +3632,21 @@ const BSBillingEditQuantity = (props) => {
);
const editedProduct = {
...CartOrderDetails[editedProductIndex],
OrderQty: qty
OrderQty: qty,
};
await handleEditQuantity(editedProduct, editedProductIndex, editedProduct.OrderRate, qty);
await handleEditQuantity(
editedProduct,
editedProductIndex,
editedProduct.OrderRate,
qty
);
props.handleEditQuantityCancel();
setClearQuantity(false);
};
const isKg =
props?.Productdata?.Size == 1 &&
["KG", "KGS"].includes(props?.Productdata?.UomName?.toUpperCase());
['KG', 'KGS'].includes(props?.Productdata?.UomName?.toUpperCase());
return (
<div className="BSBilling-EditQuantity-Modal">
@ -3688,7 +3745,8 @@ const BSBillingEditQuantity = (props) => {
Packing
</button>
{isKg && (<button
{isKg && (
<button
type="button"
className={
RadioBtnSelection === 'weightAmount'
@ -3698,8 +3756,8 @@ const BSBillingEditQuantity = (props) => {
onClick={() => onRadioBtnChange('weightAmount')}
>
Weight / Amount
</button>)}
</button>
)}
</div>
{RadioBtnSelection == 'Quantity' && (
@ -3762,18 +3820,18 @@ const BSBillingEditQuantity = (props) => {
</>
)}
{RadioBtnSelection == 'Price' && (
<div style={{ display: "flex" }} >
<div style={{ display: 'flex' }}>
<div className="EditQuantity-PriceChange">
<label className="EditQuantity-itemname">
Item Price: {safeRound(props.Productdata.SellingPrice)} /
per item{' '}
Item Price: {props.Productdata.SellingPrice} / per
item{' '}
</label>
{!RadioDetails && (
<Form ref={formRef}>
<Form.Item
name="SellPrice"
initialValue={safeRound(editedPrice)}
initialValue={editedPrice}
rules={[
{
pattern: /^(0\d+|[1-9]\d*)(\.\d+)?$/,
@ -3799,21 +3857,13 @@ const BSBillingEditQuantity = (props) => {
value={editedPrice}
label="Price Override"
autocomplete="off"
onChange={(e) => { SellingPriceChange(e?.target?.value) }}
inputMode="decimal"
isOnChange={editedPrice > 0 ? true : false}
onInput={(e) => {
const cleanedValue = e.target.value.replace(
/[^0-9.]/g,
''
);
const parts = cleanedValue.split('.');
e.target.value =
parts.length > 2
? `${parts[0]}.${parts.slice(1).join('')}`
: cleanedValue;
onChange={(e) => {
SellingPriceChange(e?.target?.value);
}}
// isOnChange={formType == "edit" || formRef.current?.getFieldsValue()?.CustName ? true : false}
inputMode="decimal"
isOnChange={
editedPrice !== '' && Number(editedPrice) > 0
}
/>
</Form.Item>
</Form>
@ -3841,7 +3891,7 @@ const BSBillingEditQuantity = (props) => {
<Form ref={detailedFormRef}>
<Form.Item
name="SellPrice"
initialValue={safeRound(editedPrice)}
// initialValue={safeRound(editedPrice)}
rules={[
{
pattern: /^[0-9]\d*(\.\d+)?$/,
@ -3863,23 +3913,12 @@ const BSBillingEditQuantity = (props) => {
label="Reduction"
fieldState={true}
fieldApi={true}
// id="error2"
autocomplete="off"
onChange={(e) => PriceChangefun(e)}
onChange={PriceChangefun}
inputMode="decimal"
isOnChange={editedPrice > 0 ? true : false}
onInput={(e) => {
const cleanedValue = e.target.value.replace(
/[^0-9.]/g,
''
);
const parts = cleanedValue.split('.');
e.target.value =
parts.length > 2
? `${parts[0]}.${parts.slice(1).join('')}`
: cleanedValue;
}}
// isOnChange={formType == "edit" || formRef.current?.getFieldsValue()?.CustName ? true : false}
isOnChange={
editedPrice !== '' && Number(editedPrice) > 0
}
/>
</Form.Item>
{/* <input type="text"
@ -3888,17 +3927,25 @@ const BSBillingEditQuantity = (props) => {
/> */}
</Form>
</div>
{editedPrice > 0 && <div className="EditQuantity-Quantity">
{editedPrice > 0 && (
<div className="EditQuantity-Quantity">
<div className="EditQuantity-itemname">
{' '}
Price: {safeRound(editedPrice ? editedPrice : 0)}
</div>
</div>}
</div>
)}
</>
)}
</div>
<div style={{ borderLeft: "1px solid #ddd", paddingLeft: "15px", marginLeft: "15px" }}>
{itemDiscount && (
<div
style={{
borderLeft: '1px solid #ddd',
paddingLeft: '15px',
marginLeft: '15px',
}}
>
<label className="EditQuantity-itemname">
Item Discount
</label>
@ -3935,6 +3982,7 @@ const BSBillingEditQuantity = (props) => {
]}
>
<InputField
ref={discountRef}
field="ItemDiscount"
name="ItemDiscount"
value={itemDiscountPrice}
@ -3942,35 +3990,29 @@ const BSBillingEditQuantity = (props) => {
fieldState={true}
fieldApi={true}
autocomplete="off"
onChange={(e) => ItemDiscountChangefun(e)}
onChange={ItemDiscountChangefun}
inputMode="decimal"
onInput={(e) => {
const cleanedValue = e.target.value.replace(
/[^0-9.]/g,
''
);
const parts = cleanedValue.split('.');
e.target.value =
parts.length > 2
? `${parts[0]}.${parts.slice(1).join('')}`
: cleanedValue;
}}
/>
</Form.Item>
</Form>
</div>
{itemDiscountPrice > 0 && safeRound(editedPrice) > 0 && <div className="EditQuantity-Quantity">
{Number(itemDiscountPrice) > 0 &&
safeRound(editedPrice) > 0 && (
<div className="EditQuantity-Quantity">
<div className="EditQuantity-itemname">
{' '}
{console.log(editedPrice, itemDiscountPrice, "itemDiscountPrice")}
Final Price: {safeRound(editedPrice) - (itemDiscountPrice || 0)}
Final Price:{' '}
{(
Number(safeRound(editedPrice)) -
Number(itemDiscountPrice || 0)
).toFixed(2)}
</div>
</div>}
</div>
)}
</>
</div>
)}
</div>
)}
{RadioBtnSelection == 'Parcel' && (
<>
@ -3986,7 +4028,7 @@ const BSBillingEditQuantity = (props) => {
/>
</>
)}
{(RadioBtnSelection == 'weightAmount') && isKg && (
{RadioBtnSelection == 'weightAmount' && isKg && (
<>
<WeightCalculatePrice
CartOrderDetails={CartOrderDetails}

View File

@ -58,9 +58,16 @@ const PreferenceList = () => {
const settingsList = tableValue[0]?.SettingDtlDetails ?? preferenceConfigs;
const allSettingsMap = {};
settingsList?.forEach(({ SettingIdName, SettingValue, SettingCount, SettingTime,Comments }) => {
allSettingsMap[SettingIdName?.toLowerCase()] = { value: SettingValue, count: SettingCount, time: SettingTime?.split(' ')?.[0], comments: Comments };
});
settingsList?.forEach(
({ SettingIdName, SettingValue, SettingCount, SettingTime, Comments }) => {
allSettingsMap[SettingIdName?.toLowerCase()] = {
value: SettingValue,
count: SettingCount,
time: SettingTime?.split(' ')?.[0],
comments: Comments,
};
}
);
console.log(featureaddDetails, 'featureaddDetails');
@ -89,16 +96,35 @@ const PreferenceList = () => {
wholesaleshortname: allSettingsMap['wholesaleshortname']?.comments || 'WS',
billitemsorder: allSettingsMap['billitemsorder']?.value === 'Y',
preorderpricechange: allSettingsMap['preorderpricechange']?.value === 'Y',
quantityrestriction: allSettingsMap['overalllimit']?.value === 'Y' || allSettingsMap['itemwiselimit']?.value === 'Y',
quantityrestrictiontype: allSettingsMap['overalllimit']?.value === 'Y' ? 'overall' : allSettingsMap['itemwiselimit']?.value === 'Y' ? 'itemwise' : 'overall',
kiosktimelimit: allSettingsMap['hours']?.value === 'Y' || allSettingsMap['minutes']?.value === 'Y',
kiosktimelimittype: allSettingsMap['hours']?.value === 'Y' ? 'hours' : allSettingsMap['minutes']?.value === 'Y' ? 'minutes' : 'minutes',
maxquantity: allSettingsMap['overalllimit']?.value === 'Y' ? allSettingsMap['overalllimit']?.count || 1 : allSettingsMap['itemwiselimit']?.value === 'Y' ? allSettingsMap['itemwiselimit']?.count || 1 : 1,
quantityrestriction:
allSettingsMap['overalllimit']?.value === 'Y' ||
allSettingsMap['itemwiselimit']?.value === 'Y',
quantityrestrictiontype:
allSettingsMap['overalllimit']?.value === 'Y'
? 'overall'
: allSettingsMap['itemwiselimit']?.value === 'Y'
? 'itemwise'
: 'overall',
kiosktimelimit:
allSettingsMap['hours']?.value === 'Y' ||
allSettingsMap['minutes']?.value === 'Y',
kiosktimelimittype:
allSettingsMap['hours']?.value === 'Y'
? 'hours'
: allSettingsMap['minutes']?.value === 'Y'
? 'minutes'
: 'minutes',
maxquantity:
allSettingsMap['overalllimit']?.value === 'Y'
? allSettingsMap['overalllimit']?.count || 1
: allSettingsMap['itemwiselimit']?.value === 'Y'
? allSettingsMap['itemwiselimit']?.count || 1
: 1,
maxtime:
allSettingsMap['hours']?.value === 'Y'
? (allSettingsMap['hours']?.time
? allSettingsMap['hours']?.time
? parseFloat(allSettingsMap['hours']?.time / 60)
: 0.5)
: 0.5
: allSettingsMap['minutes']?.value === 'Y'
? parseFloat(allSettingsMap['minutes']?.time || 30)
: 30,
@ -118,14 +144,19 @@ const PreferenceList = () => {
),
mobilea4: allSettingsMap['mobilea4']?.value === 'Y',
estimateSettings: [
...(allSettingsMap['estimateprintheader']?.value === 'Y' ? ['estimateprintheader'] : []),
...(allSettingsMap['estimatetitle']?.value === 'Y' ? ['estimatetitle'] : []),
...(allSettingsMap['estimateprintheader']?.value === 'Y'
? ['estimateprintheader']
: []),
...(allSettingsMap['estimatetitle']?.value === 'Y'
? ['estimatetitle']
: []),
],
scanlayout: allSettingsMap['scanlayout']?.value === 'Y',
verifyproduct: allSettingsMap['verifyproduct']?.value === 'Y',
imeidetails: allSettingsMap['imeidetails']?.value === 'Y',
customisedbillnumber: allSettingsMap['customisedbillnumber']?.value === 'Y',
upiqr: allSettingsMap['upiqr']?.value === 'Y',
itemdiscount: allSettingsMap['itemdiscount']?.value === 'Y',
lowstockreport: allSettingsMap['lowstockreport']?.value === 'Y',
weeklysalesreport: allSettingsMap['weeklysalesreport']?.value === 'Y',
notificationblink: allSettingsMap['notificationblink']?.value === 'Y',
@ -245,7 +276,7 @@ const PreferenceList = () => {
res?.data?.data?.map((i) => ({
SettingIdName: i.ConfigName,
SettingId: i.ConfigId,
Comments: i.Comments || "",
Comments: i.Comments || '',
SettingValue: 'N',
}))
);
@ -305,9 +336,9 @@ const PreferenceList = () => {
const handleSubmit = async () => {
const values = formRef.current.getFieldsValue();
const salesMode = values.salesmode;
console.log("Sales Mode:", values.salesmode);
console.log("Retail Short Name:", values.retailshortname);
console.log("Wholesale Short Name:", values.wholesaleshortname);
console.log('Sales Mode:', values.salesmode);
console.log('Retail Short Name:', values.retailshortname);
console.log('Wholesale Short Name:', values.wholesaleshortname);
const settings = settingsList || [];
console.log(values, 'values');
const updatedSettings = settings.map((setting) => {
@ -336,14 +367,20 @@ console.log("Wholesale Short Name:", values.wholesaleshortname);
imeidetails: values.imeidetails,
customisedbillnumber: values.customisedbillnumber,
upiqr: values.upiqr,
itemdiscount: values.itemdiscount,
lowstockreport: values.lowstockreport,
weeklysalesreport: values.weeklysalesreport,
notificationblink: values.notificationblink,
editbill: values.editbill,
overalllimit: values.quantityrestriction && values.quantityrestrictiontype === 'overall',
itemwiselimit: values.quantityrestriction && values.quantityrestrictiontype === 'itemwise',
overalllimit:
values.quantityrestriction &&
values.quantityrestrictiontype === 'overall',
itemwiselimit:
values.quantityrestriction &&
values.quantityrestrictiontype === 'itemwise',
hours: values.kiosktimelimit && values.kiosktimelimittype === 'hours',
minutes: values.kiosktimelimit && values.kiosktimelimittype === 'minutes',
minutes:
values.kiosktimelimit && values.kiosktimelimittype === 'minutes',
};
const arrayValues = {
@ -376,33 +413,33 @@ console.log("Wholesale Short Name:", values.wholesaleshortname);
SettingId: setting.SettingId,
Comments:
key === "retailshortname"
? values.retailshortname || ""
: key === "wholesaleshortname"
? values.wholesaleshortname || ""
: setting.Comments || "",
key === 'retailshortname'
? values.retailshortname || ''
: key === 'wholesaleshortname'
? values.wholesaleshortname || ''
: setting.Comments || '',
SettingValue:
key === "retailshortname" || key === "wholesaleshortname"
key === 'retailshortname' || key === 'wholesaleshortname'
? salesMode
? "Y"
: "N"
? 'Y'
: 'N'
: isChecked
? "Y"
: "N",
? 'Y'
: 'N',
SettingCount:
(key === "overalllimit" || key === "itemwiselimit") && isChecked
(key === 'overalllimit' || key === 'itemwiselimit') && isChecked
? parseFloat(values.maxquantity) || null
: null,
SettingTime:
key === "hours" && isChecked
? (parseFloat(values.maxtime) * 60).toFixed(2) + " Minutes"
: key === "minutes" && isChecked
? parseFloat(values.maxtime).toFixed(2) + " Minutes"
key === 'hours' && isChecked
? (parseFloat(values.maxtime) * 60).toFixed(2) + ' Minutes'
: key === 'minutes' && isChecked
? parseFloat(values.maxtime).toFixed(2) + ' Minutes'
: null,
};
};
});
const payload = {
@ -569,19 +606,47 @@ console.log("Wholesale Short Name:", values.wholesaleshortname);
</Form.Item>
)}
{featureaddDetails?.find(
(item) => item?.FeatureAddonName?.toLowerCase() === 'kiosk sales'
) && renderCheckbox('kioskotp', 'Enable OTP verification for Kiosk Orders?')}
(item) =>
item?.FeatureAddonName?.toLowerCase() === 'kiosk sales'
) &&
renderCheckbox(
'kioskotp',
'Enable OTP verification for Kiosk Orders?'
)}
{featureaddDetails?.find(
(item) => item?.FeatureAddonName?.toLowerCase() === 'kiosk sales'
) && (allSettingsMap['hours'] !== undefined || allSettingsMap['minutes'] !== undefined) && <>
<Form.Item name="kiosktimelimit" label="Restrict orders for the same customer within a time limit?" valuePropName="checked">
(item) =>
item?.FeatureAddonName?.toLowerCase() === 'kiosk sales'
) &&
(allSettingsMap['hours'] !== undefined ||
allSettingsMap['minutes'] !== undefined) && (
<>
<Form.Item
name="kiosktimelimit"
label="Restrict orders for the same customer within a time limit?"
valuePropName="checked"
>
<Checkbox>Yes</Checkbox>
</Form.Item>
<Form.Item noStyle shouldUpdate={(prev, curr) => prev.kiosktimelimit !== curr.kiosktimelimit}>
{({ getFieldValue }) => getFieldValue('kiosktimelimit') && (
<Form.Item
noStyle
shouldUpdate={(prev, curr) =>
prev.kiosktimelimit !== curr.kiosktimelimit
}
>
{({ getFieldValue }) =>
getFieldValue('kiosktimelimit') && (
<>
<Form.Item name="kiosktimelimittype" label="How would you like to apply the time restriction?">
<Radio.Group onChange={() => formRef.current?.setFieldsValue({ maxtime: undefined })}>
<Form.Item
name="kiosktimelimittype"
label="How would you like to apply the time restriction?"
>
<Radio.Group
onChange={() =>
formRef.current?.setFieldsValue({
maxtime: undefined,
})
}
>
{allSettingsMap['minutes'] !== undefined && (
<Radio value="minutes">Minutes</Radio>
)}
@ -594,11 +659,13 @@ console.log("Wholesale Short Name:", values.wholesaleshortname);
<Form.Item
noStyle
shouldUpdate={(prev, curr) =>
prev.kiosktimelimittype !== curr.kiosktimelimittype
prev.kiosktimelimittype !==
curr.kiosktimelimittype
}
>
{({ getFieldValue }) => {
const type = getFieldValue('kiosktimelimittype');
const type =
getFieldValue('kiosktimelimittype');
const isHours = type === 'hours';
@ -607,7 +674,10 @@ console.log("Wholesale Short Name:", values.wholesaleshortname);
name="maxtime"
label={`Maximum Time Limit (${isHours ? 'Hours' : 'Minutes'}):`}
rules={[
{ required: true, message: 'Please enter maximum time' },
{
required: true,
message: 'Please enter maximum time',
},
{
type: 'number',
min: isHours ? 0.25 : 1,
@ -628,9 +698,11 @@ console.log("Wholesale Short Name:", values.wholesaleshortname);
}}
</Form.Item>
</>
)}
)
}
</Form.Item>
</>}
</>
)}
</div>
<Divider />
@ -741,7 +813,7 @@ console.log("Wholesale Short Name:", values.wholesaleshortname);
{renderCheckbox('weightasquantity', 'Use Weight as Quantity?')}
{renderCheckbox('expiredselection', 'Show product expiry date?')}
{/* {renderCheckbox('sales mode', 'Retail or Wholesale mode?')} */}
{(allSettingsMap['sales mode'] !== undefined ) && (
{allSettingsMap['sales mode'] !== undefined && (
<>
<Form.Item
name="salesmode"
@ -762,20 +834,27 @@ console.log("Wholesale Short Name:", values.wholesaleshortname);
<Form.Item
name="retailshortname"
label="Retail Short Name"
rules={[
{ required: true, message: "Please enter Retail Short Name" },
{
required: true,
message: 'Please enter Retail Short Name',
},
]}
>
<InputField placeholder="Enter Retail Short Name" style={{ width: 250 }} />
<InputField
placeholder="Enter Retail Short Name"
style={{ width: 250 }}
/>
</Form.Item>
<Form.Item
name="wholesaleshortname"
label="Wholesale Short Name"
rules={[
{ required: true, message: "Please enter Wholesale Short Name" },
{
required: true,
message: 'Please enter Wholesale Short Name',
},
]}
>
<InputField
@ -809,24 +888,53 @@ console.log("Wholesale Short Name:", values.wholesaleshortname);
)}
{renderCheckbox('scanlayout', 'Do you Want Scan Layout Page?')}
{renderCheckbox('upiqr', 'Do you want to show the UPI QR code?')}
{renderCheckbox(
'itemdiscount',
'Do you want to show the Item Discount in Price OverRide?'
)}
{/* {renderCheckbox('editbill', 'Do you want to edit the previously created bill?')} */}
{(allSettingsMap['overalllimit'] !== undefined || allSettingsMap['itemwiselimit'] !== undefined) && (
{(allSettingsMap['overalllimit'] !== undefined ||
allSettingsMap['itemwiselimit'] !== undefined) && (
<>
<Form.Item name="quantityrestriction" label="Do you want to restrict the quantity that can be sold in a single order?" valuePropName="checked">
<Form.Item
name="quantityrestriction"
label="Do you want to restrict the quantity that can be sold in a single order?"
valuePropName="checked"
>
<Checkbox>Yes</Checkbox>
</Form.Item>
<Form.Item noStyle shouldUpdate={(prev, curr) => prev.quantityrestriction !== curr.quantityrestriction}>
{({ getFieldValue }) => getFieldValue('quantityrestriction') && (
<Form.Item
noStyle
shouldUpdate={(prev, curr) =>
prev.quantityrestriction !== curr.quantityrestriction
}
>
{({ getFieldValue }) =>
getFieldValue('quantityrestriction') && (
<>
<Form.Item name="quantityrestrictiontype" label="How would you like to apply the quantity restriction?">
<Radio.Group onChange={() => formRef.current?.setFieldsValue({ maxquantity: undefined })}>
<Form.Item
name="quantityrestrictiontype"
label="How would you like to apply the quantity restriction?"
>
<Radio.Group
onChange={() =>
formRef.current?.setFieldsValue({
maxquantity: undefined,
})
}
>
{allSettingsMap['overalllimit'] !== undefined && (
<Radio value="overall">Overall Order Quantity</Radio>
<Radio value="overall">
Overall Order Quantity
</Radio>
)}
{allSettingsMap['itemwiselimit'] !== undefined && (
<Radio value="itemwise">Item-wise Quantity</Radio>
{allSettingsMap['itemwiselimit'] !==
undefined && (
<Radio value="itemwise">
Item-wise Quantity
</Radio>
)}
</Radio.Group>
</Form.Item>
@ -835,14 +943,22 @@ console.log("Wholesale Short Name:", values.wholesaleshortname);
name="maxquantity"
label="Maximum quantity allowed:"
rules={[
{ required: true, message: 'Please enter maximum quantity' },
{ type: 'number', min: 1, message: 'Quantity must be greater than 0' }
{
required: true,
message: 'Please enter maximum quantity',
},
{
type: 'number',
min: 1,
message: 'Quantity must be greater than 0',
},
]}
>
<InputNumber min={1} style={{ width: '200px' }} />
</Form.Item>
</>
)}
)
}
</Form.Item>
</>
)}
@ -969,10 +1085,14 @@ console.log("Wholesale Short Name:", values.wholesaleshortname);
>
<Checkbox.Group>
{allSettingsMap['estimateprintheader'] !== undefined && (
<Checkbox value="estimateprintheader">Show shop header (Name, Address, GST)</Checkbox>
<Checkbox value="estimateprintheader">
Show shop header (Name, Address, GST)
</Checkbox>
)}
{allSettingsMap['estimatetitle'] !== undefined && (
<Checkbox value="estimatetitle">Show Estimate (R/W) title</Checkbox>
<Checkbox value="estimatetitle">
Show Estimate (R/W) title
</Checkbox>
)}
</Checkbox.Group>
</Form.Item>