From 5f5e0d8b05dc468efd48d24fc4c9c233552b0ec7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20S=C3=A1?= Date: Mon, 15 Nov 2021 21:15:35 +0000 Subject: [PATCH] feat: create batch when resetting bills count on Admin --- lib/new-admin/graphql/schema.js | 2 ++ .../src/pages/Maintenance/CashCassettes.js | 24 +++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/lib/new-admin/graphql/schema.js b/lib/new-admin/graphql/schema.js index 718bac9c..c739d10e 100644 --- a/lib/new-admin/graphql/schema.js +++ b/lib/new-admin/graphql/schema.js @@ -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) } } diff --git a/new-lamassu-admin/src/pages/Maintenance/CashCassettes.js b/new-lamassu-admin/src/pages/Maintenance/CashCassettes.js index 5e68435b..bf68f3f4 100644 --- a/new-lamassu-admin/src/pages/Maintenance/CashCassettes.js +++ b/new-lamassu-admin/src/pages/Maintenance/CashCassettes.js @@ -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',