pos-gis/resources/views/content/ref/merchant/action.blade.php
2024-10-07 13:13:42 +07:00

481 lines
13 KiB
PHP

<script>
// INIT FORM
function clearForm() {
$('#mForm_title').html(`Tambah Data`);
$('#mForm_subTitle').html(`Tambah Data `+title);
$('#get_id').val('');
$("#formData")[0].reset();
$('#formData').bootstrapValidator("resetForm",true);
reInitForm();
clearImage();
var avatar = new KTImageInput('kt_image');
$('#viewPark').hide();
$('#viewStartFee').hide();
$('#viewMarket').hide()
$('#mid').prop('disabled',false);
}
function clearImage() {
let imageUrl = '{{asset('img/no_img.png')}}';
$('#ava1').css("background-image", "url(" + imageUrl + ")");
$('#logo').val('');
$('#pic-cancel').hide();
}
function edit(id) {
clearForm();
$('#mForm').modal('show');
znLoadingModal('mForm');
$('#mForm_title').html(`Edit Data`);
$('#mForm_subTitle').html(`Edit Data `+title);
$('#mid').prop('disabled',true);
let formData = new FormData();
formData.append('id',id);
doPost(routeEdit, formData, function (msg, res) {
console.log(res);
znLoadingModalEnd('mForm');
var data = res.data.merchant;
$('#get_id').val(data.get_id);
$('#merchant_nm').val(data.merchant_nm);
$('#address').val(data.address);
$('#mid').val(data.mid);
// $('#email').val(data.email);
$('#phone_no').val(data.phone_no);
$('#nmid').val(data.nmid);
let is_hotel = (data.is_hotel == true) ? 't':'f';
let is_resto = (data.is_resto == true) ? 't':'f';
$('#is_resto').val(is_resto).trigger('change.select2');
$('#is_hotel').val(is_hotel).trigger('change.select2');
$('#kota').val(data.city_id).trigger('change.select2');
if(data.logo){
let imageUrl = "{{asset('gallery')}}/"+data.logo;
$('#ava1').css("background-image", "url(" + imageUrl + ")");
}
$('#formData').data('bootstrapValidator').validate();
})
}
function edc(id,title) {
$('#mEdc_title').html(`Link EDC `+title);
$('#mEdc_subTitle').html(`Daftar Link EDC `+title);
$('.select2').select2({
placeholder: "Silahkan Pilih"
});
$('#mEdc').modal('show');
$('#viewList').hide();
$('#list_edc').html(``);
$('#get_mid').val(id)
let formData = new FormData();
formData.append('id',id);
znLoadingModal('mEdc');
doPost(routeStoreCustom+'&act=listEdc', formData, function (msg, res) {
console.log(res);
znLoadingModalEnd('mEdc');
if(res.list.length > 0){
$('#viewList').show();
}
res.list.forEach(v => {
$('#list_edc').append(`
<tr>
<td>${v.device_id}</td>
<td>${v.sn}</td>
<td>${v.imei}</td>
<td>${v.name_brand}</td>
<td>${v.model}</td>
<td>${v.tid}</td>
<td> <button type="button" onclick="removeEdc(${v.device_id});" class="btn btn-sm btn-danger mr-3">
<i class="las la-unlink"></i>Unlink<b></b>
</button></td>
</tr>`)
});
})
}
function filterTable() {
let filterQuery = {
is_park_check : ($('#is_park_check').is(":checked")) ? 't':'f',
is_market_check : ($('#is_market_check').is(":checked")) ? 't':'f',
is_sale_check : ($('#is_sale_check').is(":checked")) ? 't':'f',
is_mini_atm_check : ($('#is_mini_atm_check').is(":checked")) ? 't':'f'
}
console.log(routeTable+'&'+$.param(filterQuery));
table.ajax.url(routeTable+'&'+$.param(filterQuery)).load();
}
function removeEdc(id) {
let formData = new FormData();
formData.append('device_id',id);
formData.append('mid',$('#get_mid').val());
znLoadingModal('mEdc');
doPost(routeStoreCustom+'&act=removeEdc', formData, function (msg, res) {
console.log(res);
znLoadingModalEnd('mEdc');
if(res.rc == 0){
znNotif('success','Berhasil Unlink EDC');
edc($('#get_mid').val())
ref_edc('device_id',$('#id_brand').val());
}else{
znNotif("danger", res.rm);
}
})
}
function storeEdc() {
let formData = new FormData();
formData.append('device_id',$('#device_id').val());
formData.append('mid',$('#get_mid').val());
znLoadingModal('mEdc');
doPost(routeStoreCustom+'&act=addEdc', formData, function (msg, res) {
console.log(res);
znLoadingModalEnd('mEdc');
if(res.rc == 0){
znNotif('success','Berhasil Link EDC');
table.ajax.url(routeTable).load();
edc($('#get_mid').val())
ref_edc('device_id',$('#id_brand').val());
}else{
znNotif("danger", res.rm);
}
})
}
function storeCustom() {
let myForm = document.getElementById('formData');
let formData = new FormData(myForm);
var isEdit = $('#get_id').val();
var $validator = $('#formData').data('bootstrapValidator').validate();
if ($validator.isValid()) {
znLoadingModal('mForm');
doPost(routeStoreCustom+'&act=storeMerchant', formData, function (msg, data) {
//console.log(data);
znLoadingModalEnd('mForm');
if (data == null){
znNotif("danger", msg);
}else {
if(data.rc == 0){
znNotif('success','Berhasil Menyimpan Data');
$('#mForm').modal('hide');
table.ajax.url(routeTable).load();
}else{
znNotif("danger", data.rm);
}
}
})
}
}
var idxAdd = 0;
function tax(id) {
$('#mTax').modal('show');
$('#viewListTax').hide();
$('#list_tax').html(``);
$('#get_mid_tax').val(id)
let formData = new FormData();
formData.append('id',id);
znLoadingModal('mTax');
doPost(routeStoreCustom+'&act=listTax', formData, function (msg, res) {
console.log(res);
znLoadingModalEnd('mTax');
if(res.list.length > 0){
$('#viewListTax').show();
}
res.list.forEach(v => {
$('#list_tax').append(`
<tr id="list_tax_id${idxAdd}">
<td><select autocomplete="off" class="form-control select2 znSelect2" style="width: 100%" name="tax_select[]" id="tax_select${idxAdd}"></select></td>
<td><button type="button" onclick="removeTax(${idxAdd})" class="btn btn-icon btn-danger">
<i class="la la-trash"></i>
</button></td>
</tr>`)
ref_tax('tax_select'+idxAdd,v.tax_id);
$('.select2').select2({
placeholder: "Silahkan Pilih"
});
idxAdd++
});
})
}
function addTax() {
$('#list_tax').append(`
<tr id="list_tax_id${idxAdd}">
<td>
<select autocomplete="off" class="form-control select2 znSelect2" style="width: 100%" name="tax_select[]" id="tax_select${idxAdd}"></select>
</td>
<td>
<button type="button" onclick="removeTax(${idxAdd})" class="btn btn-icon btn-danger" >
<i class="la la-trash"></i>
</button>
</td>
</tr>
`);
ref_tax('tax_select'+idxAdd);
$('.select2').select2({
placeholder: "Silahkan Pilih"
});
idxAdd++
}
function removeTax(id) {
$('#list_tax_id'+id).remove();
}
function storeTax() {
let myForm = document.getElementById('formDataTax');
let formData = new FormData(myForm);
znLoadingModal('mTax');
doPost(routeStoreCustom+'&act=addTax', formData, function (msg, res) {
console.log(res);
znLoadingModalEnd('mTax');
if(res.rc == 0){
znNotif('success','Berhasil Menyimpan Tax');
$('#mTax').modal('hide');
table.ajax.url(routeTable).load();
}else{
znNotif("danger", res.rm);
}
})
}
//VALIDASI
$(document).ready(function () {
$('#id_brand').on('select2:select', function (e) {
var data = e.params.data;
ref_edc('device_id',data.id);
});
$('#is_park_active').on('select2:select', function (e) {
var data = e.params.data;
isPark(data.id)
});
$('#is_market_active').on('select2:select', function (e) {
var data = e.params.data;
isMarket(data.id)
});
$('#park_type_id').on('select2:select', function (e) {
var data = e.params.data;
isStartFee(data.id)
});
$("#formData").bootstrapValidator({
excluded: [':disabled'],
feedbackIcons: {
valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
},
fields: {
merchant_nm: {
validators: {
notEmpty: {
message: 'Tidak Boleh Kosong'
},
stringLength: {
max:200,
message: 'Maksimal 200 Karakter'
}
}
},
mid: {
validators: {
notEmpty: {
message: 'Tidak Boleh Kosong'
},
stringLength: {
min:1,
max:15,
message: 'Minimal 1 Maksimal 15 Karakter'
}
}
},
// email: {
// validators: {
// notEmpty: {
// message: 'Tidak Boleh Kosong'
// },
// emailAddress: {
// message: 'format email salah'
// },
// stringLength: {
// max:200,
// message: 'Maksimal 200 Karakter'
// }
// }
// },
billing_type_id: {
validators: {
notEmpty: {
message: 'Tidak Boleh Kosong'
}
}
},
kota: {
validators: {
notEmpty: {
message: 'Tidak Boleh Kosong'
}
}
},
phone_no: {
validators: {
notEmpty: {
message: 'Tidak Boleh Kosong'
}
}
},
nmid: {
validators: {
notEmpty: {
message: 'Tidak Boleh Kosong'
},
stringLength: {
min:1,
max:13,
message: 'Minimal 1 Maksimal 13 Karakter'
}
}
},
address: {
validators: {
notEmpty: {
message: 'Tidak Boleh Kosong'
},
stringLength: {
max:250,
message: 'Maksimal 250 Karakter'
}
}
},
is_park_active: {
validators: {
notEmpty: {
message: 'Tidak Boleh Kosong'
}
}
},
is_market_active: {
validators: {
notEmpty: {
message: 'Tidak Boleh Kosong'
}
}
},
is_sale_active: {
validators: {
notEmpty: {
message: 'Tidak Boleh Kosong'
}
}
},
is_mini_atm_active: {
validators: {
notEmpty: {
message: 'Tidak Boleh Kosong'
}
}
},
fee: {
validators: {
notEmpty: {
message: 'Tidak Boleh Kosong'
}
}
},
logo: {
validators: {
file: {
extension: 'jpg,jpeg,png',
type: 'image/jpg,image/jpeg,image/png',
maxSize: 0.5 * (1024*1024),
message: 'File Tidak Sesuai'
}
}
},
}
}).on('success.field.bv', function (e, data) {
var $parent = data.element.parents('.form-group');
$parent.removeClass('has-success');
$parent.find('.form-control-feedback[data-bv-icon-for="' + data.field + '"]').hide();
});
});
</script>