feat: add emptyUnit bills table

feat: rework cash unit operations
fix: multiple fixes for the empty unit workflow
This commit is contained in:
Sérgio Salgado 2023-05-04 02:43:19 +01:00
parent 797f074898
commit 45f722e724
8 changed files with 171 additions and 59 deletions

View file

@ -48,8 +48,65 @@ exports.up = function (next) {
ADD COLUMN denomination_2r INTEGER,
ADD COLUMN denomination_3f INTEGER,
ADD COLUMN denomination_3r INTEGER`,
`CREATE TYPE bill_destination_unit AS ENUM ('cashbox', 'stacker1f', 'stacker1r', 'stacker2f', 'stacker2r', 'stacker3f', 'stacker3r')`,
`ALTER TABLE bills ADD COLUMN destination_unit bill_destination_unit NOT NULL DEFAULT 'cashbox'`
`CREATE TYPE cash_unit AS ENUM (
'cashbox',
'cassette1',
'cassette2',
'cassette3',
'cassette4',
'stacker1f',
'stacker1r',
'stacker2f',
'stacker2r',
'stacker3f',
'stacker3r'
)`,
`ALTER TABLE bills ADD COLUMN destination_unit cash_unit NOT NULL DEFAULT 'cashbox'`,
`CREATE TYPE cash_unit_operation_type AS ENUM(
'cash-box-empty',
'cash-box-refill',
'cash-cassette-1-refill',
'cash-cassette-1-empty',
'cash-cassette-1-count-change',
'cash-cassette-2-refill',
'cash-cassette-2-empty',
'cash-cassette-2-count-change',
'cash-cassette-3-refill',
'cash-cassette-3-empty',
'cash-cassette-3-count-change',
'cash-cassette-4-refill',
'cash-cassette-4-empty',
'cash-cassette-4-count-change',
'cash-stacker-1f-refill',
'cash-stacker-1f-empty',
'cash-stacker-1f-count-change',
'cash-stacker-1r-refill',
'cash-stacker-1r-empty',
'cash-stacker-1r-count-change',
'cash-stacker-2f-refill',
'cash-stacker-2f-empty',
'cash-stacker-2f-count-change',
'cash-stacker-2r-refill',
'cash-stacker-2r-empty',
'cash-stacker-2r-count-change',
'cash-stacker-3f-refill',
'cash-stacker-3f-empty',
'cash-stacker-3f-count-change',
'cash-stacker-3r-refill',
'cash-stacker-3r-empty',
'cash-stacker-3r-count-change'
)`,
`ALTER TABLE cashbox_batches ALTER COLUMN operation_type TYPE cash_unit_operation_type USING operation_type::text::cash_unit_operation_type`,
`ALTER TABLE cashbox_batches RENAME TO cash_unit_operation`,
`DROP TYPE cashbox_batch_type`,
`CREATE TABLE empty_unit_bills (
id UUID PRIMARY KEY,
fiat INTEGER NOT NULL,
fiat_code TEXT NOT NULL,
created TIMESTAMPTZ NOT NULL DEFAULT now(),
device_id TEXT REFERENCES devices (device_id),
cashbox_batch_id UUID REFERENCES cash_unit_operation (id)
)`
]
db.multi(sql, next)