Subversion Repositories SmartDukaan

Rev

Rev 22594 | Rev 22681 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

var googleProfile;


$(document).ajaxComplete(
        function(){
                
        }
);
var startApp = function() {
  gapi.load('auth2', function(){
    // Retrieve the singleton for the GoogleAuth library and set up the client.
    auth2 = gapi.auth2.init({
      client_id: googleApiKey,
      cookiepolicy: 'single_host_origin',
      // Request scopes in addition to 'profile' and 'email'
      //scope: 'additional_scope'
    });
    attachSignin(document.getElementById('customBtn'));
  });
};

function attachSignin(element) {
    console.log(element.id);
    auth2.attachClickHandler(element, {},
        function(googleUser) {
                googleProfile = googleUser.getBasicProfile();
                console.log(googleProfile.getImageUrl());
                submitUser(googleUser);
        }, function(error) {
          console.log(JSON.stringify(error, undefined, 2));
        });
  }

function submitUser(googleUser){
        jQuery.ajax({
        type : "POST",
        url : context+"/login",
        dataType: 'json',
        data: {"token":googleUser.getAuthResponse().id_token},
        success: function(data, textStatus, request){
                console.log(data);
                addProfileInLocalDb();
                window.location.href= data.redirectUrl;
                }
    });  
}

function addProfileInLocalDb(){
        var profile = {'image_url':googleProfile.getImageUrl(),'name':googleProfile.getName()};
        localStorage.setItem("profile",JSON.stringify(profile));
}


function loadNewGrn(domId){
        jQuery.ajax({
        type : "GET",
        url : context+"/purchase",
        success : function(response) {
            $('#' + domId).html(response);
        }
    });  
}

function loadGoodInventory(domId, search_text){
        jQuery.ajax({
        type : "GET",
        url : context+"/getCurrentInventorySnapshot/?searchTerm="+search_text,
        success : function(response) {
            $('#' + domId).html(response);
        }
    });  
}

function loadCatalog(domId, search_text){
        jQuery.ajax({
        type : "GET",
        url : context+"/getCatalog/?searchTerm="+search_text,
        success : function(response) {
            $('#' + domId).html(response);
        }
    });  
}

function getInventoryItemAgingByInterval(domId, searchContent){
        jQuery.ajax({
        type : "POST",
        url : context+"/getInventoryItemAgingByInterval?searchContent="+searchContent,
        cache: false,
        contentType: "application/json",
        processData: false,
        async: false,
        data : JSON.stringify([5,15,30,45]),
        success : function(response) {
            $('#' + domId).html(response);
        },
        error : function() {
                        alert("OOPS!!!Failed to do changes.Try Again.",'ERROR');
                },
    });  
}

function downloadAgingReport(){
        data = JSON.stringify([5,15,30,45]),
        xhttp = new XMLHttpRequest();
        xhttp.onreadystatechange = function() {
            var a;
            if (xhttp.readyState === 4 && xhttp.status === 200) {
                // Trick for making downloadable link
                a = document.createElement('a');
                a.href = window.URL.createObjectURL(xhttp.response);
                // Give filename you wish to download
                a.download = "InventoryItemAging.xlsx";
                a.style.display = 'none';
                document.body.appendChild(a);
                a.click();
            }
        };
        // Post data to URL which handles post request
        xhttp.open("POST", context+"/getInventoryItemAgingByInterval");
        xhttp.setRequestHeader("Content-Type", "application/json");
        // You should set responseType as blob for binary responses
        xhttp.responseType = 'blob';
        xhttp.send(data);
}

function downloadItemLedgerReport(){
        //data = JSON.stringify([5,10,15,20,25,30,35,40]),
        xhttp = new XMLHttpRequest();
        xhttp.onreadystatechange = function() {
            var a;
            if (xhttp.readyState === 4 && xhttp.status === 200) {
                // Trick for making downloadable link
                a = document.createElement('a');
                a.href = window.URL.createObjectURL(xhttp.response);
                // Give filename you wish to download
                a.download = "ItemCompleteLedegerReport.xlsx";
                a.style.display = 'none';
                document.body.appendChild(a);
                a.click();
            }
        };
        // Post data to URL which handles post request
        xhttp.open("GET", context+"/itemLedger/complete/download");
        //xhttp.setRequestHeader("Content-Type", "application/json");
        // You should set responseType as blob for binary responses
        xhttp.responseType = 'blob';
        xhttp.send(null);
}

function getItemAgingNextPreviousItems(offset, searchContent){
        
        jQuery.ajax({
                type : "POST",
        url : context+"/getInventoryItemAgingByInterval?offset="+offset+"&searchContent="+searchContent,
        cache: false,
        contentType: "application/json",
        processData: false,
        async: false,
        data : JSON.stringify([5,15,30,45]),
                beforeSend: function(){
                        //$('#ajax-spinner').show();
        },
        complete: function(){
                //$('#ajax-spinner').hide();
        },
        success : function(response) {
                $('#main-content').html(response);
        },
                error : function() {
                        alert("Unable to fetch items");
                 },
    });
}

function getGrnHistoryPreviousItems(start,end,pre,purchase_reference, searchType,startTime,endTime){
        jQuery.ajax({
                type : "GET",
                url : context+"/getPaginatedGrnHistory/?purchaseReference="+purchase_reference+"&searchType="+searchType
                +"&startTime="+startTime
                +"&endTime="+endTime+"&offset="+pre,
                        beforeSend: function(){
                //$('#ajax-spinner').show();
                },
                complete: function(){
                //$('#ajax-spinner').hide();
                },
                success : function(response) {
                        $( "#grn-history-paginated .end" ).text(+end - +10);
                        $( "#grn-history-paginated .start" ).text(+start - +10);
                        $('#grn-history-table').html(response);
                        $("#grn-history-paginated .next").prop('disabled', false);
                                if (parseInt(pre)==0)
                                {
                                        $("#grn-history-paginated .previous").prop('disabled', true);
                                }
                                
                },
                        error : function() {
                                alert("Unable to fetch items");
                         },
            });
}

function loadBadInventory(domId, search_text){
        jQuery.ajax({
        type : "GET",
        url : context+"/getBadInventorySnapshot/?searchTerm="+search_text,
        success : function(response) {
            $('#' + domId).html(response);
        }
    });  
}

function loadGrnHistory(domId,purchase_reference,searchType, startTime, endTime){
        jQuery.ajax({
        type : "GET",
        url : context+"/grnHistory/?purchaseReference="+purchase_reference+"&searchType="+searchType
        +"&startTime="+startTime
        +"&endTime="+endTime,
        success : function(response) {
            $('#' + domId).html(response);
        }
    });  
}





function getNextItems(start, end, searchText){
        console.log(start);
        console.log(end);
        console.log(+end + +10);
        console.log(+start + +10);
        jQuery.ajax({
                type : "GET",
                url : context+"/getPaginatedCurrentInventorySnapshot/?offset="+end+"&searchTerm="+searchText,
                        beforeSend: function(){
                //$('#ajax-spinner').show();
                },
                complete: function(){
                //$('#ajax-spinner').hide();
                },
                success : function(response) {
                        $( "#good-inventory-paginated .end" ).text(+end + +10);
                        $( "#good-inventory-paginated .start" ).text(+start + +10);
                                var last = $( "#good-inventory-paginated .end" ).text();
                                var temp = $( "#good-inventory-paginated .size" ).text();
                                if (parseInt(last) >= parseInt(temp)){
                                        $("#good-inventory-paginated .next").prop('disabled', true);
                                        //$( "#good-inventory-paginated .end" ).text(temp);
                                }
                    $('#good-inventory-table').html(response);
                    $("#good-inventory-paginated .previous").prop('disabled', false);
                },
                        error : function() {
                                alert("Unable to fetch items");
                         },
            });  
        }
function getPreviousItems(start,end,pre,searchText){
        jQuery.ajax({
                type : "GET",
                url : context+"/getPaginatedCurrentInventorySnapshot/?offset="+pre+"&searchTerm="+searchText,
                        beforeSend: function(){
                //$('#ajax-spinner').show();
                },
                complete: function(){
                //$('#ajax-spinner').hide();
                },
                success : function(response) {
                        $( "#good-inventory-paginated .end" ).text(+end - +10);
                        $( "#good-inventory-paginated .start" ).text(+start - +10);
                        $('#good-inventory-table').html(response);
                        $("#good-inventory-paginated .next").prop('disabled', false);
                                if (parseInt(pre)==0)
                                {
                                        $("#good-inventory-paginated .previous").prop('disabled', true);
                                }
                                
                },
                        error : function() {
                                alert("Unable to fetch items");
                         },
            });
}

function getGrnHistoryNextItems(start, end, purchase_reference, searchType,startTime,endTime){
        console.log(start);
        console.log(end);
        console.log(+end + +10);
        console.log(+start + +10);
        jQuery.ajax({
                type : "GET",
                url : context+"/getPaginatedGrnHistory/?purchaseReference="+purchase_reference+"&searchType="+searchType
                +"&startTime="+startTime
                +"&endTime="+endTime+"&offset="+end,
                        beforeSend: function(){
                //$('#ajax-spinner').show();
                },
                complete: function(){
                //$('#ajax-spinner').hide();
                },
                success : function(response) {
                        $( "#grn-history-paginated .end" ).text(+end + +10);
                        $( "#grn-history-paginated .start" ).text(+start + +10);
                                var last = $( "#grn-history-paginated .end" ).text();
                                var temp = $( "#grn-history-paginated .size" ).text();
                                if (parseInt(last) >= parseInt(temp)){
                                        $("#grn-history-paginated .next").prop('disabled', true);
                                        //$( "#good-inventory-paginated .end" ).text(temp);
                                }
                    $('#grn-history-table').html(response);
                    $("#grn-history-paginated .previous").prop('disabled', false);
                },
                        error : function() {
                                alert("Unable to fetch items");
                        },
            });  
        }
function getGrnHistoryPreviousItems(start,end,pre,purchase_reference, searchType,startTime,endTime){
        jQuery.ajax({
                type : "GET",
                url : context+"/getPaginatedGrnHistory/?purchaseReference="+purchase_reference+"&searchType="+searchType
                +"&startTime="+startTime
                +"&endTime="+endTime+"&offset="+pre,
                        beforeSend: function(){
                //$('#ajax-spinner').show();
                },
                complete: function(){
                //$('#ajax-spinner').hide();
                },
                success : function(response) {
                        $( "#grn-history-paginated .end" ).text(+end - +10);
                        $( "#grn-history-paginated .start" ).text(+start - +10);
                        $('#grn-history-table').html(response);
                        $("#grn-history-paginated .next").prop('disabled', false);
                                if (parseInt(pre)==0)
                                {
                                        $("#grn-history-paginated .previous").prop('disabled', true);
                                }
                                
                },
                        error : function() {
                                alert("Unable to fetch items");
                         },
            });
}

function getSaleHistoryNextItems(start, end, invoiceNumber, searchType, startTime, endTime){
        console.log(start);
        console.log(end);
        console.log(+end + +10);
        console.log(+start + +10);
        jQuery.ajax({
                type : "GET",
                url : context+"/getPaginatedSaleHistory/?invoiceNumber="+invoiceNumber+"&searchType="+searchType
                +"&startTime="+startTime
                +"&endTime="+endTime+"&offset="+end,
                        beforeSend: function(){
                //$('#ajax-spinner').show();
                },
                complete: function(){
                //$('#ajax-spinner').hide();
                },
                success : function(response) {
                        $( "#sale-history-paginated .end" ).text(+end + +10);
                        $( "#sale-history-paginated .start" ).text(+start + +10);
                                var last = $( "#sale-history-paginated .end" ).text();
                                var temp = $( "#sale-history-paginated .size" ).text();
                                if (parseInt(last) >= parseInt(temp)){
                                        $("#sale-history-paginated .next").prop('disabled', true);
                                        //$( "#good-inventory-paginated .end" ).text(temp);
                                }
                    $('#sale-history-table').html(response);
                    $("#sale-history-paginated .previous").prop('disabled', false);
                },
                        error : function() {
                                alert("Unable to fetch items");
                         },
            });  
        }
function getSaleHistoryPreviousItems(start, end, pre, invoiceNumber, searchType,startTime,endTime){
        jQuery.ajax({
                type : "GET",
                url : context+"/getPaginatedSaleHistory/?invoiceNumber="+invoiceNumber+"&searchType="+searchType
                +"&startTime="+startTime
                +"&endTime="+endTime+"&offset="+pre,
                        beforeSend: function(){
                //$('#ajax-spinner').show();
                },
                complete: function(){
                //$('#ajax-spinner').hide();
                },
                success : function(response) {
                        $( "#sale-history-paginated .end" ).text(+end - +10);
                        $( "#sale-history-paginated .start" ).text(+start - +10);
                        $('#sale-history-table').html(response);
                        $("#sale-history-paginated .next").prop('disabled', false);
                                if (parseInt(pre)==0)
                                {
                                        $("#sale-history-paginated .previous").prop('disabled', true);
                                }
                },
                        error : function() {
                                alert("Unable to fetch items");
                         },
            });
}



function getWalletHistoryNextItems(start, end, startTime, endTime){
        console.log(start);
        console.log(end);
        console.log(+end + +10);
        console.log(+start + +10);
        jQuery.ajax({
                type : "GET",
                url : context+"/getPaginatedWalletHistory?startTime="+startTime
                +"&endTime="+endTime+"&offset="+end,
                        beforeSend: function(){
                //$('#ajax-spinner').show();
                },
                complete: function(){
                //$('#ajax-spinner').hide();
                },
                success : function(response) {
                        $( "#wallet-history-paginated .end" ).text(+end + +10);
                        $( "#wallet-history-paginated .start" ).text(+start + +10);
                                var last = $( "#wallet-history-paginated .end" ).text();
                                var temp = $( "#wallet-history-paginated .size" ).text();
                                if (parseInt(last) >= parseInt(temp)){
                                        $("#wallet-history-paginated .next").prop('disabled', true);
                                        //$( "#good-inventory-paginated .end" ).text(temp);
                                }
                    $('#wallet-history-table').html(response);
                    $("#wallet-history-paginated .previous").prop('disabled', false);
                },
                        error : function() {
                                alert("Unable to fetch items");
                         },
            });  
        }
function getWalletHistoryPreviousItems(start, end, pre, invoiceNumber, searchType,startTime,endTime){
        jQuery.ajax({
                type : "GET",
                url : context+"/getPaginatedWalletHistory?startTime="+startTime
                +"&endTime="+endTime+"&offset="+pre,
                        beforeSend: function(){
                //$('#ajax-spinner').show();
                },
                complete: function(){
                //$('#ajax-spinner').hide();
                },
                success : function(response) {
                        $( "#wallet-history-paginated .end" ).text(+end - +10);
                        $( "#wallet-history-paginated .start" ).text(+start - +10);
                        $('#wallet-history-table').html(response);
                        $("#wallet-history-paginated .next").prop('disabled', false);
                                if (parseInt(pre)==0)
                                {
                                        $("#wallet-history-paginated .previous").prop('disabled', true);
                                }
                },
                        error : function() {
                                alert("Unable to fetch items");
                         },
            });
}

function loadGoodInventorySearchInfo(search_text){
        loadGoodInventory("main-content",search_text);
}

function loadGrnHistorySearchInfo(search_text,searchType,startTime,endTime){
        loadGrnHistory("main-content",search_text,searchType,startTime,endTime);
}

function findDuplicateSerialNumbers(value){
    var result = $("#grnImeiInformation :input[value='" + value + "']").length - 1;
    return result;
}

function loadGrnDetails(purchaseId,domId){
        jQuery.ajax({
        type : "GET",
        url : context+"/grnHistoryDetailByPurchaseId/?purchaseId="+purchaseId,
        success : function(response) {
            $('#' + domId).html(response);
            window.dispatchEvent(new Event('resize'));
        }
    });
}

