<?php
require_once ("varables.php");

$myJSON['factures'] = array();
$myJSON['success']="کمبود منابع...!";

if(isset($_POST["nekot"]) && isset($_POST["an1d"]) 
	&& isset($_POST["typ3"]) && isset($_POST["az"]) 
	&& isset($_POST["ta"]) && isset($_POST["CID"]))
{
	
    $type = "F";
	$C_CODE = $_POST["CID"];
	
	
    $connect = @mysqli_connect($hostname,$username,$password,$database);
    if($connect)
    {
        @mysqli_query($connect,"SET CHARACTER SET utf8mb4;");
			$query_all = "SELECT ".$tbl_factor.".Fac_Date,".$tbl_factor.".Fac_Time,".$tbl_factor.".DateUser,".$tbl_factor.".TimeUser,".$tbl_factor.".Porsant,".$tbl_factor.".Sum_Price,".$tbl_factor.".Fac_Code,".$tbl_factor.".Fac_Code_C,".$tbl_factor.".Takhfif, ".$tbl_customer.".C_Name, ".$tbl_customer.".C_Code,".$tbl_customer.".C_acc FROM ".$tbl_factor.", ".$tbl_customer." WHERE ".$tbl_factor.".C_Code = ".$tbl_customer.".C_id AND ".$tbl_factor.".C_Code = '".$C_CODE."'  AND ".$tbl_factor.".Fac_Type = 'F' ORDER BY ".$tbl_factor.".Fac_Date DESC,".$tbl_factor.".Fac_Code_C DESC LIMIT 5";
			$allres = @mysqli_query($connect,$query_all);
			if($allres){
			 while($row = @mysqli_fetch_assoc($allres))
				array_push($myJSON["factures"], $row);
				
				$myJSON['success']="200";

			}
			else{
				$myJSON['success']=@mysqli_error($connect);
			}
		
	}
	 else
		 $myJSON['success']="خطای ارتباط با پایگاه داده...!";
}
echo json_encode($myJSON);
?>