<?php
$roompricetotalusd = 0;
//nuevo query de precio con fechas
function newdate($date)
{
    list($m, $d, $a) = explode("/", $date);
    return $a . "-" . $m . "-" . $d;
}
function backdate($date)
{
    list($a, $m, $d) = explode("-", $date);
    return $m . "/" . $d . "/" . $a;
}
//Updating the availability of each room
$fiava = strtotime($checkin);
$diava = date('d', $fiava);
$miava = date('m', $fiava);
$yiava = date('Y', $fiava);
$foava = strtotime($checkout);
$doava = date('d', $foava);
$moava = date('m', $foava);
$yoava = date('Y', $foava);
$intday_ava = daysDifference($checkout, $checkin);
$preciocompleto = array();
$preciohabitacionescompleto = array();
$subtotalhabitacion = array();
$roompricetotalusd = 0;
for($kki=0;$kki<$rooms;$kki++) {
//obtenemos el precio base para todos los dias
$totalpersonsroom = $adults[$kki];
$generalprice = mysqli_query($conn, "SELECT room_price FROM hotel_room_price WHERE room_type_id = '$roomcode' AND room_person = '$totalpersonsroom' AND price_status = 'Y' LIMIT 1");
$generalpriceData = mysqli_fetch_array($generalprice);
$actualroomprice = $generalpriceData['room_price'];
//agregar el precio al array de fechas
$preciocompleto = array();
$fechaavainicial = newdate($checkin);
$preciosubtotal = 0;
	for ( $interva = 1 ; $interva <= $intday_ava ; $interva ++)      
    {
		$undia = $interva;
		$fechaavasiguiente = mktime(0,0,0, $miava,$diava,$yiava) + $undia * 24 * 60 * 60;
		$fechaavasalida=date("Y-m-d",$fechaavasiguiente);
		//reordenando fecha diaria
		$fechadeldia = backdate($fechaavainicial);
		//calculo del seasonal price por cada dia
		$veriday = mysqli_query($conn, "SELECT seasonal_price FROM hotel_seasonal_price WHERE seasonal_from = '$fechaavainicial' AND seasonal_to = '$fechaavasalida' AND room_type_id = '$roomcode' AND room_person = '$totalpersonsroom' AND seasonal_price_deleted = '0' ");
     	$totalveriday= mysqli_num_rows($veriday);
		$veridayData = mysqli_fetch_array($veriday);	 	
		if ($totalveriday > 0){
			$actualroomprice  = $veridayData['seasonal_price'];
		}
		$preciocompletotemporal = array(    
		 'date_price' => $fechadeldia,
		 'room_price' => $actualroomprice
		 );
		array_push($preciocompleto, $preciocompletotemporal);		
		$fechaavainicial = $fechaavasalida;
		$preciosubtotal = $preciosubtotal + $actualroomprice;
		$actualroomprice = $generalpriceData['room_price'];
	}
	//agregando subtotal
	$subtotaltemporal = array(    
		 'subtotal' => $preciosubtotal
	);
	array_push($subtotalhabitacion, $subtotaltemporal);
	$roompricetotalusd = $roompricetotalusd + $preciosubtotal;
	//print_r($preciocompleto);
	//echo '<br>';
	array_push($preciohabitacionescompleto, $preciocompleto);
	unset($preciocompleto);
	
}
//GRAND TOTAL
$taxfeeusd = $roompricetotalusd*$hotel_tax/100;
$roompricetaxusd = number_format($taxfeeusd, 2, '.', '');
$hotelroomwithfee = $roompricetotalusd+$roompricetaxusd;
//NEW CURRENCY
$roompricetotal = $roompricetotalusd*$finaltotal;//new currency
$roompricetax = $roompricetaxusd*$finaltotal;
$hotelroomfinalprice = $hotelroomwithfee*$finaltotal;//new currency
//print_r($subtotalhabitacion);
?>