diff --git a/lib/cashbox-batches.js b/lib/cashbox-batches.js index 86912480..b993a786 100644 --- a/lib/cashbox-batches.js +++ b/lib/cashbox-batches.js @@ -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, diff --git a/lib/machine-loader.js b/lib/machine-loader.js index a0ea1f6a..0fafb9ac 100644 --- a/lib/machine-loader.js +++ b/lib/machine-loader.js @@ -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) diff --git a/lib/new-admin/graphql/types/machine.type.js b/lib/new-admin/graphql/types/machine.type.js index 631f64ef..08476a8a 100644 --- a/lib/new-admin/graphql/types/machine.type.js +++ b/lib/new-admin/graphql/types/machine.type.js @@ -73,7 +73,6 @@ const typeDef = gql` enum MachineAction { rename - emptyCashInBills resetCashOutBills setCassetteBills unpair diff --git a/lib/routes/cashboxRoutes.js b/lib/routes/cashboxRoutes.js index 8e718a70..cec84416 100644 --- a/lib/routes/cashboxRoutes.js +++ b/lib/routes/cashboxRoutes.js @@ -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' })