Subversion Repositories SmartDukaan

Rev

Rev 24168 | View as "text/plain" | Blame | Compare with Previous | Last modification | View Log | RSS feed

$(function() {
        $(document).on('click', ".create-item", function() {
                loadCreateItem("main-content");
        });
        
        $(document).on('click', ".scan-in-items", function() {
                getAuthorisedWarehouses(function(warehouseId){
                        loadScanInItems(warehouseId, "main-content");
                });
        });
        
        $(document).on('click', ".scan-in-partner-items", function() {
                loadScanInPartnerItems("main-content");
        });

    $(document).on('click', ".scan-out-partner-items", function() {
        loadScanOutPartnerItems("main-content");
    });
        
        $(document).on('click', "#scanInPartnerItemButton", function() {
                var deliveryNoteId = $("#scanInPartnerItemModel .deliveryNoteId").text();
                var itemIdSerialNumbersMap = {};
                var itemIdQuantityMap = {};
                $('.itemIdSerialNumbersContainer').each(function(){
                        var itemId = $(this).find('.itemId').attr('itemId');
                        console.log("itemId : "+itemId);
                        var itemType = $(this).find('.itemId').attr('itemType');
                        if(itemType == 'SERIALIZED'){
                                $(this).find('.serialNumber').each(function(){
                                        var serialNumber = $(this).val();
                                        console.log(serialNumber);
                                        if(itemIdSerialNumbersMap[itemId] == undefined){
                                                itemIdSerialNumbersMap[itemId] = [];
                                        }
                                        itemIdSerialNumbersMap[itemId].push(serialNumber);
                                });
                        }else{
                                var quantity = $(this).find('.quantity').text();
                                console.log(quantity);
                                itemIdQuantityMap[itemId] = parseInt(quantity);
                        }
                });
                //console.log(itemIdSerialNumbersMap);
                //console.log(itemIdQuantityMap);
                var scanInPartnerItemRequest = {'deliveryNoteId' : deliveryNoteId, 'itemIdSerialNumbersMap' : itemIdSerialNumbersMap, 'itemIdQuantityMap' : itemIdQuantityMap};
                console.log(scanInPartnerItemRequest);
                submitScanInPartnerItem(scanInPartnerItemRequest);
                return false;
        });

    $(document).on('click', "#scanOutPartnerItemButton", function() {
        var itemId = $("#scanOutPartnerItemModel .itemId").val();
        var itemType = $("#scanOutPartnerItemModel .itemType").val();
        var serialNumber = null;
        if(itemType == 'SERIALIZED'){
            serialNumber = $("#itemSerialNumbers option:selected").val();
        }
        var firstName = $("#scanOutPartnerItemModel .firstName").val();
        if(firstName == ''){
            alert('Please enter first Name');
            //$("#scanOutPartnerItemModel .close").click();
            return;
        }
        var lastName = $("#scanOutPartnerItemModel .lastName").val();
        if(lastName == ""){
            alert('Please enter first Name');
            return;
        }
        var emailId = $("#scanOutPartnerItemModel .emailId").val();
        if(emailId == ""){
            alert('Please enter email Id');
            return;
        }
        var mobileNumber = $("#scanOutPartnerItemModel .mobileNumber").val();
        if(mobileNumber == ""){
            alert('Please enter mobile Number');
        }
        var line1 = $("#scanOutPartnerItemModel .line1").val();
        if(line1 == ""){
            alert('Please enter line1 address');
        }
        var line2 = $("#scanOutPartnerItemModel .line2").val();
        var landmark = $("#scanOutPartnerItemModel .landmark").val();
        var pinCode = $("#scanOutPartnerItemModel .pinCode").val();
        if(pinCode == ""){
            alert('Please enter pinCode');
        }
        var city = $("#scanOutPartnerItemModel .city").val();
        if(city == ""){
            alert('Please enter city name');
        }
        var state = $("#scanOutPartnerItemModel .state option:selected").val();
        if(state == ""){
            alert('Please choose state name');
        }
        var customerDetails = {};
        customerDetails['firstName'] = firstName;
        customerDetails['lastName'] = lastName;
        customerDetails['emailId'] = emailId;
        customerDetails['mobileNumber'] = mobileNumber;
        var address = {};
        address['name'] = firstName + ' ' + lastName;
        address['line1'] = line1;
        address['line2'] = line2;
        address['landmark'] = landmark;
        address['pinCode'] = pinCode;
        address['city'] = city;
        address['state'] = state;
        address['phoneNumber'] = mobileNumber;
        customerDetails['address'] = address;
        submitScanOutPartnerItem(itemId, serialNumber, customerDetails);
        return false;
    });

    $(document).on('click', "#scanOutPartnerItemResetButton", function() {
        $("#scanOutPartnerItemModel .firstName").val("");
        $("#scanOutPartnerItemModel .lastName").val("");
        $("#scanOutPartnerItemModel .emailId").val("");
        $("#scanOutPartnerItemModel .mobileNumber").val("");
        $("#scanOutPartnerItemModel .line1").val('');
        $("#scanOutPartnerItemModel .line2").val('');
        $("#scanOutPartnerItemModel .landmark").val('');
        $("#scanOutPartnerItemModel .pinCode").val('');
        $("#scanOutPartnerItemModel .city").val('');
        return false;
    });
        
        $(document).on("keyup", "#deliveryNoteId", function(e) {
                var keyCode = e.keyCode || e.which;
        if(keyCode == 13){
                scanInPartnerItemDialog();
        }
        });
        
        $(document).on('click', "#scanInItemButton", function() {
                var imeis = [];
                var error = false;
                var errorText = "";
                $("#serialNumberContainer :input").each(function(){
                        var input = $(this).val().trim();
                        if (imeis.indexOf(input) !=-1 || !input){
                                error = true;
                                if (!input){
                                        $(this).addClass("border-highlight");
                                }
                        }
                        imeis.push(input);
                        
                });
                if (error){
                        return false;
                }
                console.log("imeis : "+imeis);
                var itemId = $("#scanInItemModel .itemId").val();
                var warehouseId = $('#scanInItemModel .warehouseId').val();
                var quantity = $(".modal-body .itemQuantity>span").text();
                submitScanInItem(itemId, warehouseId, quantity, imeis);
                
                return false;
        });
        
        $(document).on('change', '#admin-warehouses', function(){
                var warehouseId = $(this).val();
                loadWarehouseInstructionItemsByWarehouseId("warehouse-instruction-items-container", warehouseId);
        });
        
        $(document).on('click', ".scan-out-items", function() {
                getAuthorisedWarehouses(function(warehouseId){
                        loadScanOutItems(warehouseId, "main-content");
                });
        });
        
        $(document).on('click', "#scanOutItemButton", function() {
                var warehouseId = $("#scanOutItemModel .warehouseId").val();
                if(warehouseId == ""){
                        alert("Please choose warehouse");
                        $("#scanOutItemModel .close").click();
                        return;
                }
                var userId = $("#scanOutItemModel .userId").val();
                if(userId == ""){
                        alert("Please choose user");
                        $("#scanOutItemModel .close").click();
                        return;
                }
                var instructionItemIdInstructionItemDetailMap = {};
                var instructionItemIds = [];
                var itemIdSerialNumbersMap = {};
                $("#instructionItemsContainer .instruction-item").each(function() {
                        var $instructionItem = $(this);
                        var instructionItemId = $instructionItem.find('.instructionItemId').text();
                        console.log("instructionItemId : "+instructionItemId);
                        instructionItemIds.push(instructionItemId);
                        $instructionItem.find('.instruction-item-detail').each(function(){
                                var $instructionItemDetail = $(this);
                                var itemId = $instructionItemDetail.find('.itemId').attr('itemId');
                                console.log("itemId : "+itemId);
                                var itemType = $instructionItemDetail.find('.itemId').attr('itemType');
                                console.log("itemType : "+itemType);
                                if(itemType == 'SERIALIZED'){
                                        $instructionItemDetail.find('.serialNumber').each(function(){
                                                var serialNumber = $(this).val();
                                                console.log("serialNumber : "+serialNumber);
                                                if(itemIdSerialNumbersMap[itemId] == undefined){
                                                        //var serialNumbers = [];
                                                        //serialNumbers.push(serialNumber);
                                                        itemIdSerialNumbersMap[itemId] = [];
                                                }
                                                itemIdSerialNumbersMap[itemId].push(serialNumber);
                                                
                                        });
                                }else{
                                        itemIdSerialNumbersMap[itemId] = [];
                                }
                        });
                });
                console.log(instructionItemIds);
                console.log(itemIdSerialNumbersMap);
                var scanOutItemRequest = {
                                        "warehouseId":parseInt(warehouseId),
                                        "userId":parseInt(userId),
                                        "instructionItemIds":instructionItemIds,
                                        "itemIdSerialNumbersMap":itemIdSerialNumbersMap
                                };
                console.log(scanOutItemRequest);
                submitScanOutItem(scanOutItemRequest);
                
                return false;
        });
        
        $(document).on('click', "#items-paginated .next", function() {
                loadPaginatedNextItems('/getPaginatedItems', null, 'items-paginated', 'items-table', null);
                $(this).blur();
    });
        
        $(document).on('click', "#items-paginated .previous", function() {
                loadPaginatedPreviousItems('/getPaginatedItems', null, 'items-paginated', 'items-table', null);
                $(this).blur();
    });
        
        $(document).on('click', "#scan-in-items-paginated .next", function() {
                var warehouseId = $('input[name="warehouseId]');
                loadPaginatedNextItems('/getPaginatedScanInItems/' + warehouseId, null, 'scan-in-items-paginated', 'scan-in-items-table', null);
                $(this).blur();
    });
        
        $(document).on('click', "#scan-in-items-paginated .previous", function() {
                loadPaginatedPreviousItems('/getPaginatedScanInItems', null, 'scan-in-items-paginated', 'scan-in-items-table', null);
                $(this).blur();
    });
        
        $(document).on('click', "#scan-out-items-paginated .next", function() {
                loadPaginatedNextItems('/getPaginatedScanOutItems', null, 'scan-out-items-paginated', 'scan-out-items-table', null);
                $(this).blur();
    });
        
        $(document).on('click', "#scan-out-items-paginated .previous", function() {
                loadPaginatedPreviousItems('/getPaginatedScanOutItems', null, 'scan-out-items-paginated', 'scan-out-items-table', null);
                $(this).blur();
    });
        
        $(document).on('click', "#scan-in-partner-items-paginated .next", function() {
                loadPaginatedNextItems('/getPaginatedScanInPartnerItems', null, 'scan-in-partner-items-paginated', 'scan-in-partner-items-table', null);
                $(this).blur();
    });
        
        $(document).on('click', "#scan-in-partner-items-paginated .previous", function() {
                loadPaginatedPreviousItems('/getPaginatedScanInPartnerItems', null, 'scan-in-partner-items-paginated', 'scan-in-partner-items-table', null);
                $(this).blur();
    });

    $(document).on('click', "#scan-out-partner-items-paginated .next", function() {
        loadPaginatedNextItems('/getPaginatedScanOutPartnerItems', null, 'scan-out-partner-items-paginated', 'scan-out-partner-items-table', null);
        $(this).blur();
    });

    $(document).on('click', "#scan-out-partner-items-paginated .previous", function() {
        loadPaginatedPreviousItems('/getPaginatedScanOutPartnerItems', null, 'scan-out-partner-items-paginated', 'scan-out-partner-items-table', null);
        $(this).blur();
    });
});

function scanInItemDialog(){
        var itemId = $('#items-for-scan-in').val();
        var itemDescription = $('#items-for-scan-in option:selected').text();
        var warehouseId = $('#warehouseId').val();
        var warehouseName = $('#warehouseName').val();
        var itemType = $('#items-for-scan-in option:selected').attr('itemType');
        var quantity = parseInt($('#quantity').val());
        if(quantity == undefined || quantity == "" || quantity <= 0 || isNaN(quantity)){
                quantity = 1;
        }
        $("#scanInItemModel .itemId").val(itemId);
        $("#scanInItemModel .warehouseId").val(warehouseId);
        
        $(".modal-body .itemInformation>span").text(itemDescription);
        $(".modal-body .warehouseName>span").text(warehouseName);
        
        $(".modal-body .itemQuantity>span").text(quantity);
        $( "#serialNumberContainer" ).empty();
        
        if(itemType == "SERIALIZED"){
                $(".modal-body .modal-title").text("Enter Serial Numbers");
                var qty = parseInt(quantity);
                var divCode = '<div class="row">CONTENT</div><p></p>';
                var innerDiv = '<div class="col-sm-3">'+
                '<div class="input-group">'+
                '<input type="text" class="form-control">'+
                '</div>'+
                '</div>';
                while(qty!=0){
                        var divText  = "";
                        if (qty < 4){
                                var cp = qty;
                                for (var i=0;i<cp;i++ ){
                                        divText = divText + innerDiv;
                                        qty = qty - 1;
                                }
                        }else{
                                for(var i=0;i<4;i++){
                                        divText = divText + innerDiv;
                                        qty = qty - 1;
                                }
                        }
                        divText = divCode.replace("CONTENT", divText); 
                        $("#serialNumberContainer")
                        .append(divText)
                }
        }else{
                $(".modal-body .modal-title").text("");
        }
        
}

function submitScanInItem(itemId, warehouseId, quantity, serialNumbers){
        var postData = JSON.stringify({"itemId":parseInt(itemId), "warehouseId":parseInt(warehouseId), "quantity":parseInt(quantity), "serialNumbers":serialNumbers});
        console.log(postData);
        doPostAjaxRequestWithJsonHandler(context+"/scanInItems", postData, function(response){
                $('#main-content').html(response);
                alert("Scanned in successfully");
        });
}

function scanOutItemDialog(){
        var warehouseId = $('#admin-warehouses-for-scan-out').val();
        var warehouseName = $('#admin-warehouses-for-scan-out option:selected').text();
        var userId = $('#fofo-users').val();
        var emailId = $('#fofo-users option:selected').text();
        console.log("warehouseId : "+warehouseId);
        console.log("warehouseName : "+warehouseName);
        console.log("userId : "+userId);
        console.log("emailId : "+emailId);
        
        $("#scanOutItemModel .warehouseId").val(warehouseId);
        $("#scanOutItemModel .userId").val(userId);
        
        $(".modal-body .warehouseInformation>span").text(warehouseName);
        $(".modal-body .userInformation>span").text(emailId);
        $( "#instructionItemsContainer" ).empty();
        
        loadPendingInstructionItemsByWarehouseIdAndUserId('instructionItemsContainer', warehouseId, userId);
        
}

function submitScanOutItem(scanOutItemRequest){
        var postData = JSON.stringify(scanOutItemRequest);
        doPostAjaxRequestWithJsonHandler(context+"/scanOutItems", postData, function(response){
                $('#main-content').html(response);
                alert("Scanned out successfully");
        });
}

function scanInPartnerItemDialog(){
        var deliveryNoteId = $('#deliveryNoteId').val();
        
        console.log("deliveryNoteId : "+deliveryNoteId);
        
        loadAdminDeliveryNoteDetails("delivery-note-details-container", deliveryNoteId);
}

function submitScanInPartnerItem(scanInPartnerItemRequest){
        doPostAjaxRequestWithJsonHandler(context+'/scanInPartnerItems', JSON.stringify(scanInPartnerItemRequest), function(response){
                $('#main-content').html(response);
                alert("Scanned in successfully");
        });
}

function scanOutPartnerItemDialog(){
    var itemId = $('#scan-out-partner-items').val();
    var itemDescription = $('#scan-out-partner-items option:selected').text();
    var itemType = $('#scan-out-partner-items option:selected').attr('itemType');
    var quantity = $('#scan-out-partner-items option:selected').attr('quantity');
    
    console.log("itemId : "+itemId);
    console.log("itemDescription : "+itemDescription);
    console.log("itemType : "+itemType);
    console.log("quantity : "+quantity);

    $("#scanOutPartnerItemModel .itemId").val(itemId);
    $("#scanOutPartnerItemModel .itemType").val(itemType);
    
    $(".modal-body .itemInformation>span").text(itemDescription);
    $( "#serialNumberContainer" ).empty();
    
    if(itemType == "SERIALIZED"){
        $(".modal-body .modal-title").text("Enter Serial Numbers");
                var qty = parseInt(quantity);
                var divCode = '<div class="row">CONTENT</div><p></p>';
                var innerDiv = '<div class="col-sm-3">'+
                '<div class="input-group">'+
                '<input type="text" class="form-control">'+
                '</div>'+
                '</div>';
                while(qty!=0){
                        var divText  = "";
                        if (qty < 4){
                                var cp = qty;
                                for (var i=0;i<cp;i++ ){
                                        divText = divText + innerDiv;
                                        qty = qty - 1;
                                }
                        }else{
                                for(var i=0;i<4;i++){
                                        divText = divText + innerDiv;
                                        qty = qty - 1;
                                }
                        }
                        divText = divCode.replace("CONTENT", divText); 
                        $("#serialNumberContainer")
                        .append(divText)
                }
        //loadItemSerialNumbers('serialNumberContainer', itemId);
    }else{
        $(".modal-body .modal-title").text("Quantity : "+quantity);
    }

}

function submitScanOutPartnerItem(itemId, serialNumber, customerDetails){
    var postData = JSON.stringify({"itemId":parseInt(itemId), "serialNumber":serialNumber, "customerDetails":customerDetails});
    doPostAjaxRequestWithJsonHandler(context+"/scanOutPartnerItem", postData, function(response){
        $('#main-content').html(response);
        alert("Scanned out successfully");
    });
}

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

function loadScanInItems(warehouseId, domId){
        doGetAjaxRequestHandler(context+"/getScanInItems/" + warehouseId, function(response){
                $('#' + domId).html(response);
        });
}

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

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


function loadScanOutItems(warehouseId, domId){
        doGetAjaxRequestHandler(context+"/getScanOutItems/" + warehouseId, function(response){
                $('#' + domId).html(response);
        });
}

function loadWarehouseItemSerialNumbers(domId, itemId, warehouseId){
        doGetAjaxRequestHandler(context+"/getSerialNumbersByItemIdWarehouseId?itemId="+itemId+"&warehouseId="+warehouseId, function(response){
                $('#' + domId).html(response);
                configureItemSerialNumbersDropDown();
        });
}

function loadPendingInstructionItemsByWarehouseIdAndUserId(domId, warehouseId, userId){
        doGetAjaxRequestHandler(context+"/getPendingInstructionItems?userId="+userId+"&warehouseId="+warehouseId, function(response){
                $('#' + domId).html(response);
        });
}

function loadItemSerialNumbers(domId, itemId){
    doGetAjaxRequestHandler(context+"/getSerialNumbersByItemId?itemId="+itemId, function(response){
        $('#' + domId).html(response);
        configureItemSerialNumbersDropDown();
    });
}

function loadAdminDeliveryNoteDetails(domId, deliveryNoteId){
        doGetAjaxRequestHandler(context+"/deliveryNoteDetails?deliveryNoteId="+deliveryNoteId, function(response){
                $('#' + domId).html(response);
        });
}

function configureVendorsDropDown(){
        $(document).ready(function() {
        $('#vendors').multiselect({
                multiple:false,
                includeSelectAllOption: true,
                maxHeight: 200,
                buttonWidth: '270px',
                numberDisplayed: 1,
                nonSelectedText: 'Vendors',
                nSelectedText: ' - Vendors Selected',
                allSelectedText: 'All Vendors Selected',
                enableFiltering: true
        });
    });
}

function configureScanOutPartnerItemsDropDown(){
    $(document).ready(function() {
        $('#scan-out-partner-items').multiselect({
            multiple:false,
            includeSelectAllOption: true,
            maxHeight: 200,
            buttonWidth: '280px',
            numberDisplayed: 1,
            nonSelectedText: 'Items',
            nSelectedText: ' - Items Selected',
            allSelectedText: 'All Items Selected',
            enableFiltering: true
        });
    });
}

function configureItemsForScanInDropDown(){
        $(document).ready(function() {
        $('#items-for-scan-in').multiselect({
                multiple:false,
                includeSelectAllOption: true,
                maxHeight: 200,
                buttonWidth: '280px',
                numberDisplayed: 1,
                nonSelectedText: 'Items',
                nSelectedText: ' - Items Selected',
                allSelectedText: 'All Items Selected',
                enableFiltering: true
        });
    });
}

function configureWarehouseItemsDropDown(){
        $(document).ready(function() {
        $('#warehouse-items').multiselect({
                multiple:true,
                includeSelectAllOption: true,
                maxHeight: 200,
                buttonWidth: '200px',
                numberDisplayed: 1,
                nonSelectedText: 'Items',
                nSelectedText: ' - Items Selected',
                allSelectedText: 'All Items Selected',
                enableFiltering: true
        });
    });
}

function configureWarehousesForScanInDropDown(){
        $(document).ready(function() {
        $('#warehouses-for-scan-in').multiselect({
                multiple:false,
                includeSelectAllOption: true,
                maxHeight: 200,
                buttonWidth: '200px',
                numberDisplayed: 1,
                nonSelectedText: 'Warehouses',
                nSelectedText: ' - Warehouses Selected',
                allSelectedText: 'All Warehouses Selected',
                enableFiltering: true
        });
    });
}

function configureWarehousesForScanOutDropDown(){
        $(document).ready(function() {
        $('#admin-warehouses-for-scan-out').multiselect({
                multiple:false,
                includeSelectAllOption: true,
                maxHeight: 200,
                buttonWidth: '200px',
                numberDisplayed: 1,
                nonSelectedText: 'Warehouses',
                nSelectedText: ' - Warehouses Selected',
                allSelectedText: 'All Warehouses Selected',
                enableFiltering: true
        });
    });
}

function configureFofoUsersDropDown(){
        $(document).ready(function() {
        $('#fofo-users').multiselect({
                multiple:false,
                includeSelectAllOption: true,
                maxHeight: 200,
                buttonWidth: '200px',
                numberDisplayed: 1,
                nonSelectedText: 'Users',
                nSelectedText: ' - Users Selected',
                allSelectedText: 'All Users Selected',
                enableFiltering: true
        });
    });
}

function configureItemSerialNumbersDropDown(){
        $(document).ready(function() {
        $('#itemSerialNumbers').multiselect({
                includeSelectAllOption: true,
                multiple:true,
                maxHeight: 200,
                buttonWidth: '350px',
                numberDisplayed: 1,
                nonSelectedText: 'Serial Numbers',
                nSelectedText: ' - Serial Numbers Selected',
                allSelectedText: 'All Serial Numbers Selected',
                enableFiltering: true
        });
    });
}