public function reserveation(Request $re) { $op = new operationController(); $re->request->add(['single' => $re->oneval, 'double' => $re->twoval, 'tripple' => $re->threeval, 'dayin' => $re->rday, 'monthin' => $re->rmonth, 'dayout' => $re->cday, 'monthout' => $re->cmonth]); $chechAv = $op->checkAvailability($re); if (!$chechAv) { return 2; } if (session_status() == PHP_SESSION_NONE) { session_start(); } $username = $_SESSION['username']; $rr = DB::table('user_table')->where('username', "{$username}")->first(); $rr2 = DB::table('reservation_table')->where('user_id', $rr->id)->first(); if ($rr2) { return 3; } if (session_status() == PHP_SESSION_NONE) { session_start(); } $form = new formaction(); $checkIN = $form->make_date($re->rday, $re->rmonth); $chechOUT = $form->make_date($re->cday, $re->cmonth); $_SESSION['checkin'] = $checkIN; $_SESSION['checkout'] = $chechOUT; $_SESSION['rt1'] = $re->oneval; $_SESSION['rt2'] = $re->twoval; $_SESSION['rt3'] = $re->threeval; $val1 = $re->oneval; $val2 = $re->twoval; $val3 = $re->threeval; $in_day = $re->rday; $in_mon = $re->rmonth; $out_day = $re->cday; $out_mon = $re->cmonth; global $in_key; global $out_in_key; global $inwit; global $tot, $tot2, $tot3; global $to, $to2, $to3; $this->validate($re, ['oneval' => 'numeric', 'twoval' => 'numeric', 'threeval' => 'numeric']); if ($val1 == 0 && $val2 == 0 && $val3 == 0) { $this->throwValidationException($re, 0); } else { if (session_status() == PHP_SESSION_NONE) { session_start(); } // job 1 : generate how many nights from the check in and out dates // job 2 : generate the price and total amount that should be paid $chechin = $form->make_date($re->rday, $re->rmonth); $checkout = $form->make_date($re->cday, $re->cmonth); // job 1 // -1 comes out when checkout or checkin is not valid date $n = DB::select(DB::raw("SELECT DATEDIFF('{$checkout}','{$chechin}') AS day")); $nights = 0; if ($n[0]->day != 1) { $nights = $n[0]->day - 1; } else { $nights = $n[0]->day; } $type1price = 0; $type2price = 0; $type3price = 0; $total = 0; if ($nights != -1) { // when valid date // job 2 if ($val1 > 0) { // partialPrice = room price * number of rooms // type1price = onedayprice * nights $partialPrice = 50 * $val1; $type1price = $partialPrice * $nights; $total = $total + $type1price; } if ($val2 > 0) { $partialPrice = 60 * $val2; $type2price = $partialPrice * $nights; $total = $total + $type2price; } if ($val3 > 0) { $partialPrice = 70 * $val3; $type3price = $partialPrice * $nights; $total = $total + $type3price; } $total = $total + 78.75; } else { // error date is not valid return 5; } $_SESSION['reservation'] = 1; $_SESSION['amount'] = $total; $ReserveInfo = array('total' => $total, 'room1num' => $val1, 'room2num' => $val2, 'room3num' => $val3, 'room1price' => $type1price, 'room2price' => $type2price, 'room3price' => $type3price, 'nights' => $nights); $_SESSION['ReserveInfo'] = $ReserveInfo; /* $month = array( 1 => 'January', 2 => 'February', 3 => 'March', 4 => 'April', 5 => 'May', 6 => 'June', 7 => 'July', 8 => 'Auguest', 9 => 'September', 10=> 'October', 11=> 'November', 12=> 'December' );*/ /*$in_all=explode( ' ', $in_mon ); $out_all=explode( ' ', $out_mon ); $_SESSION['val1']=$val1; $_SESSION['val2']=$val2; $_SESSION['val3']=$val3; $inwit=abs($in_day-$out_day)-1; return "$inwit";*/ /* if($in_all[0] == $out_all[0] && $in_all[1]==$out_all[1] && $inwit < 0) { $this->throwValidationException($re ,0); }*/ /*else if($in_all[0] == $out_all[0] && $in_all[1]==$out_all[1]) { $_SESSION['inwit']=$inwit; $to=$val1 * $inwit * 50; $_SESSION['to']=$to; $to2=$val2 * $inwit * 60; $_SESSION['to2']=$to2; $to3=$val3 * $inwit * 70; $_SESSION['to3']=$to3; $all_to=$to + $to2 +$to3; $_SESSION['all_to']=$all_to; $_SESSION['amount'] = $all_to; $_SESSION['lock']='0'; }*/ /* else { foreach ($month as $mo) { if($mo == $in_all[0] ) { $in_key= key($month)-1; } } foreach ($month as $mo) { if($mo == $out_all[0] ) { $out_in_key= key($month)-1; } } $mo= $out_in_key - $in_key; $year= abs($in_all[1]-$out_all[1]); $day=$in_day-$out_day; if($mo == 1 ) { $form = new formaction(); $in_a=$form->make_date($in_day, $in_mon); $out_a=$form->make_date($out_day, $out_mon); $diff_in = DB::select(DB::raw("SELECT DATEDIFF('$out_a','$in_a') AS day")); $date = $diff_in[0]->day; if($date == NULL) { echo $all_days=($mo +$date); $_SESSION['all_days']=$all_days; } else { echo $all_days=($mo +$date)-1; $_SESSION['all_days']=$all_days; } } else { $mo =$mo *12; $all_days=($mo +$day)-1; $_SESSION['all_days']=$all_days; } if($year >= 0 && $year <= 1) { $tot=$val1 * $all_days * 50; $_SESSION['tot']=$tot; $tot2=$val2 * $all_days * 60; $_SESSION['tot2']=$tot2; $tot3=$val3 * $all_days * 70; $_SESSION['tot3']=$tot3; $all_tota=$tot+$tot2+$tot3; $_SESSION['all_tot']=$all_tota; $_SESSION['amount'] = $all_tota; $_SESSION['lock']=1; } }*/ } }
public function reserveation(Request $re) { $op = new operationController(); $re->request->add(['single' => $re->oneval, 'double' => $re->twoval, 'tripple' => $re->threeval, 'dayin' => $re->rday, 'monthin' => $re->rmonth, 'dayout' => $re->cday, 'monthout' => $re->cmonth]); $chechAv = $op->checkAvailability($re); if (!$chechAv) { $this->throwValidationException($re, 0); } $val1 = $re->oneval; $val2 = $re->twoval; $val3 = $re->threeval; $in_day = $re->rday; $in_mon = $re->rmonth; $out_day = $re->cday; $out_mon = $re->cmonth; global $in_key; global $out_in_key; global $inwit; global $tot, $tot2, $tot3; global $to, $to2, $to3; $this->validate($re, ['oneval' => 'numeric', 'twoval' => 'numeric', 'threeval' => 'numeric']); if ($val1 == 0 && $val2 == 0 && $val3 == 0) { $this->throwValidationException($re, 0); } else { if (session_status() == PHP_SESSION_NONE) { session_start(); } $month = array(1 => 'January', 2 => 'February', 3 => 'March', 4 => 'April', 5 => 'May', 6 => 'June', 7 => 'July', 8 => 'Auguest', 9 => 'September', 10 => 'October', 11 => 'November', 12 => 'December'); $in_all = explode(' ', $in_mon); $out_all = explode(' ', $out_mon); $_SESSION['val1'] = $val1; $_SESSION['val2'] = $val2; $_SESSION['val3'] = $val3; $inwit = abs($in_day - $out_day) - 1; if ($in_all[0] == $out_all[0] && $in_all[1] == $out_all[1] && $inwit < 0) { $this->throwValidationException($re, 0); } else { if ($in_all[0] == $out_all[0] && $in_all[1] == $out_all[1]) { $_SESSION['inwit'] = $inwit; $to = $val1 * $inwit * 50; $_SESSION['to'] = $to; $to2 = $val2 * $inwit * 60; $_SESSION['to2'] = $to2; $to3 = $val3 * $inwit * 70; $_SESSION['to3'] = $to3; $all_to = $to + $to2 + $to3; $_SESSION['all_to'] = $all_to; $_SESSION['lock'] = '0'; } else { foreach ($month as $mo) { if ($mo == $in_all[0]) { $in_key = key($month) - 1; } } foreach ($month as $mo) { if ($mo == $out_all[0]) { $out_in_key = key($month) - 1; } } $mo = abs($out_in_key - $in_key) * 12; $year = abs($in_all[1] - $out_all[1]); $day = abs($in_day - $out_day); $all_days = $mo + $day - 1; $_SESSION['all_days'] = $all_days; if ($year >= 0 && $year <= 1) { $tot = $val1 * $all_days * 50; $_SESSION['tot'] = $tot; $tot2 = $val2 * $all_days * 60; $_SESSION['tot2'] = $tot2; $tot3 = $val3 * $all_days * 70; $_SESSION['tot3'] = $tot3; $all_tota = $tot + $tot2 + $tot3; $_SESSION['all_tot'] = $all_tota; $_SESSION['lock'] = 1; /************Session***********/ } } } } }