Merge pull request #1364 from siiky/feat/lam-609/cashbox-notifications
Add cash-in notifications settings
This commit is contained in:
commit
78f798fd4a
4 changed files with 126 additions and 56 deletions
|
|
@ -71,7 +71,9 @@ const fiatBalancesNotify = (fiatWarnings) => {
|
||||||
const { cassette, deviceId } = o.detail
|
const { cassette, deviceId } = o.detail
|
||||||
return cassette === balance.cassette && deviceId === balance.deviceId
|
return cassette === balance.cassette && deviceId === balance.deviceId
|
||||||
}, notInvalidated)) return
|
}, notInvalidated)) return
|
||||||
const message = `Cash-out cassette ${balance.cassette} low or empty!`
|
const message = balance.code === 'LOW_CASH_OUT' ?
|
||||||
|
`Cash-out cassette ${balance.cassette} low or empty!` :
|
||||||
|
`Cash box full or almost full!`
|
||||||
const detailB = utils.buildDetail({ deviceId: balance.deviceId, cassette: balance.cassette })
|
const detailB = utils.buildDetail({ deviceId: balance.deviceId, cassette: balance.cassette })
|
||||||
return queries.addNotification(FIAT_BALANCE, message, detailB)
|
return queries.addNotification(FIAT_BALANCE, message, detailB)
|
||||||
})
|
})
|
||||||
|
|
@ -111,11 +113,18 @@ const cryptoBalancesNotify = (cryptoWarnings) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const balancesNotify = (balances) => {
|
const balancesNotify = (balances) => {
|
||||||
const cryptoFilter = o => o.code === 'HIGH_CRYPTO_BALANCE' || o.code === 'LOW_CRYPTO_BALANCE'
|
const isCryptoCode = c => _.includes(c, ['HIGH_CRYPTO_BALANCE', 'LOW_CRYPTO_BALANCE'])
|
||||||
const fiatFilter = o => o.code === 'LOW_CASH_OUT'
|
const isFiatCode = c => _.includes(c, ['LOW_CASH_OUT', 'CASH_BOX_FULL'])
|
||||||
const cryptoWarnings = _.filter(cryptoFilter, balances)
|
const by = o =>
|
||||||
const fiatWarnings = _.filter(fiatFilter, balances)
|
isCryptoCode(o) ? 'crypto' :
|
||||||
return Promise.all([cryptoBalancesNotify(cryptoWarnings), fiatBalancesNotify(fiatWarnings)])
|
isFiatCode(o) ? 'fiat' :
|
||||||
|
undefined
|
||||||
|
const warnings = _.flow(
|
||||||
|
_.groupBy(_.flow(_.get(['code']), by)),
|
||||||
|
_.update('crypto', _.defaultTo([])),
|
||||||
|
_.update('fiat', _.defaultTo([])),
|
||||||
|
)(balances)
|
||||||
|
return Promise.all([cryptoBalancesNotify(warnings.crypto), fiatBalancesNotify(warnings.fiat)])
|
||||||
}
|
}
|
||||||
|
|
||||||
const clearOldErrorNotifications = alerts => {
|
const clearOldErrorNotifications = alerts => {
|
||||||
|
|
|
||||||
|
|
@ -74,12 +74,12 @@ const MachineRoute = () => {
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
},
|
},
|
||||||
variables: {
|
variables: {
|
||||||
deviceId: id
|
deviceId: id,
|
||||||
},
|
|
||||||
billFilters: {
|
billFilters: {
|
||||||
deviceId: id,
|
deviceId: id,
|
||||||
batch: 'none'
|
batch: 'none'
|
||||||
}
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const reload = () => {
|
const reload = () => {
|
||||||
|
|
|
||||||
|
|
@ -17,8 +17,11 @@ import styles from './FiatBalanceAlerts.styles.js'
|
||||||
|
|
||||||
const useStyles = makeStyles(styles)
|
const useStyles = makeStyles(styles)
|
||||||
|
|
||||||
const NAME = 'fiatBalanceAlerts'
|
const CASH_IN_KEY = 'fiatBalanceAlertsCashIn'
|
||||||
|
const CASH_OUT_KEY = 'fiatBalanceAlertsCashOut'
|
||||||
const DEFAULT_NUMBER_OF_CASSETTES = 2
|
const DEFAULT_NUMBER_OF_CASSETTES = 2
|
||||||
|
const notesMin = 0
|
||||||
|
const notesMax = 9999999
|
||||||
|
|
||||||
const FiatBalance = ({ section, min = 0, max = 100, fieldWidth = 80 }) => {
|
const FiatBalance = ({ section, min = 0, max = 100, fieldWidth = 80 }) => {
|
||||||
const {
|
const {
|
||||||
|
|
@ -36,9 +39,13 @@ const FiatBalance = ({ section, min = 0, max = 100, fieldWidth = 80 }) => {
|
||||||
DEFAULT_NUMBER_OF_CASSETTES
|
DEFAULT_NUMBER_OF_CASSETTES
|
||||||
)
|
)
|
||||||
|
|
||||||
const editing = isEditing(NAME)
|
|
||||||
|
|
||||||
const schema = Yup.object().shape({
|
const schema = Yup.object().shape({
|
||||||
|
cashInAlertThreshold: Yup.number()
|
||||||
|
.transform(transformNumber)
|
||||||
|
.integer()
|
||||||
|
.min(notesMin)
|
||||||
|
.max(notesMax)
|
||||||
|
.nullable(),
|
||||||
fillingPercentageCassette1: Yup.number()
|
fillingPercentageCassette1: Yup.number()
|
||||||
.transform(transformNumber)
|
.transform(transformNumber)
|
||||||
.integer()
|
.integer()
|
||||||
|
|
@ -71,6 +78,7 @@ const FiatBalance = ({ section, min = 0, max = 100, fieldWidth = 80 }) => {
|
||||||
validateOnChange={false}
|
validateOnChange={false}
|
||||||
enableReinitialize
|
enableReinitialize
|
||||||
initialValues={{
|
initialValues={{
|
||||||
|
cashInAlertThreshold: data?.cashInAlertThreshold ?? '',
|
||||||
fillingPercentageCassette1: data?.fillingPercentageCassette1 ?? '',
|
fillingPercentageCassette1: data?.fillingPercentageCassette1 ?? '',
|
||||||
fillingPercentageCassette2: data?.fillingPercentageCassette2 ?? '',
|
fillingPercentageCassette2: data?.fillingPercentageCassette2 ?? '',
|
||||||
fillingPercentageCassette3: data?.fillingPercentageCassette3 ?? '',
|
fillingPercentageCassette3: data?.fillingPercentageCassette3 ?? '',
|
||||||
|
|
@ -79,16 +87,43 @@ const FiatBalance = ({ section, min = 0, max = 100, fieldWidth = 80 }) => {
|
||||||
validationSchema={schema}
|
validationSchema={schema}
|
||||||
onSubmit={it => save(section, schema.cast(it))}
|
onSubmit={it => save(section, schema.cast(it))}
|
||||||
onReset={() => {
|
onReset={() => {
|
||||||
setEditing(NAME, false)
|
setEditing(CASH_IN_KEY, false)
|
||||||
|
setEditing(CASH_OUT_KEY, false)
|
||||||
}}>
|
}}>
|
||||||
{({ values }) => (
|
{({ values }) => (
|
||||||
|
<>
|
||||||
|
<Form className={classes.form}>
|
||||||
|
<PromptWhenDirty />
|
||||||
|
<Header
|
||||||
|
title="Cash box"
|
||||||
|
editing={isEditing(CASH_IN_KEY)}
|
||||||
|
disabled={isDisabled(CASH_IN_KEY)}
|
||||||
|
setEditing={it => setEditing(CASH_IN_KEY, it)}
|
||||||
|
/>
|
||||||
|
<div className={classes.wrapper}>
|
||||||
|
<div className={classes.first}>
|
||||||
|
<div className={classes.row}>
|
||||||
|
<div className={classes.col2}>
|
||||||
|
<EditableNumber
|
||||||
|
label="Alert me over"
|
||||||
|
name="cashInAlertThreshold"
|
||||||
|
editing={isEditing(CASH_IN_KEY)}
|
||||||
|
displayValue={x => (x === '' ? '-' : x)}
|
||||||
|
decoration="notes"
|
||||||
|
width={fieldWidth}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</Form>
|
||||||
<Form className={classes.form}>
|
<Form className={classes.form}>
|
||||||
<PromptWhenDirty />
|
<PromptWhenDirty />
|
||||||
<Header
|
<Header
|
||||||
title="Cash out (Empty)"
|
title="Cash out (Empty)"
|
||||||
editing={editing}
|
editing={isEditing(CASH_OUT_KEY)}
|
||||||
disabled={isDisabled(NAME)}
|
disabled={isDisabled(CASH_OUT_KEY)}
|
||||||
setEditing={it => setEditing(NAME, it)}
|
setEditing={it => setEditing(CASH_OUT_KEY, it)}
|
||||||
/>
|
/>
|
||||||
<div className={classes.wrapper}>
|
<div className={classes.wrapper}>
|
||||||
{R.map(
|
{R.map(
|
||||||
|
|
@ -112,7 +147,7 @@ const FiatBalance = ({ section, min = 0, max = 100, fieldWidth = 80 }) => {
|
||||||
<EditableNumber
|
<EditableNumber
|
||||||
label="Alert me under"
|
label="Alert me under"
|
||||||
name={`fillingPercentageCassette${it + 1}`}
|
name={`fillingPercentageCassette${it + 1}`}
|
||||||
editing={editing}
|
editing={isEditing(CASH_OUT_KEY)}
|
||||||
displayValue={x => (x === '' ? '-' : x)}
|
displayValue={x => (x === '' ? '-' : x)}
|
||||||
decoration="%"
|
decoration="%"
|
||||||
width={fieldWidth}
|
width={fieldWidth}
|
||||||
|
|
@ -125,6 +160,7 @@ const FiatBalance = ({ section, min = 0, max = 100, fieldWidth = 80 }) => {
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</Form>
|
</Form>
|
||||||
|
</>
|
||||||
)}
|
)}
|
||||||
</Formik>
|
</Formik>
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -10,12 +10,14 @@ import { transformNumber } from 'src/utils/number'
|
||||||
|
|
||||||
import NotificationsCtx from '../NotificationsContext'
|
import NotificationsCtx from '../NotificationsContext'
|
||||||
|
|
||||||
|
const CASHBOX_KEY = 'cashbox'
|
||||||
const CASSETTE_1_KEY = 'fillingPercentageCassette1'
|
const CASSETTE_1_KEY = 'fillingPercentageCassette1'
|
||||||
const CASSETTE_2_KEY = 'fillingPercentageCassette2'
|
const CASSETTE_2_KEY = 'fillingPercentageCassette2'
|
||||||
const CASSETTE_3_KEY = 'fillingPercentageCassette3'
|
const CASSETTE_3_KEY = 'fillingPercentageCassette3'
|
||||||
const CASSETTE_4_KEY = 'fillingPercentageCassette4'
|
const CASSETTE_4_KEY = 'fillingPercentageCassette4'
|
||||||
const MACHINE_KEY = 'machine'
|
const MACHINE_KEY = 'machine'
|
||||||
const NAME = 'fiatBalanceOverrides'
|
const NAME = 'fiatBalanceOverrides'
|
||||||
|
const DEFAULT_NUMBER_OF_CASSETTES = 2
|
||||||
|
|
||||||
const CASSETTE_LIST = [
|
const CASSETTE_LIST = [
|
||||||
CASSETTE_1_KEY,
|
CASSETTE_1_KEY,
|
||||||
|
|
@ -60,15 +62,19 @@ const FiatBalanceOverrides = ({ config, section }) => {
|
||||||
|
|
||||||
const initialValues = {
|
const initialValues = {
|
||||||
[MACHINE_KEY]: null,
|
[MACHINE_KEY]: null,
|
||||||
|
[CASHBOX_KEY]: '',
|
||||||
[CASSETTE_1_KEY]: '',
|
[CASSETTE_1_KEY]: '',
|
||||||
[CASSETTE_2_KEY]: '',
|
[CASSETTE_2_KEY]: '',
|
||||||
[CASSETTE_3_KEY]: '',
|
[CASSETTE_3_KEY]: '',
|
||||||
[CASSETTE_4_KEY]: ''
|
[CASSETTE_4_KEY]: ''
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const notesMin = 0
|
||||||
|
const notesMax = 9999999
|
||||||
|
|
||||||
const maxNumberOfCassettes = Math.max(
|
const maxNumberOfCassettes = Math.max(
|
||||||
...R.map(it => it.numberOfCassettes, machines),
|
...R.map(it => it.numberOfCassettes, machines),
|
||||||
2
|
DEFAULT_NUMBER_OF_CASSETTES
|
||||||
)
|
)
|
||||||
|
|
||||||
const percentMin = 0
|
const percentMin = 0
|
||||||
|
|
@ -79,6 +85,13 @@ const FiatBalanceOverrides = ({ config, section }) => {
|
||||||
.label('Machine')
|
.label('Machine')
|
||||||
.nullable()
|
.nullable()
|
||||||
.required(),
|
.required(),
|
||||||
|
[CASHBOX_KEY]: Yup.number()
|
||||||
|
.label('Cash box')
|
||||||
|
.transform(transformNumber)
|
||||||
|
.integer()
|
||||||
|
.min(notesMin)
|
||||||
|
.max(notesMax)
|
||||||
|
.nullable(),
|
||||||
[CASSETTE_1_KEY]: Yup.number()
|
[CASSETTE_1_KEY]: Yup.number()
|
||||||
.label('Cassette 1')
|
.label('Cassette 1')
|
||||||
.transform(transformNumber)
|
.transform(transformNumber)
|
||||||
|
|
@ -134,6 +147,18 @@ const FiatBalanceOverrides = ({ config, section }) => {
|
||||||
valueProp: 'deviceId',
|
valueProp: 'deviceId',
|
||||||
labelProp: 'name'
|
labelProp: 'name'
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: CASHBOX_KEY,
|
||||||
|
display: 'Cashbox',
|
||||||
|
width: 155,
|
||||||
|
textAlign: 'right',
|
||||||
|
bold: true,
|
||||||
|
input: NumberInput,
|
||||||
|
suffix: 'notes',
|
||||||
|
inputProps: {
|
||||||
|
decimalPlaces: 0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue