简体   繁体   English

Netsuite Suitescript 2-客户在搜索中的存款余额

[英]Netsuite Suitescript 2 - Customer Deposit remaining amount in Search

I'm facing a problem while performing a custom search on customer deposits in NetSuite using SuiteScript 2.0 使用SuiteScript 2.0对NetSuite中的客户存款执行自定义搜索时遇到问题

I need to fetch all the customer deposits ids, statuses, the amount deposited and the amount remaining (I mean the amount that has not been applied to any invoice). 我需要获取所有客户的存款ID,状态,存款金额和剩余金额(我的意思是尚未应用于任何发票的金额)。 My problem is that I can't figure out how to grab the amount remaining. 我的问题是我不知道如何获取剩余的金额。

I have tried this: 我已经试过了:

var results = [];

search.create({           
    type: search.Type.CUSTOMER_DEPOSIT,
    filters: [['lastmodifieddate', 'within', context.from_datetime, context.to_datetime]],
    columns: [
        'entity',
        'status',
        'amount',
        'amountremaining'
    ]
}).run().forEach(function() {
    results.push(result);
    return true;
});

return results;

But amountremaining field comes empty for all the deposits. 但是所有存款的amountremaining字段为空。

The amountremaining column isn't related to Customer Deposits, but you can achieve what you need by using the following approach. amountremaining栏与客户存款无关,但是您可以使用以下方法来实现所需的目的。

First you need to add a filter to ensure you pull the correct 'applying transactions': 首先,您需要添加一个过滤器,以确保提取正确的“正在应用的交易”:

["applyingtransaction.type","anyof","DepAppl"]

This makes sure you get 'Deposit Applications' but not 'Deposits' which may be applying transactions of the Customer Deposit. 这样可以确保您获得的是“存款申请”,而不是“存款”,这可能是正在应用客户存款的交易。 Then you need to add a column with a formula to add the amounts from all those Deposit Applications to the total amount of the Customer Deposit: 然后,您需要添加一个带有公式的列,以将所有这些存款申请中的金额添加到客户存款的总额中:

search.createColumn({
     name: "formulacurrency",
     summary: "MIN",
     formula: "min({amount}) + SUM({applyingtransaction.amount})",
     label: "Formula (Currency)"
  })

Note that this is added rather than subtracted, because the applyingtransaction.amount is returned as a negative. 请注意,这是相加而不是相减,因为applyingtransaction.amount返回为负数。

Also not that this requires a summary column in order to work (as there may be more than one applying transaction per customer deposit), therefore you will need to apply a grouping or summary function to all the columns you need to return. 同样不是因为这需要一个摘要列才能起作用(因为每个客户存款可能有多个应用交易),因此您将需要对需要返回的所有列应用分组或摘要功能。 Most importantly, you need to GROUP by the customer deposit internal id or document number. 最重要的是,您需要按客户分组的GROUP ID来存储内部ID或文件编号。

Using the applyingtransaction field joined, I managed to get what I wanted with this code: 通过使用applyingtransaction字段,我设法通过以下代码获得了想要的结果:

var results = [];

search.create({           
    type: search.Type.CUSTOMER_DEPOSIT,
    filters: [['lastmodifieddate', 'within', context.from_datetime, context.to_datetime]],
    columns: [
        'entity',
        'status',
        'amount',
        search.createColumn({
            name: "total",
            join: "applyingtransaction"
        })
    ]
}).run().forEach(function(result) {

    var appliedValue = parseFloat(result.getValue({ name: 'total', join: 'applyingtransaction' }));

    if (result.id in results) {
        results[result.id].remaining_credit += appliedValue;
    } else {
        var total = parseFloat(result.getValue('total'));

        results[result.id] = {
            remaining_credit: parseFloat(total + appliedValue),
        }
    }
});

return results;

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

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