public function load()
 {
     if (Request::ajax()) {
         $data = Request::all();
         $roomprice = Roommoney::find($data['data'])->toArray();
         if ($roomprice == null) {
             $data_out = 1;
             print_r($data_out);
             die;
         } else {
             $room_237 = Roomtime::mthod('KHUNGGIO7AM_23PM')->roomtype($data['data'])->get()->toArray();
             $room_pt = Roomtime::mthod('PHUTROI')->roomtype($data['data'])->get()->toArray();
             $roomprice['KHUNGGIO7AM_23PM'] = $room_237;
             $roomprice['PHUTROI'] = $room_pt;
             $data_out = json_encode($roomprice);
             print_r($data_out);
             die;
         }
     }
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Request $request)
 {
     $money_sg = 0;
     $money_tw = 0;
     $info_booking = $request->all();
     $arr_datein[] = array();
     $str = $info_booking['date_in'];
     $arr_datein = explode('/', $str);
     $day_in = $arr_datein[0];
     $m_in = $arr_datein[1];
     $y_in = $arr_datein[2];
     $arr_timein = explode(':', $info_booking['time_in']);
     $h_in = $arr_timein[0];
     $m_in = $arr_timein[1];
     $arr_timeout = explode(':', $info_booking['time_out']);
     $h_out = $arr_timeout[0];
     $m_out = $arr_timeout[1];
     $arr_dateout[] = array();
     $str2 = $info_booking['date_out'];
     $arr_dateout = explode('/', $str2);
     $day_out = $arr_dateout[0];
     $m_out = $arr_dateout[1];
     $y_out = $arr_dateout[2];
     $arrival_time = $y_in . '-' . $m_in . '-' . $day_in . ' ' . $info_booking['time_in'];
     $depart_time = $y_out . '-' . $m_out . '-' . $day_out . ' ' . $info_booking['time_out'];
     $in = new DateTime($arrival_time);
     $out = new DateTime($depart_time);
     $diff = $in->diff($out);
     $days = $diff->d;
     $hours = $diff->h;
     $minutes = $diff->i;
     $total_hours = $days * 24 + $hours;
     if ($info_booking['single'] > 0) {
         if ($info_booking['airport'] == 1) {
             $roomprice_sg = Roommoney::find(10)->toArray();
             $room_237_sg = Roomtime::mthod('KHUNGGIO7AM_23PM')->roomtype(10)->get()->toArray();
             $room_pt_sg = Roomtime::mthod('PHUTROI')->roomtype(10)->get()->toArray();
         } else {
             $roomprice_sg = Roommoney::find(12)->toArray();
             $room_237_sg = Roomtime::mthod('KHUNGGIO7AM_23PM')->roomtype(12)->get()->toArray();
             $room_pt_sg = Roomtime::mthod('PHUTROI')->roomtype(12)->get()->toArray();
         }
         if ($roomprice_sg['khunggiobatdau'] <= $h_in && $h_in < $roomprice_sg['khunggioketthuc']) {
             $kt_in = 1;
         } else {
             $kt_in = 2;
         }
         if ($roomprice_sg['khunggiobatdau'] <= $h_out && $h_out < $roomprice_sg['khunggioketthuc']) {
             $kt_out = 1;
         } else {
             $kt_out = 2;
         }
         $test_h = 60 - $m_in;
         if ($minutes < $roomprice_sg['moc1']) {
             $total_hours += $roomprice_sg['lamtron1'] / 60;
         } elseif ($roomprice_sg['moc1'] <= $minutes && $minutes <= $roomprice_sg['moc2']) {
             $total_hours += $roomprice_sg['lamtron2'] / 60;
         } else {
             $total_hours += $roomprice_sg['lamtron3'] / 60;
         }
         if ($roomprice_sg['tinhtheongaydem'] == 0) {
             if ($days < 1) {
                 $money_sg = $this->price_day($total_hours, $roomprice_sg, $room_237_sg);
             } else {
                 $full_price = $days * $roomprice_sg['gianguyenngay'];
                 $last_mn = $this->price_day($hours, $roomprice_sg, $room_237_sg);
                 $money_sg = $full_price + $last_mn;
             }
         } else {
             if ($days < 1) {
                 if ($kt_in == $kt_out) {
                     if ($kt_in == 1) {
                         if ($h_out > $h_in) {
                             $money_sg = $this->price_day($total_hours, $roomprice_sg, $room_237_sg);
                         } elseif ($h_out == $h_in) {
                             if ($m_in < $m_out) {
                                 $money_sg = $this->price_day($total_hours, $roomprice_sg, $room_237_sg);
                             } else {
                                 $money_sg = $roomprice_sg['gianguyenngay'];
                             }
                         } else {
                             if ($test_h > $roomprice_sg['moc2']) {
                                 $hours_day = $roomprice_sg['khunggioketthuc'] - $h_in - 1 + $roomprice_sg['lamtron3'] / 60;
                             }
                             if ($test_h < $roomprice_sg['moc2'] && $test_h >= $roomprice_sg['moc1']) {
                                 $hours_day = $roomprice_sg['khunggioketthuc'] - $h_in - 1 + $roomprice_sg['lamtron2'] / 60;
                             }
                             if ($test_h < $roomprice_sg['moc1']) {
                                 $hours_day = $roomprice_sg['khunggioketthuc'] - $h_in - 1 + $roomprice_sg['lamtron1'] / 60;
                             }
                             $money_sg = $this->price_day($hours_day, $roomprice_sg, $room_237_sg);
                             $money_sg += $roomprice_sg['giaquadem'];
                             if ($m_out < $roomprice_sg['moc1']) {
                                 $hours_day_2 = $h_out - $roomprice_sg['khunggiobatdau'] + $roomprice_sg['lamtron1'] / 60;
                             }
                             if ($m_out <= $roomprice_sg['moc2'] && $m_out >= $roomprice_sg['moc1']) {
                                 $hours_day_2 = $h_out - $roomprice_sg['khunggiobatdau'] + $roomprice_sg['lamtron2'] / 60;
                             }
                             if ($m_out > $roomprice_sg['moc2']) {
                                 $hours_day_2 = $h_out - $roomprice_sg['khunggiobatdau'] + $roomprice_sg['lamtron3'] / 60;
                             }
                             $money_sg += $this->price_day($hours_day_2, $roomprice_sg, $room_237_sg);
                         }
                     } else {
                         $kt_night = $roomprice_sg['khunggiobatdau'] + 24 - $roomprice_sg['khunggioketthuc'];
                         if ($total_hours <= $kt_night) {
                             $money_sg += $total_hours * $roomprice_sg['giatheogio'];
                         } else {
                             if ($h_in < $roomprice_sg['khunggiobatdau']) {
                                 if ($test_h > $roomprice_sg['moc2']) {
                                     $hours_night1 = $roomprice_sg['khunggiobatdau'] - $h_in - 1 + $roomprice_sg['lamtron3'] / 60;
                                 }
                                 if ($test_h < $roomprice_sg['moc2'] && $test_h >= $roomprice_sg['moc1']) {
                                     $hours_night1 = $roomprice_sg['khunggioketthuc'] - $h_in - 1 + $roomprice_sg['lamtron2'] / 60;
                                 }
                                 if ($test_h < $roomprice_sg['moc1']) {
                                     $hours_night1 = $roomprice_sg['khunggioketthuc'] - $h_in - 1 + $roomprice_sg['lamtron1'] / 60;
                                 }
                                 if ($hours_night1 > 3) {
                                     $money_sg += $roomprice_sg['giaquadem'];
                                 } else {
                                     $money_sg += $hours_night1 * $roomprice_sg['giatheogio'];
                                 }
                                 $money_sg += $roomprice_sg['gianguyenngay'];
                                 if ($h_out < $roomprice_sg['khunggiobatdau']) {
                                     if ($m_out > $roomprice_sg['moc2']) {
                                         $hours_night2 = $h_out + 24 - $roomprice_sg['khunggioketthuc'] + $roomprice_sg['lamtron3'] / 60;
                                     }
                                     if ($m_out < $roomprice_sg['moc2'] && $test_h >= $roomprice_sg['moc1']) {
                                         $hours_night2 = $h_out + 24 - $roomprice_sg['khunggioketthuc'] + $roomprice_sg['lamtron2'] / 60;
                                     }
                                     if ($m_out < $roomprice_sg['moc1']) {
                                         $hours_night2 = $h_out + 24 - $roomprice_sg['khunggioketthuc'] + $roomprice_sg['lamtron1'] / 60;
                                     }
                                     if ($hours_night2 > 3) {
                                         $money_sg += $roomprice_sg['giaquadem'];
                                     } else {
                                         $money_sg += $hours_night2 * $roomprice_sg['giatheogio'];
                                     }
                                 } else {
                                     if ($m_out > $roomprice_sg['moc2']) {
                                         $hours_night2 = $h_out - $roomprice_sg['khunggioketthuc'] + $roomprice_sg['lamtron3'] / 60;
                                     }
                                     if ($m_out < $roomprice_sg['moc2'] && $test_h >= $roomprice_sg['moc1']) {
                                         $hours_night2 = $h_out - $roomprice_sg['khunggioketthuc'] + $roomprice_sg['lamtron2'] / 60;
                                     }
                                     if ($m_out < $roomprice_sg['moc1']) {
                                         $hours_night2 = $h_out - $roomprice_sg['khunggioketthuc'] + $roomprice_sg['lamtron1'] / 60;
                                     }
                                     if ($hours_night2 > 3) {
                                         $money_sg += $roomprice_sg['giaquadem'];
                                     } else {
                                         $money_sg += $hours_night2 * $roomprice_sg['giatheogio'];
                                     }
                                 }
                             } else {
                                 if ($test_h > $roomprice_sg['moc2']) {
                                     $hours_night1 = $roomprice_sg['khunggiobatdau'] + 23 - $h_in + $roomprice_sg['lamtron3'] / 60;
                                 }
                                 if ($test_h < $roomprice_sg['moc2'] && $test_h >= $roomprice_sg['moc1']) {
                                     $hours_night1 = $roomprice_sg['khunggioketthuc'] + 23 - $h_in + $roomprice_sg['lamtron2'] / 60;
                                 }
                                 if ($test_h < $roomprice_sg['moc1']) {
                                     $hours_night1 = $roomprice_sg['khunggioketthuc'] + 23 - $h_in + $roomprice_sg['lamtron1'] / 60;
                                 }
                                 if ($hours_night1 > 3) {
                                     $money_sg += $roomprice_sg['giaquadem'];
                                 } else {
                                     $money_sg += $hours_night1 * $roomprice_sg['giatheogio'];
                                 }
                                 $money_sg += $roomprice_sg['gianguyenngay'];
                                 if ($m_out > $roomprice_sg['moc2']) {
                                     $hours_night2 = $h_out - $roomprice_sg['khunggioketthuc'] + $roomprice_sg['lamtron3'] / 60;
                                 }
                                 if ($m_out < $roomprice_sg['moc2'] && $test_h >= $roomprice_sg['moc1']) {
                                     $hours_night2 = $h_out - $roomprice_sg['khunggioketthuc'] + $roomprice_sg['lamtron2'] / 60;
                                 }
                                 if ($m_out < $roomprice_sg['moc1']) {
                                     $hours_night2 = $h_out - $roomprice_sg['khunggioketthuc'] + $roomprice_sg['lamtron1'] / 60;
                                 }
                                 if ($hours_night2 > 3) {
                                     $money_sg += $roomprice_sg['giaquadem'];
                                 } else {
                                     $money_sg += $hours_night2 * $roomprice_sg['giatheogio'];
                                 }
                             }
                         }
                     }
                 } else {
                     if ($kt_in == 1) {
                         if ($test_h > $roomprice_sg['moc2']) {
                             $hours_day = $roomprice_sg['khunggiobatdau'] - $h_in - 1 + $roomprice_sg['lamtron3'] / 60;
                         }
                         if ($test_h < $roomprice_sg['moc2'] && $test_h >= $roomprice_sg['moc1']) {
                             $hours_day = $roomprice_sg['khunggioketthuc'] - $h_in - 1 + $roomprice_sg['lamtron2'] / 60;
                         }
                         if ($test_h < $roomprice_sg['moc1']) {
                             $hours_day = $roomprice_sg['khunggioketthuc'] - $h_in - 1 + $roomprice_sg['lamtron1'] / 60;
                         }
                         $money_sg += $this->price_day($hours_day, $roomprice_sg, $room_237_sg);
                         if ($h_out < $roomprice_sg['khunggiobatdau']) {
                             if ($m_out > $roomprice_sg['moc2']) {
                                 $hours_night2 = $h_out + 24 - $roomprice_sg['khunggioketthuc'] + $roomprice_sg['lamtron3'] / 60;
                             }
                             if ($m_out < $roomprice_sg['moc2'] && $test_h >= $roomprice_sg['moc1']) {
                                 $hours_night2 = $h_out + 24 - $roomprice_sg['khunggioketthuc'] + $roomprice_sg['lamtron2'] / 60;
                             }
                             if ($m_out < $roomprice_sg['moc1']) {
                                 $hours_night2 = $h_out + 24 - $roomprice_sg['khunggioketthuc'] + $roomprice_sg['lamtron1'] / 60;
                             }
                             if ($hours_night2 > 3) {
                                 $money_sg += $roomprice_sg['giaquadem'];
                             } else {
                                 $money_sg += $hours_night2 * $roomprice_sg['giatheogio'];
                             }
                         } else {
                             if ($m_out > $roomprice_sg['moc2']) {
                                 $hours_night2 = $h_out - $roomprice_sg['khunggioketthuc'] + $roomprice_sg['lamtron3'] / 60;
                             }
                             if ($m_out < $roomprice_sg['moc2'] && $test_h >= $roomprice_sg['moc1']) {
                                 $hours_night2 = $h_out - $roomprice_sg['khunggioketthuc'] + $roomprice_sg['lamtron2'] / 60;
                             }
                             if ($m_out < $roomprice_sg['moc1']) {
                                 $hours_night2 = $h_out - $roomprice_sg['khunggioketthuc'] + $roomprice_sg['lamtron1'] / 60;
                             }
                             if ($hours_night2 > 3) {
                                 $money_sg += $roomprice_sg['giaquadem'];
                             } else {
                                 $money_sg += $hours_night2 * $roomprice_sg['giatheogio'];
                             }
                         }
                     } else {
                         if ($h_in < $roomprice_sg['khunggiobatdau']) {
                             if ($test_h > $roomprice_sg['moc2']) {
                                 $hours_night1 = $roomprice_sg['khunggiobatdau'] - $h_in - 1 + $roomprice_sg['lamtron3'] / 60;
                             }
                             if ($test_h < $roomprice_sg['moc2'] && $test_h >= $roomprice_sg['moc1']) {
                                 $hours_night1 = $roomprice_sg['khunggioketthuc'] - $h_in - 1 + $roomprice_sg['lamtron2'] / 60;
                             }
                             if ($test_h < $roomprice_sg['moc1']) {
                                 $hours_night1 = $roomprice_sg['khunggioketthuc'] - $h_in - 1 + $roomprice_sg['lamtron1'] / 60;
                             }
                             if ($hours_night1 > 3) {
                                 $money_sg += $roomprice_sg['giaquadem'];
                             } else {
                                 $money_sg += $hours_night1 * $roomprice_sg['giatheogio'];
                             }
                         } else {
                             if ($test_h > $roomprice_sg['moc2']) {
                                 $hours_night1 = $roomprice_sg['khunggiobatdau'] + 23 - $h_in + $roomprice_sg['lamtron3'] / 60;
                             }
                             if ($test_h < $roomprice_sg['moc2'] && $test_h >= $roomprice_sg['moc1']) {
                                 $hours_night1 = $roomprice_sg['khunggioketthuc'] + 23 - $h_in + $roomprice_sg['lamtron2'] / 60;
                             }
                             if ($test_h < $roomprice_sg['moc1']) {
                                 $hours_night1 = $roomprice_sg['khunggioketthuc'] + 23 - $h_in + $roomprice_sg['lamtron1'] / 60;
                             }
                             if ($hours_night1 > 3) {
                                 $money_sg += $roomprice_sg['giaquadem'];
                             } else {
                                 $money_sg += $hours_night1 * $roomprice_sg['giatheogio'];
                             }
                         }
                         if ($m_out > $roomprice_sg['moc2']) {
                             $hours_night2 = $h_out - $roomprice_sg['khunggiobatdau'] + $roomprice_sg['lamtron3'] / 60;
                         }
                         if ($m_out < $roomprice_sg['moc2'] && $test_h >= $roomprice_sg['moc1']) {
                             $hours_night2 = $h_out - $roomprice_sg['khunggiobatdau'] + $roomprice_sg['lamtron2'] / 60;
                         }
                         if ($m_out < $roomprice_sg['moc1']) {
                             $hours_night2 = $h_out - $roomprice_sg['khunggiobatdau'] + $roomprice_sg['lamtron1'] / 60;
                         }
                         $money_sg += $this->price_day($hours_night2, $roomprice_sg, $room_237_sg);
                     }
                 }
             }
         }
     }
     if ($info_booking['twin'] > 0) {
         if ($info_booking['airport'] == 1) {
             $roomprice_tw = Roommoney::find(11)->toArray();
             $room_237_tw = Roomtime::mthod('KHUNGGIO7AM_23PM')->roomtype(11)->get()->toArray();
             $room_pt_tw = Roomtime::mthod('PHUTROI')->roomtype(11)->get()->toArray();
         } else {
             $roomprice_tw = Roommoney::find(13)->toArray();
             $room_237_tw = Roomtime::mthod('KHUNGGIO7AM_23PM')->roomtype(13)->get()->toArray();
             $room_pt_tw = Roomtime::mthod('PHUTROI')->roomtype(13)->get()->toArray();
         }
         if ($roomprice_tw['khunggiobatdau'] <= $h_in && $h_in < $roomprice_tw['khunggioketthuc']) {
             $kt_in = 1;
         } else {
             $kt_in = 2;
         }
         if ($roomprice_tw['khunggiobatdau'] <= $h_out && $h_out < $roomprice_tw['khunggioketthuc']) {
             $kt_out = 1;
         } else {
             $kt_out = 2;
         }
         $test_h = 60 - $m_in;
         if ($minutes < $roomprice_tw['moc1']) {
             $total_hours += $roomprice_tw['lamtron1'] / 60;
         } elseif ($roomprice_tw['moc1'] <= $minutes && $minutes <= $roomprice_tw['moc2']) {
             $total_hours += $roomprice_tw['lamtron2'] / 60;
         } else {
             $total_hours += $roomprice_tw['lamtron3'] / 60;
         }
         if ($roomprice_tw['tinhtheongaydem'] == 0) {
             if ($days < 1) {
                 $money_tw = $this->price_day($total_hours, $roomprice_tw, $room_237_tw);
             } else {
                 $full_price_tw = $days * $roomprice_tw['gianguyenngay'];
                 $last_tw = $this->price_day($hours, $roomprice_tw, $room_237_tw);
                 $money_tw = $full_price_tw + $last_tw;
             }
         } else {
             if ($days < 1) {
                 if ($kt_in == $kt_out) {
                     if ($kt_in == 1) {
                         if ($h_out > $h_in) {
                             $money_tw = $this->price_day($total_hours, $roomprice_tw, $room_237_tw);
                         } elseif ($h_out == $h_in) {
                             if ($m_in < $m_out) {
                                 $money_tw = $this->price_day($total_hours, $roomprice_tw, $room_237_tw);
                             } else {
                                 $money_tw = $roomprice_tw['gianguyenngay'];
                             }
                         } else {
                             if ($test_h > $roomprice_tw['moc2']) {
                                 $hours_day = $roomprice_tw['khunggioketthuc'] - $h_in - 1 + $roomprice_tw['lamtron3'] / 60;
                             }
                             if ($test_h < $roomprice_tw['moc2'] && $test_h >= $roomprice_tw['moc1']) {
                                 $hours_day = $roomprice_tw['khunggioketthuc'] - $h_in - 1 + $roomprice_tw['lamtron2'] / 60;
                             }
                             if ($test_h < $roomprice_tw['moc1']) {
                                 $hours_day = $roomprice_tw['khunggioketthuc'] - $h_in - 1 + $roomprice_tw['lamtron1'] / 60;
                             }
                             $money_tw = $this->price_day($hours_day, $roomprice_tw, $room_237_tw);
                             $money_tw += $roomprice_tw['giaquadem'];
                             if ($m_out < $roomprice_tw['moc1']) {
                                 $hours_day_2 = $h_out - $roomprice_tw['khunggiobatdau'] + $roomprice_tw['lamtron1'] / 60;
                             }
                             if ($m_out <= $roomprice_tw['moc2'] && $m_out >= $roomprice_tw['moc1']) {
                                 $hours_day_2 = $h_out - $roomprice_tw['khunggiobatdau'] + $roomprice_tw['lamtron2'] / 60;
                             }
                             if ($m_out > $roomprice_tw['moc2']) {
                                 $hours_day_2 = $h_out - $roomprice_tw['khunggiobatdau'] + $roomprice_tw['lamtron3'] / 60;
                             }
                             $money_tw += $this->price_day($hours_day_2, $roomprice_tw, $room_237_tw);
                         }
                     } else {
                         $kt_night = $roomprice_tw['khunggiobatdau'] + 24 - $roomprice_tw['khunggioketthuc'];
                         if ($total_hours <= $kt_night) {
                             $money_tw += $total_hours * $roomprice_tw['giatheogio'];
                         } else {
                             if ($h_in < $roomprice_tw['khunggiobatdau']) {
                                 if ($test_h > $roomprice_tw['moc2']) {
                                     $hours_night1 = $roomprice_tw['khunggiobatdau'] - $h_in - 1 + $roomprice_tw['lamtron3'] / 60;
                                 }
                                 if ($test_h < $roomprice_tw['moc2'] && $test_h >= $roomprice_tw['moc1']) {
                                     $hours_night1 = $roomprice_tw['khunggioketthuc'] - $h_in - 1 + $roomprice_tw['lamtron2'] / 60;
                                 }
                                 if ($test_h < $roomprice_sg['moc1']) {
                                     $hours_night1 = $roomprice_tw['khunggioketthuc'] - $h_in - 1 + $roomprice_tw['lamtron1'] / 60;
                                 }
                                 if ($hours_night1 > 3) {
                                     $money_sg += $roomprice_tw['giaquadem'];
                                 } else {
                                     $money_sg += $hours_night1 * $roomprice_sg['giatheogio'];
                                 }
                                 $money_tw += $roomprice_tw['gianguyenngay'];
                                 if ($h_out < $roomprice_tw['khunggiobatdau']) {
                                     if ($m_out > $roomprice_tw['moc2']) {
                                         $hours_night2 = $h_out + 24 - $roomprice_tw['khunggioketthuc'] + $roomprice_tw['lamtron3'] / 60;
                                     }
                                     if ($m_out < $roomprice_tw['moc2'] && $test_h >= $roomprice_tw['moc1']) {
                                         $hours_night2 = $h_out + 24 - $roomprice_tw['khunggioketthuc'] + $roomprice_tw['lamtron2'] / 60;
                                     }
                                     if ($m_out < $roomprice_tw['moc1']) {
                                         $hours_night2 = $h_out + 24 - $roomprice_tw['khunggioketthuc'] + $roomprice_tw['lamtron1'] / 60;
                                     }
                                     if ($hours_night2 > 3) {
                                         $money_tw += $roomprice_tw['giaquadem'];
                                     } else {
                                         $money_tw += $hours_night2 * $roomprice_tw['giatheogio'];
                                     }
                                 } else {
                                     if ($m_out > $roomprice_tw['moc2']) {
                                         $hours_night2 = $h_out - $roomprice_tw['khunggioketthuc'] + $roomprice_tw['lamtron3'] / 60;
                                     }
                                     if ($m_out < $roomprice_tw['moc2'] && $test_h >= $roomprice_tw['moc1']) {
                                         $hours_night2 = $h_out - $roomprice_tw['khunggioketthuc'] + $roomprice_tw['lamtron2'] / 60;
                                     }
                                     if ($m_out < $roomprice_sg['moc1']) {
                                         $hours_night2 = $h_out - $roomprice_tw['khunggioketthuc'] + $roomprice_tw['lamtron1'] / 60;
                                     }
                                     if ($hours_night2 > 3) {
                                         $money_tw += $roomprice_tw['giaquadem'];
                                     } else {
                                         $money_tw += $hours_night2 * $roomprice_tw['giatheogio'];
                                     }
                                 }
                             } else {
                                 if ($test_h > $roomprice_tw['moc2']) {
                                     $hours_night1 = $roomprice_tw['khunggiobatdau'] + 23 - $h_in + $roomprice_tw['lamtron3'] / 60;
                                 }
                                 if ($test_h < $roomprice_tw['moc2'] && $test_h >= $roomprice_tw['moc1']) {
                                     $hours_night1 = $roomprice_tw['khunggioketthuc'] + 23 - $h_in + $roomprice_tw['lamtron2'] / 60;
                                 }
                                 if ($test_h < $roomprice_tw['moc1']) {
                                     $hours_night1 = $roomprice_tw['khunggioketthuc'] + 23 - $h_in + $roomprice_tw['lamtron1'] / 60;
                                 }
                                 if ($hours_night1 > 3) {
                                     $money_sg += $roomprice_tw['giaquadem'];
                                 } else {
                                     $money_sg += $hours_night1 * $roomprice_tw['giatheogio'];
                                 }
                                 $money_sg += $roomprice_tw['gianguyenngay'];
                                 if ($m_out > $roomprice_tw['moc2']) {
                                     $hours_night2 = $h_out - $roomprice_tw['khunggioketthuc'] + $roomprice_tw['lamtron3'] / 60;
                                 }
                                 if ($m_out < $roomprice_tw['moc2'] && $test_h >= $roomprice_tw['moc1']) {
                                     $hours_night2 = $h_out - $roomprice_tw['khunggioketthuc'] + $roomprice_tw['lamtron2'] / 60;
                                 }
                                 if ($m_out < $roomprice_tw['moc1']) {
                                     $hours_night2 = $h_out - $roomprice_tw['khunggioketthuc'] + $roomprice_tw['lamtron1'] / 60;
                                 }
                                 if ($hours_night2 > 3) {
                                     $money_tw += $roomprice_tw['giaquadem'];
                                 } else {
                                     $money_tw += $hours_night2 * $roomprice_tw['giatheogio'];
                                 }
                             }
                         }
                     }
                 } else {
                     if ($kt_in == 1) {
                         if ($test_h > $roomprice_tw['moc2']) {
                             $hours_day = $roomprice_tw['khunggiobatdau'] - $h_in - 1 + $roomprice_tw['lamtron3'] / 60;
                         }
                         if ($test_h < $roomprice_tw['moc2'] && $test_h >= $roomprice_tw['moc1']) {
                             $hours_day = $roomprice_tw['khunggioketthuc'] - $h_in - 1 + $roomprice_tw['lamtron2'] / 60;
                         }
                         if ($test_h < $roomprice_tw['moc1']) {
                             $hours_day = $roomprice_tw['khunggioketthuc'] - $h_in - 1 + $roomprice_tw['lamtron1'] / 60;
                         }
                         $money_tw += $this->price_day($hours_day, $roomprice_tw, $room_237_tw);
                         if ($h_out < $roomprice_tw['khunggiobatdau']) {
                             if ($m_out > $roomprice_tw['moc2']) {
                                 $hours_night2 = $h_out + 24 - $roomprice_tw['khunggioketthuc'] + $roomprice_tw['lamtron3'] / 60;
                             }
                             if ($m_out < $roomprice_tw['moc2'] && $test_h >= $roomprice_sg['moc1']) {
                                 $hours_night2 = $h_out + 24 - $roomprice_tw['khunggioketthuc'] + $roomprice_tw['lamtron2'] / 60;
                             }
                             if ($m_out < $roomprice_tw['moc1']) {
                                 $hours_night2 = $h_out + 24 - $roomprice_tw['khunggioketthuc'] + $roomprice_tw['lamtron1'] / 60;
                             }
                             if ($hours_night2 > 3) {
                                 $money_tw += $roomprice_tw['giaquadem'];
                             } else {
                                 $money_tw += $hours_night2 * $roomprice_tw['giatheogio'];
                             }
                         } else {
                             if ($m_out > $roomprice_tw['moc2']) {
                                 $hours_night2 = $h_out - $roomprice_tw['khunggioketthuc'] + $roomprice_tw['lamtron3'] / 60;
                             }
                             if ($m_out < $roomprice_tw['moc2'] && $test_h >= $roomprice_tw['moc1']) {
                                 $hours_night2 = $h_out - $roomprice_tw['khunggioketthuc'] + $roomprice_tw['lamtron2'] / 60;
                             }
                             if ($m_out < $roomprice_sg['moc1']) {
                                 $hours_night2 = $h_out - $roomprice_tw['khunggioketthuc'] + $roomprice_tw['lamtron1'] / 60;
                             }
                             if ($hours_night2 > 3) {
                                 $money_tw += $roomprice_tw['giaquadem'];
                             } else {
                                 $money_tw += $hours_night2 * $roomprice_tw['giatheogio'];
                             }
                         }
                     } else {
                         if ($h_in < $roomprice_tw['khunggiobatdau']) {
                             if ($test_h > $roomprice_tw['moc2']) {
                                 $hours_night1 = $roomprice_tw['khunggiobatdau'] - $h_in - 1 + $roomprice_tw['lamtron3'] / 60;
                             }
                             if ($test_h < $roomprice_tw['moc2'] && $test_h >= $roomprice_tw['moc1']) {
                                 $hours_night1 = $roomprice_tw['khunggioketthuc'] - $h_in - 1 + $roomprice_tw['lamtron2'] / 60;
                             }
                             if ($test_h < $roomprice_tw['moc1']) {
                                 $hours_night1 = $roomprice_tw['khunggioketthuc'] - $h_in - 1 + $roomprice_tw['lamtron1'] / 60;
                             }
                             if ($hours_night1 > 3) {
                                 $money_tw += $roomprice_tw['giaquadem'];
                             } else {
                                 $money_tw += $hours_night1 * $roomprice_sg['giatheogio'];
                             }
                         } else {
                             if ($test_h > $roomprice_tw['moc2']) {
                                 $hours_night1 = $roomprice_tw['khunggiobatdau'] + 23 - $h_in + $roomprice_tw['lamtron3'] / 60;
                             }
                             if ($test_h < $roomprice_tw['moc2'] && $test_h >= $roomprice_tw['moc1']) {
                                 $hours_night1 = $roomprice_tw['khunggioketthuc'] + 23 - $h_in + $roomprice_tw['lamtron2'] / 60;
                             }
                             if ($test_h < $roomprice_tw['moc1']) {
                                 $hours_night1 = $roomprice_tw['khunggioketthuc'] + 23 - $h_in + $roomprice_tw['lamtron1'] / 60;
                             }
                             if ($hours_night1 > 3) {
                                 $money_tw += $roomprice_tw['giaquadem'];
                             } else {
                                 $money_tw += $hours_night1 * $roomprice_tw['giatheogio'];
                             }
                         }
                         if ($m_out > $roomprice_tw['moc2']) {
                             $hours_night2 = $h_out - $roomprice_tw['khunggiobatdau'] + $roomprice_tw['lamtron3'] / 60;
                         }
                         if ($m_out < $roomprice_tw['moc2'] && $test_h >= $roomprice_tw['moc1']) {
                             $hours_night2 = $h_out - $roomprice_tw['khunggiobatdau'] + $roomprice_tw['lamtron2'] / 60;
                         }
                         if ($m_out < $roomprice_tw['moc1']) {
                             $hours_night2 = $h_out - $roomprice_tw['khunggiobatdau'] + $roomprice_tw['lamtron1'] / 60;
                         }
                         $money_tw += $this->price_day($hours_night2, $roomprice_tw, $room_237_sg);
                     }
                 }
             }
         }
     }
     if ($info_booking['child'] > 0) {
         $money_pt = $info_booking['child'] * $room_pt_sg[0]['mucdieuchinhgia'] * $total_hours;
     }
     $money_total = $money_sg * $info_booking['single'] + $money_tw * $info_booking['twin'] + $money_pt;
     $data_out[] = array();
     $data_out = ['time_in' => $info_booking['time_in'], 'date_in' => $info_booking['date_in'], 'time_out' => $info_booking['time_out'], 'date_out' => $info_booking['date_out'], 'adult' => $info_booking['adult'], 'child' => $info_booking['child'], 'baby' => $info_booking['baby'], 'airport' => $info_booking['airport'], 'single' => $info_booking['single'], 'twin' => $info_booking['twin'], 'mn_single' => $money_sg * $info_booking['single'], 'mn_twin' => $money_tw * $info_booking['twin'], 'mn_child' => $money_pt, 'total' => $money_total];
     $key_encrypt = $this->mc_encrypt($data_out, $this->vif_key);
     //$key_encrypt=urlencode($key_encrypt);
     return view('booking.info', compact('data_out', 'key_encrypt'));
 }
