feat: cashbox batch table and update bills
This commit is contained in:
parent
4f12bcf4cf
commit
20703d0271
2 changed files with 45 additions and 0 deletions
19
lib/cashbox-batches.js
Normal file
19
lib/cashbox-batches.js
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
const db = require('./db')
|
||||
|
||||
function createCashBoxBatch (rec) {
|
||||
const sql = 'INSERT INTO cashbox_batches (device_id, created) VALUES ($1, now()) RETURNING *'
|
||||
const sql2 = `
|
||||
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
|
||||
bills.cashbox_batch_id IS NULL
|
||||
`
|
||||
return db.oneOrNone(sql, [rec.deviceId])
|
||||
.then(res => {
|
||||
console.log(res)
|
||||
return db.oneOrNone(sql2, [res.id, res.device_id])
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = { createCashBoxBatch }
|
||||
26
migrations/1616528363530-add_cashbox_batches.js
Normal file
26
migrations/1616528363530-add_cashbox_batches.js
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
var db = require('./db')
|
||||
|
||||
exports.up = function (next) {
|
||||
var sqls = [
|
||||
`create table cashbox_batches (
|
||||
id serial PRIMARY KEY,
|
||||
device_id text REFERENCES devices (device_id),
|
||||
created timestamptz NOT NULL default now()
|
||||
)`,
|
||||
|
||||
`ALTER TABLE bills ADD COLUMN legacy boolean DEFAULT false`,
|
||||
|
||||
`ALTER TABLE bills ADD COLUMN cashbox_batch_id int`,
|
||||
|
||||
`ALTER TABLE bills ADD CONSTRAINT cashbox_batch_id
|
||||
FOREIGN KEY (cashbox_batch_id)
|
||||
REFERENCES cashbox_batches (id)`,
|
||||
|
||||
`UPDATE bills SET legacy = 'true'`
|
||||
]
|
||||
db.multi(sqls, next)
|
||||
}
|
||||
|
||||
exports.down = function (next) {
|
||||
next()
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue