<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>order_uid_list:list
resource_uid
variation_text</params>
SELECT
	catalog.*,
        movement.quantity,
        movement.target_quantity,
        movement.resource_uid,
        movement.variation_text,
        movement.source_uid,
        movement.destination_uid,
        movement.start_date,
        movement.stop_date,
        movement.target_start_date,
        movement.target_stop_date
FROM
	movement AS related_order_line,
	movement,
	catalog AS related_order,
	category AS movement_c,
	catalog LEFT JOIN category ON (category.uid=catalog.uid 
             AND category.base_category_uid = <dtml-var "portal_categories.delivery.getUid()">) 
                LEFT JOIN catalog as related_delivery ON related_delivery.uid = category.category_uid
WHERE
 	related_delivery.uid is NULL
AND
	catalog.portal_type = "Simulation Movement"
AND
	catalog.uid = movement_c.uid
AND
	movement_c.category_uid = related_order_line.uid
AND
	movement_c.base_category_uid = <dtml-var "portal_categories.order.getUid()">
AND
	related_order_line.delivery_uid = related_order.uid
AND
	catalog.uid = movement.uid
AND (
	related_order.simulation_state = 'confirmed'
OR	related_order.simulation_state = 'getting_started'
OR	related_order.simulation_state = 'started'
OR	related_order.simulation_state = 'stopped'
OR	related_order.simulation_state = 'delivered'
)
<dtml-if order_uid_list>AND	(<dtml-in order_uid_list>related_order.uid = <dtml-sqlvar sequence-item type="int"> <dtml-if sequence-end><dtml-else> OR </dtml-if> </dtml-in>
)</dtml-if><dtml-if resource_uid>AND	movement.resource_uid = <dtml-sqlvar resource_uid type="int"> 
</dtml-if><dtml-if variation_text>AND	movement.variation_text = <dtml-sqlvar variation_text type="string"> 
</dtml-if>