Example #3
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Request $request)
 {
     $money_sg = 0;
     $money_tw = 0;
     $money_pt = 0;
     $service_bf = 0;
     $service_af = 0;
     $info_booking = $request->all();
     //return $info_booking['date_in'];
     if (!isset($info_booking['twin'])) {
         $info_booking['twin'] = 0;
     }
     if (!isset($info_booking['single'])) {
         $info_booking['single'] = 0;
     }
     if (!isset($info_booking['baby'])) {
         $info_booking['baby'] = 0;
     }
     if (!isset($info_booking['child'])) {
         $info_booking['child'] = 0;
     }
     $arr_datein[] = array();
     $str = $info_booking['date_in'];
     $arr_datein = explode('/', $str);
     $day_in = $arr_datein[0];
     $mo_in = $arr_datein[1];
     $y_in = $arr_datein[2];
     $arr_timein = explode(':', $info_booking['time_in']);
     $h_in = $arr_timein[0];
     $m_in = $arr_timein[1];
     $arr_timeout = explode(':', $info_booking['time_out']);
     $h_out = $arr_timeout[0];
     $m_out = $arr_timeout[1];
     $arr_dateout[] = array();
     $str2 = $info_booking['date_out'];
     $arr_dateout = explode('/', $str2);
     $day_out = $arr_dateout[0];
     $mo_out = $arr_dateout[1];
     $y_out = $arr_dateout[2];
     $arrival_time = $y_in . '-' . $mo_in . '-' . $day_in . ' ' . $info_booking['time_in'];
     $depart_time = $y_out . '-' . $mo_out . '-' . $day_out . ' ' . $info_booking['time_out'];
     $in = new DateTime($arrival_time);
     $out = new DateTime($depart_time);
     $diff = $in->diff($out);
     $days = $diff->d;
     $hours = $diff->h;
     $minutes = $diff->i;
     $total_hours = $hours;
     if ($h_in >= 12) {
         $date = $day_in . "/" . $mo_in . "/" . $y_in;
     } else {
         $date = $this->convert_datetime($str, $info_booking['time_in']);
         $date = $date - 24 * 60 * 60;
         $date = date("d/m/Y", $date);
     }
     $roomprice_sg = Roommoney::findOrFail(1)->toArray();
     $roomMaintain = [];
     if ($info_booking['single'] > 0) {
         if ($info_booking['airport'] == 1) {
             $policy = DB::table('policy')->where('date', $date)->where('roomtype_id', 1)->first();
             if ($policy->room == 0) {
                 $roomMaintain['single'] = 0;
             } else {
                 if ($policy->room < $info_booking['single']) {
                     $roomMaintain['single'] = 1;
                     $roomMaintain['numSingle'] = $policy->room;
                 } else {
                     if (isset($policy->price)) {
                         $giaNSg = $policy->price;
                     } else {
                         $giaNSg = $roomprice_sg['gianguyenngay'];
                     }
                     if ($minutes < $roomprice_sg['moc1']) {
                         $total_hours += $roomprice_sg['lamtron1'] / 60;
                     } elseif ($minutes >= $roomprice_sg['moc1'] && $minutes <= $roomprice_sg['moc2']) {
                         $total_hours += $roomprice_sg['lamtron2'] / 60;
                     } else {
                         $total_hours += $roomprice_sg['lamtron3'] / 60;
                     }
                     if ($total_hours > $roomprice_sg['tongsogio']) {
                         $money_sg = $giaNSg + $days * $giaNSg;
                     } else {
                         $money_sg = $total_hours * $roomprice_sg['giatheogio'] + $days * $giaNSg;
                     }
                 }
             }
         } else {
             return redirect('/');
         }
     }
     if ($info_booking['twin'] > 0) {
         if ($info_booking['airport'] == 1) {
             $roomprice_tw = Roommoney::findOrFail(2)->toArray();
             $policy = DB::table('policy')->where('date', $date)->where('roomtype_id', 2)->first();
         } else {
             $roomprice_tw = Roommoney::findOrFail(3)->toArray();
             $policy = DB::table('policy')->where('date', $date)->where('roomtype_id', 3)->first();
         }
         if ($policy->room == 0) {
             $roomMaintain['twin'] = 0;
         } else {
             if ($policy->room < $info_booking['twin']) {
                 $roomMaintain['twin'] = 0;
                 $roomMaintain['numTwin'] = $policy->room;
             } else {
                 if (isset($policy->price)) {
                     $giaNTw = $policy->price;
                 } else {
                     $giaNTw = $roomprice_sg['gianguyenngay'];
                 }
                 if ($minutes < $roomprice_tw['moc1']) {
                     $total_hours += $roomprice_tw['lamtron1'] / 60;
                 } elseif ($minutes >= $roomprice_tw['moc1'] && $minutes <= $roomprice_sg['moc2']) {
                     $total_hours += $roomprice_tw['lamtron2'] / 60;
                 } else {
                     $total_hours += $roomprice_tw['lamtron3'] / 60;
                 }
                 if ($total_hours > $roomprice_tw['tongsogio']) {
                     $money_tw = $giaNTw + $days * $giaNTw;
                 } else {
                     $money_tw = $total_hours * $roomprice_tw['giatheogio'] + $days * $giaNTw;
                 }
             }
         }
     }
     if (isset($roomMaintain['twin']) || isset($roomMaintain['single'])) {
         return view('layouts.booking.full', compact('roomMaintain'));
     }
     if ($info_booking['child'] > 0) {
         $child = $info_booking['child'] + $info_booking['adult'] - $info_booking['single'] - 2 * $info_booking['twin'];
         if ($child > 0) {
             $money_pt = $child * $roomprice_sg['giaphutroi'];
         } else {
             $money_pt = 0;
         }
     }
     $money_room = $money_sg * $info_booking['single'] + $money_tw * $info_booking['twin'] + $money_pt;
     $service_out = [];
     $key = 0;
     $services = DB::table('service_lang')->join('services', 'service_lang.service_id', '=', 'services.id')->where('service_lang.lang_id', current_lang_id())->select('service_lang.*', 'services.*')->get();
     foreach ($services as $service) {
         if ($service->choice == 0) {
             $service_out[$key]['name'] = $service->name;
             if ($service->option == 0) {
                 $ser_bf = $money_room * $service->value / 100;
                 $service_bf += $ser_bf;
                 $service_out[$key]['money'] = $ser_bf;
             } else {
                 $service_bf += $service->value;
                 $service_out[$key]['money'] = $service->value;
             }
             $key++;
         }
     }
     foreach ($services as $service) {
         if ($service->choice == 1) {
             $service_out[$key]['name'] = $service->name;
             if ($service->option == 0) {
                 $ser_af = ($money_room + $service_bf) * $service->value / 100;
                 $service_af += $ser_af;
                 $service_out[$key]['money'] = $ser_af;
             } else {
                 $service_af += $service->value;
                 $service_out[$key]['money'] = $service->value;
             }
             $key++;
         }
     }
     $money_total = $money_room + $service_af + $service_bf;
     $data_out[] = array();
     $data_out = ['time_in' => $info_booking['time_in'], 'date_in' => $info_booking['date_in'], 'time_out' => $info_booking['time_out'], 'date_out' => $info_booking['date_out'], 'adult' => $info_booking['adult'], 'child' => $info_booking['child'], 'baby' => $info_booking['baby'], 'airport' => $info_booking['airport'], 'single' => $info_booking['single'], 'twin' => $info_booking['twin'], 'mn_single' => $money_sg * $info_booking['single'], 'mn_twin' => $money_tw * $info_booking['twin'], 'mn_child' => $money_pt, 'total' => $money_total, 'total_room' => $money_room, 'total_hours' => $total_hours, 'price' => $this->price];
     $time_now = time();
     $time_now = $this->encode_time($time_now);
     $key_encrypt = $this->mc_encrypt($data_out, $this->vif_key);
     $note = DB::table('post_desc')->where('post_id', 139)->where('lang_id', current_lang_id())->select('post_content')->get();
     if ($note != null) {
         $note = $note[0]->post_content;
     } else {
         $note = '';
     }
     $national = DB::table('country_codes')->select('en_short_name')->get();
     //return $data_out;
     return view('layouts.booking.info', compact('data_out', 'key_encrypt', 'time_now', 'service_out', 'note', 'national'));
 }