let table; if (typeof hidesearch === "undefined") { var hidesearch; hidesearch = [100]; } if (typeof hidesearch === "undefined") { var cstmbuttons; cstmbuttons = []; } if (typeof pageLength === "undefined") { var pageLength; pageLength = -1; } if (typeof cstmdom === "undefined") { var cstmdom; cstmdom = "flBrtip"; } if (typeof columndefs === "undefined") { var columndefs; columndefs = ""; } if (typeof columnfilter === "undefined") { var columnfilter; columnfilter = ""; } if (typeof columnoptions === "undefined") { var columnoptions; columnoptions = ""; } $('#filterrow th').each(function (i) { let title = $('#datatable thead th').eq($(this).index()).text(); if (hidesearch.includes($(this).index())) { } else if ($(this).index() == 0) { var options = ''; $('#user_id_select').find('option').each(function () { options += ''; }); $(this).html(''); } else { $(this).html(''); } }); table = $('#datatable').DataTable({ "order": [[1, "desc"]], fixedHeader: { header: true, headerOffset: $('#topnav').outerHeight() }, lengthMenu: [ [25, 50, 100, -1], [25, 50, 100, 'All'] ], columnDefs: [ {width: '300px', targets: 0}, {width: '250px', targets: 1}, {width: '80px', targets: 7}, ], pageLength: 100, "language": { "url": "/datatables/json/german.json?v1" }, orderCellsTop: true, stateSave: true, stateDuration: 60 * 60 * 24 * 30, "initComplete": function () { $('.dt-search').append(''); $('.dt-search').addClass('d-inline-block'); $.each(cstmbuttons, function (index, value) { $('.dt-buttons').append(value); }); $('#dt-length-0').addClass('form-control-sm'); $('#clear_cookie').click(function () { $('#filterrow input').val(''); $('#filterrow select').val(''); table.search('').columns().search('').draw(); }); }, "ajax": { "url": requestUrl, "type": "GET", "data": function (d) { $('.display-calendar').each(function (index) { if ($(this).hasClass('active-calendar')) { d.datatype = $(this).data('datatype'); } }) d.dataweek = $('#dataweek').val(); d.datamonth = $('#datamonth').val(); d.datayear = $('#datayear').val(); }, "dataSrc": function (json) { $('#selectsearch').change(); return json.data; } }, "columns": [ { "data": { _: "user.user", "sort": "user.order" }, className: "text-nowrap" }, { "data": { _: "date.date", "sort": "date.order" }, className: "text-nowrap" }, { "data": { _: "start.start", "sort": "start.order" }, className: "text-center" }, { "data": { _: "end.end", "sort": "end.order" }, className: "text-center" }, { "data": { _: "sum.sum", "sort": "sum.order" }, className: "text-center" }, { "data": { _: "category.category", "sort": "category.order" }, className: "" } , { "data": { _: "comment.comment", "sort": "comment.order" }, className: "text-left" }, { "data": { _: "edit.edit", "sort": "edit.order" }, className: "edit-td" } ], layout: { topStart: { search: { placeholder: '' }, buttons: [ { extend: 'excelHtml5', text: 'XLSX Export', className: 'btn-success margina d-none d-lg-block', exportOptions: { columns: ['th:not(:last-child)'], format: { body: function (data, row, column, node) { data = $('

' + data + '

').text(); return $.isNumeric(data.replace(',', '.')) ? data.replace(',', '.') : data; } } } } ] }, topEnd: { pageLength: true } } }); $('#filterrow').on('keyup', 'input', function () { table .column($(this).data('index')) .search(this.value) .draw(); }); $('#selectsearch').change(function () { table .column($(this).data('index')) .search(this.value) .draw(); }); let state = table.state.loaded(); if (state) { table.columns().eq(0).each(function (colIdx) { var colSearch = state.columns[colIdx].search; if (colSearch.search) { $('#filterrow').find("[data-index='" + colIdx + "']").val(colSearch.search); } }); table.draw(); } $(window).scroll(function () { var height = $(window).scrollTop(); if (height > 450) { if ($('#filterrow').is(':visible')) { $('#filterrow').hide(); } } else { if ($('#filterrow').is(':hidden')) { $('#filterrow').show(); } } }); $(document).ready(function () { $(".select2").select2(); $("body").on("change", "#timerecordingCategory_id", function () { if (parseInt($(this).find(':selected').data('hourday')) === 2) { $("#endtime-div").hide(); $("#endtime-div").find('input').each(function () { $(this).prop("required", false); }); $("#enddate-div").show(); $("#enddate-div").find('input').each(function () { $(this).prop("required", true); $(this).prop("min", $('#date').val()); $(this).val($('#date').val()); }); $('#days-div').hide(); $('#days').prop("required", false); $("#div-calc-overtime").hide(); } else if (parseInt($(this).find(':selected').data('hourday')) === 1 || parseInt($(this).find(':selected').data('hourday')) === 6) { if (parseInt($(this).find(':selected').data('hourday')) === 6) { $("#div-calc-overtime").show(); } else { $("#div-calc-overtime").hide(); } $("#endtime-div").show(); $("#endtime-div").find('input').each(function () { $(this).prop("required", true); $(this).prop("disabled", false); }); $("#enddate-div").hide(); $("#enddate-div").find('input').each(function () { $(this).prop("required", false); $(this).prop("min", ''); $(this).val(''); }); $('#days-div').hide(); $('#days').prop("required", false); } else if (parseInt($(this).find(':selected').data('hourday')) === 3 || parseInt($(this).find(':selected').data('hourday')) === 4) { $("#endtime-div").hide(); $("#endtime-div").find('input').each(function () { $(this).prop("required", false); $(this).prop("disabled", true); }); $("#div-calc-overtime").hide(); $("#enddate-div").hide(); $("#enddate-div").find('input').each(function () { $(this).prop("required", false); $(this).prop("min", ''); $(this).val(''); }); $('#days-div').hide(); $('#days').prop("required", false); } else if (parseInt($(this).find(':selected').data('hourday')) === 5) { $("#endtime-div").hide(); $("#endtime-div").find('input').each(function () { $(this).prop("required", false); $(this).prop("disabled", true); }); $("#enddate-div").hide(); $("#enddate-div").find('input').each(function () { $(this).prop("required", false); $(this).prop("min", ''); $(this).val(''); }); $('#days-div').show(); $('#days').prop("required", true); } else if (parseInt($(this).find(':selected').data('hourday')) === 7) { $("#endtime-div").show(); $("#endtime-div").find('input').each(function () { $(this).prop("required", true); $(this).prop("disabled", false); }); $("#enddate-div").hide(); $("#enddate-div").find('input').each(function () { $(this).prop("required", false); $(this).prop("min", ''); $(this).val(''); }) $('#businesstrip_info').val(''); $('#businesstrip_info').show(); $('.car-div-car').show(); } if (parseInt($(this).find(':selected').data('comment')) === 1) { $('#comment').prop("required", true); } else { $('#comment').prop("required", false); } if (parseInt($(this).find(':selected').data('businesstrip')) === 1) { $('.businesstrip-div').show(); $('#businesstrip').prop("checked", false); $('#businesstrip_info').val(''); $('#businesstrip_info').hide(); $('.car-div').find('input').prop("required", false); $('.car-div').find('input').val(''); $('#timerecordingCar_id').val('').change(); $('.car-div').hide(); } else if (parseInt($(this).find(':selected').data('hourday')) === 7) { $('.businesstrip-div').show(); $('.businesstrip-check-div').hide(); $('#businesstrip').prop("checked", true); $('#businesstrip_info').show(); $('#businesstrip_info').prop('required', true); $('#homeoffice-div').hide(); } else { $('.businesstrip-div').hide(); $('#businesstrip').prop("checked", false); $('#businesstrip_info').val(''); $('#timerecordingCar_id').val('').change(); $('.car-div').find('input').prop("required", false); $('.car-div').find('input').val(''); $('.car-div').hide(); $('#businesstrip_info').hide(); } if (parseInt($(this).find(':selected').data('homeoffice')) === 1) { $('#homeoffice-div').show(); $('#homeoffice').prop("checked", false); } else { $('#homeoffice').prop("checked", false); $('#homeoffice-div').hide(); } }); $("body").on("change", "#date", function () { if ($('#enddate-div').css('display') === "block") { if ($('#date').val() > $('#enddate').val()) { $('#enddate').prop("min", $('#date').val()); $('#enddate').val($('#date').val()); } else { $('#enddate').prop("min", $('#date').val()); } } }); $("body").on("change", "#start", function () { if ($('#start').val() > $('#end').val()) { $('#end').val($('#start').val()); } $('#end').prop("min", $('#start').val()); }); $("body").on("change", "#start,#end,#date,#timerecordingCategory_id,#user_id_select", function () { if (parseInt($('#timerecordingCategory_id').find(':selected').data('hourday')) === 6) { var userid; userid = $('#user_id_select').val(); $.post(checkWorkinghoursUrl, { user_id: userid, date: $.trim($('#date').val()), start: $.trim($('#start').val()), end: $.trim($('#end').val()), ajax: 1 }).done(function (data) { var result = $.parseJSON(data); if (result.state === "success") { $('#calc-overtime').html(result.message); } if (result.state === "error") { $('#calc-overtime').html('
' + result.error + '
'); } }); } }); $("body").on("click", ".edit-button", function () { $('#submit-button').hide().removeClass('btn-primary').addClass('btn-danger').show(); $('#submit-button').text('Ändern'); $('#cancel-button').show(); $('#timerecordingCategory_id').val($(this).data('category')).change(); $('#user_id_select').prop('disabled', true); $('#user_id_input').prop('disabled', false); $('#user_id_select').val($(this).data('userid')).change(); $('#user_id_input').val($(this).data('userid')); $('#id').val($(this).data('id')); $('#date').val($(this).data('date')); $('#start').val($(this).data('start')); $('#end').val($(this).data('end')); $('#end').prop("min", $('#start').val()); $('#days').val($(this).data('days')); $('#enddate').val($(this).data('enddate')); $('#enddate').prop("min", $('#date').val()); $('#comment').val($(this).data('comment')); if ($(this).data('businesstrip') == 1) { $('#businesstrip').prop("checked", true); $('#businesstrip_info').val($(this).data('businesstripinfo')); $('#businesstrip_info').show(); $('#businesstrip_info').prop('required', true); $('#homeoffice-div').hide(); $('#timerecordingCar_id').val('').change(); } if ($(this).data('homeoffice') == 1) { $('.businesstrip-div').hide(); $('#homeoffice').prop("checked", true); $('#homeoffice-div').show(); } if ($(this).data('car')) { $('#timerecordingCar_id').val($(this).data('car')).change(); if ($(this).data('mileagestart')) { $('.car-div').show(); $('.car-div').find('input').prop("required", true); $('#mileage_start').val($(this).data('mileagestart')); $('#mileage_end').val($(this).data('mileageend')); $('#mileage_end').prop("min", $(this).data('mileagestart')); } else { } } $('.alert-success').remove(); window.scrollTo(0, 0); }); $("body").on("click", "#cancel-button", function () { $('#submit-button').hide().removeClass('btn-danger').addClass('btn-primary').show(); $('#submit-button').text('Speichern'); $('#cancel-button').hide(); $('#user_id_select').prop('disabled', false); $('#user_id_input').prop('disabled', true); $('#user_id_select').change(); $('#timerecordingCategory_id').change(); $('#id').val(''); $('.businesstrip-div').hide(); $('#businesstrip').prop("checked", false); $('#businesstrip_info').val(''); $('#businesstrip_info').hide(); $('#homeoffice').prop("checked", false); $('.car-div').hide(); $('.car-div').find('input').val(''); $('.car-div').find('input').prop("required", false); $('#timerecordingCar_id').val('').change(); $('#timerecordingCategory_id').change(); }); $("body").on("change", "#dataweek,#datamonth,#datayear", function () { table.ajax.reload(null, false); }); $("body").on("change", "#selectsearch", function () { var datatype; if (!$(this).val()) { $('#must-time').text('N/A'); $('#is-time').text('N/A'); } else { $('.display-calendar').each(function (index) { if ($(this).hasClass('active-calendar')) { datatype = $(this).data('datatype'); } }); if (datatype == 1 || datatype == 2) { $.post(requestTimesUrl, { id: $.trim($(this).data('id')), datatype: datatype, user_id: $(this).find(':selected').data('userid'), dataweek: $('#dataweek').val(), datamonth: $('#datamonth').val(), ajax: 1 }).done(function (data) { var json = $.parseJSON(data); $('#must-time').text(json.time.must); $('#is-time').text(json.time.is); }); } } }); $("body").on("click", ".display-calendar", function () { $('.display-calendar').each(function (index) { $(this).removeClass('active-calendar'); }); $(this).addClass('active-calendar'); if ($(this).data('datatype') == "1") { $('#dataweek-col').show(); $('#dynamictime-div').show(); $('#datamonth-col').hide(); $('#datayear-col').hide(); } else if ($(this).data('datatype') == "2") { $('#datamonth-col').show(); $('#dynamictime-div').show(); $('#dataweek-col').hide(); $('#datayear-col').hide(); } else if ($(this).data('datatype') == "3") { $('#datayear-col').show(); $('#dynamictime-div').hide(); $('#datamonth-col').hide(); $('#dataweek-col').hide(); } $(".select2").select2(); table.ajax.reload(null, false); }); $("body").on("click", "#businesstrip", function () { if ($(this).prop('checked') == true) { $('#businesstrip_info').show(); $('#businesstrip_info').prop('required', true); $('#homeoffice').prop('checked', false); $('#homeoffice-div').hide(); $('.car-div-car').show(); } else { $('#businesstrip_info').hide(); $('#businesstrip_info').val(''); $('#businesstrip_info').prop('required', false); $('#timerecordingCategory_id').change(); } }); $("body").on("click", "#homeoffice", function () { if ($(this).prop('checked') == true) { $('#businesstrip').prop('checked', false); $('.businesstrip-div').hide(); $('#timerecordingCar_id').val(''); $('.car-div').find('input').prop("required", false); $('.car-div').find('input').val(''); $('.car-div').hide(); $('#businesstrip_info').hide(); $('#businesstrip_info').val(''); $('#businesstrip_info').prop('required', false); } else { $('#timerecordingCategory_id').change(); } }); $("body").on("change", "#timerecordingCar_id", function () { if ($('#timerecordingCar_id').val() == "") { $('.car-div').find('input').prop("required", false); $('.car-div').find('input').val(''); $('.car-div').hide(); $('.car-div-car').show(); } else { $('.car-div').show(); $('.car-div').find('input').prop("required", true); $('#mileage_start').val($(this).find(':selected').data('mileagenow')); $('#mileage_end').prop("min", $('#mileage_start').val()); } }); $("body").on("change", "#mileage_start", function () { $('#mileage_end').prop("min", $('#mileage_start').val()); }); $("body").on("click", ".delete-item", function () { if (confirm('Buchung wirklich löschen?')) { $.post(deleteUrl, { id: $.trim($(this).data('id')), ajax: 1 }).done(function (data) { table.ajax.reload(null, false); }); } }) $('form').submit(function (e) { e.preventDefault(); $('#alert-box').remove(); var userid; userid = $('#user_id_select').val(); var businesstrip = false; var homeoffice = false; var car = false; if ($('#businesstrip').prop('checked') == true) { businesstrip = 1; } if ($('#homeoffice').prop('checked') == true) { homeoffice = 1; } if ($.trim($('#timerecordingCar_id').val())) { car = 1; } $.post(insertUrl, { id: $.trim($('#id').val()), user_id: userid, timerecordingCategory_id: $.trim($('#timerecordingCategory_id').val()), date: $.trim($('#date').val()), enddate: $.trim($('#enddate').val()), start: $.trim($('#start').val()), end: $.trim($('#end').val()), days: $.trim($('#days').val()), comment: $.trim($('#comment').val()), businesstrip: businesstrip, businesstrip_info: $.trim($('#businesstrip_info').val()), timerecordingCar_id: $.trim($('#timerecordingCar_id').val()), mileage_start: $.trim($('#mileage_start').val()), mileage_end: $.trim($('#mileage_end').val()), homeoffice: homeoffice, hourday: $.trim($('#timerecordingCategory_id').find(':selected').data('hourday')), ajax: 1 }).done(function (data) { var result = $.parseJSON(data); if (result.state === "success") { $('.wrapper .container-fluid').prepend(`
Erfolgreich
` + result.message + `
`); if ($.trim($('#mileage_start').val())) { $('#timerecordingCar_id').find(':selected').data('mileagenow', $.trim($('#mileage_end').val())); } if (car == 1) { $('#timerecordingCar_id').val('').change(); } $('#businesstrip').prop('checked', false); $('#businesstrip_info').hide(); $('#businesstrip_info').val(''); $('#businesstrip_info').prop('required', false); } if (result.state === "error") { $('.wrapper .container-fluid').prepend(`
Fehler
` + result.error + `
`); } $('#submit-button').hide().removeClass('btn-danger').addClass('btn-primary').show(); $('#submit-button').text('Speichern'); $('#cancel-button').hide(); $('#user_id_select').prop('disabled', false); $('#user_id_input').prop('disabled', true); $('#user_id_select').change(); $('#id').val(''); table.ajax.reload(null, false); }); }); $('#timerecordingCategory_id').change(); }) ;