Exemplo n.º 1
0
 public function actionBook($id)
 {
     if (!Yii::app()->user->hasState("book_data")) {
         //			$backdata=  get_object_vars(json_decode(Yii::app()->user->getState("city_data")));
         $this->redirect(array("index"));
     }
     $bookdata = get_object_vars(json_decode(Yii::app()->user->getState("book_data")));
     $model = $this->loadModel($bookdata['sid']);
     $tour = $this->loadTR($model->city_id, $bookdata['tid']);
     $contact = new SegContacts();
     $ticket_count = 0;
     if (isset($_POST['SegScheduledTours'])) {
         $model->tourroute_id = $tour->idseg_tourroutes;
         if (isset($_POST['SegScheduledTours']['language_id'])) {
             $model->language_id = $_POST['SegScheduledTours']['language_id'];
         }
         if (isset($_POST['SegScheduledTours']['current_subscribers'])) {
             $ticket_count = (int) $_POST['SegScheduledTours']['current_subscribers'];
             if (is_null($model->current_subscribers)) {
                 $model->current_subscribers = 0;
             }
             $model->current_subscribers += $ticket_count;
             $model->TNmax_sched = $tour->TNmax;
         }
         if (isset($_POST['SegContacts'])) {
             $contact->attributes = $_POST['SegContacts'];
             if ($contact->validate()) {
                 $contact->save();
                 Yii::app()->user->setState('book_data', null);
                 //save booking
                 $id_user = $contact->idcontacts;
                 //save guidestourinvoice
                 $guidestourinvoices = new SegGuidestourinvoices();
                 $guidestourinvoices->creationDate = $model->date;
                 $guidestourinvoices->cityid = $model->city_id;
                 $guidestourinvoices->sched_tourid = $model->tourroute_id;
                 $guidestourinvoices->guideNr = $model->guide1_id;
                 $guidestourinvoices->status = 0;
                 $guidestourinvoices->contacts_id = $id_user;
                 $guidestourinvoices->id_sched = $model->idseg_scheduled_tours;
                 $guidestourinvoices->save();
                 $model->save();
                 //save guidestourinvoicecustomers
                 $id_invoice = $guidestourinvoices->idseg_guidesTourInvoices;
                 for ($j = 0; $j < $ticket_count; $j++) {
                     $guidestourinvoicescustomers = new SegGuidestourinvoicescustomers();
                     $guidestourinvoicescustomers->customersName = $contact->firstname . ' ' . $contact->surname;
                     //					$guidestourinvoicescustomers->price = $tour->base_price;
                     $guidestourinvoicescustomers->price = 0;
                     $guidestourinvoicescustomers->cityid = $model->city_id;
                     $guidestourinvoicescustomers->tourInvoiceid = $id_invoice;
                     //$guidestourinvoicescustomers->CustomeInvoicNumber = ;
                     $b = $tour->city['seg_cityname'][0];
                     $year = date('y', time());
                     $max = Yii::app()->db->createCommand("SELECT max(CustomerInvoiceNumber) from seg_guidestourinvoicescustomers where cityid=" . $tour->cityid)->queryScalar();
                     $max_i = $max + 1;
                     $guidestourinvoicescustomers->KA_string = 'KA' . $b . $year . '/' . $max_i;
                     $guidestourinvoicescustomers->CustomerInvoiceNumber = $max_i;
                     $guidestourinvoicescustomers->isPaid = 0;
                     //					$guidestourinvoicescustomers->origin_booking = $id_book;
                     $guidestourinvoicescustomers->save();
                 }
                 $date_ex = date('d/m/Y', $model->date_now);
                 $x1 = strtotime($model->starttime) - strtotime("00:00:00");
                 $x2 = $tour->standard_duration * 60;
                 $x3 = $x1 + $x2;
                 $x4 = $x3 + strtotime("00:00:00");
                 $x5 = date('H:i:s', $x4);
                 $tourend = $x5;
                 $guidename = $model->user_ob->contact_ob->firstname;
                 $guidemnr = $model->user_ob->contact_ob->phone;
                 $message = "Thank you for booking your city tour with Cherry Tours " . $model->city_ob->seg_cityname;
                 $message .= "\n";
                 $message .= "\nWe have just reserved the following tour date for you:";
                 $message .= "\n" . $date_ex;
                 $message .= "\nTour start: " . $model->starttime . " (Please show up at the assigned meeting point about 10 minutes before tour start.)";
                 $message .= "\n";
                 $message .= "\nEnd of tour: " . $tourend;
                 $message .= "\nTour route: " . $model->tourroute_ob->name;
                 $message .= "\nTour language: " . $model->language_ob->englishname;
                 $message .= "\nTour guide: " . $guidename;
                 $message .= "\nGuide phone: " . $guidemnr . "(for last-minute requests regarding weather or meeting point)";
                 $message .= "\nFurthermore we recommend:";
                 $message .= "\n- comfortable shoes, no high heels";
                 $message .= "\n- adequate clothing (below 15 degrees centigrade, we especially recommend wearing warm clothes and gloves)";
                 $message .= "\n- sunglasses, if necessary sun protection etc.";
                 $message .= "\n";
                 $message .= "\nPayment:";
                 $message .= "\n- On site";
                 $message .= "\n";
                 $message .= "\nWe accept the following methods of payment:";
                 $message .= "\n- Cash in EUR";
                 $message .= "\n- EC";
                 $message .= "\n- Credit cards (Visa, Master Card, American Express, JCB Cards, Union Pay)";
                 $message .= "\n- Vouchers purchased at Cherry Tours";
                 $message .= "\n";
                 $message .= "\nWeather:";
                 $message .= "\nIf the weather forecast shows a high chance of rain at the tour date, we will contact you near-term via email, SMS or phone and inform you if the tour has to be cancelled.";
                 $message .= "\nIf it rains despite a positive weather forecast, the tour guide will decide on-site if the tour can take place. Generally, the tour is arranged along a route where you can always take cover in case of a short rain shower.";
                 $message .= "\n";
                 $message .= "\n";
                 $name_forms = $model->city_ob->seg_cityname;
                 $to = $contact->email;
                 if ($this->sendMail($to, $name_forms, $message)) {
                     $stuttgart_link = Yii::app()->createUrl('thankyou');
                     //				    header( 'Location: '.$stuttgart_link.'?id=1' );
                 }
                 //			}
                 $this->render('result', array('post' => $_POST, 'contacts' => $contact->attributes, 'model' => $model->attributes));
                 return;
             }
         }
     }
     $this->render('book', array('post' => $_POST, 'model' => $model, 'contact' => $contact, 'tour' => $tour));
 }
