<dtml-comment>
title:
connection_id:erp5_sql_connection
max_rows:1000
max_cache:100
cache_time:0
class_name:ZSQLBrain
class_file:zsqlbrain.py
</dtml-comment>
<params>before_date
</params>
SELECT 
	SUM(stock.quantity) as inventory,
	section.title AS section_title,
	resource.title AS resource_title,
	MAX(movement_line.path) as path,
	movement.variation_text AS variation_text
FROM
	catalog, movement, stock, catalog as section, catalog as resource, catalog as movement_line
WHERE
	catalog.uid = movement.uid
AND	catalog.uid = stock.uid
AND	movement.is_accountable = 1
AND	movement_line.uid = movement.uid
AND	section.uid = stock.section_uid
AND	movement.resource_uid = resource.uid
AND     section.relative_url='group/Coramy'
<dtml-if before_date>AND	movement.start_date < <dtml-sqlvar before_date type="string">
</dtml-if>GROUP BY
	movement.variation_text
ORDER BY
	inventory DESC