	<?php
	/**
	* Created by PhpStorm.
	* User: ahmad
	* Date: 20/08/2019
	* Time: 11:48 AM
	*/

	require_once("../connection.php");
	$key=mysqli_real_escape_string($connect, $_POST['key']);
	
	$nama_toko=mysqli_real_escape_string($connect, $_POST['name_store']);
	$email=mysqli_real_escape_string($connect, $_POST['email']);
	$pajak=mysqli_real_escape_string($connect, $_POST['tax']);
	$service_charge=mysqli_real_escape_string($connect, $_POST['service_charge']);
	$nohp=mysqli_real_escape_string($connect, $_POST['nohp']);
	$alamat=mysqli_real_escape_string($connect, $_POST['address']);
	$footer=mysqli_real_escape_string($connect, $_POST['footer']);
	$currency=mysqli_real_escape_string($connect, $_POST['currency']);


	$getusers = mysqli_query($connect,"SELECT * FROM users WHERE id_session='$key'");
	$u	      = mysqli_fetch_array($getusers);
	$jumlah   = mysqli_num_rows($getusers);
	
	$masterakun = mysqli_query($connect,"SELECT * FROM users WHERE phone_number='$u[master]'");
	$m=mysqli_fetch_array($masterakun);


	if ($jumlah > 0){
		
		
	$datatoko = mysqli_query($connect,"SELECT number_store FROM store WHERE user='$m[phone_number]'");
	$dt=mysqli_fetch_array($datatoko);
	


	mysqli_query($connect,"INSERT INTO store(name_store,
								  number_store,
								  email,
								  nohp,
								  address,
								  tax,
								  currency,
								  footer,
								  service_charge,
								  type,
								  user) 
						VALUES('$nama_toko',
							   '$dt[number_store]',
							   '$email',
							   '$nohp',
							   '$alamat',
							   '$pajak',
							   '$currency',
							   '$footer',
							   '$service_charge',
							   'branch',
							   '$m[phone_number]')");



	
	
	$json = array(
    'status' 	=> 'true',
    'errCode' 	=> '01',
	'msg' 		=> 'Success'
	);

    echo json_encode($json);

	}else{
	
	
	$json = array(
    'status' 	=> 'true',
    'errCode' 	=> '00',
	'msg' 		=> 'User Not Found'
   );

    echo json_encode($json);	
	}
	?>