This commit is contained in:
seb
2026-10-21 06:13:29 +02:00
parent b0014d6629
commit e085bcaeba
7 changed files with 301 additions and 1 deletions

View File

@@ -189,10 +189,11 @@ 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 NOT IN ('Lieferanten', 'POS')
WHERE cg.name <> 'Lieferanten'
AND DATEDIFF_BIG(second, '1970-01-01', e.updated_at) > @cursor
`;
export const COUNT_CUSTOMER_GROUPS = `
SELECT COUNT(*) AS count
FROM customergroup cg
@@ -387,6 +388,80 @@ WHERE pc.posterminal_id = @posterminalId
ORDER BY ca.article_id ASC, ca.category_id ASC
`;
export const LIST_POS_CUSTOMER_GROUPS = `
SELECT TOP (@limit)
cg.id,
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
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
`;
export const LIST_POS_CUSTOMERS = `
SELECT TOP (@limit)
e.id,
e.customergroup_id AS customergroupId,
e.first_name AS firstName,
e.name AS lastName,
e.[number] AS customerNumber,
(
SELECT TOP 1 ea.street
FROM entityaddress ea
WHERE ea.entity_id = e.id
ORDER BY CASE WHEN ea.addresstype = 'billing' THEN 0 ELSE 1 END, ea.sort ASC, ea.id ASC
) AS street,
(
SELECT TOP 1 ea.streetnumber
FROM entityaddress ea
WHERE ea.entity_id = e.id
ORDER BY CASE WHEN ea.addresstype = 'billing' THEN 0 ELSE 1 END, ea.sort ASC, ea.id ASC
) AS streetNumber,
(
SELECT TOP 1 ea.city
FROM entityaddress ea
WHERE ea.entity_id = e.id
ORDER BY CASE WHEN ea.addresstype = 'billing' THEN 0 ELSE 1 END, ea.sort ASC, ea.id ASC
) AS city,
(
SELECT TOP 1 ea.zip
FROM entityaddress ea
WHERE ea.entity_id = e.id
ORDER BY CASE WHEN ea.addresstype = 'billing' THEN 0 ELSE 1 END, ea.sort ASC, ea.id ASC
) AS postalCode,
(
SELECT TOP 1 ea.county
FROM entityaddress ea
WHERE ea.entity_id = e.id
ORDER BY CASE WHEN ea.addresstype = 'billing' THEN 0 ELSE 1 END, ea.sort ASC, ea.id ASC
) AS [state],
(
SELECT TOP 1 ec.contact
FROM entitycontact ec
WHERE ec.entity_id = e.id AND ec.contacttype IN ('phone', 'mobile', 'tel')
ORDER BY ec.sort ASC, ec.id ASC
) AS phone,
(
SELECT TOP 1 ec.contact
FROM entitycontact ec
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
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
`;
export const LIST_POS_CUSTOMER_GROUP_IDS = `
SELECT cg.id
FROM customergroup cg
@@ -395,6 +470,7 @@ WHERE cg.name <> 'Lieferanten'
ORDER BY cg.id ASC
`;
export const LIST_POS_PRODUCT_PRICES = `
SELECT
pr.article_id AS articleId,