/**
  * @param integer $id
  * @return mixed
  */
 public function actionList($id = 0)
 {
     if (Yii::$app->request->isAjax) {
         if (!$id) {
             echo '';
             Yii::$app->end();
         }
         $tourFields = Tour::find()->with('tourFields')->where(['id' => $id])->one();
         $booking = new Booking();
         $bookingFields = new BookingFields();
         $bookingColumns = $booking->getTableSchema()->columns;
         $sort = Json::decode($tourFields->sort);
         $data = array_merge_recursive($sort, $bookingColumns);
         $addField = [];
         if ($tourFields->tourFields) {
             foreach ($tourFields->tourFields as $field) {
                 $addField['add_field_' . $field->id] = ['sort' => $field->sort, 'name' => $field->name, 'type' => $field->type, 'tour_id' => $field->tour_id];
             }
         }
         $data = array_merge($data, $addField);
         unset($data['id']);
         unset($data['tour_id']);
         $data = $booking->customMultiSort($data, 'sort');
         echo $this->renderAjax('_list', ['booking' => $booking, 'bookingFields' => $bookingFields, 'data' => $data]);
         Yii::$app->end();
     }
     return $this->redirect(Url::home());
 }
 /**
  * Finds the Tour model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Tour the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findTour($id)
 {
     if (($model = Tour::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 /**
  * Updates an existing TourField model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     $tourModel = \app\models\Tour::findOne(['id' => $model->tour_id]);
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('update', ['model' => $model, 'id' => $model->tour_id, 'tourModel' => $tourModel]);
     }
 }
 public function actionTour($id)
 {
     /** @var Tour $model */
     $model = Tour::findOne(['id' => $id]);
     if ($model === null) {
         throw new NotFoundHttpException("Такого тура не существует");
     } else {
         $provider = new ActiveDataProvider(['query' => $model->getCouples()]);
         return $this->render('list', ['provider' => $provider, 'tour' => $model]);
     }
 }
Beispiel #5
0
 public function upgrade($id)
 {
     $tour = Tour::findOne($id);
     $tour->name = $this->name;
     $tour->org = $this->org;
     $tour->tel = $this->tel;
     $tour->address = $this->address;
     $tour->info = $this->info;
     $tour->site = $this->site;
     $tour->save(false);
     return $tour ? $tour : null;
 }
 public function actionIndex()
 {
     // slide small 1
     $slideCruises = Slide::find()->where(['position' => 2])->all();
     // slide small 2
     $slideLately = Slide::find()->where(['position' => 3])->all();
     // tour hot cruises
     $tourHotCruises = Tour::find()->where(['hot' => 1])->all();
     // tour hot lately
     $tourHotLately = Tour::find()->where(['hot' => 2])->all();
     return $this->render('index', ['slideCruises' => $slideCruises, 'slideLately' => $slideLately, 'tourHotCruises' => $tourHotCruises, 'tourHotLately' => $tourHotLately]);
 }
 /**
  * lock around 20 - next 20
  *
  * @return void
  * @author 
  **/
 public function calculatebalance()
 {
     \Log::info('Re calculate ads` balance @' . date('Y-m-d H:i:s'));
     $tours = Tour::published()->upcomingtour()->adsstarted('now')->with('travel_agent')->get();
     $now = \Carbon\Carbon::now()->format('Y-m-d');
     foreach ($tours as $key => $value) {
         foreach ($value['ads'] as $key2 => $value2) {
             $query = [];
             $query[] = ['$match' => ['ads_id' => ['$eq' => $value2['ad_id']]]];
             $query[] = ['$group' => ['_id' => '$ads_id', 'count' => ['$sum' => '$credit.credit_balance'], 'total' => ['$sum' => 1]]];
             $prev_calc = TopUpLog::raw(function ($collection) use($query, $value2) {
                 return $collection->aggregate($query);
             })->toArray();
             $started = \Carbon\Carbon::parse($value2['started_at']);
             $days = $started->diffInDays(\Carbon\Carbon::parse('today'));
             $today_balance = $value2['initial_credit'] - $days * $value2['daily_rate'];
             if ($value2['started_at'] <= $now && $value2['today_balance'] > 0 && ($prev_calc[0]['count'] > 0 && $prev_calc[0]['count'] != $today_balance || is_null($prev_calc[0]))) {
                 $new_balance = $value['ads'];
                 $new_balance[$key2]['today_balance'] = $value2['initial_credit'] - $days * $value2['daily_rate'];
                 if (is_null($prev_calc[0]['count'])) {
                     $new_balance[$key2]['credit_balance'] = 0 - $new_balance[$key2]['today_balance'];
                 } else {
                     $new_balance[$key2]['credit_balance'] = 0 - ($prev_calc[0]['count'] - $new_balance[$key2]['today_balance']);
                 }
                 $value->ads = $new_balance;
                 $attributes['name'] = 'Auto debit Top Up';
                 $attributes['ads_id'] = $value2['ad_id'];
                 $attributes['transact_at'] = \Carbon\Carbon::now()->format('Y-m-d');
                 $attributes['travel_agent']['_id'] = $value->travel_agent['_id'];
                 $attributes['travel_agent']['name'] = $value->travel_agent['name'];
                 $attributes['credit']['started_at'] = $value2['started_at'];
                 $attributes['credit']['initial_credit'] = $value2['initial_credit'] * 1;
                 $attributes['credit']['daily_rate'] = $value2['daily_rate'] * 1;
                 $attributes['credit']['today_balance'] = $new_balance[$key2]['today_balance'] * 1;
                 $attributes['credit']['credit_balance'] = $new_balance[$key2]['credit_balance'];
                 $attributes['credit']['tags'] = $value2['tags'];
                 $attributes['tour']['_id'] = $value['_id'];
                 $attributes['tour']['name'] = $value['name'];
                 $attributes['tour']['tags'] = $value['tags'];
                 $top_up = new TopUpLog();
                 $top_up->fill($attributes);
                 if (!$top_up->save()) {
                     \Log::error(json_encode($top_up->getError()));
                 }
             }
         }
         if (!$value->save()) {
             \Log::error(json_encode($value->getError()));
         }
     }
     return true;
 }
Beispiel #8
0
 public function actionUpdate($id)
 {
     $model = new AddForm();
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         $tour = $model->upgrade($id);
         if (!$tour) {
             Yii::$app->session->setFlash('error', 'Ошибка при валидации');
             Yii::error('Ошибка при валидации');
             return $this->goHome();
         }
     }
     $tour = Tour::findOne($id);
     return $this->render('update', ['model' => $model, 'tour' => $tour]);
 }
Beispiel #9
0
 /**
  * [tour description]
  * @return [type] [description]
  */
 public function tour()
 {
     $featuretours = Tour::getFeatureTour();
     foreach ($featuretours as $key => $value) {
         $featuretours[$key]->periodNature = HomeController::periodNature($value->period);
     }
     $newtours = Tour::getNewTour();
     foreach ($newtours as $key => $value) {
         $newtours[$key]->periodNature = HomeController::periodNature($value->period);
     }
     $destinations = Destination::all();
     $departures = Departure::all();
     return view('home.tour', compact('featuretours', 'newtours', 'destinations', 'departures'));
 }
Beispiel #10
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Tour::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, 'countAdults' => $this->countAdults, 'countChildren' => $this->countChildren, 'countSuckling' => $this->countSuckling]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'positionFields', $this->positionFields]);
     return $dataProvider;
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Tour::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]);
     $query->andFilterWhere(['like', 'title', $this->title]);
     return $dataProvider;
 }
Beispiel #12
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Tour::find();
     // add conditions that should always apply here
     $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;
     }
     // grid filtering conditions
     $query->andFilterWhere(['id' => $this->id]);
     $query->andFilterWhere(['like', 'name', $this->name]);
     return $dataProvider;
 }
Beispiel #13
0
 public function actionDelete($id)
 {
     $request = Yii::$app->request;
     $tour = null;
     if ($id != null) {
         $tour_field = TourFields::findOne($id);
         if ($tour_field != null) {
             $tour = Tour::findOne($tour_field->tour_id);
             $tour_field->delete();
             Yii::$app->getSession()->setFlash('message', Yii::t('app', "Custom field #{$tour_field->id} deleted."));
         }
     }
     if ($tour) {
         return $this->redirect("/tour/{$tour->id}");
     } else {
         return $this->redirect("/tour");
     }
 }
Beispiel #14
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Tour::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;
     }
     if (!isset($this->status)) {
         $this->status = 1;
     }
     $query->joinWith("tourtype");
     $query->andFilterWhere(['id' => $this->id, 'length' => $this->length, 'regdate' => $this->regdate, 'editdate' => $this->editdate, 'hot' => $this->hot, 'status' => $this->status]);
     $query->andFilterWhere(['like', 'tour.name', $this->name])->andFilterWhere(['like', 'code', $this->code])->andFilterWhere(['like', 'tourtype.name', $this->id_tourtype])->andFilterWhere(['like', 'keyword', $this->keyword])->andFilterWhere(['like', 'startfrom', $this->startfrom])->andFilterWhere(['like', 'price', $this->price])->andFilterWhere(['like', 'briefinfo', $this->briefinfo])->andFilterWhere(['like', 'detailinfo', $this->detailinfo])->andFilterWhere(['like', 'smallimg', $this->smallimg])->andFilterWhere(['like', 'largeimg', $this->largeimg]);
     return $dataProvider;
 }
Beispiel #15
0
 public function add($id)
 {
     $order = new Order();
     $order->id_tour = $id;
     $order->id_user = Yii::$app->user->id;
     $order->name = $this->name;
     $order->tel = $this->tel;
     $order->count = $this->count;
     $order->email = $this->email;
     $order->info = $this->info;
     $order->date_tour = $this->date_tour;
     $order->date = date('Y-m-d h:m:s');
     $order->status = $this->status;
     $tour = Tour::findOne($id);
     $order->id_owner = $tour->id_user;
     $order->tour_name = $tour->name;
     $order->save(false);
     return $order ? $order : null;
 }
Beispiel #16
0
 public function actionIndex()
 {
     if (Yii::$app->user->isGuest) {
         return $this->goHome();
     }
     $orders = Order::find()->select('id_tour')->where(['id_user' => Yii::$app->user->id])->all();
     $i = 0;
     if (!$orders) {
         $this->redirect('tour/', 302);
     }
     foreach ($orders as $t) {
         $ids[$i] = $t->id_tour;
         $i++;
     }
     $query = Tour::find()->where(['id' => $ids]);
     //->all();
     $pagination = new Pagination(['defaultPageSize' => 3, 'totalCount' => $query->count()]);
     $tours = $query->orderBy('name')->offset($pagination->offset)->limit($pagination->limit)->all();
     return $this->render('index', ['tours' => $tours, 'pagination' => $pagination]);
 }
Beispiel #17
0
 public function upload($id)
 {
     if ($this->validate()) {
         $it = 0;
         foreach ($this->imageFiles as $file) {
             $path = 'uploads/' . $id . 'n' . $it . '.' . $file->extension;
             $file->saveAs($path);
             $gallery = new Gallery();
             $gallery->id_tour = $id;
             $gallery->path = $path;
             $gallery->save(false);
             ++$it;
         }
         $img = Tour::findOne(['id' => $id]);
         $img->image = 'uploads/' . $id . 'n0' . '.' . $this->imageFiles[0]->extension;
         $img->save(false);
         return true;
     } else {
         return false;
     }
 }
 /**
  * lock around 20 - next 20
  *
  * @return void
  * @author 
  **/
 public function checkcheapest()
 {
     \Log::info('Running Check Cheapest Tour @' . date('Y-m-d H:i:s'));
     $tours = Tour::published()->upcomingtour()->get();
     foreach ($tours as $key => $value) {
         $now = Carbon::now()->format('Y-m-d');
         $min_cost = null;
         foreach ($value['schedules'] as $key2 => $value2) {
             if (($value2['departure_until'] >= $now && $value2['departure'] >= $now || $value2['departure_until'] == '' && $value2['departure'] >= $now) && (is_null($min_cost) || $min_cost > $value2['price'])) {
                 $min_cost = $value2['price'];
             }
             // else
             // {
             // 	\Log::info($value2['departure']);
             // }
         }
         $value->cron_cheapest_price = $min_cost;
         if (!$value->save()) {
             \Log::error(json_encode($value->getError()));
         }
     }
     return true;
 }
 public function actionTour($id)
 {
     $tour = Tour::findOne($id);
     return $this->render('tour', ['tour' => $tour]);
 }
Beispiel #20
0
 function tour_per_author()
 {
     ///////////////////
     // GET PARAMETER //
     ///////////////////
     $filters = $this->request->only('ongoing');
     ///////////
     // Query //
     ///////////
     if ($filters['ongoing']) {
         $query[] = ['$match' => ['published_at' => ['$lte' => \Carbon\Carbon::now()->format('Y-m-d')], '$or' => [['schedules.departure' => ['$gte' => \Carbon\Carbon::now()->format('Y-m-d')]], ['schedules.departure_until' => ['$gte' => \Carbon\Carbon::now()->format('Y-m-d')]]]]];
     } else {
         $query[] = ['$match' => ['published_at' => ['$lte' => \Carbon\Carbon::now()->format('Y-m-d')]]];
     }
     $query[] = ['$group' => ['_id' => '$user_id', 'last_created_at' => ['$first' => '$created_at'], 'user_id' => ['$push' => '$user_id'], 'count' => ['$sum' => 1]]];
     //////////////////////////////
     // 			Get Result 		//
     //////////////////////////////
     $data = [];
     $total_tour = Tour::raw(function ($collection) use($query) {
         return $collection->aggregate($query);
     });
     foreach ($total_tour as $key => $value) {
         $new = User::find($value['_id']);
         if ($new) {
             $new['total_tour'] = $value['count'];
             $new['last_created_at'] = $value['last_created_at'];
             $data[] = $new->toArray();
         }
     }
     return response()->json(JSend::success(['count' => count($data), 'data' => $data])->asArray())->setCallback($this->request->input('callback'));
 }
Beispiel #21
0
 /**
  * store a resource 
  * @param  Request 	$request http request
  * @param  mixed  	$id      id of the resource for updating
  * @return jsend           	 jsend with newly stored source
  */
 function store($id = null)
 {
     ////////////////
     // Load Data  //
     ////////////////
     if ($id) {
         $data = Model::find($id);
         if (!$data) {
             return app()->abort(404);
         }
     } else {
         $data = new Model();
     }
     ///////////////////////////////////
     // Assign posted data to Data    //
     ///////////////////////////////////
     $data->fill($this->request->input());
     $data->slug = Model::generateSlug($data->name, $data->_id);
     //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     // REMOVE THIS AFTERWARD //
     //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     // $data->created_at = $this->request->input('created_at');
     ///////////////////////////////////////////////////////////////////
     // 							Validate data 						 //
     ///////////////////////////////////////////////////////////////////
     # Validate Travel Agent
     $travel_agent = TravelAgent::find($this->request->input('travel_agent_id'));
     if (!$travel_agent) {
         return response()->json(JSend::fail(['travel_agent_id' => ['Travel Agent is not recognized']])->asArray())->setCallback($this->request->input('callback'));
     }
     $data->travel_agent_id = $travel_agent->id;
     ///////////////////////
     // EMBED IMAGES 	 //
     ///////////////////////
     foreach ($this->request->input('images') as $x) {
         $images[] = new Image($x);
     }
     if (!$data->syncImages($images)) {
         return response()->json(JSend::fail($data->getErrors())->asArray())->setCallback($this->request->input('callback'));
     }
     ///////////////////////
     // EMBED TAGS	 	 //
     ///////////////////////
     foreach ($this->request->input('tags') as $x) {
         if ($x['tag'] && $x['type']) {
             $tags[] = new Tag($x);
         }
     }
     if (!$data->syncTags($tags)) {
         return response()->json(JSend::fail($data->getErrors())->asArray())->setCallback($this->request->input('callback'));
     }
     ////////////////////////
     // EMBED TourSchedule //
     ////////////////////////
     foreach ($this->request->input('schedules') as $x) {
         if ($x['_id']) {
             $tour_schedule = $data->schedules->where('_id', $x['_id'])->first();
             if (!$tour_schedule) {
                 return app()->abort(404);
             }
             $tour_schedule->fill($x);
         } else {
             $tour_schedule = new TourSchedule($x);
         }
         //////////////////////
         // Sync Promo 		//
         //////////////////////
         $promos = [];
         foreach ($x['promos'] as $promo_array) {
             if ($promo_array['_id']) {
                 $promo = $tour_schedule->promos->where('_id', $promo_array['_id']['$id'])->first();
                 if (!$promo) {
                     return app()->abort(404);
                 }
                 $promo->fill($promo_array);
                 $promos[] = $promo;
             } else {
                 $promos[] = new Promo($promo_array);
             }
         }
         if (!$tour_schedule->syncPromo($promos)) {
             return response()->json(JSend::fail($tour_schedule->getErrors())->asArray())->setCallback($this->request->input('callback'));
         }
         //////////////////////
         // Sync Voucher 	//
         //////////////////////
         $vouchers = [];
         foreach ($x['vouchers'] as $voucher_array) {
             if ($voucher_array['_id']) {
                 $voucher = $tour_schedule->vouchers->where('_id', $voucher_array['_id']['$id'])->first();
                 if (!$voucher) {
                     return App()->abort(404);
                 }
                 $voucher->fill($voucher_array);
                 $vouchers[] = $voucher;
             } else {
                 $vouchers[] = new Voucher($voucher_array);
             }
         }
         if (!$tour_schedule->syncVoucher($vouchers)) {
             return response()->json(JSend::fail($tour_schedule->getErrors())->asArray())->setCallback($this->request->input('callback'));
         }
         $tour_schedules[] = $tour_schedule;
     }
     if (!$data->syncTourSchedules($tour_schedules)) {
         return response()->json(JSend::fail($data->getErrors())->asArray())->setCallback($this->request->input('callback'));
     }
     ///////////////////////
     // EMBED PACKAGE  	 //
     ///////////////////////
     if (!$data->syncTourPackage(new TourPackage($this->request->input('package')))) {
         return response()->json(JSend::fail($data->getErrors())->asArray())->setCallback($this->request->input('callback'));
     }
     //////////////////
     // Check Top Up //
     //////////////////
     if ($data->ads) {
         $older_data = $data->getOriginal();
     }
     ///////////
     // Store //
     ///////////
     if ($data->save()) {
         $new_ads = $data->ads;
         if ($data->ads) {
             $ids_inc = [];
             foreach ($data->ads as $key => $value) {
                 //1. Check if new data
                 if (empty($value['ad_id'])) {
                     $new_ad = $data->ads[$key];
                     $new_ad['ad_id'] = uniqid();
                     $new_ads[$key] = $new_ad;
                     $attributes['name'] = 'Top Up';
                     $attributes['ads_id'] = $new_ad['ad_id'];
                     $attributes['transact_at'] = \Carbon\Carbon::now()->format('Y-m-d');
                     $attributes['travel_agent']['_id'] = $data->travel_agent['_id'];
                     $attributes['travel_agent']['name'] = $data->travel_agent['name'];
                     $attributes['credit']['started_at'] = $data->ads[$key]['started_at'];
                     $attributes['credit']['initial_credit'] = $data->ads[$key]['initial_credit'] * 1;
                     $attributes['credit']['daily_rate'] = $data->ads[$key]['daily_rate'] * 1;
                     $attributes['credit']['today_balance'] = $data->ads[$key]['today_balance'] * 1;
                     $attributes['credit']['credit_balance'] = $data->ads[$key]['credit_balance'] * 1;
                     $attributes['credit']['tags'] = $data->ads[$key]['tags'];
                     $attributes['tour']['_id'] = $data['_id'];
                     $attributes['tour']['name'] = $data['name'];
                     $attributes['tour']['tags'] = $data['tags']->toArray();
                     $top_up = new TopUpLog();
                     $top_up->fill($attributes);
                     if (!$top_up->save()) {
                         $error_responses = [];
                         foreach ($top_up->getErrors() as $field => $errors) {
                             $error_responses[$field] = implode(', ', $errors);
                         }
                         return response()->json(JSend::fail($top_up->getErrors())->asArray());
                     }
                 } elseif ($older_data['ads'][$key]['started_at'] != $data->ads[$key]->started_at || $older_data['ads'][$key]['initial_credit'] != $data->ads[$key]->initial_credit || $older_data['ads'][$key]['daily_rate'] != $data->ads[$key]->daily_rate || $older_data['ads'][$key]['today_balance'] != $data->ads[$key]->today_balance || $older_data['ads'][$key]['credit_balance'] != $data->ads[$key]->credit_balance) {
                     //emptied last balance
                     $last_balance = TopUpLog::where('ads_id', $older_data['ads'][$key]['ad_id'])->orderBy('created_at', 'desc')->first();
                     if ($last_balance && $last_balance['credit']['today_balance'] > 0) {
                         $attributes['name'] = 'Emptied Top Up';
                         $attributes['ads_id'] = $older_data['ads'][$key]['ad_id'];
                         $attributes['transact_at'] = \Carbon\Carbon::now()->format('Y-m-d');
                         $attributes['travel_agent']['_id'] = $data->travel_agent['_id'];
                         $attributes['travel_agent']['name'] = $data->travel_agent['name'];
                         $attributes['credit']['started_at'] = $older_data['ads'][$key]['started_at'];
                         $attributes['credit']['initial_credit'] = $older_data['ads'][$key]['initial_credit'] * 1;
                         $attributes['credit']['daily_rate'] = $older_data['ads'][$key]['daily_rate'] * 1;
                         $attributes['credit']['today_balance'] = 0 * 1;
                         $attributes['credit']['credit_balance'] = (0 - $older_data['ads'][$key]['today_balance']) * 1;
                         $attributes['credit']['tags'] = $older_data['ads'][$key]['tags'];
                         $attributes['tour']['_id'] = $older_data['_id'];
                         $attributes['tour']['name'] = $older_data['name'];
                         $attributes['tour']['tags'] = $older_data['tags'];
                         $top_up = new TopUpLog();
                         $top_up->fill($attributes);
                         if (!$top_up->save()) {
                             $error_responses = [];
                             foreach ($top_up->getErrors() as $field => $errors) {
                                 $error_responses[$field] = implode(', ', $errors);
                             }
                             return response()->json(JSend::fail($top_up->getErrors())->asArray());
                         }
                     }
                     //create new top up
                     $new_ad = $data->ads[$key];
                     $new_ads[$key] = $new_ad;
                     $attributes['name'] = 'Edited Top Up';
                     $attributes['ads_id'] = $new_ad['ad_id'];
                     $attributes['transact_at'] = \Carbon\Carbon::now()->format('Y-m-d');
                     $attributes['travel_agent']['_id'] = $data->travel_agent['_id'];
                     $attributes['travel_agent']['name'] = $data->travel_agent['name'];
                     $attributes['credit']['started_at'] = $data->ads[$key]['started_at'] * 1;
                     $attributes['credit']['initial_credit'] = $data->ads[$key]['initial_credit'] * 1;
                     $attributes['credit']['daily_rate'] = $data->ads[$key]['daily_rate'] * 1;
                     $attributes['credit']['today_balance'] = $data->ads[$key]['initial_credit'] * 1;
                     $attributes['credit']['credit_balance'] = $data->ads[$key]['initial_credit'] * 1;
                     $attributes['credit']['tags'] = $data->ads[$key]['tags'];
                     $attributes['tour']['_id'] = $data['_id'];
                     $attributes['tour']['name'] = $data['name'];
                     $attributes['tour']['tags'] = $data['tags']->toArray();
                     $top_up = new TopUpLog();
                     $top_up->fill($attributes);
                     if (!$top_up->save()) {
                         $error_responses = [];
                         foreach ($top_up->getErrors() as $field => $errors) {
                             $error_responses[$field] = implode(', ', $errors);
                         }
                         return response()->json(JSend::fail($top_up->getErrors())->asArray());
                     }
                 }
                 if ($new_ad['ad_id']) {
                     $ids_inc[] = $new_ad['ad_id'];
                 }
             }
             //3. Check if deleted data
             foreach ($older_data['ads'] as $key => $value) {
                 if (!in_array($value['ad_id'], $ids_inc)) {
                     $attributes['name'] = 'Deleted Top Up';
                     $attributes['ads_id'] = $older_data['ads'][$key]['ad_id'];
                     $attributes['transact_at'] = \Carbon\Carbon::now()->format('Y-m-d');
                     $attributes['travel_agent']['_id'] = $older_data['travel_agent']['_id'];
                     $attributes['travel_agent']['name'] = $older_data['travel_agent']['name'];
                     $attributes['credit']['started_at'] = $older_data['ads'][$key]['started_at'] * 1;
                     $attributes['credit']['initial_credit'] = $older_data['ads'][$key]['initial_credit'] * 1;
                     $attributes['credit']['daily_rate'] = $older_data['ads'][$key]['daily_rate'] * 1;
                     $attributes['credit']['today_balance'] = 0 * 1;
                     $attributes['credit']['credit_balance'] = (0 - $older_data['ads'][$key]['today_balance']) * 1;
                     $attributes['credit']['tags'] = $older_data['ads'][$key]['tags'];
                     $attributes['tour']['_id'] = $older_data['_id'];
                     $attributes['tour']['name'] = $older_data['name'];
                     $attributes['tour']['tags'] = $older_data['tags'];
                     $top_up = new TopUpLog();
                     $top_up->fill($attributes);
                     if (!$top_up->save()) {
                         $error_responses = [];
                         foreach ($top_up->getErrors() as $field => $errors) {
                             $error_responses[$field] = implode(', ', $errors);
                         }
                         return response()->json(JSend::fail($top_up->getErrors())->asArray());
                     }
                 }
             }
             $data->ads = $new_ads;
             if (!$data->save()) {
                 return response()->json(JSend::fail($data->getErrors())->asArray());
             }
         }
         return response()->json(JSend::success(['data' => $data])->asArray());
     } else {
         $error_responses = [];
         foreach ($data->getErrors() as $field => $errors) {
             $error_responses[$field] = implode(', ', $errors);
         }
         return response()->json(JSend::fail($data->getErrors())->asArray());
     }
 }
