Пример #1
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'));
 }