feat: create batch when resetting bills count on Admin

This commit is contained in:
André Sá 2021-11-15 21:15:35 +00:00
parent d9cd896d33
commit 5f5e0d8b05
2 changed files with 26 additions and 0 deletions

View file

@ -364,6 +364,7 @@ const typeDefs = gql`
toggleClearNotification(id: ID!, read: Boolean!): Notification
clearAllNotifications: Notification
cancelCashOutTransaction(id: ID): Transaction
createBatch(deviceId: ID, cashboxCount: Int): CashboxBatch
editBatch(id: ID, performedBy: String): CashboxBatch
}
`
@ -464,6 +465,7 @@ const resolvers = {
toggleClearNotification: (...[, { id, read }]) => notifierQueries.setRead(id, read),
clearAllNotifications: () => notifierQueries.markAllAsRead(),
cancelCashOutTransaction: (...[, { id }]) => cashOutTx.cancel(id),
createBatch: (...[, { deviceId, cashboxCount }]) => cashbox.createCashboxBatch(deviceId, cashboxCount),
editBatch: (...[, { id, performedBy }]) => cashbox.editBatchById(id, performedBy)
}
}

View file

@ -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 classes = useStyles()
const [showHistory, setShowHistory] = useState(false)
@ -120,6 +128,7 @@ const CashCassettes = () => {
const [setCassetteBills, { error }] = useMutation(SET_CASSETTE_BILLS, {
refetchQueries: () => ['getData']
})
const [createBatch] = useMutation(CREATE_BATCH)
const bills = R.groupBy(bill => bill.deviceId)(R.path(['bills'])(data) ?? [])
const deviceIds = R.uniq(
R.map(R.prop('deviceId'))(R.path(['bills'])(data) ?? [])
@ -130,10 +139,25 @@ const CashCassettes = () => {
const maxNumberOfCassettes = Math.max(
...R.map(it => it.numberOfCassettes, machines)
)
const cashboxCounts = R.reduce(
(ret, m) => R.assoc(m.id, m.cashbox, ret),
{},
machines
)
const onSave = (
...[, { id, cashbox, cassette1, cassette2, cassette3, cassette4 }]
) => {
const oldCashboxCount = cashboxCounts[id]
if (cashbox < oldCashboxCount) {
createBatch({
variables: {
deviceId: id,
cashboxCount: oldCashboxCount
}
})
}
return setCassetteBills({
variables: {
action: 'setCassetteBills',