feat(schema): replace manifestarticle article_id FK with sku, rename articlesupplier sku/stock fields
This commit is contained in:
@@ -31,9 +31,7 @@ WHERE m.id = @id
|
||||
export const GET_DELIVERY_LINES = `
|
||||
SELECT
|
||||
ma.id,
|
||||
ma.article_id AS articleId,
|
||||
a.sku,
|
||||
ma.customsku,
|
||||
ma.sku,
|
||||
ma.customname,
|
||||
ma.amount,
|
||||
ma.net,
|
||||
@@ -41,7 +39,6 @@ SELECT
|
||||
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
|
||||
@@ -80,8 +77,7 @@ WHERE manifest_id = @manifestId
|
||||
export const CREATE_LINE = `
|
||||
INSERT INTO manifestarticle (
|
||||
manifest_id,
|
||||
article_id,
|
||||
customsku,
|
||||
sku,
|
||||
customname,
|
||||
amount,
|
||||
net,
|
||||
@@ -92,8 +88,7 @@ INSERT INTO manifestarticle (
|
||||
OUTPUT INSERTED.id
|
||||
VALUES (
|
||||
@manifestId,
|
||||
@articleId,
|
||||
@customsku,
|
||||
@sku,
|
||||
@customname,
|
||||
@amount,
|
||||
@net,
|
||||
@@ -102,27 +97,3 @@ VALUES (
|
||||
@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