Hey ! If a payment transaction is related to more ...
# suiteql
j
Hey ! If a payment transaction is related to more than one invoice, how can I retrieve the corresponding split of the payment between the invoices ? (I am able to match a payment with its related invoices but all I only have the total of the payment in the
transaction
table) Here is how I currently retrieve the invoices for which a given payment has been made
Copy code
SELECT 
  pt.id AS invoice_id,
FROM 
  transaction t
  JOIN previoustransactionlink ptl ON ptl.nextdoc = t.id
  JOIN transaction pt ON ptl.previousdoc = pt.id
WHERE
  pt.type = 'CustInvc'
  AND t.id = "payment_id"
Thanks for your help !
e
The payment amount is in the
transactionline
table
m
Copy code
SELECT
  ptll.previousdoc AS applied_to_transaction,
  ptll.foreignamount AS amount_applied
FROM
  transaction t
  JOIN transactionline tl ON t.id = tl.transaction
  JOIN previoustransactionlinelink ptll ON (
    tl.transaction = ptll.nextdoc
    AND tl.id = ptll.nextline
    AND ptll.linktype = 'Payment'
  )
WHERE
  t.id = ?
j
Thanks ! 🙏