This commit is contained in:
seb
2026-10-19 02:28:15 +02:00
parent cce966d021
commit 5259e3bef9
6 changed files with 105 additions and 6 deletions

View File

@@ -574,7 +574,30 @@ SELECT
asup.sort,
asup.net AS [price.net],
asup.tax_id AS [price.taxId],
t.rate AS [price.taxRate]
t.rate AS [price.taxRate],
(
SELECT
m.[date] AS [date],
SUM(ma.amount - COALESCE(ma_ledger.booked_amount, 0)) AS amount
FROM manifest m
INNER JOIN manifestarticle ma ON ma.manifest_id = m.id
LEFT JOIN (
SELECT manifestarticle_id, SUM(amount) AS booked_amount
FROM ledger
WHERE warehouse_id IS NULL
GROUP BY manifestarticle_id
) ma_ledger ON ma_ledger.manifestarticle_id = ma.id
WHERE m.company_id = a.company_id
AND m.[type] = 'delivery'
AND m.entity_id = asup.entity_id
AND asup.sku IS NOT NULL
AND asup.sku <> ''
AND ma.sku = asup.sku
AND (ma.amount - COALESCE(ma_ledger.booked_amount, 0)) > 0
GROUP BY m.id, m.[date]
ORDER BY m.[date] ASC, m.id ASC
FOR JSON PATH
) AS incomingJson
FROM articlesupplier asup
INNER JOIN entity e ON e.id = asup.entity_id
LEFT JOIN tax t ON t.id = asup.tax_id