<dtml-comment>
title:
connection_id:erp5_sql_connection
max_rows:100000
max_cache:100
cache_time:0
class_name:ZSQLBrain
class_file:zsqlbrain.py
</dtml-comment>
<params>to_date
resource
simulation_state:list</params>
SELECT 
        SUM(stock.quantity) as inventory,
	section.title AS section_title,
	resource.title AS resource_title,
	resource.relative_url AS resource_relative_url,
	MAX(movement_line.path) as path,
	movement.variation_text AS variation_text
FROM
	catalog, movement, stock, catalog as section, category as node_category, category as section_category, 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	movement.resource_uid = resource.uid
AND	stock.section_uid = section.uid
AND	section_category.category_uid=<dtml-var "portal_categories.group.Coramy.getUid()">
AND	stock.section_uid = section_category.uid
AND	(node_category.category_uid=<dtml-var "portal_categories.site.Stock_MP.getUid()">
OR	node_category.category_uid=<dtml-var "portal_categories.site.Stock_PF.getUid()">)
AND	stock.node_uid = node_category.uid
<dtml-if resource>AND	resource.relative_url = <dtml-sqlvar resource type="string">
</dtml-if><dtml-if to_date> AND	movement.stop_date < <dtml-sqlvar to_date type="string">
</dtml-if><dtml-if simulation_state> AND (<dtml-in simulation_state> catalog.simulation_state = <dtml-sqlvar sequence-item type="string"><dtml-if sequence-end><dtml-else> OR </dtml-if></dtml-in>)
</dtml-if>
GROUP BY
	resource.uid, movement.variation_text
ORDER BY
	inventory