u
This commit is contained in:
@@ -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