u
This commit is contained in:
@@ -17,29 +17,6 @@ WHERE id = @articleId
|
||||
`;
|
||||
|
||||
|
||||
export const CREATE_TOMBSTONE = `
|
||||
INSERT INTO articletombstone (company_id, article_id, sku, name, taxrate, net)
|
||||
SELECT
|
||||
a.company_id,
|
||||
a.id AS article_id,
|
||||
a.sku,
|
||||
COALESCE(
|
||||
(SELECT TOP 1 at.name FROM articletext at WHERE at.article_id = a.id AND at.language_id = co.default_language_id),
|
||||
(SELECT TOP 1 at.name FROM articletext at WHERE at.article_id = a.id ORDER BY at.id ASC)
|
||||
) AS name,
|
||||
COALESCE(
|
||||
(SELECT TOP 1 t.rate FROM price pr INNER JOIN tax t ON t.id = pr.tax_id WHERE pr.article_id = a.id AND pr.customergroup_id = co.poscustomergroup_id AND pr.minmultiplier = 1),
|
||||
(SELECT TOP 1 t.rate FROM price pr INNER JOIN tax t ON t.id = pr.tax_id WHERE pr.article_id = a.id ORDER BY pr.id ASC)
|
||||
) AS taxrate,
|
||||
COALESCE(
|
||||
(SELECT TOP 1 pr.net FROM price pr WHERE pr.article_id = a.id AND pr.customergroup_id = co.poscustomergroup_id AND pr.minmultiplier = 1),
|
||||
(SELECT TOP 1 pr.net FROM price pr WHERE pr.article_id = a.id ORDER BY pr.id ASC)
|
||||
) AS net
|
||||
FROM article a
|
||||
INNER JOIN company co ON co.id = a.company_id
|
||||
WHERE a.id = @articleId
|
||||
`;
|
||||
|
||||
export const DELETE_PICS_BY_ARTICLE = `
|
||||
DELETE p
|
||||
FROM pic p
|
||||
|
||||
@@ -482,3 +482,27 @@ INNER JOIN posterminal pt ON pt.id = @posterminalId AND pt.company_id = a.compan
|
||||
WHERE pr.minmultiplier = 1
|
||||
GROUP BY pr.article_id, pr.customergroup_id
|
||||
`;
|
||||
|
||||
export const RECORD_TOMBSTONE = `
|
||||
INSERT INTO posterminaltombstone (posterminal_id, entity_type, entity_id)
|
||||
SELECT pt.id, @entityType, @entityId
|
||||
FROM posterminal pt
|
||||
WHERE pt.company_id = @companyId AND pt.token IS NOT NULL
|
||||
`;
|
||||
|
||||
export const COUNT_DELETED_ENTITIES = `
|
||||
SELECT COUNT(*) AS count
|
||||
FROM posterminaltombstone
|
||||
WHERE posterminal_id = @posterminalId AND id > @cursor
|
||||
`;
|
||||
|
||||
export const LIST_DELETED_ENTITIES = `
|
||||
SELECT TOP (@limit)
|
||||
id,
|
||||
entity_type AS entityType,
|
||||
entity_id AS entityId
|
||||
FROM posterminaltombstone
|
||||
WHERE posterminal_id = @posterminalId AND id > @cursor
|
||||
ORDER BY id ASC
|
||||
`;
|
||||
|
||||
|
||||
@@ -392,27 +392,24 @@ BEGIN
|
||||
END
|
||||
`;
|
||||
|
||||
export const INIT_ARTICLETOMBSTONE = `
|
||||
IF NOT EXISTS (SELECT * FROM sys.tables WHERE name = 'articletombstone')
|
||||
export const INIT_POSTERMINALTOMBSTONE = `
|
||||
IF NOT EXISTS (SELECT * FROM sys.tables WHERE name = 'posterminaltombstone')
|
||||
BEGIN
|
||||
CREATE TABLE articletombstone (
|
||||
CREATE TABLE posterminaltombstone (
|
||||
id INT IDENTITY(1,1) PRIMARY KEY,
|
||||
company_id INT NOT NULL,
|
||||
article_id INT NULL,
|
||||
sku NVARCHAR(100) NULL,
|
||||
name NVARCHAR(255) NULL,
|
||||
taxrate DECIMAL(18,4) NULL,
|
||||
net FLOAT NULL,
|
||||
deleted_at DATETIME2 NOT NULL CONSTRAINT DF_articletombstone_deleted_at DEFAULT SYSUTCDATETIME(),
|
||||
CONSTRAINT CK_articletombstone_article_or_sku CHECK (article_id IS NOT NULL OR sku IS NOT NULL),
|
||||
CONSTRAINT FK_articletombstone_company FOREIGN KEY (company_id) REFERENCES company(id) ON DELETE CASCADE
|
||||
posterminal_id INT NOT NULL,
|
||||
entity_type NVARCHAR(50) NOT NULL,
|
||||
entity_id INT NOT NULL,
|
||||
created_at DATETIME2 NOT NULL CONSTRAINT DF_posterminaltombstone_created_at DEFAULT SYSUTCDATETIME(),
|
||||
CONSTRAINT FK_posterminaltombstone_posterminal FOREIGN KEY (posterminal_id) REFERENCES posterminal(id) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
CREATE INDEX IX_articletombstone_company_deleted
|
||||
ON articletombstone (company_id, deleted_at);
|
||||
CREATE INDEX IX_posterminaltombstone_posterminal_id
|
||||
ON posterminaltombstone (posterminal_id, id);
|
||||
END
|
||||
`;
|
||||
|
||||
|
||||
export const INIT_ARTICLEEAN = `
|
||||
IF NOT EXISTS (SELECT * FROM sys.tables WHERE name = 'articleean')
|
||||
BEGIN
|
||||
@@ -1501,12 +1498,12 @@ export const SCHEMA_SCRIPTS = [
|
||||
INIT_MODELMESSAGE,
|
||||
INIT_MODELVFS,
|
||||
INIT_ARTICLEHISTORY,
|
||||
INIT_ARTICLETOMBSTONE,
|
||||
INIT_ENTITYHISTORY,
|
||||
INIT_COMPANYHISTORY,
|
||||
INIT_COMPANYSETTING,
|
||||
INIT_POSTERMINAL,
|
||||
INIT_POSTERMINALCATEGORY,
|
||||
INIT_POSTERMINALTOMBSTONE,
|
||||
INIT_PRINTER,
|
||||
INIT_LABELTEMPLATE,
|
||||
INIT_FILE,
|
||||
|
||||
@@ -7,29 +7,6 @@ export const {
|
||||
GET_CHILDREN_IDS, GET_LIST_IDS,
|
||||
} = queries;
|
||||
|
||||
export const CREATE_TOMBSTONE = `
|
||||
INSERT INTO articletombstone (company_id, article_id, sku, name, taxrate, net)
|
||||
SELECT
|
||||
a.company_id,
|
||||
a.id AS article_id,
|
||||
a.sku,
|
||||
COALESCE(
|
||||
(SELECT at.name FROM articletext at WHERE at.article_id = a.id AND at.language_id = co.default_language_id),
|
||||
(SELECT at.name FROM articletext at WHERE at.article_id = a.id ORDER BY at.id ASC LIMIT 1)
|
||||
) AS name,
|
||||
COALESCE(
|
||||
(SELECT t.rate FROM price pr INNER JOIN tax t ON t.id = pr.tax_id WHERE pr.article_id = a.id AND pr.customergroup_id = co.poscustomergroup_id AND pr.minmultiplier = 1),
|
||||
(SELECT t.rate FROM price pr INNER JOIN tax t ON t.id = pr.tax_id WHERE pr.article_id = a.id ORDER BY pr.id ASC LIMIT 1)
|
||||
) AS taxrate,
|
||||
COALESCE(
|
||||
(SELECT pr.net FROM price pr WHERE pr.article_id = a.id AND pr.customergroup_id = co.poscustomergroup_id AND pr.minmultiplier = 1),
|
||||
(SELECT pr.net FROM price pr WHERE pr.article_id = a.id ORDER BY pr.id ASC LIMIT 1)
|
||||
) AS net
|
||||
FROM article a
|
||||
INNER JOIN company co ON co.id = a.company_id
|
||||
WHERE a.id = @articleId
|
||||
`;
|
||||
|
||||
export const DELETE_PICS_BY_ARTICLE = `
|
||||
DELETE FROM pic
|
||||
WHERE id IN (SELECT pic_id FROM articlepic WHERE article_id = @articleId)
|
||||
|
||||
@@ -9,7 +9,7 @@ export const {
|
||||
FIND_BY_TOKEN, COUNT_PRODUCTS, COUNT_CATEGORIES, COUNT_CUSTOMERS,
|
||||
COUNT_CUSTOMER_GROUPS, COUNT_COMPOSITE_PRODUCTS, MAX_ORDER_ID,
|
||||
LIST_POS_PRODUCT_CATEGORIES, LIST_POS_CUSTOMER_GROUP_IDS, LIST_POS_PRODUCT_PRICES,
|
||||
TOUCH_LASTSEEN,
|
||||
TOUCH_LASTSEEN, RECORD_TOMBSTONE, COUNT_DELETED_ENTITIES,
|
||||
} = queries;
|
||||
|
||||
export const SET_ON = `
|
||||
@@ -263,3 +263,15 @@ AND CAST(strftime('%s', a.updated_at) AS INTEGER) > @cursor
|
||||
ORDER BY lastChanged ASC, a.id ASC
|
||||
LIMIT @limit
|
||||
`;
|
||||
|
||||
export const LIST_DELETED_ENTITIES = `
|
||||
SELECT
|
||||
id,
|
||||
entity_type AS entityType,
|
||||
entity_id AS entityId
|
||||
FROM posterminaltombstone
|
||||
WHERE posterminal_id = @posterminalId AND id > @cursor
|
||||
ORDER BY id ASC
|
||||
LIMIT @limit
|
||||
`;
|
||||
|
||||
|
||||
@@ -573,22 +573,6 @@ CREATE TABLE IF NOT EXISTS companyhistory (
|
||||
);
|
||||
`;
|
||||
|
||||
export const INIT_ARTICLETOMBSTONE = `
|
||||
CREATE TABLE IF NOT EXISTS articletombstone (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
company_id INTEGER NOT NULL,
|
||||
article_id INTEGER,
|
||||
sku TEXT COLLATE NOCASE,
|
||||
name TEXT,
|
||||
taxrate NUMERIC,
|
||||
net REAL,
|
||||
deleted_at TEXT NOT NULL DEFAULT (${UTC_NOW}),
|
||||
CHECK (article_id IS NOT NULL OR sku IS NOT NULL),
|
||||
FOREIGN KEY (company_id) REFERENCES company(id) ON DELETE CASCADE
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS IX_articletombstone_company_deleted
|
||||
ON articletombstone (company_id, deleted_at);
|
||||
`;
|
||||
|
||||
export const INIT_ENTITYHISTORY = `
|
||||
CREATE TABLE IF NOT EXISTS entityhistory (
|
||||
@@ -647,6 +631,19 @@ CREATE TABLE IF NOT EXISTS posterminalcategory (
|
||||
);
|
||||
`;
|
||||
|
||||
export const INIT_POSTERMINALTOMBSTONE = `
|
||||
CREATE TABLE IF NOT EXISTS posterminaltombstone (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
posterminal_id INTEGER NOT NULL,
|
||||
entity_type TEXT NOT NULL,
|
||||
entity_id INTEGER NOT NULL,
|
||||
created_at TEXT NOT NULL DEFAULT (${UTC_NOW}),
|
||||
FOREIGN KEY (posterminal_id) REFERENCES posterminal(id) ON DELETE CASCADE
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS IX_posterminaltombstone_posterminal_id
|
||||
ON posterminaltombstone (posterminal_id, id);
|
||||
`;
|
||||
|
||||
export const INIT_PRINTER = `
|
||||
CREATE TABLE IF NOT EXISTS printer (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
@@ -1117,12 +1114,12 @@ export const SCHEMA_SCRIPTS = [
|
||||
INIT_MODELMESSAGE,
|
||||
INIT_MODELVFS,
|
||||
INIT_ARTICLEHISTORY,
|
||||
INIT_ARTICLETOMBSTONE,
|
||||
INIT_ENTITYHISTORY,
|
||||
INIT_COMPANYHISTORY,
|
||||
INIT_COMPANYSETTING,
|
||||
INIT_POSTERMINAL,
|
||||
INIT_POSTERMINALCATEGORY,
|
||||
INIT_POSTERMINALTOMBSTONE,
|
||||
INIT_PRINTER,
|
||||
INIT_LABELTEMPLATE,
|
||||
INIT_FILE,
|
||||
|
||||
Reference in New Issue
Block a user