<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>source_section_uid=""
destination_uid=""
group_uid=""
destination_decision_uid=""</params>
SELECT DISTINCT condition.id, condition.Description, condition.path, condition.uid, condition.portal_type
FROM catalog AS condition
<dtml-if expr="source_section_uid<>''">
, category as cat1
</dtml-if>
<dtml-if expr="destination_uid<>''">
, category as cat2
</dtml-if>
<dtml-if expr="destination_decision_uid<>''">
, category as cat3
</dtml-if>
<dtml-if expr="group_uid<>''">
, category as cat4
</dtml-if>
<dtml-if expr="destination_uid==''">
LEFT JOIN category as cat2
ON (cat2.uid=condition.uid
AND cat2.base_category_uid = <dtml-var "portal_categories.destination.uid">)
</dtml-if>
WHERE condition.portal_type="Condition Vente"

<dtml-if expr="source_section_uid<>''">
AND condition.uid = cat1.uid
AND cat1.category_uid = "<dtml-var source_section_uid>"
AND cat1.base_category_uid = <dtml-var "portal_categories.source_section.uid">
AND cat1.category_strict_membership = 1
</dtml-if>

<dtml-if expr="destination_uid<>''">
AND condition.uid = cat2.uid
AND cat2.category_uid = "<dtml-var destination_uid>"
AND cat2.base_category_uid = <dtml-var "portal_categories.destination.uid">
</dtml-if>
<dtml-if expr="destination_uid==''">
AND cat2.uid IS NULL
</dtml-if>

<dtml-if expr="group_uid<>''">
AND condition.uid = cat4.uid
AND cat4.category_uid = "<dtml-var group_uid>"
AND cat4.base_category_uid = <dtml-var "portal_categories.group.uid">
</dtml-if>

<dtml-if expr="destination_decision_uid<>''">
AND condition.uid = cat3.uid
AND cat3.category_uid = "<dtml-var destination_decision_uid>"
AND cat3.base_category_uid = <dtml-var "portal_categories.destination_decision.uid">
</dtml-if>