- my $query =
- 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
- 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
- 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
- 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 transdate, trans_id, acoid, taxkey DESC|;
+ $query =
+ qq|SELECT
+ ac.acc_trans_id, g.id, 'gl' AS type, FALSE AS invoice, g.reference, ac.taxkey, c.link,
+ g.description, ac.transdate, ac.gldate, ac.source, ac.trans_id,
+ ac.amount, c.accno, g.notes, t.chart_id,
+ d.description AS department, g.transaction_description,
+ CASE WHEN (COALESCE(e.name, '') = '') THEN e.login ELSE e.name END AS employee
+ $project_columns $gl_globalproject_columns
+ $columns_for_sorting{gl}
+ FROM gl g
+ LEFT JOIN employee e ON (g.employee_id = e.id)
+ LEFT JOIN department d ON (g.department_id = d.id),
+ 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.acc_trans_id, a.id, 'ar' AS type, a.invoice, a.invnumber, ac.taxkey, c.link,
+ ct.name, ac.transdate, ac.gldate, ac.source, ac.trans_id,
+ ac.amount, c.accno, a.notes, t.chart_id,
+ d.description AS department, a.transaction_description,
+ CASE WHEN (COALESCE(e.name, '') = '') THEN e.login ELSE e.name END AS employee
+ $project_columns $arap_globalproject_columns
+ $columns_for_sorting{arap}
+ FROM ar a
+ LEFT JOIN employee e ON (a.employee_id = e.id)
+ LEFT JOIN department d ON (a.department_id = d.id)
+ $arap_globalproject_join,
+ 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.acc_trans_id, a.id, 'ap' AS type, a.invoice, a.invnumber, ac.taxkey, c.link,
+ ct.name, ac.transdate, ac.gldate, ac.source, ac.trans_id,
+ ac.amount, c.accno, a.notes, t.chart_id,
+ d.description AS department, a.transaction_description,
+ CASE WHEN (COALESCE(e.name, '') = '') THEN e.login ELSE e.name END AS employee
+ $project_columns $arap_globalproject_columns
+ $columns_for_sorting{arap}
+ FROM ap a
+ LEFT JOIN employee e ON (a.employee_id = e.id)
+ LEFT JOIN department d ON (a.department_id = d.id)
+ $arap_globalproject_join,
+ 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, acc_trans_id $sortdir|;
+# ORDER BY gldate DESC, id DESC, acc_trans_id DESC
+
+ my @values = (@glvalues, @arvalues, @apvalues);