#if ( ("$!contract_number" == "")
&& ("$!client_full_name" == "")
&& ("$!contract_activity_type" == "")
&& ("$!account_number" == "")
&& ("$!created_at_from" == "")
&& ("$!created_at_to" == "")
&& ("$!certificate_id" == "")
&& ("$!receive_method" == "")
&& ("$!certificate_date_from" == "")
&& ("$!certificate_date_to" == "")
&& ("$!snils" == "") )
and 1 = 0
#end
#if ("$!certificate_date_from" != "")
and td.date >= to_date(:certificate_date_from, 'YYYY-MM-DD')
#end
#if ("$!certificate_date_to" != "")
and td.date < to_date(:certificate_date_to, 'YYYY-MM-DD')
+ interval '1 day'
#end
WHERE 1 = 1
#if ("$!receive_method" != "")
and CASE
WHEN fj_resp.has_response_received
OR snv.contract_number IS NOT NULL
THEN 'ФНС'
WHEN b.tessa_doc_app_id IS NOT NULL
THEN 'Почта'
ELSE b.info_name
END = cast(:receive_method as text)
#end