X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;ds=sidebyside;f=SL%2FCA.pm;h=3df961307335598e56940ecd859d08b297797428;hb=a5501b166388f169f232af20d911d79528f2f5c5;hp=56036e7dea918251dbba8fd835cb5203e7cffff9;hpb=717d4a1334d916fc77ba09bc17e5999ada617b21;p=kivitendo-erp.git diff --git a/SL/CA.pm b/SL/CA.pm index 56036e7de..3df961307 100644 --- a/SL/CA.pm +++ b/SL/CA.pm @@ -41,7 +41,7 @@ use SL::DBUtils; sub all_accounts { $main::lxdebug->enter_sub(); - my ($self, $myconfig, $form) = @_; + my ($self, $myconfig, $form, $chart_id) = @_; my %amount; @@ -61,26 +61,45 @@ sub all_accounts { } $sth->finish; - $query = - qq!SELECT c.accno, c.id, c.description, c.charttype, c.category, ! . - qq! c.link, c.pos_bwa, c.pos_bilanz, c.pos_eur, c.valid_from, ! . - qq! c.datevautomatik, comma(tk.startdate) AS startdate, ! . - qq! comma(tk.taxkey_id) AS taxkey, ! . - qq! comma(tx.taxdescription || to_char (tx.rate, '99V99' ) || '%') ! . - qq! AS taxdescription, ! . - qq! comma(tx.taxnumber) AS taxaccount, comma(tk.pos_ustva) ! . - qq! AS tk_ustva, ! . - qq! ( SELECT accno FROM chart c2 WHERE c2.id = c.id ) AS new_account ! . - qq!FROM chart c ! . - qq!LEFT JOIN taxkeys tk ON (c.id = tk.chart_id) ! . - qq!LEFT JOIN tax tx ON (tk.tax_id = tx.id) ! . - qq!GROUP BY c.accno, c.id, c.description, c.charttype, ! . - qq! c.category, c.link, c.pos_bwa, c.pos_bilanz, c.pos_eur, ! . - qq! c.valid_from, c.datevautomatik ! . - qq!ORDER BY c.accno!; + my $where = "AND c.id = $chart_id" if ($chart_id ne ''); + + $query = qq{ + SELECT + c.accno, + c.id, + c.description, + c.charttype, + c.category, + c.link, + c.pos_bwa, + c.pos_bilanz, + c.pos_eur, + c.valid_from, + c.datevautomatik, + comma(tk.startdate) AS startdate, + comma(tk.taxkey_id) AS taxkey, + comma(tx.taxdescription || to_char (tx.rate, '99V99' ) || '%') AS taxdescription, + comma(tx.taxnumber) AS taxaccount, + comma(tk.pos_ustva) AS tk_ustva, + ( SELECT accno + FROM chart c2 + WHERE c2.id = c.id + ) AS new_account + FROM chart c + LEFT JOIN taxkeys tk ON (c.id = tk.chart_id) + LEFT JOIN tax tx ON (tk.tax_id = tx.id) + WHERE 1=1 + $where + GROUP BY c.accno, c.id, c.description, c.charttype, c.gifi_accno, + c.category, c.link, c.pos_bwa, c.pos_bilanz, c.pos_eur, c.valid_from, + c.datevautomatik + ORDER BY c.accno + }; + my $sth = prepare_execute_query($form, $dbh, $query); $form->{CA} = []; + while (my $ca = $sth->fetchrow_hashref(NAME_lc)) { $ca->{amount} = $amount{ $ca->{accno} }; if ($ca->{amount} < 0) { @@ -228,7 +247,7 @@ sub all_transactions { @values = (); foreach my $id (@id) { - + # NOTE: Postgres is really picky about the order of implicit CROSS # JOINs with ',' if you alias the tables and want to use the # alias later in another JOIN. the alias you want to use has to @@ -247,7 +266,6 @@ sub all_transactions { $dpt_join . qq|WHERE | . $where . $dpt_where . $project . qq| AND ac.chart_id = ? | . - qq| AND ac.trans_id = a.id | . qq|UNION | . @@ -256,9 +274,9 @@ sub all_transactions { qq|FROM acc_trans ac, customer c, ar a | . $dpt_join . qq|WHERE | . $where . $dpt_where . $project . - qq| AND ac.chart_id = ? | . - qq| AND ac.trans_id = a.id | . - qq| AND a.customer_id = c.id | . + qq| AND ac.chart_id = ? | . + qq| AND NOT a.storno | . + qq| AND a.customer_id = c.id | . qq|UNION | . @@ -267,9 +285,9 @@ sub all_transactions { qq|FROM acc_trans ac, vendor v, ap a | . $dpt_join . qq|WHERE | . $where . $dpt_where . $project . - qq| AND ac.chart_id = ? | . - qq| AND ac.trans_id = a.id | . - qq| AND a.vendor_id = v.id |; + qq| AND ac.chart_id = ? | . + qq| AND NOT a.storno | . + qq| AND a.vendor_id = v.id |; push(@values, @where_values, @department_values, @project_values, $id, @@ -326,7 +344,7 @@ sub all_transactions { $union = qq|UNION ALL|; } - $query .= qq|ORDER BY | . $sortorder; + $query .= qq|ORDER BY | . $form->{sort}; $sth = prepare_execute_query($form, $dbh, $query, @values); $form->{CA} = [];