	<?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']);
	$id=mysqli_real_escape_string($connect, $_POST['id']);
	$cash_actual=mysqli_real_escape_string($connect, $_POST['cash_actual']);
	
	$todays	= gmdate("Y-m-d H:i:s", time()+60*60*7);
	
	$today		= gmdate("Y-m-d 00:00:00", time()+60*60*7);
	$endtoday	= gmdate("Y-m-d 23:59:00", time()+60*60*7);
	


	$getusers = mysqli_query($connect,"SELECT * FROM users WHERE id_session='$key'");
	$u	      = mysqli_fetch_array($getusers);
	$count   = mysqli_num_rows($getusers);

	if ($count > 0){	
	$query = "SELECT * FROM intial WHERE cashier_id='$u[phone_number]' AND create_at>='$today' AND create_at<='$endtoday'";
	$hasil = mysqli_query($connect,$query);
	$i=mysqli_fetch_array($hasil);
	
	$cash_actuals= $cash_actual-$i['cash_awal'];
	 
	 mysqli_query($connect,"UPDATE intial SET flag		= 'S',
											   update_at = '$todays',
											   cash_actual = '$cash_actuals'
								WHERE id 	 = '$id'");
								
	 mysqli_query($connect,"UPDATE users SET initial = 'S' WHERE phone_number = '$u[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);	
	}
	?>