fix: automatic cashbox batch creation
This commit is contained in:
parent
61cc772816
commit
cba519fb4d
2 changed files with 4 additions and 5 deletions
|
|
@ -3,7 +3,7 @@ const _ = require('lodash/fp')
|
||||||
const uuid = require('uuid')
|
const uuid = require('uuid')
|
||||||
|
|
||||||
function createCashboxBatch (deviceId, cashboxCount) {
|
function createCashboxBatch (deviceId, cashboxCount) {
|
||||||
if (_.isEqual(0, cashboxCount)) throw new Error('Cashbox is empty. Cashbox batch could not be created')
|
if (_.isEqual(0, cashboxCount)) throw new Error('Cashbox is empty. Cashbox batch could not be created.')
|
||||||
const sql = `INSERT INTO cashbox_batches (id, device_id, created, operation_type) VALUES ($1, $2, now(), 'cash-in-empty') RETURNING *`
|
const sql = `INSERT INTO cashbox_batches (id, device_id, created, operation_type) VALUES ($1, $2, now(), 'cash-in-empty') RETURNING *`
|
||||||
const sql2 = `
|
const sql2 = `
|
||||||
UPDATE bills SET cashbox_batch_id=$1
|
UPDATE bills SET cashbox_batch_id=$1
|
||||||
|
|
|
||||||
|
|
@ -5,12 +5,11 @@ const cashbox = require('../cashbox-batches')
|
||||||
const machine = require('../machine-loader')
|
const machine = require('../machine-loader')
|
||||||
|
|
||||||
function notifyCashboxRemoval (req, res, next) {
|
function notifyCashboxRemoval (req, res, next) {
|
||||||
Promise.resolve()
|
return machine.getMachine(req.deviceId)
|
||||||
.then(() => machine.getMachine(req.deviceId))
|
|
||||||
.then(machine => cashbox.createCashboxBatch(req.deviceId, machine.cashbox))
|
.then(machine => cashbox.createCashboxBatch(req.deviceId, machine.cashbox))
|
||||||
.then(() => machine.emptyCashInBills(req))
|
.then(() => machine.setMachine({ deviceId: req.deviceId, action: 'emptyCashInBills' }))
|
||||||
.then(() => res.status(200).send({ status: 'OK' }))
|
.then(() => res.status(200).send({ status: 'OK' }))
|
||||||
.catch(next)
|
.catch(next)
|
||||||
}
|
}
|
||||||
|
|
||||||
router.post('/removal', notifyCashboxRemoval)
|
router.post('/removal', notifyCashboxRemoval)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue