Subversion Repositories SmartDukaan

Rev

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

$(function() {
        $(document).on('click',"a.allocation_po", function() {
                currentFofoId = 0;
                counterSize = '';
                loadIndent('main-content');
        });
        $("button.mk_pause_button")
                        .live(
                                        'click',
                                        function() {
                                                var clickedButton = $(this);

                                                var description = clickedButton.data("description");
                                                var catalogId = clickedButton.data("id");
                                                getColorsForItems(
                                                                catalogId,
                                                                0,
                                                                "Active/pause " + description,
                                                                function(itemIds) {
                                                                        console.log(itemIds);
                                                                        if (itemIds != null) {
                                                                                bootbox
                                                                                                .confirm(
                                                                                                                "Confirm Update "
                                                                                                                                + clickedButton
                                                                                                                                                .data("description")
                                                                                                                                + "?",
                                                                                                                function(result) {
                                                                                                                        if (result) {
                                                                                                                                coloredItems
                                                                                                                                                .forEach(function(
                                                                                                                                                                item) {
                                                                                                                                                        item.active = itemIds
                                                                                                                                                                        .indexOf(item.id
                                                                                                                                                                                        + "") >= 0;
                                                                                                                                                        console
                                                                                                                                                                        .log(coloredItems)
                                                                                                                                                });

                                                                                                                                doPostAjaxRequestWithJsonHandler(
                                                                                                                                                context
                                                                                                                                                                + "/indent/confirm-pause/",
                                                                                                                                                JSON
                                                                                                                                                                .stringify(coloredItems),
                                                                                                                                                function(
                                                                                                                                                                response) {
                                                                                                                                                        if (response) {
                                                                                                                                                                bootbox
                                                                                                                                                                                .alert("Item/s  Updated Successfully");
                                                                                                                                                        } else {
                                                                                                                                                                bootbox
                                                                                                                                                                                .alert("Could not pause item");
                                                                                                                                                        }

                                                                                                                                                });
                                                                                                                        }
                                                                                                                });
                                                                        }
                                                                });
                                        });
        $("button.raise_po").live('click', function() {
                if (confirm("Please confirm the PO")) {
                        raisePO();
                } else {
                        return;
                }
        });

        $("li.mk_counter_size").live('click', function() {
                if ($(this).hasClass('active')) {
                        return;
                }
                currentFofoId = 0;
                counterSize = $(this).find('a').html();
                loadIndent('main-content');
        });
        $("li.brandLi").live('click', function() {
                if (!$(this).hasClass('active')) {
                        $("table.brandPerformance").toggle();
                        $("li.brandLi").removeClass('active');
                        $(this).addClass('active');
                }
        });
        
        $(".previous-month").live('click',function(){
                currentFofoId = 0;
                counterSize = '';
                loadPreviousMonthIndent('main-content');
        });
        
        $(".current-month").live('click',function(){
                currentFofoId = 0;
                counterSize = '';
                loadIndent('main-content');
        });
        $(document).on('click','a.create_indent',  function() {
                currentFofoId = 0;
                counterSize = '';
                loadIndent("main-content");
        });
        $("button.create_indent").live('click', function() {
                loadIndent("main-content");
        });

        $("button.download_indent").live('click', function() {
                downloadIndent();
        })

        $(document).on('change', "#entire-catalog-table input",
                                                function() {
                                                        var catalogId = parseInt($(this).data("catalog-id"));
                                                        var sellingPrice = parseInt($(this).data(
                                                                        "selling-price"));
                                                        var quantity = parseInt($(this).val());
                                                        if (quantity > 40) {
                                                                alert("Quantity should not be above 40");
                                                                if (catalogId in indentMap) {
                                                                        $(this).val(indentMap[catalogId].quantity);
                                                                } else {
                                                                        $(this).val(0);
                                                                }
                                                                return;
                                                        }
                                                        brandName = $(this).data("brand-name");
                                                        description = $(this).data("description");
                                                        if (!(brandName in indentMap)) {
                                                                indentMap[brandName] = {};
                                                        }
                                                        if (catalogId in indentMap[brandName]) {
                                                                indentMap[brandName][catalogId]["quantity"] = quantity;
                                                                indentMap[brandName][catalogId]["sellingPrice"] = sellingPrice;
                                                                indentMap[brandName][catalogId]["description"] = description;
                                                                indentMap[brandName][catalogId]["catalogId"] = catalogId;
                                                                indentMap[brandName][catalogId]["diff"] = quantity
                                                                                - indentMap[brandName][catalogId]["initialQuantity"];
                                                        } else {
                                                                indentMap[brandName][catalogId] = {
                                                                        "quantity" : quantity,
                                                                        "sellingPrice" : sellingPrice,
                                                                        "description" : description,
                                                                        "catalogId" : catalogId,
                                                                        "initialQuantity" : 0,
                                                                        "diff" : quantity
                                                                };
                                                        }

                                                        console.log(indentMap);
                                                        
                                                        doPostAjaxRequestHandler(context
                                                                        + "/open-indent/save?catalogId="+catalogId+"&itemQty="+quantity
                                                                        , function(response) {
                                                                console.log(response);
                                                                if (response == 'true') {
                                                                }
                                                        });
                                                        populateIndentSummary();
                                });
        


        
         /*
                 * $("button.mk_submit_indent") .live( 'click', function() {
                 * confirmString =[]; confirmString .push('<table class="table
                 * table-striped table-condensed table-bordered"
                 * id="entire-catalog-table">'); confirmString.push('<tr>');
                 * confirmString .push('<th style="width:100px">Catalog Id</th>');
                 * confirmString .push('<th style="width:250px">Description</th>');
                 * confirmString .push('<th style="width:150px">Unit Price</th>');
                 * confirmString .push('<th style="width:150px">Quantity</th>');
                 * confirmString .push('<th style="width:200px">Item total</th>');
                 * confirmString.push('</tr>'); changedItemIds
                 * .forEach(function(itemId) {
                 * 
                 * confirmString .push('<tr style="background-color:#9C7D7E">');
                 * confirmString.push('<td>' + itemId + '</td>');
                 * confirmString.push('<td>' +indentMap[itemId].description + '</td>');
                 * confirmString .push('<td style="text-align:left">' +
                 * numberToComma(indentMap[itemId].sellingPrice) + '</td>');
                 * confirmString.push('<td style="text-align:left">' +
                 * indentMap[itemId].quantity + '(' +(indentMap[itemId].diff > 0 ? '+' :
                 * '-') + Math.abs(indentMap[itemId].diff) + ' pcs)</td>');
                 * confirmString .push('<td style="text-align:left">'
                 * +numberToComma(indentMap[itemId].quantity,
                 * indentMap[itemId].sellingPrice) + '</td>'); confirmString.push('</tr>');
                 * });
                 * 
                 * 
                 * 
                 * for ( var itemId in indentMap) { if(itemId.indexOf(changedItemIds) >
                 * 0) { continue; } if(indentMap[itemId].quantity > 0) {
                 * confirmString.push('<tr>'); confirmString.push('<td>' + itemId + '</td>');
                 * confirmString.push('<td>' +indentMap[itemId].description + '</td>');
                 * confirmString .push('<td style="text-align:left">' +
                 * numberToComma(indentMap[itemId].sellingPrice) + '</td>');
                 * confirmString.push('<td style="text-align:left">' +
                 * indentMap[itemId].quantity + '</td>'); confirmString .push('<td style="text-align:left">' +
                 * numberToComma(indentMap[itemId].quantity
                 * ,indentMap[itemId].sellingPrice) + '</td>'); confirmString.push('</tr>'); } }
                 * confirmString.push('</table>');
                 * $('#indent-container1').html(confirmString.join('')) .show();
                 * $('#indent-container').hide(); $('button.mk_submit_indent').hide();
                 * $('button.bk_toedit_indent').show();
                 * $('button.confirm_indent').show();
                 */
                  /*
                         * $("button.confirm_indent").live( 'click', function() { var
                         * itemQtyList = []; for (catalogId in indentMap) { diff =
                         * indentMap[catalogId]["quantity"] -
                         * indentMap[catalogId]["initialQuantity"]; if (diff != 0) {
                         * itemQtyList.push({ "quantity" : indentMap[catalogId]["quantity"],
                         * "catalogId" : indentMap[catalogId]["catalogId"] }); } }
                         * doPostAjaxRequestWithJsonHandler(context +
                         * "/open-indent/save?fofoId=" + currentFofoId + "&counxterSize=" +
                         * counterSize, JSON .stringify(itemQtyList), function(data) {
                         * alert('Indent has been created Successfully!'); indentMap = {};
                         * loadIndent('main-content'); }); });
                         */
        
        $(".confirm_indent").live(
                        'click',
                        function() {
                          if(confirm("Are you sure to confirm the indent")== true){
                         doPostAjaxRequestHandler(context + "/open-indent/confirm" ,
                          function(response) { 
                                  
                          console.log(response); 
                          if (response =='true') { 
                                  alert("successfully confirm"); 
                                  loadIndent('main-content');
                          } 
             }); 
                         
        
                          }
 });
                
        /*
         * $("button.bk_toedit_indent").live('click', function() {
         * $('button.bk_toedit_indent').hide(); $('button.confirm_indent').hide();
         * $('button.mk_submit_indent').show(); $('#indent-container1').hide();
         * $('#indent-container').show();
         * 
         * });
         */

});

function populateIndentSummary() {
        $planSummary = $("#plansummary");

        $planSummary.html('');
        changedItemIds=[];
        htmArr = [];
        $('button.confirm_indent').hide();
        for ( var brandName in indentMap) {

                
                allZero = true;
                trArray = [];
        
                for ( var itemId in indentMap[brandName]) {
                        var description = indentMap[brandName][itemId]['description'];

                        var itemQty = indentMap[brandName][itemId]['quantity'];
                
                        
                        var sellingPrice = indentMap [brandName][itemId]['sellingPrice'];
                          var sellPrice = itemQty*sellingPrice;
                        
                        if (itemQty != 0) {
                                allZero = false;
                                
                                trString = `<tr>
                                                        <td style = "width:80%">${description}</td>
                                                        <td>${itemQty}</td>
                                                        <td class ="currency" >${sellPrice}</td>
                                                </tr>`
                                trArray.push(trString);
                                
                        } 
                        

                }
                if(!allZero) {
                        $('button.confirm_indent').show();
                        htmArr.push('<div>');
                        htmArr.push('<h4>' + brandName + '</h4>');
                        htmArr.push('<table class="table table-condensed" id = "planning-table">');
                        htmArr.push(trArray.join(' '));
                        htmArr.push('</table>');
                        htmArr.push('</div>');
                
                        
                }

        }

                        
        
        
        
        $planSummary.html(htmArr.join(""));
        var total= 0;
        $('#planning-table tr').each(function() {
                 
                
                 var value = parseInt($('td', this).eq(2).text());
                 if (!isNaN(value)) {
             total += value;
         }
         
         console.log(total);
       
         });
        
        divString = `<div style ="float:right"><b>Total:-</b><span class="currency">${total}</span></div>`
         htmArr.push(divString);
                 $planSummary.html(htmArr.join(""));
        
          
        // $('#planning-table tfoot td').eq(2).text('Total: ' + total);
        
}
function loadIndent(domId) {
        var url = "/indent/loadIndent?fofoId=" + currentFofoId + "&counterSize="
                        + counterSize;
        doAjaxRequestHandler(context + url, "GET", function(response) {{}
                $('#' + domId).html(response);
        });
}

function loadPreviousMonthIndent(domId) {
        var url = "/indent/loadIndentPreviousMonth?fofoId=" + currentFofoId + "&counterSize="
                        + counterSize;
        doAjaxRequestHandler(context + url, "GET", function(response) {{}
                $('#' + domId).html(response);
        });
}
function downloadIndent() {
        var url = "/indent/download?fofoId=" + currentFofoId + "&counterSize="
                        + counterSize;
        doAjaxGetDownload(url, "indent.csv")
}
function raisePO() {
        doPostAjaxRequestWithJsonHandler(context + "/indent/create-po", {},
                        function(response) {
                                if (response) {
                                        alert("PO Created Successfully");
                                        $('a.allocation_po').click();
                                } else {
                                        alert("Problem while creating PO");
                                }
                        });

}