}
}
$rate = array();
if ($ratesid && !$resid) {
    get_ratebyratesid($ratesid, $rate);
}
if ($roomid && !$roomtypeid && !$ratesid && !$resid) {
    get_ratebyratesid(get_RateID_byRoomID($roomid), $rate);
}
if ($roomtypeid && !$ratesid && !$resid) {
    get_ratebyratesid(get_RateID_byRoomTypeID($roomtypeid), $rate);
}
if ($resid) {
    $details = array();
    $total = 0;
    reservation_details_byResID($resid, $details);
    foreach ($details as $resdetail) {
        $rate = array();
        $rate_id = $resdetail['ratesid'];
        get_ratebyratesid($rate_id, $rate);
        $total = $total + $rate['price'];
    }
} else {
    $total = $rate['price'];
}
if ($guestid > 0) {
    $guest = array();
    findguestbyid($guestid, $guest);
    $guestname = $guest['guest'];
}
//get the last index of the address for the profile
    $reservation['checkindate'] = $today . " " . CHECKIN;
}
if (!$reservation['checkoutdate']) {
    $reservation['checkoutdate'] = $tomorrow . " " . CHECKOUT;
}
if (!$reservation['no_nights']) {
    $reservation['no_nights'] = 1;
}
if (!$reservation['status']) {
    $reservation['status'] = RES_QUOTE;
}
if ($reservation['status'] == RES_QUOTE && $reservation['confirmed_by']) {
    $reservation['status'] = RES_ACTIVE;
}
// Get what room types are reserved
$resdetailcount = reservation_details_byResID($resid, $details);
$notcheckedincount = 0;
// Count the number of checkings
foreach ($details as $idx => $value) {
    if ($details[$idx]['status'] != RES_CHECKIN) {
        $notcheckedincount++;
    }
}
// Calculate the remainder after the checkin
$remcheckin = 0;
if ($notcheckedincount > 0) {
    $remcheckin = $notcheckedincount - 1;
}
if ($reservation['agentid'] && $reservation['reservation_id']) {
    get_agent_bookingref($reservation['reservation_id'], $reservation['agentid'], $bookref, $bookrefid);
}