- qq|SELECT g.id, 'gl' AS type, $false AS invoice, g.reference, ac.taxkey, t.taxkey AS sorttax,
- g.description, ac.transdate, ac.source, ac.trans_id,
- ac.amount, c.accno, c.gifi_accno, g.notes, t.chart_id, ac.oid
- FROM gl g, acc_trans ac, chart c LEFT JOIN tax t ON
- (t.chart_id=c.id)
- WHERE $glwhere
- AND ac.chart_id = c.id
- AND g.id = ac.trans_id
- UNION
- SELECT a.id, 'ar' AS type, a.invoice, a.invnumber, ac.taxkey, t.taxkey AS sorttax,
- ct.name, ac.transdate, ac.source, ac.trans_id,
- ac.amount, c.accno, c.gifi_accno, a.notes, t.chart_id, ac.oid
- FROM ar a, acc_trans ac, customer ct, chart c LEFT JOIN tax t ON
- (t.chart_id=c.id)
- WHERE $arwhere
- AND ac.chart_id = c.id
- AND a.customer_id = ct.id
- AND a.id = ac.trans_id
- UNION
- SELECT a.id, 'ap' AS type, a.invoice, a.invnumber, ac.taxkey, t.taxkey AS sorttax,
- ct.name, ac.transdate, ac.source, ac.trans_id,
- ac.amount, c.accno, c.gifi_accno, a.notes, t.chart_id, ac.oid
- FROM ap a, acc_trans ac, vendor ct, chart c LEFT JOIN tax t ON
- (t.chart_id=c.id)
- WHERE $apwhere
- AND ac.chart_id = c.id
- AND a.vendor_id = ct.id
- AND a.id = ac.trans_id
- ORDER BY transdate, trans_id, taxkey DESC, sorttax DESC, oid|;
- my $sth = $dbh->prepare($query);
- $sth->execute || $form->dberror($query);
-
- while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
- print(STDERR $ref->{id}, " Transaction\n");
-
- # gl
- if ($ref->{type} eq "gl") {
- $ref->{module} = "gl";
- }
+ qq|SELECT
+ ac.oid AS acoid, g.id, 'gl' AS type, $false AS invoice, g.reference, ac.taxkey, c.link,
+ g.description, ac.transdate, ac.source, ac.trans_id,
+ ac.amount, c.accno, g.notes, t.chart_id, ac.oid
+ $project_columns
+ $columns_for_sorting{gl}
+ FROM gl g, acc_trans ac $project_join, chart c
+ LEFT JOIN tax t ON (t.chart_id = c.id)
+ WHERE $glwhere
+ AND (ac.chart_id = c.id)
+ AND (g.id = ac.trans_id)
+
+ UNION
+
+ SELECT ac.oid AS acoid, a.id, 'ar' AS type, a.invoice, a.invnumber, ac.taxkey, c.link,
+ ct.name, ac.transdate, ac.source, ac.trans_id,
+ ac.amount, c.accno, a.notes, t.chart_id, ac.oid
+ $project_columns
+ $columns_for_sorting{arap}
+ FROM ar a, acc_trans ac $project_join, customer ct, chart c
+ LEFT JOIN tax t ON (t.chart_id=c.id)
+ WHERE $arwhere
+ AND (ac.chart_id = c.id)
+ AND (a.customer_id = ct.id)
+ AND (a.id = ac.trans_id)
+
+ UNION
+
+ SELECT ac.oid AS acoid, a.id, 'ap' AS type, a.invoice, a.invnumber, ac.taxkey, c.link,
+ ct.name, ac.transdate, ac.source, ac.trans_id,
+ ac.amount, c.accno, a.notes, t.chart_id, ac.oid
+ $project_columns
+ $columns_for_sorting{arap}
+ FROM ap a, acc_trans ac $project_join, vendor ct, chart c
+ LEFT JOIN tax t ON (t.chart_id=c.id)
+ WHERE $apwhere
+ AND (ac.chart_id = c.id)
+ AND (a.vendor_id = ct.id)
+ AND (a.id = ac.trans_id)
+
+ ORDER BY $sortorder, acoid $sortdir|;
+
+ my @values = (@glvalues, @arvalues, @apvalues);
+
+ # Show all $query in Debuglevel LXDebug::QUERY
+ $callingdetails = (caller (0))[3];
+ dump_query(LXDebug::QUERY, "$callingdetails", $query, @values);
+
+ $sth = prepare_execute_query($form, $dbh, $query, @values);
+ my $trans_id = "";
+ my $trans_id2 = "";
+
+ my ($i, $j, $k, $l, $ref, $ref2);
+
+ $form->{GL} = [];
+ while (my $ref0 = $sth->fetchrow_hashref(NAME_lc)) {
+
+ $trans_id = $ref0->{id};
+
+ if ($trans_id != $trans_id2) { # first line of a booking
+
+ if ($trans_id2) {
+ push(@{ $form->{GL} }, $ref);
+ $balance = 0;
+ }
+
+ $ref = $ref0;
+ $trans_id2 = $ref->{id};