On 12/18/11 14:41, [email protected] wrote:
Hi,

I just updated to the latest ledger123 by doing a git pull. Before the update I was able to do reports->Taxes. Under period I select a date of Nov 2011,
select month and detail and it worked.

After the update when I do the above I get the following errors:

DBD::Pg::st execute failed: ERROR: column reference "discount" is ambiguous
Error!

SELECT a.id, '0' AS invoice, a.datepaid AS transdate,
a.invnumber, n.name, n.customernumber,
ac.amount * 1 AS netamount,
ac.memo AS description,
a.till, n.id AS vc_id
FROM acc_trans ac
JOIN ar a ON (a.id = ac.trans_id)
JOIN customer n ON (n.id = a.customer_id)
JOIN chart ch ON (ch.id = ac.chart_id)
WHERE a.approved = '1' AND a.transdate >= '20111101' AND a.transdate <= '20111130'
AND a.invoice = '0'
AND a.netamount = a.amount
AND NOT (ch.link LIKE '%_paid' OR ch.link = 'AR')

AND ac.trans_id IN
(
SELECT trans_id
FROM acc_trans
JOIN chart ON (chart_id = chart.id)
WHERE link LIKE '%AR_paid%'
AND a.approved = '1'
AND a.datepaid <= '20111130'
AND a.paid = a.amount
)

GROUP BY a.id, a.datepaid, a.invnumber, n.name, ac.amount,
ac.memo, a.till, n.id, n.customernumber

UNION ALL

SELECT a.id, '1' AS invoice, a.datepaid AS transdate,
a.invnumber, n.name, n.customernumber,
sum(ac.sellprice * ac.qty * (1 - ac.discount)) * 1 AS netamount,
ac.description,
a.till, n.id AS vc_id
FROM invoice ac
JOIN ar a ON (a.id = ac.trans_id)
JOIN customer n ON (n.id = a.customer_id)
WHERE a.approved = '1' AND a.transdate >= '20111101' AND a.transdate <= '20111130'
AND a.invoice = '1'
AND (
a.customer_id NOT IN (
SELECT customer_id FROM customertax t (customer_id)
) OR
ac.parts_id NOT IN (
SELECT parts_id FROM partstax p (parts_id)
)
)

AND ac.trans_id IN
(
SELECT trans_id
FROM acc_trans
JOIN chart ON (chart_id = chart.id)
WHERE link LIKE '%AR_paid%'
AND a.approved = '1'
AND a.datepaid <= '20111130'
AND a.paid = a.amount
)

GROUP BY a.id, a.invnumber, a.datepaid, n.name,
ac.description, a.till, n.id, n.customernumber

UNION

SELECT a.id, '0' AS invoice, a.datepaid AS transdate,
a.invnumber, n.name, n.customernumber, a.netamount,
ac.memo AS description,
a.till, n.id AS vc_id
FROM acc_trans ac
JOIN ar a ON (a.id = ac.trans_id)
JOIN customer n ON (n.id = a.customer_id)
JOIN chart ch ON (ch.id = ac.chart_id)
WHERE a.datepaid >= '20111101'
AND a.invoice = '0'
AND a.netamount = a.amount
AND NOT (ch.link LIKE '%_paid' OR ch.link = 'AR')

AND ac.trans_id IN
(
SELECT trans_id
FROM acc_trans
JOIN chart ON (chart_id = chart.id)
WHERE link LIKE '%AR_paid%'
AND a.approved = '1'
AND a.datepaid <= '20111130'
AND a.paid = a.amount
)

GROUP BY a.id, a.datepaid, a.invnumber, n.name, a.netamount,
ac.memo, a.till, n.id, n.customernumber

UNION

SELECT a.id, '1' AS invoice, a.datepaid AS transdate,
a.invnumber, n.name, n.customernumber,
sum(ac.sellprice * ac.qty * (1 - discount)) * 1 AS netamount,
ac.description,
a.till, n.id AS vc_id
FROM invoice ac
JOIN ar a ON (a.id = ac.trans_id)
JOIN customer n ON (n.id = a.customer_id)
WHERE a.datepaid >= '20111101'
AND a.invoice = '1'
AND (
a.customer_id NOT IN (
SELECT customer_id FROM customertax t (customer_id)
) OR
ac.parts_id NOT IN (
SELECT parts_id FROM partstax p (parts_id)
)
)

AND ac.trans_id IN
(
SELECT trans_id
FROM acc_trans
JOIN chart ON (chart_id = chart.id)
WHERE link LIKE '%AR_paid%'
AND a.approved = '1'
AND a.datepaid <= '20111130'
AND a.paid = a.amount
)

GROUP BY a.id, a.invnumber, a.datepaid, n.name,
ac.description, a.till, n.id, n.customernumber

ORDER by 3 ASC,4,5
ERROR: column reference "discount" is ambiguous


If I switch to the editorderinvoices branch the same report works as expected.

Can someone tell me if this is a bug in the program or something is wrong with
my db?

Am I correct that the editorderinvoices branch and the master branch are the same except for ability to edit order invoices in the editorderinvoices branch?

Regards,


About Line 96:

sum(ac.sellprice * ac.qty * (1 - discount)) * 1 AS netamount,
                                                           ^
                                                           |

I'll bet this needs to be 'ac.discount'

But I'm not a DB whizkid.

r
_______________________________________________
SQL-Ledger mailing list
[email protected]
http://lists.ledger123.com/mailman/listinfo/sql-ledger

Reply via email to