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