<dtml-comment>
title:
connection_id:erp5_sql_connection
max_rows:1000
max_cache:100
cache_time:0
class_name:
class_file:
</dtml-comment>
<params>uid
resource_uid
variation_text</params>
SELECT
	SUM(quantity) AS inventory,
	SUM(quantity) AS total_quantity,
	SUM(total_price) AS total_price,
	SUM(target_quantity) AS target_total_quantity,
	SUM(target_total_price) AS target_total_price,
	AVG(price) AS average_price
FROM movement, catalog
WHERE
	movement.delivery_uid = <dtml-sqlvar uid type="int">
<dtml-if resource_uid>AND	(<dtml-in resource_uid> movement.resource_uid = <dtml-sqlvar sequence-item type="int"><dtml-if sequence-end><dtml-else> OR </dtml-if></dtml-in>)
</dtml-if><dtml-if variation_text>AND	movement.variation_text = <dtml-sqlvar variation_text type="string">
</dtml-if>
AND	movement.is_accountable = 1
AND	catalog.portal_type <> "Container"
AND	catalog.portal_type <> "Simulation Movement"
AND	catalog.uid = movement.uid