You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

173 lines
4.7 KiB
PHP

<?php
session_start();
if($_SESSION['validUser'] !== TRUE)
{
header("location: ./index.php");
exit();
}
?>
<?php
if(isset($_REQUEST['status']) && $_REQUEST['status'] == 'ok') {
if ($_REQUEST['operation'] == 'caripelanggan') {
cari_pelanggan($_REQUEST['txtcari']);
} elseif ($_REQUEST['operation'] == 'cariupline') {
cari_upline($_REQUEST['txtcari']);
} elseif ($_REQUEST['operation'] == 'ambilpelanggan') {
ambil_pelanggan($_REQUEST['id_pelanggan']);
} elseif ($_REQUEST['operation'] == 'hapuspelanggan') {
hapus_pelanggan($_REQUEST['id_pelanggan']);
}
}
function hapus_pelanggan($id_pelanggan){
if ($id_pelanggan != "") {
$array_data = array();
require_once '../db_login.inc.php';
$mysqli = new mysqli(HOST, USER, PASSWORD, DATABASE);
$query = "DELETE FROM pelanggan WHERE kd_customer = '".$id_pelanggan."' LIMIT 1";
$stmt = $mysqli->prepare($query);
$stmt->execute();
if($stmt->affected_rows > 0) {
$array_data[0] = 1;
} else {
$array_data[0] = 0;
}
$stmt->close();
/* tutup koneksi */
$mysqli->close();
/* cetak hasil */
//echo count($array_data);
echo json_encode($array_data);
}
}
function cek_pelanggan($id_pelanggan)
{
require_once '../db_login.inc.php';
$mysqli = new mysqli(HOST, USER, PASSWORD, DATABASE);
$data = $mysqli->query("SELECT COUNT(*) FROM pelanggan WHERE kd_customer = '{$id_pelanggan}'")->fetch_array();
if ($data[0] > 0)
{
return true;
} else
{
return false;
}
}
function cari_pelanggan($nama) {
if($nama != "") {
$harray = array();
require_once '../db_login.inc.php';
$mysqli = new mysqli(HOST, USER, PASSWORD, DATABASE);
$data = $mysqli->query("SELECT kd_customer, nama, alamat, nilai_bon, bts_bon FROM pelanggan WHERE nama LIKE '%".$nama."%'");
if($data->num_rows > 0) {
$idx = 0;
while($a = $data->fetch_array(MYSQLI_ASSOC)) {
$harray[$idx] = array(
'kd_customer' => $a['kd_customer'],
'nama' => $a['nama'],
'alamat' => $a['alamat'],
'nilai_bon' => number_format($a['nilai_bon'],0,',','.'),
'bts_bon' => number_format($a['bts_bon'],0,',','.')
);
$idx++;
}
/* tutup hasil query */
$data->close();
}
/* tutup koneksi */
$mysqli->close();
/* cetak hasil */
echo json_encode($harray);
}
}
function cari_upline($nama) {
if($nama != "") {
$harray = array();
require_once '../db_login.inc.php';
$mysqli = new mysqli(HOST, USER, PASSWORD, DATABASE);
$data = $mysqli->query("SELECT kd_customer, nama, alamat, nilai_bon, bts_bon FROM pelanggan WHERE nama LIKE '%".$nama."%' AND upline = '#'");
if($data->num_rows > 0) {
$idx = 0;
while($a = $data->fetch_array(MYSQLI_ASSOC)) {
$harray[$idx] = array(
'kd_customer' => $a['kd_customer'],
'nama' => $a['nama'],
'alamat' => $a['alamat'],
'nilai_bon' => number_format($a['nilai_bon'],0,',','.'),
'bts_bon' => number_format($a['bts_bon'],0,',','.')
);
$idx++;
}
/* tutup hasil query */
$data->close();
}
/* tutup koneksi */
$mysqli->close();
/* cetak hasil */
echo json_encode($harray);
}
}
function ambil_pelanggan($id_pelanggan) {
if ($id_pelanggan != "") {
$array_data = array();
require_once '../db_login.inc.php';
$mysqli = new mysqli(HOST, USER, PASSWORD, DATABASE);
$data = $mysqli->query("SELECT * FROM pelanggan WHERE kd_customer = '".$id_pelanggan."'");
if($data->num_rows > 0) {
$idx = 0;
while($a = $data->fetch_array(MYSQLI_ASSOC)) {
$tgl_lahir = '';
if($a['tgl_lahir'] != "") {
$tgl_lahir = substr($a['tgl_lahir'],8,2)."-".substr($a['tgl_lahir'],5,2)."-".substr($a['tgl_lahir'],0,4);
} else {
$tgl_lahir = $a['tgl_lahir'];
}
$array_data[$idx] = array(
'kd_customer' => $a['kd_customer'],
'alias' => $a['alias'],
'member' => $a['member'],
'ktp' => $a['ktp'],
'nama' => $a['nama'],
'alamat' => $a['alamat'],
'kd_lokasi' => $a['kd_lokasi'],
'wilayah' => $a['wilayah'],
'tempat_lahir' => $a['tempat_lahir'],
'tgl_lahir' => $tgl_lahir,
'jns_kelamin' => $a['jns_kelamin'],
'agama' => $a['agama'],
'kd_lokasi' => $a['kd_lokasi'],
'pekerjaan' => $a['pekerjaan'],
'status_nikah' => $a['status_nikah'],
'telp' => $a['telp'],
'ponsel' => $a['ponsel'],
'email' => $a['email'],
'status' => $a['status'],
'upline' => $a['upline'],
'bts_bon' => $a['bts_bon'],
'nilai_bon' => $a['nilai_bon'],
'bts_bon_istimewa' => $a['bts_bon_istimewa'],
'nilai_komisi' => $a['nilai_komisi'],
'komisi_diambil' => $a['komisi_diambil'],
'jenis_customer' => $a['jenis_customer']
);
$idx++;
}
/* tutup hasil query */
$data->close();
}
/* tutup koneksi */
$mysqli->close();
/* cetak hasil */
echo json_encode($array_data);
}
}
?>