fix: bills and machine data fetching for machine profile page

This commit is contained in:
Sérgio Salgado 2023-05-30 15:55:31 +01:00
parent e55ebd5d84
commit 266eb44076
5 changed files with 32 additions and 16 deletions

View file

@ -20,7 +20,7 @@ const getBills = filters => {
SELECT id, device_id FROM cash_in_txs ${deviceStatement} SELECT id, device_id FROM cash_in_txs ${deviceStatement}
) AS cit ON cit.id = b.cash_in_txs_id ${batchStatement(filters.batch)} ${_.isNil(batchStatement(filters.batch)) ? `WHERE` : `AND`} b.destination_unit = 'cashbox'` ) AS cit ON cit.id = b.cash_in_txs_id ${batchStatement(filters.batch)} ${_.isNil(batchStatement(filters.batch)) ? `WHERE` : `AND`} b.destination_unit = 'cashbox'`
const sql2 = `SELECT b.id, b.fiat, b.fiat_code, b.created, b.cashbox_batch_id, b.device_id FROM empty_unit_bills b ${deviceStatement} ${!_.isNil(filters.deviceId) && !_.isNil(filters.batch) ? `AND` : ``} ${batchStatement(filters.batch)}` const sql2 = `SELECT b.id, b.fiat, b.fiat_code, b.created, b.cashbox_batch_id, b.device_id FROM empty_unit_bills b ${deviceStatement} ${!_.isNil(filters.deviceId) && !_.isNil(filters.batch) ? `AND ${_.replace('WHERE', '', batchStatement(filters.batch))}` : `${batchStatement(filters.batch)}`}`
return Promise.all([db.any(sql), db.any(sql2)]) return Promise.all([db.any(sql), db.any(sql2)])
.then(([bills, operationalBills]) => _.map(_.mapKeys(_.camelCase), _.concat(bills, operationalBills))) .then(([bills, operationalBills]) => _.map(_.mapKeys(_.camelCase), _.concat(bills, operationalBills)))

View file

