简体   繁体   English

如何在 h SuiteQL 中收集发票、相关付款以及这些付款的“applied_to”子记录

[英]How to gather an Invoice, related payments, and the "applied_to" subrecords for those payments in h SuiteQL

I'm having a heck of a time with this.我在这上面玩得很开心。 Because SuiteQL uses Analytics Browser schema, it doesn't match up to a lot of NetSuite information out there, which is often in context of the direct ODBC schema.因为 SuiteQL 使用 Analytics Browser 模式,所以它与那里的很多 NetSuite 信息不匹配,这些信息通常在直接 ODBC 模式的上下文中。

Via REST I am trying to collect Sales Orders, Purchase Orders, and Invoices to display in Salesforce for a given Opportunity in Salesforce. I am able to retrieve the IDs via a SuiteQL query and can then use their respective end points to get the details (eg /services/rest/record/v1/salesorder/2374577 where 2374577 is the Sales Order ID).通过 REST 我正在尝试收集销售订单、采购订单和发票以在 Salesforce 中显示给定机会 Salesforce。我能够通过 SuiteQL 查询检索 ID,然后可以使用它们各自的端点来获取详细信息(例如 /services/rest/record/v1/salesorder/2374577,其中 2374577 是销售订单 ID)。

My problem is with payments - I can get the ones related to an invoice just fine, but the "total amount" on the payment may not have fully been applied to that one invoice, it may have been spread across invoices.. So I need to get the "amount applied to this invoice".我的问题是付款 - 我可以得到与发票相关的那些,但是付款的“总金额”可能没有完全应用于那张发票,它可能已经分布在发票上..所以我需要获取“应用于此发票的金额”。

I am currently using this SuiteQL query but it doesn't give me the breakdown per invoice I need:我目前正在使用此 SuiteQL 查询,但它没有提供我需要的每张发票的明细:

SELECT *, NT.TranDate, NT.TranID, REPLACE( BUILTIN.DF( NT.Status ), BUILTIN.DF( NT.Type ) || \': \' ) AS Status, NT.ForeignTotal, NT.exchangerate FROM NextTransactionLineLink AS NTLL INNER JOIN Transaction AS NT ON ( NT.ID = NTLL.NextDoc ) WHERE ( NTLL.PreviousDoc = \'2373356\' ) AND NT.Type = \'CustPymt\' ORDER BY NT.TranDate ASC

It seems like this is an ODBC approach (below) to getting that information but the "transaction_links" table/view doesn't seem to be available in SuiteQL.. So I'm not sure where to turn to at this point.似乎这是一种获取该信息的 ODBC 方法(如下),但“transaction_links”表/视图在 SuiteQL 中似乎不可用。所以我不确定此时该转向何处。

"t1".TRANSACTION_ID , t1."TRANSACTION_NUMBER", t1."TRANSACTION_TYPE"
,ln1.amount Invoice_Amount
,xref."AMOUNT_LINKED" Applied_Amount, xref."APPLIED_TRANSACTION_ID", xref."ORIGINAL_TRANSACTION_ID", xref."APPLIED_DATE_POSTED"
, t2."TRANSACTION_ID" t2_tranid, t2."TRANSACTION_NUMBER" t2_trannbr, t2."TRANSACTION_TYPE" t2_trantype
,ln2.amount Payment_Amount

from
"ns_transactions_raw" t1
join "ns_transaction_lines_raw" ln1
on t1."TRANSACTION_ID" = ln1."TRANSACTION_ID"
join
"ns_transaction_links_raw" xref
on t1."TRANSACTION_ID" = xref."ORIGINAL_TRANSACTION_ID"
and ln1."TRANSACTION_LINE_ID" = xref."ORIGINAL_TRANSACTION_LINE_ID"
join "ns_transactions_raw" "t2"
on "t2"."TRANSACTION_ID" = "xref"."APPLIED_TRANSACTION_ID"
join "ns_transaction_lines_raw" ln2
on ln2."TRANSACTION_ID" = "xref"."APPLIED_TRANSACTION_ID"
and ln2."TRANSACTION_LINE_ID" = "xref"."APPLIED_TRANSACTION_LINE_ID"
where t1."TRANSACTION_TYPE" = 'Invoice'
and t2."TRANSACTION_NUMBER" = 'PMT028551'

I was able to get this working via the NextTransactionLineLink table.我能够通过 NextTransactionLineLink 表使它正常工作。 This is my SuiteQL query, where objectId is the id of the invoice I want to get payments for.这是我的 SuiteQL 查询,其中objectId是我要为其付款的发票的 ID。 This works for all kinds of cash transactions, too, such as deposit applications, credit memos, etc:这也适用于各种现金交易,例如存款申请、贷项通知单等:

SELECT NT.ID, NT.TranDate, NT.TranID, REPLACE( BUILTIN.DF( NT.Status ), BUILTIN.DF( NT.Type ) || \': \' ) AS Status, NT.ForeignTotal, NT.exchangerate, NTLL.ForeignAmount FROM NextTransactionLineLink AS NTLL INNER JOIN Transaction AS NT ON ( NT.ID = NTLL.NextDoc ) WHERE ( NTLL.PreviousDoc = objectId ) ORDER BY NT.TranDate ASC

The ForeignAmount field on the NextTransactionLineLink record is the value of the part of the payment that applies to this invoice. NextTransactionLineLink 记录上的 ForeignAmount 字段是适用于此发票的付款部分的值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM