public function actionDashboard() { $bookings = \app\models\Bookings::find()->all(); $model = null; if (!empty($bookings)) { $model = $bookings; } return $this->render('dashboard', ['model' => $model]); }
/** * 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; }
/** * @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; }
/* @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 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 actionViewDetailsTourDate($tour_date_id) { $model = ToursDates::findOne($tour_date_id); $dataProvider = new ActiveDataProvider(['query' => Bookings::find()->where([Bookings::FIELD_TOUR_DATE_ID => $tour_date_id])]); return $this->render('details_tour_date', ['model' => $model, 'dataProvider' => $dataProvider]); }