X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FRP.pm;h=4a7b0afefdd657b7f1e1de0783a519b4a8eabc81;hb=718f7a1b58963922cb3a4512692e15e2b4267ee7;hp=a1875ab2258ed4ca52f538a33c613c38bb704c1a;hpb=a6b4b406f0a9db0a1c719f4b7d5eb8265f90bf61;p=kivitendo-erp.git diff --git a/SL/RP.pm b/SL/RP.pm index a1875ab22..4a7b0afef 100644 --- a/SL/RP.pm +++ b/SL/RP.pm @@ -211,13 +211,25 @@ sub get_accounts { $sth->finish; + # filter for opening and closing bookings # if l_ob is selected l_cb is always ignored - if ( $form->{l_ob} ) { - $where .= ' AND ac.ob_transaction is true ' - } elsif ( not $form->{l_cb} ) { - $where .= ' AND ac.cb_transaction is false '; + if ( $last_period ) { + # ob/cb-settings for "compared to" balance + if ( $form->{l_ob_compared} ) { + $where .= ' AND ac.ob_transaction is true ' + } elsif ( not $form->{l_cb_compared} ) { + $where .= ' AND ac.cb_transaction is false '; + }; + } else { + # ob/cb-settings for "as of" balance + if ( $form->{l_ob} ) { + $where .= ' AND ac.ob_transaction is true ' + } elsif ( not $form->{l_cb} ) { + $where .= ' AND ac.cb_transaction is false '; + }; }; + if ($fromdate) { $fromdate = conv_dateq($fromdate); if ($form->{method} eq 'cash') { @@ -504,7 +516,7 @@ sub get_accounts_g { if ($form->{method} eq 'cash') { $query = qq| - SELECT SUM( ac.amount * CASE WHEN COALESCE((SELECT amount FROM ar WHERE id = ac.trans_id), 0) != 0 THEN + SELECT SUM( ac.amount * CASE WHEN COALESCE((SELECT amount FROM ar a WHERE id = ac.trans_id $dpt_where), 0) != 0 THEN /* ar amount is not zero, so we can divide by amount */ (SELECT SUM(acc.amount) * -1 FROM acc_trans acc @@ -519,13 +531,6 @@ sub get_accounts_g { FROM acc_trans ac LEFT JOIN chart c ON (c.id = ac.chart_id) LEFT JOIN ar ON (ar.id = ac.trans_id) - LEFT JOIN taxkeys tk ON (tk.id = ( - SELECT id FROM taxkeys - WHERE chart_id = ac.chart_id - AND startdate <= COALESCE(ar.deliverydate,ar.transdate) - ORDER BY startdate DESC LIMIT 1 - ) - ) WHERE ac.trans_id IN (SELECT DISTINCT trans_id FROM acc_trans WHERE 1=1 $subwhere) GROUP BY c.$category @@ -1164,10 +1169,12 @@ sub aging { # mit entsprechender altersstrukturliste (s.a. Bug 1842) # eine neue variable an der oberfläche eingeführt, somit ist # todate == freier zeitrau und fordate == stichtag + # duedate_where == nur fällige rechnungen anzeigen - my ($review_of_aging_list, $todate, $fromdate, $fromwhere, $fordate); + my ($review_of_aging_list, $todate, $fromdate, $fromwhere, $fordate, + $duedate_where); - if ($form->{reporttype} eq 'custom') { # altersstrukturliste + if ($form->{reporttype} eq 'custom') { # altersstrukturliste, nur fällige # explizit rausschmeissen was man für diesen bericht nicht braucht delete $form->{fromdate}; @@ -1190,7 +1197,8 @@ sub aging { $review_of_aging_list = " AND $form->{review_of_aging_list} < (date $fordate) - duedate"; } } - } else { # freier zeitraum OHNE review_of_aging_list + $duedate_where = " AND (date $fordate) - duedate >= 0 "; + } else { # freier zeitraum, nur rechnungsdatum und OHNE review_of_aging_list $form->{todate} = $form->current_date($myconfig) unless ($form->{todate}); $todate = conv_dateq($form->{todate}); $fromdate = conv_dateq($form->{fromdate}); @@ -1223,7 +1231,7 @@ sub aging { "duedate", invoice, ${arap}.id, date_part('days', now() - duedate) as overduedays, (SELECT $buysell FROM exchangerate - WHERE (${arap}.curr = exchangerate.curr) + WHERE (${arap}.currency_id = exchangerate.currency_id) AND (exchangerate.transdate = ${arap}.transdate)) AS exchangerate FROM ${arap}, ${ct} WHERE ((paid != amount) OR (datepaid > (date $todate) AND datepaid is not null)) @@ -1233,6 +1241,7 @@ sub aging { AND (${ct}.id = ?) AND (transdate <= (date $todate) $fromwhere ) $review_of_aging_list + $duedate_where ORDER BY ctid, transdate, invnumber |; my $sth_details = prepare_query($form, $dbh, $q_details);