645 lines
19 KiB
JavaScript
645 lines
19 KiB
JavaScript
var isValidProvider = false;
|
|
var isValidCity = false;
|
|
var isNationalCode = false;
|
|
|
|
$(function () {
|
|
|
|
// show modal form type
|
|
$("#form-type").modal({
|
|
backdrop: "static"
|
|
});
|
|
|
|
//reset form and refresh
|
|
$('#reset').on('click', function () {
|
|
location.reload();
|
|
});
|
|
|
|
// select device tupe
|
|
$('.btn-type').on('click', function () {
|
|
buildForm($(this).val()).then(
|
|
(onResolved) => {
|
|
$('#form-type').modal('hide')
|
|
}
|
|
);
|
|
});
|
|
|
|
// get all provinces
|
|
$.ajax({
|
|
url: "https://rms.rmto.ir/cmms/provinces/all",
|
|
type: "GET",
|
|
headers: {
|
|
accept: "application/json",
|
|
"X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"),
|
|
},
|
|
cache: false,
|
|
contentType: false,
|
|
processData: false,
|
|
success: function (res) {
|
|
$("#province").empty();
|
|
$("#province").append('<option value="0">انتخاب استان</option>');
|
|
$.each(res.data, function (key, value) {
|
|
$("#province").append(
|
|
"<option value=" +
|
|
value.province_id +
|
|
">" +
|
|
value.province_fa +
|
|
"</option>"
|
|
);
|
|
});
|
|
},
|
|
});
|
|
|
|
// get cities by provicens_id and validation
|
|
$("#province").change(function () {
|
|
isValidProvider = false;
|
|
var province_id = $(this).val();
|
|
if (province_id != 0) {
|
|
$.ajax({
|
|
url: "https://rms.rmto.ir/api/cmms/cities?id=" + province_id,
|
|
type: "GET",
|
|
headers: {
|
|
accept: "application/json",
|
|
"X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"),
|
|
},
|
|
cache: false,
|
|
contentType: false,
|
|
processData: false,
|
|
success: function (res) {
|
|
$("#city").empty();
|
|
$("#city").append('<option value="0">انتخاب شهرستان</option>');
|
|
$.each(res.data, function (key, value) {
|
|
$("#city").append(
|
|
"<option value=" + value.id + ">" + value.name_fa + "</option>"
|
|
);
|
|
});
|
|
},
|
|
});
|
|
} else {
|
|
$("#city").empty();
|
|
$("#city").append('<option value="0">انتخاب شهرستان</option>');
|
|
}
|
|
|
|
// validation province
|
|
if (province_id != 0) {
|
|
isValidProvider = true;
|
|
} else {
|
|
isValidProvider = false;
|
|
}
|
|
|
|
formValid();
|
|
});
|
|
|
|
// validation city
|
|
$("#city").change(function () {
|
|
isValidCity = false;
|
|
var cityId = $(this).val();
|
|
if (cityId != 0) {
|
|
isValidCity = true;
|
|
} else {
|
|
isValidCity = false;
|
|
}
|
|
|
|
formValid();
|
|
});
|
|
|
|
|
|
$(".ott").click(function (event) {
|
|
if (event.target.type !== "radio") {
|
|
$(":radio", this).trigger("click");
|
|
}
|
|
});
|
|
|
|
// send all data
|
|
$("#send").on("click", function () {
|
|
var isRequire = true;
|
|
var car_type = $("#car_type").val()
|
|
var data = new FormData();
|
|
|
|
// append Moshakhasat
|
|
if ($("#personal_num").val() != '')
|
|
data.append("dedicated_number", $("#personal_num").val());
|
|
else
|
|
isRequire = false
|
|
|
|
if ($("#shasi_num").val() != '')
|
|
data.append("chassis_number", $("#shasi_num").val());
|
|
else
|
|
isRequire = false
|
|
|
|
if ($("#province").val() != '')
|
|
data.append("province_id", $("#province").val());
|
|
else
|
|
isRequire = false
|
|
|
|
if ($("#city").val() != '')
|
|
data.append("city_id", $("#city").val());
|
|
else
|
|
isRequire = false
|
|
|
|
if ($("#device_name").val() != '')
|
|
data.append("device_name", $("#device_name").val());
|
|
else
|
|
isRequire = false
|
|
|
|
if ($("#gps_code").val() != '')
|
|
data.append("gps_code", $("#gps_code").val());
|
|
else
|
|
isRequire = false
|
|
|
|
if ($("#operator_name").val() != '')
|
|
data.append("operator_name", $("#operator_name").val());
|
|
else
|
|
isRequire = false
|
|
|
|
if ($("#national_code").val() != '')
|
|
data.append("operator_nationalcode", $("#national_code").val());
|
|
else
|
|
isRequire = false
|
|
|
|
if ($("#mobile").val() != '')
|
|
data.append("operator_phone", $("#mobile").val());
|
|
else
|
|
isRequire = false
|
|
|
|
|
|
// check values undefined before append
|
|
if (typeof $('input[name="motor"]:checked').val() !== "undefined")
|
|
data.append("motor", $('input[name="motor"]:checked').val());
|
|
else
|
|
isRequire = false
|
|
|
|
if (typeof $('input[name="power"]:checked').val() !== "undefined")
|
|
data.append("power", $('input[name="power"]:checked').val());
|
|
else
|
|
isRequire = false
|
|
|
|
if (typeof $('input[name="hydraulic"]:checked').val() !== "undefined")
|
|
data.append("hydraulic", $('input[name="hydraulic"]:checked').val());
|
|
else
|
|
isRequire = false
|
|
|
|
if (car_type == "B") {
|
|
if (typeof $('input[name="ripper"]:checked').val() !== "undefined")
|
|
data.append("ripper", $('input[name="ripper"]:checked').val());
|
|
else
|
|
isRequire = false
|
|
}
|
|
|
|
if (typeof $('input[name="zirbandi"]:checked').val() !== "undefined")
|
|
data.append("zirbandi", $('input[name="zirbandi"]:checked').val());
|
|
else
|
|
isRequire = false
|
|
|
|
if (car_type == "G") {
|
|
if (typeof $('input[name="jolobandi"]:checked').val() !== "undefined")
|
|
data.append("jolobandi", $('input[name="jolobandi"]:checked').val());
|
|
else
|
|
isRequire = false
|
|
}
|
|
|
|
if (car_type == "Ex") {
|
|
if (typeof $('input[name="bucket"]:checked').val() !== "undefined")
|
|
data.append("bucket", $('input[name="bucket"]:checked').val());
|
|
else
|
|
isRequire = false
|
|
}
|
|
|
|
if (typeof $('input[name="chassis"]:checked').val() !== "undefined")
|
|
data.append("chassis", $('input[name="chassis"]:checked').val());
|
|
else
|
|
isRequire = false
|
|
|
|
if (typeof $('input[name="electrical"]:checked').val() !== "undefined")
|
|
data.append("electrical", $('input[name="electrical"]:checked').val());
|
|
else
|
|
isRequire = false
|
|
|
|
if (typeof $('input[name="safety"]:checked').val() !== "undefined")
|
|
data.append("safety", $('input[name="safety"]:checked').val());
|
|
else
|
|
isRequire = false
|
|
|
|
if (typeof $('input[name="gps"]:checked').val() !== "undefined")
|
|
data.append("gps", $('input[name="gps"]:checked').val());
|
|
else
|
|
isRequire = false
|
|
|
|
if (typeof $('input[name="color"]:checked').val() !== "undefined")
|
|
data.append("color", $('input[name="color"]:checked').val());
|
|
else
|
|
isRequire = false
|
|
|
|
|
|
|
|
data.append("motor_description", $('input[name="motor_description"]').val());
|
|
|
|
data.append("power_description", $('input[name="power_description"]').val());
|
|
|
|
data.append("hydraulic_description", $('input[name="hydraulic_description"]').val());
|
|
|
|
if (car_type == "B")
|
|
data.append("ripper_description", $('input[name="ripper_description"]').val());
|
|
|
|
data.append("zirbandi_description", $('input[name="zirbandi_description"]').val());
|
|
|
|
if (car_type == "G")
|
|
data.append("jolobandi_description", $('input[name="jolobandi_description"]').val());
|
|
|
|
if (car_type == "Ex")
|
|
data.append("bucket_description", $('input[name="bucket_description"]').val());
|
|
|
|
data.append("chassis_description", $('input[name="chassis_description"]').val());
|
|
|
|
data.append("electrical_description", $('input[name="electrical_description"]').val());
|
|
|
|
data.append("safety_description", $('input[name="safety_description"]').val());
|
|
|
|
data.append("gps_description", $('input[name="gps_description"]').val());
|
|
|
|
data.append("color_description", $('input[name="color_description"]').val());
|
|
|
|
data.append("service_description", $('input[name="service_description"]').val());
|
|
|
|
data.append("fuel_description", $('input[name="fuel_description"]').val());
|
|
|
|
|
|
if ($('input[name="motor_score"]').val() != '')
|
|
data.append("motor_score", $('input[name="motor_score"]').val());
|
|
else
|
|
isRequire = false
|
|
|
|
if ($('input[name="power_score"]').val() != '')
|
|
data.append("power_score", $('input[name="power_score"]').val());
|
|
else
|
|
isRequire = false
|
|
|
|
if ($('input[name="hydraulic_score"]').val() != '')
|
|
data.append("hydraulic_score", $('input[name="hydraulic_score"]').val());
|
|
else
|
|
isRequire = false
|
|
|
|
if (car_type == "B") {
|
|
if ($('input[name="ripper_score"]').val() != '')
|
|
data.append("ripper_score", $('input[name="ripper_score"]').val());
|
|
else
|
|
isRequire = false
|
|
}
|
|
|
|
if ($('input[name="zirbandi_score"]').val() != '')
|
|
data.append("zirbandi_score", $('input[name="zirbandi_score"]').val());
|
|
else
|
|
isRequire = false
|
|
|
|
if (car_type == "G") {
|
|
if ($('input[name="jolobandi_score"]').val() != '')
|
|
data.append("jolobandi_score", $('input[name="jolobandi_score"]').val());
|
|
else
|
|
isRequire = false
|
|
}
|
|
|
|
if (car_type == "Ex") {
|
|
if ($('input[name="bucket_score"]').val() != '')
|
|
data.append("bucket_score", $('input[name="bucket_score"]').val());
|
|
else
|
|
isRequire = false
|
|
}
|
|
|
|
if ($('input[name="chassis_score"]').val() != '')
|
|
data.append("chassis_score", $('input[name="chassis_score"]').val());
|
|
else
|
|
isRequire = false
|
|
|
|
if ($('input[name="electrical_score"]').val() != '')
|
|
data.append("electrical_score", $('input[name="electrical_score"]').val());
|
|
else
|
|
isRequire = false
|
|
|
|
if ($('input[name="safety_score"]').val() != '')
|
|
data.append("safety_score", $('input[name="safety_score"]').val());
|
|
else
|
|
isRequire = false
|
|
|
|
if ($('input[name="gps_score"]').val() != '')
|
|
data.append("gps_score", $('input[name="gps_score"]').val());
|
|
else
|
|
isRequire = false
|
|
|
|
if ($('input[name="color_score"]').val() != '')
|
|
data.append("color_score", $('input[name="color_score"]').val());
|
|
else
|
|
isRequire = false
|
|
|
|
if ($('input[name="service_status"]').val() != '')
|
|
data.append("service_status", $('input[name="service_status"]').val());
|
|
else
|
|
isRequire = false
|
|
|
|
if ($('input[name="fuel_form"]').val() != '')
|
|
data.append("fuel_form", $('input[name="fuel_form"]').val());
|
|
else
|
|
isRequire = false
|
|
|
|
|
|
// append total points
|
|
data.append("total_points", $('input[name="total_points"]').val());
|
|
|
|
|
|
// check questions undefined before append
|
|
if (typeof $('input[name="question1"]:checked').val() !== "undefined")
|
|
data.append("question1", $('input[name="question1"]:checked').val());
|
|
else
|
|
isRequire = false
|
|
|
|
if (typeof $('input[name="question2"]:checked').val() !== "undefined")
|
|
data.append("question2", $('input[name="question2"]:checked').val());
|
|
else
|
|
isRequire = false
|
|
|
|
if (typeof $('input[name="question3"]:checked').val() !== "undefined")
|
|
data.append("question3", $('input[name="question3"]:checked').val());
|
|
else
|
|
isRequire = false
|
|
|
|
if (typeof $('input[name="question4"]:checked').val() !== "undefined")
|
|
data.append("question4", $('input[name="question4"]:checked').val());
|
|
else
|
|
isRequire = false
|
|
|
|
if (typeof $('input[name="question5"]:checked').val() !== "undefined")
|
|
data.append("question5", $('input[name="question5"]:checked').val());
|
|
else
|
|
isRequire = false
|
|
|
|
// append auditor and members
|
|
data.append("auditor_name", $("#auditor_name").val());
|
|
data.append("member1_name", $("#member1_name").val());
|
|
data.append("member2_name", $("#member2_name").val());
|
|
data.append("member3_name", $("#member3_name").val());
|
|
|
|
data.append("auditor_position", $("#auditor_position").val());
|
|
data.append("member1_position", $("#member1_position").val());
|
|
data.append("member2_position", $("#member2_position").val());
|
|
data.append("member3_position", $("#member3_position").val());
|
|
|
|
// append auditor_name
|
|
data.append("car_type", $("#car_type").val());
|
|
|
|
// append device images
|
|
if (typeof $('#deviceImg1').get(0).files[0] !== "undefined")
|
|
data.append("image1", $('#deviceImg1').get(0).files[0]);
|
|
else
|
|
isRequire = false
|
|
|
|
if (typeof $('#deviceImg2').get(0).files[0] !== "undefined")
|
|
data.append("image2", $('#deviceImg2').get(0).files[0]);
|
|
else
|
|
isRequire = false
|
|
|
|
if (typeof $('#deviceImg3').get(0).files[0] !== "undefined")
|
|
data.append("image3", $('#deviceImg3').get(0).files[0]);
|
|
else
|
|
isRequire = false
|
|
|
|
// append proceedings file
|
|
if (typeof $('#proceedingsFile').get(0).files[0] !== "undefined")
|
|
data.append("file1", $('#proceedingsFile').get(0).files[0]);
|
|
else
|
|
isRequire = false
|
|
|
|
if (isRequire) {
|
|
$.ajax({
|
|
url: "https://rms.rmto.ir/cmms/create",
|
|
type: "POST",
|
|
headers: {
|
|
accept: "application/json",
|
|
"X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"),
|
|
},
|
|
beforeSend: function () {
|
|
$('#send').attr('disabled', 'disabled');
|
|
$('#send').text('در حال ثبت');
|
|
},
|
|
data: data,
|
|
cache: false,
|
|
contentType: false,
|
|
processData: false,
|
|
success: function (res) {
|
|
$('#print').removeAttr('disabled');
|
|
$('#reset').removeAttr('disabled');
|
|
$('#form_number').val(res.data.form_number);
|
|
$('#form-date').val(moment().format('jYYYY/jMM/jDD'))
|
|
$('#send').text('ثبت شد');
|
|
$('#send').removeClass('btn-primary');
|
|
$('#send').addClass('btn-success');
|
|
},
|
|
error: function (xhr) {
|
|
$('#send').removeAttr('disabled');
|
|
$('#send').text('ثبت');
|
|
},
|
|
});
|
|
}
|
|
});
|
|
|
|
// print
|
|
$('#print').on('click', function () {
|
|
window.print();
|
|
});
|
|
|
|
// get live dedicated_number by search
|
|
$("#personal_num").autocomplete({
|
|
source: function (request, response) {
|
|
var reqData = new FormData();
|
|
reqData.append("data", request.term);
|
|
$.ajax({
|
|
url: "https://rms.rmto.ir/api/cmms/search",
|
|
type: "POST",
|
|
headers: {
|
|
accept: "application/json",
|
|
"X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"),
|
|
},
|
|
data: reqData,
|
|
cache: false,
|
|
contentType: false,
|
|
processData: false,
|
|
success: function (res) {
|
|
response(res.data);
|
|
},
|
|
});
|
|
},
|
|
select: function (event, ui) {
|
|
var reqData = new FormData();
|
|
reqData.append("dedicated_number", ui.item.label);
|
|
$.ajax({
|
|
url: "https://rms.rmto.ir/api/cmms/machine",
|
|
type: "POST",
|
|
headers: {
|
|
accept: "application/json",
|
|
"X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"),
|
|
},
|
|
data: reqData,
|
|
cache: false,
|
|
contentType: false,
|
|
processData: false,
|
|
success: function (res) {
|
|
console.log(res);
|
|
resetMoshakhasat();
|
|
isValidProvider = false;
|
|
isValidCity = false;
|
|
|
|
if (typeof res.data.operator_nationalcode !== "undefined") {
|
|
if (checkNationalCode(res.data.operator_nationalcode))
|
|
isNationalCode = true;
|
|
}
|
|
|
|
formValid();
|
|
|
|
$("#shasi_num").val(res.data.body_number);
|
|
$("#currentProvince").text(res.data.unit_group_fa);
|
|
$("#currentCity").text(res.data.unit_name);
|
|
$("#device_name").val(res.data.car_name);
|
|
$("#oprator_name").val(res.data.driver_name);
|
|
$("#gps_code").val(res.data.gps_code);
|
|
$("#national_code").val(res.data.operator_nationalcode);
|
|
$("#operator_phone").val(res.data.mobile);
|
|
},
|
|
});
|
|
},
|
|
minLength: 2,
|
|
});
|
|
|
|
// check scores between 1 and 5 before sum scores
|
|
$(".shakhes_input").keyup(function () {
|
|
var total = 0;
|
|
var inputs = $(".shakhes_input");
|
|
for (var i = 0; i < inputs.length; i++) {
|
|
if (inputs[i].value != "") {
|
|
total += parseInt(inputs[i].value);
|
|
}
|
|
}
|
|
$("#total_points").val(total);
|
|
});
|
|
|
|
$(".shakhes_input").bind('keypress', function (event) {
|
|
var key = event.which;
|
|
var str = String.fromCharCode(key);
|
|
|
|
if (key == 0 || key === 32) {
|
|
return true;
|
|
}
|
|
|
|
var re = ($(this).hasClass('zero')) ? /^[0-5]$/ : /^[1-5]$/
|
|
if (re.test(str)) {
|
|
return true
|
|
}
|
|
|
|
return false
|
|
});
|
|
|
|
//upload files
|
|
$('.img-input').on('change', function () {
|
|
var input = this;
|
|
var parent = $(this).parents('.img-file');
|
|
if (input.files && input.files[0]) {
|
|
var reader = new FileReader();
|
|
|
|
reader.onload = function (e) {
|
|
parent.find('.img-title').css('display', 'none')
|
|
parent.find('.btn-delete-img').removeAttr('disabled');
|
|
parent.find('.img-preview')
|
|
.attr('src', e.target.result);
|
|
|
|
};
|
|
|
|
reader.readAsDataURL(input.files[0]);
|
|
}
|
|
})
|
|
|
|
$('#national_code').keyup(function () {
|
|
if (checkNationalCode($(this).val())) {
|
|
$('#national_code_err').css('display', 'none');
|
|
isNationalCode = true;
|
|
formValid()
|
|
return true;
|
|
} else {
|
|
$('#national_code_err').css('display', 'block');
|
|
isNationalCode = false;
|
|
formValid()
|
|
return false;
|
|
}
|
|
})
|
|
|
|
//clear files
|
|
$('.btn-delete-img').on('click', function () {
|
|
var parent = $(this).parents('.img-file');
|
|
|
|
parent.find('.img-input').val('');
|
|
parent.find('.img-preview').removeAttr('src');
|
|
parent.find('.img-title').css('display', '');
|
|
$(this).attr('disabled', 'disabled')
|
|
})
|
|
|
|
//reset moshakhasat
|
|
function resetMoshakhasat() {
|
|
$("#shasi_num").val("");
|
|
$("#province").val(0);
|
|
$("#city").val(0);
|
|
$("#device_name").val("");
|
|
$("#currentProvince").text("");
|
|
$("#currentCity").text("");
|
|
$("#oprator_name").val("");
|
|
$("#national_code").val("");
|
|
$("#operator_phone").val("");
|
|
}
|
|
|
|
//build form by car_type
|
|
function buildForm(car_type) {
|
|
//reset form
|
|
$(".form-bil").css("display", "none");
|
|
$(".form-grader").css("display", "none");
|
|
$(".form-loder").css("display", "none");
|
|
$(".form-boldozer").css("display", "none");
|
|
|
|
//build form
|
|
switch (car_type) {
|
|
case "Ex":
|
|
$(".form-bil").css("display", "");
|
|
break;
|
|
case "L":
|
|
$(".form-loder").css("display", "");
|
|
break;
|
|
case "G":
|
|
$(".form-grader").css("display", "");
|
|
break;
|
|
case "B":
|
|
$(".form-boldozer").css("display", "");
|
|
break;
|
|
}
|
|
|
|
// update car_type form
|
|
$("#car_type").val(car_type);
|
|
|
|
return Promise.resolve("Success");
|
|
}
|
|
|
|
// validation form
|
|
function formValid() {
|
|
if (isValidProvider && isValidCity && isNationalCode)
|
|
$('#send').removeAttr('disabled');
|
|
else
|
|
$('#send').attr('disabled', 'disabled');
|
|
}
|
|
|
|
function checkNationalCode(code) {
|
|
|
|
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));
|
|
}
|
|
}); |