public function save()
 {
     if (!$this->validate()) {
         return false;
     }
     if ($this->adults + $this->children + $this->babies == 0) {
         \Yii::$app->session->setFlash('danger', 'Error! You must book at least one place');
         return false;
     }
     $booking = new Bookings();
     $booking->attributes = $this->attributes;
     $booking->custom_fields = serialize($this->custom_fields);
     $booking->save();
     return true;
 }
Example #2
0
 public function actionDashboard()
 {
     $bookings = \app\models\Bookings::find()->all();
     $model = null;
     if (!empty($bookings)) {
         $model = $bookings;
     }
     return $this->render('dashboard', ['model' => $model]);
 }
 public function anyDashboard()
 {
     $website_views = WebsiteViews::all();
     $total_pending = Bookings::where('pending', 1)->count();
     $total_consulted = Bookings::where('consulted', 1)->count();
     $total_completed = Bookings::where('completed', 1)->count();
     $total_cancelled = Bookings::where('cancelled', 1)->count();
     $total_service_sales = 0;
     $total_shop_sales = 0;
     return View::make('dashboard.dashboard', ['website_views' => $website_views->count(), 'total_pending' => $total_pending, 'total_consulted' => $total_consulted, 'total_completed' => $total_completed, 'total_cancelled' => $total_cancelled, 'total_service_sales' => $total_service_sales, 'total_shop_sales' => $total_shop_sales]);
 }
Example #4
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Bookings::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, 'idCustomer' => $this->idCustomer, 'city' => $this->city, 'deliveryDate' => $this->deliveryDate, 'creationDate' => $this->creationDate]);
     $query->andFilterWhere(['like', 'address', $this->address])->andFilterWhere(['like', 'zipcode', $this->zipcode])->andFilterWhere(['like', 'comments', $this->comments]);
     return $dataProvider;
 }
Example #5
0
 /**
  * Deletes an existing Orders model.
  * If deletion is successful, the browser will be redirected to the 'index' page.
  * @param integer $id
  * @return mixed
  */
 public function actionDelete($id)
 {
     $order = $this->findModel($id);
     $bookingId = $order->idBooking;
     die("4");
     $booking = \app\models\Bookings::findOne($bookingId);
     $bookings_items = \app\models\Bookingitems::find()->where(['=', 'idBooking', $bookingId])->all();
     if (!empty($bookings_items)) {
         foreach ($bookings_items as $b) {
             $b->delete();
         }
     }
     $booking->delete();
     $order->delete();
     return $this->redirect(['bookings/index']);
 }
Example #6
0
 /**
  * @return mixed
  */
 public function getBookedPlaces($for)
 {
     $query = Bookings::find()->where([Bookings::FIELD_TOUR_DATE_ID => $this->tour_date_id]);
     return $query->sum($for) ? $query->sum($for) : 0;
 }
Example #7
0
/* @var $this yii\web\View */
/* @var $searchModel app\models\CustomersSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = 'Customers';
?>

<div class="customers-index">
    <div class="grids">
        <div id="customers-grids">
        <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'columns' => [['attribute' => 'image', 'format' => 'html', 'label' => 'Profile Image', 'value' => function ($data) {
    return Html::img('@web/images/customers/' . $data['image'], ['width' => '96px']);
}], 'id', ['attribute' => 'fullName', 'format' => 'raw', 'label' => 'Customer Full Name', 'value' => function ($data) {
    return $data['firstname'] . " " . $data['lastname'];
}], 'phone', 'email:email', ['attribute' => 'customerBookings', 'format' => 'raw', 'label' => 'No. of Bookings', 'value' => function ($data) {
    return \app\models\Bookings::find()->where(['idCustomer' => $data['id']])->count() . " Booking(s)";
}], ['label' => 'View', 'format' => 'raw', 'value' => function ($data) {
    return urldecode(\yii\helpers\Html::a('', Yii::$app->urlManager->createUrl(['customers/view&id=' . $data['id']]), ['aria-label' => 'View'])) . urldecode(\yii\helpers\Html::a('', Yii::$app->urlManager->createUrl(['customers/update&id=' . $data['id']]), ['aria-label' => 'Update'])) . urldecode(\yii\helpers\Html::a('', Yii::$app->urlManager->createUrl(['customers/delete&id=' . $data['id']]), ['aria-label' => 'Delete']));
}, 'header' => 'Action']]]);
?>
        </div>
    </div>
    
    <p class="add">
        <?php 
echo Html::a('', ['create'], ['class' => '']);
?>
    </p>

</div>
use yii\data\ActiveDataProvider;
use yii\db\Query;
use app\models\Bookings;
use app\models\CustomFields;
?>
<div class="col-sm-12">
	<div class="panel panel-default">
		<div class="panel-heading">
			<?php 
echo Html::tag('h4', $model->date);
?>
		</div>
		<div class="panel-body">
			<h5 >Booked places</h5>
			<?php 
echo GridView::widget(['dataProvider' => new ActiveDataProvider(['query' => Bookings::find()->where([Bookings::FIELD_TOUR_DATE_ID => $model->tour_date_id])]), 'columns' => [Bookings::FIELD_NAME, Bookings::FIELD_ADULTS, Bookings::FIELD_CHILDREN, Bookings::FIELD_BABIES, ['class' => DataColumn::className(), 'format' => 'html', 'attribute' => Bookings::FIELD_CUSTOM_FIELDS, 'value' => function ($model) {
    /* @var $model Bookings */
    $result = 'Not set';
    if (isset($model->custom_fields)) {
        $result = null;
        $custom_fields = unserialize($model->custom_fields);
        foreach ($custom_fields as $key => $value) {
            $custom_field = CustomFields::findOne($key);
            $result .= '<b>' . $custom_field->label . ': </b>' . $value . '<br>';
        }
    }
    return $result;
}]]]);
?>
		</div>
	</div>
 public function anyUpdateStatus($booking_uid, $status)
 {
     $booking = Bookings::where('uid', '=', $booking_uid)->first();
     $error_msg = [];
     $tz = new \DateTimeZone('NZ');
     $now = new \DateTime(date('Y-m-d H:i:s'));
     $now->setTimezone($tz);
     $current_date_time = $now->format('Y-m-d H:i:s');
     $success = false;
     $booking_date = Input::get('booking_date');
     $booking_time = Input::get('booking_time');
     if (Request::method() == 'GET') {
         return view('booking.update_status', ['booking' => $booking, 'success' => $success, 'status' => $status, 'error_msg' => $error_msg]);
     } else {
         if ($booking) {
             if ($status == 'consulted') {
                 $booking->pending = 0;
                 $booking->consulted = 1;
                 $booking->completed = 0;
                 $booking->cancelled = 0;
                 $booking->consulted_at = $current_date_time;
                 $booking->save();
                 $success = true;
             } elseif ($status == 'completed') {
                 if ($booking_date && $booking_time) {
                     $booking->pending = 0;
                     $booking->consulted = 0;
                     $booking->completed = 1;
                     $booking->cancelled = 0;
                     $booking->completed_at = $current_date_time;
                     $booking->booking_date = date('Y-m-d', strtotime($booking_date));
                     $booking->booking_time = date('H:i:s', strtotime($booking_time));
                     $booking->save();
                     $success = true;
                 } else {
                     $error_msg[] = 'Booking date and booking time are required.';
                     $success = false;
                 }
             } elseif ($status == 'cancelled') {
                 $booking->pending = 0;
                 $booking->consulted = 0;
                 $booking->completed = 0;
                 $booking->cancelled = 1;
                 $booking->cancelled_at = $current_date_time;
                 $booking->save();
                 $success = true;
             } else {
                 $error_msg[] = 'No status selected';
                 $success = false;
             }
             if ($success) {
                 return Redirect::back()->with('success', $success);
             } else {
                 return view('booking.update_status', ['booking' => $booking, 'success' => $success, 'status' => $status, 'error_msg' => $error_msg]);
             }
         } else {
             return Redirect::back()->with(['success', $success, 'error_msg', $error_msg]);
         }
     }
 }
