Untitled

mail@pastecode.io avatar
unknown
javascript
2 years ago
19 kB
3
Indexable
Never
function ok_clicked(linkclicked) {
    let totalPayment = geTotalPayment();

    if (totalPayment > 0) {
        $(".spinner").show();
        __doPostBack("btnNext1_544", JSON.stringify(listofpayments));
    }
    else {
        alert(get_message(0));        
        return;
    }
}

function epsResponse(code, msg, tranid) {
    $("#elementps").css('visibility', 'hidden'); //Task:[22297]
    $("#epsframe").attr('src', 'about:blank');
    $("#elementps").dialog("destroy");
     
    if (msg == "Duplicate") {
        __doPostBack('btnBack_103', '');
    }

    var gatewayType = $("#hdgatetype").val();

    if (tranid != "0") {
        if (code == 0 || code == 5 || (code == 100 && gatewayType == 5)) {
            $('#btnCharge_10019').attr('disabled', 'disabled').css('cursor', 'wait'); //disable charge button
            $('#btnCharge').attr('disabled', 'disabled').css('cursor', 'wait'); //disable charge button
            $('#btnBack_103').attr('disabled', 'disabled').css('cursor', 'wait'); //disable back button

            __doPostBack('btnCharge_10019', '');

        } else {
            alert(msg);
        }
    }
    else {
        alert("Something went wrong, please try again");
        __doPostBack('btnBack_103', '');
    }


}

function chargeCard() {
    var accid = $("#hdaccid").val();
    var amt = $("#amount").val();
    var url = $("#hdreturnurl").val();
    var gatewaytypeid = $("#hdgatetype").val();
    var optionSelected = 0;
    
    if (!validatePayment()) {
        return false;
    }
    
    if ($("#rbDifferent3161")[0].checked && (gatewaytypeid == 2 || gatewaytypeid == 3 || gatewaytypeid == 5)) {

        optionSelected = 1;
        $("#elementps").css('visibility', 'visible');
        $("#epsframe").attr('src', 'epspayaddress.aspx?accid=' + accid + '&amt=' + amt + '&url=' + url + '&providerid=' + gatewaytypeid + '&optionSelected=' + optionSelected);

        $("#elementps").dialog({
            resizable: false, draggable: false, modal: true, closeOnEscape: false, width: 500,
            close: function (event, ui) {
                $("#epsframe").attr('src', 'about:blank');
                $("#elementps").dialog("destroy");
            }
        });

        return;
    }
    else if ($("#rbDifferentEFT10024")[0].checked && (gatewaytypeid == 3 || gatewaytypeid == 5)) {
        optionSelected = 2;
        //open EFT form in popup
        epsShowEftPopup(accid, null, amt);
    }
    else {
        var valselected = $("#ddlCards option:selected").val();
        if (valselected != undefined) {
            var strs = valselected.split(";")
            if (strs[0].length <= 0) {
                return false;
            } else {
                optionSelected = 3;
                //Task:[CUR-142-84623]. 3/9/2016. RQ
                $("#btnCharge").prop('disabled', true).css('cursor', 'wait');
                __doPostBack('btnCharge_10019', '');
            }
        }

    }
}

function validatePayment() {
    var paidAmount = Number($("#amount").val());
    var valid = true;
    var errorMessages = [];

    if (!isNaN(paidAmount) && truncateNumber(paidAmount, 2) <= 0) {
        errorMessages.push(get_message(4));
    }

    if (errorMessages.length > 0) {
        valid = false
        $('#txtValidationMessage').text(errorMessages.join('<br/>'));
    }
    else {
        $('#txtValidationMessage').text("");
    }

    return valid;
}

function truncateNumber(amount, decimals) {
    const approach = Math.pow(10, decimals);
    return Math.floor(+(amount * approach).toFixed(decimals)) / approach;
}

function closeCCDialog() {
    $("#elementps").css('visibility', 'hidden');
    $("#epsframe").attr('src', 'about:blank');
    $("#elementps").dialog("destroy");
}

function popup() {
    var url = document.getElementById("txtURL").value;
    var name = document.getElementById("txtName").value;
    window.open(url, name, "top=400,left=550,width=400,height=500,toolbar=0,resizeable=0,menubar=0");
}

function toggle_onfile() {
    if (document.getElementById("divCardOnFile"))
        document.getElementById("divCardOnFile").style.display = "block";

    if (document.getElementById("divNewCard"))
        document.getElementById("divNewCard").style.display = "none";

    if (document.getElementById("divPaypal"))
        document.getElementById("divPaypal").style.display = "none";

    if (document.getElementById("btnCharge_3182"))
        document.getElementById("btnCharge_3182").disabled = false;
}

function toggle_different() {
    if (document.getElementById("divCardOnFile"))
        document.getElementById("divCardOnFile").style.display = "none";

    if (document.getElementById("divPaypal"))
        document.getElementById("divPaypal").style.display = "none";

    if (document.getElementById("divNewCard") && $("#hdgatetype").val() != 2 && $("#hdgatetype").val() != 3 && $("#hdgatetype").val() != 5)
        document.getElementById("divNewCard").style.display = "block";

    if (document.getElementById("btnCharge_3182"))
        document.getElementById("btnCharge_3182").disabled = false;
}

function toggle_paypal() {
    if (document.getElementById("divCardOnFile"))
        document.getElementById("divCardOnFile").style.display = "none";

    if (document.getElementById("divNewCard"))
        document.getElementById("divNewCard").style.display = "none";

    if (document.getElementById("divPaypal"))
        document.getElementById("divPaypal").style.display = "block";

    if (document.getElementById("btnCharge_3182"))
        document.getElementById("btnCharge_3182").disabled = true;
}
//'worklist #200933115931 8/7/2009 GC
function toggle_address() {
    var chk = document.getElementById("chkuseaddr_5886");
    var r = document.getElementById("traddress");

    if (chk) {
        if (chk.checked) {
            r.style.display = "";
        }
        else
            r.style.display = "none";
    }
}
function submit_form() {
    //Form1.action = "https://www.sandbox.paypal.com/cgi-bin/webscr";

    var f = document.getElementById('Form1');
    var vs = document.getElementById('__VIEWSTATE');

    //worklist #200933115931 8/7/2009 GC
    if (check_address() == false) {
        return false;
    }
    if (f) {
        f.action = document.getElementById("paypal_url").value;
        vs.name = "NOVIEWSTATE";

        document.getElementById("notify_url").value = document.getElementById("cancel_return").value;
        document.getElementById("return").value = document.getElementById("cancel_return").value;

        f.submit();
    }
}
function check_address() {
    //'worklist #200933115931 8/7/2009 GC
    var useaddr = document.getElementById("chkuseaddr_5886");
    var addr1 = document.getElementById("txtaddress1");
    var city = document.getElementById("txtcity");
    var state = document.getElementById("txtstate");
    var zip = document.getElementById("txtzip");
    if (useaddr) {
        if (useaddr.checked) {
            if (addr1.value.length == 0) {
                alert(get_message(0));
                addr1.focus();
                return false;
            }
            if (city.value.length == 0) {
                alert(get_message(1));
                city.focus();
                return false;
            }
            if (state.value.length == 0) {
                alert(get_message(2));
                state.focus();
                return false;
            }
            if (zip.value.length == 0) {
                alert(get_message(3));
                zip.focus();
                return false;
            }
        }
    }
}

function get_message(num) {
    var fld = document.getElementById("hdmessages").value;
    var myarray = fld.split(";");
    return myarray[num];
}

//////////////////////////////////////////////

$(document).ready(function (e) {

    GenerateDataTables();
    SwitchToRenewalTab();

    $('#btnNext2_544 , #btnNext1_544 ').click(function () {
        $(".spinner").show();
    });
    $("#tblInvoices_length select, #tblWorkOrders_length select, #tblRenewals_length select, #tblPrepay_length select").addClass("dropquery");
    $('.dropquery').select2();
});

function getParameterByName(name, url) {
    if (!url) url = window.location.href;
    name = name.replace(/[\[\]]/g, "\\$&");
    var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
        results = regex.exec(url);
    if (!results) return null;
    if (!results[2]) return '';
    return decodeURIComponent(results[2].replace(/\+/g, " "));
}

//check if the string is a valid number
function isNumber(n) {
    n = n.replace(/,/g, '.');
    return !isNaN(parseFloat(n)) && isFinite(n);
}

function userCurrentSeparatorAndParseFloat(n) {
    try {
        n = n.toString().replace(/,/g, '.');
        n = parseFloat(n);
        return n;
    } catch (err) {
        return 0;
    }
}
//check if the entered payment is above the max invoice/renewal amount.
//if it is, set the value to max value.
function isPaymentAbovMax(txtPay) {
    if (txtPay.value != '' && !isNumber(txtPay.value))
        return false
    else {
        var enteredPayment = userCurrentSeparatorAndParseFloat(txtPay.value);
        var maxPayment = userCurrentSeparatorAndParseFloat(txtPay.id.split('-')[2]).toFixed(2);

        //set the value to max value
        if (enteredPayment > maxPayment) {
            txtPay.value = maxPayment.toString();
        }

        return true;
    }
}

//Workitem: 14431
function automatePayPlanPaymentSetAmount($this) {
    storePaymentItem($this);
    
}

function loaddivLnkPayOnline() {
    $('#divLnkPayOnline')[0].style.display = '';
}
function seeDetails(type) {
    if (type == '0') {
        $('#tableWo')[0].style.display = 'none';
        $('#tableRen')[0].style.display = '';
        $('#tableInv')[0].style.display = '';
        $('.popupover').css('display', 'block');
        $('#divSelPay').css('display', 'block');
        // Task: [WebPortalTemplates] close not working LjB
        $('#divSelPay span.close').click(function () {
            $('.popupover').css('display', 'none');
            $('#divSelPay').css('display', 'none');
        });
    }
    if (type == '1') {
        $('#tableInv')[0].style.display = 'none';
        $('#tableRen')[0].style.display = 'none';
        $('#tableWo')[0].style.display = '';
        $('.popupover').css('display', 'block');
        $('#divSelPay').css('display', 'block');
        // Task: [WebPortalTemplates] close not working LjB
        $('#divSelPay span.close').click(function () {
            $('.popupover').css('display', 'none');
            $('#divSelPay').css('display', 'none');
        });
    }
    if (type == '2') {
        $('#tableInv')[0].style.display = '';
        $('#tableWo')[0].style.display = '';
        $('#tableRen')[0].style.display = '';
        $('.popupover').css('display', 'block');
        $('#divSelPay').css('display', 'block');
        // Task: [WebPortalTemplates] close not working LjB
        $('#divSelPay span.close').click(function () {
            $('.popupover').css('display', 'none');
            $('#divSelPay').css('display', 'none');
        });
    }
    if (type == '3') {
        $('#tableWo')[0].style.display = 'none';
        $('#tableRen')[0].style.display = 'none';
        $('#tableInv')[0].style.display = '';
        $('.popupover').css('display', 'block');
        $('#divSelPay').css('display', 'block');
        $('#divSelPay span.close').click(function () {
            $('.popupover').css('display', 'none');
            $('#divSelPay').css('display', 'none');
        });

    }
}
function loaddivLnkPayOnlineDirect() {
    $('#divLnkPayOnlineDirect')[0].style.display = '';
}

function GenerateDataTables() {

    $('input[type=checkbox]').each(function () {
        if (!($(this).attr("id").indexOf('chkAccounts_') > -1)) {
            $(this).after("<label for='" + $(this).attr("id") + "'></label>");
        }
    });


    if ($('#tblRenewals') !== undefined) {
        if ($('#tblRenewals tr').length > 0) {
            var renewals = crateDataTable(
                "#tblRenewals",
                "1",
                $('#lang').val(),
                [
                    { responsivePriority: 1, targets: 0 },
                    { responsivePriority: 2, targets: -2 },
                    { responsivePriority: 3, targets: -1 }
                ]
            );
        }
        else {
            $('#renli').hide();
        }
    }
    else {
        var renewals = crateDataTable(
            "#tblRenewals",
            "1",
            $('#lang').val(),
            [{ responsivePriority: 1, targets: 0 }]
        );
    }

    if ($('#tblInvoices') !== undefined) {
        if ($('#tblInvoices tr').length > 0) {
            var invoicestab = crateDataTable("#tblInvoices", "1", $('#lang').val(), [{ responsivePriority: 1, targets: 0 }, { responsivePriority: 2, targets: -2 }, { responsivePriority: 3, targets: -1 }]);
        }
        else {
            $('#invli').hide();
        }
    }
    else {
        var invoicestab = crateDataTable("#tblInvoices", "1", $('#lang').val(), [{ responsivePriority: 1, targets: 0 }]);
    }

    if ($('#tblPrepay') !== undefined) {
        if ($('#tblPrepay tr').length > 0) {
            crateDataTable(
                "#tblPrepay",
                "1",
                $('#lang').val(),
                [
                    { responsivePriority: 1, targets: [2,-1] },
                    { responsivePriority: 2, targets: [-2,-3] },
                    { responsivePriority: 3, targets: 2}
                ]
            );
        }
    }
    else {
        crateDataTable("#tblPrepay", "1", $('#lang').val(), [{ responsivePriority: 1, targets: 0 }]);
    }
    
    if ($('#tblWorkOrders') !== undefined) {
        if ($('#tblWorkOrders tr').length > 0) {
            var wotab = crateDataTable("#tblWorkOrders", "1", $('#lang').val(), [{ responsivePriority: 1, targets: 0 }, { responsivePriority: 2, targets: -2 }, { responsivePriority: 3, targets: -1 }]);
        }
        else {
            $('#woli').hide();
        }
    }
    else {
        var wotab = crateDataTable("#tblWorkOrders", "1", $('#lang').val(), [{ responsivePriority: 1, targets: 0 }]);
    }
}

function GoBack() {
    var portal = $('input#hdportal').val();
    window.location.href = portal + "pickaccount.aspx";
}

function SwitchToRenewalTab() {
   
    try {
        var whichTab = getParameterByName("selectedTab", window.location.href);
        if (whichTab === "renewals") {
            $(document).find('a[href="#ren"]').trigger("click");
        } else {
            whichTab = getParameterByName("itab", window.location.href)
            if (whichTab === "ren") {
                $(document).find('a[href="#ren"]').trigger("click");
            }
        }
    } catch (e) {
        console.log(e);
    }
}

//Task:[2015826105920] Web porhtal online billing system 26/08/2015 DejanK
function clearall(table) {
    table = $("#" + table).dataTable();
    if (table != undefined) {
        $('[id^=chkPay]', table.fnGetNodes()).each(function (index) {
            this.checked = false;
            let pitem = getPaymentItem(this, true);
            deleteIfExists(pitem);
            updatePayment();
        });

        $('[id^=txtPay]', table.fnGetNodes()).each(function (index) {
            let pitem = getPaymentItem(this);
            deleteIfExists(pitem);
            updatePayment();
            this.value = '';
        });
    }
}

//Task:[2015826105920] Web portal online billing system 26/08/2015 DejanK
function fillall(table) {
    table = $("#" + table).dataTable();
    if (table != undefined) {
        $('[id^=chkPay]', table.fnGetNodes()).each(function (index) {
            this.checked = true;
            storePaymentItem(this);
        });

        $('[id^=txtPay]', table.fnGetNodes()).each(function (index) {
            let pitem = getPaymentItem(this);
            this.value = pitem.originalamount;
            storePaymentItem(this);
        });
    }
}

let listofpayments = [];

function deleteIfExists(paymentitem) {
    listofpayments = listofpayments.filter(x => x.m_id !== paymentitem.m_id)
}

function getPaymentItem($this, ischeckbox) {
    if (!ischeckbox)
        return JSON.parse($($this).attr("paymentitem"));
    else
        return JSON.parse($this.closest('span').attributes.paymentitem.value);
}

function geTotalPayment() {
    return listofpayments.reduce((acc, paymentitem) => acc + paymentitem.m_value, 0);
}

function checkboxStorePaymentItem($this) {

    let paymentitem = getPaymentItem($this, true);

    paymentitem.m_value = paymentitem.originalamount;

    deleteIfExists(paymentitem);
    if ($this.checked)
        listofpayments.push(paymentitem);

    updatePayment();
}

function inputStorePaymentItem($this) {

    if (!currencyToNumber($this.value) > 0)
        return;

    let paymentitem = getPaymentItem($this);
    deleteIfExists(paymentitem);

    let paymentvalue = currencyToNumber($this.value);

    if (paymentitem.originalamount > 0) {
        if (paymentvalue >= paymentitem.originalamount) {
            paymentvalue = paymentitem.originalamount;
            $this.value = paymentvalue.toFixed(2);
        }
    }

    paymentitem.m_value = paymentvalue;
    paymentitem.m_pay = true;

    listofpayments.push(paymentitem);


    if ($this.type == 'button') {
        $("#" + $this.attributes.thistextbox.value).val(paymentitem.m_value);
    }

    updatePayment();
}
function storePaymentItem($this) {

    switch ($this.type) {
        case 'checkbox':
            checkboxStorePaymentItem($this);
            break;
        case 'button':
        case 'text':
        case 'number':
            inputStorePaymentItem($this);
            break;
        default:
        // code block
    }
}

function updatePayment() {
    let totalPayment = geTotalPayment();

    $('#hiddenChk').val(JSON.stringify(listofpayments));
    $('#btnNext2_544')[0].disabled = (totalPayment === 0);
    $('#lnkPayOnlineNow_3014')[0].disabled = (totalPayment === 0);
    $('#lblAmountToPay2').html(getCurrencySymbol() + totalPayment.toFixed(2));
}

function removePaymentPlanFromPaymentItems(accountpayplanid) {
    listofpayments = listofpayments.filter(object => {
        return object.m_id !== accountpayplanid;
    });
    document.getElementById('txtPayP-' + accountpayplanid).value = 0;

    updatePayment();
}