u
This commit is contained in:
@@ -562,14 +562,12 @@ SELECT
|
||||
asup.pu,
|
||||
asup.stock,
|
||||
asup.sort,
|
||||
asup.price_id AS priceId,
|
||||
p.net AS [price.net],
|
||||
p.tax_id AS [price.taxId],
|
||||
asup.net AS [price.net],
|
||||
asup.tax_id AS [price.taxId],
|
||||
t.rate AS [price.taxRate]
|
||||
FROM articlesupplier asup
|
||||
INNER JOIN entity e ON e.id = asup.entity_id
|
||||
LEFT JOIN price p ON p.id = asup.price_id
|
||||
LEFT JOIN tax t ON t.id = p.tax_id
|
||||
LEFT JOIN tax t ON t.id = asup.tax_id
|
||||
WHERE asup.article_id = a.id
|
||||
ORDER BY asup.sort ASC, asup.id ASC
|
||||
FOR JSON PATH
|
||||
|
||||
@@ -8,15 +8,13 @@ SELECT
|
||||
asup.pu,
|
||||
asup.stock,
|
||||
asup.sort,
|
||||
asup.price_id AS priceId,
|
||||
p.net AS priceNet,
|
||||
p.tax_id AS priceTaxId,
|
||||
asup.net AS priceNet,
|
||||
asup.tax_id AS priceTaxId,
|
||||
t.rate AS priceTaxRate
|
||||
FROM articlesupplier asup
|
||||
INNER JOIN entity e ON e.id = asup.entity_id
|
||||
INNER JOIN customergroup cg ON cg.id = e.customergroup_id
|
||||
LEFT JOIN price p ON p.id = asup.price_id
|
||||
LEFT JOIN tax t ON t.id = p.tax_id
|
||||
LEFT JOIN tax t ON t.id = asup.tax_id
|
||||
WHERE asup.article_id = @articleId
|
||||
AND cg.company_id = @companyId
|
||||
ORDER BY asup.sort ASC, asup.id ASC;
|
||||
@@ -32,15 +30,13 @@ SELECT
|
||||
asup.pu,
|
||||
asup.stock,
|
||||
asup.sort,
|
||||
asup.price_id AS priceId,
|
||||
p.net AS priceNet,
|
||||
p.tax_id AS priceTaxId,
|
||||
asup.net AS priceNet,
|
||||
asup.tax_id AS priceTaxId,
|
||||
t.rate AS priceTaxRate
|
||||
FROM articlesupplier asup
|
||||
INNER JOIN entity e ON e.id = asup.entity_id
|
||||
INNER JOIN customergroup cg ON cg.id = e.customergroup_id
|
||||
LEFT JOIN price p ON p.id = asup.price_id
|
||||
LEFT JOIN tax t ON t.id = p.tax_id
|
||||
LEFT JOIN tax t ON t.id = asup.tax_id
|
||||
WHERE asup.id = @id
|
||||
AND asup.article_id = @articleId
|
||||
AND cg.company_id = @companyId;
|
||||
@@ -59,9 +55,9 @@ WHERE article_id = @articleId;
|
||||
`;
|
||||
|
||||
export const CREATE = `
|
||||
INSERT INTO articlesupplier (article_id, entity_id, price_id, sku, stock, pu, sort)
|
||||
INSERT INTO articlesupplier (article_id, entity_id, net, tax_id, sku, stock, pu, sort)
|
||||
OUTPUT INSERTED.id
|
||||
VALUES (@articleId, @entityId, @priceId, @sku, @stock, @pu, @sort);
|
||||
VALUES (@articleId, @entityId, @net, @taxId, @sku, @stock, @pu, @sort);
|
||||
`;
|
||||
|
||||
export const UPDATE = `
|
||||
@@ -70,7 +66,8 @@ SET
|
||||
sku = @sku,
|
||||
stock = @stock,
|
||||
pu = @pu,
|
||||
price_id = @priceId,
|
||||
net = @net,
|
||||
tax_id = @taxId,
|
||||
sort = @sort
|
||||
WHERE id = @id AND article_id = @articleId;
|
||||
`;
|
||||
@@ -99,19 +96,6 @@ SET sort = @sort
|
||||
WHERE id = @id AND article_id = @articleId;
|
||||
`;
|
||||
|
||||
export const UPDATE_PRICE = `
|
||||
UPDATE price
|
||||
SET
|
||||
net = @net,
|
||||
tax_id = @taxId
|
||||
WHERE id = @id AND article_id = @articleId;
|
||||
`;
|
||||
|
||||
export const DELETE_PRICE = `
|
||||
DELETE FROM price
|
||||
WHERE id = @id AND article_id = @articleId;
|
||||
`;
|
||||
|
||||
export const GET_COMPANY_DEFAULT_TAX = `
|
||||
SELECT taxrate
|
||||
FROM company
|
||||
@@ -128,9 +112,8 @@ SELECT
|
||||
asup.pu,
|
||||
asup.stock,
|
||||
asup.sort,
|
||||
asup.price_id AS priceId,
|
||||
p.net AS priceNet,
|
||||
p.tax_id AS priceTaxId,
|
||||
asup.net AS priceNet,
|
||||
asup.tax_id AS priceTaxId,
|
||||
t.rate AS priceTaxRate,
|
||||
a.id AS a_id,
|
||||
a.sku AS a_sku,
|
||||
@@ -161,8 +144,7 @@ INNER JOIN entity e ON e.id = asup.entity_id
|
||||
INNER JOIN customergroup cg ON cg.id = e.customergroup_id
|
||||
INNER JOIN article a ON a.id = asup.article_id
|
||||
LEFT JOIN articletext at ON at.article_id = a.id AND at.language_id = @languageId
|
||||
LEFT JOIN price p ON p.id = asup.price_id
|
||||
LEFT JOIN tax t ON t.id = p.tax_id
|
||||
LEFT JOIN tax t ON t.id = asup.tax_id
|
||||
WHERE asup.entity_id = @entityId
|
||||
AND cg.company_id = @companyId
|
||||
AND (
|
||||
|
||||
@@ -590,14 +590,15 @@ BEGIN
|
||||
id INT IDENTITY(1,1) PRIMARY KEY,
|
||||
article_id INT NOT NULL,
|
||||
entity_id INT NOT NULL,
|
||||
price_id INT NULL,
|
||||
net FLOAT NULL,
|
||||
tax_id INT NULL,
|
||||
sku NVARCHAR(100) NULL,
|
||||
stock FLOAT NULL,
|
||||
pu FLOAT NOT NULL CONSTRAINT DF_articlesupplier_pu DEFAULT 1,
|
||||
sort INT NOT NULL CONSTRAINT DF_articlesupplier_sort DEFAULT 0,
|
||||
CONSTRAINT FK_articlesupplier_article FOREIGN KEY (article_id) REFERENCES article(id) ON DELETE CASCADE,
|
||||
CONSTRAINT FK_articlesupplier_entity FOREIGN KEY (entity_id) REFERENCES entity(id) ON DELETE CASCADE,
|
||||
CONSTRAINT FK_articlesupplier_price FOREIGN KEY (price_id) REFERENCES price(id) ON DELETE NO ACTION,
|
||||
CONSTRAINT FK_articlesupplier_tax FOREIGN KEY (tax_id) REFERENCES tax(id) ON DELETE NO ACTION,
|
||||
CONSTRAINT UQ_articlesupplier_article_entity UNIQUE (article_id, entity_id),
|
||||
CONSTRAINT UQ_articlesupplier_article_sort UNIQUE (article_id, sort)
|
||||
);
|
||||
|
||||
@@ -203,17 +203,16 @@ SELECT auth.*,
|
||||
'suppliersJson', json((SELECT COALESCE(json_group_array(json_object(
|
||||
'id', id, 'articleId', article_id, 'entityId', entity_id,
|
||||
'supplierName', supplier_name, 'sku', sku, 'pu', pu,
|
||||
'stock', stock, 'sort', sort, 'priceId', price_id,
|
||||
'price', CASE WHEN price_id IS NULL THEN NULL ELSE json_object(
|
||||
'stock', stock, 'sort', sort,
|
||||
'price', CASE WHEN net IS NULL THEN NULL ELSE json_object(
|
||||
'net', net, 'taxId', tax_id, 'taxRate', tax_rate
|
||||
) END
|
||||
)), '[]') FROM (
|
||||
SELECT s.id, s.article_id, s.entity_id, e.name AS supplier_name,
|
||||
s.sku, s.pu, s.stock, s.sort, s.price_id,
|
||||
pr.net, pr.tax_id, t.rate AS tax_rate
|
||||
s.sku, s.pu, s.stock, s.sort,
|
||||
s.net, s.tax_id, t.rate AS tax_rate
|
||||
FROM articlesupplier s INNER JOIN entity e ON e.id = s.entity_id
|
||||
LEFT JOIN price pr ON pr.id = s.price_id
|
||||
LEFT JOIN tax t ON t.id = pr.tax_id
|
||||
LEFT JOIN tax t ON t.id = s.tax_id
|
||||
WHERE s.article_id = a.id ORDER BY s.sort, s.id
|
||||
))),
|
||||
'warehousesJson', json((SELECT COALESCE(json_group_array(json_object(
|
||||
|
||||
@@ -3,17 +3,17 @@ import { translateQueries } from './translate.js';
|
||||
|
||||
const queries = translateQueries(source, 'articlesupplier');
|
||||
export const {
|
||||
CHECK_EXISTS, CREATE, DELETE_BY_ID_AND_ARTICLE_ID, DELETE_PRICE,
|
||||
CHECK_EXISTS, CREATE, DELETE_BY_ID_AND_ARTICLE_ID,
|
||||
GET_BY_ID_AND_ARTICLE_ID, GET_COMPANY_DEFAULT_TAX, GET_NEXT_SORT,
|
||||
LIST_BY_ARTICLE_ID, LIST_IDS_BY_ARTICLE,
|
||||
SET_TEMP_SORTS, UPDATE, UPDATE_PRICE, UPDATE_SORT,
|
||||
SET_TEMP_SORTS, UPDATE, UPDATE_SORT,
|
||||
} = queries;
|
||||
|
||||
export const LIST_BY_ENTITY_AND_SKUS = `
|
||||
SELECT
|
||||
asup.id, asup.article_id AS articleId, asup.entity_id AS entityId,
|
||||
e.name AS supplierName, asup.sku, asup.pu, asup.stock, asup.sort,
|
||||
asup.price_id AS priceId, p.net AS priceNet, p.tax_id AS priceTaxId,
|
||||
asup.net AS priceNet, asup.tax_id AS priceTaxId,
|
||||
t.rate AS priceTaxRate, a.id AS a_id, a.sku AS a_sku,
|
||||
at.name AS a_name, at.slug AS a_slug,
|
||||
(SELECT COALESCE(json_group_array(json_object(
|
||||
@@ -31,8 +31,7 @@ INNER JOIN entity e ON e.id = asup.entity_id
|
||||
INNER JOIN customergroup cg ON cg.id = e.customergroup_id
|
||||
INNER JOIN article a ON a.id = asup.article_id
|
||||
LEFT JOIN articletext at ON at.article_id = a.id AND at.language_id = @languageId
|
||||
LEFT JOIN price p ON p.id = asup.price_id
|
||||
LEFT JOIN tax t ON t.id = p.tax_id
|
||||
LEFT JOIN tax t ON t.id = asup.tax_id
|
||||
WHERE asup.entity_id = @entityId
|
||||
AND cg.company_id = @companyId
|
||||
AND (
|
||||
|
||||
@@ -385,7 +385,8 @@ CREATE TABLE IF NOT EXISTS articlesupplier (
|
||||
id INTEGER PRIMARY KEY,
|
||||
article_id INTEGER NOT NULL,
|
||||
entity_id INTEGER NOT NULL,
|
||||
price_id INTEGER,
|
||||
net REAL,
|
||||
tax_id INTEGER,
|
||||
sku TEXT,
|
||||
stock REAL,
|
||||
pu REAL NOT NULL DEFAULT 1,
|
||||
@@ -394,7 +395,7 @@ CREATE TABLE IF NOT EXISTS articlesupplier (
|
||||
UNIQUE (article_id, sort),
|
||||
FOREIGN KEY (article_id) REFERENCES article(id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (entity_id) REFERENCES entity(id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (price_id) REFERENCES price(id) ON DELETE NO ACTION
|
||||
FOREIGN KEY (tax_id) REFERENCES tax(id) ON DELETE NO ACTION
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS IX_articlesupplier_article_entity
|
||||
ON articlesupplier(article_id, entity_id);
|
||||
|
||||
Reference in New Issue
Block a user