function initializeWorkRegistration() {

    setInProgressWork();
    var decPlaces = $("#WoExDecPlacesOper").val();
    var prodType = $("#prodType").val()

    $('.btn-link').click(function () {

        var type = this.id.substring(2, 3)
        var name = this.id.substring(3)
        var value = parseInt($('#' + name).val());

        if (type === "i") {
            value = value + 1;
        } else
            if (value > 0) {
                value = value - 1;
            }
        $("#" + name).val(formatDisplay(decPlaces, value));

    });


    $(".datepicker").datepicker({
        format: 'dd.mm.yyyy',
        language: $('#languageDate').val()
    }).on('changeDate', function () {
        $(this).datepicker('hide');
    });


    $dataTable = $('#woExRegOperExp');
    $dataTable.DataTable({
        ajax: {
            url: $dataTable.attr('data-url'),
            data: function (d) {
                d.Key = $("#AcKey").val();
                d.No = $("#AnNo").val();
                d.ResursID = $("#ResursID").val();
                d.ProductionType = $("#prodType").val();
            }
        },
        columns: [

            { data: "Worker", name: "Worker" },
            { data: "DateStr", name: "DateStr" },
            {
                data: "Note", name: "AcNote",
                render: function (data, type, full) {

                    var noteClass = data === "" ? " transparent-color" : "theme-color";
                    return type === 'display' ?
                        '<button type="button" class="btn btn-link m-r-sm" data-note=' + data + ' onclick="openNoteModal1(this)">' +
                            '<i class="fa fa-comment description-hidden-icon ' + noteClass + '" ></i>' +
                        '</button >' : data;
                }
            },
            { data: "TimeStr", name: "TimeStr", className: "dt-body-center" },
            { data: "GoodPcs", name: "GoodPcs", render: $.fn.dataTable.render.number('.', ',', decPlaces), className: 'dt-body-right' },
            { data: "RepairQty", name: "RepairQty", render: $.fn.dataTable.render.number('.', ',', decPlaces), className: 'dt-body-right' },
            { data: "ScrapPcs", name: "ScrapPcs", render: $.fn.dataTable.render.number('.', ',', decPlaces), className: 'dt-body-right' },
            { data: "Tn", name: "Tn", render: $.fn.dataTable.render.number('.', ',', decPlaces), className: 'dt-body-right' },
            { data: "Tpf", name: "Tpf", render: $.fn.dataTable.render.number('.', ',', decPlaces), className: 'dt-body-right' },

            {
                data: "Exported",
                name: "Exported",
                filtertype: "string",
                className: "dt-body-center",
                render: function (data, type, full) {
                    if (data === "F") {
                        return '<span class="label label-primary">' + $("#unconfirmed").val() + '</span>';
                    } else {
                        return '<span class="label label-success">' + $("#confirmed").val() + '</span>';
                    }
                }
            }

        ]
    }); 

};

function openNoteModal1(button) {
    var note = '';

    if (button.id === "") {
        note = $(button).data("note");
        $("#modalSave").addClass("hidden");
        $("#modalClose").removeClass("hidden");
    }
    else {
        $("#modalSave").removeClass("hidden");
        $("#modalClose").addClass("hidden");
    }

    $("#Note").text(note);
    $('#note-modal').modal('show');
}

function startWorkRecording(buttonId) {

    var currentBtn = $('#' + buttonId);
    var icon = $(currentBtn).data("icon");
    var color = $(currentBtn).data("color");
    var eventType = $(currentBtn).data("event-type");

    var eventTypeCurrent = $("#EventType").val();

    if ((eventTypeCurrent === "OE") ||
        (eventTypeCurrent === "OP" && eventType === "OB") ||
        (eventTypeCurrent === "OB" && eventType === "OC") ||
        (eventTypeCurrent === "OC" && eventType === "OB"))
        return false;

    if ($('#Worker').val() === "") {
        $().customModal({
            destroyOnClose: true,
            showCloseButton: true,
            id: "requiedEmployee",
            type: "alert",
            text: $("#notEmployeeText").val(),
            buttons: [
                {
                    icon: 'fa fa-check',
                    text: $("#buttonText").val(),
                    closeOnAction: true,
                    type: 'primary'
                }
            ]
        });
        return false;
    }

    if (!$(currentBtn).hasClass('pressed')) {
        if ($('.entry-type-button').hasClass('pressed')) {
            $('.pressed').removeClass('pressed')
                .css("border-bottom", "");
        }
        else if (eventType === "OP" || eventType === "OC") {
            return;
        }

        $(currentBtn).addClass('pressed')
            .css("border-bottom", "4px solid " + color);

        swapLoadingIcon(true, buttonId, icon);
        createEvent(currentBtn, icon);
    }
}

function stopWorkRecordings(buttonId) {

    var currentBtn = $('#' + buttonId);
    var icon = $(currentBtn).data("icon");
    var color = $(currentBtn).data("color");

    if (!$(currentBtn).hasClass('pressed')) {

        if ($('.entry-type-button').hasClass('pressed')) {

            $(currentBtn).addClass('pressed')
                .css("border-bottom", "4px solid " + color);

            swapLoadingIcon(true, buttonId, icon);
            createEvent(currentBtn, icon);

        }
    }
}

function createEvent(currentBtn, icon, isMobile) {

    var eventType = $(currentBtn).data("event-type");
    var buttonText = $("#buttonText").val();

    $.ajax({
        type: "POST",
        dataType: 'json',
        data: {
            AcKey: $("#AcKey").val(),
            AnNo: $("#AnNo").val(),
            Ident: $("#Ident").val(),
            Descr: $("#Descr").val(),
            UM: $("#UM").val(),
            EventType: eventType,
            EventTime: $("#EventTime").val(),
            ResursID: $("#ResursID").val(),
            Worker: $("#Worker").val(),
            ParentWorker: $("#ParentWorker").val(),
            Priority: $("#Priority").val(),
            CalendarQId: $("#CalendarQId").val(),
            Shift: $("#Shift").val(),
            QId: $("#QId").val()
        },

        success: function (data) {
            if (!data.Success) {
                let errorText = data.Error;

                $().customModal({
                    destroyOnClose: true,
                    showCloseButton: true,
                    id: "displayPopupErrorModal",
                    type: "alert",
                    text: errorText,
                    buttons: [
                        {
                            icon: 'fa fa-check',
                            text: buttonText,
                            closeOnAction: true,
                            type: 'primary',
                            action: function () {
                                location.reload();
                            }
                        }
                    ]
                });
                customModalForMobile(isMobile);
                return;
            }
            
            location.reload();
            startTracking(eventType);
            swapLoadingIcon(false, currentBtnId, icon);
            $("#confirmButton").addClass('disabled');
        },
        error: function (error) {
            swapLoadingIcon(false, currentBtnId, icon);
            $("#confirmButton").removeClass('disabled');
        }
    });
}

function startTracking(eventType) {
    if (eventType === "OB") {
        $(".stopwatch").stopwatch().stopwatch('start');
    }
    if (eventType === "OP") {
        $(".stopwatch").stopwatch().stopwatch('stop');
    }
    if (eventType === "OC") {
        $(".stopwatch").stopwatch().stopwatch('start');
    }
    if (eventType === "OE") {

    }
}

function setInProgressWork() {

    var isBtnStarted = $(".set-in-progress");

    if (isBtnStarted.length > 0) {
        var button = $(".set-in-progress")[0];
        var color = $(button).data('color');
        var ms = $(button).data('milliseconds');
        var eventType = $(button).data("event-type");

        $(button).addClass('pressed')
            .css("border-bottom", "4px solid " + color);

        setDisabledControls(eventType);
        continueStopwatch(ms, eventType);

    }
    else {
        setDisabledControls(false);
    }

}

function continueStopwatch(milliseconds, eventType) {
    if ((eventType === "OP") || (eventType === "OE")) {
        $('.stopwatch').stopwatch({ startTime: milliseconds }).stopwatch('render');
    }
    else {
        $('.stopwatch').stopwatch({ startTime: milliseconds }).stopwatch('start');
    }
}

