fix: cashout detection on cash cassette wizard
fix: cashbox wizard onContinue data fix: cashbox batch creation query feat: cashbox batch creation flow on UI
This commit is contained in:
parent
e05e44f468
commit
482e1afc3a
5 changed files with 45 additions and 11 deletions
|
|
@ -1,8 +1,10 @@
|
|||
const db = require('./db')
|
||||
const _ = require('lodash/fp')
|
||||
const uuid = require('uuid')
|
||||
|
||||
function createCashboxBatch (rec) {
|
||||
const sql = 'INSERT INTO cashbox_batches (device_id, created) VALUES ($1, now()) RETURNING *'
|
||||
function createCashboxBatch (deviceId) {
|
||||
console.log('herererere')
|
||||
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
|
||||
|
|
@ -11,7 +13,7 @@ function createCashboxBatch (rec) {
|
|||
bills.cashbox_batch_id IS NULL
|
||||
`
|
||||
return db.tx(async t => {
|
||||
const newBatch = await t.oneOrNone(sql, [rec.deviceId])
|
||||
const newBatch = await t.oneOrNone(sql, [uuid.v4(), deviceId])
|
||||
return t.oneOrNone(sql2, [newBatch.id, newBatch.device_id])
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ const resolvers = {
|
|||
cashboxBatches: () => cashbox.getBatches()
|
||||
},
|
||||
Mutation: {
|
||||
createBatch: (...[, { deviceId }]) => cashbox.createCashboxBatch(deviceId),
|
||||
editBatch: (...[, { id, performedBy }]) => cashbox.editBatchById(id, performedBy)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ const typeDef = gql`
|
|||
}
|
||||
|
||||
type Mutation {
|
||||
createBatch(deviceId: ID): CashboxBatch
|
||||
editBatch(id: ID, performedBy: String): CashboxBatch
|
||||
}
|
||||
`
|
||||
|
|
|
|||
|
|
@ -175,7 +175,7 @@ const CashboxHistory = ({ machines, currency }) => {
|
|||
{
|
||||
name: 'date',
|
||||
header: 'Date',
|
||||
width: 125,
|
||||
width: 135,
|
||||
textAlign: 'right',
|
||||
view: it => moment.utc(it.created).format('YYYY-MM-DD')
|
||||
},
|
||||
|
|
@ -189,7 +189,7 @@ const CashboxHistory = ({ machines, currency }) => {
|
|||
{
|
||||
name: 'performedBy',
|
||||
header: 'Performed by',
|
||||
width: 190,
|
||||
width: 180,
|
||||
textAlign: 'left',
|
||||
view: it => {
|
||||
if (!editing)
|
||||
|
|
@ -239,7 +239,12 @@ const CashboxHistory = ({ machines, currency }) => {
|
|||
return (
|
||||
<>
|
||||
{!loading && (
|
||||
<DataTable name="cashboxHistory" elements={elements} data={batches} />
|
||||
<DataTable
|
||||
name="cashboxHistory"
|
||||
elements={elements}
|
||||
data={batches}
|
||||
emptyText="No cashbox batches so far"
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
import { useMutation } from '@apollo/react-hooks'
|
||||
import gql from 'graphql-tag'
|
||||
import * as R from 'ramda'
|
||||
import React, { useState } from 'react'
|
||||
import * as Yup from 'yup'
|
||||
|
|
@ -11,22 +13,47 @@ const MODAL_WIDTH = 554
|
|||
const MODAL_HEIGHT = 520
|
||||
const CASHBOX_DEFAULT_CAPACITY = 500
|
||||
|
||||
const CREATE_BATCH = gql`
|
||||
mutation createBatch($deviceId: ID) {
|
||||
createBatch(deviceId: $deviceId) {
|
||||
id
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
const Wizard = ({ machine, cashoutSettings, locale, onClose, save, error }) => {
|
||||
const [{ step, config }, setState] = useState({
|
||||
step: 0,
|
||||
config: { active: true }
|
||||
})
|
||||
|
||||
const LAST_STEP = R.isEmpty(cashoutSettings) ? 1 : 3
|
||||
const [createBatch] = useMutation(CREATE_BATCH)
|
||||
|
||||
const isCashOutDisabled =
|
||||
R.isEmpty(cashoutSettings) || !cashoutSettings?.active
|
||||
|
||||
const LAST_STEP = isCashOutDisabled ? 1 : 3
|
||||
|
||||
const title = `Update counts`
|
||||
const isLastStep = step === LAST_STEP
|
||||
|
||||
const onContinue = it => {
|
||||
const cashbox = config?.wasCashboxEmptied === 'YES' ? 0 : machine?.cashbox
|
||||
console.log('it?.wasCashboxEmptied', it?.wasCashboxEmptied)
|
||||
const wasCashboxEmptied = it?.wasCashboxEmptied === 'YES'
|
||||
|
||||
const cashbox = wasCashboxEmptied ? 0 : machine?.cashbox
|
||||
|
||||
const newConfig = R.merge(config, it)
|
||||
if (isLastStep) {
|
||||
if (wasCashboxEmptied) {
|
||||
console.log('cashbox was emptied')
|
||||
createBatch({
|
||||
variables: {
|
||||
deviceId: machine.id
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
save(
|
||||
machine.id,
|
||||
parseInt(cashbox),
|
||||
|
|
@ -73,9 +100,7 @@ const Wizard = ({ machine, cashoutSettings, locale, onClose, save, error }) => {
|
|||
]
|
||||
|
||||
const filteredSteps = R.filter(it => {
|
||||
return (
|
||||
!it.cashoutRequired || (!R.isEmpty(cashoutSettings) && it.cashoutRequired)
|
||||
)
|
||||
return !it.cashoutRequired || (!isCashOutDisabled && it.cashoutRequired)
|
||||
}, steps)
|
||||
|
||||
return (
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue