0) { if(array_key_exists('Order', $arr[0])) { return $arr[0]['Order']; } } return 0; } FUNCTION CalcForAllHotels($hotelIDs,$fromDate,$toDate,$conn,$selected_tickets,$selected_tours,$selected_trans,$mid,$mealName,$toomType,$roomView) { // $mealName = "SAI"; // $toomType = "STD"; //$roomView = "GV"; if($hotelIDs==null) return; $data = Array(); foreach($hotelIDs as $hotelID) { $data1 = Array(); $data1[] = CalcForHotel($hotelID,$fromDate,$toDate,$conn,$selected_tickets,$selected_tours,$selected_trans,$mid,$mealName,$toomType,$roomView); $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; //print_r($data); //usort($data,"orderSort"); //echo "---After Sort---"; //print_r($data); return $data; } function orderSort($item1,$item2) { if ($item1['Order'] == $item2['Order']) return 0; return ($item1['Order'] < $item2['Order']) ? 1 : -1; } FUNCTION getTicketData($selected_tickets,$conn) { $sql = "SELECT additional_price,child_price,intant_price FROM Tickets where ticket_id=" . $selected_tickets; $result = mysql_query($sql,$conn); $rows = array(); while(($row = mysql_fetch_array($result))) { $rows[] = $row; } return $rows; } FUNCTION getTourData($selected_tours,$conn) { $sql = "SELECT additional_price FROM Tours where tour_id=" . $selected_tours; $result = mysql_query($sql,$conn); $rows = array(); while(($row = mysql_fetch_array($result))) { $rows[] = $row; } return $rows; } FUNCTION getTransData($selected_trans,$conn) { $sql = "SELECT additional_price FROM Transportations where transportation_id=" . $selected_trans; $result = mysql_query($sql,$conn); $rows = array(); while(($row = mysql_fetch_array($result))) { $rows[] = $row; } return $rows; } FUNCTION aLength($var) { $counter = 0; if($var==0) { return 0; } foreach($var AS $value) { $counter++; } return $counter; } FUNCTION CalcForHotel($hotelID,$fromDate,$toDate,$conn,$selected_tickets,$selected_tours,$selected_trans,$mid,$mealName,$toomType,$roomView) { $roomData = getHotelRoomData($hotelID,$fromDate,$toDate,$conn,$mealName,$toomType,$roomView); //$mid = 36; $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 $totalDays = 0; 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'] * $room['Count']; $newRoom['intant'] = $room['intant'] * $room['Count']; //$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'] == "5DLX") $colName = "starts3DLX"; $Margion = $MargionsData[0][$colName]; $MargionType = $MargionsData[0][$type]; 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 { $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'] * $room['Count']; $newRoom['intant'] = $room['intant'] * $room['Count']; 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'] == "5DLX") $colName = "starts3DLX"; $Margion = $MargionsData[0][$colName]; $MargionType = $MargionsData[0][$type]; 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; $newRoom['child_2_5_without_bed'] = $newRoom['child_2_5_without_bed'] + $childPrice; $newRoom['intant'] = $newRoom['intant'] + $intantPrice; } else { $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; $newRoom['child_2_5_without_bed'] = $newRoom['child_2_5_without_bed'] + $childPrice; $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 30; elseif($rating=="5") return 29; elseif($rating=="4DLX") return 31; elseif($rating=="4") return 32; elseif($rating=="3DLX") return 34; elseif($rating=="3") return 33; } 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 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; } 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,$mealName,$toomType,$roomView) { $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 + rv.additional_price 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.5,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 gm.meal_name = '" . $mealName . "' and grt.type = '" . $toomType . "' and grv.room_view_name = '" . $roomView . "' 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 getMargin($mid,$conn) { $sql = " select margin_name,type,starts3,starts3DLX,starts4,starts4DLX,starts5,starts5DLX from Margins where margin_id = '$mid' "; $result = mysql_query($sql,$conn); $rows = array(); while(($row = mysql_fetch_array($result))) { $rows[] = $row; } return $rows; } ?> FB View
Select Customer


Select Destination
 
Select Tickets
 
Select Margin
 
Select Hotel Rating
 
Select Hotel Name
Select Room Type
 
Select Room View
 
Select Meal
 
Select Tours
 
Select Transportation
 
Going
 
Return
 
Airport Tax
 

No. of Single Rooms    

No. of Double Rooms       # Persons   

Child 6-12 with Bed       Childs 2-5 Without Bed       Intants   



and ending bu need to be looped depend on results values if($FinalData == null) return; foreach($FinalData as $Hotel) { foreach($Hotel as $row) { $hotel_name =$row['hotel_name']; $hotel_name_ar =$row['hotel_name_ar']; $hotel_rating=$row['rating']; $hotel_meal=$row['meal_name']; $hotel_location=$row['area_name']; $hotel_location_en=$row['area_name_en']; $room_view=$row['room_view_name']; $room_type=$row['type']; $website=$row['website']; $map=$row['map']; $double_price=round($row['Double']/5) * 5; $single_price=round($row['Single']/5) * 5; $child_2_12_price=round($row['child_2_12_with_bed']/5) * 5; $child_2_5_without_bed=round($row['child_2_5_without_bed']/5) * 5; $intant=round($row['intant']/5) * 5; ?>

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


Child Price 2-5 without bed in JD: ". $child_2_5_without_bed."

Intant price in JD :".$intant." "; ?>


Going    ::
Return ::