u
This commit is contained in:
@@ -10,12 +10,14 @@ import { ADD as MSSQL_ADD_CATEGORYARTICLE } from '../../providers/mssql/queries/
|
||||
import { ADD as SQLITE_ADD_CATEGORYARTICLE } from '../../providers/sqlite3/queries/categoryarticle.js';
|
||||
import { CREATE as MSSQL_CREATE_ARTICLETEXT } from '../../providers/mssql/queries/articletext.js';
|
||||
import { CREATE as SQLITE_CREATE_ARTICLETEXT } from '../../providers/sqlite3/queries/articletext.js';
|
||||
import { INSERT as MSSQL_INSERT_HISTORY } from '../../providers/mssql/queries/articlehistory.js';
|
||||
import { INSERT as SQLITE_INSERT_HISTORY } from '../../providers/sqlite3/queries/articlehistory.js';
|
||||
import resolveArticleBySku from './resolveArticleBySku.js';
|
||||
import getBySku from './getBySku.js';
|
||||
import makeRunner from '../runner.js';
|
||||
import resolveUniqueSlug from './resolveUniqueSlug.js';
|
||||
import {
|
||||
recordVariantAddedOnParentHistory,
|
||||
recordChildAssignedToParentHistory,
|
||||
} from '../articlehistory/record.js';
|
||||
import attachChild from './attachChild.js';
|
||||
|
||||
export default function addChild(provider) {
|
||||
@@ -31,7 +33,6 @@ export default function addChild(provider) {
|
||||
const articleAttrValQueries = isSqlite ? sqliteArticleAttrVal : mssqlArticleAttrVal;
|
||||
const addCategoryArticleSql = isSqlite ? SQLITE_ADD_CATEGORYARTICLE : MSSQL_ADD_CATEGORYARTICLE;
|
||||
const createArticleTextSql = isSqlite ? SQLITE_CREATE_ARTICLETEXT : MSSQL_CREATE_ARTICLETEXT;
|
||||
const insertHistorySql = isSqlite ? SQLITE_INSERT_HISTORY : MSSQL_INSERT_HISTORY;
|
||||
|
||||
/**
|
||||
* Adds a child article to a parent article (creates and attaches with auto-generated SKU).
|
||||
@@ -242,17 +243,21 @@ export default function addChild(provider) {
|
||||
});
|
||||
|
||||
// History on child
|
||||
await runner.query(insertHistorySql, {
|
||||
articleId: childId,
|
||||
await recordChildAssignedToParentHistory(runner, {
|
||||
childId,
|
||||
companyuserId,
|
||||
text: `Artikel "${childName}" (${childSku}) als Variante von "${parent.sku}" angelegt`,
|
||||
childName,
|
||||
childSku,
|
||||
parentSku: parent.sku,
|
||||
created: true,
|
||||
});
|
||||
|
||||
// History on parent
|
||||
await runner.query(insertHistorySql, {
|
||||
articleId: parentId,
|
||||
await recordVariantAddedOnParentHistory(runner, {
|
||||
parentId,
|
||||
companyuserId,
|
||||
text: `Variante "${childName}" (${childSku}) hinzugefügt`,
|
||||
childName,
|
||||
childSku,
|
||||
});
|
||||
|
||||
return load(googleAuthId, childSku, runner);
|
||||
|
||||
@@ -6,11 +6,13 @@ import * as mssqlArticleAttrVal from '../../providers/mssql/queries/articleattri
|
||||
import * as sqliteArticleAttrVal from '../../providers/sqlite3/queries/articleattributevalue.js';
|
||||
import { ADD as MSSQL_ADD_CATEGORYARTICLE } from '../../providers/mssql/queries/categoryarticle.js';
|
||||
import { ADD as SQLITE_ADD_CATEGORYARTICLE } from '../../providers/sqlite3/queries/categoryarticle.js';
|
||||
import { INSERT as MSSQL_INSERT_HISTORY } from '../../providers/mssql/queries/articlehistory.js';
|
||||
import { INSERT as SQLITE_INSERT_HISTORY } from '../../providers/sqlite3/queries/articlehistory.js';
|
||||
import resolveArticleBySku from './resolveArticleBySku.js';
|
||||
import getBySku from './getBySku.js';
|
||||
import listChildren from './listChildren.js';
|
||||
import {
|
||||
recordChildAssignedToParentHistory,
|
||||
recordVariantAddedOnParentHistory,
|
||||
} from '../articlehistory/record.js';
|
||||
import makeRunner from '../runner.js';
|
||||
|
||||
export default function attachChild(provider) {
|
||||
@@ -23,7 +25,6 @@ export default function attachChild(provider) {
|
||||
const attrValQueries = isSqlite ? sqliteAttrVal : mssqlAttrVal;
|
||||
const articleAttrValQueries = isSqlite ? sqliteArticleAttrVal : mssqlArticleAttrVal;
|
||||
const addCategoryArticleSql = isSqlite ? SQLITE_ADD_CATEGORYARTICLE : MSSQL_ADD_CATEGORYARTICLE;
|
||||
const insertHistorySql = isSqlite ? SQLITE_INSERT_HISTORY : MSSQL_INSERT_HISTORY;
|
||||
|
||||
/**
|
||||
* Attaches an existing article as a child to a parent article.
|
||||
@@ -288,16 +289,19 @@ export default function attachChild(provider) {
|
||||
|
||||
// History only if not already child
|
||||
if (!isAlreadyChildOfThisParent) {
|
||||
await runner.query(insertHistorySql, {
|
||||
articleId: child.id,
|
||||
await recordChildAssignedToParentHistory(runner, {
|
||||
childId: child.id,
|
||||
companyuserId,
|
||||
text: `Artikel "${childName}" (${childSku}) als Variante von "${parent.sku}" zugewiesen`,
|
||||
childName,
|
||||
childSku,
|
||||
parentSku: parent.sku,
|
||||
});
|
||||
|
||||
await runner.query(insertHistorySql, {
|
||||
articleId: parentId,
|
||||
await recordVariantAddedOnParentHistory(runner, {
|
||||
parentId,
|
||||
companyuserId,
|
||||
text: `Variante "${childName}" (${childSku}) hinzugefügt`,
|
||||
childName,
|
||||
childSku,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -4,14 +4,13 @@ import { ADD as MSSQL_ADD_CATEGORYARTICLE } from '../../providers/mssql/queries/
|
||||
import { ADD as SQLITE_ADD_CATEGORYARTICLE } from '../../providers/sqlite3/queries/categoryarticle.js';
|
||||
import { CREATE as MSSQL_CREATE_ARTICLETEXT } from '../../providers/mssql/queries/articletext.js';
|
||||
import { CREATE as SQLITE_CREATE_ARTICLETEXT } from '../../providers/sqlite3/queries/articletext.js';
|
||||
import { INSERT as MSSQL_INSERT_HISTORY } from '../../providers/mssql/queries/articlehistory.js';
|
||||
import { INSERT as SQLITE_INSERT_HISTORY } from '../../providers/sqlite3/queries/articlehistory.js';
|
||||
import { isUniqueConstraintError } from '../../providers/provider.js';
|
||||
import resolveCategoryAccess from '../category/resolveCategoryAccess.js';
|
||||
import ensureDefaultUnit from '../unit/ensureDefault.js';
|
||||
import nextSku from '../numbers/nextSku.js';
|
||||
import makeRunner from '../runner.js';
|
||||
import resolveUniqueSlug from './resolveUniqueSlug.js';
|
||||
import { recordArticleCreatedHistory } from '../articlehistory/record.js';
|
||||
|
||||
export default function createUnderParent(provider) {
|
||||
const access = resolveCategoryAccess(provider);
|
||||
@@ -23,7 +22,6 @@ export default function createUnderParent(provider) {
|
||||
const createArticleSql = isSqlite ? SQLITE_CREATE_ARTICLE : MSSQL_CREATE_ARTICLE;
|
||||
const addCategoryArticleSql = isSqlite ? SQLITE_ADD_CATEGORYARTICLE : MSSQL_ADD_CATEGORYARTICLE;
|
||||
const createArticleTextSql = isSqlite ? SQLITE_CREATE_ARTICLETEXT : MSSQL_CREATE_ARTICLETEXT;
|
||||
const insertHistorySql = isSqlite ? SQLITE_INSERT_HISTORY : MSSQL_INSERT_HISTORY;
|
||||
|
||||
/**
|
||||
* Creates a new article under a given parent category, allocating a SKU and
|
||||
@@ -95,10 +93,10 @@ export default function createUnderParent(provider) {
|
||||
seo: finalSeo,
|
||||
});
|
||||
|
||||
await runner.query(insertHistorySql, {
|
||||
await recordArticleCreatedHistory(runner, {
|
||||
articleId: id,
|
||||
companyuserId,
|
||||
text: `Artikel "${name}" angelegt`,
|
||||
name,
|
||||
});
|
||||
|
||||
return {
|
||||
|
||||
@@ -17,11 +17,11 @@ export default function getHistoryBySku(provider) {
|
||||
* @param {object} [opts] - Optional options.
|
||||
* @param {number} [opts.limit] - Maximum number of entries to return (newest first).
|
||||
* @param {object} [tx] - Optional transaction.
|
||||
* @returns {Promise<Array<{id: number, companyuserId: number|null, date: string, text: string}>>} The article history entries.
|
||||
* @returns {Promise<Array<{id: number, companyuserId: number|null, date: string, text: string, meta: string|null}>>} The article history entries.
|
||||
*
|
||||
* @example
|
||||
* const history = await store.article.getHistoryBySku(42, 'SKU-1');
|
||||
* // => [{ id, companyuserId, date, text }]
|
||||
* // => [{ id, companyuserId, date, text, meta }]
|
||||
*
|
||||
* const recent = await store.article.getHistoryBySku(42, 'SKU-1', { limit: 5 });
|
||||
* // => up to 5 most recent entries
|
||||
@@ -51,6 +51,7 @@ export default function getHistoryBySku(provider) {
|
||||
companyuserId: row.companyuserId ?? null,
|
||||
date: row.date,
|
||||
text: row.text,
|
||||
meta: row.meta ?? null,
|
||||
}));
|
||||
};
|
||||
}
|
||||
|
||||
@@ -4,10 +4,14 @@ import { ADD as MSSQL_ADD_CATEGORYARTICLE } from '../../providers/mssql/queries/
|
||||
import { ADD as SQLITE_ADD_CATEGORYARTICLE } from '../../providers/sqlite3/queries/categoryarticle.js';
|
||||
import { CREATE as MSSQL_CREATE_ARTICLETEXT } from '../../providers/mssql/queries/articletext.js';
|
||||
import { CREATE as SQLITE_CREATE_ARTICLETEXT } from '../../providers/sqlite3/queries/articletext.js';
|
||||
import { INSERT as MSSQL_INSERT_HISTORY } from '../../providers/mssql/queries/articlehistory.js';
|
||||
import { INSERT as SQLITE_INSERT_HISTORY } from '../../providers/sqlite3/queries/articlehistory.js';
|
||||
import { GET_CHILD_COUNT as MSSQL_GET_CHILD_COUNT } from '../../providers/mssql/queries/articleDelete.js';
|
||||
import { GET_CHILD_COUNT as SQLITE_GET_CHILD_COUNT } from '../../providers/sqlite3/queries/articleDelete.js';
|
||||
import {
|
||||
recordParentConvertedHistory,
|
||||
recordVariantAddedOnParentHistory,
|
||||
recordChildAssignedToParentHistory,
|
||||
recordArticleImportedHistory,
|
||||
} from '../articlehistory/record.js';
|
||||
import {
|
||||
CREATE as MSSQL_CREATE_BRAND,
|
||||
GET_BY_COMPANY_AND_NAME as MSSQL_GET_BRAND_BY_NAME,
|
||||
@@ -55,7 +59,6 @@ export default function importRows(provider) {
|
||||
const articleQueries = isSqlite ? sqliteArticle : mssqlArticle;
|
||||
const addCategoryArticleSql = isSqlite ? SQLITE_ADD_CATEGORYARTICLE : MSSQL_ADD_CATEGORYARTICLE;
|
||||
const createArticleTextSql = isSqlite ? SQLITE_CREATE_ARTICLETEXT : MSSQL_CREATE_ARTICLETEXT;
|
||||
const insertHistorySql = isSqlite ? SQLITE_INSERT_HISTORY : MSSQL_INSERT_HISTORY;
|
||||
const getChildCountSql = isSqlite ? SQLITE_GET_CHILD_COUNT : MSSQL_GET_CHILD_COUNT;
|
||||
const getBrandByNameSql = isSqlite ? SQLITE_GET_BRAND_BY_NAME : MSSQL_GET_BRAND_BY_NAME;
|
||||
const createBrandSql = isSqlite ? SQLITE_CREATE_BRAND : MSSQL_CREATE_BRAND;
|
||||
@@ -210,10 +213,10 @@ export default function importRows(provider) {
|
||||
seo: null,
|
||||
});
|
||||
|
||||
await runner.query(insertHistorySql, {
|
||||
await recordArticleImportedHistory(runner, {
|
||||
articleId,
|
||||
companyuserId,
|
||||
text: `Artikel "${name}" importiert`,
|
||||
name,
|
||||
});
|
||||
|
||||
// Brand (upsert by name).
|
||||
@@ -318,22 +321,24 @@ export default function importRows(provider) {
|
||||
});
|
||||
|
||||
if (!wasParent) {
|
||||
await runner.query(insertHistorySql, {
|
||||
await recordParentConvertedHistory(runner, {
|
||||
articleId: parentId,
|
||||
companyuserId,
|
||||
text: 'Artikel zu Vaterartikel konvertiert',
|
||||
});
|
||||
}
|
||||
const childName = String(row?.name ?? sku).trim();
|
||||
await runner.query(insertHistorySql, {
|
||||
articleId: parentId,
|
||||
await recordVariantAddedOnParentHistory(runner, {
|
||||
parentId,
|
||||
companyuserId,
|
||||
text: `Variante "${childName}" (${sku}) hinzugefügt`,
|
||||
childName,
|
||||
childSku: sku,
|
||||
});
|
||||
await runner.query(insertHistorySql, {
|
||||
articleId: childId,
|
||||
await recordChildAssignedToParentHistory(runner, {
|
||||
childId,
|
||||
companyuserId,
|
||||
text: `Artikel "${childName}" (${sku}) als Variante von "${parentSku}" zugewiesen`,
|
||||
childName,
|
||||
childSku: sku,
|
||||
parentSku,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import * as mssqlArticle from '../../providers/mssql/queries/article.js';
|
||||
import * as sqliteArticle from '../../providers/sqlite3/queries/article.js';
|
||||
import { INSERT as MSSQL_INSERT_HISTORY } from '../../providers/mssql/queries/articlehistory.js';
|
||||
import { INSERT as SQLITE_INSERT_HISTORY } from '../../providers/sqlite3/queries/articlehistory.js';
|
||||
import resolveArticleBySku from './resolveArticleBySku.js';
|
||||
import articleDelete from './delete.js';
|
||||
import {
|
||||
recordChildUnlinkedFromParentHistory,
|
||||
recordChildDeletedFromParentHistory,
|
||||
} from '../articlehistory/record.js';
|
||||
import makeRunner from '../runner.js';
|
||||
|
||||
export default function removeChild(provider) {
|
||||
@@ -12,7 +14,6 @@ export default function removeChild(provider) {
|
||||
const isSqlite = provider?.dialect === 'sqlite3';
|
||||
|
||||
const queries = isSqlite ? sqliteArticle : mssqlArticle;
|
||||
const insertHistorySql = isSqlite ? SQLITE_INSERT_HISTORY : MSSQL_INSERT_HISTORY;
|
||||
|
||||
/**
|
||||
* Removes a child article from a parent article, either by unlinking or deleting it.
|
||||
@@ -78,10 +79,11 @@ export default function removeChild(provider) {
|
||||
await recompactParentSort();
|
||||
|
||||
// History on parent (child article is gone so we can only log on parent)
|
||||
await runner.query(insertHistorySql, {
|
||||
articleId: parentId,
|
||||
await recordChildDeletedFromParentHistory(runner, {
|
||||
parentId,
|
||||
companyuserId,
|
||||
text: `Variante "${childName}" (${childSku}) gelöscht`,
|
||||
childName,
|
||||
childSku,
|
||||
});
|
||||
|
||||
return {
|
||||
@@ -119,18 +121,14 @@ export default function removeChild(provider) {
|
||||
|
||||
await recompactParentSort();
|
||||
|
||||
// Add history on child
|
||||
await runner.query(insertHistorySql, {
|
||||
articleId: childId,
|
||||
// Add history on child and parent
|
||||
await recordChildUnlinkedFromParentHistory(runner, {
|
||||
childId,
|
||||
parentId,
|
||||
companyuserId,
|
||||
text: `Artikel "${childSku}" von Vaterartikel "${parentSku}" getrennt`,
|
||||
});
|
||||
|
||||
// Add history on parent
|
||||
await runner.query(insertHistorySql, {
|
||||
articleId: parentId,
|
||||
companyuserId,
|
||||
text: `Variante "${childName}" (${childSku}) getrennt`,
|
||||
childSku,
|
||||
childName,
|
||||
parentSku,
|
||||
});
|
||||
|
||||
return {
|
||||
|
||||
@@ -6,10 +6,9 @@ import {
|
||||
GET_BRAND_BY_COMPANY_AND_ID as SQLITE_GET_BRAND,
|
||||
UPDATE_BRAND as SQLITE_UPDATE_BRAND,
|
||||
} from '../../providers/sqlite3/queries/article.js';
|
||||
import { INSERT as MSSQL_INSERT_HISTORY } from '../../providers/mssql/queries/articlehistory.js';
|
||||
import { INSERT as SQLITE_INSERT_HISTORY } from '../../providers/sqlite3/queries/articlehistory.js';
|
||||
import queryBySku from './queryBySku.js';
|
||||
import resolveArticleBySku from './resolveArticleBySku.js';
|
||||
import { recordBrandChangeHistory } from '../articlehistory/record.js';
|
||||
import makeRunner from '../runner.js';
|
||||
|
||||
export default function setBrandIdBySku(provider) {
|
||||
@@ -19,7 +18,6 @@ export default function setBrandIdBySku(provider) {
|
||||
|
||||
const getBrandSql = isSqlite ? SQLITE_GET_BRAND : MSSQL_GET_BRAND;
|
||||
const updateBrandSql = isSqlite ? SQLITE_UPDATE_BRAND : MSSQL_UPDATE_BRAND;
|
||||
const insertHistorySql = isSqlite ? SQLITE_INSERT_HISTORY : MSSQL_INSERT_HISTORY;
|
||||
|
||||
/**
|
||||
* Sets (or clears) the brand of an article by its SKU.
|
||||
@@ -82,13 +80,12 @@ export default function setBrandIdBySku(provider) {
|
||||
}
|
||||
|
||||
// null = no brand; treat as distinct sentinel so first assignment is logged
|
||||
if (oldBrandName !== newBrandName) {
|
||||
await runner.query(insertHistorySql, {
|
||||
articleId,
|
||||
companyuserId,
|
||||
text: `Marke ge\u00e4ndert von "${oldBrandName ?? ''}" auf "${newBrandName ?? ''}"`,
|
||||
});
|
||||
}
|
||||
await recordBrandChangeHistory(runner, {
|
||||
articleId,
|
||||
companyuserId,
|
||||
oldBrandName,
|
||||
newBrandName,
|
||||
});
|
||||
|
||||
const article = await load(articleId, languageId, runner);
|
||||
if (!article) {
|
||||
|
||||
@@ -6,11 +6,10 @@ import {
|
||||
ADD_CATEGORY as SQLITE_ADD_CATEGORY,
|
||||
DELETE_CATEGORIES_BY_ARTICLE as SQLITE_DELETE_CATEGORIES,
|
||||
} from '../../providers/sqlite3/queries/article.js';
|
||||
import { INSERT as MSSQL_INSERT_HISTORY } from '../../providers/mssql/queries/articlehistory.js';
|
||||
import { INSERT as SQLITE_INSERT_HISTORY } from '../../providers/sqlite3/queries/articlehistory.js';
|
||||
import resolveCategoryAccess from '../category/resolveCategoryAccess.js';
|
||||
import queryBySku from './queryBySku.js';
|
||||
import resolveArticleBySku from './resolveArticleBySku.js';
|
||||
import { recordCategoryChangeHistory } from '../articlehistory/record.js';
|
||||
import makeRunner from '../runner.js';
|
||||
|
||||
export default function setCategoryIdsBySku(provider) {
|
||||
@@ -21,7 +20,6 @@ export default function setCategoryIdsBySku(provider) {
|
||||
|
||||
const addCategorySql = isSqlite ? SQLITE_ADD_CATEGORY : MSSQL_ADD_CATEGORY;
|
||||
const deleteCategoriesSql = isSqlite ? SQLITE_DELETE_CATEGORIES : MSSQL_DELETE_CATEGORIES;
|
||||
const insertHistorySql = isSqlite ? SQLITE_INSERT_HISTORY : MSSQL_INSERT_HISTORY;
|
||||
|
||||
/**
|
||||
* Replaces the category membership of an article by its SKU.
|
||||
@@ -86,15 +84,12 @@ export default function setCategoryIdsBySku(provider) {
|
||||
}
|
||||
|
||||
// Write history if categories changed
|
||||
const oldStr = oldCategoryIds.join(', ');
|
||||
const newStr = [...normalized].sort((a, b) => a - b).join(', ');
|
||||
if (oldStr !== newStr) {
|
||||
await runner.query(insertHistorySql, {
|
||||
articleId,
|
||||
companyuserId,
|
||||
text: `Kategorien geändert von [${oldStr}] auf [${newStr}]`,
|
||||
});
|
||||
}
|
||||
await recordCategoryChangeHistory(runner, {
|
||||
articleId,
|
||||
companyuserId,
|
||||
oldCategoryIds,
|
||||
newCategoryIds: normalized,
|
||||
});
|
||||
|
||||
const article = await load(articleId, languageId, runner);
|
||||
if (!article) {
|
||||
|
||||
@@ -8,11 +8,10 @@ import {
|
||||
DELETE_EANS_BY_ARTICLE as SQLITE_DELETE_EANS,
|
||||
EAN_EXISTS_FOR_OTHER_ARTICLE as SQLITE_CHECK_CONFLICT,
|
||||
} from '../../providers/sqlite3/queries/article.js';
|
||||
import { INSERT as MSSQL_INSERT_HISTORY } from '../../providers/mssql/queries/articlehistory.js';
|
||||
import { INSERT as SQLITE_INSERT_HISTORY } from '../../providers/sqlite3/queries/articlehistory.js';
|
||||
import { isUniqueConstraintError } from '../../providers/provider.js';
|
||||
import queryBySku from './queryBySku.js';
|
||||
import resolveArticleBySku from './resolveArticleBySku.js';
|
||||
import { recordEanChangeHistory } from '../articlehistory/record.js';
|
||||
import makeRunner from '../runner.js';
|
||||
|
||||
export default function setEansBySku(provider) {
|
||||
@@ -22,7 +21,6 @@ export default function setEansBySku(provider) {
|
||||
|
||||
const addEanSql = isSqlite ? SQLITE_ADD_EAN : MSSQL_ADD_EAN;
|
||||
const deleteEansSql = isSqlite ? SQLITE_DELETE_EANS : MSSQL_DELETE_EANS;
|
||||
const insertHistorySql = isSqlite ? SQLITE_INSERT_HISTORY : MSSQL_INSERT_HISTORY;
|
||||
const checkConflictSql = isSqlite ? SQLITE_CHECK_CONFLICT : MSSQL_CHECK_CONFLICT;
|
||||
|
||||
/**
|
||||
@@ -93,15 +91,12 @@ export default function setEansBySku(provider) {
|
||||
}
|
||||
|
||||
// Write history if EANs changed
|
||||
const oldStr = oldEans.join(', ');
|
||||
const newStr = [...normalized].sort().join(', ');
|
||||
if (oldStr !== newStr) {
|
||||
await runner.query(insertHistorySql, {
|
||||
articleId,
|
||||
companyuserId,
|
||||
text: `EANs geändert von "${oldStr}" auf "${newStr}"`,
|
||||
});
|
||||
}
|
||||
await recordEanChangeHistory(runner, {
|
||||
articleId,
|
||||
companyuserId,
|
||||
oldEans,
|
||||
newEans: normalized,
|
||||
});
|
||||
|
||||
const article = await load(articleId, languageId, runner);
|
||||
if (!article) {
|
||||
|
||||
@@ -2,10 +2,13 @@ import * as mssqlArticle from '../../providers/mssql/queries/article.js';
|
||||
import * as sqliteArticle from '../../providers/sqlite3/queries/article.js';
|
||||
import { GET_CHILD_COUNT as MSSQL_GET_CHILD_COUNT } from '../../providers/mssql/queries/articleDelete.js';
|
||||
import { GET_CHILD_COUNT as SQLITE_GET_CHILD_COUNT } from '../../providers/sqlite3/queries/articleDelete.js';
|
||||
import { INSERT as MSSQL_INSERT_HISTORY } from '../../providers/mssql/queries/articlehistory.js';
|
||||
import { INSERT as SQLITE_INSERT_HISTORY } from '../../providers/sqlite3/queries/articlehistory.js';
|
||||
import queryBySku from './queryBySku.js';
|
||||
import resolveArticleBySku from './resolveArticleBySku.js';
|
||||
import {
|
||||
recordParentConvertedHistory,
|
||||
recordVariantAddedOnParentHistory,
|
||||
recordChildAssignedToParentHistory,
|
||||
} from '../articlehistory/record.js';
|
||||
import makeRunner from '../runner.js';
|
||||
|
||||
export default function setParentBySku(provider) {
|
||||
@@ -15,7 +18,6 @@ export default function setParentBySku(provider) {
|
||||
|
||||
const queries = isSqlite ? sqliteArticle : mssqlArticle;
|
||||
const getChildCountSql = isSqlite ? SQLITE_GET_CHILD_COUNT : MSSQL_GET_CHILD_COUNT;
|
||||
const insertHistorySql = isSqlite ? SQLITE_INSERT_HISTORY : MSSQL_INSERT_HISTORY;
|
||||
|
||||
/**
|
||||
* Links an article to a parent article (V/K compound) by their SKUs.
|
||||
@@ -118,23 +120,25 @@ export default function setParentBySku(provider) {
|
||||
});
|
||||
|
||||
if (!wasParent) {
|
||||
await runner.query(insertHistorySql, {
|
||||
await recordParentConvertedHistory(runner, {
|
||||
articleId: parentId,
|
||||
companyuserId,
|
||||
text: 'Artikel zu Vaterartikel konvertiert',
|
||||
});
|
||||
}
|
||||
|
||||
await runner.query(insertHistorySql, {
|
||||
articleId: parentId,
|
||||
await recordVariantAddedOnParentHistory(runner, {
|
||||
parentId,
|
||||
companyuserId,
|
||||
text: `Variante "${childName}" (${sku}) hinzugefügt`,
|
||||
childName,
|
||||
childSku: sku,
|
||||
});
|
||||
|
||||
await runner.query(insertHistorySql, {
|
||||
articleId,
|
||||
await recordChildAssignedToParentHistory(runner, {
|
||||
childId: articleId,
|
||||
companyuserId,
|
||||
text: `Artikel "${sku}" als Variante von "${parentSku}" zugewiesen`,
|
||||
childName: null,
|
||||
childSku: sku,
|
||||
parentSku,
|
||||
});
|
||||
|
||||
const article = await load(articleId, languageId, runner);
|
||||
|
||||
@@ -6,11 +6,10 @@ import {
|
||||
CREATE as SQLITE_CREATE_PRICE,
|
||||
DELETE_BY_ARTICLE_AND_CUSTOMERGROUP as SQLITE_DELETE_PRICE,
|
||||
} from '../../providers/sqlite3/queries/price.js';
|
||||
import { INSERT as MSSQL_INSERT_HISTORY } from '../../providers/mssql/queries/articlehistory.js';
|
||||
import { INSERT as SQLITE_INSERT_HISTORY } from '../../providers/sqlite3/queries/articlehistory.js';
|
||||
import taxEnsure from '../tax/ensure.js';
|
||||
import queryBySku from './queryBySku.js';
|
||||
import resolveArticleBySku from './resolveArticleBySku.js';
|
||||
import { recordPriceChangeHistory } from '../articlehistory/record.js';
|
||||
import makeRunner from '../runner.js';
|
||||
|
||||
function normalizePrices(prices) {
|
||||
@@ -66,7 +65,6 @@ export default function setPricesBySku(provider) {
|
||||
|
||||
const createPriceSql = isSqlite ? SQLITE_CREATE_PRICE : MSSQL_CREATE_PRICE;
|
||||
const deletePriceSql = isSqlite ? SQLITE_DELETE_PRICE : MSSQL_DELETE_PRICE;
|
||||
const insertHistorySql = isSqlite ? SQLITE_INSERT_HISTORY : MSSQL_INSERT_HISTORY;
|
||||
|
||||
/**
|
||||
* Replaces the price list of an article by its SKU.
|
||||
@@ -136,16 +134,12 @@ export default function setPricesBySku(provider) {
|
||||
}
|
||||
|
||||
// Write history if prices changed
|
||||
const fmtPrice = (p) => `${p.net}@${p.taxRate ?? 0}%`;
|
||||
const oldStr = oldPrices.map(fmtPrice).join(', ');
|
||||
const newStr = normalized.map((e) => `${e.price}@${e.tax}%`).join(', ');
|
||||
if (oldStr !== newStr) {
|
||||
await runner.query(insertHistorySql, {
|
||||
articleId,
|
||||
companyuserId,
|
||||
text: `Preise geändert von [${oldStr}] auf [${newStr}]`,
|
||||
});
|
||||
}
|
||||
await recordPriceChangeHistory(runner, {
|
||||
articleId,
|
||||
companyuserId,
|
||||
oldPrices,
|
||||
newPrices: normalized,
|
||||
});
|
||||
|
||||
const article = await load(articleId, languageId, runner);
|
||||
if (!article) {
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import { UPDATE_TRACK_STOCK as MSSQL_UPDATE_TRACK_STOCK } from '../../providers/mssql/queries/article.js';
|
||||
import { UPDATE_TRACK_STOCK as SQLITE_UPDATE_TRACK_STOCK } from '../../providers/sqlite3/queries/article.js';
|
||||
import { INSERT as MSSQL_INSERT_HISTORY } from '../../providers/mssql/queries/articlehistory.js';
|
||||
import { INSERT as SQLITE_INSERT_HISTORY } from '../../providers/sqlite3/queries/articlehistory.js';
|
||||
import queryBySku from './queryBySku.js';
|
||||
import resolveArticleBySku from './resolveArticleBySku.js';
|
||||
import { recordTrackStockChangeHistory } from '../articlehistory/record.js';
|
||||
import makeRunner from '../runner.js';
|
||||
|
||||
export default function setTrackStockBySku(provider) {
|
||||
@@ -13,7 +12,6 @@ export default function setTrackStockBySku(provider) {
|
||||
provider?.dialect === 'sqlite3'
|
||||
? SQLITE_UPDATE_TRACK_STOCK
|
||||
: MSSQL_UPDATE_TRACK_STOCK;
|
||||
const insertHistorySql = provider?.dialect === 'sqlite3' ? SQLITE_INSERT_HISTORY : MSSQL_INSERT_HISTORY;
|
||||
|
||||
/**
|
||||
* Sets the track_stock flag of an article by its SKU.
|
||||
@@ -55,13 +53,12 @@ export default function setTrackStockBySku(provider) {
|
||||
}
|
||||
|
||||
// Write history if track_stock changed
|
||||
if (oldTrack !== newTrack) {
|
||||
await runner.query(insertHistorySql, {
|
||||
articleId,
|
||||
companyuserId,
|
||||
text: `Bestandsführung geändert von "${oldTrack ? 'Ja' : 'Nein'}" auf "${newTrack ? 'Ja' : 'Nein'}"`,
|
||||
});
|
||||
}
|
||||
await recordTrackStockChangeHistory(runner, {
|
||||
articleId,
|
||||
companyuserId,
|
||||
oldTrack,
|
||||
newTrack,
|
||||
});
|
||||
|
||||
const article = await load(articleId, languageId, runner);
|
||||
if (!article) {
|
||||
|
||||
@@ -1,16 +1,14 @@
|
||||
import { UPDATE_WEIGHT as MSSQL_UPDATE_WEIGHT } from '../../providers/mssql/queries/article.js';
|
||||
import { UPDATE_WEIGHT as SQLITE_UPDATE_WEIGHT } from '../../providers/sqlite3/queries/article.js';
|
||||
import { INSERT as MSSQL_INSERT_HISTORY } from '../../providers/mssql/queries/articlehistory.js';
|
||||
import { INSERT as SQLITE_INSERT_HISTORY } from '../../providers/sqlite3/queries/articlehistory.js';
|
||||
import queryBySku from './queryBySku.js';
|
||||
import resolveArticleBySku from './resolveArticleBySku.js';
|
||||
import { recordWeightChangeHistory } from '../articlehistory/record.js';
|
||||
import makeRunner from '../runner.js';
|
||||
|
||||
export default function setWeightBySku(provider) {
|
||||
const resolve = resolveArticleBySku(provider);
|
||||
const load = queryBySku(provider);
|
||||
const sql = provider?.dialect === 'sqlite3' ? SQLITE_UPDATE_WEIGHT : MSSQL_UPDATE_WEIGHT;
|
||||
const insertHistorySql = provider?.dialect === 'sqlite3' ? SQLITE_INSERT_HISTORY : MSSQL_INSERT_HISTORY;
|
||||
|
||||
/**
|
||||
* Sets the weight of an article by its SKU.
|
||||
@@ -51,13 +49,12 @@ export default function setWeightBySku(provider) {
|
||||
}
|
||||
|
||||
// Write history if weight changed
|
||||
if (Number(oldWeight) !== weight) {
|
||||
await runner.query(insertHistorySql, {
|
||||
articleId,
|
||||
companyuserId,
|
||||
text: `Gewicht geändert von "${oldWeight}" auf "${weight}"`,
|
||||
});
|
||||
}
|
||||
await recordWeightChangeHistory(runner, {
|
||||
articleId,
|
||||
companyuserId,
|
||||
oldWeight,
|
||||
newWeight: weight,
|
||||
});
|
||||
|
||||
const article = await load(articleId, languageId, runner);
|
||||
if (!article) {
|
||||
|
||||
@@ -4,10 +4,12 @@ import { GET_CHILD_COUNT as MSSQL_GET_CHILD_COUNT } from '../../providers/mssql/
|
||||
import { GET_CHILD_COUNT as SQLITE_GET_CHILD_COUNT } from '../../providers/sqlite3/queries/articleDelete.js';
|
||||
import * as mssqlAttr from '../../providers/mssql/queries/attributename.js';
|
||||
import * as sqliteAttr from '../../providers/sqlite3/queries/attributename.js';
|
||||
import { INSERT as MSSQL_INSERT_HISTORY } from '../../providers/mssql/queries/articlehistory.js';
|
||||
import { INSERT as SQLITE_INSERT_HISTORY } from '../../providers/sqlite3/queries/articlehistory.js';
|
||||
import resolveArticleBySku from './resolveArticleBySku.js';
|
||||
import getBySku from './getBySku.js';
|
||||
import {
|
||||
recordParentConvertedHistory,
|
||||
recordParentDeactivatedHistory,
|
||||
} from '../articlehistory/record.js';
|
||||
import makeRunner from '../runner.js';
|
||||
|
||||
export default function toggleParent(provider) {
|
||||
@@ -18,7 +20,6 @@ export default function toggleParent(provider) {
|
||||
const queries = isSqlite ? sqliteArticle : mssqlArticle;
|
||||
const getChildCountSql = isSqlite ? SQLITE_GET_CHILD_COUNT : MSSQL_GET_CHILD_COUNT;
|
||||
const attrQueries = isSqlite ? sqliteAttr : mssqlAttr;
|
||||
const insertHistorySql = isSqlite ? SQLITE_INSERT_HISTORY : MSSQL_INSERT_HISTORY;
|
||||
|
||||
/**
|
||||
* Toggles an article into or out of parent mode.
|
||||
@@ -142,32 +143,11 @@ export default function toggleParent(provider) {
|
||||
});
|
||||
|
||||
// Add history entry recording parent conversion and deleted prices
|
||||
const historyLines = [
|
||||
`Artikel zu Vaterartikel konvertiert (Varianten-Attribut: "${attributeName}")`,
|
||||
];
|
||||
|
||||
if (existingPrices.length > 0) {
|
||||
const priceParts = existingPrices.map((p) => {
|
||||
let str = `${p.net} €`;
|
||||
if (p.taxRate != null) {
|
||||
str += ` (${p.taxRate}% MwSt.)`;
|
||||
}
|
||||
if (p.minmultiplier > 1) {
|
||||
str += ` ab ${p.minmultiplier} Stk.`;
|
||||
}
|
||||
if (p.customerGroupName) {
|
||||
str += ` [${p.customerGroupName}]`;
|
||||
}
|
||||
return str;
|
||||
});
|
||||
const label = existingPrices.length === 1 ? 'Bisheriger Preis gelöscht' : 'Bisherige Preise gelöscht';
|
||||
historyLines.push(`${label}: ${priceParts.join(', ')}`);
|
||||
}
|
||||
|
||||
await runner.query(insertHistorySql, {
|
||||
await recordParentConvertedHistory(runner, {
|
||||
articleId,
|
||||
companyuserId,
|
||||
text: historyLines.join('\n'),
|
||||
attributeName,
|
||||
existingPrices,
|
||||
});
|
||||
} else {
|
||||
// Disabling parent: verify zero children
|
||||
@@ -183,10 +163,9 @@ export default function toggleParent(provider) {
|
||||
parentAttributeNameId: null,
|
||||
});
|
||||
|
||||
await runner.query(insertHistorySql, {
|
||||
await recordParentDeactivatedHistory(runner, {
|
||||
articleId,
|
||||
companyuserId,
|
||||
text: 'Vaterartikel-Modus deaktiviert',
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import * as mssqlArticle from '../../providers/mssql/queries/article.js';
|
||||
import * as sqliteArticle from '../../providers/sqlite3/queries/article.js';
|
||||
import { INSERT as MSSQL_INSERT_HISTORY } from '../../providers/mssql/queries/articlehistory.js';
|
||||
import { INSERT as SQLITE_INSERT_HISTORY } from '../../providers/sqlite3/queries/articlehistory.js';
|
||||
import { UPDATE_BY_ARTICLE_AND_LANGUAGE as MSSQL_UPDATE_TEXT } from '../../providers/mssql/queries/articletext.js';
|
||||
import { UPDATE_BY_ARTICLE_AND_LANGUAGE as SQLITE_UPDATE_TEXT } from '../../providers/sqlite3/queries/articletext.js';
|
||||
import { GET_DETAIL_BY_ARTICLE_ID as MSSQL_GET_DETAIL } from '../../providers/mssql/queries/articleDetail.js';
|
||||
@@ -12,6 +10,7 @@ import queryBySku from './queryBySku.js';
|
||||
import resolveArticleBySku from './resolveArticleBySku.js';
|
||||
import makeRunner from '../runner.js';
|
||||
import resolveUniqueSlug from './resolveUniqueSlug.js';
|
||||
import { recordArticleUpdateHistory } from '../articlehistory/record.js';
|
||||
|
||||
function formatUnitLabel(amount, symbol) {
|
||||
const sym = symbol ?? '';
|
||||
@@ -28,7 +27,6 @@ export default function updateBySku(provider) {
|
||||
const isSqlite = provider?.dialect === 'sqlite3';
|
||||
|
||||
const articleQueries = isSqlite ? sqliteArticle : mssqlArticle;
|
||||
const insertHistorySql = isSqlite ? SQLITE_INSERT_HISTORY : MSSQL_INSERT_HISTORY;
|
||||
const updateTextSql = isSqlite ? SQLITE_UPDATE_TEXT : MSSQL_UPDATE_TEXT;
|
||||
const getDetailSql = isSqlite ? SQLITE_GET_DETAIL : MSSQL_GET_DETAIL;
|
||||
const getUnitSql = isSqlite ? SQLITE_GET_UNIT : MSSQL_GET_UNIT;
|
||||
@@ -221,10 +219,10 @@ export default function updateBySku(provider) {
|
||||
}
|
||||
|
||||
if (historyLines.length) {
|
||||
await runner.query(insertHistorySql, {
|
||||
await recordArticleUpdateHistory(runner, {
|
||||
articleId,
|
||||
companyuserId,
|
||||
text: historyLines.join('\n'),
|
||||
historyLines,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user