function loadSaleDetails(orderId, domId){
        jQuery.ajax({
        type : "GET",
        url : context+"/saleDetails?orderId="+orderId,
        success : function(response) {
            $('#' + domId).html(response);
            window.dispatchEvent(new Event('resize'));
        }
    });
}

function loadPendingGrnDetails(purchaseId,domId){
        jQuery.ajax({
                url: context+"/purchase/?airwayBillOrInvoiceNumber="+purchaseId,
                type: 'POST',
                async: false,
                success: function (data) {
                        $('#'+domId).html(data);
                },
                error : function() {
                        alert("OOPS!!!Failed to do changes.Try Again.",'ERROR');
                },
                cache: false,
                contentType: false,
                processData: false
        });
}

function getNextCatalogItems(start, end, searchText){
        console.log(start);
        console.log(end);
        console.log(+end + +10);
        console.log(+start + +10);
        jQuery.ajax({
                type : "GET",
                url : context+"/getPaginatedCatalog/?offset="+end+"&searchTerm="+searchText,
                        beforeSend: function(){
                //$('#ajax-spinner').show();
                },
                complete: function(){
                //$('#ajax-spinner').hide();
                },
                success : function(response) {
                        $( "#catalog-paginated .end" ).text(+end + +10);
                        $( "#catalog-paginated .start" ).text(+start + +10);
                                var last = $( "#catalog-paginated .end" ).text();
                                var temp = $( "#catalog-paginated .size" ).text();
                                if (parseInt(last) >= parseInt(temp)){
                                        $("#catalog-paginated .next").prop('disabled', true);
                                }
                    $('#catalog-table').html(response);
                    $("#catalog-paginated .previous").prop('disabled', false);
                },
                        error : function() {
                                alert("Unable to fetch items");
                         },
            });  
        }
function getPreviousCatalogItems(start,end,pre,searchText){
        jQuery.ajax({
                type : "GET",
                url : context+"/getPaginatedCatalog/?offset="+pre+"&searchTerm="+searchText,
                        beforeSend: function(){
                //$('#ajax-spinner').show();
                },
                complete: function(){
                //$('#ajax-spinner').hide();
                },
                success : function(response) {
                        $( "#catalog-paginated .end" ).text(+end - +10);
                        $( "#catalog-paginated .start" ).text(+start - +10);
                        $('#catalog-table').html(response);
                        $("#catalog-paginated .next").prop('disabled', false);
                                if (parseInt(pre)==0)
                                {
                                        $("#catalog-paginated .previous").prop('disabled', true);
                                }
                                
                },
                        error : function() {
                                alert("Unable to fetch items");
                         },
            });
}

function loadCatalogSearchInfo(search_text){
        loadCatalog("main-content",search_text);
}

function addItemInLocalStorage(bagObj){
        if (localStorage.getItem("bag")!=null){
                var bag = JSON.parse(localStorage.getItem("bag"));
                bag[bagObj.itemId] = bagObj
                localStorage.setItem("bag",JSON.stringify(bag));
                bag = localStorage.getItem("bag")
                $("#cart_bar").find('span').text(Object.keys(JSON.parse(bag)).length);
        }
        else{
                var tempObj = {};
                tempObj[bagObj.itemId] = bagObj
                localStorage.setItem("bag",JSON.stringify(tempObj));
                var bag = localStorage.getItem("bag")
                $("#cart_bar").find('span').text(Object.keys(JSON.parse(bag)).length);
        }
}


function changeQuantityInLocalStorage(itemId, newQuantity){
        var bag = JSON.parse(localStorage.getItem("bag"));
        bag[itemId].quantity = newQuantity;
        localStorage.setItem("bag",JSON.stringify(bag));
}

function removeItemFromLocalStorage(itemId){
        if (localStorage.getItem("bag")!=null){
                var bag = JSON.parse(localStorage.getItem("bag"));
                delete bag[itemId];
                localStorage.setItem("bag",JSON.stringify(bag));
                $("#cart_bar").find('span').text(Object.keys(bag).length);
        }
}

function emptyBag(){
        localStorage.setItem("bag",JSON.stringify({}));
        $("#cart_bar").find('span').text(0);
}

