Can anyone help me with fetching credit amounts ap...
# suiteql
b
Can anyone help me with fetching credit amounts applied to open bills?
I have this query which pulls vendor credit records and total amount in that credit, linked to specific bills.
Copy code
select 
	billcredit.id billcreditid,
	billcredit.foreignTotal,
	vendbill.id billid
from 
	transaction billcredit
join
	PreviousTransactionLink link ON billcredit.id = link.nextdoc
join
	transaction vendbill ON vendbill.id=link.previousDoc
where
	vendbill.id in (160135,160236)
Now I need to get amounts applied to these bills, instead of total credit amount. I was trying
AppliedCreditTransactionLineLink
table but it seems it only provides data for fully paid bills. I need it for open and partially paid bills. TIA
m
b
This mostly provides rows for payment records, even when removing last
Payment
condition
This did the trick for me (this can be stripped to fewer fields and tables)
Copy code
SELECT 
	BillCredit.ID bill_credit_id,
	BillCredit.ForeignTotal bill_credit_total, 
	NTLL.ForeignAmount bill_credit_applied_to_bill,
	Bill.ID bill_id,
FROM 
	NextTransactionLineLink AS NTLL 
INNER JOIN Transaction AS BillCredit
	ON BillCredit.ID = NTLL.NextDoc
INNER JOIN Transaction AS Bill
	ON NTLL.PreviousDoc = Bill.ID
WHERE
	BillCredit.type = 'VendCred' AND
	NTLL.PreviousDoc in (160135,160236)