<dtml-comment>
title:
connection_id:MySQL
max_rows:100000
max_cache:100
cache_time:0
class_name:ZSQLBrain
class_file:zsqlbrain.py
</dtml-comment>
<params>source_section_uid</params>
SELECT resource.id AS resource_id, sum(movement.target_quantity) AS quantity, sum(movement.total_price) AS total_price
FROM catalog AS sale_order, catalog AS order_line, category AS category_sc, movement, catalog AS resource

WHERE sale_order.portal_type = "Sales Order"
AND ( order_line.portal_type = "Sales Order Line"
OR order_line.portal_type = "Delivery Cell" )

AND order_line.uid = movement.uid
AND movement.delivery_uid = sale_order.uid
AND movement.has_cell_content = 0

AND resource.uid = movement.resource_uid

AND (sale_order.simulation_state = "planned"
OR sale_order.simulation_state = "ordered"
OR sale_order.simulation_state = "draft"
OR sale_order.simulation_state = "confirmed")

AND category_sc.uid=sale_order.uid
AND category_sc.base_category_uid = <dtml-var "portal_categories.source_section.uid">
AND category_sc.category_uid = <dtml-var source_section_uid>
AND category_sc.category_strict_membership = 1

GROUP BY resource.id