function loadCart(domId){
        jQuery.ajax({
        type : "POST",
        data: {"cartData":localStorage.getItem("bag")},
        url : context+"/cart",
        success : function(response) {
            $('#' + domId).html(response);
        }
    });  
}

function loadWallet(domId, startTime, endTime){
        jQuery.ajax({
        type : "GET",
        //data: {"cartData":localStorage.getItem("bag")},
        url : context+"/walletDetails?startTime="+startTime
        +"&endTime="+endTime,
        success : function(response) {
            $('#' + domId).html(response);
        }
    });  
}

function checkout(domId){
        jQuery.ajax({
        type : "GET",
        data: {"cartData":localStorage.getItem("bag")},
        url : context+"/validate-cart",
        success : function(response) {
                var obj = JSON.parse(response);
                redirectCart(obj.redirectUrl, obj.params, obj.method, "main-content");
                $('#main-content').html(response);
        }
    });
}

function redirectCart(url, cartData, method, domId){
        jQuery.ajax({
        type : method,
        data: {"cartData":cartData},
        url : context+url,
        success : function(response) {
            $('#' + domId).html(response);
            window.dispatchEvent(new Event('resize'));
        }
    });  
}

function saleHistory(domId, invoiceNumber, searchType, startTime, endTime){
        jQuery.ajax({
        type : "GET",
        url : context+"/saleHistory?invoiceNumber="+invoiceNumber+"&searchType="+searchType
        +"&startTime="+startTime
        +"&endTime="+endTime,
        success : function(response) {
            $('#' + domId).html(response);
        }
    });  
}


function contactUs(domId){
        jQuery.ajax({
        type : "GET",
        url : context+"/contactUs",
        success : function(response) {
            $('#' + domId).html(response);
        }
    });  
}

function writeOldCustomerDetailsByMobileNumber(mobileNumber){
        jQuery.ajax({
        type : "GET",
        url : context+"/customer/mobileNumber?mobileNumber="+mobileNumber,
        success : function(response) {
                console.log("response"+response);
                var customer = response.response;
            $('#firstName').attr('value', customer.firstName);
            $('#lastName').attr('value', customer.lastName);
            $('#email').attr('value', customer.emailId);
            $('#phone').attr('value', customer.mobileNumber);
            $('#alternatePhone').attr('value', customer.address.phoneNumber);
            $('#line1').attr('value', customer.address.line1);
            $('#line2').attr('value', customer.address.line2);
            $('#landmark').attr('value', customer.address.landmark);
            $('#pinCode').attr('value', customer.address.pinCode);
            $('#city').attr('value', customer.address.city);
            $('#state').attr('value', customer.address.state);
        }
    });  
}

function saleHistorySearchInfo(search_text, searchType, startTime, endTime){
        saleHistory("main-content", search_text, searchType, startTime, endTime);
}

function walletHistoryDateSearchSearchInfo(startTime, endTime){
        
}


function validateOrderDetails(){
        var sNumbers = [];
        var error = false;
        $("form#cd input.serialNumber").each(function(){
                var input = $(this).val().trim();
                var itemType = $(this).attr("itemType");
                $(this).removeClass("border-highlight");
                if (sNumbers.indexOf(input) !=-1 || (itemType ==='SERIALIZED' && !input)){
                        error = true;
                        $(this).addClass("border-highlight");
                }
                sNumbers.push(input);
        });
        
        $("form#cd input.unitPrice").each(function(){
                var input = $(this).val().trim();
                $(this).removeClass("border-highlight");
                if (!input || parseInt(input)<=0 || isNaN(input)){
                        error=true;
                        $(this).addClass("border-highlight");
                }
        });
        
        // checking input discountAmount is not greater than maxDiscountAmount
        $("form#cd input.discountAmount").each(function(){
                var input = $(this).val().trim();
                var mop = $(this).attr("mop");
                var maxDiscountPrice = parseFloat($(this).attr("placeholder").substring(6));
                if(mop){
                        $(this).removeClass("border-highlight");
                        if (!input || parseFloat(input)<0 || isNaN(input)){
                                alert("DiscountAmount value can not be lesser than 0 or invalid value");
                                error=true;
                                $(this).addClass("border-highlight");
                        }
                        if(parseFloat(input) > maxDiscountPrice){
                                alert("DiscountAmount [" + parseFloat(input) + "] value can not be greater than the suggested maxDiscountPrice [" + maxDiscountPrice + "]");
                                error=true;
                                $(this).addClass("border-highlight");
                        }
                }
        });
        
        var amount = 0;
        var netPayableAmount = parseFloat($("form#cd input.netPayableAmount").val());
        
        
        $("form#cd input.amount").each(function(){
                if ($(this).val() == ""){
                        $(this).val(0);
                }
                var tmpAmount = parseFloat($(this).val());
                amount = amount + tmpAmount;
        });
        
        console.log(amount);
        console.log(netPayableAmount);
        
        if (amount != netPayableAmount){
                if(amount < netPayableAmount){
                        alert("[" + (netPayableAmount - amount) + "] is more required to complete the payment");
                }else{
                        alert("[" + (amount - netPayableAmount) + "] is extra amount, please reduce the amount");
                }
                $("form#cd input.netPayableAmount").each(function(){
                        $(this).addClass("border-highlight");
                });
                error = true;
        }
        
        if (error){
                return false;
        }
        return true;
        
}

