Merge pull request #933 from SiIky/feat/iCfPSCAQ/cashbox-history-backport
feat: cashbox history backport
This commit is contained in:
commit
60e939a4b9
16 changed files with 952 additions and 23 deletions
37
lib/cashbox-batches.js
Normal file
37
lib/cashbox-batches.js
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
const db = require('./db')
|
||||
const _ = require('lodash/fp')
|
||||
const uuid = require('uuid')
|
||||
|
||||
function createCashboxBatch (deviceId, cashboxCount) {
|
||||
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 sql2 = `
|
||||
UPDATE bills SET cashbox_batch_id=$1
|
||||
FROM cash_in_txs
|
||||
WHERE bills.cash_in_txs_id = cash_in_txs.id AND
|
||||
cash_in_txs.device_id = $2 AND
|
||||
bills.cashbox_batch_id IS NULL
|
||||
`
|
||||
return db.tx(async t => {
|
||||
const newBatch = await t.oneOrNone(sql, [uuid.v4(), deviceId])
|
||||
return t.oneOrNone(sql2, [newBatch.id, newBatch.device_id])
|
||||
})
|
||||
}
|
||||
|
||||
function getBatches () {
|
||||
const sql = `SELECT cb.id, cb.device_id, cb.created, cb.operation_type, cb.bill_count_override, cb.performed_by,
|
||||
json_agg(b.*) AS bills FROM cashbox_batches cb LEFT JOIN bills b ON cb.id=b.cashbox_batch_id GROUP BY cb.id`
|
||||
return db.any(sql).then(res => _.map(it => _.mapKeys(ite => _.camelCase(ite), it), res))
|
||||
}
|
||||
|
||||
function editBatchById (id, performedBy) {
|
||||
const sql = `UPDATE cashbox_batches SET performed_by=$1 WHERE id=$2`
|
||||
return db.none(sql, [performedBy, id])
|
||||
}
|
||||
|
||||
function getBillsByBatchId (id) {
|
||||
const sql = `SELECT * FROM bills WHERE cashbox_batch_id=$1`
|
||||
return db.any(sql, [id])
|
||||
}
|
||||
|
||||
module.exports = { createCashboxBatch, getBatches, getBillsByBatchId, editBatchById }
|
||||
|
|
@ -118,7 +118,7 @@ function getMachine (machineId, config) {
|
|||
.then(([machine, events, config]) => {
|
||||
const pings = checkPings([machine])
|
||||
|
||||
return [machine].map(addName(pings, events, config))[0]
|
||||
return addName(pings, events, config)(machine)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ const { GraphQLJSON, GraphQLJSONObject } = require('graphql-type-json')
|
|||
const got = require('got')
|
||||
const DataLoader = require('dataloader')
|
||||
|
||||
const cashbox = require('../../cashbox-batches')
|
||||
const machineLoader = require('../../machine-loader')
|
||||
const customers = require('../../customers')
|
||||
const { machineAction } = require('../machines')
|
||||
|
|
@ -273,14 +274,25 @@ const typeDefs = gql`
|
|||
valid: Boolean
|
||||
}
|
||||
|
||||
type Bills {
|
||||
type Bill {
|
||||
fiat: Int
|
||||
deviceId: ID
|
||||
created: Date
|
||||
cashbox: Int
|
||||
}
|
||||
|
||||
type CashboxBatch {
|
||||
id: ID
|
||||
deviceId: ID
|
||||
created: Date
|
||||
operationType: String
|
||||
customBillCount: Int
|
||||
performedBy: String
|
||||
bills: [Bill]
|
||||
}
|
||||
|
||||
type Query {
|
||||
cashboxBatches: [CashboxBatch]
|
||||
countries: [Country]
|
||||
currencies: [Currency]
|
||||
languages: [Language]
|
||||
|
|
@ -315,7 +327,7 @@ const typeDefs = gql`
|
|||
notifications: [Notification]
|
||||
alerts: [Notification]
|
||||
hasUnreadNotifications: Boolean
|
||||
bills: [Bills]
|
||||
bills: [Bill]
|
||||
}
|
||||
|
||||
type SupportLogsResponse {
|
||||
|
|
@ -352,6 +364,8 @@ const typeDefs = gql`
|
|||
toggleClearNotification(id: ID!, read: Boolean!): Notification
|
||||
clearAllNotifications: Notification
|
||||
cancelCashOutTransaction(id: ID): Transaction
|
||||
createBatch(deviceId: ID, cashboxCount: Int): CashboxBatch
|
||||
editBatch(id: ID, performedBy: String): CashboxBatch
|
||||
}
|
||||
`
|
||||
|
||||
|
|
@ -378,6 +392,7 @@ const resolvers = {
|
|||
latestEvent: parent => machineEventsLoader.load(parent.deviceId)
|
||||
},
|
||||
Query: {
|
||||
cashboxBatches: () => cashbox.getBatches(),
|
||||
countries: () => countries,
|
||||
currencies: () => currencies,
|
||||
languages: () => languages,
|
||||
|
|
@ -449,7 +464,9 @@ const resolvers = {
|
|||
deletePromoCode: (...[, { codeId }]) => promoCodeManager.deletePromoCode(codeId),
|
||||
toggleClearNotification: (...[, { id, read }]) => notifierQueries.setRead(id, read),
|
||||
clearAllNotifications: () => notifierQueries.markAllAsRead(),
|
||||
cancelCashOutTransaction: (...[, { id }]) => cashOutTx.cancel(id)
|
||||
cancelCashOutTransaction: (...[, { id }]) => cashOutTx.cancel(id),
|
||||
createBatch: (...[, { deviceId, cashboxCount }]) => cashbox.createCashboxBatch(deviceId, cashboxCount),
|
||||
editBatch: (...[, { id, performedBy }]) => cashbox.editBatchById(id, performedBy)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ const express = require('express')
|
|||
const nmd = require('nano-markdown')
|
||||
const semver = require('semver')
|
||||
|
||||
const cashbox = require('./cashbox-batches')
|
||||
const dbErrorCodes = require('./db-error-codes')
|
||||
const options = require('./options')
|
||||
const logger = require('./logger')
|
||||
|
|
@ -222,6 +223,14 @@ function stateChange (req, res, next) {
|
|||
.catch(next)
|
||||
}
|
||||
|
||||
function notifyCashboxRemoval (req, res, next) {
|
||||
return machineLoader.getMachine(req.deviceId)
|
||||
.then(machineLoader => cashbox.createCashboxBatch(req.deviceId, machineLoader.cashbox))
|
||||
.then(() => machineLoader.setMachine({ deviceId: req.deviceId, action: 'emptyCashInBills' }))
|
||||
.then(() => res.status(200).send({ status: 'OK' }))
|
||||
.catch(next)
|
||||
}
|
||||
|
||||
function verifyUser (req, res, next) {
|
||||
const pi = plugins(req.settings, req.deviceId)
|
||||
pi.verifyUser(req.body)
|
||||
|
|
@ -546,6 +555,7 @@ app.use(filterOldRequests)
|
|||
app.get('/poll', poll)
|
||||
app.get('/terms_conditions', getTermsConditions)
|
||||
app.post('/state', stateChange)
|
||||
app.post('/cashbox/removal', notifyCashboxRemoval)
|
||||
|
||||
app.post('/network/heartbeat', networkHeartbeat)
|
||||
app.post('/network/performance', networkPerformance)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue