diff --git a/lib/cash-in/cash-in-atomic.js b/lib/cash-in/cash-in-atomic.js index 079dc25c..a10f0b0f 100644 --- a/lib/cash-in/cash-in-atomic.js +++ b/lib/cash-in/cash-in-atomic.js @@ -46,8 +46,14 @@ function insertNewBills (t, billRows, machineTx) { const dbBills = _.map(cashInLow.massage, bills) const columns = ['id', 'fiat', 'fiat_code', 'crypto_code', 'cash_in_fee', 'cash_in_txs_id', 'device_time'] const sql = pgp.helpers.insert(dbBills, columns, 'bills') + const deviceID = machineTx.deviceId + const sql2 = `update devices set cashbox = cashbox + $2 + where device_id = $1` - return t.none(sql) + return t.none(sql2, [deviceID, dbBills.length]) + .then(() => { + return t.none(sql) + }) .then(() => bills) } diff --git a/lib/machine-loader.js b/lib/machine-loader.js index 5d3d23f0..6308ea9e 100644 --- a/lib/machine-loader.js +++ b/lib/machine-loader.js @@ -108,6 +108,11 @@ function emptyCashInBills (rec) { return db.none(sql, [rec.deviceId]) } +function setCassetteBills (rec) { + const sql = 'update devices set cashbox=$1, cassette1=$2, cassette2=$3 where device_id=$4' + return db.none(sql, [rec.cashbox, rec.cassettes[0], rec.cassettes[1], rec.deviceId]) +} + function unpair (rec) { return pairing.unpair(rec.deviceId) } @@ -129,6 +134,7 @@ function setMachine (rec) { case 'rename': return renameMachine(rec) case 'emptyCashInBills': return emptyCashInBills(rec) case 'resetCashOutBills': return resetCashOutBills(rec) + case 'setCassetteBills': return setCassetteBills(rec) case 'unpair': return unpair(rec) case 'reboot': return reboot(rec) case 'shutdown': return shutdown(rec) diff --git a/lib/new-admin/graphql/schema.js b/lib/new-admin/graphql/schema.js index 5648e229..f80e69d4 100644 --- a/lib/new-admin/graphql/schema.js +++ b/lib/new-admin/graphql/schema.js @@ -275,6 +275,7 @@ const typeDefs = gql` rename emptyCashInBills resetCashOutBills + setCassetteBills unpair reboot shutdown @@ -282,7 +283,7 @@ const typeDefs = gql` } type Mutation { - machineAction(deviceId:ID!, action: MachineAction!, cassette1: Int, cassette2: Int, newName: String): Machine + machineAction(deviceId:ID!, action: MachineAction!, cashbox: Int, cassette1: Int, cassette2: Int, newName: String): Machine setCustomer(customerId: ID!, customerInput: CustomerInput): Customer saveConfig(config: JSONObject): JSONObject resetConfig(schemaVersion: Int): JSONObject @@ -348,7 +349,7 @@ const resolvers = { coupons: () => couponManager.getAvailableCoupons() }, Mutation: { - machineAction: (...[, { deviceId, action, cassette1, cassette2, newName }]) => machineAction({ deviceId, action, cassette1, cassette2, newName }), + machineAction: (...[, { deviceId, action, cashbox, cassette1, cassette2, newName }]) => machineAction({ deviceId, action, cashbox, cassette1, cassette2, newName }), createPairingTotem: (...[, { name }]) => pairing.totem(name), saveAccounts: (...[, { accounts }]) => settingsLoader.saveAccounts(accounts), resetAccounts: (...[, { schemaVersion }]) => settingsLoader.resetAccounts(schemaVersion), diff --git a/lib/new-admin/machines.js b/lib/new-admin/machines.js index c34f0caa..78e2f46a 100644 --- a/lib/new-admin/machines.js +++ b/lib/new-admin/machines.js @@ -6,13 +6,13 @@ function getMachine (machineId) { .then(machines => machines.find(({ deviceId }) => deviceId === machineId)) } -function machineAction ({ deviceId, action, cassette1, cassette2, newName }) { +function machineAction ({ deviceId, action, cashbox, cassette1, cassette2, newName }) { return getMachine(deviceId) .then(machine => { if (!machine) throw new UserInputError(`machine:${deviceId} not found`, { deviceId }) return machine }) - .then(machineLoader.setMachine({ deviceId, action, cassettes: [cassette1, cassette2], newName })) + .then(machineLoader.setMachine({ deviceId, action, cashbox, cassettes: [cassette1, cassette2], newName })) .then(getMachine(deviceId)) } diff --git a/new-lamassu-admin/src/components/inputs/cashbox/Cashbox.js b/new-lamassu-admin/src/components/inputs/cashbox/Cashbox.js index 5305fd7d..9cbefaf9 100644 --- a/new-lamassu-admin/src/components/inputs/cashbox/Cashbox.js +++ b/new-lamassu-admin/src/components/inputs/cashbox/Cashbox.js @@ -31,19 +31,19 @@ const Cashbox = ({ percent = 0, cashOut = false, className }) => { // https://support.lamassu.is/hc/en-us/articles/360025595552-Installing-the-Sintra-Forte // Sintra and Sintra Forte can have up to 500 notes per cashOut box and up to 1000 per cashIn box -const CashIn = ({ capacity = 1000, notes = 0, total = 0 }) => { - const percent = (100 * notes) / capacity +const CashIn = ({ currency, notes, total }) => { const classes = gridClasses() return ( <>
-
- -
-
+
{notes} notes - {total} +
+
+ + {total} {currency.code} +
diff --git a/new-lamassu-admin/src/pages/Maintenance/CashCassettes.js b/new-lamassu-admin/src/pages/Maintenance/CashCassettes.js index c56ca880..b98ac604 100644 --- a/new-lamassu-admin/src/pages/Maintenance/CashCassettes.js +++ b/new-lamassu-admin/src/pages/Maintenance/CashCassettes.js @@ -5,7 +5,7 @@ import React from 'react' import * as Yup from 'yup' import { Table as EditableTable } from 'src/components/editableTable' -import { CashOut } from 'src/components/inputs/cashbox/Cashbox' +import { CashOut, CashIn } from 'src/components/inputs/cashbox/Cashbox' import { NumberInput } from 'src/components/inputs/formik' import TitleSection from 'src/components/layout/TitleSection' import { fromNamespace } from 'src/utils/config' @@ -16,6 +16,12 @@ const useStyles = makeStyles(styles) const ValidationSchema = Yup.object().shape({ name: Yup.string().required(), + cashbox: Yup.number() + .label('Cashbox') + .required() + .integer() + .min(0) + .max(1000), cassette1: Yup.number() .label('Cassette 1 (top)') .required() @@ -35,6 +41,7 @@ const GET_MACHINES_AND_CONFIG = gql` machines { name id: deviceId + cashbox cassette1 cassette2 } @@ -42,20 +49,23 @@ const GET_MACHINES_AND_CONFIG = gql` } ` -const RESET_CASHOUT_BILLS = gql` +const SET_CASSETTE_BILLS = gql` mutation MachineAction( $deviceId: ID! $action: MachineAction! + $cashbox: Int! $cassette1: Int! $cassette2: Int! ) { machineAction( deviceId: $deviceId action: $action + cashbox: $cashbox cassette1: $cassette1 cassette2: $cassette2 ) { deviceId + cashbox cassette1 cassette2 } @@ -67,7 +77,7 @@ const CashCassettes = () => { const { data } = useQuery(GET_MACHINES_AND_CONFIG) - const [resetCashOut, { error }] = useMutation(RESET_CASHOUT_BILLS, { + const [setCassetteBills, { error }] = useMutation(SET_CASSETTE_BILLS, { refetchQueries: () => ['getData'] }) @@ -75,11 +85,12 @@ const CashCassettes = () => { const locale = data?.config && fromNamespace('locale')(data.config) const fiatCurrency = locale?.fiatCurrency - const onSave = (...[, { id, cassette1, cassette2 }]) => { - return resetCashOut({ + const onSave = (...[, { id, cashbox, cassette1, cassette2 }]) => { + return setCassetteBills({ variables: { - action: 'resetCashOutBills', + action: 'setCassetteBills', deviceId: id, + cashbox, cassette1, cassette2 } @@ -97,6 +108,19 @@ const CashCassettes = () => { view: name => <>{name}, input: ({ field: { value: name } }) => <>{name} }, + { + name: 'cashbox', + header: 'Cashbox', + width: 240, + stripe: true, + view: value => ( + + ), + input: NumberInput, + inputProps: { + decimalPlaces: 0 + } + }, { name: 'cassette1', header: 'Cassette 1 (Top)',