x
This commit is contained in:
@@ -172,66 +172,100 @@ WHERE token = @token
|
||||
`;
|
||||
|
||||
export const COUNT_PRODUCTS = `
|
||||
SELECT COUNT(DISTINCT a.id) AS count
|
||||
FROM article a
|
||||
INNER JOIN posterminal pt ON pt.id = @posterminalId AND pt.company_id = a.company_id
|
||||
WHERE EXISTS (
|
||||
SELECT 1
|
||||
FROM categoryarticle ca
|
||||
INNER JOIN posterminalcategory pc ON pc.category_id = ca.category_id
|
||||
WHERE ca.article_id = a.id
|
||||
AND pc.posterminal_id = @posterminalId
|
||||
)
|
||||
AND (DATEDIFF_BIG(second, '1970-01-01', a.updated_at) * 1000000 + (a.id % 1000000)) > @cursor
|
||||
SELECT COUNT(*) AS count
|
||||
FROM (
|
||||
SELECT MAX(q.id) AS syncId, a.id
|
||||
FROM posterminalsyncqueue q
|
||||
INNER JOIN article a ON a.id = q.entity_id
|
||||
INNER JOIN posterminal pt ON pt.id = q.posterminal_id AND pt.company_id = a.company_id
|
||||
WHERE q.posterminal_id = @posterminalId
|
||||
AND q.entity_type = 'article'
|
||||
AND EXISTS (
|
||||
SELECT 1
|
||||
FROM categoryarticle ca
|
||||
INNER JOIN posterminalcategory pc ON pc.category_id = ca.category_id
|
||||
WHERE ca.article_id = a.id
|
||||
AND pc.posterminal_id = @posterminalId
|
||||
)
|
||||
GROUP BY a.id
|
||||
HAVING MAX(q.id) > @cursor
|
||||
) t
|
||||
`;
|
||||
|
||||
export const COUNT_CATEGORIES = `
|
||||
SELECT COUNT(*) AS count
|
||||
FROM category c
|
||||
INNER JOIN posterminalcategory pc ON pc.category_id = c.id
|
||||
INNER JOIN posterminal pt ON pt.id = pc.posterminal_id
|
||||
INNER JOIN company co ON co.id = pt.company_id
|
||||
WHERE pc.posterminal_id = @posterminalId
|
||||
AND (co.root_category_id IS NULL OR c.id <> co.root_category_id)
|
||||
AND DATEDIFF_BIG(second, '1970-01-01', c.updated_at) > @cursor
|
||||
FROM (
|
||||
SELECT MAX(q.id) AS syncId, c.id
|
||||
FROM posterminalsyncqueue q
|
||||
INNER JOIN category c ON c.id = q.entity_id
|
||||
INNER JOIN posterminalcategory pc ON pc.category_id = c.id AND pc.posterminal_id = q.posterminal_id
|
||||
INNER JOIN posterminal pt ON pt.id = pc.posterminal_id
|
||||
INNER JOIN company co ON co.id = pt.company_id
|
||||
WHERE q.posterminal_id = @posterminalId
|
||||
AND q.entity_type = 'category'
|
||||
AND (co.root_category_id IS NULL OR c.id <> co.root_category_id)
|
||||
GROUP BY c.id
|
||||
HAVING MAX(q.id) > @cursor
|
||||
) t
|
||||
`;
|
||||
|
||||
export const COUNT_CUSTOMERS = `
|
||||
SELECT COUNT(*) AS count
|
||||
FROM entity e
|
||||
INNER JOIN customergroup cg ON cg.id = e.customergroup_id
|
||||
INNER JOIN posterminal pt ON pt.id = @posterminalId AND pt.company_id = cg.company_id
|
||||
WHERE cg.name <> 'Lieferanten'
|
||||
AND DATEDIFF_BIG(second, '1970-01-01', e.updated_at) > @cursor
|
||||
FROM (
|
||||
SELECT MAX(q.id) AS syncId, e.id
|
||||
FROM posterminalsyncqueue q
|
||||
INNER JOIN entity e ON e.id = q.entity_id
|
||||
INNER JOIN customergroup cg ON cg.id = e.customergroup_id
|
||||
INNER JOIN posterminal pt ON pt.id = q.posterminal_id AND pt.company_id = cg.company_id
|
||||
WHERE q.posterminal_id = @posterminalId
|
||||
AND q.entity_type = 'customer'
|
||||
AND cg.name <> 'Lieferanten'
|
||||
GROUP BY e.id
|
||||
HAVING MAX(q.id) > @cursor
|
||||
) t
|
||||
`;
|
||||
|
||||
|
||||
export const COUNT_CUSTOMER_GROUPS = `
|
||||
SELECT COUNT(*) AS count
|
||||
FROM customergroup cg
|
||||
INNER JOIN posterminal pt ON pt.id = @posterminalId AND pt.company_id = cg.company_id
|
||||
WHERE cg.name <> 'Lieferanten'
|
||||
AND DATEDIFF_BIG(second, '1970-01-01', cg.updated_at) > @cursor
|
||||
FROM (
|
||||
SELECT MAX(q.id) AS syncId, cg.id
|
||||
FROM posterminalsyncqueue q
|
||||
INNER JOIN customergroup cg ON cg.id = q.entity_id
|
||||
INNER JOIN posterminal pt ON pt.id = q.posterminal_id AND pt.company_id = cg.company_id
|
||||
WHERE q.posterminal_id = @posterminalId
|
||||
AND q.entity_type = 'customergroup'
|
||||
AND cg.name <> 'Lieferanten'
|
||||
GROUP BY cg.id
|
||||
HAVING MAX(q.id) > @cursor
|
||||
) t
|
||||
`;
|
||||
|
||||
export const COUNT_COMPOSITE_PRODUCTS = `
|
||||
SELECT COUNT(DISTINCT a.id) AS count
|
||||
FROM article a
|
||||
INNER JOIN posterminal pt ON pt.id = @posterminalId AND pt.company_id = a.company_id
|
||||
WHERE a.articlelist_id IS NOT NULL
|
||||
AND EXISTS (
|
||||
SELECT 1
|
||||
FROM articlelistarticle ala
|
||||
WHERE ala.articlelist_id = a.articlelist_id
|
||||
)
|
||||
AND EXISTS (
|
||||
SELECT 1
|
||||
FROM categoryarticle ca
|
||||
INNER JOIN posterminalcategory pc ON pc.category_id = ca.category_id
|
||||
WHERE ca.article_id = a.id
|
||||
AND pc.posterminal_id = @posterminalId
|
||||
)
|
||||
AND (DATEDIFF_BIG(second, '1970-01-01', a.updated_at) * 1000000 + (a.id % 1000000)) > @cursor
|
||||
SELECT COUNT(*) AS count
|
||||
FROM (
|
||||
SELECT MAX(q.id) AS syncId, a.id
|
||||
FROM posterminalsyncqueue q
|
||||
INNER JOIN article a ON a.id = q.entity_id
|
||||
INNER JOIN posterminal pt ON pt.id = q.posterminal_id AND pt.company_id = a.company_id
|
||||
WHERE q.posterminal_id = @posterminalId
|
||||
AND q.entity_type = 'article'
|
||||
AND a.articlelist_id IS NOT NULL
|
||||
AND EXISTS (
|
||||
SELECT 1
|
||||
FROM articlelistarticle ala
|
||||
WHERE ala.articlelist_id = a.articlelist_id
|
||||
)
|
||||
AND EXISTS (
|
||||
SELECT 1
|
||||
FROM categoryarticle ca
|
||||
INNER JOIN posterminalcategory pc ON pc.category_id = ca.category_id
|
||||
WHERE ca.article_id = a.id
|
||||
AND pc.posterminal_id = @posterminalId
|
||||
)
|
||||
GROUP BY a.id
|
||||
HAVING MAX(q.id) > @cursor
|
||||
) t
|
||||
`;
|
||||
|
||||
export const MAX_ORDER_ID = `
|
||||
@@ -255,16 +289,21 @@ SELECT TOP (@limit)
|
||||
WHERE cp.category_id = c.id
|
||||
ORDER BY cp.sort ASC, cp.id ASC
|
||||
) AS imgHash,
|
||||
DATEDIFF_BIG(second, '1970-01-01', c.updated_at) AS lastChanged
|
||||
FROM category c
|
||||
INNER JOIN posterminalcategory pc ON pc.category_id = c.id
|
||||
sq.syncId AS lastChanged
|
||||
FROM (
|
||||
SELECT entity_id, MAX(id) AS syncId
|
||||
FROM posterminalsyncqueue
|
||||
WHERE posterminal_id = @posterminalId AND entity_type = 'category'
|
||||
GROUP BY entity_id
|
||||
HAVING MAX(id) > @cursor
|
||||
) sq
|
||||
INNER JOIN category c ON c.id = sq.entity_id
|
||||
INNER JOIN posterminalcategory pc ON pc.category_id = c.id AND pc.posterminal_id = @posterminalId
|
||||
INNER JOIN posterminal pt ON pt.id = pc.posterminal_id
|
||||
INNER JOIN company co ON co.id = pt.company_id
|
||||
LEFT JOIN categorytext ct ON ct.category_id = c.id AND ct.language_id = co.default_language_id
|
||||
WHERE pc.posterminal_id = @posterminalId
|
||||
AND (co.root_category_id IS NULL OR c.id <> co.root_category_id)
|
||||
AND DATEDIFF_BIG(second, '1970-01-01', c.updated_at) > @cursor
|
||||
ORDER BY DATEDIFF_BIG(second, '1970-01-01', c.updated_at) ASC, c.id ASC
|
||||
WHERE (co.root_category_id IS NULL OR c.id <> co.root_category_id)
|
||||
ORDER BY sq.syncId ASC
|
||||
`;
|
||||
|
||||
export const LIST_POS_PRODUCTS = `
|
||||
@@ -275,7 +314,7 @@ SELECT TOP (@limit)
|
||||
COALESCE(pr.net, 0) AS netPrice,
|
||||
COALESCE(ptax.rate, ctax.rate, 0) AS taxRate,
|
||||
a.created_at AS createdAt,
|
||||
(DATEDIFF_BIG(second, '1970-01-01', a.updated_at) * 1000000 + (a.id % 1000000)) AS lastChanged,
|
||||
sq.syncId AS lastChanged,
|
||||
COALESCE(
|
||||
(
|
||||
SELECT TOP 1 p.hash
|
||||
@@ -374,7 +413,14 @@ SELECT TOP (@limit)
|
||||
co.id AS companyId,
|
||||
co.root_category_id AS rootCategoryId,
|
||||
co.poscustomergroup_id AS posCustomerGroupId
|
||||
FROM article a
|
||||
FROM (
|
||||
SELECT entity_id, MAX(id) AS syncId
|
||||
FROM posterminalsyncqueue
|
||||
WHERE posterminal_id = @posterminalId AND entity_type = 'article'
|
||||
GROUP BY entity_id
|
||||
HAVING MAX(id) > @cursor
|
||||
) sq
|
||||
INNER JOIN article a ON a.id = sq.entity_id
|
||||
INNER JOIN posterminal pt ON pt.id = @posterminalId AND pt.company_id = a.company_id
|
||||
INNER JOIN company co ON co.id = a.company_id
|
||||
LEFT JOIN articletext at ON at.article_id = a.id AND at.language_id = co.default_language_id
|
||||
@@ -388,8 +434,7 @@ WHERE EXISTS (
|
||||
WHERE ca.article_id = a.id
|
||||
AND pc.posterminal_id = @posterminalId
|
||||
)
|
||||
AND (DATEDIFF_BIG(second, '1970-01-01', a.updated_at) * 1000000 + (a.id % 1000000)) > @cursor
|
||||
ORDER BY (DATEDIFF_BIG(second, '1970-01-01', a.updated_at) * 1000000 + (a.id % 1000000)) ASC
|
||||
ORDER BY sq.syncId ASC
|
||||
`;
|
||||
|
||||
export const LIST_POS_PRODUCT_CATEGORIES = `
|
||||
@@ -411,13 +456,19 @@ SELECT TOP (@limit)
|
||||
cg.name,
|
||||
CASE WHEN cg.id = co.poscustomergroup_id THEN '1' ELSE '0' END AS standard,
|
||||
'0.000000' AS discountPercent,
|
||||
DATEDIFF_BIG(second, '1970-01-01', cg.updated_at) AS lastChanged
|
||||
FROM customergroup cg
|
||||
sq.syncId AS lastChanged
|
||||
FROM (
|
||||
SELECT entity_id, MAX(id) AS syncId
|
||||
FROM posterminalsyncqueue
|
||||
WHERE posterminal_id = @posterminalId AND entity_type = 'customergroup'
|
||||
GROUP BY entity_id
|
||||
HAVING MAX(id) > @cursor
|
||||
) sq
|
||||
INNER JOIN customergroup cg ON cg.id = sq.entity_id
|
||||
INNER JOIN posterminal pt ON pt.id = @posterminalId AND pt.company_id = cg.company_id
|
||||
INNER JOIN company co ON co.id = pt.company_id
|
||||
WHERE cg.name <> 'Lieferanten'
|
||||
AND DATEDIFF_BIG(second, '1970-01-01', cg.updated_at) > @cursor
|
||||
ORDER BY DATEDIFF_BIG(second, '1970-01-01', cg.updated_at) ASC, cg.id ASC
|
||||
ORDER BY sq.syncId ASC
|
||||
`;
|
||||
|
||||
export const LIST_POS_CUSTOMERS = `
|
||||
@@ -469,13 +520,19 @@ SELECT TOP (@limit)
|
||||
WHERE ec.entity_id = e.id AND ec.contacttype IN ('email', 'mail')
|
||||
ORDER BY ec.sort ASC, ec.id ASC
|
||||
) AS email,
|
||||
DATEDIFF_BIG(second, '1970-01-01', e.updated_at) AS lastChanged
|
||||
FROM entity e
|
||||
sq.syncId AS lastChanged
|
||||
FROM (
|
||||
SELECT entity_id, MAX(id) AS syncId
|
||||
FROM posterminalsyncqueue
|
||||
WHERE posterminal_id = @posterminalId AND entity_type = 'customer'
|
||||
GROUP BY entity_id
|
||||
HAVING MAX(id) > @cursor
|
||||
) sq
|
||||
INNER JOIN entity e ON e.id = sq.entity_id
|
||||
INNER JOIN customergroup cg ON cg.id = e.customergroup_id
|
||||
INNER JOIN posterminal pt ON pt.id = @posterminalId AND pt.company_id = cg.company_id
|
||||
WHERE cg.name <> 'Lieferanten'
|
||||
AND DATEDIFF_BIG(second, '1970-01-01', e.updated_at) > @cursor
|
||||
ORDER BY DATEDIFF_BIG(second, '1970-01-01', e.updated_at) ASC, e.id ASC
|
||||
ORDER BY sq.syncId ASC
|
||||
`;
|
||||
|
||||
|
||||
@@ -541,6 +598,34 @@ FROM posterminal pt
|
||||
WHERE pt.company_id = @companyId AND pt.token IS NOT NULL
|
||||
`;
|
||||
|
||||
export const RECORD_SYNC_QUEUE = `
|
||||
INSERT INTO posterminalsyncqueue (posterminal_id, entity_type, entity_id)
|
||||
SELECT pt.id, @entityType, @entityId
|
||||
FROM posterminal pt
|
||||
WHERE pt.company_id = @companyId
|
||||
`;
|
||||
|
||||
export const SEED_SYNC_QUEUE_FOR_TERMINAL = `
|
||||
INSERT INTO posterminalsyncqueue (posterminal_id, entity_type, entity_id)
|
||||
SELECT @posterminalId, 'customergroup', cg.id
|
||||
FROM customergroup cg
|
||||
WHERE cg.company_id = @companyId
|
||||
UNION ALL
|
||||
SELECT @posterminalId, 'customer', e.id
|
||||
FROM entity e
|
||||
INNER JOIN customergroup cg ON cg.id = e.customergroup_id
|
||||
WHERE cg.company_id = @companyId
|
||||
UNION ALL
|
||||
SELECT @posterminalId, 'category', c.id
|
||||
FROM category c
|
||||
INNER JOIN posterminalcategory pc ON pc.category_id = c.id
|
||||
WHERE pc.posterminal_id = @posterminalId
|
||||
UNION ALL
|
||||
SELECT @posterminalId, 'article', a.id
|
||||
FROM article a
|
||||
WHERE a.company_id = @companyId
|
||||
`;
|
||||
|
||||
export const COUNT_DELETED_ENTITIES = `
|
||||
SELECT COUNT(*) AS count
|
||||
FROM posterminalobituary
|
||||
|
||||
Reference in New Issue
Block a user