Advertisement
tukangbegal

add-customer-json

Apr 15th, 2018
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.05 KB | None | 0 0
  1. <?php
  2.     include_once "dbconnect.php";
  3.    
  4.  
  5. if($_SERVER['REQUEST_METHOD']=='POST'){
  6.     class emp{}
  7.    
  8.  
  9.     $user = $_POST['user'];
  10.     $tanggal = $_POST['tanggal'];
  11.     $jam = $_POST['jam'];
  12.     $latitude = $_POST['latitude'];
  13.     $longitude = $_POST['longitude'];
  14.  
  15.    
  16.     $image = $_POST['image'];
  17.     $user = $_POST['user'];
  18.     $tanggal = $_POST['tanggal'];
  19.     $jam = $_POST['jam'];
  20.     $latitude = $_POST['latitude'];
  21.     $longitude = $_POST['longitude'];
  22.  
  23.    
  24.     $nm_toko = $_POST['nmToko'];
  25.     $tel_toko = $_POST['telToko'];
  26.     $hp_toko = $_POST['hpToko'];
  27.     $fax_toko = $_POST['faxToko'];
  28.     $alm_toko = $_POST['almToko'];
  29.     $kota_toko = $_POST['kotaToko'];
  30.     $tipe_toko = $_POST['tipeToko'];
  31.    
  32.     $ktp_cust = $_POST['ktpCust'];
  33.     $nm_cust = $_POST['nmCust'];
  34.     $alm_cust = $_POST['almCust'];
  35.     $kota_cust = $_POST['kotaCust'];   
  36.    
  37.     $npwp_cust = $_POST['npwpCust'];
  38.     $alm_npwp_cust = $_POST['almNpwp'];
  39.     $nama_npwp_cust = $_POST['nmNpwp'];
  40.     $nppkp_cust = $_POST['nppkp'];
  41.    
  42.     $payment_cust = $_POST['paymentCust'];
  43.     $limit_cust = $_POST['limitToko'];
  44.     $top_cust = $_POST['topToko'];
  45.    
  46.     $foto_cust = $_POST['fotoToko'];
  47.     $foto_ktp_cust = $_POST['fotoKtp'];
  48.     $foto_signature_cust = $_POST['fotoSignature'];
  49.     $status="pending";
  50.  
  51.    
  52.         $random = random_word(20);
  53.        
  54.         $pathToko = "upload/toko/".$random.".png";
  55.         $pathKTP = "upload/ktp/".$random.".png";
  56.         $pathsignature = "upload/signature/".$random.".png";
  57.    
  58.         $actualpath = $random.".png";
  59.  
  60.         $node = mysqli_query($con, "SELECT Node_ID from tbl_user_pass where User_LoginName='$user');
  61.    
  62.         $locationToko = mysqli_query($con, "SELECT po.postal_name, co.country_name FROM tbl_postal po
  63.                                             LEFT JOIN tbl_city ci ON ci.postal_id=po.postal_id
  64.                                             LEFT JOIN tbl_country co ON co.country_id=po.country_id
  65.                                             WHERE ci.city_name='$kota_toko'");
  66.        
  67.         $locationOwner = mysqli_query($con, "SELECT po.postal_name, co.country_name FROM tbl_postal po
  68.                                             LEFT JOIN tbl_city ci ON ci.postal_id=po.postal_id
  69.                                             LEFT JOIN tbl_country co ON co.country_id=po.country_id
  70.                                             WHERE ci.city_name='$kota_cust'");
  71.  
  72.         $hasiltoko=mysqli_fetch_array($locationToko);
  73.         $hasilowner=mysqli_fetch_array($locationOwner);
  74.        $hasilnode=mysqli_fetch_array($node);
  75.        
  76.         $insertCustomer = mysqli_query($con, "INSERT INTO tbl_customer_pending (cust_company,cust_name,cust_address1,cust_city,cust_postal,cust_country
  77.         cust_phone,cust_fax,cust_mobile,cust_id_number,cust_id_address1,cust_id_city,cust_id_postal,cust_id_country,cust_NPWP,cust_NPWP_Address1
  78.         cust_NPWP_Name,cust_NPPKP,cust_payment,cust_limit,cust_TOP,cust_Type,cust_since,cust_salesID,Node_ID,cust_latitude,cust_longitude,cust_status,
  79.         cust_pic,cust_id_pic,cust_signature) VALUES     ('$nm_toko','$nm_cust','$alm_toko','$kota_toko','$hasiltoko['postal_name']','$hasiltoko['country_name']','$tel_toko','$fax_toko','$hp_toko',
  80.         '$ktp_cust','$alm_cust','$kota_cust','$hasilowner['postal_name']','$hasilowner['country_name']','$npwp_cust','$alm_npwp_cust','$nm_npwp_cust',
  81.         '$nppkp_npwp','$payment_cust','$limit_cust','$top_cust','$tipe_toko','$tanggal','$user','$hasilnode['Node_ID']','$latitude','$longitude','$status'
  82.         '$pathToko','$pathKTP','$pathSignature')");
  83.        
  84.         if ($insertCustomer){
  85.             file_put_contents($pathToko,base64_decode($foto_cust));
  86.            file_put_contents($pathKTP,base64_decode($foto_ktp_cust));
  87.            file_put_contents($pathSignature,base64_decode($foto_signature_cust));
  88.            
  89.             $response = new emp();
  90.             $response->success = 1;
  91.             $response->message = "Berhasil Menambah Customer";
  92.             die(json_encode($response));
  93.         } else{
  94.             $response = new emp();
  95.             $response->success = 0;
  96.             $response->message = "Terjadi Kesalahan Pada Server";
  97.             die(json_encode($response));
  98.         }
  99.     }
  100.    
  101.     // fungsi random string pada gambar untuk menghindari nama file yang sama
  102.         function random_word($id = 20){
  103.         $pool = '1234567890abcdefghijkmnpqrstuvwxyz';
  104.        
  105.         $word = '';
  106.         for ($i = 0; $i < $id; $i++){
  107.             $word .= substr($pool, mt_rand(0, strlen($pool) -1), 1);
  108.         }
  109.         return $word;
  110.     }
  111.     mysqli_close($con);
  112.    
  113. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement