Subversion Repositories SmartDukaan

Rev

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

$(function() {
        $(".create-item").live('click', function() {
                loadCreateItem("main-content");
        });
        
        $(".scan-in-items").live('click', function() {
                loadScanInItems("main-content");
        });
        
        $(".scan-in-partner-items").live('click', function() {
                loadScanInPartnerItems("main-content");
        });
        
        $("#scanInPartnerItemButton").live('click', function() {
                var deliveryNoteId = $("#scanInPartnerItemModel .deliveryNoteId").val();
                submitScanInPartnerItem(deliveryNoteId);
                return false;
        });
        
        $("#deliveryNoteId").live("keyup", function(e) {
                var keyCode = e.keyCode || e.which;
        if(keyCode == 13){
                scanInPartnerItemDialog();
        }
        });
        
        $("#scanInItemButton").live('click', 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 quantity = $(".modal-body .itemQuantity>span").text();
                var reserved = $(".modal-body .itemReservedQuantity>span").text();
                submitScanInItem(itemId, quantity, reserved, imeis);
                
                return false;
        });
        
        $('#warehouses').live('change', function(){
                var warehouseId = $(this).val();
                loadItemsItemsByWarehouseId("warehouse-items-container", warehouseId);
        });
        
        $(".scan-out-items").live('click', function() {
                loadScanOutItems("main-content");
        });
        
        $("#scanOutItemButton").live('click', function() {
                var itemId = $("#scanOutItemModel .itemId").val();
                if(itemId == ""){
                        alert("Please choose item");
                        $("#scanOutItemModel .close").click();
                        return;
                }
                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 quantity = $(".modal-body .itemQuantity>span").text();
                var itemType = $("#scanOutItemModel .itemType").val();
                var imeis = [];
                if(itemType == 'SERIALIZED'){
                        imeis = $("#itemSerialNumbers").val();
                        console.log("imeis : "+imeis);
                        if(imeis.length > quantity){
                                alert("Serial numbers can not choosen more than quantity");
                                return;
                        }
                }
                
                submitScanOutItem(itemId, warehouseId, userId, quantity, imeis);
                
                return false;
        });
        
        $("#items-paginated .next").live('click', function() {
                loadPaginatedNextItems('/getPaginatedItems', null, 'items-paginated', 'items-table', null);
                $(this).blur();
    });
        
        $("#items-paginated .previous").live('click', function() {
                loadPaginatedPreviousItems('/getPaginatedItems', null, 'items-paginated', 'items-table', null);
                $(this).blur();
    });
        
        $("#scan-in-items-paginated .next").live('click', function() {
                loadPaginatedNextItems('/getPaginatedScanInItems', null, 'scan-in-items-paginated', 'scan-in-items-table', null);
                $(this).blur();
    });
        
        $("#scan-in-items-paginated .previous").live('click', function() {
                loadPaginatedPreviousItems('/getPaginatedScanInItems', null, 'scan-in-items-paginated', 'scan-in-items-table', null);
                $(this).blur();
    });
        
        $("#scan-out-items-paginated .next").live('click', function() {
                loadPaginatedNextItems('/getPaginatedScanOutItems', null, 'scan-out-items-paginated', 'scan-out-items-table', null);
                $(this).blur();
    });
        
        $("#scan-out-items-paginated .previous").live('click', function() {
                loadPaginatedPreviousItems('/getPaginatedScanOutItems', null, 'scan-out-items-paginated', 'scan-out-items-table', null);
                $(this).blur();
    });
        
        $("#scan-in-partner-items-paginated .next").live('click', function() {
                loadPaginatedNextItems('/getPaginatedScanInPartnerItems', null, 'scan-in-partner-items-paginated', 'scan-in-partner-items-table', null);
                $(this).blur();
    });
        
        $("#scan-in-partner-items-paginated .previous").live('click', function() {
                loadPaginatedPreviousItems('/getPaginatedScanInPartnerItems', null, 'scan-in-partner-items-paginated', 'scan-in-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 itemType = $('#items-for-scan-in option:selected').attr('itemType');
        var quantity = parseInt($('#quantity').val());
        if(quantity == undefined || quantity == "" || quantity <= 0 || isNaN(quantity)){
                quantity = 1;
        }
        var reserved = parseInt($('#reserved').val());
        if(reserved == undefined || reserved == "" || reserved <0 || isNaN(reserved)){
                reserved = 0;
        }
        console.log("itemId : "+itemId);
        console.log("itemDescription : "+itemDescription);
        console.log("itemType : "+itemType);
        console.log("quantity : "+quantity);
        console.log("reserved : "+reserved);
        
        $("#scanInItemModel .itemId").val(itemId);
        
        $(".modal-body .itemInformation>span").text(itemDescription);
        $(".modal-body .itemQuantity>span").text(quantity);
        $(".modal-body .itemReservedQuantity>span").text(reserved);
        $( "#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, quantity, reserved, serialNumbers){
        var postData = JSON.stringify({"itemId":parseInt(itemId), "quantity":parseInt(quantity), "reserved":parseInt(reserved), "serialNumbers":serialNumbers});
        doPostAjaxRequestWithJsonHandler(context+"/scanInItems", postData, function(response){
                $('#main-content').html(response);
                alert("Scanned in successfully");
        });
}

function scanOutItemDialog(){
        var itemId = $('#warehouse-items').val();
        var itemDescription = $('#warehouse-items option:selected').text();
        var itemType = $('#warehouse-items option:selected').attr('itemType');
        var warehouseId = $('#warehouses').val();
        var warehouseName = $('#warehouses option:selected').text();
        var userId = $('#fofo-users').val();
        var emailId = $('#fofo-users option:selected').text();
        var quantity = parseInt($('#quantity').val());
        if(quantity == undefined || quantity == "" || quantity <= 0 || isNaN(quantity)){
                quantity = 1;
        }
        console.log("itemId : "+itemId);
        console.log("itemDescription : "+itemDescription);
        console.log("itemType : "+itemType);
        console.log("warehouseId : "+warehouseId);
        console.log("warehouseName : "+warehouseName);
        console.log("userId : "+userId);
        console.log("emailId : "+emailId);
        console.log("quantity : "+quantity);
        
        $("#scanOutItemModel .itemId").val(itemId);
        $("#scanOutItemModel .itemType").val(itemType);
        $("#scanOutItemModel .warehouseId").val(warehouseId);
        $("#scanOutItemModel .userId").val(userId);
        
        $(".modal-body .itemInformation>span").text(itemDescription);
        $(".modal-body .warehouseInformation>span").text(warehouseName);
        $(".modal-body .userInformation>span").text(emailId);
        $(".modal-body .itemQuantity>span").text(quantity);
        $( "#serialNumberContainer" ).empty();
        
        if(itemType == "SERIALIZED"){
                loadItemSerialNumbers('serialNumberContainer', itemId, warehouseId);
        }else{
                $(".modal-body .modal-title").text("");
        }
        
}

function submitScanOutItem(itemId, warehouseId, userId, quantity, imeis){
        var postData = JSON.stringify({"itemId":parseInt(itemId), "warehouseId":parseInt(warehouseId), "userId":parseInt(userId), "quantity":parseInt(quantity), "serialNumbers":imeis});
        doPostAjaxRequestWithJsonHandler(context+"/scanOutItems", postData, function(response){
                $('#main-content').html(response);
                alert("Scanned out successfully");
        });
}

function scanInPartnerItemDialog(){
        var deliveryNoteId = $('#deliveryNoteId').val();
        
        console.log("deliveryNoteId : "+deliveryNoteId);
        
        $("#scanInPartnerItemModel .deliveryNoteId").val(deliveryNoteId);
        $(".modal-body .deliveryNoteInformation>span").text(deliveryNoteId);
        
        loadAdminDeliveryNoteDetails(deliveryNoteId);
}

function submitScanInPartnerItem(deliveryNoteId){
        doGetAjaxRequestHandler(context+"/scanInPartnerItems?deliveryNoteId="+deliveryNoteId, function(response){
                $('#main-content').html(response);
                alert("Scanned in successfully");
        });
}

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

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

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

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

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

function loadAdminDeliveryNoteDetails(deliveryNoteId){
        doGetAjaxRequestHandler(context+"/deliveryNoteDetails?deliveryNoteId="+deliveryNoteId, function(response){
                response = response.response;
                console.log(response);
                $(".modal-body .warehouseInformation>span").text(response.warehouseName);
                $(".modal-body .itemInformation>span").text(response.itemDescription);
                $(".modal-body .serialNumberInformation>span").text(response.serialNumber);
                $(".modal-body .itemQuantity>span").text(response.quantity);
        });
}

function loadItemsItemsByWarehouseId(domId, warehouseId){
        doGetAjaxRequestHandler(context+"/getItemsByWarehouseId?warehouseId="+warehouseId, function(response){
                $('#' + domId).html(response);
                configureWarehouseItemsDropDown();
        });
}

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 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:false,
                includeSelectAllOption: true,
                maxHeight: 200,
                buttonWidth: '200px',
                numberDisplayed: 1,
                nonSelectedText: 'Items',
                nSelectedText: ' - Items Selected',
                allSelectedText: 'All Items Selected',
                enableFiltering: true
        });
    });
}

function configureWarehousesDropDown(){
        $(document).ready(function() {
        $('#warehouses').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
        });
    });
}