public function ajax() { $Logger = new TransLog(); $UserModel = new User(); $Amenities = new Amenities(); $type = Input::get('type'); if ($type) { switch ($type) { case 'packages-list': $pending = DB::table('tbl_packages')->join('tbl_package_group', 'package_id', '=', 'pc_groupid'); $dtResult = GlobalController::setDatatable($pending, array('pc_id', 'package_name', 'pc_price'), 'pc_id'); $aN = array(); $aQ = array(); foreach ($dtResult['objResult'] as $aRow) { unset($aN); $aN = array(); foreach (json_decode($aRow->pc_itemid) as $aM) { $name = $Amenities->getAmenityByOne($aM->id); array_push($aN, $aM->quantity . " " . $name->am_name); } $data = array($aRow->pc_id, $aRow->pc_name, $aN, number_format($aRow->pc_price, 2), '', '<div class="button-container">' . '<button class="btn-blue-admin btn-view-item" data-id="' . $aRow->pc_id . '">View</button>' . ' ' . '<button class="btn-blue-admin btn-edit-item" data-id="' . $aRow->pc_id . '">Update</button>' . '</div>'); $dtResult['aaData'][] = $data; } unset($dtResult['objResult']); echo json_encode($dtResult); break; case 'viewPackage': $id = Input::get('id'); $aM = DB::table('tbl_packages')->join('tbl_package_group', 'package_id', '=', 'pc_groupid')->where('pc_id', $id)->first(); $a = array(); foreach (json_decode($aM->pc_itemid) as $aMm) { $name = $Amenities->getAmenityByOne($aMm->id); $data = array('am_id' => $aMm->id, 'name' => $name->am_name, 'quantity' => $aMm->quantity); array_push($a, $data); } $data = array('pc_id' => $id, 'package_id' => $aM->package_id, 'package_name' => $aM->pc_name, 'package_type' => $aM->package_name, 'amenities' => $a, 'numpax' => $aM->pc_num_pax, 'quantity' => $aM->pc_quantity_perday, 'total_amount' => number_format($aM->pc_price, 2)); return Response::json($data); break; // case 'checkQuantity': { // $id = Input::get('id'); // $quantity = Input::get('field'); // $result = ""; // $aM = $Amenities->getAmenityByOne($id); // if($quantity > $aM->am_quantity){ // $result = 'Not enough stock.'; // } // return Response::json( array('result' => $result )); // break; // } } } }
public function ajax() { $Logger = new TransLog(); $UserModel = new User(); $Amenities = new Amenities(); $Orders = new Orders(); $type = Input::get('type'); if ($type) { switch ($type) { case 'cancelReservation': $id = Input::get('id'); $updateArr = array('status' => 0); $whereArr = array('id' => $id); $data = $this->GlobalModel->updateModel('tbl_reservation', $whereArr, $updateArr); $updateArr = array('order_status' => 0); $whereArr = array('order_id' => $id); $data = $this->GlobalModel->updateModel('tbl_orders', $whereArr, $updateArr); break; case 'order-list': $pending = DB::table('tbl_reservation')->join('tbl_orders', 'tbl_orders.order_id', '=', 'tbl_reservation.order_id')->join('tbl_orders_room', 'tbl_orders_room.or_orderid', '=', 'tbl_orders.order_id'); $dtResult = GlobalController::setDatatable($pending, array('id', 'pack_name', 'number_of_person', 'date_time_from', 'date_time_to', 'order_datecreated', 'order_status'), 'id'); foreach ($dtResult['objResult'] as $aRow) { switch ($aRow->status) { case 0: $status = '<button class="colorBtn2 styleBtn">Cancelled</button>'; $status .= '<button class="colorBtn8 styleBtn viewMe" data-id="' . $aRow->id . '" >View</button>'; break; case 1: $status = 'In Progress'; $status .= '<button class="colorBtn2 styleBtn" data-id="' . $aRow->id . '" id="cancelOrder">Cancel</button>'; $status .= '<button class="colorBtn8 styleBtn viewMe" data-id="' . $aRow->id . '" >View</button>'; break; case 2: $status = '<button class="colorBtn2 styleBtn">Pending</button>'; $status .= '<button class="colorBtn2 styleBtn" data-id="' . $aRow->id . '" id="cancelOrder">Cancel</button>'; $status .= '<button class="colorBtn8 styleBtn viewMe" data-id="' . $aRow->id . '" >View</button>'; break; case 3: $status = '<button class="colorBtn4 styleBtn">Completed</button>'; $status .= '<button class="colorBtn8 styleBtn viewMe" data-id="' . $aRow->id . '" >View</button>'; break; case 4: $status = '<button class="colorBtn4 styleBtn">Done</button>'; break; default: $status = ''; } $data = array($aRow->id, $aRow->pack_name, $aRow->number_of_person, '₱' . number_format($aRow->total_amount, 2), $this->GlobalModel->convertDate($aRow->date_time_from) . " - " . $this->GlobalModel->convertDate($aRow->date_time_to), $this->GlobalModel->convertDate($aRow->order_datecreated), $status); $dtResult['aaData'][] = $data; } unset($dtResult['objResult']); echo json_encode($dtResult); break; case 'viewReservation': $id = Input::get('id'); $getReserve = DB::table('tbl_reservation')->join('tbl_orders', 'tbl_orders.order_id', '=', 'tbl_reservation.order_id')->where('id', $id)->first(); foreach (json_decode($getReserve->pc_itemid) as $aMm) { $name = $Amenities->getAmenityByOne($aMm->id); $data = array('am_id' => $aMm->id, 'name' => $name->am_name, 'quantity' => $aMm->quantity); array_push($a, $name->am_name); } return Response::json(array('reserveId' => $getReserve->id, 'dateTo' => $getReserve->date_time_to, 'dateFrom' => $getReserve->date_time_from, 'amt' => $getReserve->total_amount)); break; } } }
public function ajax() { $Logger = new TransLog(); $UserModel = new User(); $Amenities = new Amenities(); $Orders = new Orders(); $type = Input::get('type'); if ($type) { switch ($type) { case 'packages-list': $pending = DB::table('tbl_packages')->join('tbl_package_group', 'package_id', '=', 'pc_groupid'); $dtResult = GlobalController::setDatatable($pending, array('pc_id', 'package_name', 'pc_price'), 'pc_id'); $aN = array(); $aQ = array(); foreach ($dtResult['objResult'] as $aRow) { unset($aN); $aN = array(); foreach (json_decode($aRow->pc_itemid) as $aM) { $name = $Amenities->getAmenityByOne($aM->id); array_push($aN, $aM->quantity . " " . $name->am_name); } $data = array($aRow->pc_id, $aRow->pc_name, $aN, number_format($aRow->pc_price, 2), '', '<div class="button-container">' . '<button class="btn-blue-admin btn-view-item" data-id="' . $aRow->pc_id . '">View</button>' . ' ' . '<button class="btn-blue-admin btn-edit-item" data-id="' . $aRow->pc_id . '">Update</button>' . '</div>'); $dtResult['aaData'][] = $data; } unset($dtResult['objResult']); echo json_encode($dtResult); break; case 'viewPackage': $id = Input::get('id'); $aM = DB::table('tbl_packages')->join('tbl_package_group', 'package_id', '=', 'pc_groupid')->where('pc_id', $id)->first(); $a = array(); foreach (json_decode($aM->pc_itemid) as $aMm) { $name = $Amenities->getAmenityByOne($aMm->id); $data = array('am_id' => $aMm->id, 'name' => $name->am_name, 'quantity' => $aMm->quantity); array_push($a, $data); } $data = array('pc_id' => $id, 'package_id' => $aM->package_id, 'package_name' => $aM->pc_name, 'amenities' => $a, 'numpax' => $aM->pc_num_pax, 'total_amount' => number_format($aM->pc_price, 2)); return Response::json($data); break; case 'accommodation-table': if (Input::get('id') > 0) { $Packages = DB::table('tbl_packages')->join('tbl_package_group', 'package_id', '=', 'pc_groupid')->where('pc_id', Input::get('id'))->get(); } else { $Packages = DB::table('tbl_packages')->join('tbl_package_group', 'package_id', '=', 'pc_groupid')->get(); } $a = array(); $b = array(); $c = array(); $tbody = ''; foreach ($Packages as $pk) { unset($a); $a = array(); // $Orders = new Orders(); // $date = Input::get('date') ? Input::get('date') : date('Y-m-d') ; // $date2 = Input::get('date_to') ? Input::get('date_to') : date('Y-m-d') ; // $rooms = $Orders->getRoomOrder($date, $date2); // $order_room = array(); // foreach($rooms as $room){ // $data = array( // 'package_id' => $room->order_packageid, // 'or_roomid' => json_decode($room->or_roomid) // ); // array_push($order_room, $data); // } $tbody .= '<tr>'; foreach (json_decode($pk->pc_itemid) as $aMm) { $name = $Amenities->getAmenityByOne($aMm->id); $room = null; if ($name->am_group == 4) { $room = '<br/>(' . $name->am_quantity . ' Left)'; } array_push($a, $aMm->quantity . ' ' . $name->am_name . $room); } $tbody .= ' <td class="lhs"> <a href="#" class="tooltip-ors" style="cursor: pointer;"> <b>' . $pk->pc_name . '</b> <span> <img class="callout" src="../img/callout.gif"> <strong>Inclusions</strong><br /> ' . implode("<br/>", $a) . ' </span> </a> </td><td></td> <td style="text-align: center;">' . $pk->pc_num_pax . '</td> '; if (Input::has('date')) { $d = Input::get('date'); $day = substr($d, -2); } else { $d = date('Y-m-d'); $day = date('d'); } $date_today = date('Y-m-d'); $datediff = strtotime(Input::get('date_to')) - strtotime($d); $final_date = floor($datediff / (60 * 60 * 24)); if ($final_date > 12) { $x = $final_date; } else { $x = 12; } $bookable = 0; unset($b); $b = array(); $check = $Orders->getOrderByID($pk->pc_id); $m = 0; if ($x > 18) { $tbody .= '<td></td>'; for ($i = 0; $i <= $x; $i++) { $date = date('Y-m-d', strtotime($d . ' +' . $i . ' day')); $availability = ""; if (Input::get('pax') > $pk->pc_num_pax) { $availability = '<td class="max-pax">Max ' . $pk->pc_num_pax . '</td>'; $bookable = 1; } else { if ($check->count()) { foreach ($check->get() as $chk) { if (strtotime($date) >= strtotime(Input::get('date')) && strtotime($date) <= strtotime(Input::get('date_to')) && strtotime(Input::get('date')) <= strtotime(Input::get('date_to')) && strtotime($date) >= strtotime($chk->order_datefrom) && strtotime($date) <= strtotime($chk->order_dateto) && strtotime($chk->order_datefrom) <= strtotime($chk->order_dateto)) { array_push($b, 1); } } } } if ($m == 0) { $tbody .= $availability; $m = 1; } } if (implode(",", $b) > 0) { $tbody .= '<td class="unavailable"">✗</td>'; array_push($b, 1); } else { if ($bookable != 1) { $tbody .= '<td class="available">✓</td>'; } } $tbody .= '<td></td>'; } else { for ($i = 0; $i <= $x; $i++) { $date = date('Y-m-d', strtotime($d . ' +' . $i . ' day')); $availability = '<td class="available">✓</td>'; if ($date_today > Input::get('date')) { $availability = '<td class="unavailable"">✗</td>'; array_push($b, 1); $bookable = 1; } else { if (Input::get('pax') > $pk->pc_num_pax) { $availability = '<td class="max-pax">Max ' . $pk->pc_num_pax . '</td>'; $bookable = 1; } else { if ($check->count() > 0) { foreach ($check->get() as $chk) { if (Input::has('date') && Input::has('date_to')) { $order_count = $Orders->getSumAllOrders($pk->pc_id, Input::get('date'), Input::get('date_to')); if ($pk->pc_quantity_perday <= $order_count) { $availability = '<td class="unavailable"">✗</td>'; array_push($b, 1); } } if (strtotime($date) >= strtotime($chk->order_datefrom) && strtotime($date) <= strtotime($chk->order_dateto) && strtotime($chk->order_datefrom) <= strtotime($chk->order_dateto)) { $availability = '<td class="unavailable"">✗</td>'; array_push($b, 1); } if (strtotime($date) >= strtotime(Input::get('date')) && strtotime($date) <= strtotime(Input::get('date_to')) && strtotime(Input::get('date')) <= strtotime(Input::get('date_to')) && strtotime($date) >= strtotime($chk->order_datefrom) && strtotime($date) <= strtotime($chk->order_dateto) && strtotime($chk->order_datefrom) <= strtotime($chk->order_dateto)) { array_push($b, 1); } } } else { if ($Orders->checkDateAvailability($date, $pk->pc_id) == 1) { $availability = '<td class="available">✓</td>'; } else { $availability = '<td class="available">✓</td>'; } } } } $tbody .= $availability; $day++; } } $price = number_format($pk->pc_price * ($final_date + 1), 2) < 0 ? $pk->pc_price : number_format($pk->pc_price * ($final_date + 1), 2); if (implode(",", $b) > 0 || Input::has('date_to') && $final_date < 0) { $tB = '<td class="maxGuests button"><a class="bookable notavailable notavailable-bg" title="Not Available"><b class="text notavailable">Date not</b><b class="price notavailable">available</b></a></td>'; } else { if (Input::has('id')) { $tB = '<td class="maxGuests button booknow-btn"><a class="bookable booknow bookable-cl" title="Book Now" data-id="' . $pk->pc_id . '"><b class="text">Rebook</b><b class="price">₱' . $price . '</b></a></td> <td class="maxGuests button booknow-btn proceed proceed-' . $pk->pc_id . '"><a class="proceed-payment bookable disabled-payment" title="Proceed" data-id="' . $pk->pc_id . '"><b class="text">Proceed</b><b class="price">payment</b></td> '; } else { $tB = '<td class="maxGuests button booknow-btn"><a class="bookable booknow bookable-cl" title="Book Now" data-id="' . $pk->pc_id . '"><b class="text">Book now</b><b class="price">₱' . $price . '</b></a></td> <td class="maxGuests button booknow-btn proceed proceed-' . $pk->pc_id . '"><a class="proceed-payment bookable" title="Proceed" data-id="' . $pk->pc_id . '"><b class="text">Proceed</b><b class="price">payment</b></td> '; } } $tbody .= $bookable == 1 ? '<td class="maxGuests button"><a class="bookable notavailable notavailable-bg" title="Not Available" ><b class="text notavailable">Not</b><b class="price notavailable">Available</b></a></td>' : $tB; $data = array('am_name' => implode(", ", $a), 'package_id' => $pk->package_id, 'package_name' => $pk->pc_name, 'numpax' => $pk->pc_num_pax, 'total_amount' => number_format($pk->pc_price, 2)); $tbody .= '</tr>'; } $thead = ' <th class="tblHeaderGlobal lhs">Package</th> <th class="tblHeaderGlobal"></th> <th class="tblHeaderGlobal maxGuests">MAX GUESTS</th> '; if (Input::has('date')) { $d = Input::get('date'); $day = substr($d, -2); } else { $d = date('Y-m-d'); $day = date('d'); } $datediff = strtotime(Input::get('date_to')) - strtotime($d); $final_date = floor($datediff / (60 * 60 * 24)); if ($final_date > 12) { $x = $final_date; } else { $x = 12; } if ($x > 18) { $thead .= '<th class="tblHeaderGlobal selected"> <b class="day">' . strtoupper(substr(date('l', strtotime($d)), 0, 3)) . '</b> <b class="date">' . date('d', strtotime($d)) . '</b> <b class="month">' . strtoupper(date('M', strtotime($d))) . '</b> </th> <th class="tblHeaderGlobal selected"> <b class="date"> >> </b> </th> <th class="tblHeaderGlobal selected"> <b class="day">' . strtoupper(substr(date('l', strtotime(Input::get('date_to'))), 0, 3)) . '</b> <b class="date">' . date('d', strtotime(Input::get('date_to'))) . '</b> <b class="month">' . strtoupper(date('M', strtotime(Input::get('date_to')))) . '</b> </th> '; } else { for ($i = 0; $i <= $x; $i++) { $date = date('Y-m-d', strtotime($d . ' +' . $i . ' day')); $day_ = strtoupper(date('d', strtotime($date))); if (Input::has('date_to') && strtotime($date) <= strtotime(Input::get('date_to'))) { $class = 'selected_day'; } else { if (date('N', strtotime($date)) >= 6) { $class = 'data weekend'; } else { $class = 'selected'; } } $thead .= '<th class="tblHeaderGlobal ' . $class . '"> <b class="day">' . strtoupper(substr(date('l', strtotime($date)), 0, 3)) . '</b> <b class="date">' . $day_ . '</b> <b class="month">' . strtoupper(date('M', strtotime($date))) . '</b> </th>'; $day++; } } $thead .= '<th class="tblHeaderGlobal"></th>'; $data = array('date' => $thead, 'packages' => $tbody); return Response::json($data); break; case 'accommodation-pertable': $Packages = DB::table('tbl_packages')->join('tbl_package_group', 'package_id', '=', 'pc_groupid')->where('pc_id', Input::get('id'))->get(); $a = array(); $b = array(); $c = array(); $tbody = ''; foreach ($Packages as $pk) { unset($a); $a = array(); $tbody .= '<tr>'; foreach (json_decode($pk->pc_itemid) as $aMm) { $name = $Amenities->getAmenityByOne($aMm->id); $data = array('am_id' => $aMm->id, 'name' => $name->am_name, 'quantity' => $aMm->quantity); array_push($a, $name->am_name); } $tbody .= ' <td class="lhs"> <a href="#" class="tooltip-ors" style="cursor: pointer;"> <b>' . $pk->pc_name . '</b> <span> <img class="callout" src="../img/callout.gif"> <strong>Inclusions</strong><br /> ' . implode(", ", $a) . ' </span> </a> </td><td></td> <td style="text-align: center;">' . $pk->pc_num_pax . '</td> '; if (Input::has('date')) { $d = Input::get('date'); $day = substr($d, -2); } else { $d = date('Y-m-d'); $day = date('d'); } $datediff = strtotime(Input::get('date_to')) - strtotime($d); $final_date = floor($datediff / (60 * 60 * 24)); if ($final_date > 12) { $x = $final_date; } else { $x = 12; } $bookable = 0; unset($b); $b = array(); $check = $Orders->getOrderByID($pk->pc_id); $m = 0; if ($x > 18) { $tbody .= '<td></td>'; for ($i = 0; $i <= $x; $i++) { $date = date('Y-m-d', strtotime($d . ' +' . $i . ' day')); $availability = ""; if (Input::get('pax') > $pk->pc_num_pax) { $availability = '<td class="max-pax">Max ' . $pk->pc_num_pax . '</td>'; $bookable = 1; } else { if ($check) { if (strtotime($date) >= strtotime(Input::get('date')) && strtotime($date) <= strtotime(Input::get('date_to')) && strtotime(Input::get('date')) <= strtotime(Input::get('date_to')) && strtotime($date) >= strtotime($check->order_datefrom) && strtotime($date) <= strtotime($check->order_dateto) && strtotime($check->order_datefrom) <= strtotime($check->order_dateto)) { array_push($b, 1); } } } if ($m == 0) { $tbody .= $availability; $m = 1; } } if (implode(",", $b) > 0) { $tbody .= '<td class="unavailable"">✗</td>'; array_push($b, 1); } else { if ($bookable != 1) { $tbody .= '<td class="available">✓</td>'; } } $tbody .= '<td></td>'; } else { for ($i = 0; $i <= $x; $i++) { $date = date('Y-m-d', strtotime($d . ' +' . $i . ' day')); $availability = '<td class="available">✓</td>'; if (Input::get('pax') > $pk->pc_num_pax) { $availability = '<td class="max-pax">Max ' . $pk->pc_num_pax . '</td>'; $bookable = 1; } else { if ($check) { if (strtotime($date) >= strtotime($check->order_datefrom) && strtotime($date) <= strtotime($check->order_dateto) && strtotime($check->order_datefrom) <= strtotime($check->order_dateto)) { $availability = '<td class="unavailable"">✗</td>'; array_push($b, 1); } if (strtotime($date) >= strtotime(Input::get('date')) && strtotime($date) <= strtotime(Input::get('date_to')) && strtotime(Input::get('date')) <= strtotime(Input::get('date_to')) && strtotime($date) >= strtotime($check->order_datefrom) && strtotime($date) <= strtotime($check->order_dateto) && strtotime($check->order_datefrom) <= strtotime($check->order_dateto)) { array_push($b, 1); } } else { if ($Orders->checkDateAvailability($date, $pk->pc_id) == 1) { $availability = '<td class="available">✓</td>'; } else { $availability = '<td class="available">✓</td>'; } } } $tbody .= $availability; $day++; } } $price = number_format($pk->pc_price * ($final_date + 1), 2) < 0 ? $pk->pc_price : number_format($pk->pc_price * ($final_date + 1), 2); if (implode(",", $b) > 0 || Input::has('date_to') && $final_date < 0) { $tB = '<td class="maxGuests button"><a class="bookable notavailable notavailable-bg" title="Not Available"><b class="text notavailable">Date not</b><b class="price notavailable">available</b></a></td>'; } else { $tB = '<td class="maxGuests button booknow-btn"><a class="bookable" title="Book Now" data-id="' . $pk->pc_id . '"><b class="text">Book now</b><b class="price">₱' . $price . '</b></td>'; } $tbody .= $bookable == 1 ? '<td class="maxGuests button"><a class="bookable notavailable notavailable-bg" title="Not Available" ><b class="text notavailable">Not</b><b class="price notavailable">Available</b></a></td>' : $tB; $data = array('am_name' => implode(", ", $a), 'package_id' => $pk->package_id, 'package_name' => $pk->pc_name, 'numpax' => $pk->pc_num_pax, 'total_amount' => number_format($pk->pc_price, 2)); $tbody .= '</tr>'; } $thead = ' <th class="tblHeaderGlobal lhs">Package</th> <th class="tblHeaderGlobal"></th> <th class="tblHeaderGlobal maxGuests">MAX GUESTS</th> '; if (Input::has('date')) { $d = Input::get('date'); $day = substr($d, -2); } else { $d = date('Y-m-d'); $day = date('d'); } $datediff = strtotime(Input::get('date_to')) - strtotime($d); $final_date = floor($datediff / (60 * 60 * 24)); if ($final_date > 12) { $x = $final_date; } else { $x = 12; } if ($x > 18) { $thead .= '<th class="tblHeaderGlobal selected"> <b class="day">' . strtoupper(substr(date('l', strtotime($d)), 0, 3)) . '</b> <b class="date">' . date('d', strtotime($d)) . '</b> <b class="month">' . strtoupper(date('M', strtotime($d))) . '</b> </th> <th class="tblHeaderGlobal selected"> <b class="date"> >> </b> </th> <th class="tblHeaderGlobal selected"> <b class="day">' . strtoupper(substr(date('l', strtotime(Input::get('date_to'))), 0, 3)) . '</b> <b class="date">' . date('d', strtotime(Input::get('date_to'))) . '</b> <b class="month">' . strtoupper(date('M', strtotime(Input::get('date_to')))) . '</b> </th> '; } else { for ($i = 0; $i <= $x; $i++) { $date = date('Y-m-d', strtotime($d . ' +' . $i . ' day')); $day_ = strtoupper(date('d', strtotime($date))); if (Input::has('date_to') && strtotime($date) <= strtotime(Input::get('date_to'))) { $class = 'selected_day'; } else { if (date('N', strtotime($date)) >= 6) { $class = 'data weekend'; } else { $class = 'selected'; } } $thead .= '<th class="tblHeaderGlobal ' . $class . '"> <b class="day">' . strtoupper(substr(date('l', strtotime($date)), 0, 3)) . '</b> <b class="date">' . $day_ . '</b> <b class="month">' . strtoupper(date('M', strtotime($date))) . '</b> </th>'; $day++; } } $thead .= '<th class="tblHeaderGlobal"></th>'; $data = array('date' => $thead, 'packages' => $tbody); return Response::json($data); break; // case 'checkQuantity': { // $id = Input::get('id'); // $quantity = Input::get('field'); // $result = ""; // $aM = $Amenities->getAmenityByOne($id); // if($quantity > $aM->am_quantity){ // $result = 'Not enough stock.'; // } // return Response::json( array('result' => $result )); // break; // } } } }