Constrain the overall qty

This commit is contained in:
unknown 2026-02-24 14:24:20 +05:30
parent f717c55f67
commit 58e1a5e7a7
1 changed files with 201 additions and 163 deletions

View File

@ -1,6 +1,6 @@
import { useCallback, useEffect, useRef, useState } from 'react'; import { useCallback, useEffect, useRef, useState } from 'react';
import { useDispatch, useSelector } from 'react-redux'; import { useDispatch, useSelector } from 'react-redux';
import { Form, Checkbox, Radio, Divider } from 'antd'; import { Form, Checkbox, Radio, Divider, InputNumber } from 'antd';
import { ArrowRightOutlined } from '@ant-design/icons'; import { ArrowRightOutlined } from '@ant-design/icons';
import FormHeader from '../PageComponents/FormHeader.jsx'; import FormHeader from '../PageComponents/FormHeader.jsx';
import Buttons from '../../Components/Forms/Buttons.jsx'; import Buttons from '../../Components/Forms/Buttons.jsx';
@ -57,68 +57,71 @@ const PreferenceList = () => {
const settingsList = tableValue[0]?.SettingDtlDetails ?? preferenceConfigs; const settingsList = tableValue[0]?.SettingDtlDetails ?? preferenceConfigs;
const allSettingsMap = {}; const allSettingsMap = {};
settingsList?.forEach(({ SettingIdName, SettingValue }) => { settingsList?.forEach(({ SettingIdName, SettingValue, SettingCount }) => {
allSettingsMap[SettingIdName?.toLowerCase()] = SettingValue; allSettingsMap[SettingIdName?.toLowerCase()] = { value: SettingValue, count: SettingCount };
}); });
console.log(allSettingsMap, 'allSettingsMapallSettingsMapallSettingsMap'); console.log(settingsList, 'settingsList');
const buildInitialValues = () => ({ const buildInitialValues = () => ({
dashboard: allSettingsMap['dashboard'] === 'Y', dashboard: allSettingsMap['dashboard']?.value === 'Y',
shortcutkeys: allSettingsMap['shortcutkeys'] === 'Y', shortcutkeys: allSettingsMap['shortcutkeys']?.value === 'Y',
autoreceivestock: allSettingsMap['autoreceivestock'] === 'Y', autoreceivestock: allSettingsMap['autoreceivestock']?.value === 'Y',
decimal: allSettingsMap['decimal'] === 'Y', decimal: allSettingsMap['decimal']?.value === 'Y',
enabledModules: [ enabledModules: [
...(allSettingsMap['dinein'] === 'Y' ? ['dinein'] : []), ...(allSettingsMap['dinein']?.value === 'Y' ? ['dinein'] : []),
...(allSettingsMap['estimation'] === 'Y' ? ['estimation'] : []), ...(allSettingsMap['estimation']?.value === 'Y' ? ['estimation'] : []),
], ],
searchfocus: allSettingsMap['searchfocus'] === 'Y', searchfocus: allSettingsMap['searchfocus']?.value === 'Y',
addproductcard: allSettingsMap['addproductcard'] === 'Y', addproductcard: allSettingsMap['addproductcard']?.value === 'Y',
enabledFeatures: [ enabledFeatures: [
...(allSettingsMap['parking'] === 'Y' ? ['parking'] : []), ...(allSettingsMap['parking']?.value === 'Y' ? ['parking'] : []),
...(allSettingsMap['offer'] === 'Y' ? ['offer'] : []), ...(allSettingsMap['offer']?.value === 'Y' ? ['offer'] : []),
], ],
stockselection: allSettingsMap['stockselection'] === 'Y', stockselection: allSettingsMap['stockselection']?.value === 'Y',
weightasquantity: allSettingsMap['weightasquantity'] === 'Y', weightasquantity: allSettingsMap['weightasquantity']?.value === 'Y',
expiredselection: allSettingsMap['expiredselection'] === 'Y', expiredselection: allSettingsMap['expiredselection']?.value === 'Y',
'sales mode': allSettingsMap['sales mode'] === 'Y', 'sales mode': allSettingsMap['sales mode']?.value === 'Y',
billitemsorder: allSettingsMap['billitemsorder'] === 'Y', billitemsorder: allSettingsMap['billitemsorder']?.value === 'Y',
preorderpricechange: allSettingsMap['preorderpricechange'] === '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',
maxquantity: allSettingsMap['overalllimit']?.value === 'Y' ? allSettingsMap['overalllimit']?.count || 1 : allSettingsMap['itemwiselimit']?.value === 'Y' ? allSettingsMap['itemwiselimit']?.count || 1 : 1,
billOption: ['whatsapp', 'sms', 'email'].some( billOption: ['whatsapp', 'sms', 'email'].some(
(k) => allSettingsMap[k] === 'Y' (k) => allSettingsMap[k]?.value === 'Y'
) )
? 'pdf' ? 'pdf'
: 'print', : 'print',
pdfSendOptions: ['whatsapp', 'email', 'sms'].filter( pdfSendOptions: ['whatsapp', 'email', 'sms'].filter(
(k) => allSettingsMap[k] === 'Y' (k) => allSettingsMap[k]?.value === 'Y'
), ),
tokenonly: allSettingsMap['tokenonly'] === 'Y', tokenonly: allSettingsMap['tokenonly']?.value === 'Y',
allproductindividualtoken: allproductindividualtoken:
allSettingsMap['allproductindividualtoken'] === 'Y', allSettingsMap['allproductindividualtoken']?.value === 'Y',
printOptions: ['printuom', 'printlogo', 'printgreetings'].filter( printOptions: ['printuom', 'printlogo', 'printgreetings'].filter(
(k) => allSettingsMap[k] === 'Y' (k) => allSettingsMap[k]?.value === 'Y'
), ),
mobilea4: allSettingsMap['mobilea4'] === 'Y', mobilea4: allSettingsMap['mobilea4']?.value === 'Y',
estimateprintheader: allSettingsMap['estimateprintheader'] === 'Y', estimateprintheader: allSettingsMap['estimateprintheader']?.value === 'Y',
scanlayout: allSettingsMap['scanlayout'] === 'Y', scanlayout: allSettingsMap['scanlayout']?.value === 'Y',
verifyproduct: allSettingsMap['verifyproduct'] === 'Y', verifyproduct: allSettingsMap['verifyproduct']?.value === 'Y',
customisedbillnumber: allSettingsMap['customisedbillnumber'] === 'Y', customisedbillnumber: allSettingsMap['customisedbillnumber']?.value === 'Y',
upiqr: allSettingsMap['upiqr'] === 'Y', upiqr: allSettingsMap['upiqr']?.value === 'Y',
lowstockreport: allSettingsMap['lowstockreport'] === 'Y', lowstockreport: allSettingsMap['lowstockreport']?.value === 'Y',
weeklysalesreport: allSettingsMap['weeklysalesreport'] === 'Y', weeklysalesreport: allSettingsMap['weeklysalesreport']?.value === 'Y',
notificationblink: allSettingsMap['notificationblink'] === 'Y', notificationblink: allSettingsMap['notificationblink']?.value === 'Y',
onlineindivdualslots: allSettingsMap['onlineindivdualslots'] === 'Y', onlineindivdualslots: allSettingsMap['onlineindivdualslots']?.value === 'Y',
editbill: allSettingsMap['editbill'] === 'Y', editbill: allSettingsMap['editbill']?.value === 'Y',
notification: [ notification: [
...(allSettingsMap['onbilltime'] === 'Y' ? ['onbilltime'] : []), ...(allSettingsMap['onbilltime']?.value === 'Y' ? ['onbilltime'] : []),
...(allSettingsMap['1daybefore'] === 'Y' ? ['1daybefore'] : []), ...(allSettingsMap['1daybefore']?.value === 'Y' ? ['1daybefore'] : []),
...(allSettingsMap['1hourbefore'] === 'Y' ? ['1hourbefore'] : []), ...(allSettingsMap['1hourbefore']?.value === 'Y' ? ['1hourbefore'] : []),
], ],
BookingOptionsandmethod: [ BookingOptionsandmethod: [
...(allSettingsMap['allow individual booking'] === 'Y' ...(allSettingsMap['allow individual booking']?.value === 'Y'
? ['allow individual booking'] ? ['allow individual booking']
: []), : []),
...(allSettingsMap['single booking only'] === 'Y' ...(allSettingsMap['single booking only']?.value === 'Y'
? ['single booking only'] ? ['single booking only']
: []), : []),
], ],
@ -310,6 +313,8 @@ const PreferenceList = () => {
weeklysalesreport: values.weeklysalesreport, weeklysalesreport: values.weeklysalesreport,
notificationblink: values.notificationblink, notificationblink: values.notificationblink,
editbill: values.editbill, editbill: values.editbill,
overalllimit: values.quantityrestriction && values.quantityrestrictiontype === 'overall',
itemwiselimit: values.quantityrestriction && values.quantityrestrictiontype === 'itemwise',
}; };
const arrayValues = { const arrayValues = {
@ -340,6 +345,7 @@ const PreferenceList = () => {
SettingId: setting.SettingId, SettingId: setting.SettingId,
Comments: setting.Comments || 'Enter Comment', Comments: setting.Comments || 'Enter Comment',
SettingValue: isChecked ? 'Y' : 'N', SettingValue: isChecked ? 'Y' : 'N',
SettingCount: ((key === 'overalllimit' || key === 'itemwiselimit') && isChecked) ? parseFloat(values.maxquantity) || null : null
}; };
}); });
@ -482,25 +488,25 @@ const PreferenceList = () => {
{(allSettingsMap['onlineindividualslots'] !== undefined || {(allSettingsMap['onlineindividualslots'] !== undefined ||
allSettingsMap['allow individual booking'] !== undefined || allSettingsMap['allow individual booking'] !== undefined ||
allSettingsMap['single booking only'] !== undefined) && ( allSettingsMap['single booking only'] !== undefined) && (
<Form.Item <Form.Item
name="BookingOptionsandmethod" name="BookingOptionsandmethod"
label="Individual Selling Setup" label="Individual Selling Setup"
> >
<Checkbox.Group> <Checkbox.Group>
{allSettingsMap['allow individual booking'] !== {allSettingsMap['allow individual booking'] !==
undefined && ( undefined && (
<Checkbox value="allow individual booking"> <Checkbox value="allow individual booking">
Allow online individual booking Allow online individual booking
</Checkbox> </Checkbox>
)} )}
{allSettingsMap['single booking only'] !== undefined && ( {allSettingsMap['single booking only'] !== undefined && (
<Checkbox value="single booking only"> <Checkbox value="single booking only">
Allow single booking Only Allow single booking Only
</Checkbox> </Checkbox>
)} )}
</Checkbox.Group> </Checkbox.Group>
</Form.Item> </Form.Item>
)} )}
</div> </div>
<Divider /> <Divider />
@ -532,23 +538,23 @@ const PreferenceList = () => {
{(allSettingsMap['onbilltime'] !== undefined || {(allSettingsMap['onbilltime'] !== undefined ||
allSettingsMap['1daybefore'] !== undefined || allSettingsMap['1daybefore'] !== undefined ||
allSettingsMap['1hourbefore'] !== undefined) && ( allSettingsMap['1hourbefore'] !== undefined) && (
<Form.Item <Form.Item
name="notification" name="notification"
label="Choose notification timing:" label="Choose notification timing:"
> >
<Checkbox.Group> <Checkbox.Group>
{allSettingsMap['onbilltime'] !== undefined && ( {allSettingsMap['onbilltime'] !== undefined && (
<Checkbox value="onbilltime">On Bill Time</Checkbox> <Checkbox value="onbilltime">On Bill Time</Checkbox>
)} )}
{allSettingsMap['1daybefore'] !== undefined && ( {allSettingsMap['1daybefore'] !== undefined && (
<Checkbox value="1daybefore">1 Day Before</Checkbox> <Checkbox value="1daybefore">1 Day Before</Checkbox>
)} )}
{allSettingsMap['1hourbefore'] !== undefined && ( {allSettingsMap['1hourbefore'] !== undefined && (
<Checkbox value="1hourbefore">1 Hour Before</Checkbox> <Checkbox value="1hourbefore">1 Hour Before</Checkbox>
)} )}
</Checkbox.Group> </Checkbox.Group>
</Form.Item> </Form.Item>
)} )}
</div> </div>
<div <div
@ -575,37 +581,37 @@ const PreferenceList = () => {
{(allSettingsMap['offer'] !== undefined || {(allSettingsMap['offer'] !== undefined ||
allSettingsMap['parking'] !== undefined) && ( allSettingsMap['parking'] !== undefined) && (
<Form.Item <Form.Item
name="enabledFeatures" name="enabledFeatures"
label="Select the features you want to enable:" label="Select the features you want to enable:"
> >
<Checkbox.Group> <Checkbox.Group>
{allSettingsMap['parking'] !== undefined && ( {allSettingsMap['parking'] !== undefined && (
<Checkbox value="parking">Parking</Checkbox> <Checkbox value="parking">Parking</Checkbox>
)} )}
{allSettingsMap['offer'] !== undefined && ( {allSettingsMap['offer'] !== undefined && (
<Checkbox value="offer">Offer</Checkbox> <Checkbox value="offer">Offer</Checkbox>
)} )}
</Checkbox.Group> </Checkbox.Group>
</Form.Item> </Form.Item>
)} )}
{((allSettingsMap['dinein'] !== undefined && dinePreference) || {((allSettingsMap['dinein'] !== undefined && dinePreference) ||
allSettingsMap['estimation'] !== undefined) && ( allSettingsMap['estimation'] !== undefined) && (
<Form.Item <Form.Item
name="enabledModules" name="enabledModules"
label="Select the modules you want to enable:" label="Select the modules you want to enable:"
> >
<Checkbox.Group> <Checkbox.Group>
{allSettingsMap['dinein'] !== undefined && {allSettingsMap['dinein'] !== undefined &&
dinePreference && ( dinePreference && (
<Checkbox value="dinein">Dine-In</Checkbox> <Checkbox value="dinein">Dine-In</Checkbox>
)}
{allSettingsMap['estimation'] !== undefined && (
<Checkbox value="estimation">Estimation</Checkbox>
)} )}
{allSettingsMap['estimation'] !== undefined && ( </Checkbox.Group>
<Checkbox value="estimation">Estimation</Checkbox> </Form.Item>
)} )}
</Checkbox.Group>
</Form.Item>
)}
{renderCheckbox('stockselection', 'Enable stock selection?')} {renderCheckbox('stockselection', 'Enable stock selection?')}
{renderCheckbox('weightasquantity', 'Use Weight as Quantity?')} {renderCheckbox('weightasquantity', 'Use Weight as Quantity?')}
@ -630,6 +636,38 @@ const PreferenceList = () => {
{renderCheckbox('scanlayout', 'Do you Want Scan Layout Page?')} {renderCheckbox('scanlayout', 'Do you Want Scan Layout Page?')}
{renderCheckbox('upiqr', 'Do you want to show the UPI QR code?')} {renderCheckbox('upiqr', 'Do you want to show the UPI QR code?')}
{/* {renderCheckbox('editbill', 'Do you want to edit the previously created bill?')} */} {/* {renderCheckbox('editbill', 'Do you want to edit the previously created bill?')} */}
{(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">
<Checkbox>Yes</Checkbox>
</Form.Item>
<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 })}>
<Radio value="overall">Overall Order Quantity</Radio>
<Radio value="itemwise">Item-wise Quantity</Radio>
</Radio.Group>
</Form.Item>
<Form.Item
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' }
]}
>
<InputNumber min={1} style={{ width: '200px' }} />
</Form.Item>
</>
)}
</Form.Item>
</>
)}
</div> </div>
<Divider /> <Divider />
@ -652,46 +690,46 @@ const PreferenceList = () => {
{['whatsapp', 'sms', 'email'].some( {['whatsapp', 'sms', 'email'].some(
(k) => allSettingsMap[k] !== undefined (k) => allSettingsMap[k] !== undefined
) && ( ) && (
<> <>
<Form.Item <Form.Item
name="billOption" name="billOption"
label="Choose how to handle bills:" label="Choose how to handle bills:"
> >
<Radio.Group> <Radio.Group>
<Radio value="print">Print Bill</Radio> <Radio value="print">Print Bill</Radio>
<Radio value="pdf">Send PDF</Radio> <Radio value="pdf">Send PDF</Radio>
</Radio.Group> </Radio.Group>
</Form.Item> </Form.Item>
<Form.Item <Form.Item
noStyle noStyle
shouldUpdate={(prev, curr) => shouldUpdate={(prev, curr) =>
prev.billOption !== curr.billOption prev.billOption !== curr.billOption
} }
> >
{({ getFieldValue }) => {({ getFieldValue }) =>
getFieldValue('billOption') === 'pdf' && ( getFieldValue('billOption') === 'pdf' && (
<Form.Item <Form.Item
name="pdfSendOptions" name="pdfSendOptions"
label="Select how to send the PDF:" label="Select how to send the PDF:"
> >
<Checkbox.Group> <Checkbox.Group>
{allSettingsMap['whatsapp'] !== undefined && ( {allSettingsMap['whatsapp'] !== undefined && (
<Checkbox value="whatsapp">WhatsApp</Checkbox> <Checkbox value="whatsapp">WhatsApp</Checkbox>
)} )}
{allSettingsMap['email'] !== undefined && ( {allSettingsMap['email'] !== undefined && (
<Checkbox value="email">Email</Checkbox> <Checkbox value="email">Email</Checkbox>
)} )}
{allSettingsMap['sms'] !== undefined && ( {allSettingsMap['sms'] !== undefined && (
<Checkbox value="sms">SMS</Checkbox> <Checkbox value="sms">SMS</Checkbox>
)} )}
</Checkbox.Group> </Checkbox.Group>
</Form.Item> </Form.Item>
) )
} }
</Form.Item> </Form.Item>
</> </>
)} )}
{renderCheckbox( {renderCheckbox(
'tokenonly', 'tokenonly',
@ -721,25 +759,25 @@ const PreferenceList = () => {
{['printuom', 'printlogo', 'printgreetings'].some( {['printuom', 'printlogo', 'printgreetings'].some(
(k) => allSettingsMap[k] !== undefined (k) => allSettingsMap[k] !== undefined
) && ( ) && (
<Form.Item <Form.Item
name="printOptions" name="printOptions"
label="Select what you want to include in the print:" label="Select what you want to include in the print:"
> >
<Checkbox.Group> <Checkbox.Group>
{allSettingsMap['printuom'] !== undefined && ( {allSettingsMap['printuom'] !== undefined && (
<Checkbox value="printuom"> <Checkbox value="printuom">
Unit of Measure (UOM) Unit of Measure (UOM)
</Checkbox> </Checkbox>
)} )}
{allSettingsMap['printlogo'] !== undefined && ( {allSettingsMap['printlogo'] !== undefined && (
<Checkbox value="printlogo">Branch Logo</Checkbox> <Checkbox value="printlogo">Branch Logo</Checkbox>
)} )}
{allSettingsMap['printgreetings'] !== undefined && ( {allSettingsMap['printgreetings'] !== undefined && (
<Checkbox value="printgreetings">Greetings</Checkbox> <Checkbox value="printgreetings">Greetings</Checkbox>
)} )}
</Checkbox.Group> </Checkbox.Group>
</Form.Item> </Form.Item>
)} )}
{renderCheckbox( {renderCheckbox(
'mobilea4', 'mobilea4',