From 5d92bf355c0df5643c0ba1e282fdcb8c98d1be14 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Mon, 11 Jun 2007 08:35:36 +0000 Subject: [PATCH] =?utf8?q?Mahnwesen:=201.=20Beim=20Erzeugen=20neuer=20Mahn?= =?utf8?q?ungen=20wurden=20unter=20Umst=C3=A4nden=20=C3=BCberall=20die=20f?= =?utf8?q?alschen=20n=C3=A4chsten=20Mahnstufen=20vorausgew=C3=A4hlt.=202.?= =?utf8?q?=20Rechnungen,=20die=20bereits=20auf=20der=20h=C3=B6chsten=20Mah?= =?utf8?q?nstufe=20waren,=20wurden=20nicht=20mehr=20angezeigt.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/DN.pm | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/SL/DN.pm b/SL/DN.pm index 711a88463..4f0827104 100644 --- a/SL/DN.pm +++ b/SL/DN.pm @@ -462,6 +462,12 @@ sub get_invoices { push(@values, $form->{minamount}); } + $query = + qq|SELECT id + FROM dunning_config + WHERE dunning_level = (SELECT MAX(dunning_level) FROM dunning_config)|; + my ($id_for_max_dunning_level) = selectrow_query($form, $dbh, $query); + $query = qq|SELECT a.id, a.ordnumber, a.transdate, a.invnumber, a.amount, @@ -486,16 +492,19 @@ sub get_invoices { LEFT JOIN dunning_config cfg ON (a.dunning_config_id = cfg.id) LEFT JOIN dunning_config nextcfg ON (nextcfg.id = - (SELECT id - FROM dunning_config - WHERE dunning_level > - COALESCE((SELECT dunning_level - FROM dunning_config - WHERE id = a.dunning_config_id - ORDER BY dunning_level DESC - LIMIT 1), - 0) - LIMIT 1)) + COALESCE( + (SELECT id + FROM dunning_config + WHERE dunning_level > + COALESCE((SELECT dunning_level + FROM dunning_config + WHERE id = a.dunning_config_id + ORDER BY dunning_level DESC + LIMIT 1), + 0) + ORDER BY dunning_level ASC + LIMIT 1) + , ?)) LEFT JOIN dunning d ON ((d.trans_id = a.id) AND (cfg.dunning_level = d.dunning_level)) WHERE (a.paid < a.amount) @@ -504,7 +513,7 @@ sub get_invoices { $where ORDER BY a.id, transdate, duedate, name|; - my $sth = prepare_execute_query($form, $dbh, $query, @values); + my $sth = prepare_execute_query($form, $dbh, $query, $id_for_max_dunning_level, @values); $form->{DUNNINGS} = []; -- 2.20.1