fix: cashbox batch creation with the new settings
fix: correctly update cassette and stacker count post-cashout tx
This commit is contained in:
parent
460a8cf1fd
commit
4338b3d98e
6 changed files with 15 additions and 18 deletions
|
|
@ -107,17 +107,10 @@ function nextHd (t, isHd, tx) {
|
|||
function updateCassettes (t, tx) {
|
||||
if (!dispenseOccurred(tx.bills)) return Promise.resolve()
|
||||
|
||||
const sql = `update devices set
|
||||
${_.size(tx.bills) > 0 ? `cassette1 = cassette1 - $1` : ``}
|
||||
${_.size(tx.bills) > 1 ? `, cassette2 = cassette2 - $2` : ``}
|
||||
${_.size(tx.bills) > 2 ? `, cassette3 = cassette3 - $3` : ``}
|
||||
${_.size(tx.bills) > 3 ? `, cassette4 = cassette4 - $4` : ``}
|
||||
where device_id = $${_.size(tx.bills) + 1}
|
||||
returning
|
||||
${_.size(tx.bills) > 0 ? `cassette1` : ``}
|
||||
${_.size(tx.bills) > 1 ? `, cassette2`: ``}
|
||||
${_.size(tx.bills) > 2 ? `, cassette3` : ``}
|
||||
${_.size(tx.bills) > 3 ? `, cassette4` : ``}`
|
||||
const billsStmt = _.join(', ')(_.map(it => `${tx.bills[it].name} = ${tx.bills[it].name} - $${it + 1}`)(_.range(0, _.size(tx.bills))))
|
||||
const returnStmt = _.join(', ')(_.map(bill => `${bill.name}`)(tx.bills))
|
||||
|
||||
const sql = `UPDATE devices SET ${billsStmt} WHERE device_id = $${_.size(tx.bills) + 1} RETURNING ${returnStmt}`
|
||||
|
||||
const values = []
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,8 @@ function createCashboxBatch (deviceId, cashboxCount) {
|
|||
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
|
||||
cash_in_txs.device_id = $2 AND
|
||||
bills.destination_unit = 'cashbox' AND
|
||||
bills.cashbox_batch_id IS NULL
|
||||
`
|
||||
const sql3 = `
|
||||
|
|
@ -42,7 +43,8 @@ function updateMachineWithBatch (machineContext, oldCashboxCount) {
|
|||
const q1 = t.none(`INSERT INTO cash_unit_operation (id, device_id, created, operation_type) VALUES ($1, $2, now(), 'cash-box-empty')`, [batchId, deviceId])
|
||||
const q2 = t.none(`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
|
||||
cash_in_txs.device_id = $2 AND
|
||||
bills.destination_unit = 'cashbox' AND
|
||||
bills.cashbox_batch_id IS NULL`, [batchId, deviceId])
|
||||
const q3 = t.none(`UPDATE empty_unit_bills SET cashbox_batch_id=$1
|
||||
WHERE empty_unit_bills.device_id = $2 AND empty_unit_bills.cashbox_batch_id IS NULL`, [batchId, deviceId])
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ const getBills = filters => {
|
|||
|
||||
const sql = `SELECT b.id, b.fiat, b.fiat_code, b.created, b.cashbox_batch_id, cit.device_id AS device_id FROM bills b LEFT OUTER JOIN (
|
||||
SELECT id, device_id FROM cash_in_txs ${deviceStatement}
|
||||
) AS cit ON cit.id = b.cash_in_txs_id ${batchStatement(filters.batch)}`
|
||||
) AS cit ON cit.id = b.cash_in_txs_id ${batchStatement(filters.batch)} ${_.isNil(batchStatement(filters.batch)) ? `WHERE` : `AND`} b.destination_unit = 'cashbox'`
|
||||
|
||||
const sql2 = `SELECT b.id, b.fiat, b.fiat_code, b.created, b.cashbox_batch_id, b.device_id FROM empty_unit_bills b ${deviceStatement} ${!_.isNil(filters.deviceId) && !_.isNil(filters.batch) ? `AND` : ``} ${batchStatement(filters.batch)}`
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue