Merge pull request #950 from chaotixkilla/fix-cashbox-history-nan-and-machine-status-wizard
Add cash cassettes wizard to the machine status screen
This commit is contained in:
commit
d25994c16a
3 changed files with 79 additions and 20 deletions
|
|
@ -2,12 +2,15 @@ import { useMutation } from '@apollo/react-hooks'
|
||||||
import { makeStyles } from '@material-ui/core'
|
import { makeStyles } from '@material-ui/core'
|
||||||
import gql from 'graphql-tag'
|
import gql from 'graphql-tag'
|
||||||
import * as R from 'ramda'
|
import * as R from 'ramda'
|
||||||
import React from 'react'
|
import React, { useState } from 'react'
|
||||||
import * as Yup from 'yup'
|
import * as Yup from 'yup'
|
||||||
|
|
||||||
|
import { IconButton } from 'src/components/buttons'
|
||||||
import { Table as EditableTable } from 'src/components/editableTable'
|
import { Table as EditableTable } from 'src/components/editableTable'
|
||||||
import { CashOut, CashIn } from 'src/components/inputs/cashbox/Cashbox'
|
import { CashOut, CashIn } from 'src/components/inputs/cashbox/Cashbox'
|
||||||
import { NumberInput, CashCassetteInput } from 'src/components/inputs/formik'
|
import { NumberInput, CashCassetteInput } from 'src/components/inputs/formik'
|
||||||
|
import Wizard from 'src/pages/Maintenance/Wizard/Wizard'
|
||||||
|
import { ReactComponent as EditIcon } from 'src/styling/icons/action/edit/enabled.svg'
|
||||||
import { fromNamespace } from 'src/utils/config'
|
import { fromNamespace } from 'src/utils/config'
|
||||||
|
|
||||||
import styles from './Cassettes.styles'
|
import styles from './Cassettes.styles'
|
||||||
|
|
@ -79,10 +82,20 @@ const SET_CASSETTE_BILLS = gql`
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
|
const CREATE_BATCH = gql`
|
||||||
|
mutation createBatch($deviceId: ID, $cashboxCount: Int) {
|
||||||
|
createBatch(deviceId: $deviceId, cashboxCount: $cashboxCount) {
|
||||||
|
id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|
||||||
const CashCassettes = ({ machine, config, refetchData }) => {
|
const CashCassettes = ({ machine, config, refetchData }) => {
|
||||||
const data = { machine, config }
|
const data = { machine, config }
|
||||||
const classes = useStyles()
|
const classes = useStyles()
|
||||||
|
|
||||||
|
const [wizard, setWizard] = useState(false)
|
||||||
|
|
||||||
const cashout = data?.config && fromNamespace('cashOut')(data.config)
|
const cashout = data?.config && fromNamespace('cashOut')(data.config)
|
||||||
const locale = data?.config && fromNamespace('locale')(data.config)
|
const locale = data?.config && fromNamespace('locale')(data.config)
|
||||||
const fiatCurrency = locale?.fiatCurrency
|
const fiatCurrency = locale?.fiatCurrency
|
||||||
|
|
@ -143,17 +156,43 @@ const CashCassettes = ({ machine, config, refetchData }) => {
|
||||||
1
|
1
|
||||||
)
|
)
|
||||||
|
|
||||||
|
elements.push({
|
||||||
|
name: 'edit',
|
||||||
|
header: 'Edit',
|
||||||
|
width: 87,
|
||||||
|
view: () => {
|
||||||
|
return (
|
||||||
|
<IconButton
|
||||||
|
onClick={() => {
|
||||||
|
setWizard(true)
|
||||||
|
}}>
|
||||||
|
<EditIcon />
|
||||||
|
</IconButton>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
const [setCassetteBills, { error }] = useMutation(SET_CASSETTE_BILLS, {
|
const [setCassetteBills, { error }] = useMutation(SET_CASSETTE_BILLS, {
|
||||||
refetchQueries: () => refetchData()
|
refetchQueries: () => refetchData()
|
||||||
})
|
})
|
||||||
|
|
||||||
const onSave = (
|
const [createBatch] = useMutation(CREATE_BATCH)
|
||||||
...[, { deviceId, cashbox, cassette1, cassette2, cassette3, cassette4 }]
|
|
||||||
) => {
|
const onSave = (_, cashbox, cassette1, cassette2, cassette3, cassette4) => {
|
||||||
|
const oldCashboxCount = machine.cashbox
|
||||||
|
if (cashbox < oldCashboxCount) {
|
||||||
|
createBatch({
|
||||||
|
variables: {
|
||||||
|
deviceId: machine.deviceId,
|
||||||
|
cashboxCount: oldCashboxCount
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
return setCassetteBills({
|
return setCassetteBills({
|
||||||
variables: {
|
variables: {
|
||||||
action: 'setCassetteBills',
|
action: 'setCassetteBills',
|
||||||
deviceId: deviceId,
|
deviceId: machine.deviceId,
|
||||||
cashbox,
|
cashbox,
|
||||||
cassette1,
|
cassette1,
|
||||||
cassette2,
|
cassette2,
|
||||||
|
|
@ -164,9 +203,9 @@ const CashCassettes = ({ machine, config, refetchData }) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
return machine.name ? (
|
return machine.name ? (
|
||||||
|
<>
|
||||||
<EditableTable
|
<EditableTable
|
||||||
error={error?.message}
|
error={error?.message}
|
||||||
enableEdit
|
|
||||||
editWidth={widthsByNumberOfCassettes[numberOfCassettes].editWidth}
|
editWidth={widthsByNumberOfCassettes[numberOfCassettes].editWidth}
|
||||||
stripeWhen={isCashOutDisabled}
|
stripeWhen={isCashOutDisabled}
|
||||||
disableRowEdit={isCashOutDisabled}
|
disableRowEdit={isCashOutDisabled}
|
||||||
|
|
@ -176,6 +215,19 @@ const CashCassettes = ({ machine, config, refetchData }) => {
|
||||||
save={onSave}
|
save={onSave}
|
||||||
validationSchema={ValidationSchema}
|
validationSchema={ValidationSchema}
|
||||||
/>
|
/>
|
||||||
|
{wizard && (
|
||||||
|
<Wizard
|
||||||
|
machine={machine}
|
||||||
|
cashoutSettings={getCashoutSettings(machine.deviceId)}
|
||||||
|
onClose={() => {
|
||||||
|
setWizard(false)
|
||||||
|
}}
|
||||||
|
error={error?.message}
|
||||||
|
save={onSave}
|
||||||
|
locale={locale}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
) : null
|
) : null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -163,7 +163,7 @@ const CashboxHistory = ({ machines, currency }) => {
|
||||||
{
|
{
|
||||||
name: 'total',
|
name: 'total',
|
||||||
header: 'Total',
|
header: 'Total',
|
||||||
width: 100,
|
width: 180,
|
||||||
textAlign: 'right',
|
textAlign: 'right',
|
||||||
view: it => (
|
view: it => (
|
||||||
<span>
|
<span>
|
||||||
|
|
@ -217,7 +217,7 @@ const CashboxHistory = ({ machines, currency }) => {
|
||||||
{
|
{
|
||||||
name: '',
|
name: '',
|
||||||
header: 'Edit',
|
header: 'Edit',
|
||||||
width: 150,
|
width: 80,
|
||||||
textAlign: 'right',
|
textAlign: 'right',
|
||||||
view: it => {
|
view: it => {
|
||||||
if (notEditing(it.id))
|
if (notEditing(it.id))
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,14 @@ const Wizard = ({ machine, cashoutSettings, locale, onClose, save, error }) => {
|
||||||
|
|
||||||
if (isLastStep) {
|
if (isLastStep) {
|
||||||
const { cassette1, cassette2, cassette3, cassette4 } = R.map(parseInt, it)
|
const { cassette1, cassette2, cassette3, cassette4 } = R.map(parseInt, it)
|
||||||
save(machine.id, cashbox, cassette1, cassette2, cassette3, cassette4)
|
save(
|
||||||
|
machine.id,
|
||||||
|
cashbox,
|
||||||
|
cassette1 ?? 0,
|
||||||
|
cassette2 ?? 0,
|
||||||
|
cassette3 ?? 0,
|
||||||
|
cassette4 ?? 0
|
||||||
|
)
|
||||||
return onClose()
|
return onClose()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue