fix: cashbox still being used elsewhere

This commit is contained in:
Taranto 2023-08-09 18:23:37 +01:00
parent 13d5860ccb
commit 53f74a1fc3
4 changed files with 8 additions and 20 deletions

View file

@ -48,8 +48,7 @@ function updateMachineWithBatch (machineContext, oldCashboxCount) {
bills.cashbox_batch_id IS NULL`, [batchId, deviceId])
const q3 = t.none(`UPDATE empty_unit_bills SET cashbox_batch_id=$1
WHERE empty_unit_bills.device_id = $2 AND empty_unit_bills.cashbox_batch_id IS NULL`, [batchId, deviceId])
const q4 = t.none(`UPDATE devices SET cashbox=$1, cassette1=$2, cassette2=$3, cassette3=$4, cassette4=$5, stacker1f=$6, stacker1r=$7, stacker2f=$8, stacker2r=$9, stacker3f=$10, stacker3r=$11 WHERE device_id=$12`, [
cashUnits.cashbox,
const q4 = t.none(`UPDATE devices SET cassette1=$1, cassette2=$2, cassette3=$3, cassette4=$4, stacker1f=$5, stacker1r=$6, stacker2f=$7, stacker2r=$8, stacker3f=$9, stacker3r=$10 WHERE device_id=$11`, [
cashUnits.cassette1,
cashUnits.cassette2,
cashUnits.cassette3,

View file

@ -172,21 +172,17 @@ function resetCashOutBills (rec) {
return db.none(sql, [cassette1, cassette2, cassette3, cassette4, stacker1f, stacker1r, stacker2f, stacker2r, stacker3f, stacker3r, rec.deviceId]).then(() => notifierQueries.invalidateNotification(detailB, 'fiatBalance'))
}
function emptyCashInBills (rec) {
const sql = 'UPDATE devices SET cashbox=0 WHERE device_id=$1'
return db.none(sql, [rec.deviceId])
}
function setCassetteBills (rec) {
const { cashbox, cassette1, cassette2, cassette3, cassette4, stacker1f, stacker1r, stacker2f, stacker2r, stacker3f, stacker3r } = rec.cashUnits
return db.oneOrNone(`SELECT cashbox FROM devices WHERE device_id=$1 LIMIT 1`, [rec.deviceId])
.then(oldCashboxValue => {
if (_.isNil(oldCashboxValue) || cashbox === oldCashboxValue.cashbox) {
const sql = 'UPDATE devices SET cashbox=$1, cassette1=$2, cassette2=$3, cassette3=$4, cassette4=$5, stacker1f=$6, stacker1r=$7, stacker2f=$8, stacker2r=$9, stacker3f=$10, stacker3r=$11 WHERE device_id=$12'
return db.none(sql, [cashbox, cassette1, cassette2, cassette3, cassette4, stacker1f, stacker1r, stacker2f, stacker2r, stacker3f, stacker3r, rec.deviceId])
return getMachine(rec.deviceId)
.then(machine => {
const oldCashboxCount = machine?.cashUnits?.cashbox
if (_.isNil(oldCashboxCount) || cashbox === oldCashboxCount) {
const sql = 'UPDATE devices SET cassette1=$1, cassette2=$2, cassette3=$3, cassette4=$4, stacker1f=$5, stacker1r=$6, stacker2f=$7, stacker2r=$8, stacker3f=$9, stacker3r=$10 WHERE device_id=$11'
return db.none(sql, [cassette1, cassette2, cassette3, cassette4, stacker1f, stacker1r, stacker2f, stacker2r, stacker3f, stacker3r, rec.deviceId])
}
return batching.updateMachineWithBatch({ ...rec, oldCashboxValue })
return batching.updateMachineWithBatch({ ...rec, oldCashboxValue: oldCashboxCount })
})
}
@ -361,7 +357,6 @@ function setMachine (rec, operatorId) {
rec.operatorId = operatorId
switch (rec.action) {
case 'rename': return renameMachine(rec)
case 'emptyCashInBills': return emptyCashInBills(rec)
case 'resetCashOutBills': return resetCashOutBills(rec)
case 'setCassetteBills': return setCassetteBills(rec)
case 'unpair': return unpair(rec)

View file

@ -73,7 +73,6 @@ const typeDef = gql`
enum MachineAction {
rename
emptyCashInBills
resetCashOutBills
setCassetteBills
unpair

View file

@ -27,11 +27,6 @@ function notifyCashboxRemoval (req, res, next) {
logger.info('** DEBUG ** - Cashbox removal - Cashbox reset is set to automatic. A cashbox batch WILL be created')
logger.info('** DEBUG ** - Cashbox removal - Creating new batch...')
return cashbox.createCashboxBatch(req.deviceId, machine.cashUnits.cashbox)
.then(() => {
logger.info(`** DEBUG ** - Cashbox removal - Finished creating the new cashbox batch`)
logger.info(`** DEBUG ** - Cashbox removal - Resetting the cashbox counter on device ${req.deviceId}`)
return setMachine({ deviceId: req.deviceId, action: 'emptyCashInBills' }, operatorId)
})
.then(() => {
logger.info(`** DEBUG ** - Cashbox removal - Process finished`)
return res.status(200).send({ status: 'OK' })