412 lines
12 KiB
PHP
412 lines
12 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();
|
|
$('#isService').hide();
|
|
}
|
|
|
|
function confirm(id,titleSet) {
|
|
clearForm();
|
|
$('#mFormConf').modal('show');
|
|
znLoadingModal('mFormConf');
|
|
$('#mFormConf_title').html(`Confirm Outlet`);
|
|
$('#mFormConf_subTitle').html(`Confirm Outlet `+titleSet);
|
|
|
|
let formData = new FormData();
|
|
formData.append('id',id);
|
|
|
|
doPost(routeStoreCustom+'&act=dataConfirm', formData, function (msg, res) {
|
|
|
|
znLoadingModalEnd('mFormConf');
|
|
var data = res.data;
|
|
$('#get_mid_conf').val(data.mid);
|
|
$('#get_outlet_id_conf').val(data.outlet_id);
|
|
$('#mid_trx').val(data.mid_trx);
|
|
|
|
$('#formData').data('bootstrapValidator').validate();
|
|
})
|
|
}
|
|
|
|
function edcData(id) {
|
|
$('#viewList').hide();
|
|
|
|
$('#list_edc').html(``);
|
|
$('#get_outlet_id_edc').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();
|
|
}
|
|
|
|
$('#tbListEDC').DataTable().clear().destroy();
|
|
|
|
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},'${title}');" class="btn btn-sm btn-danger mr-3">
|
|
<i class="las la-unlink"></i>Unlink<b></b>
|
|
</button></td>
|
|
</tr>`)
|
|
});
|
|
|
|
$('#tbListEDC').DataTable({
|
|
aLengthMenu: [[5, 10, 25, 50, -1], [5, 10, 25, 50, "All"]],
|
|
processing: true,
|
|
pageLength: 5,
|
|
responsive: true,
|
|
// dom: `<'row'<'col-sm-12'tr>><'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7 dataTables_pager'lp>>`,
|
|
language: {
|
|
'lengthMenu': 'Display _MENU_',
|
|
}
|
|
});
|
|
|
|
})
|
|
}
|
|
|
|
function edc(id,title) {
|
|
|
|
$('#mEdc_title').html(`Link EDC `+title);
|
|
$('#mEdc_subTitle').html(`Daftar Link EDC `+title);
|
|
|
|
$("#formDataEdc")[0].reset();
|
|
$('#formDataEdc').bootstrapValidator("resetForm",true);
|
|
$('#id_brand').val(null).trigger('change.select2');
|
|
$('#device_id').val(null).trigger('change.select2');
|
|
|
|
$('#mEdc').modal('show');
|
|
|
|
edcData(id)
|
|
|
|
}
|
|
|
|
|
|
function removeEdc(id,title) {
|
|
let formData = new FormData();
|
|
formData.append('device_id',id);
|
|
formData.append('mid',$('#get_outlet_id_edc').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_outlet_id_edc').val(),title)
|
|
|
|
edcData($('#get_outlet_id_edc').val())
|
|
ref_edc('device_id',$('#id_brand').val());
|
|
table.ajax.url(routeTable).load();
|
|
}else{
|
|
znNotif("danger", res.rm);
|
|
}
|
|
|
|
|
|
|
|
})
|
|
}
|
|
|
|
function storeEdc() {
|
|
|
|
var $validator = $('#formDataEdc').data('bootstrapValidator').validate();
|
|
if ($validator.isValid()) {
|
|
let formData = new FormData();
|
|
formData.append('device_id',$('#device_id').val());
|
|
formData.append('mid',$('#get_mid_edc').val());
|
|
formData.append('outlet_id',$('#get_outlet_id_edc').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();
|
|
edcData($('#get_outlet_id_edc').val())
|
|
|
|
|
|
console.log($('#id_brand').val());
|
|
ref_edc('device_id',$('#id_brand').val());
|
|
}else{
|
|
znNotif("danger", res.rm);
|
|
}
|
|
})
|
|
}
|
|
|
|
}
|
|
|
|
|
|
function edit(id) {
|
|
clearForm();
|
|
$('#mForm').modal('show');
|
|
znLoadingModal('mForm');
|
|
$('#mForm_title').html(`Edit Data`);
|
|
$('#mForm_subTitle').html(`Edit Data `+title);
|
|
|
|
let formData = new FormData();
|
|
formData.append('id',id);
|
|
doPost(routeEdit, formData, function (msg, res) {
|
|
console.log(res);
|
|
znLoadingModalEnd('mForm');
|
|
var data = res.data.outlet;
|
|
var bank = res.data.bank;
|
|
|
|
$('#get_id').val(data.outlet_id);
|
|
$('#outlet_nm').val(data.outlet_nm);
|
|
$('#outlet_code').val(data.outlet_code);
|
|
$('#address').val(data.address);
|
|
$('#nmid').val(data.nmid);
|
|
$('#charge_service_prs').val(data.charge_service_prs);
|
|
|
|
$('#city_id').val(data.city_id).trigger('change.select2');
|
|
$('#mid').val(data.mid).trigger('change.select2');
|
|
$('#outlet_type_id').val(data.outlet_type_id).trigger('change.select2');
|
|
|
|
let is_charge_service = (data.is_charge_service == true) ? 't':'f';
|
|
|
|
if (is_charge_service == 't') {
|
|
$('#isService').show();
|
|
}else{
|
|
$('#isService').hide();
|
|
}
|
|
|
|
bank.forEach(v => {
|
|
$('#outlet_bank_'+v.bank_code).prop('checked', true);
|
|
});
|
|
|
|
|
|
|
|
$('#is_charge_service').val(is_charge_service).trigger('change.select2');
|
|
|
|
$('#formData').data('bootstrapValidator').validate();
|
|
})
|
|
}
|
|
|
|
function storeCustomConf() {
|
|
let myForm = document.getElementById('formDataConf');
|
|
let formData = new FormData(myForm);
|
|
|
|
var $validator = $('#formDataConf').data('bootstrapValidator').validate();
|
|
if ($validator.isValid()) {
|
|
znLoadingModal('mFormConf');
|
|
doPost(routeStoreCustom+'&act=storeConfirm', formData, function (msg, data) {
|
|
//console.log(data);
|
|
znLoadingModalEnd('mFormConf');
|
|
if (data == null){
|
|
znNotif("danger", msg);
|
|
}else {
|
|
if(data.rc == 0){
|
|
znNotif('success','Berhasil Menyimpan Data');
|
|
$('#mFormConf').modal('hide');
|
|
table.ajax.url(routeTable).load();
|
|
}else{
|
|
znNotif("danger", data.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=storeToko', 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);
|
|
$('#mForm').css('overflow','auto');
|
|
}
|
|
}
|
|
})
|
|
}
|
|
|
|
}
|
|
|
|
function getTable() {
|
|
let merchant = $('#merchant_filter').val();
|
|
|
|
table.ajax.url(routeTable+'&merchant='+merchant).load();
|
|
}
|
|
|
|
|
|
//VALIDASI
|
|
$(document).ready(function () {
|
|
|
|
$('.select2').select2({
|
|
placeholder: "Silahkan Pilih"
|
|
});
|
|
|
|
$('#id_brand').on('select2:select', function (e) {
|
|
var data = e.params.data;
|
|
ref_edc('device_id',data.id);
|
|
});
|
|
|
|
$('#is_charge_service').on('select2:select', function (e) {
|
|
var data = e.params.data;
|
|
if (data.id == 't') {
|
|
$('#isService').show();
|
|
}else{
|
|
$('#isService').hide();
|
|
}
|
|
});
|
|
|
|
|
|
|
|
|
|
$("#formData").bootstrapValidator({
|
|
excluded: [':disabled'],
|
|
feedbackIcons: {
|
|
valid: 'glyphicon glyphicon-ok',
|
|
invalid: 'glyphicon glyphicon-remove',
|
|
validating: 'glyphicon glyphicon-refresh'
|
|
},
|
|
fields: {
|
|
outlet_nm: {
|
|
validators: {
|
|
notEmpty: {
|
|
message: 'Tidak Boleh Kosong'
|
|
},
|
|
stringLength: {
|
|
max:250,
|
|
message: 'Maksimal 250 Karakter'
|
|
}
|
|
}
|
|
},
|
|
mid: {
|
|
validators: {
|
|
notEmpty: {
|
|
message: 'Tidak Boleh Kosong'
|
|
},
|
|
stringLength: {
|
|
max:15,
|
|
message: 'Maksimal 15 Karakter'
|
|
}
|
|
}
|
|
},
|
|
|
|
outlet_code: {
|
|
validators: {
|
|
notEmpty: {
|
|
message: 'Tidak Boleh Kosong'
|
|
},
|
|
stringLength: {
|
|
max:10,
|
|
message: 'Maksimal 10 Karakter'
|
|
}
|
|
}
|
|
},
|
|
nmid: {
|
|
validators: {
|
|
notEmpty: {
|
|
message: 'Tidak Boleh Kosong'
|
|
},
|
|
stringLength: {
|
|
max:13,
|
|
message: 'Maksimal 13 Karakter'
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
}).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();
|
|
});
|
|
|
|
$("#formDataConf").bootstrapValidator({
|
|
excluded: [':disabled'],
|
|
feedbackIcons: {
|
|
valid: 'glyphicon glyphicon-ok',
|
|
invalid: 'glyphicon glyphicon-remove',
|
|
validating: 'glyphicon glyphicon-refresh'
|
|
},
|
|
fields: {
|
|
mid_trx: {
|
|
validators: {
|
|
notEmpty: {
|
|
message: 'Tidak Boleh Kosong'
|
|
},
|
|
stringLength: {
|
|
max:20,
|
|
message: 'Maksimal 20 Karakter'
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
}).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();
|
|
});
|
|
|
|
$("#formDataEdc").bootstrapValidator({
|
|
excluded: [':disabled'],
|
|
feedbackIcons: {
|
|
valid: 'glyphicon glyphicon-ok',
|
|
invalid: 'glyphicon glyphicon-remove',
|
|
validating: 'glyphicon glyphicon-refresh'
|
|
},
|
|
fields: {
|
|
id_brand: {
|
|
validators: {
|
|
notEmpty: {
|
|
message: 'Tidak Boleh Kosong'
|
|
}
|
|
}
|
|
},
|
|
device_id: {
|
|
validators: {
|
|
notEmpty: {
|
|
message: 'Tidak Boleh Kosong'
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
}).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>
|