Beispiel #22
0
 public function del($id)
 {
     $tour = Tour::findOne($id);
     $tour->delete();
 }
Beispiel #23
0
<div class="tour-fields-form">

    <?php 
$form = ActiveForm::begin();
?>

    <?php 
echo $form->field($model, 'name')->textInput(['maxlength' => true]);
?>

    <?php 
echo $form->field($model, 'type')->textInput();
?>
    <?php 
echo $form->field($model, 'tour_id')->dropDownList(ArrayHelper::map(Tour::getTours(true), 'id', 'name'), ['prompt' => Yii::t('app', '-- Select tour --')]);
?>
    <?php 
echo $form->field($model, 'sort')->input(['number']);
?>


    <div class="form-group">
        <?php 
echo Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']);
?>
    </div>

    <?php 
ActiveForm::end();
?>
Beispiel #24
0
 /**
  * relation to tour table
  */
 public function getTours()
 {
     return $this->hasMany(Tour::className(), ['id_tourtype' => 'id']);
 }
Beispiel #25
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getTours()
 {
     return $this->hasMany(Tour::className(), ['concert_id' => 'id']);
 }
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getTour()
 {
     return $this->hasOne(Tour::className(), ['id' => 'tour_id']);
 }
Beispiel #27
0
 /**
  * [detailtour description]
  * @param  [type] $id [description]
  * @return [type]     [description]
  */
 public function detailtour($id)
 {
     $tourimages = Tour::getImageTour($id);
     $tour = Tour::getDetailAndInfoAround($id);
     return view('home.detailtour', compact('tourimages', 'tour'));
 }
