Add supplier CRUD on entity with Lieferanten group and entityhistory

This commit is contained in:
seb
2026-08-06 03:56:32 +02:00
parent 561ba5bb99
commit 4f46967f28
17 changed files with 1853 additions and 1338 deletions

View File

@@ -15,3 +15,9 @@ UPDATE customergroup
SET company_id = @companyId
WHERE id = @id
`;
export const GET_BY_COMPANY_AND_NAME = `
SELECT id
FROM customergroup
WHERE company_id = @companyId AND name = @name
`;

59
src/sql/entity.js Normal file
View File

@@ -0,0 +1,59 @@
export const SUPPLIER_GROUP_NAME = 'Lieferanten';
export const LIST_SUPPLIERS_BY_COMPANY = `
SELECT
e.id,
e.name,
e.created_at AS createdAt,
e.updated_at AS updatedAt
FROM entity e
INNER JOIN customergroup cg ON cg.id = e.customergroup_id
WHERE cg.company_id = @companyId
AND cg.name = @groupName
ORDER BY e.name, e.id
`;
export const GET_SUPPLIER_BY_ID = `
SELECT
e.id,
e.name,
e.created_at AS createdAt,
e.updated_at AS updatedAt
FROM entity e
INNER JOIN customergroup cg ON cg.id = e.customergroup_id
WHERE e.id = @id
AND cg.company_id = @companyId
AND cg.name = @groupName
`;
export const CREATE = `
INSERT INTO entity (customergroup_id, name)
OUTPUT INSERTED.id, INSERTED.name, INSERTED.created_at AS createdAt, INSERTED.updated_at AS updatedAt
VALUES (@customergroupId, @name)
`;
export const UPDATE_NAME = `
UPDATE entity
SET name = @name, updated_at = SYSUTCDATETIME()
OUTPUT INSERTED.id, INSERTED.name, INSERTED.created_at AS createdAt, INSERTED.updated_at AS updatedAt
WHERE id = @id
AND customergroup_id = @customergroupId
`;
export const DELETE_BY_ID = `
DELETE e
FROM entity e
INNER JOIN customergroup cg ON cg.id = e.customergroup_id
WHERE e.id = @id
AND cg.company_id = @companyId
AND cg.name = @groupName
`;
export const GET_GROUP_ID_FOR_SUPPLIER = `
SELECT e.customergroup_id AS customergroupId, e.name
FROM entity e
INNER JOIN customergroup cg ON cg.id = e.customergroup_id
WHERE e.id = @id
AND cg.company_id = @companyId
AND cg.name = @groupName
`;

11
src/sql/entityhistory.js Normal file
View File

@@ -0,0 +1,11 @@
export const INSERT = `
INSERT INTO entityhistory (entity_id, companyuser_id, [text])
VALUES (@entityId, @companyuserId, @text)
`;
export const LIST_BY_ENTITY_ID = `
SELECT id, companyuser_id AS companyuserId, [date], [text]
FROM entityhistory
WHERE entity_id = @entityId
ORDER BY [date] DESC, id DESC
`;

View File

@@ -19,6 +19,7 @@ export const TABLES = [
'articlepic',
'articleean',
'articlehistory',
'entityhistory',
'article',
'brand',
'articlelist',