1179 lines
43 KiB
JavaScript
1179 lines
43 KiB
JavaScript
var lawmakersTable;
|
||
|
||
var PERMISSIONS = [];
|
||
|
||
(function () {
|
||
|
||
$.ajax({
|
||
url: "/webapi/user/get-permission",
|
||
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);
|
||
},
|
||
});
|
||
}
|
||
})
|
||
|
||
/// [START] lawmaker_add_btn
|
||
if (!($.inArray('add-lawmaker', PERMISSIONS) != -1 || $.inArray('add-lawmaker-province', PERMISSIONS) != -1))
|
||
$('.add-lawmaker-btn').remove()
|
||
/// [END] lawmaker_add_btn
|
||
|
||
$("#constituency_excel").empty();
|
||
$("#constituency_excel").append('<option value="0">انتخاب حوزه انتخابیه </option>');
|
||
|
||
/// [start] lawmaker_add_province
|
||
if ($.inArray('add-lawmaker', PERMISSIONS) != -1 || $.inArray('add-lawmaker-province', PERMISSIONS) != -1) {
|
||
$.ajax({
|
||
/// [start] lawmaker_add_province_url
|
||
url: `/webapi/getuser/province-perm${$.inArray('add-lawmaker', PERMISSIONS) != -1 ? '?type=all' : ''}`,
|
||
/// [end] lawmaker_add_province_url
|
||
type: "GET",
|
||
beforeSend: function () {
|
||
showLoaderScreen();
|
||
},
|
||
success: function (result) {
|
||
const provinces = result.data;
|
||
|
||
$("#add_lawmaker_province").empty();
|
||
$("#add_lawmaker_province").append('<option value="0">انتخاب استان</option>');
|
||
|
||
for (let index = 0; index < provinces.length; index++) {
|
||
$("#add_lawmaker_province").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] lawmaker_add_province
|
||
|
||
/// [start] lawmaker_edit_province
|
||
if ($.inArray('edit-lawmaker', PERMISSIONS) != -1 || $.inArray('edit-lawmaker-province', PERMISSIONS) != -1) {
|
||
$.ajax({
|
||
/// [start] lawmaker_edit_province_url
|
||
url: `/webapi/getuser/province-perm${$.inArray('edit-lawmaker', PERMISSIONS) != -1 ? '?type=all' : ''}`,
|
||
/// [end] lawmaker_edit_province_url
|
||
type: "GET",
|
||
beforeSend: function () {
|
||
showLoaderScreen();
|
||
},
|
||
success: function (result) {
|
||
const provinces = result.data;
|
||
|
||
$("#edit_lawmaker_province").empty();
|
||
$("#edit_lawmaker_province").append('<option value="0">انتخاب استان</option>');
|
||
|
||
for (let index = 0; index < provinces.length; index++) {
|
||
$("#edit_lawmaker_province").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] lawmaker_edit_province
|
||
|
||
$.ajax({
|
||
/// [start] lawmaker_filter_province_url
|
||
url: `/webapi/getuser/province-perm${$.inArray('show-lawmaker', PERMISSIONS) != -1 ? '?type=all' : ''}`,
|
||
/// [end] lawmaker_filter_province_url
|
||
type: "GET",
|
||
beforeSend: function () {
|
||
showLoaderScreen();
|
||
},
|
||
success: function (result) {
|
||
const provinces = result.data;
|
||
|
||
$("#province_excel").empty();
|
||
$("#province_excel").append('<option value="0">انتخاب استان</option>');
|
||
|
||
for (let index = 0; index < provinces.length; index++) {
|
||
$("#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);
|
||
},
|
||
});
|
||
},
|
||
});
|
||
|
||
$.ajax({
|
||
url: "/api/get-units",
|
||
type: "GET",
|
||
beforeSend: function () {
|
||
showLoaderScreen();
|
||
},
|
||
success: function (result) {
|
||
const units = result.data;
|
||
|
||
$("#add_lawmaker_unit").empty();
|
||
$("#edit_lawmaker_unit").empty();
|
||
$("#add_lawmaker_unit").append('<option value="0">انتخاب واحد</option>');
|
||
$("#edit_lawmaker_unit").append('<option value="0">انتخاب واحد</option>');
|
||
|
||
for (let index = 0; index < units.length; index++) {
|
||
$("#add_lawmaker_unit").append(
|
||
"\
|
||
<option value=" +
|
||
units[index].id +
|
||
">" +
|
||
units[index].unit_fa +
|
||
"</option>\
|
||
"
|
||
);
|
||
|
||
$("#edit_lawmaker_unit").append(
|
||
"\
|
||
<option value=" +
|
||
units[index].id +
|
||
">" +
|
||
units[index].unit_fa +
|
||
"</option>\
|
||
"
|
||
);
|
||
}
|
||
|
||
hideLoaderScreen();
|
||
},
|
||
error: function (error) {
|
||
hideLoaderScreen();
|
||
Swal.fire({
|
||
icon: "error",
|
||
title: "خطا",
|
||
text: "مشکل در دریافت واحدها",
|
||
confirmButtonText: "بروزرسانی صفحه",
|
||
showLoaderOnConfirm: true,
|
||
preConfirm: () => {
|
||
location.reload(true);
|
||
},
|
||
});
|
||
},
|
||
});
|
||
|
||
lawmakersTable = $("#table_lawmakers").DataTable({
|
||
dom: "<flB<t>p>",
|
||
pagingType: "simple_numbers",
|
||
paging: true,
|
||
scrollX: true,
|
||
destroy: true,
|
||
responsive: true,
|
||
language: {
|
||
sEmptyTable: "هیچ دادهای در جدول وجود ندارد",
|
||
sInfo: "نمایش _START_ تا _END_ از _TOTAL_ ردیف",
|
||
sInfoEmpty: "نمایش 0 تا 0 از 0 ردیف",
|
||
sInfoFiltered: "(فیلتر شده از _MAX_ ردیف)",
|
||
sInfoPostFix: "",
|
||
sInfoThousands: ",",
|
||
sLengthMenu: "نمایش _MENU_ ردیف",
|
||
sLoadingRecords: "در حال بارگذاری...",
|
||
sProcessing: "در حال پردازش...",
|
||
sSearch: "جستجو: ",
|
||
sZeroRecords: "رکوردی با این مشخصات پیدا نشد",
|
||
oPaginate: {
|
||
sFirst: "برگهی نخست",
|
||
sLast: "برگهی آخر",
|
||
sNext: "بعدی",
|
||
sPrevious: "قبلی",
|
||
},
|
||
oAria: {
|
||
sSortAscending: ": فعال سازی نمایش به صورت صعودی",
|
||
sSortDescending: ": فعال سازی نمایش به صورت نزولی",
|
||
},
|
||
},
|
||
order: [
|
||
[0, "desc"]
|
||
],
|
||
processing: true,
|
||
ajax: {
|
||
url: "/lawmakers/all",
|
||
type: "GET",
|
||
beforeSend: function () {
|
||
showLoaderScreen();
|
||
},
|
||
dataSrc: function (json) {
|
||
hideLoaderScreen();
|
||
access = {
|
||
edit: json.canEdit,
|
||
delete: json.canDelete
|
||
}
|
||
return json.data;
|
||
},
|
||
error: function () {
|
||
hideLoaderScreen();
|
||
Swal.fire({
|
||
icon: "error",
|
||
title: "خطا",
|
||
text: "مشکل در دریافت مکاتبات نمایندگان مجلس",
|
||
confirmButtonText: "بروزرسانی صفحه",
|
||
showLoaderOnConfirm: true,
|
||
preConfirm: () => {
|
||
location.reload(true);
|
||
},
|
||
});
|
||
}
|
||
},
|
||
columns: [
|
||
{
|
||
className: "text-center",
|
||
data: null,
|
||
render: function (data, type, row, meta) {
|
||
return meta.row + 1;
|
||
},
|
||
},
|
||
{
|
||
data: 'unique_code',
|
||
className: 'text-center text-nowrap'
|
||
},
|
||
{
|
||
data: 'province_fa',
|
||
className: 'text-center text-nowrap'
|
||
},
|
||
{
|
||
data: 'constituency_fa',
|
||
className: 'text-center text-nowrap'
|
||
},
|
||
{
|
||
data: 'lawmaker_name',
|
||
className: 'text-center text-nowrap'
|
||
},
|
||
{
|
||
data: 'project_name',
|
||
className: 'text-center text-nowrap'
|
||
},
|
||
{
|
||
data: 'unit_fa',
|
||
className: 'text-center text-nowrap'
|
||
},
|
||
{
|
||
data: 'amount',
|
||
className: 'text-center text-nowrap'
|
||
},
|
||
{
|
||
className: "text-center text-nowrap",
|
||
data: null,
|
||
render: function (data) {
|
||
const total_credit = parseInt(data.total_credit != null ? data.total_credit : 0).toLocaleString('en');
|
||
return total_credit
|
||
}
|
||
},
|
||
{
|
||
className: "text-center text-nowrap",
|
||
data: null,
|
||
render: function (data) {
|
||
const national_credit = parseInt(data.national_credit != null ? data.national_credit : 0).toLocaleString('en');
|
||
return national_credit
|
||
}
|
||
},
|
||
{
|
||
className: "text-center text-nowrap",
|
||
data: null,
|
||
render: function (data) {
|
||
const province_credit = parseInt(data.province_credit != null ? data.province_credit : 0).toLocaleString('en');
|
||
return province_credit
|
||
}
|
||
},
|
||
{
|
||
className: "text-center text-nowrap",
|
||
data: null,
|
||
render: function (data) {
|
||
const licence_credit = parseInt(data.licence_credit != null ? data.licence_credit : 0).toLocaleString('en');
|
||
return licence_credit
|
||
}
|
||
},
|
||
{
|
||
data: 'preaction_by_setad',
|
||
className: 'text-center text-nowrap'
|
||
},
|
||
{
|
||
data: 'action_by_province',
|
||
className: 'text-center text-nowrap'
|
||
},
|
||
{
|
||
data: 'needed_actions',
|
||
className: 'text-center text-nowrap'
|
||
},
|
||
{
|
||
data: 'last_action',
|
||
className: 'text-center text-nowrap'
|
||
},
|
||
{
|
||
className: "text-center text-nowrap",
|
||
data: null,
|
||
render: function (data) {
|
||
if (data.last_update_fa != null) {
|
||
return moment(data.last_update_fa).format('YYYY/MM/DD')
|
||
}
|
||
return ''
|
||
}
|
||
},
|
||
{
|
||
data: null,
|
||
render: function (data, type, row) {
|
||
let content = '<div class="d-flex justify-content-center">'
|
||
/// [start] lawmaker_edit_can
|
||
if (data.canEdit)
|
||
content += '<button class="btn-dataTable btn-edit-lawmaker"><i class="fas fa-edit"></i></button>'
|
||
/// [end] lawmaker_edit_can
|
||
/// [start] lawmaker_delete_can
|
||
if (data.canDelete)
|
||
content += '<button class="btn-dataTable btn-delete-lawmaker"><i class="fa fa-trash"></i></button>'
|
||
/// [end] lawmaker_delete_can
|
||
content += '</div>'
|
||
return content
|
||
},
|
||
className: 'text-center text-nowrap'
|
||
},
|
||
],
|
||
|
||
buttons: [
|
||
{
|
||
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");
|
||
},
|
||
|
||
},
|
||
],
|
||
|
||
});
|
||
})()
|
||
|
||
function showLoaderScreen() {
|
||
$(".divloader").css("display", "flex").hide().fadeIn();
|
||
}
|
||
|
||
function hideLoaderScreen() {
|
||
$(".divloader").fadeOut();
|
||
}
|
||
|
||
$(document).on('click', '.add-lawmaker-btn', function () {
|
||
const modal = $('#modal_add_lawmaker')
|
||
|
||
modal.find('.input-lawmaker').val('')
|
||
modal.find('.input-lawmaker').removeClass("validity-checker");
|
||
|
||
modal.find(".select-lawmaker-constituency").empty();
|
||
modal.find(".select-lawmaker-constituency").append('<option value="0">انتخاب حوزه انتخابیه</option>');
|
||
|
||
modal.find('.select-lawmaker').val(0)
|
||
modal.find('.select-lawmaker').removeClass("validity-checker");
|
||
|
||
|
||
modal.find('.input-lawmaker-credit').val('')
|
||
modal.find('.input-lawmaker-credit').removeClass("validity-checker");
|
||
|
||
modal.find('.span-lawmaker-credit').text('0')
|
||
|
||
modal.find('#btn_add_lawmaker').prop('disabled', false)
|
||
|
||
modal.modal('show')
|
||
|
||
})
|
||
|
||
$(document).on('click', '.btn-edit-lawmaker', function () {
|
||
const modal = $('#modal_edit_lawmaker')
|
||
const tr = $(this).closest("tr");
|
||
const row = lawmakersTable.row(tr);
|
||
|
||
modal.find('.input-lawmaker').val('')
|
||
modal.find('.input-lawmaker').removeClass("validity-checker");
|
||
|
||
modal.find('.select-lawmaker').val(0)
|
||
modal.find('.select-lawmaker').removeClass("validity-checker");
|
||
|
||
modal.find('.input-lawmaker-credit').val('')
|
||
modal.find('.input-lawmaker-credit').removeClass("validity-checker");
|
||
|
||
modal.find('.span-lawmaker-credit').text('0')
|
||
|
||
modal.find('#btn_edit_lawmaker').prop('disabled', false)
|
||
|
||
$.ajax({
|
||
url: "/api/get-constituencies/" + row.data().province_id,
|
||
type: "GET",
|
||
beforeSend: function () {
|
||
modal.find(".select-lawmaker-constituency").empty();
|
||
modal.find(".select-lawmaker-constituency").append('<option value="-1">درحال دریافت حوزه انتخابیه</option>');
|
||
showLoaderScreen();
|
||
},
|
||
success: function (result) {
|
||
const constituencys = result.data;
|
||
|
||
modal.find(".select-lawmaker-constituency").empty();
|
||
modal.find(".select-lawmaker-constituency").append('<option value="0">انتخاب حوزه انتخابیه</option>');
|
||
|
||
for (let index = 0; index < constituencys.length; index++) {
|
||
|
||
if (constituencys[index].id == row.data().constituency_id) {
|
||
modal.find(".select-lawmaker-constituency").append(
|
||
"\
|
||
<option selected value=" +
|
||
constituencys[index].id +
|
||
">" +
|
||
constituencys[index].constituency_fa +
|
||
"</option>\
|
||
"
|
||
);
|
||
} else {
|
||
modal.find(".select-lawmaker-constituency").append(
|
||
"\
|
||
<option value=" +
|
||
constituencys[index].id +
|
||
">" +
|
||
constituencys[index].constituency_fa +
|
||
"</option>\
|
||
"
|
||
);
|
||
}
|
||
}
|
||
|
||
modal.find('#modal_edit_uniqe_code').text(row.data().unique_code)
|
||
modal.find('#edit_lawmaker_id').val(row.data().id)
|
||
modal.find('#edit_lawmaker_province').val(row.data().province_id)
|
||
|
||
modal.find('#edit_lawmaker_name').val(row.data().lawmaker_name)
|
||
modal.find('#edit_lawmaker_project_name').val(row.data().project_name)
|
||
modal.find('#edit_lawmaker_unit').val(row.data().unit_id)
|
||
modal.find('#edit_lawmaker_amount').val(row.data().amount)
|
||
|
||
const total_credit = parseInt(row.data().total_credit != null ? row.data().total_credit : 0)
|
||
const national_credit = parseInt(row.data().national_credit != null ? row.data().national_credit : 0)
|
||
const province_credit = parseInt(row.data().province_credit != null ? row.data().province_credit : 0)
|
||
const licence_credit = parseInt(row.data().licence_credit != null ? row.data().licence_credit : 0)
|
||
|
||
modal.find('#edit_lawmaker_total_credit').val(total_credit)
|
||
modal.find('#edit_lawmaker_national_credit').val(national_credit)
|
||
modal.find('#edit_lawmaker_province_credit').val(province_credit)
|
||
modal.find('#edit_lawmaker_licence_credit').val(licence_credit)
|
||
|
||
modal.find('#edit_lawmaker_total_credit_span').text(total_credit.toLocaleString('en'))
|
||
modal.find('#edit_lawmaker_national_credit_span').text(national_credit.toLocaleString('en'))
|
||
modal.find('#edit_lawmaker_province_credit_span').text(province_credit.toLocaleString('en'))
|
||
modal.find('#edit_lawmaker_licence_credit_span').text(licence_credit.toLocaleString('en'))
|
||
|
||
modal.find('#edit_lawmaker_preaction_by_setad').val(row.data().preaction_by_setad)
|
||
modal.find('#edit_lawmaker_action_by_province').val(row.data().action_by_province)
|
||
modal.find('#edit_lawmaker_needed_actions').val(row.data().needed_actions)
|
||
modal.find('#edit_lawmaker_last_action').val(row.data().last_action)
|
||
|
||
modal.modal('show')
|
||
|
||
hideLoaderScreen();
|
||
},
|
||
error: function (error) {
|
||
hideLoaderScreen();
|
||
Swal.fire({
|
||
icon: "error",
|
||
title: "خطا",
|
||
text: "مشکل در دریافت حوزه انتخابیه",
|
||
confirmButtonText: "بروزرسانی صفحه",
|
||
showLoaderOnConfirm: true,
|
||
preConfirm: () => {
|
||
location.reload(true);
|
||
},
|
||
});
|
||
},
|
||
});
|
||
|
||
})
|
||
|
||
$(document).on('click', '#btn_add_lawmaker', function () {
|
||
const thisBtn = $(this)
|
||
thisBtn.prop('disabled', true)
|
||
|
||
const modal = $('#modal_add_lawmaker')
|
||
|
||
let isValid = true;
|
||
|
||
const id = modal.find('#add_lawmaker_id').val()
|
||
const province_id = modal.find('#add_lawmaker_province').val()
|
||
const province_fa = modal.find('#add_lawmaker_province option:selected').text()
|
||
const constituency_id = modal.find('#add_lawmaker_constituency').val()
|
||
const constituency_fa = modal.find('#add_lawmaker_constituency option:selected').text()
|
||
const lawmaker_name = modal.find('#add_lawmaker_name').val()
|
||
const project_name = modal.find('#add_lawmaker_project_name').val()
|
||
const unit_id = modal.find('#add_lawmaker_unit').val()
|
||
const unit_fa = modal.find('#add_lawmaker_unit option:selected').text()
|
||
const amount = modal.find('#add_lawmaker_amount').val()
|
||
const total_credit = modal.find('#add_lawmaker_total_credit').val()
|
||
const national_credit = modal.find('#add_lawmaker_national_credit').val()
|
||
const province_credit = modal.find('#add_lawmaker_province_credit').val()
|
||
const licence_credit = modal.find('#add_lawmaker_licence_credit').val()
|
||
const preaction_by_setad = modal.find('#add_lawmaker_preaction_by_setad').val()
|
||
const action_by_province = modal.find('#add_lawmaker_action_by_province').val()
|
||
const needed_actions = modal.find('#add_lawmaker_needed_actions').val()
|
||
const last_action = modal.find('#add_lawmaker_last_action').val()
|
||
|
||
if (province_id == 0) {
|
||
isValid = false
|
||
modal.find('#add_lawmaker_province').addClass("validity-checker");
|
||
} else {
|
||
modal.find('#add_lawmaker_province').removeClass("validity-checker");
|
||
}
|
||
|
||
if (constituency_id == 0) {
|
||
isValid = false
|
||
modal.find('#add_lawmaker_constituency').addClass("validity-checker");
|
||
} else {
|
||
modal.find('#add_lawmaker_constituency').removeClass("validity-checker");
|
||
}
|
||
|
||
if (lawmaker_name == '') {
|
||
isValid = false
|
||
modal.find('#add_lawmaker_name').addClass("validity-checker");
|
||
} else {
|
||
modal.find('#add_lawmaker_name').removeClass("validity-checker");
|
||
}
|
||
|
||
if (project_name == '') {
|
||
isValid = false
|
||
modal.find('#add_lawmaker_project_name').addClass("validity-checker");
|
||
} else {
|
||
modal.find('#add_lawmaker_project_name').removeClass("validity-checker");
|
||
}
|
||
|
||
if (unit_id == 0) {
|
||
isValid = false
|
||
modal.find('#add_lawmaker_unit').addClass("validity-checker");
|
||
} else {
|
||
modal.find('#add_lawmaker_unit').removeClass("validity-checker");
|
||
}
|
||
|
||
if (amount == '') {
|
||
isValid = false
|
||
modal.find('#add_lawmaker_amount').addClass("validity-checker");
|
||
} else {
|
||
modal.find('#add_lawmaker_amount').removeClass("validity-checker");
|
||
}
|
||
|
||
if (total_credit == '') {
|
||
isValid = false
|
||
modal.find('#add_lawmaker_total_credit').addClass("validity-checker");
|
||
} else {
|
||
modal.find('#add_lawmaker_total_credit').removeClass("validity-checker");
|
||
}
|
||
|
||
if (national_credit == '') {
|
||
isValid = false
|
||
modal.find('#add_lawmaker_national_credit').addClass("validity-checker");
|
||
} else {
|
||
modal.find('#add_lawmaker_national_credit').removeClass("validity-checker");
|
||
}
|
||
|
||
if (province_credit == '') {
|
||
isValid = false
|
||
modal.find('#add_lawmaker_province_credit').addClass("validity-checker");
|
||
} else {
|
||
modal.find('#add_lawmaker_province_credit').removeClass("validity-checker");
|
||
}
|
||
|
||
if (licence_credit == '') {
|
||
isValid = false
|
||
modal.find('#add_lawmaker_licence_credit').addClass("validity-checker");
|
||
} else {
|
||
modal.find('#add_lawmaker_licence_credit').removeClass("validity-checker");
|
||
}
|
||
|
||
if (preaction_by_setad == '') {
|
||
isValid = false
|
||
modal.find('#add_lawmaker_preaction_by_setad').addClass("validity-checker");
|
||
} else {
|
||
modal.find('#add_lawmaker_preaction_by_setad').removeClass("validity-checker");
|
||
}
|
||
|
||
if (action_by_province == '') {
|
||
isValid = false
|
||
modal.find('#add_lawmaker_action_by_province').addClass("validity-checker");
|
||
} else {
|
||
modal.find('#add_lawmaker_action_by_province').removeClass("validity-checker");
|
||
}
|
||
|
||
if (needed_actions == '') {
|
||
isValid = false
|
||
modal.find('#add_lawmaker_needed_actions').addClass("validity-checker");
|
||
} else {
|
||
modal.find('#add_lawmaker_needed_actions').removeClass("validity-checker");
|
||
}
|
||
|
||
if (last_action == '') {
|
||
isValid = false
|
||
modal.find('#add_lawmaker_last_action').addClass("validity-checker");
|
||
} else {
|
||
modal.find('#add_lawmaker_last_action').removeClass("validity-checker");
|
||
}
|
||
|
||
if (!isValid) {
|
||
Swal.fire({
|
||
icon: "warning",
|
||
title: "هشدار",
|
||
text: "لطفا تمامی مقادیر اجباری را وارد کنید",
|
||
cancelButtonText: "بستن",
|
||
showConfirmButton: false,
|
||
showCancelButton: true,
|
||
});
|
||
thisBtn.prop('disabled', false)
|
||
return false
|
||
} else {
|
||
let formData = new FormData();
|
||
|
||
formData.append("province_id", province_id);
|
||
formData.append("province_fa", province_fa);
|
||
formData.append("constituency_id", constituency_id);
|
||
formData.append("constituency_fa", constituency_fa);
|
||
formData.append("lawmaker_name", lawmaker_name);
|
||
formData.append("project_name", project_name);
|
||
formData.append("unit_id", unit_id);
|
||
formData.append("unit_fa", unit_fa);
|
||
formData.append("amount", amount);
|
||
formData.append("total_credit", total_credit);
|
||
formData.append("national_credit", national_credit);
|
||
formData.append("province_credit", province_credit);
|
||
formData.append("licence_credit", licence_credit);
|
||
formData.append("preaction_by_setad", preaction_by_setad);
|
||
formData.append("action_by_province", action_by_province);
|
||
formData.append("needed_actions", needed_actions);
|
||
formData.append("last_action", last_action);
|
||
|
||
$.ajax({
|
||
url: "/lawmakers/store",
|
||
type: "POST",
|
||
data: formData,
|
||
cache: false,
|
||
contentType: false,
|
||
processData: 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 => {
|
||
lawmakersTable.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_edit_lawmaker', function () {
|
||
const thisBtn = $(this)
|
||
thisBtn.prop('disabled', true)
|
||
|
||
const modal = $('#modal_edit_lawmaker')
|
||
|
||
let isValid = true;
|
||
|
||
const id = modal.find('#edit_lawmaker_id').val()
|
||
const province_id = modal.find('#edit_lawmaker_province').val()
|
||
const province_fa = modal.find('#edit_lawmaker_province option:selected').text()
|
||
const constituency_id = modal.find('#edit_lawmaker_constituency').val()
|
||
const constituency_fa = modal.find('#edit_lawmaker_constituency option:selected').text()
|
||
const lawmaker_name = modal.find('#edit_lawmaker_name').val()
|
||
const project_name = modal.find('#edit_lawmaker_project_name').val()
|
||
const unit_id = modal.find('#edit_lawmaker_unit').val()
|
||
const unit_fa = modal.find('#edit_lawmaker_unit option:selected').text()
|
||
const amount = modal.find('#edit_lawmaker_amount').val()
|
||
const total_credit = modal.find('#edit_lawmaker_total_credit').val()
|
||
const national_credit = modal.find('#edit_lawmaker_national_credit').val()
|
||
const province_credit = modal.find('#edit_lawmaker_province_credit').val()
|
||
const licence_credit = modal.find('#edit_lawmaker_licence_credit').val()
|
||
const preaction_by_setad = modal.find('#edit_lawmaker_preaction_by_setad').val()
|
||
const action_by_province = modal.find('#edit_lawmaker_action_by_province').val()
|
||
const needed_actions = modal.find('#edit_lawmaker_needed_actions').val()
|
||
const last_action = modal.find('#edit_lawmaker_last_action').val()
|
||
|
||
if (province_id == 0) {
|
||
isValid = false
|
||
modal.find('#edit_lawmaker_province').addClass("validity-checker");
|
||
} else {
|
||
modal.find('#edit_lawmaker_province').removeClass("validity-checker");
|
||
}
|
||
|
||
if (constituency_id == 0) {
|
||
isValid = false
|
||
modal.find('#edit_lawmaker_constituency').addClass("validity-checker");
|
||
} else {
|
||
modal.find('#edit_lawmaker_constituency').removeClass("validity-checker");
|
||
}
|
||
|
||
if (lawmaker_name == '') {
|
||
isValid = false
|
||
modal.find('#edit_lawmaker_name').addClass("validity-checker");
|
||
} else {
|
||
modal.find('#edit_lawmaker_name').removeClass("validity-checker");
|
||
}
|
||
|
||
if (project_name == '') {
|
||
isValid = false
|
||
modal.find('#edit_lawmaker_project_name').addClass("validity-checker");
|
||
} else {
|
||
modal.find('#edit_lawmaker_project_name').removeClass("validity-checker");
|
||
}
|
||
|
||
if (unit_id == 0) {
|
||
isValid = false
|
||
modal.find('#edit_lawmaker_unit').addClass("validity-checker");
|
||
} else {
|
||
modal.find('#edit_lawmaker_unit').removeClass("validity-checker");
|
||
}
|
||
|
||
if (amount == '') {
|
||
isValid = false
|
||
modal.find('#edit_lawmaker_amount').addClass("validity-checker");
|
||
} else {
|
||
modal.find('#edit_lawmaker_amount').removeClass("validity-checker");
|
||
}
|
||
|
||
if (total_credit == '') {
|
||
isValid = false
|
||
modal.find('#edit_lawmaker_total_credit').addClass("validity-checker");
|
||
} else {
|
||
modal.find('#edit_lawmaker_total_credit').removeClass("validity-checker");
|
||
}
|
||
|
||
if (national_credit == '') {
|
||
isValid = false
|
||
modal.find('#edit_lawmaker_national_credit').addClass("validity-checker");
|
||
} else {
|
||
modal.find('#edit_lawmaker_national_credit').removeClass("validity-checker");
|
||
}
|
||
|
||
if (province_credit == '') {
|
||
isValid = false
|
||
modal.find('#edit_lawmaker_province_credit').addClass("validity-checker");
|
||
} else {
|
||
modal.find('#edit_lawmaker_province_credit').removeClass("validity-checker");
|
||
}
|
||
|
||
if (licence_credit == '') {
|
||
isValid = false
|
||
modal.find('#edit_lawmaker_licence_credit').addClass("validity-checker");
|
||
} else {
|
||
modal.find('#edit_lawmaker_licence_credit').removeClass("validity-checker");
|
||
}
|
||
|
||
if (preaction_by_setad == '') {
|
||
isValid = false
|
||
modal.find('#edit_lawmaker_preaction_by_setad').addClass("validity-checker");
|
||
} else {
|
||
modal.find('#edit_lawmaker_preaction_by_setad').removeClass("validity-checker");
|
||
}
|
||
|
||
if (action_by_province == '') {
|
||
isValid = false
|
||
modal.find('#edit_lawmaker_action_by_province').addClass("validity-checker");
|
||
} else {
|
||
modal.find('#edit_lawmaker_action_by_province').removeClass("validity-checker");
|
||
}
|
||
|
||
if (needed_actions == '') {
|
||
isValid = false
|
||
modal.find('#edit_lawmaker_needed_actions').addClass("validity-checker");
|
||
} else {
|
||
modal.find('#edit_lawmaker_needed_actions').removeClass("validity-checker");
|
||
}
|
||
|
||
if (last_action == '') {
|
||
isValid = false
|
||
modal.find('#edit_lawmaker_last_action').addClass("validity-checker");
|
||
} else {
|
||
modal.find('#edit_lawmaker_last_action').removeClass("validity-checker");
|
||
}
|
||
|
||
if (!isValid) {
|
||
Swal.fire({
|
||
icon: "warning",
|
||
title: "هشدار",
|
||
text: "لطفا تمامی مقادیر اجباری را وارد کنید",
|
||
cancelButtonText: "بستن",
|
||
showConfirmButton: false,
|
||
showCancelButton: true,
|
||
});
|
||
thisBtn.prop('disabled', false)
|
||
return false
|
||
} else {
|
||
let formData = new FormData();
|
||
|
||
formData.append("province_id", province_id);
|
||
formData.append("province_fa", province_fa);
|
||
formData.append("constituency_id", constituency_id);
|
||
formData.append("constituency_fa", constituency_fa);
|
||
formData.append("lawmaker_name", lawmaker_name);
|
||
formData.append("project_name", project_name);
|
||
formData.append("unit_id", unit_id);
|
||
formData.append("unit_fa", unit_fa);
|
||
formData.append("amount", amount);
|
||
formData.append("total_credit", total_credit);
|
||
formData.append("national_credit", national_credit);
|
||
formData.append("province_credit", province_credit);
|
||
formData.append("licence_credit", licence_credit);
|
||
formData.append("preaction_by_setad", preaction_by_setad);
|
||
formData.append("action_by_province", action_by_province);
|
||
formData.append("needed_actions", needed_actions);
|
||
formData.append("last_action", last_action);
|
||
|
||
$.ajax({
|
||
url: "/lawmakers/update/" + id,
|
||
type: "POST",
|
||
data: formData,
|
||
cache: false,
|
||
contentType: false,
|
||
processData: 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 => {
|
||
lawmakersTable.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-delete-lawmaker', function () {
|
||
const tr = $(this).closest("tr");
|
||
const row = lawmakersTable.row(tr);
|
||
|
||
Swal.fire({
|
||
icon: "warning",
|
||
title: "آیا برای حذف مطمئن هستید؟",
|
||
showCancelButton: true,
|
||
confirmButtonColor: "#3085d6",
|
||
cancelButtonColor: "#d33",
|
||
confirmButtonText: "بله، حذف شود",
|
||
cancelButtonText: "منصرف شدم!",
|
||
showLoaderOnConfirm: true,
|
||
preConfirm: () => {
|
||
$.ajax({
|
||
url: "/lawmakers/delete/" + row.data().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) {
|
||
hideLoaderScreen();
|
||
lawmakersTable.ajax.reload(null, false);
|
||
},
|
||
error: function (error) {
|
||
hideLoaderScreen();
|
||
Swal.fire({
|
||
icon: "error",
|
||
title: "خطا",
|
||
text: "مشکل در حذف مکاتبه",
|
||
cancelButtonText: "بستن",
|
||
showConfirmButton: false,
|
||
showCancelButton: true,
|
||
});
|
||
},
|
||
});
|
||
},
|
||
});
|
||
})
|
||
|
||
$(document).bind('click', function (e) {
|
||
const clicked = $(e.target);
|
||
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).on('change', '.select-lawmaker-province', function () {
|
||
const modal = $(this).parents('.modal')
|
||
const provinceId = $(this).val()
|
||
|
||
$.ajax({
|
||
url: "/api/get-constituencies/" + provinceId,
|
||
type: "GET",
|
||
beforeSend: function () {
|
||
modal.find(".select-lawmaker-constituency").empty();
|
||
modal.find(".select-lawmaker-constituency").append('<option value="-1">درحال دریافت حوزه انتخابیه</option>');
|
||
},
|
||
success: function (result) {
|
||
const constituencys = result.data;
|
||
|
||
modal.find(".select-lawmaker-constituency").empty();
|
||
modal.find(".select-lawmaker-constituency").append('<option value="0">انتخاب حوزه انتخابیه</option>');
|
||
|
||
for (let index = 0; index < constituencys.length; index++) {
|
||
|
||
modal.find(".select-lawmaker-constituency").append(
|
||
"\
|
||
<option value=" +
|
||
constituencys[index].id +
|
||
">" +
|
||
constituencys[index].constituency_fa +
|
||
"</option>\
|
||
"
|
||
);
|
||
}
|
||
},
|
||
error: function (error) {
|
||
Swal.fire({
|
||
icon: "error",
|
||
title: "خطا",
|
||
text: "مشکل در دریافت حوزه انتخابیه",
|
||
confirmButtonText: "بروزرسانی صفحه",
|
||
showLoaderOnConfirm: true,
|
||
preConfirm: () => {
|
||
location.reload(true);
|
||
},
|
||
});
|
||
},
|
||
});
|
||
})
|
||
|
||
$(document).on('change', '.select-filter-province', function () {
|
||
const parent = $(this).parents('.filter-box')
|
||
const provinceId = $(this).val()
|
||
|
||
$.ajax({
|
||
url: "/api/get-constituencies/" + provinceId,
|
||
type: "GET",
|
||
beforeSend: function () {
|
||
parent.find(".select-filter-constituency").empty();
|
||
parent.find(".select-filter-constituency").append('<option value="-1">درحال دریافت حوزه انتخابیه</option>');
|
||
},
|
||
success: function (result) {
|
||
const constituencys = result.data;
|
||
|
||
parent.find(".select-filter-constituency").empty();
|
||
parent.find(".select-filter-constituency").append('<option value="0">انتخاب حوزه انتخابیه</option>');
|
||
|
||
for (let index = 0; index < constituencys.length; index++) {
|
||
|
||
parent.find(".select-filter-constituency").append(
|
||
"\
|
||
<option value=" +
|
||
constituencys[index].id +
|
||
">" +
|
||
constituencys[index].constituency_fa +
|
||
"</option>\
|
||
"
|
||
);
|
||
}
|
||
},
|
||
error: function (error) {
|
||
Swal.fire({
|
||
icon: "error",
|
||
title: "خطا",
|
||
text: "مشکل در دریافت حوزه انتخابیه",
|
||
confirmButtonText: "بروزرسانی صفحه",
|
||
showLoaderOnConfirm: true,
|
||
preConfirm: () => {
|
||
location.reload(true);
|
||
},
|
||
});
|
||
},
|
||
});
|
||
})
|
||
|
||
$(document).on('input', '.input-lawmaker-credit', function () {
|
||
var parent = $(this).closest('.lawmaker-credit-box')
|
||
if ($(this).val() == '') {
|
||
parent.find('.span-lawmaker-credit').text('0')
|
||
return false;
|
||
}
|
||
parent.find('.span-lawmaker-credit').text(parseInt($(this).val()).toLocaleString('en'))
|
||
});
|
||
|
||
$('input[type=text]').bind('keypress', function (event) {
|
||
const arabicCharUnicodeRange = /[\u0600-\u06FF-0-9-45]/;
|
||
const key = event.which;
|
||
|
||
if (key == 8 || key == 0 || key === 32) {
|
||
return true;
|
||
}
|
||
|
||
var str = String.fromCharCode(key);
|
||
if (arabicCharUnicodeRange.test(str)) {
|
||
return true;
|
||
}
|
||
|
||
Swal.fire({
|
||
icon: "warning",
|
||
title: "هشدار",
|
||
text: "لطفا فقط از حروف فارسی استفاده کنید",
|
||
cancelButtonText: "بستن",
|
||
showConfirmButton: false,
|
||
showCancelButton: true,
|
||
});
|
||
return false;
|
||
})
|
||
|
||
$('textarea').bind('keypress', function (event) {
|
||
const arabicCharUnicodeRange = /[\u0600-\u06FF-0-9-45]/;
|
||
const key = event.which;
|
||
|
||
if (key == 8 || key == 0 || key === 32) {
|
||
return true;
|
||
}
|
||
|
||
var str = String.fromCharCode(key);
|
||
if (arabicCharUnicodeRange.test(str)) {
|
||
return true;
|
||
}
|
||
|
||
Swal.fire({
|
||
icon: "warning",
|
||
title: "هشدار",
|
||
text: "لطفا فقط از حروف فارسی استفاده کنید",
|
||
cancelButtonText: "بستن",
|
||
showConfirmButton: false,
|
||
showCancelButton: true,
|
||
});
|
||
return false;
|
||
})
|
||
|
||
$(document).on('click', '#btn_excel_download', function () {
|
||
let queryParems = []
|
||
const province = $('#province_excel').val()
|
||
const constituency = $('#constituency_excel').val()
|
||
|
||
if (province != 0)
|
||
queryParems.push(`province=${province}`)
|
||
if (constituency > 0)
|
||
queryParems.push(`constituency=${constituency}`)
|
||
|
||
const url = `/reports/lawmakers${queryParems.length != 0 ? `?${queryParems.join('&')}` : ''}`
|
||
|
||
window.open(url, '_blank')
|
||
}) |