This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//MEMBUAT COMBOBOX BIASA YANG BISA DIPAKAI BERKALI-KALI PADA BANYAK MENU TANPA PERLU LOAD ULANG FUNCTION INI LAGI, CUKUP LOAD SEKALI SAJA, PADA SAAT LOGIN | |
<?php | |
header("Access-Control-Allow-Origin: *"); | |
header("Content-Type: application/json; charset=UTF-8"); | |
include "../configurations/configs.php"; | |
try { | |
$stmt2 = $db2->prepare("SELECT * FROM cabang WHERE status_cabang='1' ORDER BY id_cabang ASC"); | |
$stmt2->execute(); | |
$rows2 = $stmt2->fetchAll(PDO::FETCH_ASSOC); | |
$data = array(); | |
/* | |
$data[0] = array( //TAMBAHKAN DEFAULT VALUE -- KOSONG -- | |
"hasil" => 0, | |
"pesan_hasil" => htmlspecialchars("-- KOSONG --"), | |
); | |
*/ | |
for ($y = 0; $y < count($rows2); $y++) { //AMBIL DATA TABEL cabang | |
$id_cabang = $rows2[$y]["id_cabang"]; | |
$nama_cabang = $rows2[$y]["nama_cabang"]; | |
$data[$y + 0] = array( //ANGKA 0 DIGANTI 1, KETIKA DEFAULT VALUE DIATAS AKTIF | |
"hasil" => htmlspecialchars($id_cabang), | |
"pesan_hasil" => htmlspecialchars($nama_cabang), | |
); | |
} | |
$json_data = json_encode($data); | |
if (count($data) > 0) { //ADA DATA | |
echo $json_data; | |
} else { //TIDAK ADA DATA | |
echo '[{"hasil":0,"pesan_hasil":"TIDAK ADA DATA"}]'; | |
} | |
} catch (PDOException $ex) { | |
echo '[{"hasil":0,"pesan_hasil":"' . $ex->getMessage() . '"}]'; | |
} | |
?> | |
function ee_cabang_lokal() { | |
var data = { | |
token_pengguna: isi_token_pengguna | |
}; | |
$.ajax({ | |
url: protocol + "://" + host + "/" + directory + "/actions/ee_cabang_lokal.php?nc=" + (new Date()).getTime(), | |
type: "POST", | |
dataType: "json", | |
data: data, | |
success: function (pesan) { | |
var hasil = ""; | |
var data_combobox = ""; | |
$.each(pesan, function (i, n) { | |
hasil = n["hasil"]; | |
pesan_hasil = n["pesan_hasil"]; | |
data_combobox += "<option value=\"" + hasil + "\">" + pesan_hasil + "</option>"; | |
}); | |
localStorage.setItem("data_combobox_cc_cabang_lokal", data_combobox); | |
}, | |
error: function (pesan) { | |
alert("ERROR: ee_cabang_lokal"); | |
} | |
}); | |
} | |
ee_cabang_lokal(); //LOAD CUKUP SEKALI PADA SAAT LOGIN SAJA | |
<div class="form-group form-group-sm"> | |
<label class="col-sm-3" for="id_cabang">ID Cabang*</label> | |
<div class="col-sm-9"> | |
<select class="form-control input-sm" id="id_cabang" name="id_cabang" required disabled> | |
<option value="0">-- PILIH CABANG --</option> | |
</select> | |
</div> | |
</div> | |
$(document).ready(function () { | |
$("#id_cabang").html(localStorage.getItem("data_combobox_cc_cabang_lokal")); //TINGGAL LOAD INI PADA VIEW TAMPILAN | |
}); | |
//MEMBUAT COMBOBOX BIASA YANG DIPANGGIL PADA MENU SAAT DIBUTUHKAN, MASUKKAN FULL FUNCTION JS PADA HTML | |
<?php | |
header("Access-Control-Allow-Origin: *"); | |
header("Content-Type: application/json; charset=UTF-8"); | |
include "../configurations/configs.php"; | |
try { | |
$stmt2 = $db2->prepare("SELECT * FROM gudang WHERE status_gudang='1' ORDER BY id_gudang ASC"); | |
$stmt2->execute(); | |
$rows2 = $stmt2->fetchAll(PDO::FETCH_ASSOC); | |
$data = array(); | |
for ($y = 0; $y < count($rows2); $y++) { //AMBIL DATA TABEL gudang | |
$id_gudang = $rows2[$y]["id_gudang"]; | |
$nama_gudang = $rows2[$y]["nama_gudang"]; | |
$data[$y + 0] = array( | |
"hasil" => htmlspecialchars($id_gudang), | |
"pesan_hasil" => htmlspecialchars($nama_gudang), | |
); | |
} | |
/* | |
$data[0] = array( //TAMBAHKAN DEFAULT VALUE -- KOSONG -- | |
"hasil" => 0, | |
"pesan_hasil" => htmlspecialchars("-- KOSONG --"), | |
); | |
*/ | |
$json_data = json_encode($data); | |
if (count($data) > 0) { //ADA DATA | |
echo $json_data; | |
} else { //TIDAK ADA DATA | |
echo '[{"hasil":0,"pesan_hasil":"TIDAK ADA DATA"}]'; | |
} | |
} catch (PDOException $ex) { | |
echo '[{"hasil":0,"pesan_hasil":"' . $ex->getMessage() . '"}]'; | |
} | |
?> | |
<div class="form-group form-group-sm"> | |
<label class="col-sm-2" for="id_gudang">Gudang*</label> | |
<div class="col-sm-10"> | |
<select class="form-control input-sm" id="id_gudang" name="id_gudang" required> | |
<option value="0">-- KOSONG --</option> | |
</select> | |
<small class="form-text text-muted sr-only">Keterangan tambahan untuk field Gudang</small> | |
<div class="help-block with-errors sr-only"></div> | |
</div> | |
</div> | |
function gudang_combobox() { | |
var data = { | |
token_pengguna: isi_token_pengguna | |
}; | |
$.ajax({ | |
url: protocol + "://" + host + "/" + directory + "/actions/gudang_combobox.php?nc=" + (new Date()).getTime(), | |
type: "POST", | |
data: data, | |
success: function (pesan) { | |
var hasil = ""; | |
var data_combobox = ""; | |
$.each(pesan, function (i, n) { | |
hasil = n["hasil"]; | |
pesan_hasil = n["pesan_hasil"]; | |
data_combobox = data_combobox + "<option value=\"" + hasil + "\">" + pesan_hasil + "</option>"; | |
}); | |
$("#id_gudang").html(data_combobox); | |
}, | |
error: function (pesan) { | |
alert("ERROR: gudang_combobox"); | |
} | |
}); | |
} | |
$(document).ready(function () { | |
gudang_combobox(); //JALANKAN INI UNTUK MENJALANKAN | |
}); | |
//ONCHANGE BERKELANJUTAN, JIKA DI TRIGGER DARI COMBOBOX BIASA | |
<?php | |
header("Access-Control-Allow-Origin: *"); | |
header("Content-Type: application/json; charset=UTF-8"); | |
include "../configurations/configs.php"; | |
try { | |
$stmt2 = $db4->prepare("SELECT * FROM gudang WHERE id_cabang=:2"); | |
$stmt2->execute(array(":2" => $_POST['id_cabang'])); | |
$rows2 = $stmt2->fetchAll(PDO::FETCH_ASSOC); | |
$data = array(); | |
// $data[0] = array( //TAMBAHKAN DEFAULT VALUE -- KOSONG -- | |
// "hasil" => 0, | |
// "pesan_hasil" => htmlspecialchars("-- PILIH --"), | |
// ); | |
for ($y = 0; $y < count($rows2); $y++) { //AMBIL DATA TABEL master_mesin | |
$id_gudang = $rows2[$y]["id_gudang"]; | |
$kode_gudang = $rows2[$y]["kode_gudang"]; | |
$nama_gudang = $rows2[$y]["nama_gudang"]; | |
$data[$y + 0] = array( //UBAH 0 MENJADI 1 JIKA DEFAULT VALUE DIATAS AKTIF | |
"hasil" => htmlspecialchars($id_gudang), | |
"pesan_hasil" => htmlspecialchars($kode_gudang . " - " . $nama_gudang), | |
); | |
} | |
$json_data = json_encode($data); | |
//$decoded_data = json_decode($json_data); | |
if (count($data) > 0) { //ADA DATA | |
echo $json_data; | |
} else { //TIDAK ADA DATA | |
echo '[{"hasil":0,"pesan_hasil":"TIDAK ADA DATA"}]'; | |
} | |
} catch (PDOException $ex) { //TERDAPAT KESALAHAN PADA QUERY ATAU VARIABLE | |
echo '[{"hasil":0,"pesan_hasil":"' . $ex->getMessage() . '"}]'; | |
} | |
?> | |
<div class="form-group form-group-sm"> | |
<label class="col-sm-3" for="id_cabang">ID Cabang*</label> | |
<div class="col-sm-9"> | |
<select class="form-control input-sm" id="id_cabang" name="id_cabang" required> | |
<option value="0">-- PILIH CABANG --</option> | |
</select> | |
</div> | |
</div> | |
<div class="form-group form-group-sm"> | |
<label class="col-sm-3" for="id_gudang">ID Gudang*</label> | |
<div class="col-sm-9"> | |
<select class="form-control input-sm" id="id_gudang" name="id_gudang" required> | |
<option value="0">-- PILIH GUDANG --</option> | |
</select> | |
</div> | |
</div> | |
$('#id_cabang').change(function () { | |
master_gudang_autocomplete_tampungan(); | |
}); | |
function master_gudang_autocomplete_tampungan() { | |
var data = { | |
id_cabang: $('#id_cabang').val(), | |
token_pengguna: isi_token_pengguna | |
}; | |
$.ajax({ | |
url: protocol + "://" + host + "/" + directory + "/actions/master_gudang_autocomplete_tampungan.php?nc=" + (new Date()).getTime(), | |
type: "POST", | |
data: data, | |
success: function (pesan) { | |
var hasil = ""; | |
var data_combobox = ""; | |
$.each(pesan, function (i, n) { | |
hasil = n["hasil"]; | |
pesan_hasil = n["pesan_hasil"]; | |
data_combobox += "<option value=\"" + hasil + "\">" + pesan_hasil + "</option>"; | |
}); | |
$("#id_gudang").html(data_combobox); | |
}, | |
error: function (pesan) { | |
alert("ERROR: ff_master_wrapper_lokal"); | |
} | |
}); | |
} | |
//MEMBUAT COMBOBOX SELECT2 YANG BISA DIPAKAI BERKALI-KALI PADA BANYAK MENU TANPA PERLU LOAD ULANG FUNCTION INI LAGI, CUKUP LOAD SEKALI SAJA, PADA SAAT LOGIN | |
<?php | |
header("Access-Control-Allow-Origin: *"); | |
header("Content-Type: application/json; charset=UTF-8"); | |
include "../configurations/configs.php"; | |
try { | |
$stmt2 = $db4->prepare("SELECT * FROM master_slip ORDER BY id_slip ASC"); | |
$stmt2->execute(); | |
$rows2 = $stmt2->fetchAll(PDO::FETCH_ASSOC); | |
for ($y = 0; $y < count($rows2); $y++) { | |
//$data[] = array($rows2[$y]["id_wrapper"], trim(preg_replace('/\s+/', ' ', $rows2[$y]["nama_wrapper"] . " = " . ROUND($rows2[$y]["weight"], 0) . " KG"))); | |
$data[] = array( | |
$rows2[$y]["id_slip"], | |
trim(preg_replace('/\s+/', ' ', $rows2[$y]["kode_slip"] . " - " . $rows2[$y]["nama_slip"])), | |
); | |
} | |
if (count($rows2) == 0) { | |
$data[] = array(0, "TIDAK ADA DATA"); | |
} | |
$json_data = json_encode($data); | |
echo $json_data; | |
} catch (PDOException $ex) { //TERDAPAT KESALAHAN PADA QUERY ATAU VARIABLE | |
echo '[{"hasil":0,"pesan_hasil":"' . $ex->getMessage() . '"}]'; | |
} | |
?> | |
function ff_master_slip_lokal() { | |
var data = { | |
token_pengguna: isi_token_pengguna | |
}; | |
$.ajax({ | |
url: protocol + "://" + host + "/" + directory + "/actions/ff_master_slip_lokal.php?nc=" + (new Date()).getTime(), | |
type: "POST", | |
dataType: "json", | |
data: data, | |
success: function (pesan) { | |
let tempTampungan = [{ id: '-1', text: '-- PILIH SLIP --' }]; | |
//let tempTampungan = []; | |
for (let i = 0; i < pesan.length; i++) { | |
tempTampungan.push({ id: pesan[i][0], text: pesan[i][1] }); | |
} | |
localStorage.setItem("data_select2_cc_master_slip_lokal", JSON.stringify(tempTampungan)); | |
}, | |
error: function (pesan) { | |
alert("ERROR: ff_master_slip_lokal"); | |
} | |
}); | |
} | |
ff_master_slip_lokal(); //LOAD CUKUP SEKALI PADA SAAT LOGIN SAJA | |
<div class="form-group form-group-sm"> | |
<label class="col-sm-3" for="id_slip">Slip*</label> | |
<div class="col-sm-9"> | |
<select class="form-control input-sm" id="id_slip" name="id_slip" required> | |
<option value="0">-- Pilih Slip --</option> | |
</select> | |
<small class="form-text text-muted sr-only">Keterangan tambahan untuk field Ppn Pembelian</small> | |
<div class="help-block with-errors sr-only"></div> | |
</div> | |
</div> | |
function cc_master_slip_lokal2() { | |
let pesan = JSON.parse(localStorage.getItem("data_select2_cc_master_slip_lokal")); | |
$('#id_slip').empty(); | |
$('#id_slip').select2({ | |
data: pesan | |
}); | |
$('#id_slip').trigger("change"); | |
} | |
$(document).ready(function () { | |
cc_master_slip_lokal2(); //JALANKAN INI UNTUK MENJALANKAN | |
}); | |
//MEMBUAT COMBOBOX SELECT2 YANG DIPANGGIL PADA MENU SAAT DIBUTUHKAN, MASUKKAN FULL FUNCTION JS, BISA DITAMBAHKAN PARAMETER OUTPUT TAMBAHAN | |
<?php | |
header("Access-Control-Allow-Origin: *"); | |
header("Content-Type: application/json; charset=UTF-8"); | |
include "../configurations/configs.php"; | |
try { | |
if (isset($_POST["id_cabang"])) { | |
if ($_POST["id_cabang"] != "") { | |
$stmt2 = $db2->prepare("SELECT * FROM master_wrapper WHERE id_cabang=:1 ORDER BY id_wrapper ASC"); | |
$stmt2->execute(array(":1" => $_POST["id_cabang"])); | |
} else { | |
$stmt2 = $db2->prepare("SELECT * FROM master_wrapper ORDER BY id_wrapper ASC"); | |
$stmt2->execute(); | |
} | |
} else { | |
$stmt2 = $db2->prepare("SELECT * FROM master_wrapper ORDER BY id_wrapper ASC"); | |
$stmt2->execute(); | |
} | |
$rows2 = $stmt2->fetchAll(PDO::FETCH_ASSOC); | |
for ($y = 0; $y < count($rows2); $y++) { | |
$data[] = array( | |
$rows2[$y]["id_wrapper"], | |
trim(preg_replace('/\s+/', ' ', $rows2[$y]["nama_wrapper"] . " = " . ROUND($rows2[$y]["weight"], 4) . " KG")), | |
trim(preg_replace('/\s+/', ' ', ROUND($rows2[$y]["weight"], 4))), | |
); | |
} | |
if (count($rows2) == 0) { | |
$data[] = array(0, "TIDAK ADA DATA", 0); | |
} | |
$json_data = json_encode($data); | |
echo $json_data; | |
} catch (PDOException $ex) { //TERDAPAT KESALAHAN PADA QUERY ATAU VARIABLE | |
echo '[{"hasil":0,"pesan_hasil":"' . $ex->getMessage() . '"}]'; | |
} | |
?> | |
<div class="form-group form-group-sm"> | |
<label class="col-sm-3" for="id_wrapper">Wrapper*</label> | |
<div class="col-sm-9"> | |
<select class="form-control input-sm" id="id_wrapper" name="id_wrapper" required> | |
<option value="0">-- PILIH WRAPPER --</option> | |
</select> | |
<small class="form-text text-muted sr-only">Keterangan tambahan untuk field Perkiraan</small> | |
<div class="help-block with-errors sr-only"></div> | |
</div> | |
</div> | |
<input type="number" step="0.0001" class="form-control input-sm" id="weight" name="weight" data-minlength="1" maxlength="" value="0" data-error="Wajib isi" placeholder="Masukkan Sg Pembelian Detail" required> | |
function ff_master_wrapper_lokal() { | |
var data = { | |
id_cabang: $('#id_cabang').val(), | |
token_pengguna: isi_token_pengguna | |
}; | |
$.ajax({ | |
url: protocol + "://" + host + "/" + directory + "/actions/ff_master_wrapper_lokal.php?nc=" + (new Date()).getTime(), | |
type: "POST", | |
dataType: "json", | |
data: data, | |
success: function (pesan) { | |
$('#id_wrapper').empty(); //KOSONGKAN ISI SELECT2 | |
let tempTampungan = [{ id: '-1', text: '-- PILIH MASTER WRAPPER --', weight: 0 }]; //MEMBUAT DATA PERTAMA MANUAL SELECT2 | |
//let tempTampungan = []; | |
for (let i = 0; i < pesan.length; i++) { | |
tempTampungan.push({ | |
id: pesan[i][0], //VALUE | |
text: pesan[i][1], //TEXT-HTML | |
weight: pesan[i][2] //TAMBAHAN | |
}); | |
} | |
$('#id_wrapper').select2({ | |
data: tempTampungan | |
}); | |
//$('#id_wrapper').val(1); //JIKA INGIN MENGESET DEFAULT VALUE | |
$('#id_wrapper').trigger("change"); //HARUS SET INI PALING AKHIR, UNTUK MENGUBAH SESUAI DATA DIATAS | |
}, | |
error: function (pesan) { | |
alert("ERROR: ff_master_wrapper_lokal"); | |
} | |
}); | |
} | |
$('#id_wrapper').on('select2:select', function (e) { //PENGGANTI ONCHANGE DISINI | |
let dataselect = e.params.data; | |
$("#weight").val(dataselect.weight); | |
$('#id_wrapper').trigger("change"); | |
}); | |
$(document).ready(function () { | |
ff_master_wrapper_lokal(); //JALANKAN INI UNTUK MENJALANKAN | |
}); |
Tidak ada komentar:
Posting Komentar