+ my $fromto = shift;
+
+ my $myconfig = \%main::myconfig;
+ my $form = $main::form;
+
+ my $dbh = $form->get_standard_dbh($myconfig);
+
+ my ($notsplitindex);
+ my @errors = ();
+
+ $form->{net_gross_differences} = [];
+ $form->{sum_net_gross_differences} = 0;
+
+ $fromto =~ s/transdate/ac\.transdate/g;
+
+ my $taxkeys = Taxkeys->new();
+ my $filter = ''; # Useful for debugging purposes
+
+ my %all_taxchart_ids = selectall_as_map($form, $dbh, qq|SELECT DISTINCT chart_id, TRUE AS is_set FROM tax|, 'chart_id', 'is_set');
+
+ my $query =
+ qq|SELECT ac.acc_trans_id, 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, c.link,
+ ar.invoice
+ FROM acc_trans ac
+ LEFT JOIN ar ON (ac.trans_id = ar.id)
+ LEFT JOIN customer ct ON (ar.customer_id = ct.id)
+ LEFT JOIN chart c ON (ac.chart_id = c.id)
+ WHERE (ar.id IS NOT NULL)
+ AND $fromto
+ $filter
+
+ UNION ALL
+
+ SELECT ac.acc_trans_id, 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, c.link,
+ ap.invoice
+ FROM acc_trans ac
+ LEFT JOIN ap ON (ac.trans_id = ap.id)
+ LEFT JOIN vendor ct ON (ap.vendor_id = ct.id)
+ LEFT JOIN chart c ON (ac.chart_id = c.id)
+ WHERE (ap.id IS NOT NULL)
+ AND $fromto
+ $filter
+
+ UNION ALL
+
+ SELECT ac.acc_trans_id, 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, c.link,
+ FALSE AS invoice
+ FROM acc_trans ac
+ LEFT JOIN gl ON (ac.trans_id = gl.id)
+ LEFT JOIN chart c ON (ac.chart_id = c.id)
+ WHERE (gl.id IS NOT NULL)
+ AND $fromto
+ $filter
+
+ ORDER BY trans_id, acc_trans_id|;
+
+ my $sth = prepare_execute_query($form, $dbh, $query);
+
+ my $counter = 0;
+ while (my $ref = $sth->fetchrow_hashref("NAME_lc")) {
+ $counter++;
+ if (($counter % 500) == 0) {
+ print("$counter ");
+ }