fix: cashbox still being used elsewhere
This commit is contained in:
parent
13d5860ccb
commit
53f74a1fc3
4 changed files with 8 additions and 20 deletions
|
|
@ -48,8 +48,7 @@ function updateMachineWithBatch (machineContext, oldCashboxCount) {
|
||||||
bills.cashbox_batch_id IS NULL`, [batchId, deviceId])
|
bills.cashbox_batch_id IS NULL`, [batchId, deviceId])
|
||||||
const q3 = t.none(`UPDATE empty_unit_bills SET cashbox_batch_id=$1
|
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])
|
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`, [
|
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.cashbox,
|
|
||||||
cashUnits.cassette1,
|
cashUnits.cassette1,
|
||||||
cashUnits.cassette2,
|
cashUnits.cassette2,
|
||||||
cashUnits.cassette3,
|
cashUnits.cassette3,
|
||||||
|
|
|
||||||
|
|
@ -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'))
|
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) {
|
function setCassetteBills (rec) {
|
||||||
const { cashbox, cassette1, cassette2, cassette3, cassette4, stacker1f, stacker1r, stacker2f, stacker2r, stacker3f, stacker3r } = rec.cashUnits
|
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])
|
return getMachine(rec.deviceId)
|
||||||
.then(oldCashboxValue => {
|
.then(machine => {
|
||||||
if (_.isNil(oldCashboxValue) || cashbox === oldCashboxValue.cashbox) {
|
const oldCashboxCount = machine?.cashUnits?.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'
|
if (_.isNil(oldCashboxCount) || cashbox === oldCashboxCount) {
|
||||||
return db.none(sql, [cashbox, cassette1, cassette2, cassette3, cassette4, stacker1f, stacker1r, stacker2f, stacker2r, stacker3f, stacker3r, rec.deviceId])
|
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
|
rec.operatorId = operatorId
|
||||||
switch (rec.action) {
|
switch (rec.action) {
|
||||||
case 'rename': return renameMachine(rec)
|
case 'rename': return renameMachine(rec)
|
||||||
case 'emptyCashInBills': return emptyCashInBills(rec)
|
|
||||||
case 'resetCashOutBills': return resetCashOutBills(rec)
|
case 'resetCashOutBills': return resetCashOutBills(rec)
|
||||||
case 'setCassetteBills': return setCassetteBills(rec)
|
case 'setCassetteBills': return setCassetteBills(rec)
|
||||||
case 'unpair': return unpair(rec)
|
case 'unpair': return unpair(rec)
|
||||||
|
|
|
||||||
|
|
@ -73,7 +73,6 @@ const typeDef = gql`
|
||||||
|
|
||||||
enum MachineAction {
|
enum MachineAction {
|
||||||
rename
|
rename
|
||||||
emptyCashInBills
|
|
||||||
resetCashOutBills
|
resetCashOutBills
|
||||||
setCassetteBills
|
setCassetteBills
|
||||||
unpair
|
unpair
|
||||||
|
|
|
||||||
|
|
@ -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 - Cashbox reset is set to automatic. A cashbox batch WILL be created')
|
||||||
logger.info('** DEBUG ** - Cashbox removal - Creating new batch...')
|
logger.info('** DEBUG ** - Cashbox removal - Creating new batch...')
|
||||||
return cashbox.createCashboxBatch(req.deviceId, machine.cashUnits.cashbox)
|
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(() => {
|
.then(() => {
|
||||||
logger.info(`** DEBUG ** - Cashbox removal - Process finished`)
|
logger.info(`** DEBUG ** - Cashbox removal - Process finished`)
|
||||||
return res.status(200).send({ status: 'OK' })
|
return res.status(200).send({ status: 'OK' })
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue