var detect_id = "";
setInterval(function(){
    check_shipment();
}, 30000);
function checkShipNType(type){
    var result = "";
    if(type == 'out'){
        result = "Outbound";
    } else {
        result = "Inbound";
    }
    return result;
}
function checkOrderNType(param){
    var result = "";

    if(param == "website"){
        result = "Website";
    } else if(param == "marketplace") {
        result = "Marketplace";
    } else if(param == "wholesale") {
        result = "Wholesale";
    } else if(param == "store") {
        result = "Store";
    } else if(param == "employee") {
        result = "Employee Purchase";
    } else if(param == "retur") {
        result = "Retur";
    } else if(param == "purchasing") {
        result = "Purchasing";
    } else if(param == "other") {
        result = "Other";
    }

    return result;
}
function check_shipment(){

    var url = api_notif_shipment;
    var session_id = $("#session-id").val();
    var session_total = $("#session-total").val();
    
    var data = {
        user_id : session_id,
        cur_total : session_total
    }
    $.ajax({type: "POST",url: url,data : data, success:function(result){
        if(result.code == 200){
            var total_data = result.total_data;
            if(total_data > 0){
                if(total_data > session_total){
                    var shipment_id = result.data[0].shipment_id;
                    var shipment_type = checkShipNType(result.data[0].shipment_type);
                    var order_type = checkOrderNType(result.data[0].order_type);
                    var par_title = "New Shipment "+shipment_type+" For "+order_type;
                    var link = "module/shipment/detail/"+shipment_id+"/";
                    if(detect_id != shipment_id){
                        pushNotif(par_title,link);
                    }
                    detect_id = shipment_id;
                }
            }
        }
    }});
};
function pushNotif(par_title,link){
    $.notify("Warehouse System", {
        title: par_title,
        icon: url_global+"img/logo/logo-t.png"
    }).click(function(){
        location.href = url_global+link;
    });
}