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

@@ -29,6 +29,88 @@ SELECT @posterminalId, id FROM cats WHERE 1
ON CONFLICT (posterminal_id, category_id) DO NOTHING
`;
export const LIST_POS_CUSTOMER_GROUPS = `
SELECT
cg.id,
cg.name,
CASE WHEN cg.id = co.poscustomergroup_id THEN '1' ELSE '0' END AS standard,
'0.000000' AS discountPercent,
CAST(strftime('%s', cg.updated_at) AS INTEGER) 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 CAST(strftime('%s', cg.updated_at) AS INTEGER) > @cursor
ORDER BY lastChanged ASC, cg.id ASC
LIMIT @limit
`;
export const LIST_POS_CUSTOMERS = `
SELECT
e.id,
e.customergroup_id AS customergroupId,
e.first_name AS firstName,
e.name AS lastName,
e."number" AS customerNumber,
(
SELECT 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
LIMIT 1
) AS street,
(
SELECT 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
LIMIT 1
) AS streetNumber,
(
SELECT 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
LIMIT 1
) AS city,
(
SELECT 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
LIMIT 1
) AS postalCode,
(
SELECT 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
LIMIT 1
) AS "state",
(
SELECT 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
LIMIT 1
) AS phone,
(
SELECT 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
LIMIT 1
) AS email,
CAST(strftime('%s', e.updated_at) AS INTEGER) 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 CAST(strftime('%s', e.updated_at) AS INTEGER) > @cursor
ORDER BY lastChanged ASC, e.id ASC
LIMIT @limit
`;
export const LIST_POS_CATEGORIES = `
SELECT
c.id,