function orderDetailsPayload(){
                var orderObj = {};
                var priceQtyArray = [];
                var customerObj = {};
                var paymentOption = [];
                
                $("form#cd input.serialNumber").each(function(){
                        var itemId = parseInt($(this).attr("itemId"));
                        if (orderObj.hasOwnProperty('fofoLineItems')){
                                var itemDetails = orderObj['fofoLineItems'];
                                if (itemDetails.hasOwnProperty(itemId)){
                                        var serialNumbers = itemDetails[itemId];
                                        serialNumbers.push($(this).val());
                                        itemDetails[itemId] = serialNumbers;
                                }else{
                                        var serialNumbers = [];
                                        serialNumbers.push($(this).val());
                                        itemDetails[itemId] = serialNumbers;
                                }
                        }else{
                                var serialNumbers = [];
                                serialNumbers.push($(this).val());
                                var tmp ={};
                                tmp[itemId]  = serialNumbers;
                                orderObj['fofoLineItems'] = tmp;
                        }
                });
                console.log( JSON.stringify(orderObj));
                /*$("form#cd input.unitPrice").each(function(){
                        var itemId = parseInt($(this).attr("itemId"));
                        var unitPrice = parseFloat($(this).val());
                        var qty = parseInt($(this).attr("quantity"));
                        var discountAmount = parseFloat($(this).val());
                        var tmpObj = {'itemId':itemId,'sellingPrice':unitPrice,'quantity':qty};
                        if (orderObj['fofoLineItems'][itemId] === undefined){
                                tmpObj['serialNumberDetails'] =[];
                        }
                        else{
                                //tmpObj['serialNumbers'] = orderObj['fofoLineItems'][itemId];
                                tmpObj['serialNumberDetails'] = [];
                        }
                        var found = false;
                        for(var i = 0; i < priceQtyArray.length; i++){                  
                                if (priceQtyArray[i]["itemId"] == itemId){
                                        found = true;
                                        break;
                                }
                        }
                        if(!found){
                                priceQtyArray.push(tmpObj);
                        }
                });*/
                
                $("#order-details").find("tr:not(:first-child)").each(function(index, el){
                        //console.log(el);
                        //console.log(index);
                        var $unitPriceElement = $(el).find('.unitPrice');
                        var $discountAmountElement = $(el).find('.discountAmount');
                        
                        var itemId = parseInt($unitPriceElement.attr("itemId"));
                        var unitPrice = parseFloat($unitPriceElement.val());
                        var qty = parseInt($unitPriceElement.attr("quantity"));
                        var discountAmount = parseFloat($discountAmountElement.val());
                        var mop = $discountAmountElement.attr("mop");
                        var tmpObj = {'itemId':itemId,'sellingPrice':unitPrice,'quantity':qty};
                        tmpObj.discountAmount = discountAmount;
                        
                        if (orderObj['fofoLineItems'][itemId] === undefined){
                                tmpObj['serialNumberDetails'] =[];
                        }
                        else{
                                //tmpObj['serialNumbers'] = orderObj['fofoLineItems'][itemId];
                                tmpObj['serialNumberDetails'] = [];
                        }
                        var found = false;
                        for(var i = 0; i < priceQtyArray.length; i++){                  
                                if (priceQtyArray[i]["itemId"] == itemId){
                                        found = true;
                                        break;
                                }
                        }
                        if(!found){
                                priceQtyArray.push(tmpObj);
                        }
                });
                
                
                $("#order-details").find("tr:not(:first-child)").each(function(index,el){
                        //console.log(el);
                        //console.log(index);
                        var $serialNumberElement = $(el).find('.serialNumber');
                        var itemId = parseInt($serialNumberElement.attr("itemId"));
                        var insuranceAmount = parseFloat($(el).find('.insuranceAmount').val());
                        //if (priceQtyArray['fofoLineItems'][itemId] !=undefined){
                                
                        //}
                        //console.log($serialNumberElement.val());
                        //console.log(itemId);
                        for(var i = 0; i < priceQtyArray.length; i++){
                                console.log(priceQtyArray[i]["itemId"]);                        
                                if (priceQtyArray[i]["itemId"] == itemId){
                                        if(insuranceAmount > 0){
                                                insurance = true;
                                        }else{
                                                insurance = false;
                                        }
                                        var serialNumberDetails = {'serialNumber':$serialNumberElement.val(),'insurance':insurance,'amount':insuranceAmount}
                                        priceQtyArray[i]['serialNumberDetails'].push(serialNumberDetails);
                                }
            }
                        
                });
                
                console.log("priceQtyArray : "+JSON.stringify(priceQtyArray));
                //customer-details
                /*$("#customer-details input").each(function(){
                        console.log($(this).attr('name'));
                        customerObj[$(this).attr('name')] = $(this).val();
                });*/
                //$("input[name=nameGoesHere]").val();
                customerObj['firstName'] = $("form#cd input[name=firstName]").val();
                customerObj['lastName'] = $("form#cd input[name=lastName]").val();
                customerObj['mobileNumber'] = $("form#cd input[name=phone]").val(); 
                customerObj['emailId'] = $("form#cd input[name=email]").val();
                customerObj['dateOfBirth'] = $("form#cd input[name=dateOfBirth]").val();
                var customerAddress = {};
                customerAddress['name'] = $("form#cd input[name=firstName]").val() + " " + $("form#cd input[name=lastName]").val();
                customerAddress['line1'] = $("form#cd input[name=line1]").val();
                customerAddress['line2'] = $("form#cd input[name=line2]").val();
                customerAddress['landmark'] = $("form#cd input[name=landmark]").val();
                customerAddress['city'] = $("form#cd input[name=city]").val();
                customerAddress['state'] = $('select[name=state] option:selected').val();
                customerAddress['pinCode'] = $("form#cd input[name=pinCode]").val();
                customerAddress['phoneNumber'] = $("form#cd input[name=alternatePhone]").val();
                customerAddress['country'] = "India";
                customerObj['address'] = customerAddress; 
                console.log( JSON.stringify(customerObj));
                $("#payment-details input").each(function(){
                console.log($(this).attr('name'));
                if ($(this).attr('name') =="" ){
                        return;
                }
                var paymentObj = {};
                paymentObj['type'] = $(this).attr('name');
                if ($(this).val() == ""){
                        paymentObj['amount'] = 0.0;
                }
                else{
                        paymentObj['amount'] = parseFloat($(this).val());
                }
                paymentOption.push(paymentObj);
                });
                console.log( JSON.stringify(paymentOption));
                
                var retObj = {};
                var dateOfBirth = $("form#cd input[name=dateOfBirth]").val();
                if(insurance){
                        retObj['customerDateOfBirth'] = (dateOfBirth)
                }
                retObj['fofoLineItems'] = (priceQtyArray);
                retObj['customer'] = (customerObj);
                retObj['paymentOptions'] =  (paymentOption);
                
                console.log(retObj);
                return  JSON.stringify(retObj);
}