@ -65,20 +65,19 @@ const CashCassettes = ({ machine, config, refetchData, bills }) => {
refetchQueries: () => refetchData() refetchQueries: () => refetchData()
}) })
const onSave = (_, cashbox, cassettes) => const onSave = (_, cashUnits) =>
setCassetteBills({ setCassetteBills({
variables: { variables: {
action: 'setCassetteBills', action: 'setCassetteBills',
deviceId: machine.deviceId, deviceId: machine.deviceId,
cashbox, cashUnits
...cassettes
} }
}) })
const InnerCashUnitDetails = ({ it }) => ( const InnerCashUnitDetails = ({ it }) => (
<CashUnitDetails <CashUnitDetails
machine={it} machine={it}
bills={bills[it.id] ?? []} bills={bills[it.deviceId] ?? []}
currency={fiatCurrency} currency={fiatCurrency}
config={config} config={config}
hideMachineData hideMachineData

View file

@ -109,7 +109,7 @@ const Machines = ({ data, refetch, reload }) => {
const machine = R.path(['machine'])(data) ?? {} const machine = R.path(['machine'])(data) ?? {}
const config = R.path(['config'])(data) ?? {} const config = R.path(['config'])(data) ?? {}
const bills = R.path(['bills'])(data) ?? [] const bills = R.groupBy(bill => bill.deviceId)(R.path(['bills'])(data) ?? [])
const machineName = R.path(['name'])(machine) ?? null const machineName = R.path(['name'])(machine) ?? null
const machineID = R.path(['deviceId'])(machine) ?? null const machineID = R.path(['deviceId'])(machine) ?? null

View file

@ -39,7 +39,7 @@ const styles = {
billList: ({ hideMachineData }) => ({ billList: ({ hideMachineData }) => ({
display: 'flex', display: 'flex',
flexDirection: 'column', flexDirection: 'column',
minWidth: hideMachineData ? 80 : 160, minWidth: hideMachineData ? 60 : 160,
'& > span': { '& > span': {
display: 'flex', display: 'flex',
flexDirection: 'row', flexDirection: 'row',
@ -126,7 +126,11 @@ const CashUnitDetails = ({
height={40} height={40}
currency={{ code: currency }} currency={{ code: currency }}
notes={machine.cashUnits[`cassette${it}`]} notes={machine.cashUnits[`cassette${it}`]}
denomination={getCashoutSettings(machine.id)[`cassette${it}`]} denomination={
getCashoutSettings(machine.id ?? machine.deviceId)[
`cassette${it}`
]
}
threshold={ threshold={
fillingPercentageSettings[`fillingPercentageCassette${it}`] fillingPercentageSettings[`fillingPercentageCassette${it}`]
} }
@ -152,7 +156,9 @@ const CashUnitDetails = ({
currency={{ code: currency }} currency={{ code: currency }}
notes={machine.cashUnits[`cassette${it}`]} notes={machine.cashUnits[`cassette${it}`]}
denomination={ denomination={
getCashoutSettings(machine.id)[`cassette${it}`] getCashoutSettings(machine.id ?? machine.deviceId)[
`cassette${it}`
]
} }
threshold={ threshold={
fillingPercentageSettings[ fillingPercentageSettings[
@ -178,7 +184,9 @@ const CashUnitDetails = ({
currency={{ code: currency }} currency={{ code: currency }}
notes={machine.cashUnits[`stacker${it}f`]} notes={machine.cashUnits[`stacker${it}f`]}
denomination={ denomination={
getCashoutSettings(machine.id)[`stacker${it}f`] getCashoutSettings(machine.id ?? machine.deviceId)[
`stacker${it}f`
]
} }
threshold={ threshold={
fillingPercentageSettings[ fillingPercentageSettings[
@ -193,7 +201,9 @@ const CashUnitDetails = ({
currency={{ code: currency }} currency={{ code: currency }}
notes={machine.cashUnits[`stacker${it}r`]} notes={machine.cashUnits[`stacker${it}r`]}
denomination={ denomination={
getCashoutSettings(machine.id)[`stacker${it}r`] getCashoutSettings(machine.id ?? machine.deviceId)[
`stacker${it}r`
]
} }
threshold={ threshold={
fillingPercentageSettings[ fillingPercentageSettings[

View file

@ -14,6 +14,7 @@ const getElements = (
widths, widths,
setMachineId setMachineId
) => { ) => {
console.log(config)
const fillingPercentageSettings = fromNamespace('notifications', config) const fillingPercentageSettings = fromNamespace('notifications', config)
const locale = fromNamespace('locale')(config) const locale = fromNamespace('locale')(config)
const cashout = fromNamespace('cashOut')(config) const cashout = fromNamespace('cashOut')(config)
@ -37,7 +38,7 @@ const getElements = (
<CashIn <CashIn
currency={{ code: fiatCurrency }} currency={{ code: fiatCurrency }}
notes={m.cashUnits.cashbox} notes={m.cashUnits.cashbox}
total={R.sum(R.map(it => it.fiat, bills[m.id] ?? []))} total={R.sum(R.map(it => it.fiat, bills[m.id ?? m.deviceId] ?? []))}
width={25} width={25}
height={45} height={45}
omitInnerPercentage omitInnerPercentage
@ -61,7 +62,9 @@ const getElements = (
width={'100%'} width={'100%'}
currency={{ code: fiatCurrency }} currency={{ code: fiatCurrency }}
notes={m.cashUnits[`cassette${it}`]} notes={m.cashUnits[`cassette${it}`]}
denomination={getCashoutSettings(m.id)[`cassette${it}`]} denomination={
getCashoutSettings(m.id ?? m.deviceId)[`cassette${it}`]
}
threshold={ threshold={
fillingPercentageSettings[`fillingPercentageCassette${it}`] fillingPercentageSettings[`fillingPercentageCassette${it}`]
} }
@ -76,7 +79,9 @@ const getElements = (
width={'100%'} width={'100%'}
currency={{ code: fiatCurrency }} currency={{ code: fiatCurrency }}
notes={m.cashUnits[`stacker${it}f`]} notes={m.cashUnits[`stacker${it}f`]}
denomination={getCashoutSettings(m.id)[`stacker${it}f`]} denomination={
getCashoutSettings(m.id ?? m.deviceId)[`stacker${it}f`]
}
threshold={ threshold={
fillingPercentageSettings[ fillingPercentageSettings[
`fillingPercentageStacker${it}f` `fillingPercentageStacker${it}f`
@ -88,7 +93,9 @@ const getElements = (
width={'100%'} width={'100%'}
currency={{ code: fiatCurrency }} currency={{ code: fiatCurrency }}
notes={m.cashUnits[`stacker${it}r`]} notes={m.cashUnits[`stacker${it}r`]}
denomination={getCashoutSettings(m.id)[`stacker${it}r`]} denomination={
getCashoutSettings(m.id ?? m.deviceId)[`stacker${it}r`]
}
threshold={ threshold={
fillingPercentageSettings[ fillingPercentageSettings[
`fillingPercentageStacker${it}r` `fillingPercentageStacker${it}r`
@ -118,7 +125,7 @@ const getElements = (
return ( return (
<IconButton <IconButton
onClick={() => { onClick={() => {
!R.isNil(setMachineId) && setMachineId(m.id) !R.isNil(setMachineId) && setMachineId(m.id ?? m.deviceId)
setWizard(true) setWizard(true)
}}> }}>
<EditIcon /> <EditIcon />