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

	require_once("../connection.php");
	$name_spending=mysqli_real_escape_string($connect, $_POST['name_spending']);
	$user=mysqli_real_escape_string($connect, $_POST['user']);
	$no_invoice=mysqli_real_escape_string($connect, $_POST['no_invoice']);
	$nominal=mysqli_real_escape_string($connect, $_POST['nominal']);
	$date=mysqli_real_escape_string($connect, $_POST['date']);

	
	$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);

	mysqli_query($connect,"INSERT INTO spending(name_spending, user, no_invoice, nominal, date) 
                    VALUES('$name_spending', '$m[phone_number]', '$no_invoice', '$nominal', '$date')");
	
	$responses = array(
    'status' 	=> 'true',
    'errCode' 	=> '01',
	'msg' 		=> 'Success'
	);
   

	echo json_encode($responses);


	?>