This commit is contained in:
seb
2026-10-01 17:40:04 +02:00
parent 62c3e69ed4
commit 84e547660e
53 changed files with 4604 additions and 2059 deletions

View File

@@ -123,54 +123,16 @@ export default function adjust(provider) {
throw new Error(`A father article cannot have stock (${item.sku})`);
}
const articlelistId = artRes.rows[0]?.articlelist_id;
if (articlelistId != null) {
const compRes = await runner.query(`
SELECT
ala.article_id AS articleId,
ala.count,
a.sku,
at.name AS articleName
FROM articlelistarticle ala
INNER JOIN article a ON a.id = ala.article_id
LEFT JOIN articletext at ON at.article_id = a.id AND at.language_id = @languageId
WHERE ala.articlelist_id = @articlelistId
ORDER BY ala.sort ASC, ala.id ASC
`, {
articlelistId,
languageId: resolved.languageId,
});
if (compRes.rows.length === 0) {
throw new Error(`Stückliste has no items (${item.sku})`);
}
for (const comp of compRes.rows) {
const compCount = Number(comp.count || 1);
const compAmount = item.amount * compCount;
const compText = item.text
? `${item.text} (${item.sku})`
: (compAmount > 0
? `Manual stock addition (+${compAmount}) [${item.sku}]`
: `Manual stock removal (${compAmount}) [${item.sku}]`);
resolvedArticles.push({
sku: comp.sku,
warehouseId: item.warehouseId,
amount: compAmount,
text: compText,
articleId: comp.articleId,
articleName: comp.articleName || comp.sku,
});
}
} else {
const nameRes = await runner.query(GET_ARTICLE_NAME_SQL, {
articleId: resolved.articleId,
languageId: resolved.languageId,
});
const articleName = nameRes.rows[0]?.name ?? item.sku;
resolvedArticles.push({ ...item, ...resolved, articleName });
if (artRes.rows[0]?.articlelist_id != null) {
throw new Error(`A Stückliste cannot have manual stock adjustments (${item.sku})`);
}
const nameRes = await runner.query(GET_ARTICLE_NAME_SQL, {
articleId: resolved.articleId,
languageId: resolved.languageId,
});
const articleName = nameRes.rows[0]?.name ?? item.sku;
resolvedArticles.push({ ...item, ...resolved, articleName });
}
// Allocate unique adjustment number using the dedicated adjustment number scheme