Files

2733 lines
115 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
var PERMISSIONS = [];
var excelDatepickerFirstTable = {};
var damege_item_counter = 0;
var damage_items = '';
// map variables
var addMap = null;
var editMap = null;
var mapShow;
var mapShow_all;
var markerAdd;
var markerEdit;
var isSetMarkerAdd = false;
var isSetMarkerEdit = false;
var showMapMarker;
var markerEdit;
// end map variables
// date/time picker variable
var date_add;
var police_date_add;
var time_add;
var date_edit;
var police_date_edit;
var time_edit;
var filter_date_from;
// end date/time picker variable
// api list
var damage_api = "/v2/receipt/get-damages";
var permissions_api = "/webapi/user/get-permission";
var province_api = "/webapi/getuser/province-perm";
var receipt_show = "/v2/receipt/show";
var receipt_add_api = "/v2/receipt/store";
var receipt_edit_api = "/v2/receipt/update/";
var receipt_delete_api = "/v2/receipt/delete/";
var mapUrl = "https://rmsmap.rmto.ir/141map/";
var city_api = "/public/contents/provinces/";
var accident_type_api = "/daily_accident/accident_types";
var payment_info_api = "/v2/receipt/upload-payment-info/";
var get_all_info_api = "/v2/receipt/";
var sendToInsurance = "/v2/receipt/send-to-insurance/";
var sendToDaghi = "/v2/receipt/send-to-daghi/";
var documentRelease = "/v2/receipt/document-release/";
var invoice_bill_api = "/v2/receipt/invoice-bill/";
var send_sms_again = "/v2/receipt/send-sms-again/";
var call_payment_status_api = "/v2/receipt/call-payment-status/";
// end api list
// icon static
var divIcon = L.divIcon({
html: `
<div id="pin_marker" class="pin-marker">
<div class="map-pin-marker">
<div class="pin-main-circle"></div>
<div class="pin-white-circle"></div>
<div class="pin-title-circle">
<span class="title-circle-text">مکان</span>
</div>
<div class="pin-main-line"></div>
</div>
<div class="pin-main-shadow">
<div class="shadow-dot">
</div>
</div>
</div>
`,
iconSize: [55, 75],
iconAnchor: [33, 64],
});
var divIconEdit = L.divIcon({
html: `
<div id="pin_marker_edit" class="pin-marker">
<div class="map-pin-marker">
<div class="pin-main-circle"></div>
<div class="pin-white-circle"></div>
<div class="pin-title-circle">
<span class="title-circle-text">مکان</span>
</div>
<div class="pin-main-line"></div>
</div>
<div class="pin-main-shadow">
<div class="shadow-dot">
</div>
</div>
</div>
`,
iconSize: [55, 75],
iconAnchor: [33, 64],
});
// end icon static
// functions
$("[data-mask]").inputmask();
//// loader
function showLoaderScreen() {
$(".divloader").css("display", "flex").hide().fadeIn();
}
function hideLoaderScreen() {
$(".divloader").fadeOut();
}
//// end loader
//// recive receipt items
function DamageItem() {
$("#add_Receipt_modal").find("#damage_items_add0").empty();
$("#edit_Receipt_modal").find("#damage_items_edit0").empty();
$("#add_Receipt_modal").find("#damage_items_add0").append(`<option disabled selected value="0">انتخاب آیتم های خسارت</option>`);
$("#edit_Receipt_modal").find("#damage_items_edit0").append(`<option disabled selected value="0">انتخاب آیتم های خسارت</option>`);
damage_items += `<option disabled selected value="0">انتخاب آیتم های خسارت</option>`;
$.ajax({
url: damage_api,
type: "GET",
cache: false,
async: false,
contentType: false,
processData: false,
success: function (results) {
results.forEach(function (result) {
$("#add_Receipt_modal").find("#damage_items_add0").append(`<option data-unit="${result.unit}" data-base-price="${result.base_price}" value="${result.id}">${result.title}</option>`);
$("#edit_Receipt_modal").find("#damage_items_edit0").append(`<option data-unit="${result.unit}" data-base-price="${result.base_price}" value="${result.id}">${result.title}</option>`);
damage_items += `<option data-unit="${result.unit}" data-base-price="${result.base_price}" value="${result.id}">${result.title}</option>`;
});
},
error: function () {
Swal.fire({
icon: "error",
title: "خطا",
text: "مشکل در دریافت آیتم های خسارت وارده",
confirmButtonText: "بروزرسانی صفحه",
showLoaderOnConfirm: true,
preConfirm: () => {
location.reload(true);
},
});
},
});
}
//// end recive receipt items
function accident_type() {
$("#add_Receipt_modal").find("#accident_type_add").empty();
$("#edit_Receipt_modal").find("#accident_type_edit").empty();
$("#add_Receipt_modal").find("#accident_type_add").append(`<option disabled selected value="0">انتخاب نوع تصادف</option>`);
$("#edit_Receipt_modal").find("#accident_type_edit").append(`<option disabled selected value="0">انتخاب نوع تصادف</option>`);
$.ajax({
url: accident_type_api,
type: "GET",
cache: false,
async: false,
contentType: false,
processData: false,
success: function (results) {
results.forEach(function (result) {
$("#add_Receipt_modal").find("#accident_type_add").append(`<option value="${result.key}">${result.value}</option>`);
$("#edit_Receipt_modal").find("#accident_type_edit").append(`<option value="${result.key}">${result.value}</option>`);
});
},
error: function () {
Swal.fire({
icon: "error",
title: "خطا",
text: "مشکل در دریافت آیتم های خسارت وارده",
confirmButtonText: "بروزرسانی صفحه",
showLoaderOnConfirm: true,
preConfirm: () => {
location.reload(true);
},
});
},
});
}
//// end recive receipt items
//// create map add
function createAddMap(modal) {
return new Promise(resolve => {
setTimeout(() => {
const bounds = [
[42.9130026312, 75.6166317076],
[20.5782370061, 35.5092252948],
];
if (addMap != null) {
addMap.setView([35.7065, 51.3477], 7)
markerAdd.setLatLng(L.latLng([35.7065, 51.3477]));
modal.find("#pin_marker").removeClass("pin-move pin-set");
} else {
addMap = L.map("add_map", {
maxBounds: bounds,
minZoom: 6,
attributionControl: false
}).setView([35.7065, 51.3477], 7);
L.tileLayer(`${mapUrl}{z}/{x}/{y}.png`, {}).addTo(addMap);
setMarkerDefaultAdd(modal);
}
resolve()
}, 400)
})
}
//// end create map add
//// create map edit
function createEditMap(modal, lat, lng) {
return new Promise(resolve => {
var bounds = [
[42.9130026312, 75.6166317076],
[20.5782370061, 35.5092252948],
];
setTimeout(() => {
if (editMap != null) {
editMap.setView([lat, lng], 7)
markerEdit.setLatLng(L.latLng([lat, lng]));
} else {
editMap = L.map("edit_map", {
maxBounds: bounds,
minZoom: 6,
attributionControl: false
}).setView([lat, lng], 7);
L.tileLayer(`${mapUrl}{z}/{x}/{y}.png`, {}).addTo(editMap);
setMarkerDefaultEdit(modal, lat, lng);
}
resolve()
}, 400)
})
}
//// end create map edit
function setMarkerDefaultEdit(modal, lat, lng) {
isSetMarkerEdit = false;
modal.find("#accident_point_map").val("");
markerEdit = new L.marker([lat, lng], {
icon: divIcon,
draggable: true,
}).addTo(editMap);
modal.find("#pin_marker").removeClass("pin-move pin-warn").addClass("pin-set");
markerEdit.on("click", function () {
if (!isSetMarkerEdit) {
markerEdit.setLatLng(L.latLng(editMap.getCenter()));
isSetMarkerEdit = true;
modal.find("#pin_marker")
.removeClass("pin-move pin-warn")
.addClass("pin-set");
modal.find("#accident_point_map").val(
markerEdit.getLatLng().lat.toFixed(6) +
markerEdit.getLatLng().lng.toFixed(6)
);
modal.find("#accident_point_map").removeClass("validity-checker");
}
markerEdit.addTo(editMap);
$(this).hide();
modal.find("#pin_marker").removeClass("pin-move pin-warn").addClass("pin-set");
});
markerEdit.on("drag", function () {
modal.find("#pin_marker").addClass("pin-move");
});
markerEdit.on("dragend", function () {
modal.find("#pin_marker").removeClass("pin-move");
if (modal.find("#pin_marker").hasClass("pin-set") || isSetMarkerEdit) {
modal.find("#pin_marker").addClass("pin-set");
modal.find("#accident_point_map").val(
markerEdit.getLatLng().lat.toFixed(6) +
markerEdit.getLatLng().lng.toFixed(6)
);
$("#edit_project_start_map").val(
markerEdit.getLatLng().lat.toFixed(6) +
markerEdit.getLatLng().lng.toFixed(6)
);
modal.find("#accident_point_map").removeClass("validity-checker");
} else {
editMap.setView(markerEdit.getLatLng());
modal.find("#pin_marker").addClass("pin-set");
$("#edit_project_start_map").val(
markerEdit.getLatLng().lat.toFixed(6) +
markerEdit.getLatLng().lng.toFixed(6)
);
}
});
}
//// set marker [add]
function setMarkerDefaultAdd(modal) {
isSetMarkerAdd = false;
modal.find("#pin_marker").removeClass("pin-set");
modal.find("#accident_point_map").val("");
modal.find("#add_project_start_map").val("");
markerAdd = new L.marker([35.7065, 51.3477], {
icon: divIcon,
draggable: true,
}).addTo(addMap);
addMap.on("move", function () {
if (!isSetMarkerAdd) {
markerAdd.setLatLng(L.latLng(addMap.getCenter()));
modal.find("#pin_marker").removeClass("pin-set").addClass("pin-move");
}
});
addMap.on("moveend", function () {
if (!isSetMarkerAdd) {
markerAdd.setLatLng(L.latLng(addMap.getCenter()));
modal.find("#pin_marker").removeClass("pin-move pin-set");
}
});
markerAdd.on("click", function () {
if (!isSetMarkerAdd) {
markerAdd.setLatLng(L.latLng(addMap.getCenter()));
isSetMarkerAdd = true;
modal.find("#pin_marker")
.removeClass("pin-move pin-warn")
.addClass("pin-set");
modal.find("#accident_point_map").val(
markerAdd.getLatLng().lat.toFixed(6) +
markerAdd.getLatLng().lng.toFixed(6)
);
modal.find("#accident_point_map").removeClass("validity-checker");
$("#add_project_start_map").val(
markerAdd.getLatLng().lat.toFixed(6) +
markerAdd.getLatLng().lng.toFixed(6)
);
}
markerAdd.addTo(addMap);
$(this).hide();
modal.find("#pin_marker").removeClass("pin-move pin-warn").addClass("pin-set");
});
markerAdd.on("drag", function () {
modal.find("#pin_marker").addClass("pin-move");
});
markerAdd.on("dragend", function () {
modal.find("#pin_marker").removeClass("pin-move");
if (modal.find("#pin_marker").hasClass("pin-set") || isSetMarkerAdd) {
modal.find("#pin_marker").addClass("pin-set");
modal.find("#accident_point_map").val(
markerAdd.getLatLng().lat.toFixed(6) +
markerAdd.getLatLng().lng.toFixed(6)
);
$("#add_project_start_map").val(
markerAdd.getLatLng().lat.toFixed(6) +
markerAdd.getLatLng().lng.toFixed(6)
);
modal.find("#accident_point_map").removeClass("validity-checker");
} else {
addMap.setView(markerAdd.getLatLng());
}
});
}
//// end set marker
//// build show map
function buildMapShowAndMarker(position) {
return new Promise(function (resolve) {
setTimeout(() => {
const bounds = [
[42.9130026312, 75.6166317076],
[20.5782370061, 35.5092252948],
];
mapShow = L.map("map_show", {
maxBounds: bounds,
minZoom: 6,
zoomControl: false,
attributionControl: false
}).setView(position, 7);
mapShow.invalidateSize();
L.tileLayer(`${mapUrl}/{z}/{x}/{y}.png`, {}).addTo(mapShow);
showMapMarker = L.marker(position, { icon: divIcon }).addTo(mapShow);
resolve();
}, 200)
});
}
function buildMapShowAndMarker_all(position) {
return new Promise(function (resolve) {
setTimeout(() => {
const bounds = [
[42.9130026312, 75.6166317076],
[20.5782370061, 35.5092252948],
];
mapShow_all = L.map("map_show_all", {
maxBounds: bounds,
minZoom: 6,
zoomControl: false,
attributionControl: false
}).setView(position, 7);
mapShow_all.invalidateSize();
L.tileLayer(`${mapUrl}/{z}/{x}/{y}.png`, {}).addTo(mapShow_all);
showMapMarker = L.marker(position, { icon: divIcon }).addTo(mapShow_all);
resolve();
}, 200)
});
}
//// end build show map
//// relocate show map
function changePositionMarkerInMapShow(position) {
return new Promise(function (resolve) {
setTimeout(() => {
mapShow.setView(position, 7);
mapShow.invalidateSize();
showMapMarker.setLatLng(position)
resolve();
}, 200)
});
}
function changePositionMarkerInMapShow_all(position) {
return new Promise(function (resolve) {
setTimeout(() => {
mapShow_all.setView(position, 7);
mapShow_all.invalidateSize();
showMapMarker.setLatLng(position)
resolve();
}, 200)
});
}
//// end relocate show map
//// excel datepicker
excelDatepickerFirstTable.from = $(
"#datapicker-from-excel-table"
).persianDatepicker({
format: "YYYY/MM/DD",
autoClose: true,
onSelect: function (unix) {
excelDatepickerFirstTable.from.touched = true;
$("#datapicker-to-excel-table").prop("disabled", "");
if (
excelDatepickerFirstTable.from.getState().selected.unixDate >=
excelDatepickerFirstTable.to.getState().selected.unixDate
) {
excelDatepickerFirstTable.to.setDate(
excelDatepickerFirstTable.from.getState().selected.unixDate
);
}
if (
excelDatepickerFirstTable.to &&
excelDatepickerFirstTable.to.options &&
excelDatepickerFirstTable.to.options.minDate != unix
) {
let cachedValue =
excelDatepickerFirstTable.to.getState().selected.unixDate;
excelDatepickerFirstTable.to.options = { minDate: unix };
if (excelDatepickerFirstTable.from.touched) {
excelDatepickerFirstTable.to.setDate(cachedValue);
}
}
},
});
excelDatepickerFirstTable.to = $(
"#datapicker-to-excel-table"
).persianDatepicker({
format: "YYYY/MM/DD",
autoClose: true,
onSelect: function (unix) {
excelDatepickerFirstTable.to.touched = true;
},
});
//// end excel datepicker
// just persian text accept
function restrictInputOtherThanArabic($field) {
var arabicCharUnicodeRange = /[\u0600-\u06FF-0-9-45]/;
$field.bind("keypress", function (event) {
var key = event.which;
if (key == 8 || key == 0 || key === 32) {
return true;
}
var str = String.fromCharCode(key);
if (arabicCharUnicodeRange.test(str)) {
return true;
}
return false;
});
}
// end just persian text accept
$("#add_project_start_map").on("keyup", function () {
checkStartMarkerValidation();
if ($(this).val() == "") {
markerAdd.setLatLng(L.latLng([35.7065, 51.3477]));
addMap.setView(L.latLng([35.7065, 51.3477]));
}
});
$("#edit_project_start_map").on("keyup", function () {
checkStartMarkerValidationEdit();
if ($(this).val() == "") {
$("#pin_marker").removeClass("pin-move pin-set");
markerEdit.setLatLng(L.latLng([35.7065, 51.3477]));
editMap.setView(L.latLng([35.7065, 51.3477]));
}
});
function checkStartMarkerValidation(forSaveData = false, pageOnLoad = false) {
let reg = /^([0-9]){2}\.([0-9])+$/;
let endLatLngVal = $("#add_project_start_map")
.val()
.split(" - ");
let endLatLng = endLatLngVal.map(function (e) {
e = e.replace(/_/g, "");
return parseFloat(e.slice(1, -1));
});
if (isNaN(endLatLng[0])) {
if (!forSaveData) {
$("#add_project_start_map").removeClass(
"is-invalid-input"
);
} else {
$("#add_project_start_map").addClass(
"is-invalid-input"
);
}
$("#pin_marker").removeClass("pin-move pin-set");
$("#add_project_start_map").val("");
$("#add_project_start_map").attr(
"placeholder",
"(پایان) => (عرض جغرافیایی) - (طول جغرافیایی)"
);
return false;
} else if (!endLatLng == 2 ||
!reg.test(endLatLng[0]) ||
!reg.test(endLatLng[1])
) {
$("#add_project_start_map").addClass(
"is-invalid-input"
);
$("#pin_marker").removeClass("pin-move pin-set");
return false;
} else {
if (!forSaveData) {
$("#add_project_start_map").removeClass(
"is-invalid-input"
);
markerAdd.setLatLng(endLatLng);
isSetMarkerAdd = true;
if (pageOnLoad) {
setTimeout(() => {
$("#pin_marker").removeClass("pin-move").addClass("pin-set");
markerAdd.setLatLng(endLatLng);
}, 10);
} else {
$("#pin_marker").removeClass("pin-move").addClass("pin-set");
}
let markerLatLng = [
markerAdd.getLatLng().lat,
markerAdd.getLatLng().lng + 0.0008,
];
addMap.setView(markerLatLng);
isSetMarkerAdd = true;
}
return true;
}
}
function checkStartMarkerValidationEdit(forSaveData = false, pageOnLoad = false) {
let reg = /^([0-9]){2}\.([0-9])+$/;
let endLatLngVal = $("#edit_project_start_map")
.val()
.split(" - ");
let endLatLng = endLatLngVal.map(function (e) {
e = e.replace(/_/g, "");
return parseFloat(e.slice(1, -1));
});
if (isNaN(endLatLng[0])) {
if (!forSaveData) {
$("#edit_project_start_map").removeClass("is-invalid-input");
} else {
$("#edit_project_start_map").addClass("is-invalid-input");
}
$("#pin_marker_edit").removeClass("pin-move pin-set");
$("#edit_project_start_map").val("");
$("#edit_project_start_map").attr("placeholder", "(پایان) => (عرض جغرافیایی) - (طول جغرافیایی)");
return false;
} else if (!endLatLng == 2 ||
!reg.test(endLatLng[0]) ||
!reg.test(endLatLng[1])
) {
$("#edit_project_start_map").addClass("is-invalid-input");
$("#pin_marker_edit").removeClass("pin-move pin-set");
return false;
} else {
if (!forSaveData) {
$("#edit_project_start_map").removeClass("is-invalid-input");
markerEdit.setLatLng(endLatLng);
isSetMarkerEdit = true;
if (pageOnLoad) {
setTimeout(() => {
$("#pin_marker_edit").removeClass("pin-move").addClass("pin-set");
markerEdit.setLatLng(endLatLng);
}, 10);
} else {
$("#pin_marker_edit").removeClass("pin-move").addClass("pin-set");
}
let markerLatLng = [
markerEdit.getLatLng().lat,
markerEdit.getLatLng().lng + 0.0008,
];
editMap.setView(markerLatLng);
isSetMarkerEdit = true;
}
return true;
}
}
// end functions
$(document).bind("click", function (e) {
const clicked = $(e.target);
if (clicked.parents(".toolbox").length != 0) return false;
if (clicked.parents(".datepicker-grid-view").length != 0) return false;
if (clicked.parents(".datepicker-navigator").length != 0) return false;
if (clicked.parents(".datepicker-container").length != 0) return false;
if (clicked.parents(".select2-selection__choice").length != 0) return false;
if (
clicked.closest(".btn-table-filter").length == 0 &&
clicked.closest(".parent-filter").length == 0 &&
$(".parent-filter").css("display") != "none"
) {
$(".parent-filter").css("display", "none");
}
if (
clicked.closest(".btn-table-excel").length == 0 &&
clicked.closest(".parent-excel").length == 0 &&
$(".parent-excel").css("display") != "none"
) {
$(".parent-excel").css("display", "none");
}
});
$(document).ready(function () {
restrictInputOtherThanArabic($("input[type=text]"));
// date/time picker
date_add = $("#add_Receipt_modal").find('#date_add').persianDatepicker({
format: "YYYY/MM/DD",
autoClose: true,
initialValue: false,
onSelect: function (unix) {
$("#add_Receipt_modal").find('#add_day_of_the_week').val(
new persianDate([date_add.getState().selected.year, date_add.getState().selected.month, date_add.getState().selected.date]).format('dddd'));
police_date_add.options = {
minDate: unix
}
if (unix > police_date_add.getState().selected.unixDate) {
police_date_add.setDate(+moment())
$("#add_Receipt_modal").find('#police_date_add').val('')
}
}
});
police_date_add = $("#add_Receipt_modal").find('#police_date_add').persianDatepicker({
format: "YYYY/MM/DD",
autoClose: true,
initialValue: false,
onSelect: function (unix) {
$("#add_Receipt_modal").find('#add_day_of_the_week').val(
new persianDate([police_date_add.getState().selected.year, police_date_add.getState().selected.month, police_date_add.getState().selected.date]).format('dddd'));
}
});
time_add = $("#add_Receipt_modal").find('#time_add').persianDatepicker({
format: "HH:mm",
autoClose: true,
initialValue: false,
onlyTimePicker: true,
timePicker: {
second: {
enabled: false,
}
}
});
date_edit = $("#edit_Receipt_modal").find('#date_edit').persianDatepicker({
format: "YYYY/MM/DD",
autoClose: true,
initialValue: false,
onSelect: function (unix) {
$("#edit_Receipt_modal").find('#edit_day_of_the_week').val(
new persianDate([date_edit.getState().selected.year, date_edit.getState().selected.month, date_edit.getState().selected.date]).format('dddd'));
police_date_edit.options = {
minDate: unix
}
if (unix > police_date_edit.getState().selected.unixDate) {
police_date_edit.setDate(+moment())
$("#edit_Receipt_modal").find('#police_date_edit').val('')
}
}
});
police_date_edit = $("#edit_Receipt_modal").find('#police_date_edit').persianDatepicker({
format: "YYYY/MM/DD",
autoClose: true,
initialValue: false,
onSelect: function (unix) {
$("#edit_Receipt_modal").find('#edit_day_of_the_week').val(
new persianDate([police_date_edit.getState().selected.year, police_date_edit.getState().selected.month, police_date_edit.getState().selected.date]).format('dddd'));
}
});
time_edit = $("#edit_Receipt_modal").find('#time_edit').persianDatepicker({
format: "HH:mm",
autoClose: true,
initialValue: false,
onlyTimePicker: true,
timePicker: {
second: {
enabled: false,
}
}
});
filter_date_from = $(".parent-filter").find('#filter_date_from').persianDatepicker({
format: "YYYY/MM/DD",
initialValue: false,
autoClose: true,
initialValueType: "persian",
});
// end date/time picker
DamageItem();
accident_type()
//permission
//// get PERMISSIONS list
$.ajax({
url: permissions_api,
type: "GET",
cache: false,
async: false,
contentType: false,
processData: false,
success: function (result) {
PERMISSIONS = result.data;
},
error: function () {
Swal.fire({
icon: "error",
title: "خطا",
text: "مشکل در دریافت سطوح دسترسی",
confirmButtonText: "بروزرسانی صفحه",
showLoaderOnConfirm: true,
preConfirm: () => {
location.reload(true);
},
});
},
});
//// end get PERMISSIONS list
if ($.inArray("add-receipt", PERMISSIONS) != -1 || $.inArray("add-receipt-province", PERMISSIONS) != -1)
$('#Receipt_add').removeClass('d-none')
else
$('#Receipt_add').remove()
//// province permission
if ($.inArray("add-receipt", PERMISSIONS) != -1 || $.inArray("add-receipt-province", PERMISSIONS) != -1) {
$.ajax({
url: province_api + (($.inArray("add-receipt", PERMISSIONS) != -1 ? "?type=all" : "")),
type: "GET",
beforeSend: function () {
showLoaderScreen();
},
success: function (result) {
const provinces = result.data;
const addModal = $("#add_Receipt_modal");
const editModal = $("#edit_Receipt_modal");
addModal.find("#province_add").empty();
editModal.find("#province_edit").empty();
$("#filter_province").empty();
addModal.find("#province_add").append('<option disabled value="0">انتخاب استان</option>');
editModal.find("#province_edit").append('<option disabled value="0">انتخاب استان</option>');
$("#filter_province").append('<option value="0">انتخاب استان</option>');
$("#select-province-excel").append('<option value="0">انتخاب استان</option>');
for (let index = 0; index < provinces.length; index++) {
addModal.find("#province_add").append(`<option data-center-lat="${provinces[index].center_lat}" data-center-lon="${provinces[index].center_long}" value="${provinces[index].id}">${provinces[index].name_fa}</option>`);
editModal.find("#province_edit").append(`<option data-center-lat="${provinces[index].center_lat}" data-center-lon="${provinces[index].center_long}" value="${provinces[index].id}">${provinces[index].name_fa}</option>`);
$("#filter_province").append(`<option value="${provinces[index].id}">${provinces[index].name_fa}</option>`);
$("#select-province-excel").append("<option value=" + provinces[index].id + ">" + provinces[index].name_fa + "</option>");
}
hideLoaderScreen();
},
error: function (error) {
hideLoaderScreen();
Swal.fire({
icon: "error",
title: "خطا",
text: "مشکل در دریافت استان ها",
confirmButtonText: "بروزرسانی صفحه",
showLoaderOnConfirm: true,
preConfirm: () => {
location.reload(true);
},
});
},
});
}
//// end province permission
//permission
// receipt render table
table = $("#Receipt_table").DataTable({
serverSide: true,
dom: "<lB<t>p>",
pagingType: "simple_numbers",
filter: 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: [
[0, "asc"][(1, "asc")],
[2, "desc"],
[3, "desc"],
[4, "desc"]
],
order: [
[0, "desc"]
],
processing: true,
select: true,
ajax: {
url: receipt_show,
type: "GET",
beforeSend: function () {
showLoaderScreen();
},
dataSrc: function (json) {
if (json.can_submit == 0) {
$('#point-add').prop('disabled', true)
}
canSubmit = json.can_submit
hideLoaderScreen();
return json.data;
},
},
columns: [{
className: "text-center",
data: null,
render: function (data, type, row, meta) {
return (meta.settings._iDisplayStart + meta.row) + 1
},
name: {
name: 'id',
type: 'option'
},
searchable: false,
orderable: false,
},
{
className: "text-center sorting",
data: "id",
name: {
name: 'id',
type: 'text'
},
searchable: true,
orderable: true,
},
{
className: "text-center sorting",
data: "province_fa",
name: {
name: 'province_fa',
type: 'text'
},
searchable: true,
orderable: true,
},
{
className: "text-center sorting",
data: "city_fa",
name: {
name: 'city_fa',
type: 'text'
},
searchable: true,
orderable: true,
},
{
className: "text-center sorting",
data: "axis_name",
name: {
name: 'axis_name',
type: 'text'
},
searchable: true,
orderable: true,
},
{
className: "text-center sorting",
data: "accident_type_fa",
name: {
name: 'accident_type_fa',
type: 'text'
},
searchable: true,
orderable: true,
},
{
className: "text-center",
data: null,
name: {
name: 'accident_date',
type: 'option'
},
render: function (data, type, row) {
return moment(data.accident_date).locale('fa').format('HH:MM || YYYY/MM/DD');
},
orderable: false,
searchable: false,
},
{
className: "text-center",
data: null,
name: {
name: 'option',
type: 'option'
},
render: function (data, type, row) {
return `<div class="text-center"><button class="btn-dataTable btn-showOnMap-receipt" title="نمایش مختصات"><i class="fa fa-map-marker icon-btnTable"></i></button></div>`;
},
orderable: false,
searchable: false,
},
{
className: "text-center",
data: null,
name: {
name: 'option',
type: 'option'
},
render: function (data, type, row) {
let content = `<div class="d-flex justify-content-around">`;
if (data.damage_picture2 == null && data.damage_picture1 != null) {
content += `<img class="table-image" width="20px" height="20px" src="/storage/${data.damage_picture1}" />`
} else if (data.damage_picture1 == null && data.damage_picture2 != null) {
content += `<img class="table-image" width="20px" height="20px" src="/storage/${data.damage_picture2}" />`
} else if (data.damage_picture1 == null && data.damage_picture2 == null) {
content += `عکسی موجود نمی باشد`
} else {
content += `<img class="table-image" width="20px" height="20px" src="/storage/${data.damage_picture1}" /><img class="table-image" width="20px" height="20px" src="/storage/${data.damage_picture2}" />`
}
content += `</div>`;
return content;
},
orderable: false,
searchable: false,
},
{
className: "text-center",
data: null,
name: {
name: 'sum',
type: 'option'
},
render: function (data, type, row) {
return `${Number(data.sum).toLocaleString("en")} ریال`;
// return `-`;
},
orderable: false,
searchable: false,
},
{
data: null,
name: {
name: 'plaque',
type: 'option'
},
render: function (data, type, row) {
const plaque = data.plaque.split("-");
return `<div class="d-flex align-items-center justify-content-center" style="direction: ltr; font-weight: bold"><div class="mr-1">${plaque[0]}</div><div class="mr-1">${plaque[1] == "*" ? '<i class="fa fa-wheelchair"></i>' : plaque[1]}</div><div class="mr-1">${plaque[2]}</div>-<div class="ml-1 mr-1">ایران</div><div>${plaque[3]}</div></div>`;
},
orderable: false,
searchable: false,
},
{
className: "text-center",
data: null,
name: {
name: 'created_at',
type: 'between'
},
render: function (data, type, row) {
return moment(data.created_at).locale('fa').format('HH:MM || YYYY/MM/DD');
},
orderable: true,
searchable: true,
},
{
className: "text-center",
data: "status_fa",
name: {
name: 'status',
type: 'text'
},
searchable: true,
orderable: true,
},
{
className: "text-center",
data: null,
name: {
name: 'option',
type: 'option'
},
render: function (data, type, row) {
let content = `<div class="d-flex justify-content-center align-items-center">`
switch (data.status) {
case 5:
case 4:
content += `<button class="btn-dataTable btn-letter-to-police" title="نامه پلیس راه"><i class="fa fa-file icon-btnTable"></i></button>`
content += `<button class="btn-dataTable btn-all-data-show" title="نمایش تمامی اطلاعات"><i class="fa fa-folder icon-btnTable"></i></button>`
break;
case 3:
content += `<button class="btn-dataTable btn-documentation-deposit" title="مستندات واریز"><i class="fa fa-address-card icon-btnTable"></i></button>`
content += `<button class="btn-dataTable btn-all-data-show" title="نمایش تمامی اطلاعات"><i class="fa fa-folder icon-btnTable"></i></button>`
break;
case 2:
content += `<button class="btn-dataTable btn-documentation-deposit" title="مستندات واریز"><i class="fa fa-address-card icon-btnTable"></i></button>`
case 1:
content += `<button class="btn-dataTable btn-insurance-receipt" title="ثبت فیش بیمه و داغی"><i class="fa fa-receipt icon-btnTable"></i></button>`
case 0:
content += `<button class="btn-dataTable btn-letter-to-insurance" title="نامه بیمه"><i class="fa fa-envelope icon-btnTable"></i></button>`
content += `<button class="btn-dataTable btn-all-data-show" title="نمایش تمامی اطلاعات"><i class="fa fa-folder icon-btnTable"></i></button>`
break;
}
if (data.status < 2 && (($.inArray("edit-receipt", PERMISSIONS) != -1 || $.inArray("edit-receipt-province", PERMISSIONS) != -1))) {
content += `<button class="btn-dataTable btn-edit-receipt" title="ویرایش"><i class="fa fa-edit"></i></button>`
}
if (($.inArray("delete-receipt", PERMISSIONS) != -1 || $.inArray("delete-receipt-province", PERMISSIONS) != -1)) {
content += `<button class="btn-dataTable btn-delete-receipt" title="حذف"><i class="fa fa-trash icon-btnTable"></i></button>`
}
content += `</div>`
return content;
},
orderable: false,
searchable: false,
},
{
className: "text-center",
data: null,
name: {
name: 'final_amount',
type: 'option'
},
render: function (data, type, row) {
if (data.status >= 4 ) {
return Number(data.final_amount).toLocaleString('en')
}else{
return 0;
}
},
searchable: false,
orderable: false,
},
{
className: "text-center",
data: null,
name: {
name: 'deposit_insurance_amount',
type: 'option'
},
render: function (data, type, row) {
return Number(data.deposit_insurance_amount).toLocaleString('en')
},
orderable: false,
searchable: false,
},
{
className: "text-center",
data: null,
name: {
name: 'deposit_daghi_amount',
type: 'option'
},
render: function (data, type, row) {
return Number(data.deposit_daghi_amount).toLocaleString('en')
},
orderable: false,
searchable: false,
},
],
buttons: [{
text: '<div class="btn-table-filter"><div class="d-flex flex-column"><i class="fa mb-2 fa-filter icon-color"></i>فیلترینگ پیشرفته</div></div>',
action: function (e, dt, node, config) {
topPosition = $(e.target).parents('.btn-table-filter').offset().top + $(e.target).parents('.btn-table-filter').height() + 5
$(".parent-filter").css('top', topPosition)
$(".parent-filter").css("display", "block");
},
},
{
className: "static-btn-cta",
text: '<div class="btn-table-excel"><div class="d-flex flex-column"><i class="fa mb-2 fa-book icon-color"></i>گزارش آماری</div></div>',
action: function (e, dt, node, config) {
topPosition = $(e.target).parents('.btn-table-excel').offset().top + $(e.target).parents('.btn-table-excel').height() + 5
$(".parent-excel").css('top', topPosition)
$(".parent-excel").css("display", "block");
},
},
],
});
// end receipt render table
});
$(document).on("click", "#Receipt_add", function () {
const receipt_add = true;
const modal = $("#add_Receipt_modal");
modal.modal("show");
$("#plaque_text_modal").find(".select-text").removeClass("last-time-select");
modal.find(".input-add-receipt").removeClass("validation-checker");
modal.find(".text-Plaque").removeClass("validation-checker");
modal.find(".select-add-receipt").removeClass("validation-checker");
modal.find('.file-add-receipt').removeClass("validation-checker");
modal.find(".div-Plaque").removeClass("validation-checker");
modal.find(".imgbox").removeClass("validation-checker");
modal.find(".btn-delete-img").data('isDelete', true);
modal.find(".img-input").val("");
modal.find(".img-preview").removeAttr("src");
modal.find(".img-preview").css("display", "none");
modal.find(".img-title").css("display", "");
modal.find(".btn-delete-img").attr("disabled", "disabled");
modal.find(".damage-amount").prop("readonly", true);
modal.find("#police_chart_radio_add").prop("checked", true);
modal.find(".input-add-receipt").prop("disabled", false);
modal.find('.file-add-receipt').prop("disabled", false);
modal.find(".text-Plaque").val("");
modal.find(".div-Plaque").data("value", "");
modal.find(".input-add-receipt").val("");
modal.find(".select-add-receipt").val(0);
modal.find(".recive-city").empty();
modal.find(".recive-city").append('<option selected disabled value="0">انتخاب شهرستان</option>');
modal.find('.file-add-receipt').val("");
modal.find('.phone-is-correct').val("09");
modal.find('.phone-is-correct').removeClass("validation-checker");
modal.find(".custom-file-label").text("انتخاب فایل");
modal.find(".damage-value").prop("disabled", true);
modal.find(".div-Plaque").text("");
damege_item_counter = 0;
modal.find("#new_damage_box_add").empty();
createAddMap(modal).then(() => {
hideLoaderScreen()
});
});
$(document).on("click", ".btn-edit-receipt", function () {
const receipt_add = false;
const modal = $("#edit_Receipt_modal");
$("#plaque_text_edit_modal").find(".select-text").removeClass("last-time-select");
modal.find(".input-edit-receipt").removeClass("validation-checker");
modal.find(".select-edit-receipt").removeClass("validation-checker");
modal.find(".text-Plaque").removeClass("validation-checker");
modal.find('.file-edit-receipt').removeClass("validation-cheker");
modal.find(".imgbox").removeClass("validation-checker");
modal.find('#police_date_edit').prop("disabled", false);
modal.find(".input-edit-receipt").val("");
modal.find(".select-edit-receipt").val(0);
modal.find('.file-edit-receipt').val("");
modal.find(".text-Plaque").val("");
modal.find(".div-Plaque").data("value", "");
modal.find(".custom-file-label").text("انتخاب فایل");
modal.find(".btn-delete-img").prop("disabled", true);
modal.find(".btn-delete-img").data('isDelete', false);
modal.find(".img-input").val("");
modal.find(".img-preview").removeAttr("src");
modal.find(".img-preview").css("display", "none");
modal.find('.phone-is-correct').val("09");
modal.find('.phone-is-correct').removeClass("validation-checker");
modal.find(".img-title").css("display", "");
modal.find(".btn-delete-img").attr("disabled", "disabled");
modal.find("#new_damage_box_edit").empty();
modal.find(".damage-value").prop("disabled", false);
damege_item_counter = 0;
let tr = $(this).closest("tr");
let row = table.row(tr);
let data = row.data();
modal.find("#Receipt_edit_cta").data("rowId", data.id);
date_edit.setDate(+moment(data.accident_date))
time_edit.setDate(+moment(`2000-01-01 ${data.accident_time}`)) // 2000-01-01 is fake
modal.find("#accident_type_edit").val(data.accident_type);
modal.find('#province_edit').val(data.province_id);
city(modal, data.province_id, true, () => {
modal.find("#city_edit").val(data.city_id);
})
modal.find('#axis_name_edit').val(data.axis_name);
modal.find("#name_family_edit").val(data.driver_name);
modal.find("#national_code_edit").val(data.driver_national_code);
modal.find("#phone_number_edit").val(data.driver_phone_number);
phone_checker(modal.find("#phone_number_edit"))
const plaque_value = data.plaque.split("-");
modal.find("#plaque_number_edit1").val(plaque_value[0]);
modal.find("#plaque_word_edit1").empty();
$("#plaque_text_edit_modal").find(".select-text").each(function (index) { if ($(this).data("value") == plaque_value[1]) $(this).addClass("last-time-select") });
$("#plaque_text_edit_modal").find(".select-text").data("value")
if (plaque_value[1] == "*") {
modal.find("#plaque_word_edit1").append(`<i class="fa fa-wheelchair"></i>`)
} else {
modal.find("#plaque_word_edit1").text(plaque_value[1])
}
modal.find("#plaque_word_edit1").data("value", plaque_value[1]);
modal.find("#plaque_number_edit2").val(plaque_value[2]);
modal.find("#plaque_number_edit3").val(plaque_value[3]);
if (data.damage_picture1 != null) {
modal.find("#deviceImg1Preview_edit").attr("src", "/storage/" + data.damage_picture1);
modal.find("#deviceImg1Title_edit").css("display", "none");
modal.find("#deviceImg1Preview_edit").css("display", "");
modal.find("#deleteDeviceImg1_edit").prop("disabled", false);
}
if (data.damage_picture2 != null) {
modal.find("#deviceImg2Preview_edit").attr("src", "/storage/" + data.damage_picture2);
modal.find("#deviceImg2Title_edit").css("display", "none");
modal.find("#deviceImg2Preview_edit").css("display", "");
modal.find("#deleteDeviceImg2_edit").prop("disabled", false);
}
if (data.report_base == 0) {
modal.find("#police_chart_radio_edit").prop("checked", true);
modal.find("#police_file_edit").prop("disabled", false);
modal.find("#police_chart_edit").prop("disabled", false);
modal.find("#police_date_edit").prop("disabled", false);
} else {
modal.find("#visit_expert_edit").prop("checked", true);
modal.find("#police_file_edit").prop("disabled", true);
modal.find("#police_chart_edit").prop("disabled", true);
modal.find("#police_date_edit").prop("disabled", true);
}
modal.find("#police_file_edit").data("policeFile", data.police_file);
data.police_serial != null ? modal.find("#police_chart_edit").val(data.police_serial) : '';
data.police_file_date != null ? modal.find('#police_date_edit').val(moment(data.police_file_date).locale('fa').format('YYYY/MM/DD')) : modal.find('#police_date_edit').prop("disabled", true);
let perv_file = modal.find("#download_perv_file");
if (data.police_file != null) {
perv_file.find("button").prop("disabled", false);
perv_file.attr("href", `/storage/${data.police_file}`);
} else {
perv_file.find("button").prop("disabled", true);
perv_file.removeAttr("href");
}
createEditMap(modal, data.lat, data.lng).then(() => {
editMap.setView([data.lat, data.lng], 7)
isSetMarkerEdit = true;
markerEdit.setLatLng(L.latLng([data.lat, data.lng]));
modal.find("#edit_project_start_map").val(
markerEdit.getLatLng().lat.toFixed(6) +
markerEdit.getLatLng().lng.toFixed(6)
);
modal.find("#pin_marker").removeClass("pin-move pin-warn").addClass("pin-set");
hideLoaderScreen()
})
modal.find("#damage_items_edit0").val(data.damages[0].id);
modal.find("#damage_items_value_edit0").val(data.damages[0].pivot.value);
modal.find("#damage_amount_edit0").val(data.damages[0].pivot.amount);
for (i = 1; i < data.damages.length; i++) {
damege_item_counter++;
const mainBox = modal.find("#damge_box");
const contents_parent = modal.find("#new_damage_box_edit");
const content =
`<div class="row col-12 justify-content-between align-items-end parent-damage">
<div class="row col-4 justify-content-between align-items-center">
<div class="col-12 form-group">
<label for="damage_items_edit${damege_item_counter}">آیتم های خسارت</label><span style="color: crimson">*</span>
<select class="form-control select-edit-receipt damage-items" name="damage_items_edit" id="damage_items_edit${damege_item_counter}"></select>
</div>
</div>
<div class="col-4 form-group">
<label for="damage_items_value_edit${damege_item_counter}">میزان خسارت <span class="selected-unit"></span></label><span style="color: crimson">*</span>
<input type="text" class="form-control input-edit-receipt damage-value" name="damage_items_value_edit" id="damage_items_value_edit${damege_item_counter}"></input>
</div>
<div class="col-3 form-group">
<label for="damage_amount_edit${damege_item_counter}">هزینه خسارت (ریال)</label><span style="color: crimson">*</span>
<input type="text" class="form-control input-edit-receipt damage-amount" readonly name="damage_items_amount_edit" id="damage_amount_edit${damege_item_counter}"></input>
</div>
<div class="col-1 form-group">
<button class="btn btn-danger close-box"><span aria-hidden="true">&times;</span></button>
</div>
</div>`;
contents_parent.append(content);
modal.find(`#damage_items_edit${damege_item_counter}`).append(damage_items);
modal.find(`#damage_items_edit${damege_item_counter}`).val(data.damages[i].id);
modal.find(`#damage_items_value_edit${damege_item_counter}`).val(data.damages[i].pivot.value);
modal.find(`#damage_amount_edit${damege_item_counter}`).val(data.damages[i].pivot.amount);
}
modal.modal("show");
});
$(document).on("change", ".damage-items", function () {
const parent = $(this).parents(".parent-damage");
parent.find(".selected-unit").text('');
parent.find(".selected-unit").text(`( ${$(this).find("option:selected").data("unit")} )`);
parent.find(".damage-value").prop("disabled", false);
parent.find(".damage-value").val("");
parent.find(".damage-amount").val("")
});
$(".custom-file-input").on("change", function () {
const fileName = $(this).val().split("\\").pop();
$(this).siblings(".custom-file-label").addClass("selected").html(fileName);
});
$(document).on("click", "#add_damge", function () {
if ($(`#damage_items_value_add${damege_item_counter}`).val() == "" || $(`#damage_items_add${damege_item_counter} option:selected`).val() == 0 || $(`#damage_amount_add${damege_item_counter}`).val() == "") {
if ($(`#damage_items_value_add${damege_item_counter}`).val() == "") $(`#damage_items_value_add${damege_item_counter}`).addClass("validation-checker");
if ($(`#damage_items_add${damege_item_counter} option:selected`).val() == 0) $(`#damage_items_add${damege_item_counter}`).addClass("validation-checker");
if ($(`#damage_amount_add${damege_item_counter}`).val() == "") $(`#damage_amount_add${damege_item_counter}`).addClass("validation-checker");
if ($(`#damage_items_value_add${damege_item_counter}`).val() != "") $(`#damage_items_value_add${damege_item_counter}`).removeClass("validation-checker");
if ($(`#damage_items_add${damege_item_counter} option:selected`).val() != 0) $(`#damage_items_add${damege_item_counter}`).removeClass("validation-checker");
if ($(`#damage_amount_add${damege_item_counter}`).val() != "") $(`#damage_amount_add${damege_item_counter}`).removeClass("validation-checker");
Swal.fire({
icon: "error",
title: "خطا",
text: "لطفا مقادیر قبلی را تکمیل کنید",
cancelButtonText: "بستن",
showConfirmButton: false,
showCancelButton: true,
});
} else {
if ($(`#damage_items_value_add${damege_item_counter}`).val() != "") $(`#damage_items_value_add${damege_item_counter}`).removeClass("validation-checker");
if ($(`#damage_items_add${damege_item_counter} option:selected`).val() != 0) $(`#damage_items_add${damege_item_counter}`).removeClass("validation-checker");
if ($(`#damage_amount_add${damege_item_counter} option:selected`).val() != 0) $(`#damage_amount_add${damege_item_counter}`).removeClass("validation-checker");
damege_item_counter++;
const mainBox = $(this).parents("#damge_box");
const contents_parent = $("#new_damage_box_add");
const content =
`<div class="row col-12 justify-content-between align-items-end parent-damage">
<div class="row col-4 justify-content-between align-items-center">
<div class="col-12 form-group">
<label for="damage_items_add${damege_item_counter}">آیتم های خسارت</label><span style="color: crimson">*</span>
<select class="form-control select-add-receipt damage-items" name="damage_items_add" id="damage_items_add${damege_item_counter}"></select>
</div>
</div>
<div class="col-4 form-group">
<label for="damage_items_value_add${damege_item_counter}">میزان خسارت <span class="selected-unit"></span></label><span style="color: crimson">*</span>
<input type="text" class="form-control input-add-receipt damage-value" disabled name="damage_items_value_add" id="damage_items_value_add${damege_item_counter}"></input>
</div>
<div class="col-3 form-group">
<label for="damage_amount_add${damege_item_counter}">هزینه خسارت (ریال)</label><span style="color: crimson">*</span>
<input type="text" class="form-control input-add-receipt damage-amount" readonly name="damage_items_amount_add" id="damage_amount_add${damege_item_counter}"></input>
</div>
<div class="col-1 form-group">
<button class="btn btn-danger close-box"><span aria-hidden="true">&times;</span></button>
</div>
</div>`;
contents_parent.append(content);
$(`#damage_items_add${damege_item_counter}`).append(damage_items);
}
});
$(document).on("click", "#edit_damge", function () {
if ($(`#damage_items_value_edit${damege_item_counter}`).val() == "" || $(`#damage_items_edit${damege_item_counter} option:selected`).val() == 0 || $(`#damage_amount_edit${damege_item_counter}`).val() == "") {
if ($(`#damage_items_value_edit${damege_item_counter}`).val() == "") $(`#damage_items_value_edit${damege_item_counter}`).addClass("validation-checker");
if ($(`#damage_items_edit${damege_item_counter} option:selected`).val() == 0) $(`#damage_items_edit${damege_item_counter}`).addClass("validation-checker");
if ($(`#damage_amount_edit${damege_item_counter}`).val() == "") $(`#damage_amount_edit${damege_item_counter}`).addClass("validation-checker");
if ($(`#damage_items_value_edit${damege_item_counter}`).val() != "") $(`#damage_items_value_edit${damege_item_counter}`).removeClass("validation-checker");
if ($(`#damage_items_edit${damege_item_counter} option:selected`).val() != 0) $(`#damage_items_edit${damege_item_counter}`).removeClass("validation-checker");
if ($(`#damage_amount_edit${damege_item_counter}`).val() != "") $(`#damage_amount_edit${damege_item_counter}`).removeClass("validation-checker");
Swal.fire({
icon: "error",
title: "خطا",
text: "لطفا مقادیر قبلی را تکمیل کنید",
cancelButtonText: "بستن",
showConfirmButton: false,
showCancelButton: true,
});
} else {
if ($(`#damage_items_value_edit${damege_item_counter}`).val() != "") $(`#damage_items_value_edit${damege_item_counter}`).removeClass("validation-checker");
if ($(`#damage_items_edit${damege_item_counter} option:selected`).val() != 0) $(`#damage_items_edit${damege_item_counter}`).removeClass("validation-checker");
if ($(`#damage_amount_edit${damege_item_counter} option:selected`).val() != 0) $(`#damage_amount_edit${damege_item_counter}`).removeClass("validation-checker");
damege_item_counter++;
const mainBox = $(this).parents("#damge_box");
const contents_parent = $("#new_damage_box_edit");
const content =
`<div class="row col-12 justify-content-between align-items-end parent-damage">
<div class="row col-4 justify-content-between align-items-center">
<div class="col-12 form-group">
<label for="damage_items_edit${damege_item_counter}">آیتم های خسارت</label><span style="color: crimson">*</span>
<select class="form-control select-edit-receipt damage-items" name="damage_items_edit" id="damage_items_edit${damege_item_counter}"></select>
</div>
</div>
<div class="col-4 form-group">
<label for="damage_items_value_edit${damege_item_counter}">میزان خسارت <span class="selected-unit"></span></label><span style="color: crimson">*</span>
<input type="text" class="form-control input-edit-receipt damage-value" disabled name="damage_items_value_edit" id="damage_items_value_edit${damege_item_counter}"></input>
</div>
<div class="col-3 form-group">
<label for="damage_amount_edit${damege_item_counter}">هزینه خسارت (ریال)</label><span style="color: crimson">*</span>
<input type="text" class="form-control input-edit-receipt damage-amount" readonly name="damage_items_amount_add" id="damage_amount_edit${damege_item_counter}"></input>
</div>
<div class="col-1 form-group">
<button class="btn btn-danger close-box"><span aria-hidden="true">&times;</span></button>
</div>
</div>`;
contents_parent.append(content);
$(`#damage_items_edit${damege_item_counter}`).append(damage_items);
}
});
// phone validation
function phone_checker(item) {
const modal = item.parents(".modal");
if (modal.find(".phone-is-correct").val().length == 11) {
item.removeClass("validation-checker");
modal.find(".attent-num").fadeOut("100");
} else {
item.addClass("validation-checker")
modal.find(".attent-num").fadeIn("100");
}
}
// end phone validation
$(document).on("click", "#Receipt_add_cta", function () {
const thisBtn = $(this);
const modal = $("#add_Receipt_modal");
thisBtn.prop("disabled", true);
modal.find(".select-add-receipt").removeClass("validation-checker");
modal.find(".input-add-receipt").removeClass("validation-checker");
modal.find(".input-add-receipt-chart").removeClass("validation-checker");
modal.find(".text-Plaque").removeClass("validation-checker");
modal.find(".radio-input").removeClass("validation-checker");
modal.find('.file-valid-need').removeClass("validation-checker");
modal.find(".div-Plaque").removeClass("validation-checker");
modal.find(".img-valid-need").parents(".img-box").find(".imgbox").removeClass("validation-checker");
let imgIsValid = false
modal.find('.img-valid-need').each(function (index) {
if ($(this).get(0).files.length != 0) imgIsValid = true
});
if (!imgIsValid) modal.find('.img-valid-need').parents(".img-box").find(".imgbox").addClass("validation-checker")
modal.find('.phone-is-correct').each(function (index) {
if ($(this).val().length != 11) { $(this).removeClass("valid").addClass("validation-checker") } else { $(this).removeClass("validation-checker") }
})
modal.find('.file-valid-need').each(function (index) {
if ($(this).get(0).files.length == 0 && modal.find('input[name=acc_base_add]:checked').val() == 0) $(this).addClass("validation-checker")
});
modal.find(".select-add-receipt").each(function (index) { if ($(this).find("option:selected").val() == 0) $(this).addClass("validation-checker") });
modal.find(".input-add-receipt").each(function (index) { if ($(this).val() == "") $(this).addClass("validation-checker") });
if (modal.find("#police_chart_add").val() == "" && modal.find('input[name=acc_base_add]:checked').val() == 0) { modal.find("#police_chart_add").addClass("validation-checker") } else { modal.find("#police_chart_add").removeClass("validation-checker") }
if (modal.find("#police_date_add").val() == "" && modal.find('input[name=acc_base_add]:checked').val() == 0) { modal.find("#police_date_add").addClass("validation-checker") } else { modal.find("#police_date_add").removeClass("validation-checker") }
modal.find(".input-add-receipt-chart").each(function (index) { if ($(this).val() == "") $(this).addClass("validation-checker") });
modal.find(".text-Plaque").each(function (index) { if ($(this).val().length < $(this).attr("maxLength")) $(this).addClass("validation-checker") });
if (modal.find(".div-Plaque").data("value") == "") { modal.find(".div-Plaque").addClass("validation-checker") }
if (modal.find(".validation-checker").length != 0) {
Swal.fire({
icon: "error",
title: "خطا",
text: "لطفا تمامی مقادیر را تکمیل کنید",
cancelButtonText: "بستن",
showConfirmButton: false,
showCancelButton: true,
});
thisBtn.prop("disabled", false);
} else if (!national_code_validation(modal.find("#national_code_add").val())) {
Swal.fire({
icon: "error",
title: "خطا",
text: "لطفا شماره ملی با فرمت درست وارد کنید",
cancelButtonText: "بستن",
showConfirmButton: false,
showCancelButton: true,
});
thisBtn.prop("disabled", false);
} else {
const accident_type_add = modal.find("#accident_type_add option:selected").val();
const police_chart_add = modal.find("#police_chart_add").val();
const province_add = modal.find("#province_add option:selected").val();
const report_base = modal.find('input[name=acc_base_add]:checked').val();
const city_add = modal.find("#city_add option:selected").val();
const police_file_add = modal.find("#police_file_add").get(0).files[0];
const plaque_number_add1 = modal.find("#plaque_number_add1").val();
const plaque_word_add1 = modal.find("#plaque_word_add1").data("value");
const plaque_number_add2 = modal.find("#plaque_number_add2").val();
const plaque_number_add3 = modal.find("#plaque_number_add3").val();
const plaque_number_add = plaque_number_add1 + "-" + plaque_word_add1 + "-" + plaque_number_add2 + "-" + plaque_number_add3;
const axis_name_add = modal.find("#axis_name_add").val();
const name_family_add = modal.find("#name_family_add").val();
const phone_number_add = modal.find("#phone_number_add").val();
const national_code_add = modal.find("#national_code_add").val();
const damage_picture1 = modal.find("#adddeviceImg1").get(0).files[0];
const damage_picture2 = modal.find("#adddeviceImg2").get(0).files[0];
const markerAdd_lat = markerAdd.getLatLng().lat.toFixed(6);
const markerAdd_lng = markerAdd.getLatLng().lng.toFixed(6);
let items_damge = [];
let parent = modal.find(".parent-damage");
parent.map(function (e) {
const item_damage = {
id: $(this).find(".damage-items").val(),
value: $(this).find(".damage-value").val(),
amount: $(this).find(".damage-amount").val(),
}
items_damge.push(item_damage);
});
items_damge = JSON.stringify(items_damge);
let formData = new FormData();
formData.append("accident_date", moment(date_add.getState().selected.unixDate).format('YYYY-MM-DD'));
formData.append("accident_time", moment(time_add.getState().selected.unixDate).format('HH:mm'));
formData.append("accident_type", accident_type_add);
formData.append("province_id", province_add);
formData.append("city_id", city_add);
formData.append("axis_name", axis_name_add);
formData.append("driver_name", name_family_add);
formData.append("phone_number", phone_number_add);
formData.append("national_code", national_code_add);
formData.append("plaque", plaque_number_add);
if (typeof damage_picture1 !== 'undefined') formData.append("damage_picture1", damage_picture1);
if (typeof damage_picture2 !== 'undefined') formData.append("damage_picture2", damage_picture2);
formData.append("report_base", report_base);
if (typeof police_file_add !== 'undefined') formData.append("police_file", police_file_add);
if (typeof police_file_add !== 'undefined') formData.append("police_file_date", moment(police_date_add.getState().selected.unixDate).format('YYYY-MM-DD'));
if (police_chart_add != '') formData.append("police_serial", police_chart_add);
formData.append("lat", markerAdd_lat);
formData.append("lng", markerAdd_lng);
formData.append("items_damge", items_damge);
$.ajax({
url: receipt_add_api,
type: "POST",
data: formData,
cache: false,
processData: false,
contentType: false,
headers: {
"X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"),
},
beforeSend: function () {
showLoaderScreen();
},
success: function (result) {
thisBtn.prop('disabled', false);
modal.modal('hide')
hideLoaderScreen();
Swal.fire({
icon: "success",
title: "ثبت موفق",
text: "تصادف با موفقیت ثبت شد",
cancelButtonText: "بستن",
showConfirmButton: false,
showCancelButton: true,
}).then(result => {
table.ajax.reload(null, false);
})
},
error: function (error) {
thisBtn.prop('disabled', false)
hideLoaderScreen();
Swal.fire({
icon: "error",
title: "خطا",
text: "مشکل در ثبت",
cancelButtonText: "بستن",
showConfirmButton: false,
showCancelButton: true,
});
},
});
}
});
$("#Receipt_table").on("click", ".btn-showOnMap-receipt", function () {
showLoaderScreen();
const modal = $("#show_Receipt_modal");
const tr = $(this).closest("tr");
const row = table.row(tr);
const row_lat = row.data().lat;
const row_lng = row.data().lng;
const markerPosition = [row_lat, row_lng];
modal.find("#show_on_map_lat").text(row_lat);
modal.find("#show_on_map_lng").text(row_lng);
if (mapShow == null) {
buildMapShowAndMarker(markerPosition).then(() => {
hideLoaderScreen();
});
} else {
changePositionMarkerInMapShow(markerPosition).then(() => {
hideLoaderScreen();
});
}
modal.modal("show");
});
// delete accident
$(document).on('click', '.btn-delete-receipt', function () {
let tr = $(this).closest("tr");
let row = table.row(tr);
let row_id = row.data().id;
let formData = new FormData();
Swal.fire({
icon: "warning",
title: "آیا برای حذف مطمئن هستید؟",
showCancelButton: true,
confirmButtonColor: "#3085d6",
cancelButtonColor: "#d33",
confirmButtonText: "بله، حذف می‌شود",
cancelButtonText: "منصرف شدم!",
showLoaderOnConfirm: true,
preConfirm: () => {
showLoaderScreen();
$.ajax({
url: receipt_delete_api + row_id,
type: "POST",
headers: {
"X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"),
},
cache: false,
contentType: false,
processData: false,
beforeSend: function () {
showLoaderScreen();
},
success: function (result) {
table.ajax.reload(null, false);
hideLoaderScreen();
},
error: function (error) {
hideLoaderScreen();
Swal.fire({
icon: "error",
title: "خطا",
text: "مشکل در برقراری ارتباط با سرور",
confirmButtonText: "بستن",
});
},
});
},
});
});
// end delete accident
// filter [table]
$(document).on("click", "#btn_filter_show", function () {
_table = table
const id_value = $("#filter_id");
const province_value = $("#filter_province option:selected");
const type_accident_value = $("#filter_type_accident option:selected");
const filter_status = $("#filter_status");
const filter_date_from_value = moment(filter_date_from.getState().selected.unixDate).format("YYYY-MM-DD");
if (id_value.val() != 0) {
_table = _table.column(1).search(id_value.val());
} else {
_table = _table.column(1).search('');
}
if (province_value.val() != 0) {
_table = _table.column(2).search(province_value.text());
} else {
_table = _table.column(2).search('');
}
if (type_accident_value.val() != 0) {
_table = _table.column(5).search(type_accident_value.text());
} else {
_table = _table.column(5).search('');
}
if ($("#filter_date_from").val() != "") {
_table = _table.column(11).search(filter_date_from_value + "&" + moment().format("YYYY-MM-DD"));
} else {
_table = _table.column(11).search('');
}
if (filter_status.val() != -1) {
_table = _table.column(12).search(filter_status.val());
} else {
_table = _table.column(12).search('');
}
_table.draw();
});
// end filter
// image upload begin
$(document).on("change", ".img-input", function () {
var input = this;
var parent = $(input).parents(".img-box");
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
parent.find(".img-title").css("display", "none");
parent.find(".img-preview").css("display", "");
parent.find(".btn-delete-img").removeAttr("disabled");
parent.find(".btn-delete-img").data('isDelete', false)
parent.find(".img-preview").attr("src", e.target.result);
};
reader.readAsDataURL(input.files[0]);
}
});
$(".btn-delete-img").on("click", function () {
var parent = $(this).parents(".img-box");
$(this).data('isDelete', true)
parent.find(".img-input").val("");
parent.find(".img-preview").removeAttr("src");
parent.find(".img-preview").css("display", "none");
parent.find(".img-title").css("display", "");
$(this).attr("disabled", "disabled");
});
// image upload end
async function city(modal, pro_id, async, callback = () => { }) {
$.ajax({
url: city_api + pro_id,
type: "GET",
async: async,
beforeSend: function () {
showLoaderScreen();
},
success: function (result) {
const city = result.data;
modal.find(".recive-city").empty();
modal.find(".recive-city").append('<option selected disabled value="0">انتخاب شهرستان</option>');
for (let index = 0; index < city.length; index++) {
modal.find(".recive-city").append(`<option value="${city[index].id}">${city[index].name_fa}</option>`);
}
callback()
hideLoaderScreen();
},
error: function (error) {
hideLoaderScreen();
Swal.fire({
icon: "error",
title: "خطا",
text: "مشکل در برقراری ارتباط با سرور",
confirmButtonText: "بستن",
});
},
});
}
// find city
$(document).on("change", ".find-city", function () {
const modal = $(this).parents(".modal");
const pro_id = $(this).val();
city(modal, pro_id, true);
modal.find(".recive-city").append();
});
// end find city
$(document).on("change", "input[name=acc_base_add]", function () {
$(this).val() == 0 ? $("#police_file_add").prop("disabled", false) && $("#police_chart_add").prop("disabled", false) && $("#police_date_add").prop("disabled", false) : $("#police_file_add").prop("disabled", true) && $("#police_chart_add").prop("disabled", true) && $("#police_date_add").prop("disabled", true);
});
$(document).on("change", "input[name=acc_base_edit]", function () {
$(this).val() == 0 ? $("#police_file_edit").prop("disabled", false) && $("#police_chart_edit").prop("disabled", false) && $("#police_date_edit").prop("disabled", false) : $("#police_file_edit").prop("disabled", true) && $("#police_chart_edit").prop("disabled", true) && $("#police_date_edit").prop("disabled", true);
});
$(document).on("click", "#Receipt_edit_cta", function () {
const thisBtn = $(this);
const modal = $("#edit_Receipt_modal");
thisBtn.prop("disabled", true);
modal.find(".select-edit-receipt").removeClass("validation-checker");
modal.find(".input-edit-receipt").removeClass("validation-checker");
modal.find(".radio-input").removeClass("validation-checker");
modal.find('.file-valid-need').removeClass("validation-checker");
modal.find(".text-Plaque").removeClass("validation-checker");
modal.find(".div-Plaque").removeClass("validation-checker");
modal.find(".img-valid-need").parents(".img-box").find(".imgbox").removeClass("validation-checker");
let imgIsValid = false
modal.find('.img-preview').each(function (index) {
if ($(this).attr("src")) imgIsValid = true
});
if (!imgIsValid) modal.find('.img-preview').parents(".imgbox").addClass("validation-checker")
modal.find(".select-edit-receipt").each(function (index) { if ($(this).find("option:selected").val() == 0) $(this).addClass("validation-checker") });
modal.find(".input-edit-receipt").each(function (index) { if ($(this).val() == "" && $(this).prop("disabled") == false) $(this).addClass("validation-checker") });
modal.find(".text-Plaque").each(function (index) { if ($(this).val().length < $(this).attr("maxLength")) $(this).addClass("validation-checker") });
if (modal.find("#police_chart_edit").val() == "" && modal.find('input[name=acc_base_edit]:checked').val() == 0) { modal.find("#police_chart_edit").addClass("validation-checker"); } else { modal.find("#police_chart_edit").removeClass("validation-checker"); }
if (modal.find("#police_date_edit").val() == "" && modal.find('input[name=acc_base_edit]:checked').val() == 0) { modal.find("#police_date_edit").addClass("validation-checker"); } else { modal.find("#police_chart_edit").removeClass("validation-checker"); }
if (modal.find(".validation-checker").length != 0) {
Swal.fire({
icon: "error",
title: "خطا",
text: "لطفا تمامی مقادیر را تکمیل کنید",
cancelButtonText: "بستن",
showConfirmButton: false,
showCancelButton: true,
});
thisBtn.prop("disabled", false);
} else if (!national_code_validation(modal.find("#national_code_edit").val())) {
Swal.fire({
icon: "error",
title: "خطا",
text: "لطفا شماره ملی با فرمت درست وارد کنید",
cancelButtonText: "بستن",
showConfirmButton: false,
showCancelButton: true,
});
thisBtn.prop("disabled", false);
} else {
const accident_type_edit = modal.find("#accident_type_edit option:selected").val();
const police_chart_edit = modal.find("#police_chart_edit").val();
const province_edit = modal.find("#province_edit option:selected").val();
const report_base = modal.find('input[name=acc_base_edit]:checked').val();
const city_edit = modal.find("#city_edit option:selected").val();
const police_file_edit = modal.find("#police_file_edit").get(0).files[0];
const plaque_number_edit1 = modal.find("#plaque_number_edit1").val();
const plaque_word_edit1 = modal.find("#plaque_word_edit1").data("value");
const plaque_number_edit2 = modal.find("#plaque_number_edit2").val();
const plaque_number_edit3 = modal.find("#plaque_number_edit3").val();
const plaque_number_edit = plaque_number_edit1 + "-" + plaque_word_edit1 + "-" + plaque_number_edit2 + "-" + plaque_number_edit3;
const axis_name_edit = modal.find("#axis_name_edit").val();
const name_family_edit = modal.find("#name_family_edit").val();
const phone_number_edit = modal.find("#phone_number_edit").val();
const national_code_edit = modal.find("#national_code_edit").val();
const damage_picture1 = modal.find("#editdeviceImg1_edit").get(0).files[0];
const damage_picture2 = modal.find("#editdeviceImg2_edit").get(0).files[0];
const markerEdit_lat = markerEdit.getLatLng().lat.toFixed(6);
const markerEdit_lng = markerEdit.getLatLng().lng.toFixed(6);
let items_damge = [];
let parent = modal.find(".parent-damage");
parent.map(function (e) {
const item_damage = {
id: $(this).find(".damage-items").val(),
value: $(this).find(".damage-value").val(),
amount: $(this).find(".damage-amount").val(),
}
items_damge.push(item_damage);
});
items_damge = JSON.stringify(items_damge);
let formData = new FormData();
formData.append("accident_date", moment(date_edit.getState().selected.unixDate).format('YYYY-MM-DD'));
formData.append("accident_time", moment(time_edit.getState().selected.unixDate).format('HH:mm'));
formData.append("accident_type", accident_type_edit);
formData.append("province_id", province_edit);
formData.append("city_id", city_edit);
formData.append("axis_name", axis_name_edit);
formData.append("driver_name", name_family_edit);
formData.append("phone_number", phone_number_edit);
formData.append("national_code", national_code_edit);
formData.append("plaque", plaque_number_edit);
if (typeof damage_picture1 !== 'undefined') formData.append("damage_picture1", damage_picture1);
if (modal.find('#deleteDeviceImg1_edit').data('isDelete')) formData.append("damage_picture1_is_delete", 1);
if (typeof damage_picture2 !== 'undefined') formData.append("damage_picture2", damage_picture2);
if (modal.find('#deleteDeviceImg2_edit').data('isDelete')) formData.append("damage_picture2_is_delete", 1);
formData.append("report_base", report_base);
if ($("input[name='acc_base_edit']:checked").val() == 0) {
if (typeof police_file_edit !== 'undefined') formData.append("police_file", police_file_edit);
}
if ($("input[name='acc_base_edit']:checked").val() == 0) formData.append("police_serial", police_chart_edit);
if ($("input[name='acc_base_edit']:checked").val() == 0) formData.append("police_file_date", moment(police_date_edit.getState().selected.unixDate).format('YYYY-MM-DD'))
formData.append("lat", markerEdit_lat);
formData.append("lng", markerEdit_lng);
formData.append("items_damge", items_damge);
$.ajax({
url: receipt_edit_api + modal.find("#Receipt_edit_cta").data("rowId"),
type: "POST",
data: formData,
cache: false,
processData: false,
contentType: false,
headers: {
"X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"),
},
beforeSend: function () {
showLoaderScreen();
},
success: function (result) {
thisBtn.prop('disabled', false);
modal.modal('hide')
hideLoaderScreen();
Swal.fire({
icon: "success",
title: "ثبت موفق",
text: "تصادف با موفقیت اصلاح شد",
cancelButtonText: "بستن",
showConfirmButton: false,
showCancelButton: true,
}).then(result => {
table.ajax.reload(null, false);
})
},
error: function (error) {
thisBtn.prop('disabled', false)
hideLoaderScreen();
Swal.fire({
icon: "error",
title: "خطا",
text: "مشکل در اصلاح",
cancelButtonText: "بستن",
showConfirmButton: false,
showCancelButton: true,
});
},
});
}
});
$(document).on('change', '.deposit-redio', function () {
const parent = $(this).closest('.deposit_box')
if ($(this).val() == 1) {
parent.find(".img-input").removeAttr("disabled");
parent.find(".input-text-cleaner").removeAttr("disabled");
} else {
parent.find(".img-input").attr("disabled", "disabled");
parent.find(".input-text-cleaner").val("").attr("disabled", "disabled");
parent.find(".img-input").val("").attr("disabled", "disabled");
parent.find(".img-preview").removeAttr("src");
parent.find(".img-preview").css("display", "none");
parent.find(".img-title").css("display", "");
parent.find(".btn-delete-img").attr("disabled", "disabled");
parent.find(".input-text-cleaner").val("").attr("disabled", "disabled");
parent.find(".depo-insurance").removeClass("validation-checker");
parent.find(".depo-daghi").removeClass("validation-checker");
}
})
$(document).on("click", ".btn-insurance-receipt", function () {
let tr = $(this).closest("tr");
let row = table.row(tr);
let data = row.data();
const modal = $("#insurance_receipt_modal");
modal.find(".img-input").val("").attr("disabled", "disabled");
modal.find(".img-preview").removeAttr("src");
modal.find(".img-preview").css("display", "none");
modal.find(".img-title").css("display", "");
modal.find(".input-text-cleaner").val("").attr("disabled", "disabled");
modal.find(".redio-cleaner[value='0']").prop('checked', true);
modal.find(".depo-insurance").removeClass("validation-checker");
modal.find(".depo-daghi").removeClass("validation-checker");
if (data.status == 2) {
if (data.deposit_insurance_image) {
modal.find("input[name='deposit_redio_insurance'][value='1']").prop('checked', true);
modal.find("#deposit_slip_insurance").val("").removeAttr("disabled");
modal.find("#deposit_slip_insurancePreview").attr("src", `/storage/${data.deposit_insurance_image}`);
modal.find("#deposit_slip_insurancePreview").css("display", "");
modal.find("#deposit_slip_insuranceTitle").css("display", "none");
modal.find('#deposit_slip_insurance_amount').removeAttr("disabled").val(data.deposit_insurance_amount)
}
if (data.deposit_daghi_amount) {
modal.find("input[name='deposit_redio_daghi'][value='1']").prop('checked', true);
modal.find("#deposit_slip_daghi").val("").removeAttr("disabled");
modal.find("#deposit_slip_daghiPreview").attr("src", `/storage/${data.deposit_daghi_image}`);
modal.find("#deposit_slip_daghiPreview").css("display", "");
modal.find("#deposit_slip_daghiTitle").css("display", "none");
modal.find('#deposit_slip_daghi_amount').removeAttr("disabled").val(data.deposit_daghi_amount)
}
}
modal.find("#insurance_receipt_cta").data("rowId", data.id)
modal.find("#insurance_receipt_cta").data("rowStatus", data.status)
modal.find("#insurance_receipt_cta").data("rowSum", data.sum)
modal.modal("show");
});
$(document).on("click", "#insurance_receipt_cta", function () {
const thisBtn = $(this);
const modal = $("#insurance_receipt_modal");
modal.find('.depo-insurance').removeClass("validation-checker");
modal.find(".depo-daghi").removeClass("validation-checker");
if (thisBtn.data("rowStatus") == 1) {
if (modal.find('input[name="deposit_redio_insurance"]:checked').val() == 1) {
if (modal.find(".depo-file-insurance").get(0).files.length == 0) modal.find(".depo-file-insurance").addClass("validation-checker")
if (modal.find(".depo-input-insurance").val() == "") modal.find(".depo-input-insurance").addClass("validation-checker")
}
if (modal.find('input[name="deposit_redio_daghi"]:checked').val() == 1) {
if (modal.find(".depo-file-daghi").get(0).files.length == 0) modal.find(".depo-file-daghi").addClass("validation-checker")
if (modal.find(".depo-input-daghi").val() == "")
modal.find(".depo-input-daghi").addClass("validation-checker")
}
} else if (thisBtn.data("rowStatus") == 2) {
if (modal.find('input[name="deposit_redio_insurance"]:checked').val() == 1) {
if (modal.find(".depo-input-insurance").val() == "") modal.find(".depo-input-insurance").addClass("validation-checker")
}
if (modal.find('input[name="deposit_redio_daghi"]:checked').val() == 1) {
if (modal.find(".depo-input-daghi").val() == "")
modal.find(".depo-input-daghi").addClass("validation-checker")
}
}
const sumForm = Number(modal.find("#deposit_slip_insurance_amount").val()) + Number(modal.find("#deposit_slip_daghi_amount").val())
const maxDaghi = thisBtn.data("rowSum") * 0.3
if (modal.find(".validation-checker").length != 0) {
Swal.fire({
icon: "error",
title: "خطا",
text: "لطفا تمامی مقادیر را تکمیل کنید",
cancelButtonText: "بستن",
showConfirmButton: false,
showCancelButton: true,
});
thisBtn.prop("disabled", false);
} else if (thisBtn.data("rowSum") < sumForm) {
Swal.fire({
icon: "error",
title: "خطا",
text: "مبالغ انتخابی نباید از مبلغ کل خسارت بیشتر باشد",
cancelButtonText: "بستن",
showConfirmButton: false,
showCancelButton: true,
});
thisBtn.prop("disabled", false);
} else if (maxDaghi < Number(modal.find("#deposit_slip_daghi_amount").val())) {
Swal.fire({
icon: "error",
title: "خطا",
text: "مبلغ داغی نباید بیشتر از 30٪ کل خسارت باشد",
cancelButtonText: "بستن",
showConfirmButton: false,
showCancelButton: true,
});
thisBtn.prop("disabled", false);
} else {
let formData = new FormData();
if (thisBtn.data("rowStatus") == 1) {
if (modal.find('input[name="deposit_redio_insurance"]:checked').val() == 1) {
formData.append("deposit_insurance_status", 1);
const deposit_insurance_amount = modal.find("#deposit_slip_insurance_amount").val();
formData.append("deposit_insurance_amount", deposit_insurance_amount);
const deposit_insurance_image = modal.find("#deposit_slip_insurance").get(0).files[0];
formData.append("deposit_insurance_image", deposit_insurance_image);
} else formData.append("deposit_insurance_satus", 0);
if (modal.find('input[name="deposit_redio_daghi"]:checked').val() == 1) {
formData.append("deposit_daghi_status", 1);
const deposit_daghi_amount = modal.find("#deposit_slip_daghi_amount").val();
formData.append("deposit_daghi_amount", deposit_daghi_amount);
const deposit_daghi_image = modal.find("#deposit_slip_daghi").get(0).files[0];
formData.append("deposit_daghi_image", deposit_daghi_image);
} else formData.append("deposit_daghi_status", 0);
} else if (thisBtn.data("rowStatus") == 2) {
if (modal.find('input[name="deposit_redio_insurance"]:checked').val() == 1) {
formData.append("deposit_insurance_status", 1);
const deposit_insurance_amount = modal.find("#deposit_slip_insurance_amount").val();
formData.append("deposit_insurance_amount", deposit_insurance_amount);
if (modal.find(".depo-file-insurance").get(0).files.length != 0) {
const deposit_insurance_image = modal.find("#deposit_slip_insurance").get(0).files[0];
formData.append("deposit_insurance_image", deposit_insurance_image);
}
} else formData.append("deposit_insurance_satus", 0);
if (modal.find('input[name="deposit_redio_daghi"]:checked').val() == 1) {
formData.append("deposit_daghi_status", 1);
const deposit_daghi_amount = modal.find("#deposit_slip_daghi_amount").val();
formData.append("deposit_daghi_amount", deposit_daghi_amount);
if (modal.find(".depo-file-daghi").get(0).files.length != 0) {
const deposit_daghi_image = modal.find("#deposit_slip_daghi").get(0).files[0];
formData.append("deposit_daghi_image", deposit_daghi_image);
}
} else formData.append("deposit_daghi_status", 0)
}
$.ajax({
url: payment_info_api + thisBtn.data("rowId"),
type: "POST",
data: formData,
cache: false,
processData: false,
contentType: false,
headers: {
"X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"),
},
beforeSend: function () {
showLoaderScreen();
},
success: function (result) {
thisBtn.prop('disabled', false);
modal.modal('hide')
hideLoaderScreen();
Swal.fire({
icon: "success",
title: "ثبت موفق",
text: "اطلاعات فیش با موفقیت ثبت شد",
cancelButtonText: "بستن",
showConfirmButton: false,
showCancelButton: true,
}).then(result => {
table.ajax.reload(null, false);
})
},
error: function (error) {
thisBtn.prop('disabled', false)
hideLoaderScreen();
Swal.fire({
icon: "error",
title: "خطا",
text: "مشکل در ثبت",
cancelButtonText: "بستن",
showConfirmButton: false,
showCancelButton: true,
});
},
});
}
});
$(document).on("click", ".btn-documentation-deposit", function () {
let tr = $(this).closest("tr");
let row = table.row(tr);
let data = row.data();
const modal = $("#deposit_documentation_modal");
modal.find(".input-text-cleaner").val("");
modal.find("#deposit_sum_label").text(Number(data.sum).toLocaleString("en"))
modal.find("#deposit_sum").val(data.sum)
modal.find("#deposit_insurance_label").text(Number(data.deposit_insurance_amount).toLocaleString("en"))
modal.find("#deposit_insurance").val(data.deposit_insurance_amount)
modal.find("#deposit_daghi_label").text(Number(data.deposit_daghi_amount).toLocaleString("en"))
modal.find("#deposit_daghi").val(data.deposit_daghi_amount)
const pay = data.sum - (data.deposit_insurance_amount + data.deposit_daghi_amount)
modal.find("#deposit_pay_label").text(Number(pay).toLocaleString("en"))
modal.find("#deposit_pay").val(data.pay)
modal.find("#deposit_documentation_cta").removeClass('btn-success btn-warning')
modal.find("#deposit_send_sms_again_cta").addClass('d-none')
if (data.status == 2) {
modal.find("#deposit_documentation_cta").text('ایجاد فاکتور').addClass('btn-success')
modal.find("#deposit_send_sms_again_cta").addClass('d-none')
} else if (data.status == 3) {
modal.find("#deposit_documentation_cta").text('استعلام پرداخت').addClass('btn-warning')
modal.find("#deposit_send_sms_again_cta").removeClass('d-none')
}
modal.find("#deposit_documentation_cta").data("rowId", data.id)
modal.find("#deposit_send_sms_again_cta").data("rowId", data.id)
modal.find("#deposit_documentation_cta").data("rowStatus", data.status)
modal.modal("show");
});
$(document).on('click', '#deposit_send_sms_again_cta', function () {
const thisBtn = $(this);
$.ajax({
url: send_sms_again + thisBtn.data("rowId"),
type: "GET",
cache: false,
processData: false,
contentType: false,
headers: {
"X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"),
},
beforeSend: function () {
showLoaderScreen();
},
success: function (result) {
thisBtn.prop('disabled', false);
hideLoaderScreen();
Swal.fire({
icon: "success",
title: "ثبت موفق",
text: "پیام با موفقیت ارسال شد!",
cancelButtonText: "بستن",
showConfirmButton: false,
showCancelButton: true,
})
},
error: function (error) {
thisBtn.prop('disabled', false)
hideLoaderScreen();
Swal.fire({
icon: "error",
title: "خطا",
text: "مشکل در ارسال پیام",
cancelButtonText: "بستن",
showConfirmButton: false,
showCancelButton: true,
});
},
});
})
$(document).on('click', '#deposit_documentation_cta', function () {
const thisBtn = $(this);
const modal = $("#deposit_documentation_modal");
thisBtn.prop("disabled", true);
if (thisBtn.data("rowStatus") == 2) {
$.ajax({
url: invoice_bill_api + thisBtn.data("rowId"),
type: "POST",
cache: false,
processData: false,
contentType: false,
headers: {
"X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"),
},
beforeSend: function () {
showLoaderScreen();
},
success: function (result) {
thisBtn.prop('disabled', false);
hideLoaderScreen();
if (result.status == 3) {
modal.find("#deposit_documentation_cta").text('استعلام پرداخت').addClass('btn-warning')
modal.find("#deposit_documentation_cta").data("rowStatus", result.status)
modal.find("#deposit_send_sms_again_cta").removeClass('d-none')
}
Swal.fire({
icon: "success",
title: "ثبت موفق",
text: "فاکتور با موفقیت ایجاد شد!",
cancelButtonText: "بستن",
showConfirmButton: false,
showCancelButton: true,
}).then(result => {
table.ajax.reload(null, false);
})
},
error: function (error) {
thisBtn.prop('disabled', false)
hideLoaderScreen();
Swal.fire({
icon: "error",
title: "خطا",
text: "مشکل در ثبت",
cancelButtonText: "بستن",
showConfirmButton: false,
showCancelButton: true,
});
},
});
} else if (thisBtn.data("rowStatus") == 3) {
$.ajax({
url: call_payment_status_api + thisBtn.data("rowId"),
type: "POST",
cache: false,
processData: false,
contentType: false,
headers: {
"X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"),
},
beforeSend: function () {
showLoaderScreen();
},
success: function (result) {
thisBtn.prop('disabled', false);
hideLoaderScreen();
if (result.status == 3) {
Swal.fire({
icon: "warning",
title: "وضعیت پرداخت",
text: "فاکتور پرداخت نشده است!",
cancelButtonText: "بستن",
showConfirmButton: false,
showCancelButton: true,
})
}
else if (result.status == 4) {
Swal.fire({
icon: "success",
title: "وضعیت پرداخت",
text: "فاکتور پرداخت شده است!",
cancelButtonText: "بستن",
showConfirmButton: false,
showCancelButton: true,
})
modal.modal('hide')
table.ajax.reload(null, false);
}
},
error: function (error) {
thisBtn.prop('disabled', false)
hideLoaderScreen();
Swal.fire({
icon: "error",
title: "خطا",
text: "مشکل در ثبت",
cancelButtonText: "بستن",
showConfirmButton: false,
showCancelButton: true,
});
},
});
}
})
$(document).on("click", ".btn-all-data-show", function () {
const modal = $("#show_all_data_modal");
let tr = $(this).closest("tr");
let row = table.row(tr);
let id = row.data().id;
modal.find("#table_body").empty();
modal.find(".img-box-1").empty();
modal.find(".img-box-2").empty();
modal.find(".amount-box-deposit-insurance").empty();
modal.find(".img-box-deposit-insurance").empty();
modal.find(".amount-box-deposit-daghi").empty();
modal.find(".img-box-deposit-daghi").empty();
modal.find(".empty-data-all").text("")
modal.find("#police_file_all button").prop("disabled", false);
modal.find("#police_file_all").removeAttr("href");
modal.modal("show");
$.ajax({
url: get_all_info_api + id,
type: "GET",
cache: false,
async: false,
contentType: false,
processData: false,
success: function (results) {
modal.find("#accident_date_all").text(moment(results.accident_date).locale('fa').format('YYYY/MM/DD'));
modal.find("#accident_time_all").text(results.accident_time);
modal.find("#province_fa_all").text(results.province_fa);
modal.find("#city_fa_all").text(results.city_fa);
modal.find("#driver_name_all").text(results.driver_name);
const plaque_all = results.plaque.split("-");
modal.find("#plaque_all1").text(plaque_all[0]);
modal.find("#plaque_all2").append(plaque_all[1] == "*" ? "<i class='fa fa-wheelchair'></i>" : plaque_all[1]);
modal.find("#plaque_all3").text(plaque_all[2]);
modal.find("#plaque_all4").text(plaque_all[3]);
modal.find("#accident_type_fa_all").text(results.accident_type_fa);
modal.find("#axis_name_all").text(results.axis_name);
modal.find("#status_all").text(results.status_fa);
results.police_serial != null ? modal.find("#police_serial_all").text(results.police_serial) : modal.find("#police_serial_all").text("-")
results.police_file != null ? modal.find("#police_file_all").attr("href", `/storage/${results.police_file}`) : modal.find("#police_file_all button").prop("disabled", true);
results.damage_picture1 != null ? modal.find(".img-box-1").append(`<a href="/storage/${results.damage_picture1}" download=""><img style="max-width: 100%; max-height: 200px;" src="/storage/${results.damage_picture1}" alt=""></a>`) : modal.find(".img-box-1").append(`<h5 class='p-3 mx-auto text-info'>تصویری آپلود نشده است<h5>`);
results.damage_picture2 != null ? modal.find(".img-box-2").append(`<a href="/storage/${results.damage_picture2}" download=""><img style="max-width: 100%; max-height: 200px;" src="/storage/${results.damage_picture2}" alt=""></a>`) : modal.find(".img-box-2").append(`<h5 class='p-3 mx-auto text-info'>تصویری آپلود نشده است<h5>`);
results.deposit_insurance_image != null ? modal.find(".img-box-deposit-insurance").append(`<a href="/storage/${results.deposit_insurance_image}" download=""><img style="max-width: 100%; max-height: 200px;" src="/storage/${results.deposit_insurance_image}" alt=""></a>`) : "تصویری آپلود نشده است";
results.deposit_insurance_image != null ? modal.find(".amount-box-deposit-insurance").html(`<span>سهم بیمه : <h6>${Number(results.deposit_insurance_amount).toLocaleString("en")} ریال</h6></span>`) : modal.find(".amount-box-deposit-insurance").html(`<span>سهم بیمه : <h6>${Number(0).toLocaleString("en")} ریال</h6></span>`);
results.deposit_daghi_image != null ? modal.find(".img-box-deposit-daghi").append(`<a href="/storage/${results.deposit_daghi_image}" download=""><img style="max-width: 100%; max-height: 200px;" src="/storage/${results.deposit_daghi_image}" alt=""></a>`) : "تصویری آپلود نشده است";
results.deposit_daghi_image != null ? modal.find(".amount-box-deposit-daghi").html(`<span>سهم داغی : <h6>${Number(results.deposit_daghi_amount).toLocaleString("en")} ریال</h6></span>`) : modal.find(".amount-box-deposit-daghi").html(`<span>سهم داغی : <h6>${Number(0).toLocaleString("en")} ریال</h6></span>`);
results.bill_code != null ? modal.find(".text-box-bill-code").html(`<span><h6>${results.bill_code} </h6></span>`) : modal.find(".text-box-bill-code").html(`<span><h6>فاکتوری صادر نشده است.</h6></span>`);
Number(results.status) > 3 ? modal.find(".text-box-final-amount").html(`<span><h6>${Number(results.final_amount).toLocaleString("en")} </h6></span>`) : modal.find(".text-box-final-amount").html(`<span><h6>مبلغی واریز نشده است.</h6></span>`);
const markerPosition = [results.lat, results.lng];
modal.find("#map_lat_all").text(results.lat);
modal.find("#map_lng_all").text(results.lng);
if (mapShow_all == null) {
buildMapShowAndMarker_all(markerPosition).then(() => {
hideLoaderScreen();
});
} else {
changePositionMarkerInMapShow_all(markerPosition).then(() => {
hideLoaderScreen();
});
}
const damages = results.damages;
let row_counter;
let i;
for (i = 0; i < damages.length; i++) {
row_counter = i + 1;
let table_row_content = `<tr>`;
table_row_content += `<td class="text-center">${row_counter}</td>`;
table_row_content += `<td class="text-center">${damages[i].title}</td>`;
table_row_content += `<td class="text-center">${damages[i].pivot.unit}</td>`;
table_row_content += `<td class="text-center">${damages[i].pivot.value}</td>`;
table_row_content += `<td class="text-center">${Number(damages[i].pivot.amount).toLocaleString("en")}</td>`;
table_row_content += `</tr>`;
$("#table_body").append(table_row_content);
}
row_counter = i + 1;
let table_row_content = `<tr>`;
table_row_content += `<td class="text-center">${row_counter}</td>`;
table_row_content += `<td class="text-center" colspan="3">اجرت نصب</td>`;
table_row_content += `<td class="text-center">${Number(results.ojrate_nasb).toLocaleString("en")}</td>`;
table_row_content += `</tr>`;
$("#table_body").append(table_row_content)
modal.find("#sum_all").text(Number(results.sum).toLocaleString("en"));
},
error: function () {
Swal.fire({
icon: "error",
title: "خطا",
text: "مشکل در دریافت تمامی اطلاعات",
confirmButtonText: "بروزرسانی صفحه",
showLoaderOnConfirm: true,
preConfirm: () => {
location.reload(true);
},
});
},
});
});
$("#btn_excel-download").on("click", function () {
let currentDate = {};
let queryParems = [];
const province = $('select[name="select-province-excel"]').val();
if (!(
$("#datapicker-from-excel-table").is(":disabled") &&
$("#datapicker-to-excel-table").is(":disabled")
)) {
if (
excelDatepickerFirstTable.from != "" &&
excelDatepickerFirstTable.to != ""
) {
currentDate.from = moment(
excelDatepickerFirstTable.from.getState().selected.year +
"/" +
excelDatepickerFirstTable.from.getState().selected.month +
"/" +
excelDatepickerFirstTable.from.getState().selected.date,
"jYYYY/jM/jD"
).format("YYYY-MM-DD");
currentDate.to = moment(
excelDatepickerFirstTable.to.getState().selected.year +
"/" +
excelDatepickerFirstTable.to.getState().selected.month +
"/" +
excelDatepickerFirstTable.to.getState().selected.date,
"jYYYY/jM/jD"
).format("YYYY-MM-DD");
queryParems.push(`fromDate=${currentDate.from}`);
queryParems.push(`toDate=${currentDate.to}`);
}
}
if (province != 0) queryParems.push(`province=${province}`);
const url = `/reports/receipt${queryParems.length != 0 ? `?${queryParems.join("&")}` : ""}`;
window.open(url, "_blank");
});
$(document).on("click", ".close-box", function () {
const parent_damage = $(this).parents(".parent-damage").remove();
damege_item_counter--
});
$(document).on("change", "#province_edit", function () {
const This = $(this);
let latLonPro = [
This.find("option:selected").data("centerLat"),
This.find("option:selected").data("centerLon")
]
editMap.setView(latLonPro);
markerEdit.setLatLng(latLonPro);
$("#edit_project_start_map").val(markerEdit.getLatLng().lat.toFixed(6) + markerEdit.getLatLng().lng.toFixed(6));
});
$(document).on("change", "#province_add", function () {
const This = $(this);
let latLonPro = [
This.find("option:selected").data("centerLat"),
This.find("option:selected").data("centerLon")
]
addMap.setView(latLonPro);
markerAdd.setLatLng(latLonPro);
});
$(document).on("keyup", ".damage-value", function () {
console.log($(this).parents(".parent-damage").find(".damage-amount").prop("readonly") != true);
if ($(this).parents(".parent-damage").find(".damage-amount").prop("readonly") == true) {
const parent = $(this).parents(".parent-damage");
const item_parent = parent.find(".damage-items");
const base_price = item_parent.find("option:selected").data("basePrice");
$(this).val() != "" ? parent.find(".damage-amount").val(parseInt($(this).val()) * parseInt(base_price)) : parent.find(".damage-amount").val("");
}
});
$(document).on("click", ".btn-letter-to-insurance", function () {
let tr = $(this).closest("tr");
let row = table.row(tr);
let id = row.data().id;
Swal.fire({
icon: "warning",
title: "آیا برای صدور نامه به بیمه مطمئن هستید؟",
showCancelButton: true,
confirmButtonColor: "#3085d6",
cancelButtonColor: "#d33",
confirmButtonText: "بله",
cancelButtonText: "منصرف شدم!",
showLoaderOnConfirm: true,
preConfirm: () => {
const sendToInsurancePage = window.open(sendToInsurance + id);
showLoaderScreen();
setTimeout(function () {
table.ajax.reload(null, false);
}, 3000);
// location.reload(true);
},
});
});
$(document).on("click", ".btn-letter-to-police", function () {
let tr = $(this).closest("tr");
let row = table.row(tr);
let id = row.data().id;
Swal.fire({
icon: "warning",
title: "آیا برای صدور نامه به پلیس راه مطمئن هستید؟",
showCancelButton: true,
confirmButtonColor: "#3085d6",
cancelButtonColor: "#d33",
confirmButtonText: "بله",
cancelButtonText: "منصرف شدم!",
showLoaderOnConfirm: true,
preConfirm: () => {
window.open(documentRelease + id, '_blank');
showLoaderScreen();
setTimeout(function () {
table.ajax.reload(null, false);
}, 3000);
// location.reload(true);
},
});
});
$(document).on("click", "#show_all_data_cta", function () {
printElem = document.getElementById("printthis");
printElement(printElem);
});
function printElement(elem) {
var domClone = elem.cloneNode(true);
var $printSection = document.getElementById("printSection");
if (!$printSection) {
var $printSection = document.createElement("div");
$printSection.id = "printSection";
document.body.appendChild($printSection);
}
$printSection.innerHTML = "";
$printSection.appendChild(domClone);
window.print();
}
$(document).on("click", "#plaque_word_add1", function () {
const modal = $("#plaque_text_modal");
modal.modal("show");
modal.find(".select-text").prop("disabled", false)
modal.find(".last-time-select").prop("disabled", true)
});
$(document).on("click", "#plaque_word_edit1", function () {
const modal = $("#plaque_text_edit_modal");
modal.modal("show");
modal.find(".select-text").prop("disabled", false)
modal.find(".last-time-select").prop("disabled", true)
});
function searchPlaque() {
var input, filter, ul, li, i, txtValue;
input = document.getElementById("serach_plaque_field");
filter = input.value.toUpperCase();
ul = document.getElementById("plaque_text_box");
li = ul.getElementsByTagName("button");
for (i = 0; i < li.length; i++) {
txtValue = li[i].textContent || li[i].innerText;
if (txtValue.toUpperCase().indexOf(filter) > -1) {
li[i].style.display = "";
} else {
li[i].style.display = "none";
}
}
}
$('#plaque_text_box').on("click", ".select-text", function () {
const modal = $(this).parents(".modal");
$("#plaque_word_add1").empty();
$("#plaque_word_add1").data("value", $(this).data("value"));
if ($(this).data("value") == "*") {
$("#plaque_word_add1").append(`<i class="fa fa-wheelchair"></i>`);
} else {
$("#plaque_word_add1").append($(this).data("value"));
}
modal.find(".select-text").removeClass("last-time-select")
$(this).addClass("last-time-select");
modal.modal("hide");
});
function searchPlaqueEdit() {
var input, filter, ul, li, i, txtValue;
input = document.getElementById("serach_plaque_field_edit");
filter = input.value.toUpperCase();
ul = document.getElementById("plaque_text_box_edit");
li = ul.getElementsByTagName("button");
for (i = 0; i < li.length; i++) {
txtValue = li[i].textContent || li[i].innerText;
if (txtValue.toUpperCase().indexOf(filter) > -1) {
li[i].style.display = "";
} else {
li[i].style.display = "none";
}
}
}
$('#plaque_text_box_edit').on("click", ".select-text", function () {
const modal = $(this).parents(".modal");
$("#plaque_word_edit1").empty();
$("#plaque_word_edit1").data("value", $(this).data("value"));
if ($(this).data("value") == "*") {
$("#plaque_word_edit1").append(`<i class="fa fa-wheelchair"></i>`);
} else {
$("#plaque_word_edit1").append($(this).data("value"));
}
modal.find(".select-text").removeClass("last-time-select");
$(this).addClass("last-time-select");
modal.modal("hide");
});
$(document).on("change", ".damage-items", function () {
const parent = $(this).parents(".parent-damage");
if ($(this).find("option:selected").data("basePrice") == 0) {
parent.find(".damage-amount").prop("readonly", false);
} else {
parent.find(".damage-amount").prop("readonly", true);
}
});
function national_code_validation(code) {
if (code == "1111111111" || code == "2222222222" || code == "3333333333" || code == "4444444444" || code == "5555555555" || code == "6666666666" || code == "7777777777" || code == "8888888888" || code == "9999999999") { return false }
var L = code.length;
if (L < 8 || parseInt(code, 10) == 0) { return false }
code = ('0000' + code).substr(L + 4 - 10);
if (parseInt(code.substr(3, 6), 10) == 0) { return false }
var c = parseInt(code.substr(9, 1), 10);
var s = 0;
for (var i = 0; i < 9; i++)
s += parseInt(code.substr(i, 1), 10) * (10 - i);
s = s % 11;
return (s < 2 && c == s) || (s >= 2 && c == (11 - s));
}
// end national code validation