X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/3b3ef5ba0b9d0d6fb45e082cbfafa524243ae6f7..3d967be3d2f32e2b00f5f55769edcbf5be866ce6:/SL/AR.pm diff --git a/SL/AR.pm b/SL/AR.pm index 7357ae9d6..3364c864e 100644 --- a/SL/AR.pm +++ b/SL/AR.pm @@ -38,6 +38,8 @@ use Data::Dumper; use SL::DBUtils; use SL::MoreCommon; +use strict; + our (%myconfig, $form); sub post_transaction { @@ -252,7 +254,7 @@ sub post_transaction { $amount = $form->round_amount( $form->{"paid_$i"} * ($form->{exchangerate} - $form->{"exchangerate_$i"}) * -1, 2); if ($amount != 0) { - $accno = ($amount > 0) ? $form->{fxgain_accno} : $form->{fxloss_accno}; + my $accno = ($amount > 0) ? $form->{fxgain_accno} : $form->{fxloss_accno}; $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, fx_transaction, cleared, project_id, taxkey) VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, 't', 'f', ?, (SELECT taxkey_id FROM chart WHERE accno = ?))|; @values = (conv_i($form->{id}), $accno, $amount, conv_date($form->{"datepaid_$i"}), $project_id, $accno); @@ -407,12 +409,12 @@ sub ar_transactions { my ($self, $myconfig, $form) = @_; # connect to database - my $dbh = $form->dbconnect($myconfig); + my $dbh = $form->get_standard_dbh($myconfig); my @values; my $query = - qq|SELECT a.id, a.invnumber, a.ordnumber, a.transdate, | . + qq|SELECT DISTINCT a.id, a.invnumber, a.ordnumber, a.transdate, | . qq| a.duedate, a.netamount, a.amount, a.paid, | . qq| a.invoice, a.datepaid, a.terms, a.notes, a.shipvia, | . qq| a.shippingpoint, a.storno, a.storno_id, a.globalproject_id, | . @@ -423,7 +425,14 @@ sub ar_transactions { qq| e.name AS employee, | . qq| e2.name AS salesman, | . qq| tz.description AS taxzone, | . - qq| pt.description AS payment_terms | . + qq| pt.description AS payment_terms, | . + qq{ ( SELECT ch.accno || ' -- ' || ch.description + FROM acc_trans at + LEFT JOIN chart ch ON ch.id = at.chart_id + WHERE ch.link ~ 'AR[[:>:]]' + AND at.trans_id = a.id + LIMIT 1 + ) AS charts } . qq|FROM ar a | . qq|JOIN customer c ON (a.customer_id = c.id) | . qq|LEFT JOIN employee e ON (a.employee_id = e.id) | . @@ -485,17 +494,9 @@ sub ar_transactions { $query .= " WHERE $where ORDER BY $sortorder"; - my $sth = $dbh->prepare($query); - $sth->execute(@values) || - $form->dberror($query . " (" . join(", ", @values) . ")"); + my @result = selectall_hashref_query($form, $dbh, $query, @values); - $form->{AR} = []; - while (my $ar = $sth->fetchrow_hashref(NAME_lc)) { - push @{ $form->{AR} }, $ar; - } - - $sth->finish; - $dbh->disconnect; + $form->{AR} = [ @result ]; $main::lxdebug->leave_sub(); } @@ -525,7 +526,8 @@ sub setup_form { my ($self, $form) = @_; - my ($exchangerate, $key, $akey, $i, $j, $k, $index, $taxamount, $totaltax, $taxrate, $diff); + my ($exchangerate, $key, $akey, $i, $j, $k, $index, $taxamount, $totaltax, $taxrate, $diff, $totalwithholding, $withholdingrate, + $totalamount, $taxincluded, $tax); # forex $form->{forex} = $form->{exchangerate};