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 ( <>