public function actionGrid()
 {
     $query = Reservation::find();
     $searchModel = new Reservation();
     if (isset($_GET['Reservation'])) {
         $searchModel->load(Yii::$app->request->get());
         $query->andFilterWhere(['customer_id' => isset($_GET['Reservation']['customer_id']) ? $_GET['Reservation']['customer_id'] : null]);
     }
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 10]]);
     return $this->render('grid', compact('dataProvider'));
 }
 public function actionAjaxDropDownListByCustomerid($customer_id)
 {
     $output = '';
     $items = Reservation::findAll(['customer_id' => $customer_id]);
     foreach ($items as $item) {
         $content = sprintf('reservation #%s at %s', $item->id, date('Y-m-d H:i:s', strtotime($item->reservation_date)));
         $output .= \yii\helpers\Html::tag('option', $content, ['value' => $item->id]);
     }
     return $output;
 }
 public function actionDatePicker()
 {
     $reservationUpdated = false;
     $reservation = Reservation::findOne(1);
     if (isset($_POST['Reservation'])) {
         $reservation->load(Yii::$app->request->post());
         $reservation->date_from = Yii::$app->formatter->asDate(date_create_from_format('d/m/Y', $reservation->date_from), 'php:Y-m-d');
         $reservation->date_to = Yii::$app->formatter->asDate(date_create_from_format('d/m/Y', $reservation->date_to), 'php:Y-m-d');
         $reservationUpdated = $reservation->save();
     }
     return $this->render('datePicker', ['reservation' => $reservation, 'reservationUpdated' => $reservationUpdated]);
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Reservation::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'room_id' => $this->room_id, 'customer_id' => $this->customer_id, 'price_per_day' => $this->price_per_day, 'date_from' => $this->date_from, 'date_to' => $this->date_to, 'reservation_date' => $this->reservation_date]);
     return $dataProvider;
 }
 public function actionCreateCustomerAndReservation()
 {
     $customer = new Customer();
     $reservation = new Reservation();
     $reservation->customer_id = 0;
     if ($customer->load(Yii::$app->request->post()) && $reservation->load(Yii::$app->request->post()) && $customer->validate() && $reservation->validate()) {
         $dbTrans = Yii::$app->db->beginTransaction();
         $customerSaved = $customer->save();
         if ($customerSaved) {
             $reservation->customer_id = $customer->id;
             $reservationSaved = $reservation->save();
             if ($reservationSaved) {
                 $dbTrans->commit();
             } else {
                 $dbTrans->rollback();
             }
         } else {
             $dbTrans->rollback();
         }
     }
     return $this->render('createCustomerAndReservation', ['customer' => $customer, 'reservation' => $reservation]);
 }
 public function actionCreateCustomerAndReservation()
 {
     $customer = new \app\models\Customer();
     $reservation = new \app\models\Reservation();
     // It is useful to set fake customer_id to reservation model to avoid validationerror (because customer_id is mandatory)
     $reservation->customer_id = 0;
     if ($customer->load(Yii::$app->request->post()) && $reservation->load(Yii::$app->request->post()) && $customer->validate() && $reservation->validate()) {
         $dbTrans = Yii::$app->db->beginTransaction();
         $customerSaved = $customer->save();
         if ($customerSaved) {
             $reservation->customer_id = $customer->id;
             $reservationSaved = $reservation->save();
             if ($reservationSaved) {
                 $dbTrans->commit();
             } else {
                 $dbTrans->rollback();
             }
         } else {
             $dbTrans->rollback();
         }
     }
     return $this->render('createCustomerAndReservation', ['customer' => $customer, 'reservation' => $reservation]);
 }
Example #7
0
 public function search($input)
 {
     $query = Reservation::query();
     $columns = Schema::getColumnListing('reservations');
     $attributes = array();
     foreach ($columns as $attribute) {
         if (isset($input[$attribute]) and !empty($input[$attribute])) {
             $query->where($attribute, $input[$attribute]);
             $attributes[$attribute] = $input[$attribute];
         } else {
             $attributes[$attribute] = null;
         }
     }
     return [$query->get(), $attributes];
 }
Example #8
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $all = $request->all();
     $rooms = json_decode($all['rrooms'], true);
     $now = date('Y-m-d H:i:s');
     $reservecode = isset($all['reserve_code']) && trim($all['reserve_code']) != '' ? $all['reserve_code'] : Reservation::generateReserveCode();
     $reservation = ["guest_id" => $all['guest_id'], "reserve_date" => $all['reserve_date'], "Partner" => $all['partner'], "pax" => $all['pax'], "pickup_time" => $all['pickup_time'], "pickup_location" => $all['pickup_location'], "notes" => $all['notes'], "reserve_fee" => $all['reserve_fee'], "card_type" => $all['cardType'], "date_created" => $now, "date_updated" => $now, "batch_number" => $all['batch_number'], "is_debit" => isset($all['is_debit']) ? 1 : 0, "card_suffix" => $all['card_suffix'], "multi_entry_approver" => ""];
     $res = Reservation::find($reservecode);
     if (is_null($res)) {
         $reservation['reserve_code'] = $reservecode;
         Reservation::create($reservation);
     } else {
         Reservation::find($reservecode)->update($reservation);
     }
     $partnerTrxn = ["booking_number" => $all['booking_number'], "payable" => $all['commission'], "transaction_date" => $all['reserve_date'], "reserve_code" => $reservecode, "result_status" => 'Confirmed', "receivable" => '0.00', "partner_name" => $all['partner'], "remarks" => $all['remarks']];
     $pt = PartnerTransaction::where(['reserve_code' => $reservecode])->get()->first();
     if (is_null($pt)) {
         PartnerTransaction::create($partnerTrxn);
     } else {
         $pt->update($partnerTrxn);
     }
     $this->saveReserveRooms($rooms, $reservecode);
     return redirect('reservations' . '?reserve_code=' . $reservecode)->with('status', 'Reservation data saved');
 }
 public function rules()
 {
     return array_merge(parent::rules(), [['customer.surname', 'safe']]);
 }
    \$(document).on('change', '#reservation-id', function(ev) {
        \$(this).parents('form').submit();
        ev.preventDefault();
    });
EOT_JS
);
?>
<div class="customer-form">
<?php 
$form = ActiveForm::begin(['enableAjaxValidation' => true, 'enableClientValidation' => true, 'options' => ['data-pjax' => '']]);
?>

<?php 
$customers = Customer::find()->all();
echo $form->field($model, 'customer_id')->dropDownList(ArrayHelper::map($customers, 'id', 'nameAndSurname'), ['prompt' => '--- choose']);
$reservations = Reservation::findAll(['customer_id' => $model->customer_id]);
?>

<?php 
echo $form->field($model, 'id')->label('Reservation ID')->dropDownList(ArrayHelper::map($reservations, 'id', function ($temp, $defaultValue) {
    $content = sprintf('reservation #%s at %s', $temp->id, date('Y-m-d H:i:s', strtotime($temp->reservation_date)));
    return $content;
}), ['prompt' => '--- choose']);
?>
<div id="detail">
    <?php 
if ($showDetail) {
    ?>
    <hr />
    <h2>Reservation Detail:</h2>
    <table>
Example #11
0
 public function getLastReservation()
 {
     return $this->hasOne(Reservation::className(), ['room_id' => 'id'])->orderBy(['id' => SORT_DESC]);
 }
Example #12
0
 public function actionIndexWithRelationships()
 {
     $room_id = Yii::$app->request->get('room_id', null);
     $reservation_id = Yii::$app->request->get('reservation_id', null);
     $customer_id = Yii::$app->request->get('customer_id', null);
     $roomSelected = null;
     $reservationSelected = null;
     $customerSelected = null;
     if ($room_id != null) {
         $roomSelected = Room::findOne($room_id);
         $rooms = array($roomSelected);
         $reservations = $roomSelected->reservations;
         $customers = $roomSelected->customers;
     } elseif ($reservation_id != null) {
         $reservationSelected = Reservation::findOne($reservation_id);
         $rooms = array($reservationSelected->room);
         $reservations = array($reservationSelected);
         $customers = array($reservationSelected->customer);
     } elseif ($customer_id != null) {
         $customerSelected = Customer::findOne($customer_id);
         $rooms = $customerSelected->rooms;
         $reservations = $customerSelected->reservations;
         $customers = array($customerSelected);
     } else {
         $rooms = Room::find()->all();
         $reservations = Reservation::find()->all();
         $customers = Customer::find()->all();
     }
     return $this->render('indexWithRelationShips', compact('roomSelected', 'reservationSelected', 'customerSelected', 'rooms', 'reservations', 'customers'));
 }
Example #13
0
 public function storeData(Request $request, $id)
 {
     Reservation::create($request->all());
     return redirect('admin/pesan/' . $id);
 }
Example #14
0
 public function getReservationsCount()
 {
     return $this->hasMany(Reservation::className(), ['customer_id' => 'id'])->count();
 }
 /**
  * Finds the Reservation model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Reservation the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Reservation::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 public function getPastReservations()
 {
     if (Auth::check()) {
         return \View::make('layouts.default')->with('title', 'Past Reservations')->with('reservations', \App\Models\Reservation::showPastReservations());
     } else {
         return Redirect::route('home')->with('message', 'You are not logged in!');
     }
 }
Example #17
0
 public static function postAddGuest()
 {
     if (Auth::check()) {
         $validation = \App\Models\Guest::validate(Input::all());
         if ($validation->passes()) {
             if (count(\App\Models\Reservation::checkIfExistsZakaznik(Input::get('guest_id'))) == 0) {
                 /** Here, you have to check if user_id is valid ID number **/
                 DB::insert('INSERT INTO zakaznik (meno, rodnecislo, adresa, datnar, telcis, mail) VALUES (?, ?, ?, ?, ?, ?)', [Input::get('name'), Input::get('guest_id'), Input::get('address'), Input::get('birth_date'), Input::get('telephone'), Input::get('mail')]);
             }
             DB::insert('INSERT INTO obyvana (CisPobytu, IDZak) VALUES (?, ?)', [Input::get('id'), Input::get('guest_id')]);
             return Redirect::route('home')->with('message', 'Guest successfully added!');
         } else {
             return Redirect::route('addguest')->withErrors($validation)->withInput()->with('id', Input::get('id'));
         }
     } else {
         return Redirect::route('home')->with('message', 'You are not logged in!');
     }
 }
Example #18
0
 public function attributes()
 {
     return array_merge(parent::attributes(), ['customer.surname']);
 }