FROM ${arap}
LEFT JOIN ${vc} vc ON (${arap}.${vc}_id = vc.id)
- LEFT JOIN (SELECT sei.${arap}_id, SUM(sei.amount) AS amount
+ LEFT JOIN (SELECT sei.${arap}_id, SUM(sei.amount) + SUM(COALESCE(sei.skonto_amount,0)) AS amount
FROM sepa_export_items sei
LEFT JOIN sepa_export se ON (sei.sepa_export_id = se.id)
WHERE NOT se.closed
$joins_sub{$arap} = 1;
}
+ if ($filter->{message_id}) {
+ push @values, '%' . $filter->{message_id} . '%';
+ push @where, <<SQL;
+ se.id IN (
+ SELECT sepa_export_id
+ FROM sepa_export_message_ids
+ WHERE message_id ILIKE ?
+ )
+SQL
+ }
+
if ($filter->{vc}) {
push @where_sub, "vc.name ILIKE ?";
push @values_sub, '%' . $filter->{vc} . '%';