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([])
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 sql = pgp.helpers.insert(dbBills, columns, 'bills')
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`
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(() => {
return t.none(sql)
})