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

	require_once("../connection.php");
	$content 	= trim(file_get_contents("php://input"));
	$decoded 	= json_decode($content, true);
	
	$id_customer=mysqli_real_escape_string($connect, $_POST['id_customer']);
	$id_store=mysqli_real_escape_string($connect, $_POST['id_store']);
	$date=mysqli_real_escape_string($connect, $_POST['date']);
	$due_date=mysqli_real_escape_string($connect, $_POST['due_date']);
	$no_invoice=mysqli_real_escape_string($connect, $_POST['no_invoice']);
	$payment=mysqli_real_escape_string($connect, $_POST['payment']);
	$totalorder=mysqli_real_escape_string($connect, $_POST['totalorder']);
	$totalprice=mysqli_real_escape_string($connect, $_POST['totalprice']);
	$changepay=mysqli_real_escape_string($connect, $_POST['changepay']);
	$totalpay=mysqli_real_escape_string($connect, $_POST['totalpay']);
	$status=mysqli_real_escape_string($connect, $_POST['status']);
	$user=mysqli_real_escape_string($connect, $_POST['user']);
	$service_charge=mysqli_real_escape_string($connect, $_POST['service_charge']);
	$tax=mysqli_real_escape_string($connect, $_POST['tax']);
	$discount=mysqli_real_escape_string($connect, $_POST['discount']);
	$location=mysqli_real_escape_string($connect, $_POST['location']);
	$note=mysqli_real_escape_string($connect, $_POST['note']);
	

	$getusers	= mysqli_query($connect,"SELECT * FROM users WHERE phone_number='$user'");
	$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){

	mysqli_query($connect,"INSERT INTO sales_data(id_customer,
								  no_invoice,
								  date,
								  id_store,
								  payment,
								  totalorder,
								  totalpay,
								  totalprice,
								  changepay,
								  status,
								  due_date,
								  note,
								  operator,
								  tax,
								  discount,
								  service_charge,
								  location,
                                  user) 
                    VALUES('$id_customer',
						   '$no_invoice',
						   '$date',
						   '$id_store',
						   '$payment',
						   '$totalorder',
						   '$totalpay',
						   '$totalprice',
						   '$changepay',
						   '$status',
						   '$due_date',
						   '$note',
						   '$u[phone_number]',
						   '$tax',
						   '$discount',
						   '$service_charge',
						   '$location',
                           '$m[phone_number]')");
						   
					
	

	
  

	$responses = array(
    'status' 	=> 'true',
    'errCode' 	=> '01',
	'msg' 		=> 'success'
	);
   

	echo json_encode($responses);


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

    echo json_encode($json);	
	}
	?>