<?php

if(isset($_POST["carid"]))
{
	// include "dbPDO.php";
	require_once "./../magic/DataBase.php";
	$dataBase = new DataBase();
	$conn = $dataBase->getConnection();

	$dd = $_POST["carid"];
	$output = array();
	$sql = $conn->prepare("SELECT * FROM cars WHERE carid = ? LIMIT 1");
	$sql->bindParam(1,$dd);
	$sql->execute();
  if($sql->rowCount()>0){$row = $sql->fetch();
		$output["carid"]   		= $row["carid"];
		$output["brand"]    	= $row["brand"];
    	$output["kind"]     	= $row["kind"];
		$output["model"]    	= $row["model"];
    	$output["kind_use"]		= $row["kind_use"];
		$output["color"]    	= $row["color"];
    	$output["letters"]  	= $row["letters"];
		$output["numbers"]   	= $row["numbers"];
		$output["skilton"]   	= $row["skilton"];
    	$output["lic_expire"] 	= $row["lic_expire"];
		$output["costday"]   	= $row["costday"];
		$output["monthly"]   	= $row["monthly"];
		$output["minn"]     	= $row["minn"];
    	$output["km1"]     		= $row["km1"];
		$output["km2"]      	= $row["km2"];
    	$output["km3"]     		= $row["km3"];
		$output["freekilo"]   	= $row["freekilo"];
    	$output["carstatus"]  	= $row["carstatus"];
		$output["target"]  		= $row["target"];
		$output["month_cost"]  	= $row["month_cost"];



		$output["car_job_id"]   	= $row["car_job_id"];
		$output["insurance_id"]   	= $row["insurance_id"];
		$output["insurance_no"]   	= $row["insurance_no"];
		$output["insurance_kind"]   = $row["insurance_kind"];
		$output["insurance_money"]  = $row["insurance_money"];
		$output["insurance_expire"] = $row["insurance_expire"];
		$output["wesam_ins"]  		= $row["wesam_ins"];
		$output["open_kilo"] 		= $row["open_kilo"];
		$output["active_ins"]  		= $row["active_ins"];
		$output["active_kilo"] 		= $row["active_kilo"];

		$output["woner"]   			= $row["woner"];
		$output["cont_id"]   		= $row["cont_id"];
		$output["woner_permeation"]   = $row["woner_permeation"];
		$output["first_pay"]   		= $row["first_pay"];
		$output["kest"]   			= $row["kest"];
		$output["kest_qty"]   		= $row["kest_qty"];
		$output["last_pay"]   		= $row["last_pay"];
		$output["total_cost"]   	= $row["total_cost"];

		$output["lic_photo"]  		= $row["lic_photo"];
		$output["start"]   			= $row["start"];
		$output["date_sale"]   		= $row["date_sale"];
    $output["keywords"] 			= $row["keywords"];
		$output["used_percent"] 	= $row["used_percent"];
		$output["comm"] 			= $row["comm"];
		$output["branch"] 			= $row["branch"];
		$output["area"] 			= $row["area"];

		$km = $conn->prepare("SELECT km_in  from contracts where carid = ?
							AND date_in = (select max(date_in) from contracts where carid = ?)");
		$km->bindParam(1,$dd);
		$km->bindParam(2,$dd);
		$km->execute();
	  if($km->rowCount()>0){$kmm = $km->fetch();
  	$output["maxkm"]     		= $kmm["km_in"];
		}
   }
	echo json_encode($output);
}
?>
