feat: assign unit destination during cash-in

fix: cash cassettes wizard initial values
This commit is contained in:
Sérgio Salgado 2023-04-21 01:07:46 +01:00
parent 2967ad3a75
commit 2d010fc359
3 changed files with 46 additions and 22 deletions

View file

@ -41,13 +41,24 @@ function insertNewBills (t, billRows, machineTx) {
if (_.isEmpty(bills)) return Promise.resolve([]) if (_.isEmpty(bills)) return Promise.resolve([])
const dbBills = _.map(cashInLow.massage, bills) const dbBills = _.map(cashInLow.massage, bills)
const getBillsByDestination = destination => _.filter(it => it.destination_unit === destination)(dbBills)
const columns = ['id', 'fiat', 'fiat_code', 'crypto_code', 'cash_in_fee', 'cash_in_txs_id', 'device_time', 'destination_unit'] const columns = ['id', 'fiat', 'fiat_code', 'crypto_code', 'cash_in_fee', 'cash_in_txs_id', 'device_time', 'destination_unit']
const sql = pgp.helpers.insert(dbBills, columns, 'bills') const sql = pgp.helpers.insert(dbBills, columns, 'bills')
const deviceID = machineTx.deviceId const deviceID = machineTx.deviceId
const sql2 = `update devices set cashbox = cashbox + $2 const sql2 = `update devices set cashbox = cashbox + $2, stacker1f = stacker1f + $3, stacker1r = stacker1r + $4, stacker2f = stacker2f + $5, stacker2r = stacker2r + $6, stacker3f = stacker3f + $7, stacker3r = stacker3r + $8
where device_id = $1` where device_id = $1`
return t.none(sql2, [deviceID, dbBills.length]) return t.none(sql2, [
deviceID,
getBillsByDestination('cashbox').length,
getBillsByDestination('stacker1f').length,
getBillsByDestination('stacker1r').length,
getBillsByDestination('stacker2f').length,
getBillsByDestination('stacker2r').length,
getBillsByDestination('stacker3f').length,
getBillsByDestination('stacker3r').length
])
.then(() => { .then(() => {
return t.none(sql) return t.none(sql)
}) })

View file

@ -229,25 +229,22 @@ const dynamicConfig = ({ deviceId, operatorId, pid, pq, settings, }) => {
const configs = (parent, { currentConfigVersion }, { deviceId, deviceName, operatorId, pid, settings }, info) => const configs = (parent, { currentConfigVersion }, { deviceId, deviceName, operatorId, pid, settings }, info) =>
plugins(settings, deviceId) plugins(settings, deviceId)
.pollQueries() .pollQueries()
.then(pq => { .then(pq => ({
console.log(pq) static: staticConfig({
return { currentConfigVersion,
static: staticConfig({ deviceId,
currentConfigVersion, deviceName,
deviceId, pq,
deviceName, settings,
pq, }),
settings, dynamic: dynamicConfig({
}), deviceId,
dynamic: dynamicConfig({ operatorId,
deviceId, pid,
operatorId, pq,
pid, settings,
pq, }),
settings, }))
}),
}
})
const massageTerms = terms => (terms.active && terms.text) ? ({ const massageTerms = terms => (terms.active && terms.text) ? ({

View file

@ -156,7 +156,7 @@ const Wizard = ({ machine, cashoutSettings, locale, onClose, save, error }) => {
]) ])
) )
const makeInitialValues = () => const makeCassettesInitialValues = () =>
!R.isEmpty(cashoutSettings) !R.isEmpty(cashoutSettings)
? R.reduce( ? R.reduce(
(acc, value) => { (acc, value) => {
@ -168,6 +168,22 @@ const Wizard = ({ machine, cashoutSettings, locale, onClose, save, error }) => {
) )
: {} : {}
const makeStackersInitialValues = () =>
!R.isEmpty(cashoutSettings)
? R.reduce(
(acc, value) => {
acc[`stacker${value}f`] = ''
acc[`stacker${value}r`] = ''
return acc
},
{},
R.range(1, numberOfStackers + 1)
)
: {}
const makeInitialValues = () =>
R.merge(makeCassettesInitialValues(), makeStackersInitialValues())
const steps = R.pipe( const steps = R.pipe(
R.concat(makeStackerSteps(numberOfStackers)), R.concat(makeStackerSteps(numberOfStackers)),
R.concat(makeCassetteSteps(numberOfCassettes)), R.concat(makeCassetteSteps(numberOfCassettes)),