0) { if(array_key_exists('Order', $arr[0])) { return $arr[0]['Order']; } } return 0; } FUNCTION CalcForAllHotels($hotelIDs,$fromDate,$toDate,$conn) { if($hotelIDs==null) return; $data = Array(); foreach($hotelIDs as $hotelID) { $data1 = Array(); $data1[] = CalcForHotel($hotelID,$fromDate,$toDate,$conn); $data1['Order'] = getOrder($data1[0]); $data[] = $data1; } $data1 = Array(); $order = Array(); foreach ($data as $key => $row) { $order[$key] = $row['Order']; } array_multisort($order, SORT_ASC, $data); $newData = Array(); foreach($data as $key => $row) { $newData[] = $row[0]; } $data = $newData; return $data; } FUNCTION CalcForHotel($hotelID,$fromDate,$toDate,$conn) { $roomData = getHotelRoomData($hotelID,$fromDate,$toDate,$conn); //$mid = 36; $totalDays = (strtotime($toDate . ' 12:00') - strtotime($fromDate . ' 12:00') )/86400; $minTotal = 1000000; $additions = 0; $ticketPrice = 0; $chiledPrice = 0; /* if($selected_tickets!=null) { $ticketData = getTicketData($selected_tickets,$conn); //$additions = $additions + $ticketData[0][0]; $ticketPrice = $ticketData[0][0]; $childPrice = $ticketData[0]['child_price']; $intantPrice = $ticketData[0]['intant_price']; } if($selected_tours!=null) { $tourData = getTourData($selected_tours,$conn); $additions = $additions + $tourData[0][0]; } if($selected_trans!=null) { $transData = getTransData($selected_trans,$conn); $additions = $additions + $transData[0][0]; } */ //echo "additions="; //echo $additions; //return 0; /* $Margions = getMargions($conn); $MargionsData = getMargin($mid,$conn); */ $newRoomData = Array(); $zeroOutput = false; $startTime = strtotime($fromDate . ' 12:00'); $endTime = strtotime($toDate . ' 12:00'); //$endTime = strtotime('-1 day',$toDate . ' 12:00'); $endTime = strtotime($toDate . ' 12:00') - 86400; $nDays = 0; // Loop between timestamps, 24 hours at a time for ($i = $startTime; $i <= $endTime; $i = $i + 86400) { $thisDate = date('Y-m-d', $i); // 2010-05-01, 2010-05-02, etc $found = false; //echo "This Date" . $thisDate; $nDays++; foreach($roomData as &$room ) { if($thisDate <= $room['end_date'] && $thisDate >= $room['start_date']) { $room['Count']++; $found = true; } } if(!$found) { $zeroOutput = true; } } $colName = null; if($nDays>0 && $nDays<=3) $colName = 3;// "1_3_margin"; elseif($nDays>=4 && $nDays<=6) $colName = 4;// "4_6_margin"; elseif($nDays>=7 && $nDays<=10) $colName = 5;//"7_10_margin"; elseif($nDays>10) $colName = 6;//"10_more_margin"; //------------------------------------------------------------------------------- $newRoomData = $roomData; $uniqueHids = getUniqueCombination("hotel_id",$newRoomData); //$uniqueRTids = getUniqueCombination("general_room_type_id",$newRoomData); $uniqueRVids = getUniqueCombination("general_room_view_id",$newRoomData); $uniqueMids = getUniqueCombination("general_meal_id",$newRoomData); $uniqueRoomTypes = getUniqueRoomTypes($conn); $newRoomData2 = Array(); foreach($uniqueHids as $h ) { //foreach($uniqueRTids as $rt ) //{ foreach($uniqueRVids as $rv ) { foreach($uniqueMids as $m ) { foreach($uniqueRoomTypes as $roomType ) { $newRoom = Array(); $newRoom['hotel_id'] = $h; //$newRoom['general_room_type_id'] = $rt; $newRoom['general_room_view_id'] = $rv; $newRoom['general_meal_id'] = $m; $newRoom['type'] = $roomType['type']; $in = 0; $fixedMargionAddedInSingle = false; $fixedMargionAddedInDouble = false; foreach($newRoomData as &$room ) { if(($room['hotel_id'] == $h) AND ($room['general_room_view_id'] == $rv) AND ($room['general_meal_id'] == $m) AND ($room['type'] == $roomType['type']) AND $room['number_of_people'] == 1) { $in = 1; $newRoom['hotel_name'] = $room['hotel_name']; $newRoom['hotel_name_ar'] = $room['hotel_name_ar']; $newRoom['rating'] = $room['rating']; $newRoom['meal_name'] = $room['meal_name']; $newRoom['area_name'] = $room['area_name']; $newRoom['area_name_en'] = $room['area_name_en']; $newRoom['website'] = $room['website']; $newRoom['room_view_name'] = $room['room_view_name']; $newRoom['child_2_5_without_bed'] = $room['child_2_5_without_bed'] * $totalDays; //alaa //echo " ChildRoom:" . $room['child_2_5_without_bed']; //echo " RoomCount:" . $totalDays; //echo " childPrice:" . $childPrice; $newRoom['intant'] = $room['intant'] * $totalDays; //$Margion = getMargionFromMargions($Margions,$nDays,$colName,$newRoom['rating']); //$MargionType = getMargionTypeFromMargions($Margions,$nDays,$colName,$newRoom['rating']); if($newRoom['rating'] == "5") $colName = "starts5"; elseif($newRoom['rating'] == "5DLX") $colName = "starts5DLX"; elseif($newRoom['rating'] == "4") $colName = "starts4"; elseif($newRoom['rating'] == "4DLX") $colName = "starts4DLX"; elseif($newRoom['rating'] == "3") $colName = "starts3"; elseif($newRoom['rating'] == "3DLX") $colName = "starts3DLX"; $Margion = 0; $MargionType = "FIXED"; if($room['number_of_people'] == 1 )//'Single' { if(strtoupper($MargionType)=="PERCENT") { $locTotal = $room['Total'] * $room['Count']; $locTotal = $locTotal + ($locTotal * $Margion/100); $newRoom['Single'] = $newRoom['Single'] + $locTotal; } else { //echo "Single:"; //echo "Room Total:" . $room['Total']; //echo "Margion:" . $Margion; //echo "Room Count:" . $room['Count']; $locTotal = $room['Total'] * $room['Count']; if(!$fixedMargionAddedInSingle) { $locTotal = $locTotal + ($Margion * 2); } $newRoom['Single'] = $newRoom['Single'] + $locTotal ; $fixedMargionAddedInSingle = true; } } } } foreach($newRoomData as &$room ) { if(($room['hotel_id'] == $h) AND ($room['general_room_view_id'] == $rv) AND ($room['general_meal_id'] == $m) AND ($room['type'] == $roomType['type']) AND $room['number_of_people'] == 2) { $in = 1; $newRoom['hotel_name'] = $room['hotel_name']; $newRoom['hotel_name_ar'] = $room['hotel_name_ar']; $newRoom['rating'] = $room['rating']; $newRoom['meal_name'] = $room['meal_name']; $newRoom['area_name'] = $room['area_name']; $newRoom['area_name_en'] = $room['area_name_en']; $newRoom['website'] = $room['website']; $newRoom['room_view_name'] = $room['room_view_name']; $newRoom['map'] = $room['map']; $newRoom['child_2_5_without_bed'] = $room['child_2_5_without_bed'] * $totalDays; $newRoom['intant'] = $room['intant'] * $totalDays; if($newRoom['rating'] == "5") $colName = "starts5"; elseif($newRoom['rating'] == "5DLX") $colName = "starts5DLX"; elseif($newRoom['rating'] == "4") $colName = "starts4"; elseif($newRoom['rating'] == "4DLX") $colName = "starts4DLX"; elseif($newRoom['rating'] == "3") $colName = "starts3"; elseif($newRoom['rating'] == "3DLX") $colName = "starts3DLX"; $Margion = 0; $MargionType = "FIXED"; if ($room['number_of_people'] == 2 ) //Double { if(strtoupper($MargionType)=="PERCENT") { $locTotal = $room['Total'] * $room['Count']; $locTotal = $locTotal + ($locTotal * $Margion/100); $newRoom['Double'] = $newRoom['Double'] + $locTotal; $locTotal = $room['child_2_12_with_bed'] * $room['Count']; $locTotal = $locTotal + ($locTotal * $Margion/100); $newRoom['child_2_12_with_bed'] = $newRoom['child_2_12_with_bed'] + $locTotal; } else { $locTotal = $room['Total'] * $room['Count']; if(!$fixedMargionAddedInDouble) { $locTotal = $locTotal + $Margion; } $newRoom['Double'] = $newRoom['Double'] + $locTotal ; $locTotal = $room['child_2_12_with_bed'] * $room['Count']; if(!$fixedMargionAddedInDouble) { $locTotal = $locTotal + $Margion/2; } $newRoom['child_2_12_with_bed'] = $newRoom['child_2_12_with_bed'] + $locTotal ; $fixedMargionAddedInDouble = true; } } } } if($in==1) { if(!$zeroOutput) { if(strtoupper($MargionType)=="PERCENT") { $additions2 = $additions + ($additions * $Margion/100); $ticketPrice2 = $ticketPrice + ($ticketPrice * $Margion/100); $childPrice2 = $childPrice + ($childPrice * $Margion/100); $newRoom['Single'] = $newRoom['Single'] + $additions2 + $ticketPrice2; $newRoom['Double'] = $newRoom['Double'] + $additions2 + $ticketPrice2; $newRoom['child_2_12_with_bed'] = $newRoom['child_2_12_with_bed'] + $additions2 + $childPrice2; if($childPrice=="0") { $newRoom['child_2_5_without_bed'] = 0; } else { $newRoom['child_2_5_without_bed'] = $newRoom['child_2_5_without_bed'] + $childPrice; } if($intantPrice=="0") { $newRoom['intant'] = 0; } else { $newRoom['intant'] = $newRoom['intant'] + $intantPrice; } } else { //echo "Additions:" . $additions; //echo "TicketPrice:" . $ticketPrice; $newRoom['Single'] = $newRoom['Single'] + $additions + $ticketPrice; $newRoom['Double'] = $newRoom['Double'] + $additions + $ticketPrice; $newRoom['child_2_12_with_bed'] = $newRoom['child_2_12_with_bed'] + $additions + $childPrice; if($childPrice==0) { $newRoom['child_2_5_without_bed'] = 0; } else { $newRoom['child_2_5_without_bed'] = $newRoom['child_2_5_without_bed'] + $childPrice; } if($intantPrice=="0") { $newRoom['intant'] = 0; } else { $newRoom['intant'] = $newRoom['intant'] + $intantPrice; } } } else { $newRoom['Single']=0; $newRoom['Double']=0; $newRoom['Triple']=0; $newRoom['child_2_12_with_bed']=0; $newRoom['child_2_5_without_bed'] = 0; $newRoom['intant'] = 0; } if($newRoom['Double'] < $minTotal) { $minTotal = $newRoom['Double']; } $newRoomData2[] = $newRoom; } } } } //} } //echo "-------------------------------------------------------------------------------------------------------------------"; //print_r($newRoomData2); $newRoomData3 = Array(); foreach($newRoomData2 as &$room3 ) { $newRoom = Array(); $newRoom = $room3; $newRoom['Order'] = $minTotal; $newRoomData3[] = $newRoom; } //echo "-------------------------------------------------------------------------------------------------------------------"; //print_r($newRoomData2); //echo "=================="; //print_r($newRoomData3); //echo "-------------------------------------------------------------------------------------------------------------------"; return $newRoomData3; } FUNCTION getRatingNum($rating) { if($rating=="5DLX") return 36; elseif($rating=="5") return 35; elseif($rating=="4DLX") return 38; elseif($rating=="4") return 37; elseif($rating=="3DLX") return 40; elseif($rating=="3") return 39; } FUNCTION getMargionFromMargions($Margions,$nDays,$colName,$rating) { $rating = getRatingNum($rating); foreach($Margions as $margionRow) { if($margionRow['id'] == $rating) { return $margionRow[$colName]; } } } FUNCTION getMargionTypeFromMargions($Margions,$nDays,$colName,$rating) { $rating = getRatingNum($rating); foreach($Margions as $margionRow) { if($margionRow['id'] == $rating) { return $margionRow['margin_type']; } } } FUNCTION getUniqueCombination($val,$newRoomData) { $hids = array(); foreach ($newRoomData as $x) { $hids[] = $x[$val]; } $uniqueHids = array_unique($hids); return $uniqueHids; } FUNCTION getHotelRoomData($hotelID,$fromDate,$toDate,$conn) { $sql = "SELECT h.hotel_id, h.hotel_name, h.website, h.map, h.hotel_name_ar, h.rating, gm.general_meal_id, gm.meal_name, h.area_name, h.area_name_en, grv.general_room_view_id, grv.room_view_name, grt.general_room_type_id, grt.number_of_people, grt.room_type_name, grt.type, if(hp.spatial_price>0,hp.spatial_price,hp.base_price) + m.additional_price * if(number_of_people=1,2,1) + rv.additional_price * 1.5 as 'Total', if(number_of_people=2,if(hp.spatial_price>0,hp.spatial_price,hp.base_price) /2 + rv.additional_price * 1.5 + m.additional_price * 1,0) as 'child_2_12_with_bed', 5 as 'child_2_5_without_bed', 5 as 'intant', hp.start_date, hp.end_date, 0 as 'Count' FROM Hotels h, Meals m, General_Meals gm, General_Room_Views grv, General_Room_Types grt, Room_Type rt, Room_View rv, Hotel_Prices hp WHERE h.hotel_id = ". $hotelID ." and m.hotel_id_f = ". $hotelID ." and gm.general_meal_id = m.general_meal_id_f and rt.hotel_id_f = ". $hotelID ." and rv.room_type_id_f = rt.room_type_id and grt.general_room_type_id = rt.general_room_type_id_f and grv.general_room_view_id = rv.general_room_view_id_f and hp.room_type_id_f = rt.room_type_id and (hp.end_date >= '" . $fromDate . "' AND " . " hp.start_date <= '". $toDate . "') "; //echo $sql; $result = mysql_query($sql,$conn); $rows = array(); while(($row = mysql_fetch_array($result))) { $rows[] = $row; } return $rows; } FUNCTION getMargions($conn) { $sql = "SELECT * from setting"; $result = mysql_query($sql,$conn); $rows = array(); while(($row = mysql_fetch_array($result))) { $rows[] = $row; } return $rows; } FUNCTION getUniqueRoomTypes($conn) { $sql = "SELECT DISTINCT type FROM General_Room_Types"; $result = mysql_query($sql,$conn); $rows = array(); while(($row = mysql_fetch_array($result))) { $rows[] = $row; } return $rows; } ?> FB View
Select Destination
 
Select Hotel Rating
 
Select Hotel Name
From Date
 
To Date
 

Report Template "; } ?>
Hotel Name Rating Meals Location Room View Room Type Double/Triple Single Child 2-12 with Bed