Merge pull request #1440 from siiky/fix/lam-609/no-cashout-cashin-notifs-overrides
Show "Add overrides" button even if there are no two-way machines
This commit is contained in:
commit
6ff1efcb9b
2 changed files with 58 additions and 60 deletions
|
|
@ -70,7 +70,7 @@ const Header = () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const mapElement = (
|
const mapElement = (
|
||||||
{ name, width = DEFAULT_COL_SIZE, header, textAlign },
|
{ name, display, width = DEFAULT_COL_SIZE, header, textAlign },
|
||||||
idx
|
idx
|
||||||
) => {
|
) => {
|
||||||
const orderClasses = classnames({
|
const orderClasses = classnames({
|
||||||
|
|
@ -99,7 +99,7 @@ const Header = () => {
|
||||||
<>{attachOrderedByToComplexHeader(header) ?? header}</>
|
<>{attachOrderedByToComplexHeader(header) ?? header}</>
|
||||||
) : (
|
) : (
|
||||||
<span className={orderClasses}>
|
<span className={orderClasses}>
|
||||||
{startCase(name)}{' '}
|
{!R.isNil(display) ? display : startCase(name)}{' '}
|
||||||
{!R.isNil(orderedBy) && R.equals(name, orderedBy.code) && '-'}
|
{!R.isNil(orderedBy) && R.equals(name, orderedBy.code) && '-'}
|
||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
|
|
|
||||||
|
|
@ -27,9 +27,9 @@ const CASSETTE_LIST = [
|
||||||
]
|
]
|
||||||
|
|
||||||
const widthsByNumberOfCassettes = {
|
const widthsByNumberOfCassettes = {
|
||||||
2: { machine: 230, cassette: 250 },
|
2: { machine: 230, cashbox: 150, cassette: 250 },
|
||||||
3: { machine: 216, cassette: 270 },
|
3: { machine: 216, cashbox: 150, cassette: 270 },
|
||||||
4: { machine: 210, cassette: 204 }
|
4: { machine: 210, cashbox: 150, cassette: 204 }
|
||||||
}
|
}
|
||||||
|
|
||||||
const FiatBalanceOverrides = ({ config, section }) => {
|
const FiatBalanceOverrides = ({ config, section }) => {
|
||||||
|
|
@ -44,19 +44,17 @@ const FiatBalanceOverrides = ({ config, section }) => {
|
||||||
|
|
||||||
const setupValues = data?.fiatBalanceOverrides ?? []
|
const setupValues = data?.fiatBalanceOverrides ?? []
|
||||||
const innerSetEditing = it => setEditing(NAME, it)
|
const innerSetEditing = it => setEditing(NAME, it)
|
||||||
|
|
||||||
const cashoutConfig = it => fromNamespace(it)(config)
|
const cashoutConfig = it => fromNamespace(it)(config)
|
||||||
|
|
||||||
const overriddenMachines = R.map(override => override.machine, setupValues)
|
const overriddenMachines = R.map(override => override.machine, setupValues)
|
||||||
const suggestionFilter = R.filter(
|
const suggestions = R.differenceWith(
|
||||||
it =>
|
(it, m) => it.deviceId === m,
|
||||||
!R.includes(it.deviceId, overriddenMachines) &&
|
machines,
|
||||||
cashoutConfig(it.deviceId).active
|
overriddenMachines
|
||||||
)
|
)
|
||||||
const suggestions = suggestionFilter(machines)
|
|
||||||
|
|
||||||
const findSuggestion = it => {
|
const findSuggestion = it => {
|
||||||
const coin = R.compose(R.find(R.propEq('deviceId', it?.machine)))(machines)
|
const coin = R.find(R.propEq('deviceId', it?.machine), machines)
|
||||||
return coin ? [coin] : []
|
return coin ? [coin] : []
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -83,7 +81,6 @@ const FiatBalanceOverrides = ({ config, section }) => {
|
||||||
.shape({
|
.shape({
|
||||||
[MACHINE_KEY]: Yup.string()
|
[MACHINE_KEY]: Yup.string()
|
||||||
.label('Machine')
|
.label('Machine')
|
||||||
.nullable()
|
|
||||||
.required(),
|
.required(),
|
||||||
[CASHBOX_KEY]: Yup.number()
|
[CASHBOX_KEY]: Yup.number()
|
||||||
.label('Cash box')
|
.label('Cash box')
|
||||||
|
|
@ -121,23 +118,24 @@ const FiatBalanceOverrides = ({ config, section }) => {
|
||||||
.max(percentMax)
|
.max(percentMax)
|
||||||
.nullable()
|
.nullable()
|
||||||
})
|
})
|
||||||
.test((values, context) => {
|
.test((values, context) =>
|
||||||
const picked = R.pick(CASSETTE_LIST, values)
|
R.any(key => !R.isNil(values[key]), R.prepend(CASHBOX_KEY, CASSETTE_LIST))
|
||||||
|
? undefined
|
||||||
if (CASSETTE_LIST.some(it => !R.isNil(picked[it]))) return
|
: context.createError({
|
||||||
|
path: CASHBOX_KEY,
|
||||||
return context.createError({
|
message:
|
||||||
path: CASSETTE_1_KEY,
|
'The cash box or at least one of the cassettes must have a value'
|
||||||
message: 'At least one of the cassettes must have a value'
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
)
|
||||||
|
|
||||||
const viewMachine = it =>
|
const viewMachine = it =>
|
||||||
R.compose(R.path(['name']), R.find(R.propEq('deviceId', it)))(machines)
|
R.compose(R.path(['name']), R.find(R.propEq('deviceId', it)))(machines)
|
||||||
|
|
||||||
const elements = [
|
const elements = R.concat(
|
||||||
|
[
|
||||||
{
|
{
|
||||||
name: MACHINE_KEY,
|
name: MACHINE_KEY,
|
||||||
|
display: 'Machine',
|
||||||
width: widthsByNumberOfCassettes[maxNumberOfCassettes].machine,
|
width: widthsByNumberOfCassettes[maxNumberOfCassettes].machine,
|
||||||
size: 'sm',
|
size: 'sm',
|
||||||
view: viewMachine,
|
view: viewMachine,
|
||||||
|
|
@ -151,7 +149,7 @@ const FiatBalanceOverrides = ({ config, section }) => {
|
||||||
{
|
{
|
||||||
name: CASHBOX_KEY,
|
name: CASHBOX_KEY,
|
||||||
display: 'Cash box',
|
display: 'Cash box',
|
||||||
width: 155,
|
width: widthsByNumberOfCassettes[maxNumberOfCassettes].cashbox,
|
||||||
textAlign: 'right',
|
textAlign: 'right',
|
||||||
bold: true,
|
bold: true,
|
||||||
input: NumberInput,
|
input: NumberInput,
|
||||||
|
|
@ -160,12 +158,9 @@ const FiatBalanceOverrides = ({ config, section }) => {
|
||||||
decimalPlaces: 0
|
decimalPlaces: 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
|
R.map(
|
||||||
R.until(
|
it => ({
|
||||||
R.gt(R.__, maxNumberOfCassettes),
|
|
||||||
it => {
|
|
||||||
elements.push({
|
|
||||||
name: `fillingPercentageCassette${it}`,
|
name: `fillingPercentageCassette${it}`,
|
||||||
display: `Cash cassette ${it}`,
|
display: `Cash cassette ${it}`,
|
||||||
width: widthsByNumberOfCassettes[maxNumberOfCassettes].cassette,
|
width: widthsByNumberOfCassettes[maxNumberOfCassettes].cassette,
|
||||||
|
|
@ -177,15 +172,18 @@ const FiatBalanceOverrides = ({ config, section }) => {
|
||||||
inputProps: {
|
inputProps: {
|
||||||
decimalPlaces: 0
|
decimalPlaces: 0
|
||||||
},
|
},
|
||||||
view: it => it?.toString() ?? '—',
|
view: el => el?.toString() ?? '—',
|
||||||
isHidden: value =>
|
isHidden: value =>
|
||||||
|
!cashoutConfig(value.machine).active ||
|
||||||
it >
|
it >
|
||||||
|
R.defaultTo(
|
||||||
|
0,
|
||||||
machines.find(({ deviceId }) => deviceId === value.machine)
|
machines.find(({ deviceId }) => deviceId === value.machine)
|
||||||
?.numberOfCassettes
|
?.numberOfCassettes
|
||||||
})
|
)
|
||||||
return R.add(1, it)
|
}),
|
||||||
},
|
R.range(1, maxNumberOfCassettes + 1)
|
||||||
1
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue