From bce45d34e0e817bbf1bd2b78d9cc3184f68c953e Mon Sep 17 00:00:00 2001
From: csrapr <26280794+csrapr@users.noreply.github.com>
Date: Thu, 18 Feb 2021 18:00:38 +0000
Subject: [PATCH] Feat: footer calculate cashout total
---
lib/new-admin/bills.js | 18 ++++++++++++
lib/new-admin/graphql/schema.js | 12 +++++++-
.../src/pages/Maintenance/CashCassettes.js | 24 +++++++++++++---
.../pages/Maintenance/CashCassettesFooter.js | 28 +++++++++++++++----
.../Maintenance/CashCassettesFooter.styles.js | 3 +-
5 files changed, 74 insertions(+), 11 deletions(-)
create mode 100644 lib/new-admin/bills.js
diff --git a/lib/new-admin/bills.js b/lib/new-admin/bills.js
new file mode 100644
index 00000000..25a8661d
--- /dev/null
+++ b/lib/new-admin/bills.js
@@ -0,0 +1,18 @@
+const db = require('../db')
+
+// Get all bills with device id
+const getBills = () => {
+ return db.any(`SELECT d.device_id, b.fiat, b.created, d.cashbox FROM cash_in_txs INNER JOIN bills AS b ON b.cash_in_txs_id = cash_in_txs.id INNER JOIN devices as d ON d.device_id = cash_in_txs.device_id ORDER BY device_id, created DESC`)
+ .then(res => {
+ return res.map(item => ({
+ fiat: item.fiat,
+ deviceId: item.device_id,
+ cashbox: item.cashbox,
+ created: item.created
+ }))
+ })
+}
+
+module.exports = {
+ getBills
+}
diff --git a/lib/new-admin/graphql/schema.js b/lib/new-admin/graphql/schema.js
index 81d143e9..65151303 100644
--- a/lib/new-admin/graphql/schema.js
+++ b/lib/new-admin/graphql/schema.js
@@ -15,6 +15,7 @@ const blacklist = require('../../blacklist')
const machineEventsByIdBatch = require('../../postgresql_interface').machineEventsByIdBatch
const promoCodeManager = require('../../promo-codes')
const notifierQueries = require('../../notifier/queries')
+const bills = require('../bills')
const serverVersion = require('../../../package.json').version
const transactions = require('../transactions')
@@ -259,6 +260,13 @@ const typeDefs = gql`
valid: Boolean
}
+ type Bills {
+ fiat: Int
+ deviceId: ID
+ created: Date
+ cashbox: Int
+ }
+
type Query {
countries: [Country]
currencies: [Currency]
@@ -294,6 +302,7 @@ const typeDefs = gql`
notifications: [Notification]
alerts: [Notification]
hasUnreadNotifications: Boolean
+ bills: [Bills]
}
type SupportLogsResponse {
@@ -393,7 +402,8 @@ const resolvers = {
fiatRates: () => forex.getFiatRates(),
notifications: () => notifierQueries.getNotifications(),
hasUnreadNotifications: () => notifierQueries.hasUnreadNotifications(),
- alerts: () => notifierQueries.getAlerts()
+ alerts: () => notifierQueries.getAlerts(),
+ bills: () => bills.getBills()
},
Mutation: {
machineAction: (...[, { deviceId, action, cashbox, cassette1, cassette2, newName }]) => machineAction({ deviceId, action, cashbox, cassette1, cassette2, newName }),
diff --git a/new-lamassu-admin/src/pages/Maintenance/CashCassettes.js b/new-lamassu-admin/src/pages/Maintenance/CashCassettes.js
index 5059cc86..004bcd01 100644
--- a/new-lamassu-admin/src/pages/Maintenance/CashCassettes.js
+++ b/new-lamassu-admin/src/pages/Maintenance/CashCassettes.js
@@ -49,6 +49,12 @@ const GET_MACHINES_AND_CONFIG = gql`
cassette2
}
config
+ bills {
+ fiat
+ deviceId
+ created
+ cashbox
+ }
}
`
@@ -79,14 +85,19 @@ const CashCassettes = () => {
const classes = useStyles()
const { data } = useQuery(GET_MACHINES_AND_CONFIG)
+
+ const machines = R.path(['machines'])(data) ?? []
+ const config = R.path(['config'])(data) ?? {}
const [setCassetteBills, { error }] = useMutation(SET_CASSETTE_BILLS, {
refetchQueries: () => ['getData']
})
-
+ const bills = R.groupBy(bill => bill.deviceId)(R.path(['bills'])(data) ?? [])
+ const deviceIds = R.uniq(
+ R.map(R.prop('deviceId'))(R.path(['bills'])(data) ?? [])
+ )
const cashout = data?.config && fromNamespace('cashOut')(data.config)
const locale = data?.config && fromNamespace('locale')(data.config)
const fiatCurrency = locale?.fiatCurrency
- const machines = R.path(['machines'])(data) ?? []
const onSave = (...[, { id, cashbox, cassette1, cassette2 }]) => {
return setCassetteBills({
@@ -99,7 +110,6 @@ const CashCassettes = () => {
}
})
}
-
const getCashoutSettings = id => fromNamespace(id)(cashout)
const isCashOutDisabled = ({ id }) => !getCashoutSettings(id).active
@@ -183,7 +193,13 @@ const CashCassettes = () => {