Exemplo n.º 2
0
 public function actionBook($id)
 {
     $sid = '';
     if (Yii::app()->user->hasState("book_data") || $_POST['sid']) {
         if (Yii::app()->user->getState("book_data")) {
             $bookdata = get_object_vars(json_decode(Yii::app()->user->getState("book_data")));
             $sid = $bookdata['sid'];
             $tid = $bookdata['tid'];
         }
         //var_dump($sid);
         //var_dump($_POST); exit;
         if (isset($_POST['sid'])) {
             $sid = $_POST['sid'] * 1;
         }
         if (isset($_POST['tid'])) {
             $tid = $_POST['tid'] * 1;
         }
         //
         $model = $this->loadModel($sid);
         $tour = $this->loadTR($model->city_id, $tid);
     }
     $contact = new SegContacts();
     $ticket_count = 0;
     if (isset($_POST['SegScheduledTours'])) {
         $model->tourroute_id = $tour->idseg_tourroutes;
         if (isset($_POST['SegScheduledTours']['language_id'])) {
             $model->language_id = $_POST['SegScheduledTours']['language_id'];
         }
         if (isset($_POST['SegScheduledTours']['current_subscribers'])) {
             $ticket_count = (int) $_POST['SegScheduledTours']['current_subscribers'];
             if (is_null($model->current_subscribers)) {
                 $model->current_subscribers = 0;
             }
             $model->current_subscribers += $ticket_count;
             $model->TNmax_sched = $tour->TNmax;
         }
         if (isset($_POST['SegContacts'])) {
             $contact->attributes = $_POST['SegContacts'];
             if ($contact->validate()) {
                 $contact->save();
                 Yii::app()->user->setState('book_data', null);
                 //save booking
                 $id_user = $contact->idcontacts;
                 //save guidestourinvoice
                 $guidestourinvoices = new SegGuidestourinvoices();
                 $guidestourinvoices->creationDate = $model->date;
                 $guidestourinvoices->cityid = $model->city_id;
                 $guidestourinvoices->sched_tourid = $model->tourroute_id;
                 $guidestourinvoices->guideNr = $model->guide1_id;
                 $guidestourinvoices->status = 0;
                 $guidestourinvoices->contacts_id = $id_user;
                 $guidestourinvoices->id_sched = $model->idseg_scheduled_tours;
                 $guidestourinvoices->save();
                 $model->save();
                 //save guidestourinvoicecustomers
                 $id_invoice = $guidestourinvoices->idseg_guidesTourInvoices;
                 for ($j = 0; $j < $ticket_count; $j++) {
                     $guidestourinvoicescustomers = new SegGuidestourinvoicescustomers();
                     $guidestourinvoicescustomers->customersName = $contact->firstname . ' ' . $contact->surname;
                     //$guidestourinvoicescustomers->price = $tour->base_price;
                     $guidestourinvoicescustomers->price = 0;
                     $guidestourinvoicescustomers->cityid = $model->city_id;
                     $guidestourinvoicescustomers->tourInvoiceid = $id_invoice;
                     //$guidestourinvoicescustomers->CustomeInvoicNumber = ;
                     $b = $tour->city['seg_cityname'][0];
                     $year = date('y', time());
                     $max = Yii::app()->db->createCommand("SELECT max(CustomerInvoiceNumber) from seg_guidestourinvoicescustomers where cityid=" . $tour->cityid)->queryScalar();
                     $max_i = $max + 1;
                     $guidestourinvoicescustomers->KA_string = 'KA' . $b . $year . '/' . $max_i;
                     $guidestourinvoicescustomers->CustomerInvoiceNumber = $max_i;
                     $guidestourinvoicescustomers->isPaid = 0;
                     //$guidestourinvoicescustomers->origin_booking = $id_book;
                     $guidestourinvoicescustomers->save();
                 }
                 $to = $contact->email;
                 //////////text email
                 $otpr = $stopt = 0;
                 /////
                 $starttime = str_replace('00:00', '00', $model->starttime);
                 $tourdate = $this->dateEn($model->date);
                 if (!empty($model->duration)) {
                     $stopt = $model->duration;
                 } else {
                     $stopt = $tour->standard_duration;
                 }
                 $stoptime = date("H:i", strtotime($model->date . ' ' . $model->starttime) + $stopt * 60) . ' Uhr';
                 $tour_name = $model->city_ob->seg_cityname . ' ' . $tour->name;
                 ////lang
                 $text_lang = $model->language_ob->germanname;
                 if (is_null($model->language_id)) {
                     $lang = SegLanguagesGuides::model()->with('languages')->findAll('users_id=' . $model->guide1_id);
                     $zp = $text_lang = '';
                     foreach ($lang as $val) {
                         $text_lang .= $zp . $val->languages->germanname;
                         $zp = ', ';
                     }
                 }
                 ////point
                 $meetingpoint = $tour->meetingpoint_description;
                 if (Yii::app()->language == 'en') {
                     $meetingpoint = $tour->meetingpoint_description_en;
                 }
                 //settings template mail
                 $mailtext = array('city_name' => $model->city_ob->seg_cityname, 'city_en' => $model->city_ob->webadress_en, 'tour_date' => $tourdate, 'tour_starttime' => $starttime, 'tour_stoptime' => $stoptime, 'tour_guest' => $ticket_count, 'tour_name' => $tour_name, 'tour_lang' => $text_lang, 'tour_guide_name' => $model->user_ob->guidename, 'tour_guide_tel' => $model->user_ob->contact_ob->phone, 'contact_name' => $_POST['SegContacts']['firstname'] . ' ' . $_POST['SegContacts']['surname'], 'contact_street' => $_POST['SegContacts']['additional_address'] . '<br>' . $_POST['SegContacts']['street'], 'contact_city' => $_POST['SegContacts']['city'], 'contact_land' => $_POST['SegContacts']['country'], 'contact_tel' => $_POST['SegContacts']['phone'], 'contact_email' => $_POST['SegContacts']['email'], 'meetingpoint' => $meetingpoint);
                 //template mail
                 $msg = $this->renderPartial('../thankyousend/tour_mail', $mailtext, TRUE);
                 if ($this->sendMail($to, 'Cherrytours: ' . $tour_name, $msg)) {
                     // send mail admin
                     //$email_admin = $model->city_ob->mailInfo;
                     $email_admin = '*****@*****.**';
                     $msg = $this->renderPartial('../thankyousend/tour_mail_admin', $mailtext, TRUE);
                     $this->sendMail($email_admin, 'Cherrytours: New client ' . $tour_name, $msg);
                     ///
                     $this->render('thankyou', array('model' => $model, 'tour' => $tour, 'post' => $_POST, 'sid' => $sid, 'tid' => $tid, 'guest' => $ticket_count));
                 } else {
                     $this->render('../thankyousend/mail_success', array('text_link' => 'Anwendung beibehalten. Ich kann nicht einen Brief schicken.', 'city_en' => $model->city_ob->webadress_en));
                 }
                 //unset($_POST);
             } else {
                 echo 'goto_book';
                 $this->render('book', array('post' => $_POST, 'model' => $model, 'contact' => $contact, 'tour' => $tour, 'sid' => $sid, 'tid' => $tid));
             }
         }
     } else {
         $this->render('book', array('post' => $_POST, 'model' => $model, 'contact' => $contact, 'tour' => $tour, 'sid' => $sid, 'tid' => $tid));
     }
 }
Exemplo n.º 3
0
    public function actionBooky($id_sched)
	{
		$tour=null;
        $scheduled = SegScheduledTours::model()->findByPk($id_sched);
 		/*tourroutes*/
        if($scheduled->tourroute_id==null){
            $criteria_tours_link = new CDbCriteria;
            $criteria_tours_link->condition = 'usersid=:usersid';
            $criteria_tours_link->params = array(':usersid' => $scheduled->guide1_id);
            $criteria_tours_link->join = 'LEFT JOIN `seg_guides_tourroutes` ON ((`seg_guides_tourroutes`.`tourroutes_id` = `t`.`id_tour_categories`) AND(`t`.`cityid` = '.$scheduled->city_id.'))';
            $tours_guide = SegTourroutes::model()->findAll($criteria_tours_link);
        }else{
			$criteria_tours_link2 = new CDbCriteria;
            $criteria_tours_link2->condition = 'idseg_tourroutes=:idseg_tourroutes';
            $criteria_tours_link2->params = array(':idseg_tourroutes' => $scheduled->tourroute_id);
            $tours_guide = SegTourroutes::model()->findAll($criteria_tours_link2);
			$criteria = new CDbCriteria;
			 $criteria->condition = 'cityid=:cityid AND idseg_tourroutes=:id_tour_categories';
			 $criteria->params = array(':cityid' => $scheduled->city_id,':id_tour_categories'=>$scheduled->tourroute_id);
			 $tour = SegTourroutes::model()->find($criteria);
		 }
		 /*languages*/
        if($scheduled->language_id==null){
            $criteria_lan_link = new CDbCriteria;
            $criteria_lan_link->condition = 'users_id=:users_id';
            $criteria_lan_link->params = array(':users_id' => $scheduled->guide1_id);
            $criteria_lan_link->join = 'LEFT JOIN `seg_languages_guides` ON `seg_languages_guides`.`languages_id` = `t`.`id_languages`';
            $languages_guide = Languages::model()->findAll($criteria_lan_link);
        }else{
            $languages_guide = Languages::model()->findByPk($scheduled->language_id);
        } 
        
        //$model = new SegContacts;
        
        $contact = new Bookq;
        
       	if(isset($_POST['Bookq']))
		{
			
			if(is_null($scheduled->tourroute_id))
			{
				$scheduled->tourroute_id = $_POST['Bookq']['tour'];
				$scheduled->language_id = $_POST['Bookq']['language'];
				$criteria = new CDbCriteria;
				 $criteria->condition = 'cityid=:cityid AND idseg_tourroutes=:id_tour_categories';
				 $criteria->params = array(':cityid' => $scheduled->city_id,':id_tour_categories'=>$scheduled->tourroute_id);
				 $tour = SegTourroutes::model()->find($criteria);
			}
			$contact->attributes=$_POST['Bookq'];
			
			$ticket_array = SegTourroutes::model()->findByPk($scheduled->tourroute_id);
                        $ticket_count =	$contact->tickets;

/*			
			$cat_i = $_POST['Bookq']['cat_hidden'];
			if($cat_i == 1)$ticket_count = $_POST['Bookq']['tickets1'];
			if($cat_i == 2)$ticket_count = $_POST['Bookq']['tickets2'];
			if($cat_i == 3)$ticket_count = $_POST['Bookq']['tickets3'];
			$contact->tickets = $ticket_count;
  */
   
                        if($contact->validate()){
								
				//save contact
				$user_contact =  new SegContacts;
    
				$user_contact->firstname = $_POST['Bookq']['firstname'];
				$user_contact->surname = $_POST['Bookq']['lastname'];
				$user_contact->additional_address = $_POST['Bookq']['additional_address'];
				$user_contact->city = $_POST['Bookq']['city'];
				$user_contact->street = $_POST['Bookq']['street'];
				$user_contact->postalcode = $_POST['Bookq']['postalcode'];
//				$user_contact->house = $_POST['Bookq']['house'];
				$user_contact->country = $_POST['Bookq']['country'];
				$user_contact->phone = $_POST['Bookq']['phone'];
				$user_contact->email = $_POST['Bookq']['email'];
				$user_contact->save();

				$id_user = $user_contact->idcontacts;
				//save guidestourinvoice
				$guidestourinvoices = new SegGuidestourinvoices;
				$guidestourinvoices->creationDate = $scheduled->date;
				$guidestourinvoices->cityid = $scheduled->city_id;
				$guidestourinvoices->sched_tourid = $scheduled->tourroute_id;
				$guidestourinvoices->guideNr = $scheduled->guide1_id;
				$guidestourinvoices->status = 0;
				$guidestourinvoices->contacts_id = $id_user;
				$guidestourinvoices->id_sched = $scheduled->idseg_scheduled_tours;
				$guidestourinvoices->save();	
				
			
				
				//save guidestourinvoicecustomers
				$id_invoice = $guidestourinvoices->idseg_guidesTourInvoices;
				for($j=0;$j<$ticket_count;$j++){
					$guidestourinvoicescustomers = new SegGuidestourinvoicescustomers;
					$guidestourinvoicescustomers->customersName = $user_contact->firstname.' '.$user_contact->surname;
//					$guidestourinvoicescustomers->price = $tour->base_price;
					$guidestourinvoicescustomers->price = 0;
					$guidestourinvoicescustomers->cityid = $tour->cityid;
					
					$guidestourinvoicescustomers->tourInvoiceid = $id_invoice;
					
					//$guidestourinvoicescustomers->CustomeInvoicNumber = ;
					$b = $tour->city['seg_cityname']{0};
					$year = date('y',time());
					$max= Yii::app()->db->createCommand("SELECT max(CustomerInvoiceNumber) from seg_guidestourinvoicescustomers where cityid=".$scheduled->city_id)->queryScalar();
					$max_i = $max+1;
					
					$guidestourinvoicescustomers->KA_string = 'KA'.$b.$year.'/'.$max_i;
					$guidestourinvoicescustomers->CustomerInvoiceNumber = $max_i;
					$guidestourinvoicescustomers->isPaid = 0;
//					$guidestourinvoicescustomers->origin_booking = $id_book;
					
					
					$guidestourinvoicescustomers->save();
				}
				
            	//save scheduled
				$scheduled->TNmax_sched = $ticket_array->TNmax;
				if($scheduled->current_subscribers==null){
					$scheduled->current_subscribers=$ticket_count;
				}else{
					$scheduled->current_subscribers=$scheduled->current_subscribers +$ticket_count;
				}
				$scheduled->save();
				
            	//email
				$date_ex = date('d/m/Y',$scheduled->date_now);
				$x1 = strtotime($scheduled->starttime) - strtotime("00:00:00");
				$x2 = $tour->standard_duration*60;
				$x3 = $x1+$x2;
				$x4 = $x3+strtotime("00:00:00");
				$x5 = date('H:i:s',$x4);
				$tourend = $x5;
				
				$guidename = $scheduled->user_ob->contact_ob->firstname;
				$guidemnr = $scheduled->user_ob->contact_ob->phone;
				
				$message="Thank you for booking your city tour with Cherry Tours ".$scheduled->city_ob->seg_cityname;
				$message.="\n";
				$message.="\nWe have just reserved the following tour date for you:";
				$message.="\n".$date_ex;
				$message.="\nTour start: ".$scheduled->date_now." (Please show up at the assigned meeting point about 10 minutes before tour start.)";
				$message.="\n";
				$message.="\nEnd of tour: ".$tourend;
				$message.="\nTour route: ".$scheduled->tourroute_ob->name;
				$message.="\nTour language: ".$scheduled->language_ob->englishname;
				$message.="\nTour guide: ".$guidename;
				$message.="\nGuide phone: ".$guidemnr."(for last-minute requests regarding weather or meeting point)";
				
				$message.="\nFurthermore we recommend:";
				$message.="\n- comfortable shoes, no high heels";
				$message.="\n- adequate clothing (below 15 degrees centigrade, we especially recommend wearing warm clothes and gloves)";
				$message.="\n- sunglasses, if necessary sun protection etc.";
				$message.="\n";
				$message.="\nPayment:";
				$message.="\n- On site";
				$message.="\n";
				$message.="\nWe accept the following methods of payment:";
				$message.="\n- Cash in EUR";
				$message.="\n- EC";
				$message.="\n- Credit cards (Visa, Master Card, American Express, JCB Cards, Union Pay)";
				$message.="\n- Vouchers purchased at Cherry Tours";
				$message.="\n";
				
				$message.="\nWeather:";
				$message.="\nIf the weather forecast shows a high chance of rain at the tour date, we will contact you near-term via email, SMS or phone and inform you if the tour has to be cancelled.";
				$message.="\nIf it rains despite a positive weather forecast, the tour guide will decide on-site if the tour can take place. Generally, the tour is arranged along a route where you can always take cover in case of a short rain shower."; 
				$message.="\n";
				$message.="\n";
				
				$name_forms = $scheduled->city_ob->seg_cityname;
				$to = $user_contact->email;
        			if ($this->sendMail($to, $name_forms, $message))
				{
					$this->redirect(array('current','id_sched'=>$id_sched));
				
				}
			}
		}
		
//		$criteria_cat = new CDbCriteria;
//        $criteria_cat->condition = 'cityid=:cityid AND id_tour_categories=:id_tour_categories';
//        $criteria_cat->params = array(':cityid' => $scheduled->city_id,':id_tour_categories'=>$cat);
//		$cat_item = SegTourroutes::model()->find($criteria_cat)->idseg_tourroutes;

				
		$test=array('guide'=>$this->loadGuide(),'tours'=>$this->loadTours(),'todo'=>$this->loadUnreported());

        $this->render('book',array(
			'scheduled'=>$scheduled,
			'contact'=>$contact,
			'tour'=>$tour,
			'tours_guide'=>$tours_guide,
			'languages_guide'=>$languages_guide,
			'info'=>$test,

				));
    }