Subversion Repositories SmartDukaan

Rev

Rev 24152 | Rev 25093 | Go to most recent revision | View as "text/plain" | Blame | Compare with Previous | Last modification | View Log | RSS feed

var saleHistory = saleHistory || {};
saleHistory.searchText = "";
saleHistory.searchType = "";
saleHistory.startTime = "";
saleHistory.endTime = "";

$(function() {

        $(".sale-history").live('click', function() {
                console.log("Sale History Button Clicked...")
                saleHistory("main-content", "", "", startDate, endDate);
        });

        $(".insurance-policy-details").live('click', function() {
                console.log("insurance-policy-details");
                insurancePolicyDetails("main-content");
        });

        $(".updatePaymentDetails")
                        .live(
                                        'click',
                                        function() {
                                                console
                                                                .log("updatePaymentDetails target Button Clicked...");
                                                var i = 1;
                                                var changedTotalAmount = 0;
                                                var invoiceNumber = $(this).data('invoicenumber');
                                                var fofoId = $(this).data('fofoid');

                                                var totalNumberOfPaymentOptionId = $(this).data(
                                                                'totalnumberofpaymentoptionid');
                                                console.log("totalNumberOfPaymentOptionId"
                                                                + totalNumberOfPaymentOptionId);
                                                var referenceId = $(this).data('orderid');
                                                var referenceType = "ORDER";
                                                var createdTimeStamp = $(this).data('createddatetime');
                                                console.log(createdTimeStamp);
                                                console.log(fofoId);
                                                console.log(referenceId);
                                                console.log(invoiceNumber);
                                                console.log(referenceType);
                                                var paymentOptionTransactionModels = [];
                                                var inputvalues = {};
                                                $('.paymentOptions input')
                                                                .each(
                                                                                function() {
                                                                                        console.log($(this).val())
                                                                                        if (!isFinite($(this).val())) {
                                                                                                return;
                                                                                        }
                                                                                        inputvalues = {};
                                                                                        inputvalues['paymentOptionId'] = $(
                                                                                                        this).data(
                                                                                                        'payment-option-id');
                                                                                        inputvalues['amount'] = $(this)
                                                                                                        .val();
                                                                                        inputvalues['createdTimeStamp'] = createdTimeStamp;
                                                                                        console
                                                                                                        .log(inputvalues['createdTimeStamp']);
                                                                                        if (!inputvalues['amount']) {
                                                                                                inputvalues['amount'] = "0";
                                                                                        }
                                                                                        console.log("inputvalues['amount']"
                                                                                                        + inputvalues['amount']);
                                                                                        paymentOptionTransactionModels
                                                                                                        .push(inputvalues);
                                                                                });
                                                if (paymentOptionTransactionModels.length != totalNumberOfPaymentOptionId) {
                                                        alert("Sending less or more paymentOptionIds for"
                                                                        + fofoId);
                                                        return false;
                                                }
                                                console.log(paymentOptionTransactionModels);
                                                if (confirm("Are you sure you want to update paymentTransaction!") == true) {
                                                        doPutAjaxRequestWithJsonHandler(
                                                                        context
                                                                                        + "/updatePaymentTransaction?referenceId="
                                                                                        + referenceId + "&referenceType="
                                                                                        + referenceType + "&fofoId="
                                                                                        + fofoId,
                                                                        JSON
                                                                                        .stringify(paymentOptionTransactionModels),
                                                                        function(response) {
                                                                                if (response === 'true') {
                                                                                        alert("successfully added");
                                                                                        loadSearchOrderDetails(
                                                                                                        invoiceNumber,
                                                                                                        "search-order-details-container");
                                                                                }
                                                                        });
                                                }

                                        });

        $('#searchType').live(
                        'change',
                        function() {
                                var searchType = $("#searchType option:selected").val();
                                var searchTypevalue = $(this).find('option:selected').text();
                                ;
                                saleHistory.searchType = searchType;
                                console.log("selected searchType = " + searchType);

                                saleHistory("main-content", saleHistory.searchType, "",
                                                startDate, endDate);

                                $("#sale-history-search-text").val('');
                        });

        $("#sale-history-search-button").live(
                        'click',
                        function() {
                                console.log("sale-history-search-button clicked")
                                var searchType = $("#searchType option:selected").val();
                                console.log("searchType = " + searchType);
                                $("#searchType").removeClass("border-highlight");
                                // if(searchType == ""){
                                // alert("Please choose Search Type");
                                // $("#searchType").addClass("border-highlight");
                                // }else{
                                saleHistory.searchText = $("#sale-history-search-text").val();
                                saleHistory.searchType = searchType;
                                saleHistory.startTime = startDate;
                                saleHistory.endTime = endDate;
                                if (typeof (saleHistory.searchText) == "undefined"
                                                || !saleHistory.searchText) {
                                        saleHistory.searchText = "";
                                }
                                saleHistorySearchInfo(saleHistory.searchType,
                                                saleHistory.searchText, saleHistory.startTime,
                                                saleHistory.endTime);
                                // $("#sale-history-search-text").val(saleHistory.searchText);
                                // $("#searchType").val(searchType);
                                // $('input[name="startDateTime"]').val(saleHistory.startTime);
                                // $('input[name="endDateTime"]').val(saleHistory.endTime);
                                // }
                        });

        $(".search-order").live('click', function() {
                console.log("search-order clicked")
                loadSearchOrder("main-content");
        });

        $("#search-order-button").live(
                        'click',
                        function() {
                                console.log("search-order-button clicked")
                                var invoiceNumber = $("#search-order-text").val();
                                loadSearchOrderDetails(invoiceNumber,
                                                "search-order-details-container");
                        });

        $("#sale-history-paginated .next").live(
                        'click',
                        function() {
                                var params = {};
                                params['searchType'] = saleHistory.searchType;
                                params['searchValue'] = saleHistory.searchText;
                                params['startTime'] = walletHistory.startTime;
                                params['endTime'] = walletHistory.endTime;
                                loadPaginatedNextItems('/getPaginatedSaleHistory', params,
                                                'sale-history-paginated', 'sale-history-table',
                                                'sale-details-container');
                                $(this).blur();
                        });
        $("#insurance-paginated .next").live(
                        'click',
                        function() {
                                loadPaginatedNextItems('/insuranceDetailsPaginated', null,
                                                'insurance-paginated', 'insurance-details-table',
                                                'insurance-policy-details-container');
                                $(this).blur();
                        });
        $("#insurance-paginated .previous").live(
                        'click',
                        function() {
                                loadPaginatedNextItems('/insuranceDetailsPaginated', null,
                                                'insurance-paginated', 'insurance-details-table',
                                                'insurance-policy-details-container');
                                $(this).blur();
                        });

        $("#sale-history-paginated .previous").live(
                        'click',
                        function() {
                                var params = {};
                                params['searchType'] = saleHistory.searchType;
                                params['searchValue'] = saleHistory.searchText;
                                params['startTime'] = walletHistory.startTime;
                                params['endTime'] = walletHistory.endTime;
                                loadPaginatedPreviousItems('/getPaginatedSaleHistory', params,
                                                'sale-history-paginated', 'sale-history-table',
                                                'sale-details-container');
                                $(this).blur();
                        });

        // grn-details

        $(".sale-details").live('click', function() {
                orderId = $(this).attr('data');
                console.log("orderId = " + orderId);
                loadSaleDetails(orderId, "sale-details-container");
        });
});

function loadSaleDetails(orderId, domId) {
        doGetAjaxRequestHandler(context + "/saleDetails?orderId=" + orderId,
                        function(response) {
                                $('#' + domId).html(response);
                        });
}

function loadSearchOrder(domId) {
        doGetAjaxRequestHandler(context + "/getSearchOrder", function(response) {
                $('#' + domId).html(response);
        });
}

function loadSearchOrderDetails(invoiceNumber, domId) {
        doGetAjaxRequestHandler(context + "/searchOrderDetails?invoiceNumber="
                        + invoiceNumber, function(response) {
                $('#' + domId).html(response);
        });
}

function saleHistory(domId, searchType, searchValue, startTime, endTime) {
        doGetAjaxRequestHandler(context + "/saleHistory?searchType=" + searchType
                        + "&searchValue=" + searchValue + "&startTime=" + startTime
                        + "&endTime=" + endTime, function(response) {
                $('#' + domId).html(response);
        });
}

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

}
function insurancePolicyDetails(domId) {
        doGetAjaxRequestHandler(context + "/insuranceDetails", function(response) {
                $('#' + domId).html(response);
        });
}