Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
12 kB
2
Indexable
Never
$(document).ready(function () {
        
    typeObj =[
    {
        "Germany": {
            "SAR Investigation": {"id":"11", "duration":0, "caseCount":0},
            "SAR No Investigation": {"id":"12", "duration":0, "caseCount":0},
            "XSAR Investigation": {"id":"13", "duration":0, "caseCount":0},
            "XSAR No Investigation": {"id":"14", "duration":0, "caseCount":0},
        }
    },
    {
        "Germany Advanced": {
            "SAR Investigation": {"id":"21", "duration":0, "caseCount":0},
            "SAR No Investigation": {"id":"22", "duration":0, "caseCount":0},
            "XSAR Investigation": {"id":"23", "duration":0, "caseCount":0},
            "XSAR No Investigation": {"id":"24", "duration":0, "caseCount":0},
        }
    },
    {
        "Germany Manual Standart": {
            "Agent Referral": {"id":"31", "duration":0, "caseCount":0},
            "Internal Referral": {"id":"32", "duration":0, "caseCount":0},
            "Manual XReport": {"id":"33", "duration":0, "caseCount":0},
            "Significant STR": {"id":"34", "duration":0, "caseCount":0},
        }
    },
    {
        "Germany Extensive": {
            "Agent Referral": {"id":"41", "duration":0, "caseCount":0},
            "Internal Referral": {"id":"42", "duration":0, "caseCount":0},
            "Manual XReport": {"id":"43", "duration":0, "caseCount":0},
            "Significant STR": {"id":"44", "duration":0, "caseCount":0},
        }
    }
    ]
    var id = 0;
    var employee = "";
    var timer = new easytimer.Timer();

    $("#toggle").click(function(){
        $("#total").toggle();
    });
    
    $(".employeebtn").click(function () {
        employee = $(".employee").val();
        $(".employee").attr('placeholder', employee).attr("disabled", true);
        $(".employeebtn").hide();
    })
    
    $(document).on("click", "button#stopButton", function () {
    });
    
    $(document).on("click", "button#pauseButton", function () {
        $(this).attr("disabled", true);
        $(this).closest('td').next('td').children().attr("disabled", false);
        $(this).closest('td').prev('td').find('button').attr("disabled", true);
        timer.pause();
    });
    
    $(document).on("click", "button#resumeButton", function () {
        $(this).attr("disabled", true);
        $(this).closest('td').prev('td').children().attr("disabled", false);
        $(this).closest('td').prev('td').prev('td').find('button').attr("disabled", false);
        timer.start();
    });
    
    $(document).on("click", ".dropdown-item", function () {
        timer.stop();
        $(this).closest('td').prev('td').prev('td').text(new Date().toLocaleTimeString());
        $(this).closest('td').find('button').attr("disabled", true);
        $(this).closest('td').next('td').children().attr("disabled", true);
        $(this).closest('td').next('td').next('td').children().attr("disabled", true);

        
        var type = $(this).closest('td').prev('td').prev('td').prev('td').prev('td').text();
        var subtype = $(this).text();
        var string = type + " " + subtype;
        $(this).closest('td').prev('td').prev('td').prev('td').prev('td').text(string);
        
        typeID = getTypeID(type, subtype)

        $(this).closest('td').prev('td').attr("class", typeID.id);
        
        obj = {
            "11": {
                "duration": 0,
                "caseCount": 0,
                "target": getTargetInSeconds(23.34),
                "efficiency":0
            },
            "12": {
                "duration": 0,
                "caseCount": 0,
                "target": getTargetInSeconds(20.39),
                "efficiency":0
            },
            "13": {
                "duration": 0,
                "caseCount": 0,
                "target": getTargetInSeconds(14.47),
                "efficiency":0
            },
            "14": {
                "duration": 0,
                "caseCount": 0,
                "target": getTargetInSeconds(11.15),
                "efficiency":0
            },
            "21": {
                "duration": 0,
                "caseCount": 0,
                "target": getTargetInSeconds(22.81),
                "efficiency":0
            },
            "22": {
                "duration": 0,
                "caseCount": 0,
                "target": getTargetInSeconds(17.22),
                "efficiency":0
            },
            "23": {
                "duration": 0,
                "caseCount": 0,
                "target": getTargetInSeconds(13.6),
                "efficiency":0
            },
            "24": {
                "duration": 0,
                "caseCount": 0,
                "target": getTargetInSeconds(9.31),
                "efficiency":0
            },
            "31": {
                "duration": 0,
                "caseCount": 0,
                "target": getTargetInSeconds(23.13),
                "efficiency":0
            },
            "32": {
                "duration": 0,
                "caseCount": 0,
                "target": getTargetInSeconds(33.8),
                "efficiency":0
            },
            "33": {
                "duration": 0,
                "caseCount": 0,
                "target": getTargetInSeconds(15.66),
                "efficiency":0
            },
            "34": {
                "duration": 0,
                "caseCount": 0,
                "target": getTargetInSeconds(53.51),
                "efficiency":0
            },
            "41": {
                "duration": 0,
                "caseCount": 0,
                "target": getTargetInSeconds(0),
                "efficiency":0
            },
            "42": {
                "duration": 0,
                "caseCount": 0,
                "target": getTargetInSeconds(52.9),
                "efficiency":0
            },
            "43": {
                "duration": 0,
                "caseCount": 0,
                "target": getTargetInSeconds(0),
                "efficiency":0
            },
            "44": {
                "duration": 0,
                "caseCount": 0,
                "target": getTargetInSeconds(68),
                "efficiency":0
            }
        }

        var totalDuration = 0;
        var totalCaseCount = 0;
        var totalEfficiency = 0;
        $.each(obj, function(key, value) {
            $("."+key).each(function () {
                var num = timestrToSec($(this).text());
                var p = pad(num);
                value.duration += parseFloat(p);
                value.caseCount += 1;
                value.efficiency = calculateEfficiency(value);


                $("#totalDuration"+key).html(formatTime(value.duration)).attr("class", "dur");
                $("#caseCount"+key).html(value.caseCount).attr("class", "count");
                $("#efficiency"+key).html(value.efficiency+"%").attr("class", "eff");
            });
            totalDuration += value.duration;
            totalCaseCount += value.caseCount
            totalEfficiency += value.efficiency * value.caseCount;
        });

        $("#totalDur").html(formatTime(totalDuration));
        $("#totalCount").html(totalCaseCount);
        

        $("#totalEff").html((totalEfficiency / totalCaseCount) +"%");

    });
    
    $(".opt").click(function () {
        if (timer.isRunning()) {
            alert("Please stop the timer before adding a new entry!");
            return
        }

        if($("#" + id).closest('td').next('td').next('td').next('td').next('td').next('td').next('td').next('td').find('button').prop('disabled') &&
        !$("#" + id).closest('td').next('td').next('td').next('td').next('td').next('td').next('td').next('td').next('td').find('button').prop('disabled')){
            alert('Please unpause the timer before stopping');
            return
        }

        timer.start()
        id += 1;
        var now = new Date();
        var t = now.toLocaleTimeString();
        var type = $(this).text();
        
        var markup = "<tr>";
            markup += "<td id=" + id + ">" + id + "</td>";
            markup += "<td>" + employee + "</td>"
            markup += "<td class='type'>" + type + "</td>"
            markup += "<td>" + t + "</td>"
            markup += "<td>-</td>"
            markup += "<td class='dur' placeholder='00:00:00'>00:00:00</td>"
            markup += "<td>"
            markup += "<div class='dropdown'>"
            markup += "<button class='btn btn-danger dropdown-toggle' type='button' id='stopButton' data-bs-toggle='dropdown' aria-expanded='false'>Stop</button>"
            markup += "<ul class='dropdown-menu' aria-labelledby='dropdownMenuButton1'>"
            if (type == "Germany" || type == "Germany Advanced") {
                markup += "<li><a class='dropdown-item' href='#' id='sari'>SAR Investigation</a></li>"
                markup += "<li><a class='dropdown-item' href='#' id='sarni'>SAR No Investigation</a></li>"
                markup += "<li><a class='dropdown-item' href='#' id='xsari'>XSAR Investigation</a></li>"
                markup += "<li><a class='dropdown-item' href='#' id='xsarni'>XSAR No Investigation</a></li>"
            } else {
                markup += "<li><a class='dropdown-item' href='#' id='xsarni'>Agent Referral</a></li>"
                markup += "<li><a class='dropdown-item' href='#' id='xsarni'>Internal Referral</a></li>"
                markup += "<li><a class='dropdown-item' href='#' id='xsarni'>Manual XReport</a></li>"
                markup += "<li><a class='dropdown-item' href='#' id='xsarni'>Significant STR</a></li>"
            }
            markup += "</ul>"
            markup += "</div>"
            markup += "</td><td><button type='button' class='btn btn-primary' id='pauseButton'>Pause</button></td>"
            markup += "<td><button type='button' class='btn btn-success' disabled='true' id='resumeButton'>Resume</button>"
            markup += "</td>"
            markup += "</tr>";
            $("#current tbody").append(markup);
    });
    
    timer.addEventListener('secondsUpdated', function (e) {
        $("#" + id).closest('td').next('td').next('td').next('td').next('td').next('td').html(timer.getTimeValues().toString());
    });
    

    timer.addEventListener('stopped', function (e) {
    });
    
    
    function timestrToSec(timestr) {
        var parts = timestr.split(":");
        return (parts[0] * 3600) +
        (parts[1] * 60) +
        (+parts[2]);
    }
    
    function pad(num) {
        if (num < 10) {
            return "0" + num;
        } else {
            return "" + num;
        }
    }
    
    function formatTime(seconds) {
        return [pad(Math.floor(seconds / 3600) % 60),
        pad(Math.floor(seconds / 60) % 60),
        pad(seconds % 60),
        ].join(":");
    }

    function getTypeID(type, subtype) {
        var id;
        $.each(typeObj, function(key, value) {
            $.each(value, function(key, value) {
                if(type === key){
                    $.each(value, function(key, value) {
                        if(subtype === key) {
                            id = value
                        }
                    });
                }
            });
        });
        return id;
    }

    function getTargetInSeconds(target) {
        return Math.floor(parseFloat(target)  * 60)
    }

    function calculateEfficiency(obj) {
        
        
        if(obj.duration == 0) {
            return
        }
        totalDuration = obj.duration //30
        totalTarget = obj.caseCount * obj.target //2 * 60
        totalEfficiency = totalTarget/totalDuration * 100 // 120 / 30 * 100

        return Math.floor(totalTarget/totalDuration * 100)
    }
}
);
Leave a Comment