<?php
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
header("Access-Control-Allow-Methods: POST");

include_once '../config/database.php';
include_once '../objects/installation.php';
include_once '../objects/installation_detail.php';
// session_start();
 
$database = new Database();
$db = $database->getConnection();

$installation = new Installation($db);
$installation_detail = new InstallationDetail($db);
$data = json_decode(file_get_contents("php://input"));

$installation->id = $data->id;
$installation->getOneRow();

$s_details = array();
$installation_detail->installation_id = $data->id;
$stmt = $installation_detail->getInstallationDetail();
$num = $stmt->rowCount();
if($num>0){
    while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){
        extract($row);
		$s_detail=array(
            "id" => $id,
            "item_code" => $item_code,
			"item_name" => $item_name,
            "quantity" => $quantity,		
            "unit" => $unit
        );
        array_push($s_details, $s_detail);
    }
}

$sales = array(
    "id" => (int)$installation->id,
	"install_date" => $installation->install_date,
	"install_address" => $installation->install_address,
    "geolocation" => $installation->geolocation,
	"dn" => $installation->dn,
	"sn" => $installation->sn,
    "technician1" => $installation->technician1,
    "technician2" => $installation->technician2,
	"technician3" => $installation->technician3,
    "remark" => $installation->remark,
	"s_details" => $s_details
);
echo json_encode($sales);

?>