Beispiel #28
0
 */
/**
 * Created by PhpStorm.
 * User: redmenote
 * Date: 07.01.16
 * Time: 16:58
 */
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use yii\widgets\LinkPager;
use yii\jui\AutoComplete;
use app\models\Tour;
$this->title = 'Расширенный поиск';
$this->params['breadcrumbs'][] = ['label' => 'Туры', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
$listdata = Tour::find()->select(['name as value', 'name as label'])->where(['status' => 1])->asArray()->all();
?>


<div class="add-tour">

    <?php 
$form = ActiveForm::begin(['action' => 'result', 'method' => 'get']);
?>

        <?php 
echo $form->field($model, 'search')->widget(AutoComplete::className(), ['clientOptions' => ['source' => $listdata], 'options' => ['class' => 'form-control']]);
?>
        <?php 
echo $form->field($model, 'category')->dropDownList(['name' => 'Название', 'org' => 'Организация', 'address' => 'Адрес', 'info' => 'Информация', 'tel' => 'Телефон']);
?>
Beispiel #29
0
 /**
  * [getDetailAndInfoAround description]
  * @param  [type] $id [description]
  * @return [type]     [description]
  */
 public static function getDetailAndInfoAround($id)
 {
     $tour = Tour::find($id);
     $tour->departure = Departure::find($tour->departure_id);
     $tour_relevant = DB::table('tours')->where('departure_id', $tour->departure_id)->take(4)->get();
     foreach ($tour_relevant as $key => $value) {
         $image = TourImage::where('tour_id', $value->id)->first();
         $tour_relevant[$key]->image = $image;
         $tour_relevant[$key]->periodNature = HomeController::periodNature($value->period);
     }
     $tour->tour_relevant = $tour_relevant;
     $tour->destinations = DB::table('destinations')->join('tour_destinations', 'destinations.id', '=', 'tour_destinations.destination_id')->where('tour_destinations.tour_id', $id)->get();
     return $tour;
 }
Beispiel #30
0
 function issue($tour_id, $schedule_id, $voucher_id, $user_id)
 {
     ///////////////
     // Load Tour //
     ///////////////
     $tour = Model::find($tour_id);
     if (!$tour) {
         return app()->abort(404);
     }
     //////////////////
     // GET SCHEDULE //
     //////////////////
     foreach ($tour->schedules as $schedule) {
         if (str_is($schedule_id, $schedule->_id)) {
             $selected_schedule = $schedule;
         }
     }
     if (!$selected_schedule) {
         return App()->abort(404);
     }
     ////////////////////////
     // GET EDITED VOUCHER //
     ////////////////////////
     foreach ($selected_schedule->vouchers as $voucher) {
         if ($voucher->_id == $voucher_id) {
             $selected_voucher = $voucher;
         }
     }
     if (!$selected_voucher) {
         return App()->abort(404);
     }
     ////////////////
     /// Load User //
     ////////////////
     $user = User::find($user_id);
     if (!$user) {
         return App()->abort(404);
     }
     //////////////////////
     // Generate Voucher //
     //////////////////////
     $issued_voucher = new IssuedVoucher();
     $issued_voucher->tour_id = $tour->_id;
     $issued_voucher->user_id = $user->_id;
     $issued_voucher->schedule_id = $selected_schedule->_id;
     $issued_voucher->voucher_id = $selected_voucher->_id;
     if ($issued_voucher->save()) {
         return response()->json(JSend::success(['count' => $count, 'data' => $issued_voucher->toArray()])->asArray())->setCallback($this->request->input('callback'));
     } else {
         return response()->json(JSend::fail($issued_voucher->getErrors())->asArray())->setCallback($this->request->input('callback'));
     }
 }