Example #10
0
 public function getBookings()
 {
     return $this->hasOne(Bookings::className(), ['id' => 'idBooking']);
 }
Example #11
0
 public function actionEvents()
 {
     if (\filter_input(INPUT_GET, 'q')) {
         $q = \filter_input(INPUT_GET, 'q');
         $query = new Query();
         $query->select("`b`.*")->from("bookings b, customers c, items i, bookingitems bi")->where("(" . "b.idCustomer=c.id AND " . "(" . "CONCAT(c.firstname, ' ', c.lastname) LIKE '{$q}' OR " . "c.firstname LIKE '{$q}' OR " . "c.lastname LIKE '{$q}' OR " . "CONCAT(c.lastname, ' ', c.firstname) LIKE '{$q}'" . ")" . ") OR (bi.idItem=i.id AND (i.name LIKE '{$q}' OR i.idItem LIKE '{$q}'))")->groupBy("b.id");
         $bookings = $query->createCommand()->queryAll();
     } else {
         $bookings = Bookings::find()->all();
     }
     if (!empty($bookings)) {
         $status = 1;
         $events = array();
         for ($i = 0; $i < sizeof($bookings); $i++) {
             $is_order = !empty(Orders::find()->where(['idBooking' => $bookings[$i]['id']])->one()->id) ? true : false;
             $date_passed = strtotime($bookings[$i]['deliveryDate']) < strtotime(date('Y-m-d')) ? true : false;
             $delivered = $is_order ? Orders::find()->where(['idBooking' => $bookings[$i]['id']])->one()->delivered == 1 ? true : false : false;
             if (!$is_order && $date_passed) {
                 $status = 3;
             } elseif ($is_order && $date_passed && !$delivered) {
                 $status = 4;
             } elseif ($is_order && !$date_passed) {
                 $status = 2;
             } elseif ($is_order && $date_passed && $delivered) {
                 $status = 5;
             } else {
                 $status = 1;
             }
             $customer = Customers::find()->where(['id' => $bookings[$i]['idCustomer']])->one();
             $Event = new \yii2fullcalendar\models\Event();
             $Event->id = $bookings[$i]['id'];
             if (!empty($customer)) {
                 $Event->title = $customer->firstname . " " . $customer->lastname;
             }
             $Event->start = $bookings[$i]['deliveryDate'];
             $Event->status = $status;
             $events[] = $Event;
         }
         if (!empty($events)) {
             return json_encode($events);
         }
     }
 }
 public function actionDeleteCustomField($custom_field_id)
 {
     $custom_field = CustomFields::findOne($custom_field_id);
     if ($bookings = Bookings::findAll([Bookings::FIELD_TOUR_DATE_ID => $custom_field->tour_id])) {
         Yii::$app->session->setFlash('danger', 'This custom field can not delete because it contains in reserved places records');
         return $this->redirect(['edit-tour', Tours::FIELD_TOUR_ID => $custom_field->tour_id]);
     }
     $custom_field->delete();
     Yii::$app->session->setFlash('success', 'Tours date successful deleted');
     return $this->redirect(['edit-tour', Tours::FIELD_TOUR_ID => $custom_field->tour_id]);
 }