feat: cashbox batch creation on machine cashbox removal
fix: cashbox batch creation with empty cashbox
This commit is contained in:
parent
482e1afc3a
commit
61cc772816
5 changed files with 15 additions and 13 deletions
|
|
@ -2,8 +2,8 @@ const db = require('./db')
|
||||||
const _ = require('lodash/fp')
|
const _ = require('lodash/fp')
|
||||||
const uuid = require('uuid')
|
const uuid = require('uuid')
|
||||||
|
|
||||||
function createCashboxBatch (deviceId) {
|
function createCashboxBatch (deviceId, cashboxCount) {
|
||||||
console.log('herererere')
|
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,7 +5,7 @@ const resolvers = {
|
||||||
cashboxBatches: () => cashbox.getBatches()
|
cashboxBatches: () => cashbox.getBatches()
|
||||||
},
|
},
|
||||||
Mutation: {
|
Mutation: {
|
||||||
createBatch: (...[, { deviceId }]) => cashbox.createCashboxBatch(deviceId),
|
createBatch: (...[, { deviceId, cashboxCount }]) => cashbox.createCashboxBatch(deviceId, cashboxCount),
|
||||||
editBatch: (...[, { id, performedBy }]) => cashbox.editBatchById(id, performedBy)
|
editBatch: (...[, { id, performedBy }]) => cashbox.editBatchById(id, performedBy)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ const typeDef = gql`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Mutation {
|
type Mutation {
|
||||||
createBatch(deviceId: ID): CashboxBatch
|
createBatch(deviceId: ID, cashboxCount: Int): CashboxBatch
|
||||||
editBatch(id: ID, performedBy: String): CashboxBatch
|
editBatch(id: ID, performedBy: String): CashboxBatch
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,15 @@
|
||||||
const express = require('express')
|
const express = require('express')
|
||||||
const router = express.Router()
|
const router = express.Router()
|
||||||
|
|
||||||
|
const cashbox = require('../cashbox-batches')
|
||||||
|
const machine = require('../machine-loader')
|
||||||
|
|
||||||
function notifyCashboxRemoval (req, res, next) {
|
function notifyCashboxRemoval (req, res, next) {
|
||||||
Promise.resolve()
|
Promise.resolve()
|
||||||
.then(() => {
|
.then(() => machine.getMachine(req.deviceId))
|
||||||
console.log(`Device ${req.deviceId} had its cashbox removed.`)
|
.then(machine => cashbox.createCashboxBatch(req.deviceId, machine.cashbox))
|
||||||
return res.status(200).send({ status: 'OK' })
|
.then(() => machine.emptyCashInBills(req))
|
||||||
})
|
.then(() => res.status(200).send({ status: 'OK' }))
|
||||||
.catch(next)
|
.catch(next)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,8 +14,8 @@ const MODAL_HEIGHT = 520
|
||||||
const CASHBOX_DEFAULT_CAPACITY = 500
|
const CASHBOX_DEFAULT_CAPACITY = 500
|
||||||
|
|
||||||
const CREATE_BATCH = gql`
|
const CREATE_BATCH = gql`
|
||||||
mutation createBatch($deviceId: ID) {
|
mutation createBatch($deviceId: ID, $cashboxCount: Int) {
|
||||||
createBatch(deviceId: $deviceId) {
|
createBatch(deviceId: $deviceId, cashboxCount: $cashboxCount) {
|
||||||
id
|
id
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -38,7 +38,6 @@ const Wizard = ({ machine, cashoutSettings, locale, onClose, save, error }) => {
|
||||||
const isLastStep = step === LAST_STEP
|
const isLastStep = step === LAST_STEP
|
||||||
|
|
||||||
const onContinue = it => {
|
const onContinue = it => {
|
||||||
console.log('it?.wasCashboxEmptied', it?.wasCashboxEmptied)
|
|
||||||
const wasCashboxEmptied = it?.wasCashboxEmptied === 'YES'
|
const wasCashboxEmptied = it?.wasCashboxEmptied === 'YES'
|
||||||
|
|
||||||
const cashbox = wasCashboxEmptied ? 0 : machine?.cashbox
|
const cashbox = wasCashboxEmptied ? 0 : machine?.cashbox
|
||||||
|
|
@ -46,10 +45,10 @@ const Wizard = ({ machine, cashoutSettings, locale, onClose, save, error }) => {
|
||||||
const newConfig = R.merge(config, it)
|
const newConfig = R.merge(config, it)
|
||||||
if (isLastStep) {
|
if (isLastStep) {
|
||||||
if (wasCashboxEmptied) {
|
if (wasCashboxEmptied) {
|
||||||
console.log('cashbox was emptied')
|
|
||||||
createBatch({
|
createBatch({
|
||||||
variables: {
|
variables: {
|
||||||
deviceId: machine.id
|
deviceId: machine.id,
|
||||||
|
cashboxCount: machine.cashbox
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue