var mashinalatTable; var url = "/"; const MAP_ENDPOINT = "https://testmap.141.ir"; const MAP_MIN_ZOOM = 5; const MAP_MAX_ZOOM = 10; var time_start, time_end; var time_start_sum, time_end_sum; var map_oparation_status; var map_oparation_time; var markerLayers = []; var markerlist = []; var markershowbytime = null; var loderMarker; var usedMarker; var dedicate_num; var dedicate_num_sum; var bounds = [ [42.9130026312, 75.6166317076], [20.5782370061, 30.5092252948], ]; var deviceIcon = L.icon({ iconUrl: "../dist/images/icons/cmms2.png", }); //showloader function showLoaderScreen() { $(".divloader").css("display", "flex").hide().fadeIn(); } function hideLoaderScreen() { $(".divloader").fadeOut(); } //hideloader //showtable $(function () { // fill mashinalat table mashinalatTable = $("#example-mashinalat").DataTable({ dom: "p>", pagingType: "simple_numbers", destroy: true, scrollX: true, responsive: true, language: { sEmptyTable: "هیچ داده‌ای در جدول وجود ندارد", sInfo: "نمایش _START_ تا _END_ از _TOTAL_ ردیف", sInfoEmpty: "نمایش 0 تا 0 از 0 ردیف", sInfoFiltered: "(فیلتر شده از _MAX_ ردیف)", sInfoPostFix: "", sInfoThousands: ",", sLengthMenu: "نمایش _MENU_ ردیف", sLoadingRecords: "در حال بارگزاری...", sProcessing: "در حال پردازش...", sSearch: "جستجو: ", sZeroRecords: "رکوردی با این مشخصات پیدا نشد", oPaginate: { sFirst: "برگه‌ی نخست", sLast: "برگه‌ی آخر", sNext: "بعدی", sPrevious: "قبلی", }, oAria: { sSortAscending: ": فعال سازی نمایش به صورت صعودی", sSortDescending: ": فعال سازی نمایش به صورت نزولی", }, }, order: [[1, "desc"]], processing: true, ajax: { url: url + "cmms/all", type: "GET", dataSrc: function (json) { return json.data; }, error: function () { Swal.fire({ icon: "error", title: "خطا سرور", text: "مشکل در دریافت اطلاعات", confirmButtonText: "بروزرسانی صفحه", }).then((result) => { if (result.isConfirmed) { location.reload(true); return true; } }); }, }, columns: [ // { // data: null, // className: "text-center text-nowrap", // render: function (data, type, row) { // // return ``; // return ( // '' // ); // }, // }, { data: "form_number", className: "text-center text-nowrap", }, { data: "updated_at_fa", className: "text-center text-nowrap", }, { data: "dedicated_number", className: "text-center text-nowrap", }, { data: "chassis_number", className: "text-center text-nowrap", }, { data: "province_fa", className: "text-center text-nowrap", }, { data: "city_fa", className: "text-center text-nowrap", }, { data: "car_type_fa", className: "text-center text-nowrap", }, { data: "device_name", className: "text-center text-nowrap", }, { data: "total_points", className: "text-center text-nowrap", }, { data: "gps_code", className: "text-center text-nowrap", }, { data: "operator_name", className: "text-center text-nowrap", }, { data: "operator_nationalcode", className: "text-center text-nowrap", }, { data: "operator_phone", className: "text-center text-nowrap", }, { data: null, render: function (data, type, row) { // return ``; return `
`; }, className: "text-center text-nowrap", }, ], buttons: [ { text: '
فرم جدید
', action: function (e, dt, node, config) { window.location = `${url}cmms-audit/add`; }, }, // { // text: '
آخرین نقطه خودروها
', // action: function (e, dt, node, config) { // }, // }, ], }); }); //showtable //status $(document).on("click", ".btn-car-opration-status", function () { showLoaderScreen(); var tr = $(this).closest("tr"); var row = mashinalatTable.row(tr); var dedicated_number = row.data().dedicated_number; $.ajax({ async: false, url: url + "webapi/cmms/getVehicleData?machine=" + dedicated_number, type: "GET", headers: { accept: "application/json", }, cache: false, contentType: false, processData: false, success: function (res) { console.log("res", res); if (res.message != "failed") { setspanres(res.data); if (map_oparation_status == null) { setTimeout(() => { createLeafletMap([res.data.Latitude, res.data.Longitude]); }, 200); } else { initialMarkerMapValue([res.data.Latitude, res.data.Longitude]); } $("#modal-car-opration-status .modal-title").empty(); $("#modal-car-opration-status .modal-title").html( `آخرین وضعیت خودرو با شماره ${dedicated_number}` ); $("#modal-car-opration-status").modal(); } else { showLoaderScreen(); Swal.fire({ icon: "error", title: "خطا ", text: "مشکل در دریافت آخرین وضعیت دستگاه", showCancelButton: true, showConfirmButton: false, cancelButtonText: "بستن", }); hideLoaderScreen(); } hideLoaderScreen(); }, error: function (error) { hideLoaderScreen(); Swal.fire({ icon: "error", title: "خطا ", text: "مشکل در دریافت آخرین وضعیت دستگاه", showCancelButton: true, showConfirmButton: false, cancelButtonText: "بستن", }); }, }); }); //status //time $(document).on("click", ".btn-car-opration-time", function () { resetAllinput(); var tr = $(this).closest("tr"); var row = mashinalatTable.row(tr); dedicate_num = row.data().dedicated_number; $("#modal-car-oparation-time .modal-title").empty(); $("#modal-car-oparation-time .modal-title").html( `کارکرد خودرو با شماره ${dedicate_num}` ); $("#modal-timepicker").modal("show"); }); $("#searchMarkers").on("click", function () { var stoptime = $("#stoptime").children("option:selected").val(); if ($("#time_start").val() != "" && $("#time_end").val() != "") { let startDate = moment( time_start.getState().selected.year + "/" + time_start.getState().selected.month + "/" + time_start.getState().selected.date, "jYYYY/jM/jD" ).format("YYYY-MM-DD"); let endDate = moment( time_end.getState().selected.year + "/" + time_end.getState().selected.month + "/" + time_end.getState().selected.date, "jYYYY/jM/jD" ).format("YYYY-MM-DD"); if (stoptime != 0) { showLoaderScreen(); $.ajax({ url: url + "api/cmms/getVehicleActivity?machineCode=" + dedicate_num + "&startDT=" + startDate + "&endDT=" + endDate + "&minStopDuration=" + stoptime, type: "GET", cache: false, contentType: false, processData: false, success: function (res) { hideLoaderScreen(); if (res.message != "failed") { showtimemachine(res.data); if (res.data.StopPoints.length != 0) { $("#modal-timepicker").modal("hide"); $("#modal-car-oparation-time").modal("show"); if (map_oparation_time == null) { setTimeout(() => { createLeafletMapTime(res.data.StopPoints); }, 200); } else { initialMarkerMapValueTime(res.data.StopPoints); } } else { Swal.fire({ icon: "error", title: "خطا ", text: "نقاطی برای نمایش کارکرد خودرو وجود ندارد ", showCancelButton: true, showConfirmButton: false, cancelButtonText: "بستن", }); } } else { Swal.fire({ icon: "error", title: "خطا ", text: "مشکل در دریافت کارکرد خودرو", showCancelButton: true, showConfirmButton: false, cancelButtonText: "بستن", }); } }, error: function (error) { hideLoaderScreen(); Swal.fire({ icon: "error", title: "خطا ", text: "مشکل در دریافت کارکرد خودرو", showCancelButton: true, showConfirmButton: false, cancelButtonText: "بستن", }); }, }); } else { $("#stoptime").addClass("is-invalid"); } } else { $("#time_start").addClass("is-invalid"); $("#time_end").addClass("is-invalid"); } }); //time //show summery $(document).on("click", ".btn-sum-time", function () { resetSummery(); var tr = $(this).closest("tr"); var row = mashinalatTable.row(tr); dedicate_num_sum = row.data().dedicated_number; $("#modal-show-sum.modal-title").empty(); $("#modal-show-sum .modal-title").html( `خلاصه کارکرد خودرو با شماره ${dedicate_num_sum}` ); $("#modal-timepicker-summery").modal("show"); }); $("#searchSum").on("click", function () { if ($("#time_start_sum").val() != "" && $("#time_end_sum").val() != "") { let startDate = moment( time_start_sum.getState().selected.year + "/" + time_start_sum.getState().selected.month + "/" + time_start_sum.getState().selected.date, "jYYYY/jM/jD" ).format("YYYY-MM-DD"); let endDate = moment( time_end_sum.getState().selected.year + "/" + time_end_sum.getState().selected.month + "/" + time_end_sum.getState().selected.date, "jYYYY/jM/jD" ).format("YYYY-MM-DD"); showLoaderScreen(); $.ajax({ url: url + "api/cmms/getVehicleActivitySummary?machineCode=" + dedicate_num_sum + "&startDT=" + startDate + "&endDT=" + endDate, type: "GET", cache: false, contentType: false, processData: false, success: function (res) { hideLoaderScreen(); if (res.message != "failed") { shownextmodal(res.data); } else { Swal.fire({ icon: "error", title: "خطا ", text: "مشکل در دریافت خلاصه کارکرد خودرو", showCancelButton: true, showConfirmButton: false, cancelButtonText: "بستن", }); } }, error: function (error) { hideLoaderScreen(); Swal.fire({ icon: "error", title: "خطا ", text: "مشکل در دریافت خلاصه کارکرد خودرو", showCancelButton: true, showConfirmButton: false, cancelButtonText: "بستن", }); }, }); } else { $("#time_start_sum").addClass("is-invalid"); $("#time_end_sum").addClass("is-invalid"); } }); //showsummery //make status map function createLeafletMap(latlng) { map_oparation_status = L.map("map", { maxBounds: bounds, minZoom: MAP_MIN_ZOOM, zoomControl: false, }).setView(latlng, 11); L.tileLayer(MAP_ENDPOINT + "/141map/{z}/{x}/{y}.png", {}).addTo( map_oparation_status ); loderMarker = new L.marker(latlng, { icon: deviceIcon, draggable: false, }).addTo(map_oparation_status); } function initialMarkerMapValue(latlng) { map_oparation_status.setView(latlng, 11); loderMarker.setLatLng(latlng); } //make status map //make time map function createLeafletMapTime(data) { var lat = data[0].Latitude; var lng = data[0].Longitude; var markerlistbytime = []; map_oparation_time = L.map("map_time", { maxBounds: bounds, minZoom: MAP_MIN_ZOOM, zoomControl: false, }).setView([lat, lng], 16); L.tileLayer(MAP_ENDPOINT + "/141map/{z}/{x}/{y}.png", {}).addTo( map_oparation_time ); for (let i = 0; i < data.length; i++) { let marker = L.marker([data[i].Latitude, data[i].Longitude], { icon: deviceIcon, content: data[i], }).bindPopup(showpopuptime(data[i]), { className: "customPopupStyle" }); markerlistbytime.push(marker); } console.log("test", markerlistbytime); markershowbytime = L.layerGroup(markerlistbytime); console.log("markershowbytime", markershowbytime); map_oparation_time.addLayer(markershowbytime); } function initialMarkerMapValueTime(data) { console.log("pitikoo1", markershowbytime); if (markershowbytime != null) { map_oparation_time.removeLayer(markershowbytime); markershowbytime = null; } var lat = data[0].Latitude; var lng = data[0].Longitude; var markerlistbytime = []; map_oparation_time.setView([lat, lng], 16); console.log("pitikoo", markershowbytime); for (let i = 0; i < data.length; i++) { let marker = L.marker([data[i].Latitude, data[i].Longitude], { icon: deviceIcon, content: data[i], }).bindPopup(showpopuptime(data[i]), { className: "customPopupStyle" }); markerlistbytime.push(marker); } console.log("test", markerlistbytime); markershowbytime = L.layerGroup(markerlistbytime); console.log("markershowbytime", markershowbytime); map_oparation_time.addLayer(markershowbytime); } //make time map //set speed and lastpoint function setspanres(data) { if (data.LastPointDT != null) { $(".lastpoint").text( moment(data.LastPointDT).format("HH:mm jYYYY/jMM/jDD") ); } else { $(".lastpoint").text("-"); } if (data.Speed != null) { $(".speed").text(data.Speed); } else { $(".speed").text("-"); } } //set speed and lastpoint //popup baze zamani function showpopuptime(data) { console.log("dsdsdsdsds", data); return ( '\ \ " ); } //popup //fill span time function showtimemachine(data) { if (data.Mileage != null) { $(".roadNum").text(data.Mileage); } else { $(".roadNum").text("-"); } if (data.AccOnDuration != null) { $(".onMachintime").text(data.AccOnDuration); } else { $(".onMachintime").text("-"); } if (data.FuelConsumption != null) { $(".fuelNum").text(data.FuelConsumption); } else { $(".fuelNum").text("-"); } } //fill span time //set date time function setDate(data) { return moment(data).format("HH:mm jYYYY/jMM/jDD"); } //set date time //reset time modal function resetAllinput() { $("#time_end").prop("disabled", true); $("#stoptime").val(0); $("#stoptime").removeClass("is-invalid"); $("#time_start").removeClass("is-invalid"); $("#time_end").removeClass("is-invalid"); time_start = $("#time_start").persianDatepicker({ format: "YYYY/MM/DD", autoClose: true, onSelect: function (unix) { time_start.touched = true; $("#time_end").prop("disabled", ""); if ( time_start.getState().selected.unixDate >= time_end.getState().selected.unixDate ) { time_end.setDate(time_start.getState().selected.unixDate); } if (time_end && time_end.options && time_end.options.minDate != unix) { let cachedValue = time_end.getState().selected.unixDate; time_end.options = { minDate: unix }; if (time_end.touched) { time_end.setDate(cachedValue); } } }, }); time_end = $("#time_end").persianDatepicker({ format: "YYYY/MM/DD", autoClose: true, onSelect: function (unix) { time_end.touched = true; $("#time_end").prop("disabled", ""); if ( time_end.getState().selected.unixDate >= time_end.getState().selected.unixDate ) { time_end.setDate(time_end.getState().selected.unixDate); } if (time_end && time_end.options && time_end.options.minDate != unix) { let cachedValue = time_end.getState().selected.unixDate; time_end.options = { minDate: unix }; if (time_end.touched) { time_end.setDate(cachedValue); } } }, }); } //reset time modal //reset summery function resetSummery() { $("#time_end_sum").prop("disabled", true); $("#time_start_sum").removeClass("is-invalid"); $("#time_end_sum").removeClass("is-invalid"); time_start_sum = $("#time_start_sum").persianDatepicker({ format: "YYYY/MM/DD", autoClose: true, onSelect: function (unix) { time_start_sum.touched = true; $("#time_end_sum").prop("disabled", ""); if ( time_start_sum.getState().selected.unixDate >= time_end_sum.getState().selected.unixDate ) { time_end_sum.setDate(time_start_sum.getState().selected.unixDate); } if ( time_end_sum && time_end_sum.options && time_end_sum.options.minDate != unix ) { let cachedValue = time_end_sum.getState().selected.unixDate; time_end_sum.options = { minDate: unix }; if (time_end_sum.touched) { time_end_sum.setDate(cachedValue); } } }, }); time_end_sum = $("#time_end_sum").persianDatepicker({ format: "YYYY/MM/DD", autoClose: true, onSelect: function (unix) { time_end_sum.touched = true; $("#time_end_sum").prop("disabled", ""); if ( time_end_sum.getState().selected.unixDate >= time_end_sum.getState().selected.unixDate ) { time_end_sum.setDate(time_end_sum.getState().selected.unixDate); } if ( time_end_sum && time_end_sum.options && time_end_sum.options.minDate != unix ) { let cachedValue = time_end_sum.getState().selected.unixDate; time_end_sum.options = { minDate: unix }; if (time_end_sum.touched) { time_end_sum.setDate(cachedValue); } } }, }); } function shownextmodal(data) { $("#modal-timepicker-summery").modal("hide"); $("#modal-show-sum").modal("show"); if (data.Mileage != null) { $(".masafat_sum").text(data.Mileage); } else { $(".masafat_sum").text("-"); } if (data.AccOnDuration != null) { $(".time_sum").text(data.AccOnDuration); } else { $(".time_sum").text("-"); } console.log("fu;e", data.FuelConsumption); if (data.FuelConsumption != null) { $(".fuel_sum").text(data.FuelConsumption); } else { $(".fuel_sum").text("-"); } if (data.StopDuration != null) { $(".stop_sum").text(data.StopDuration); } else { $(".stop_sum").text("-"); } } //reset summer //show modal machine radyab function showcarmodal() { alert("hiii"); } $("#example-select-all").on("click", function () { // Check/uncheck all checkboxes in the table var rows = mashinalatTable.rows({ search: "applied" }).nodes(); $('input[type="checkbox"]', rows).prop("checked", this.checked); }); $("#example-mashinalat tbody").on( "change", 'input[type="checkbox"]', function () { console.log("hiii"); // If checkbox is not checked if (!this.checked) { var el = $("#example-select-all").get(0); console.log("el", el); // If "Select all" control is checked and has 'indeterminate' property if (el && el.checked && "indeterminate" in el) { // Set visual state of "Select all" control // as 'indeterminate' el.indeterminate = true; } } } ); //show modal machine radyab