<dtml-comment>
title:
connection_id:MySQL
max_rows:1000
max_cache:100
cache_time:0
class_name:
class_file:
</dtml-comment>
<params></params>
SELECT DISTINCT
	count(distinct item.uid)
FROM
	catalog AS item

LEFT JOIN category
ON (category.category_uid=item.uid
AND category.base_category_uid = <dtml-var "portal_categories.aggregate.getUid()">)

LEFT JOIN movement
ON (movement.uid = category.uid)

LEFT JOIN catalog AS delivery
ON (delivery.uid = movement.delivery_uid)

LEFT JOIN stock
ON (stock.uid = category.uid
AND ((stock.node_uid = <dtml-var "portal_categories.site.Stock_MP.Gravelines.getUid()">
AND  stock.quantity < 0)
OR (delivery.portal_type <> "Production Packing List" AND delivery.portal_type <> "Movement MP" )))

WHERE item.portal_type = "Piece Tissu"
AND stock.uid IS NULL