From: Moritz Bunkus Date: Fri, 5 Sep 2008 10:23:19 +0000 (+0000) Subject: Kosmetik X-Git-Tag: release-2.6.0beta2~264 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=032e5fcd1c5d2d4c803f4d4af44392e8d93a7b54;p=kivitendo-erp.git Kosmetik --- diff --git a/SL/DATEV.pm b/SL/DATEV.pm index 8d1601a9a..fb11d580d 100644 --- a/SL/DATEV.pm +++ b/SL/DATEV.pm @@ -26,6 +26,8 @@ package DATEV; +use SL::DBUtils; + use Data::Dumper; sub get_datev_stamm { @@ -217,47 +219,61 @@ sub get_dates { sub get_transactions { $main::lxdebug->enter_sub(); - my ($myconfig, $form, $fromto) = @_; - - # connect to database - my $dbh = $form->dbconnect($myconfig); + my $dbh = $form->get_standard_dbh($myconfig); $fromto =~ s/transdate/ac\.transdate/g; - $query = qq|SELECT id, taxkey, rate FROM tax|; - $sth = $dbh->prepare($query); - $sth->execute || $form->dberror($query); + my %taxes = selectall_as_map($form, $dbh, qq|SELECT id, rate FROM tax|, 'id', 'rate'); + + my $query = + qq|SELECT ac.oid, ac.transdate, ac.trans_id,ar.id, ac.amount, ac.taxkey, + ar.invnumber, ar.duedate, ar.amount as umsatz, + ct.name, + c.accno, c.taxkey_id as charttax, c.datevautomatik, c.id, + t.chart_id, t.rate, t.id AS taxid, t.taxkey AS taxtaxkey + FROM acc_trans ac,ar ar, customer ct, chart c + LEFT JOIN tax t ON (t.chart_id = c.id) + WHERE $fromto + AND (ac.trans_id = ar.id) + AND (ac.trans_id = ar.id) + AND (ar.customer_id = ct.id) + AND (ac.chart_id = c.id) + + UNION ALL + + SELECT ac.oid, ac.transdate, ac.trans_id,ap.id, ac.amount, ac.taxkey, + ap.invnumber, ap.duedate, ap.amount as umsatz, + ct.name, + c.accno, c.taxkey_id as charttax, c.datevautomatik, c.id, + t.chart_id, t.rate, t.id AS taxid, t.taxkey AS taxtaxkey + FROM acc_trans ac, ap ap, vendor ct, chart c + LEFT JOIN tax t ON (t.chart_id = c.id) + WHERE $fromto + AND (ac.trans_id = ap.id) + AND (ap.vendor_id = ct.id) + AND (ac.chart_id = c.id) + + UNION ALL + + SELECT ac.oid, ac.transdate, ac.trans_id,gl.id, ac.amount, ac.taxkey, + gl.reference AS invnumber, gl.transdate AS duedate, ac.amount as umsatz, + gl.description AS name, + c.accno, c.taxkey_id as charttax, c.datevautomatik, c.id, + t.chart_id, t.rate, t.id AS taxid, t.taxkey AS taxtaxkey + FROM acc_trans ac, gl gl, chart c + LEFT JOIN tax t ON (t.chart_id = c.id) + WHERE $fromto + AND (ac.trans_id = gl.id) + AND (ac.chart_id = c.id) + + ORDER BY trans_id, oid|; + + my $sth = prepare_execute_query($form, $dbh, $query); - while (my $ref = $sth->fetchrow_hashref(NAME_lc)) { - $taxes{ $ref->{id} } = $ref->{rate}; - } - - $sth->finish(); - - $query = - qq|SELECT ac.oid, ac.transdate, ac.trans_id,ar.id, ac.amount, ac.taxkey, ar.invnumber, ar.duedate, ar.amount as umsatz, - ct.name, c.accno, c.taxkey_id as charttax, c.datevautomatik, c.id, t.chart_id, t.rate, t.id AS taxid, t.taxkey AS taxtaxkey FROM acc_trans ac,ar ar, customer ct, - chart c LEFT JOIN tax t ON - (t.chart_id=c.id)WHERE $fromto AND ac.trans_id=ar.id AND ac.trans_id=ar.id - AND ar.customer_id=ct.id AND ac.chart_id=c.id - UNION ALL - SELECT ac.oid, ac.transdate, ac.trans_id,ap.id, ac.amount, ac.taxkey, ap.invnumber, ap.duedate, ap.amount as umsatz, - ct.name, c.accno, c.taxkey_id as charttax, c.datevautomatik, c.id, t.chart_id, t.rate, t.id AS taxid, t.taxkey AS taxtaxkey FROM acc_trans ac, ap ap, vendor ct, chart c LEFT JOIN tax t ON - (t.chart_id=c.id) - WHERE $fromto AND ac.trans_id=ap.id AND ap.vendor_id=ct.id AND ac.chart_id=c.id - UNION ALL - SELECT ac.oid, ac.transdate, ac.trans_id,gl.id, ac.amount, ac.taxkey, gl.reference AS invnumber, gl.transdate AS duedate, ac.amount as umsatz, - gl.description AS name, c.accno, c.taxkey_id as charttax, c.datevautomatik, c.id, t.chart_id, t.rate, t.id AS taxid, t.taxkey AS taxtaxkey FROM acc_trans ac, gl gl, - chart c LEFT JOIN tax t ON - (t.chart_id=c.id) WHERE $fromto AND ac.trans_id=gl.id AND ac.chart_id=c.id - ORDER BY trans_id, oid|; - - $sth = $dbh->prepare($query); - $sth->execute || $form->dberror($query); $i = 0; $g = 0; my $counter = 0; - @splits; + my @splits; while (my $ref = $sth->fetchrow_hashref(NAME_lc)) { $count = 0; $firstrun = 1;