123 lines
2.3 KiB
JavaScript
123 lines
2.3 KiB
JavaScript
export const DELIVERY_TYPE = 'delivery';
|
|
|
|
export const LIST_DELIVERIES = `
|
|
SELECT
|
|
m.id,
|
|
m.[number],
|
|
m.[type],
|
|
m.entity_id AS supplierId,
|
|
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_DELIVERY_HEADER = `
|
|
SELECT
|
|
m.id,
|
|
m.[number],
|
|
m.[type],
|
|
m.entity_id AS supplierId,
|
|
m.[date]
|
|
FROM manifest m
|
|
WHERE m.id = @id
|
|
AND m.company_id = @companyId
|
|
AND m.[type] = @type
|
|
`;
|
|
|
|
export const GET_DELIVERY_LINES = `
|
|
SELECT
|
|
ma.id,
|
|
ma.article_id AS articleId,
|
|
a.sku,
|
|
ma.amount,
|
|
ma.net,
|
|
ma.transactedamount AS transactedAmount,
|
|
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,
|
|
transactedamount,
|
|
comment,
|
|
rebate,
|
|
tax_id
|
|
)
|
|
OUTPUT INSERTED.id
|
|
VALUES (
|
|
@manifestId,
|
|
@articleId,
|
|
@amount,
|
|
@net,
|
|
@transactedAmount,
|
|
@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
|
|
)
|
|
`;
|