Add quote and order stores plus ledger hash_version.
Mirror delivery on manifest for quote/order with customer entityId (excluding Lieferanten/POS), and support entity.list role=customer for pickers.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
export const SUPPLIER_GROUP_NAME = 'Lieferanten';
|
||||
export const POS_GROUP_NAME = 'POS';
|
||||
|
||||
export const ENTITY_COLUMNS = `
|
||||
e.id,
|
||||
@@ -28,6 +29,17 @@ WHERE cg.company_id = @companyId
|
||||
ORDER BY e.name, e.id
|
||||
`;
|
||||
|
||||
/** Entities whose group is not Lieferanten and not POS (customer picker). */
|
||||
export const LIST_CUSTOMERS_BY_COMPANY = `
|
||||
SELECT
|
||||
${ENTITY_COLUMNS}
|
||||
FROM entity e
|
||||
INNER JOIN customergroup cg ON cg.id = e.customergroup_id
|
||||
WHERE cg.company_id = @companyId
|
||||
AND cg.name NOT IN (@supplierGroupName, @posGroupName)
|
||||
ORDER BY e.name, e.id
|
||||
`;
|
||||
|
||||
export const GET_BY_COMPANY_AND_ID = `
|
||||
SELECT
|
||||
${ENTITY_COLUMNS}
|
||||
@@ -37,6 +49,17 @@ WHERE e.id = @id
|
||||
AND cg.company_id = @companyId
|
||||
`;
|
||||
|
||||
/** Customer entity: company-scoped and not Lieferanten/POS. */
|
||||
export const GET_CUSTOMER_BY_ID = `
|
||||
SELECT
|
||||
${ENTITY_COLUMNS}
|
||||
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 NOT IN (@supplierGroupName, @posGroupName)
|
||||
`;
|
||||
|
||||
export const LIST_SUPPLIERS_BY_COMPANY = `
|
||||
SELECT
|
||||
e.id,
|
||||
|
||||
125
src/sql/manifestDoc.js
Normal file
125
src/sql/manifestDoc.js
Normal file
@@ -0,0 +1,125 @@
|
||||
/**
|
||||
* Shared SQL for typed manifest documents (quote / order).
|
||||
* Delivery keeps its own SQL with supplierId naming.
|
||||
*/
|
||||
|
||||
export const QUOTE_TYPE = 'quote';
|
||||
export const ORDER_TYPE = 'order';
|
||||
|
||||
export const LIST_MANIFESTS = `
|
||||
SELECT
|
||||
m.id,
|
||||
m.[number],
|
||||
m.[type],
|
||||
m.entity_id AS entityId,
|
||||
m.[date]
|
||||
FROM manifest m
|
||||
WHERE m.company_id = @companyId
|
||||
AND m.[type] = @type
|
||||
ORDER BY m.[date] DESC, m.id DESC
|
||||
`;
|
||||
|
||||
export const GET_MANIFEST_HEADER = `
|
||||
SELECT
|
||||
m.id,
|
||||
m.[number],
|
||||
m.[type],
|
||||
m.entity_id AS entityId,
|
||||
m.[date]
|
||||
FROM manifest m
|
||||
WHERE m.id = @id
|
||||
AND m.company_id = @companyId
|
||||
AND m.[type] = @type
|
||||
`;
|
||||
|
||||
export const GET_MANIFEST_LINES = `
|
||||
SELECT
|
||||
ma.id,
|
||||
ma.article_id AS articleId,
|
||||
a.sku,
|
||||
ma.amount,
|
||||
ma.net,
|
||||
ma.rebate,
|
||||
t.rate AS tax,
|
||||
ma.comment
|
||||
FROM manifestarticle ma
|
||||
LEFT JOIN article a ON a.id = ma.article_id
|
||||
INNER JOIN tax t ON t.id = ma.tax_id
|
||||
WHERE ma.manifest_id = @manifestId
|
||||
ORDER BY ma.id
|
||||
`;
|
||||
|
||||
export const CREATE_MANIFEST = `
|
||||
INSERT INTO manifest (company_id, [number], [type], entity_id, [date])
|
||||
OUTPUT INSERTED.id
|
||||
VALUES (@companyId, @number, @type, @entityId, @date)
|
||||
`;
|
||||
|
||||
export const UPDATE_MANIFEST = `
|
||||
UPDATE manifest
|
||||
SET
|
||||
[number] = @number,
|
||||
entity_id = @entityId,
|
||||
[date] = @date
|
||||
WHERE id = @id
|
||||
AND company_id = @companyId
|
||||
AND [type] = @type
|
||||
`;
|
||||
|
||||
export const DELETE_MANIFEST = `
|
||||
DELETE FROM manifest
|
||||
WHERE id = @id
|
||||
AND company_id = @companyId
|
||||
AND [type] = @type
|
||||
`;
|
||||
|
||||
export const DELETE_LINES_BY_MANIFEST = `
|
||||
DELETE FROM manifestarticle
|
||||
WHERE manifest_id = @manifestId
|
||||
`;
|
||||
|
||||
export const CREATE_LINE = `
|
||||
INSERT INTO manifestarticle (
|
||||
manifest_id,
|
||||
article_id,
|
||||
amount,
|
||||
net,
|
||||
comment,
|
||||
rebate,
|
||||
tax_id
|
||||
)
|
||||
OUTPUT INSERTED.id
|
||||
VALUES (
|
||||
@manifestId,
|
||||
@articleId,
|
||||
@amount,
|
||||
@net,
|
||||
@comment,
|
||||
@rebate,
|
||||
@taxId
|
||||
)
|
||||
`;
|
||||
|
||||
/** Resolve SKU to article id if reachable via the company category tree. */
|
||||
export const RESOLVE_ARTICLE_ID_BY_SKU = `
|
||||
;WITH category_tree AS (
|
||||
SELECT id
|
||||
FROM category
|
||||
WHERE id = @rootCategoryId
|
||||
|
||||
UNION ALL
|
||||
|
||||
SELECT c.id
|
||||
FROM category c
|
||||
INNER JOIN category_tree ct ON c.parent_id = ct.id
|
||||
)
|
||||
SELECT TOP 1 a.id
|
||||
FROM article a
|
||||
WHERE a.sku = @sku
|
||||
AND EXISTS (
|
||||
SELECT 1
|
||||
FROM categoryarticle ca
|
||||
INNER JOIN category_tree ct ON ct.id = ca.category_id
|
||||
WHERE ca.article_id = a.id
|
||||
)
|
||||
`;
|
||||
Reference in New Issue
Block a user