feat: create batch when resetting bills count on Admin
This commit is contained in:
parent
d9cd896d33
commit
5f5e0d8b05
2 changed files with 26 additions and 0 deletions
|
|
@ -364,6 +364,7 @@ const typeDefs = gql`
|
||||||
toggleClearNotification(id: ID!, read: Boolean!): Notification
|
toggleClearNotification(id: ID!, read: Boolean!): Notification
|
||||||
clearAllNotifications: Notification
|
clearAllNotifications: Notification
|
||||||
cancelCashOutTransaction(id: ID): Transaction
|
cancelCashOutTransaction(id: ID): Transaction
|
||||||
|
createBatch(deviceId: ID, cashboxCount: Int): CashboxBatch
|
||||||
editBatch(id: ID, performedBy: String): CashboxBatch
|
editBatch(id: ID, performedBy: String): CashboxBatch
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
@ -464,6 +465,7 @@ const resolvers = {
|
||||||
toggleClearNotification: (...[, { id, read }]) => notifierQueries.setRead(id, read),
|
toggleClearNotification: (...[, { id, read }]) => notifierQueries.setRead(id, read),
|
||||||
clearAllNotifications: () => notifierQueries.markAllAsRead(),
|
clearAllNotifications: () => notifierQueries.markAllAsRead(),
|
||||||
cancelCashOutTransaction: (...[, { id }]) => cashOutTx.cancel(id),
|
cancelCashOutTransaction: (...[, { id }]) => cashOutTx.cancel(id),
|
||||||
|
createBatch: (...[, { deviceId, cashboxCount }]) => cashbox.createCashboxBatch(deviceId, cashboxCount),
|
||||||
editBatch: (...[, { id, performedBy }]) => cashbox.editBatchById(id, performedBy)
|
editBatch: (...[, { id, performedBy }]) => cashbox.editBatchById(id, performedBy)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -109,6 +109,14 @@ const SET_CASSETTE_BILLS = gql`
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
|
const CREATE_BATCH = gql`
|
||||||
|
mutation createBatch($deviceId: ID, $cashboxCount: Int) {
|
||||||
|
createBatch(deviceId: $deviceId, cashboxCount: $cashboxCount) {
|
||||||
|
id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|
||||||
const CashCassettes = () => {
|
const CashCassettes = () => {
|
||||||
const classes = useStyles()
|
const classes = useStyles()
|
||||||
const [showHistory, setShowHistory] = useState(false)
|
const [showHistory, setShowHistory] = useState(false)
|
||||||
|
|
@ -120,6 +128,7 @@ const CashCassettes = () => {
|
||||||
const [setCassetteBills, { error }] = useMutation(SET_CASSETTE_BILLS, {
|
const [setCassetteBills, { error }] = useMutation(SET_CASSETTE_BILLS, {
|
||||||
refetchQueries: () => ['getData']
|
refetchQueries: () => ['getData']
|
||||||
})
|
})
|
||||||
|
const [createBatch] = useMutation(CREATE_BATCH)
|
||||||
const bills = R.groupBy(bill => bill.deviceId)(R.path(['bills'])(data) ?? [])
|
const bills = R.groupBy(bill => bill.deviceId)(R.path(['bills'])(data) ?? [])
|
||||||
const deviceIds = R.uniq(
|
const deviceIds = R.uniq(
|
||||||
R.map(R.prop('deviceId'))(R.path(['bills'])(data) ?? [])
|
R.map(R.prop('deviceId'))(R.path(['bills'])(data) ?? [])
|
||||||
|
|
@ -130,10 +139,25 @@ const CashCassettes = () => {
|
||||||
const maxNumberOfCassettes = Math.max(
|
const maxNumberOfCassettes = Math.max(
|
||||||
...R.map(it => it.numberOfCassettes, machines)
|
...R.map(it => it.numberOfCassettes, machines)
|
||||||
)
|
)
|
||||||
|
const cashboxCounts = R.reduce(
|
||||||
|
(ret, m) => R.assoc(m.id, m.cashbox, ret),
|
||||||
|
{},
|
||||||
|
machines
|
||||||
|
)
|
||||||
|
|
||||||
const onSave = (
|
const onSave = (
|
||||||
...[, { id, cashbox, cassette1, cassette2, cassette3, cassette4 }]
|
...[, { id, cashbox, cassette1, cassette2, cassette3, cassette4 }]
|
||||||
) => {
|
) => {
|
||||||
|
const oldCashboxCount = cashboxCounts[id]
|
||||||
|
if (cashbox < oldCashboxCount) {
|
||||||
|
createBatch({
|
||||||
|
variables: {
|
||||||
|
deviceId: id,
|
||||||
|
cashboxCount: oldCashboxCount
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
return setCassetteBills({
|
return setCassetteBills({
|
||||||
variables: {
|
variables: {
|
||||||
action: 'setCassetteBills',
|
action: 'setCassetteBills',
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue