From 482e1afc3a60581eac2cd1361c7159d8702f651e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Salgado?= Date: Wed, 28 Apr 2021 16:11:43 +0100 Subject: [PATCH] fix: cashout detection on cash cassette wizard fix: cashbox wizard onContinue data fix: cashbox batch creation query feat: cashbox batch creation flow on UI --- lib/cashbox-batches.js | 8 +++-- .../graphql/resolvers/cashbox.resolver.js | 1 + lib/new-admin/graphql/types/cashbox.type.js | 1 + .../src/pages/Maintenance/CashboxHistory.js | 11 ++++-- .../src/pages/Maintenance/Wizard/Wizard.js | 35 ++++++++++++++++--- 5 files changed, 45 insertions(+), 11 deletions(-) diff --git a/lib/cashbox-batches.js b/lib/cashbox-batches.js index 4da64701..e670855a 100644 --- a/lib/cashbox-batches.js +++ b/lib/cashbox-batches.js @@ -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]) }) } diff --git a/lib/new-admin/graphql/resolvers/cashbox.resolver.js b/lib/new-admin/graphql/resolvers/cashbox.resolver.js index f44a1cbf..91e489bd 100644 --- a/lib/new-admin/graphql/resolvers/cashbox.resolver.js +++ b/lib/new-admin/graphql/resolvers/cashbox.resolver.js @@ -5,6 +5,7 @@ const resolvers = { cashboxBatches: () => cashbox.getBatches() }, Mutation: { + createBatch: (...[, { deviceId }]) => cashbox.createCashboxBatch(deviceId), editBatch: (...[, { id, performedBy }]) => cashbox.editBatchById(id, performedBy) } } diff --git a/lib/new-admin/graphql/types/cashbox.type.js b/lib/new-admin/graphql/types/cashbox.type.js index defb8f1c..15bc99e4 100644 --- a/lib/new-admin/graphql/types/cashbox.type.js +++ b/lib/new-admin/graphql/types/cashbox.type.js @@ -16,6 +16,7 @@ const typeDef = gql` } type Mutation { + createBatch(deviceId: ID): CashboxBatch editBatch(id: ID, performedBy: String): CashboxBatch } ` diff --git a/new-lamassu-admin/src/pages/Maintenance/CashboxHistory.js b/new-lamassu-admin/src/pages/Maintenance/CashboxHistory.js index e92482cf..6809cfdf 100644 --- a/new-lamassu-admin/src/pages/Maintenance/CashboxHistory.js +++ b/new-lamassu-admin/src/pages/Maintenance/CashboxHistory.js @@ -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 && ( - + )} ) diff --git a/new-lamassu-admin/src/pages/Maintenance/Wizard/Wizard.js b/new-lamassu-admin/src/pages/Maintenance/Wizard/Wizard.js index 61b1ab5d..187cbe51 100644 --- a/new-lamassu-admin/src/pages/Maintenance/Wizard/Wizard.js +++ b/new-lamassu-admin/src/pages/Maintenance/Wizard/Wizard.js @@ -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 (