<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>resource_uid_list:list
to_date
node_uid
section_uid
variation_text</params>
SELECT 
	SUM(stock.quantity) as inventory,
	node.title AS node_title,
	section.title AS section_title,
	resource.title AS resource_title,
	movement.variation_text AS variation_text
FROM
	catalog, movement, stock, catalog as node, catalog as section, catalog as resource
WHERE
	catalog.uid = movement.uid
AND	catalog.uid = stock.uid
AND	(<dtml-in resource_uid_list>movement.resource_uid = <dtml-sqlvar sequence-item type="int"><dtml-if sequence-end> <dtml-else> OR </dtml-if></dtml-in>)
AND	movement.is_accountable = 1
AND	node.uid = stock.node_uid
AND	section.uid = stock.node_uid
AND	movement.resource_uid = resource.uid
<dtml-if to_date>AND	movement.start_date < <dtml-sqlvar to_date type="string">
</dtml-if><dtml-if node_uid>AND	stock.node_uid  = <dtml-sqlvar node_uid type="int">
</dtml-if><dtml-if section_uid>AND	stock.section_uid  = <dtml-sqlvar section_uid type="int">
</dtml-if><dtml-if variation_text>AND	movement.variation_text = <dtml-sqlvar variation_text type="string">
</dtml-if>GROUP BY
	stock.node_uid, stock.section_uid, resource_uid, movement.variation_text
ORDER BY
	inventory DESC