function setDisabledControls(eventType) {

    var disTime = (eventType !== false);
    var disQty = !((eventType === "OE") || (eventType === false));

    $("#beginTime").children().prop('disabled', disTime);
    $("#usedTime").children().prop('disabled', disTime);
    $("#goodPcs").children().prop('disabled', disQty);
    $("#repairPcs").children().prop('disabled', disQty);
    $("#scrapPcs").children().prop('disabled', disQty);
    $("#wastePcs").children().prop('disabled', disQty);
    $("#note").children().prop('disabled', disQty);
}

function confirmOperationWork(isMobile) {

    if ($('#Worker').val() === "") {
        $().customModal({
            destroyOnClose: true,
            showCloseButton: true,
            id: "requiedEmployee",
            type: "alert",
            text: $("#notEmployeeText").val(),
            buttons: [
                {
                    icon: 'fa fa-check',
                    text: $("#buttonText").val(),
                    closeOnAction: true,
                    type: 'primary'
                }
            ]
        });
        customModalForMobile(isMobile);
        return false;
    }

    if ($("#EventType").val() === "") {
        confirmOperation(isMobile);
    }
    else
        if ($("#EventType").val() === "OE") {
            confirmWorkReg(isMobile);
        }
        else {
            $().customModal({
                destroyOnClose: true,
                showCloseButton: true,
                id: "displayPopupSuccessModal",
                type: "question",
                text: $("#questionText").val(),
                buttons: [
                    {
                        icon: 'fa fa-check',
                        text: $("#buttonYes").val(),
                        closeOnAction: true,
                        type: 'primary',
                        action: function () {
                            stopWorkRecordings("record-button-3");
                        }
                    },
                    {
                        icon: 'fa fa-times',
                        text: $("#buttonNo").val(),
                        closeOnAction: true,
                        type: 'primary'
                    },

                ]
            });
            customModalForMobile(isMobile);
        }
}

function confirmWorkReg(isMobile) {

    var buttonText = $("#buttonText").val();
    var succesText = $("#succesText").val();

    swapLoadingIcon(true, "confirmButton", "fa fa-check");
    $("#confirmButton").addClass('disabled');

    var data = {
        AcKey: $("#AcKey").val(),
        AnNo: $("#AnNo").val(),
        Ident: $("#Ident").val(),
        Descr: $("#Descr").val(),
        UM: $("#UM").val(),
        BeginTime: $("#BeginTime").val(),
        EventType: $("#EventType").val(),
        EventTime: $("#EventTime").val(),
        ResursID: $("#ResursID").val(),
        Worker: $("#Worker").val(),
        ParentWorker: $("#ParentWorker").val(),
        Priority: $("#Priority").val(),
        CalendarQId: $("#CalendarQId").val(),
        Date: $("#Date").val(),
        Shift: $("#Shift").val(),
        QId: $("#QId").val(),
        Milliseconds: toNumber($("#UsedTime").val()) * 1000 * 60 * 60,
        GoodPcs: $("#GoodPcs").val().replace('.', ','),
        ScrapPcs: $("#ScrapPcs").val().replace('.', ','),
        WastePcs: $("#WastePcs").val(),
        RepairQty: $("#RepairQty").val().replace('.', ','),
        HoldUps: $("#HoldUps").val(),
        Note: $("#Note").val(),
        Finished: $("#finishOperation").is(":checked") ? "Y" : "N",
        ConfirmReceive: $("#confirmReceive").is(":checked") ? "1" : "0",
        ProdType: $("#prodType").val()

    };

    var url = $('#confirmOperWork').val();

    $.post(url, data)
        .done(function (response) {

            if (response.Success) {

                $().customModal({
                    destroyOnClose: true,
                    showCloseButton: true,
                    id: "displayPopupSuccessModal",
                    type: "success",
                    text: succesText,
                    buttons: [
                        {
                            icon: 'fa fa-check',
                            text: buttonText,
                            closeOnAction: true,
                            type: 'primary',
                            action: function () {
                                location.reload();

                            }
                        }
                    ]
                });
                customModalForMobile(isMobile);

            } else {

                let errorText = response.Error;

                $().customModal({
                    destroyOnClose: true,
                    showCloseButton: true,
                    id: "displayPopupErrorModal",
                    type: "alert",
                    text: errorText,
                    buttons: [
                        {
                            icon: 'fa fa-check',
                            text: buttonText,
                            closeOnAction: true,
                            type: 'primary'
                        }
                    ]
                });
                customModalForMobile(isMobile);
            }
            swapLoadingIcon(false, "confirmButton", "fa fa-check");
            $("#confirmButton").removeClass('disabled');
        });


}

function confirmOperation(isMobile) {

    var buttonText = $("#buttonText").val();

    if (toNumber($("#UsedTime").val()) === 0) {
        var requiedText = $("#requiedQty").val();
        $().customModal({
            destroyOnClose: true,
            showCloseButton: true,
            id: "requiedInput",
            type: "alert",
            text: requiedText,
            buttons: [
                {
                    icon: 'fa fa-check',
                    text: buttonText,
                    closeOnAction: true,
                    type: 'primary'
                }
            ]
        });
        customModalForMobile(isMobile);
        return false;
    };

    swapLoadingIcon(true, "confirmButton", "fa fa-check");
    $("#confirmButton").addClass('disabled');

    var data = {
        AcKey: $("#AcKey").val(),
        AnNo: $("#AnNo").val(),
        Ident: $("#Ident").val(),
        Descr: $("#Descr").val(),
        Date: $("#Date").val(),
        UM: $("#UM").val(),
        Worker: $("#Worker").val(),
        QId: $("#WoExItem_QId").val(),
        Note: $("#Note").val(),
        ResursID: $("#ResursID").val(),
        ResourceQId: $("#resourceQId").val(),
        BeginTime: $("#BeginTime").val(),
        Time: $("#UsedTime").val().replace('.', ','),
        Qty: $("#GoodPcs").val().replace('.', ','),
        ScrapPcs: $("#ScrapPcs").val().replace('.', ','),
        WastePcs: $("#WastePcs").val(),
        RepairQty: $("#RepairQty").val().replace('.', ','),
        HoldUps: $("#HoldUps").val(),
        Note: $("#Note").val(),
        Finished: $("#finishOperation").is(":checked") ? "Y" : "N",
        ConfirmReceive: $("#confirmReceive").is(":checked") ? "1" : "0",
        ProdType: $("#prodType").val()
    };

    $.post($('#confirmOperation').val(), data)
        .done(function (response) {

            if (response.Success) {

                $().customModal({
                    destroyOnClose: true,
                    showCloseButton: true,
                    id: "displayPopupSuccessModal",
                    type: "success",
                    text: $("#succesText").val(),
                    buttons: [
                        {
                            icon: 'fa fa-check',
                            text: buttonText,
                            closeOnAction: true,
                            type: 'primary',
                            action: function () {
                                location.reload();
                            }
                        }
                    ]
                });
                customModalForMobile(isMobile);

            } else {

                let errorText = response.Error;

                $().customModal({
                    destroyOnClose: true,
                    showCloseButton: true,
                    id: "displayPopupErrorModal",
                    type: "alert",
                    text: errorText,
                    buttons: [
                        {
                            icon: 'fa fa-check',
                            text: buttonText,
                            closeOnAction: true,
                            type: 'primary'
                        }
                    ]
                });
                customModalForMobile(isMobile);

            }
         
            swapLoadingIcon(false, "confirmButton", "fa fa-check");
            $("#confirmButton").removeClass('disabled');
        });

}

function initializeWorkRegistrationMobile() {

    if ($("#Picture").val() == "") {
        $("#image").addClass('hidden');
        $("#noImage").removeClass('hidden');
    }

    $(window).on("orientationchange", function (event) {

        var table = $('#woExRegOperExp').DataTable();
        table.draw();

    });

    setInProgressWorkMobile();
    var decPlaces = $("#WoExDecPlacesOper").val();
    var prodType = $("#prodType").val()

    $('.card-work-reg').find('input[type=number]').val(roundToPercision(decPlaces, 0));

    $('.card-work-reg').find('input[type=number]').blur(function () {
        $(this).val(roundToPercision(decPlaces, Number($(this).val())));
    });


    $('.btn-plus-minus').click(function () {

        var control = $(this).parents("div").children(".form-control");


        if ($(this).children().hasClass("fa-plus")) {
            control.val(roundToPercision(decPlaces, Number(control.val()) + 1));
        };

        if ($(this).children().hasClass("fa-minus")) {
            if (Number(control.val()) > 0)
                control.val(roundToPercision(decPlaces, Number(control.val()) - 1));
        };

    });


    $('#options').on("click", function () {

        $('#sideNavBar>.tab-pane').removeClass("active");
        $('#sideNavBar>.nav>.nav-item').removeClass("active");
        $('#sideNavBar>#item-options').addClass("fade").addClass("in").addClass("active");
        $("#confirm-receiving").removeClass("active");
        $("#confirm-receiving :input").prop('checked', false);
        $("#finish-task").removeClass("active");
        $("#finish-task :input").prop('checked', false);

        $(".divided-content").addClass("divided-content-side-opened").removeClass("divided-content-side-closed");
    });

    $('#apply').on("click", function () {
        $(".divided-content").addClass("divided-content-side-closed").removeClass("divided-content-side-opened");

    });

    $('.btn-close-side-panel').on("click", function () {
        $(".divided-content").addClass("divided-content-side-closed").removeClass("divided-content-side-opened");
    });


    $('#work-history').on("click", function () {
        var caption = $("#work-history").find("h3").text();
        $("#tabCaption").text(caption);

        InitWoExregOperExp();

    });

    $('#image').on("click", function () {
        $("#imageModal").modal('show');
    });

    $('#note').on("click", function () {
        var caption = $("#note").find("h3").text();
        $("#tabCaption").text(caption);

    });

    $('#operation-materials').on("click", function () {
        var caption = $("#operation-materials").find("h3").text();
        $("#tabCaption").text(caption);

        initializeMaterialsTab();

    });

    $('#finish-task').on("click", function () {

        if ($("#finish-task").hasClass('active')) {
            $("#finish-task").removeClass("active");
            $("#finish-task :input").prop('checked', false);

        } else {
            $("#finish-task").addClass("active");
            $("#finish-task :input").prop('checked', true);
        }


    });

    $('#confirm-receiving').on("click", function () {

        if ($("#confirm-receiving").hasClass('active')) {
            $("#confirm-receiving").removeClass("active");
            $("#confirm-receiving :input").prop('checked', false);

        } else {
            $("#confirm-receiving").addClass("active");
            $("#confirm-receiving :input").prop('checked', true);
        }


    });

    $(".datepicker").datepicker({
        format: 'dd.mm.yyyy',
        language: $('#languageDate').val()
    }).on('changeDate', function () {
        $(this).datepicker('hide');
    });

    


};

function InitWoExregOperExp() {
    var decPlaces = $("#WoExDecPlacesOper").val();
    $dataTable = $('#woExRegOperExp');
    $dataTable.DataTable({
        initComplete: function () {
            $('.dataTables_scrollBody').css('max-height', '70vh');
            $('.dataTables_scrollBody').css('height', '70vh');
        },
        ajax: {
            url: $dataTable.attr('data-url'),
            data: function (d) {
                d.Key = $("#AcKey").val();
                d.No = $("#AnNo").val();
                d.ResursID = $("#ResursID").val();
                d.ProductionType = $("#prodType").val();
            }
        },
        columns: [

            { data: "Worker", name: "Worker" },
            { data: "DateStr", name: "DateStr" },            
            { data: "TimeStr", name: "TimeStr", className: "dt-body-center" },

            {
                name: "StatePcs",
                render: function (data, type, full) {

                    var goodPcs = $.fn.dataTable.render.number('.', ',', decPlaces).display(full.GoodPcs);
                    var repairQty = $.fn.dataTable.render.number('.', ',', decPlaces).display(full.RepairQty);
                    var scrapPcs = $.fn.dataTable.render.number('.', ',', decPlaces).display(full.ScrapPcs);

                    return '<span class="label-success m-r-sm" style="padding:5px; border-radius:10px"><i class="fas fa-thumbs-up m-r-sm"></i>' + goodPcs + '</span>' +
                        '<span class="label-primary m-r-sm" style="padding:5px; border-radius:10px"><i class="fas fa-wrench m-r-sm"></i>' + repairQty + '</span>' +
                        '<span class="label-danger" style="padding:5px; border-radius:10px"><i class="fas fa-times m-r-sm"></i>' + scrapPcs + '</span>';


                }
            },
            {
                data: "Note", name: "AcNote",
                render: function (data, type, full) {

                    var noteClass = data === "" ? " transparent-color" : "theme-color";
                    return type === 'display' ?
                        '<button type="button" class="btn btn-link m-r-sm" data-note=' + data + ' onclick="openNoteModal1(this)">' +
                        '<i class="fa fa-comment description-hidden-icon ' + noteClass + '" ></i>' +
                        '</button >' : data;
                }
            },
            {
                data: "Exported",
                name: "Exported",
                className: "dt-body-center",
                render: function (data, type, full) {
                    if (data === "F") {
                        return '<span class="label label-primary">' + $("#unconfirmed").val() + '</span>';
                    } else {
                        return '<span class="label label-success">' + $("#confirmed").val() + '</span>';
                    }
                }
            }

        ]
    });
}

function startWorkRecordingMobile(button) {

    var icon = $(button).data("icon");
    var eventType = $(button).data("event-type");   
    var eventTypeCurrent = $("#EventType").val();

    if ($(button).hasClass("btn-primary")) {

        swapLoadingIcon(true, $(button).attr('id'), icon);
        $(button).attr("disabled", true);

        confirmOperationWork(true);
    }

    if ((eventTypeCurrent === "OE") ||
        (eventTypeCurrent === "OP" && eventType === "OB") ||
        (eventTypeCurrent === "OB" && eventType === "OC") ||
        (eventTypeCurrent === "OC" && eventType === "OB"))
        return false;

    if ($('#Worker').val() === "") {
        $().customModal({
            destroyOnClose: true,
            showCloseButton: true,
            id: "requiedEmployee",
            type: "alert",
            text: $("#notEmployeeText").val(),
            buttons: [
                {
                    icon: 'fa fa-check',
                    text: $("#buttonText").val(),
                    closeOnAction: true,
                    type: 'primary'
                }
            ]
        });
        return false;
    }

    swapLoadingIcon(true, $(button).attr('id'), icon);
    $(button).attr("disabled", true);
    
    createEvent(button, icon, true);

}

function setInProgressWorkMobile() {

    var eventTypeCurrent = $("#EventType").val();

    if (eventTypeCurrent != "") {
        var button = $(".cont-right a[data-event-type=" + eventTypeCurrent + "]");
        var ms = $(button).data('milliseconds');

        continueStopwatch(ms, eventTypeCurrent);
    }
    else {
        $('#doneTime').removeClass('hidden');
    }
}

function initializeMaterialsTab() {
    var productionType = $("#prodType").val();
    var fromDailyPlan = productionType === "MF" ? localStorage.getItem('WoFromDailyPlan') : "false";
   
    $itemsTable = $('#mainGridMaterials');
    var itemsTable = $itemsTable.DataTable({
        initComplete: function () {
            $('.dataTables_scrollBody').css('max-height', '100vh');
            $('.dataTables_scrollBody').css('height', '100vh');

        },
        ajax: {
            url: $itemsTable.attr('data-url'),
            data: function (d) {
                d.Key = $("#AcKey").val();
                d.ItemType = "";
                d.DataFromDailyPlan = fromDailyPlan;
            }
        },
        columns: [
            {
                class: 'border-bottom',
                data: function (data) {
                    var image = data.Picture !== '' ? " <img style='max-width:100%' src='" + data.Picture + "' />" : "<i class='fal fa-image fa-3x text-muted' style='opacity:0.5'></i>";
                    return "<span style='width:100rem;position: relative;text-align: center;vertical-align: middle;display: table-cell;height: 150px;'>" + image + "</span>";
                },
                orderable: false,
                render: function (data) {
                    return data;
                }
            },

            {
                data: "IdentDescr",
                name: "IdentDescr",
                filtertype: "text",
                className: "dt-body-left",
                render: function (data, type, full) {
                    return type === 'display' ?
                        '    <span data-toggle="tooltip"  class="card-caption"  data-original-title="' + data + '" >' + data + '</span>' : data;

                }
            },
            {
                data: "AnNo",
                name: "AnNo",
                filtertype: "text",
                className: "dt-body-left",
                render: function (data, type, full) {
                    return type === 'display' ?
                        '<span style="margin-right:2px"> <i class="fa fa-hashtag"></i> </span> <span>' + data + '</span>' : data;
                }
            },
            {
                data: 'CompletedPrcQty',
                render: function (data, type, full) {
                    var status = $.fn.dataTable.render.number('.', ',', 0, '', "").display(full.Status);
                    var completedPrc = $.fn.dataTable.render.number('.', ',', 0, '', " ").display(full.CompletedPrcQty);
                    var planQty = $.fn.dataTable.render.number('.', ',', 2, '', "").display(full.PlanPcs);
                    var qty = $.fn.dataTable.render.number('.', ',', 2, '', "").display(full.DonePcs);
                    var color = data >= 100 ? "bg-c-green" : "bg-c-yellow"
                    return type === 'display' ?
                        '<div class="progress-card">' +
                        '<div class="progress">' +
                        '    <div class="progress-bar ' + color + '" style="width:' + data + '%" aria-valuenow="' + data + '" aria-valuemin="0" aria-valuemax="100"></div>' +
                        '</div>' +
                        '</div>' +
                        '<span>' + status + ' (' + completedPrc + '%)</span>  <span class="pull-right">' + qty + '/' + planQty + ' ' + full.UM + '</span>' : data;

                }
            }

        ],
        createdRow: function (row, data, dataIndex) {
            $(row).css('cursor', 'pointer');
        },
        drawCallback: function () {
            $("[data-toggle='tooltip']").tooltip({
                container: 'body'
            });
        }
    })

    itemsTable.on('click', 'tr', function () {
        var data = itemsTable.row($(this)).data();
        window.location.href = "EditMat?key=" + data.AcKey + '&no=' + data.AnNo + '&type=' + productionType;
    });


};

function editTime(e) {
    element.innerHTML = '<input type="number" id="done-time-input" onblur="spanReset(this)" style="font-size: 18px;width:80px" step="0.1" min="0" max="100" value="0.00" />';
    $("#done-time-input").focus();
}

function spanReset(e) {

    let value = e.value;
    let timePrev = $("#doneTime").text();
    let element = document.getElementById('element');

    if (toNumber(value) === 0) {
        element.innerHTML = "<span id='doneTime' style='font-size: 18px' class='@(!Model.EventType.IsEmpty() ? 'hidden' : String.Empty) ' onclick = 'editTime(this)' >" + timePrev + "</span >";
        $("#start").removeClass("hidden");
        $("#confirmButton").addClass("hidden");
        return false;
    }

    value = value.replace(',', '.');
    var time = moment.utc(value * 3600 * 1000).format('HH:mm:ss')

    $("#UsedTime").val(value);

    element.innerHTML = "<span id='doneTime' style='font-size: 18px' class='@(!Model.EventType.IsEmpty() ? 'hidden' : String.Empty) ' onclick = 'editTime(this)' >" + time + "</span >";

    $("#start").addClass("hidden");
    $("#confirmButton").removeClass("hidden");
}
