Оплатить счет (оплаченный полностью) в NetSuite с помощью RESTlet - PullRequest
0 голосов
/ 03 августа 2020

Я пытаюсь оплатить открытый счет в NetSuite. Моя цель - оплатить счет и вернуть ему статус «Оплачено полностью».

Я могу довольно легко создать запись о платеже клиента, используя приведенный ниже код, но, похоже, я не могу для присвоения платежа фактическому счету-фактуре. Когда я выполняю платеж вручную (см. Изображение), отображается список открытых счетов-фактур, и пользователь делает выбор.

enter image description here

In SuiteScript, I have mimicked this and created a recordset of Open Invoices for that customer. The recordset is traversed and checked for a matching Invoice ID. If at matching Invoice id is found I'm updating these fields, both found in the применить подсписок

record.setLineItemValue('apply', 'amount', r, '1.03');
record.setLineItemValue('apply', 'apply', r, 'T');

Однако это дает мне следующую ошибку: «Вы попытались выполнить недопустимую операцию с подсписком или строкой. Вы либо пытаетесь получить доступ к полю в несуществующей строке, либо пытаетесь добавить или удалить строки из stati c подсписок ".

function postRESTlet(dataIn) {


    var record = null;
    var err = new Object();
    var rectype = "customerpayment";
    var id = 5915556;

    try{
        record = nlapiCreateRecord(rectype); 

        record.setFieldValue('currency', 1); // GBP
        record.setFieldValue('customer', 40562);
        record.setFieldValue('customform', 118);
        record.setFieldValue('exchangerate', '1.00');
        record.setFieldValue('payment', '1.03');
        record.setFieldValue('paymentmethod', 8);
        record.setFieldValue('account', 154);    

        var records = nlapiSearchRecord('invoice', null, [
            new nlobjSearchFilter('status', null, 'is', 'CustInvc:A'), // Open Invoices
            new nlobjSearchFilter('entity', null, 'is', 40562), // Entity
            new nlobjSearchFilter('mainline', null, 'is', 'T') // Mainline True
        ], [
            new nlobjSearchColumn('internalid').setSort(false)
        ]);


    if (!records){
        nlapiLogExecution('DEBUG', '0 Records Found');
        return 'no records found';
    };

    // Loop all Open Invoices for this entity
    for (var r=0; r<records.length; r++) {

        // Check for match
        if(id == records[r].getId()) {

            // Update sublist
            //record.setLineItemValue('apply', 'amount', r, '1.03');
            //record.setLineItemValue('apply', 'apply', r, 'T');

        }

    }

    var recordId = nlapiSubmitRecord(record,false,true);
    var nlobj = nlapiLoadRecord(rectype,recordId);

    return nlobj;

} catch(err){
    var message = (!!err.message)?err.message:"An unexpected error ocurred";
    message +=  (!!dataIn.id)?("Record ID is: " + dataIn.id):"No ID supplied" + err.message;
    return message;
}

}

Кто-нибудь знает, какие шаги мне нужно выполнить, чтобы назначить платеж на один счет-фактуру.

Заранее спасибо :)

ОБНОВЛЕННЫЙ РАБОЧИЙ РЕСТЛЕТ (на случай, если он кому-то поможет):

    function postRESTlet(dataIn) {

    var id = dataIn[0]['sid'];
    var entity = dataIn[0]['entity'];
    var amount = dataIn[0]['amount'];
    var paymethod = dataIn[0]['paymethod'];
    var payaccount = dataIn[0]['payaccount'];

    var record = null;
    var err = new Object();
    var rectype = "customerpayment";
    var paymentapplied = 0;

    try {

        var records = nlapiSearchRecord('invoice', null, [
            new nlobjSearchFilter('status', null, 'is', 'CustInvc:A'), // Open Invoices
            new nlobjSearchFilter('entity', null, 'is', entity), // Entity
            new nlobjSearchFilter('mainline', null, 'is', 'T') // Mainline True
        ], [
            new nlobjSearchColumn('internalid').setSort(false)
        ]);


    if (!records){
        nlapiLogExecution('DEBUG', 'No Records Found');
        return 'no records found';
    };

    // Loop all Open Invoices for this entity
    for(var r=0; r<records.length; r++ ) {

            if(records[r].getId() == id) { // The Invoice id matches

                // Transform below does not appear documented; but works as expected
                var deposit = nlapiTransformRecord('invoice', records[r].getId(), 'customerpayment');

                deposit.setFieldValue('trandate', nlapiDateToString(new Date()));
                deposit.setFieldValue('currency', 1); // GBP
                deposit.setFieldValue('customer', entity);
                deposit.setFieldValue('customform', 118);
                deposit.setFieldValue('exchangerate', '1.00');
                deposit.setFieldValue('payment', amount);
                deposit.setFieldValue('paymentmethod', paymethod);
                deposit.setFieldValue('account', payaccount);

                // Walk the invoice list that we want to apply; find the invoice we are working on
                var a = deposit.getLineItemCount('apply');

                for(var i = 1; i <= a; i++) {

                    if(deposit.getLineItemValue('apply', 'internalid', i) == id ) {
                        nlapiLogExecution('DEBUG', 'working on invoice line:' + i, deposit.getLineItemValue('apply', 'refnum', i));
                        deposit.setLineItemValue('apply', 'amount', i, deposit.getLineItemValue('apply', 'total', i));
                        deposit.setLineItemValue('apply', 'apply', i, 'T');
                    };
                };

                paymentapplied = 1;
                nlapiSubmitRecord(deposit);
                return 'Payment Completed';
            }

        };

        if(paymentapplied == 0)
        return 'No Payment made.  Is the Invoice already Paid?';

} catch(err){
    var message = (!!err.message)?err.message:"An unexpected error ocurred";
    return message;
}

}

1 Ответ

1 голос
/ 03 августа 2020

Используйте преобразование записи вместо создания, чтобы преобразовать счет-фактуру в платеж клиента. См. Справочную документацию для nlapiTransformRecord().

...