This commit is contained in:
seb
2026-09-30 21:27:27 +02:00
parent ed91ccbaee
commit bc467e29da
3 changed files with 100 additions and 8 deletions

View File

@@ -54,8 +54,16 @@ export default function toggleFather(provider) {
}
const stockRes = await runner.query(
'SELECT COALESCE(SUM(l.amount), 0) AS totalStock FROM ledger l WHERE l.article_id = @articleId',
{ articleId },
`SELECT COALESCE(SUM(l.amount), 0) AS totalStock
FROM ledger l
INNER JOIN manifestarticle ma ON ma.id = l.manifestarticle_id
INNER JOIN manifest m ON m.id = ma.manifest_id
WHERE m.company_id = @companyId
AND (
ma.sku = @sku
OR ma.sku IN (SELECT asup.sku FROM articlesupplier asup WHERE asup.article_id = @articleId)
)`,
{ companyId, sku, articleId },
);
const totalStock = Number(stockRes.rows[0]?.totalStock ?? 0);
if (totalStock !== 0) {