<dtml-comment>
title:
connection_id:MySQL
max_rows:1000
max_cache:100
cache_time:0
class_name:
class_file:
</dtml-comment>
<params>year</params>
SELECT
   YEAR(movement.target_stop_date) as target_stop_date,
   movement.variation_text AS variation_text,
   destination.title as destination_title,
  - SUM(movement.total_price) as total_price
FROM
  catalog
LEFT JOIN
  movement ON (movement.uid = catalog.uid)
LEFT JOIN 
  catalog AS destination ON (movement.destination_uid = destination.uid)
WHERE
  catalog.portal_type = "Pay Sheet Cell" <dtml-if year>and YEAR(movement.target_stop_date)=<dtml-sqlvar year type="int"> </dtml-if> 
GROUP BY
  movement.target_stop_date, movement.destination_uid, movement.variation_text