예제 #1
0
 public function actionSerachMiles()
 {
     $companyServiceSum = array();
     $sumCompanyAdnlser = array();
     $sumadminAdnlser = array();
     // code to get the miles
     /*$theta = $lon1 - $lon2;
       $dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) +  cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta));
       $dist = acos($dist);
       $dist = rad2deg($dist);
       $miles = $dist * 60 * 1.1515;
       */
     //echo "<pre>";print_r($_REQUEST);die;
     $requestCleaningPage = Yii::app()->session['CleaningReqst'];
     //echo "<pre>";print_r($request['Cleaning']);die;
     $ses = Yii::app()->session['CleaningDetail'];
     //echo "<pre>";print_r($ses);die;
     $serTypeId = Yii::app()->session['ServiceTypeId'];
     $zip = $ses['CleaningTime']['PostCode'];
     $cleaningDate = $ses['CleaningTime']['CleaningDate'];
     $time = $ses['CleaningTime']['time'];
     // code to calculate the postcodes within radius
     //echo "<pre>";print_r($_REQUEST);die;
     if (isset($_REQUEST['Cleaning']) && is_array($_REQUEST['Cleaning'])) {
         if (key_exists('Property', $_REQUEST['Cleaning'])) {
             $property = $_REQUEST['Cleaning']['Property'];
         } else {
             $property = '';
         }
         $baths = $_REQUEST['Cleaning']['Bathrooms'];
         $beds = $_REQUEST['Cleaning']['Bedrooms'];
     }
     // get the customer lat and long from where we want to calculate other postcodes
     $recUk = UkPostcodes::model()->findByPk($zip);
     $r = 3959;
     //earth radius in miles
     //$d=5.6;
     $d = $_REQUEST['mile'];
     //$d=$_REQUEST['mile']*60*1.1515;
     $c = count($recUk);
     if ($c > 0) {
         $lat1 = $recUk->latitude;
         $lon1 = $recUk->longitude;
         $nlat1 = deg2rad($lat1);
         $nlon1 = deg2rad($lon1);
         $latN = rad2deg(asin(sin(deg2rad($lat1)) * cos($d / $r) + cos(deg2rad($lat1)) * sin($d / $r) * cos(deg2rad(0))));
         $latS = rad2deg(asin(sin(deg2rad($lat1)) * cos($d / $r) + cos(deg2rad($lat1)) * sin($d / $r) * cos(deg2rad(180))));
         $lonE = rad2deg(deg2rad($lon1) + atan2(sin(deg2rad(90)) * sin($d / $r) * cos(deg2rad($lat1)), cos($d / $r) - sin(deg2rad($lat1)) * sin(deg2rad($latN))));
         $lonW = rad2deg(deg2rad($lon1) + atan2(sin(deg2rad(270)) * sin($d / $r) * cos(deg2rad($lat1)), cos($d / $r) - sin(deg2rad($lat1)) * sin(deg2rad($latN))));
         $query = "SELECT * from ccobs_service_user WHERE (lat <= {$latN} AND lat >= {$latS} AND longitude <= {$lonE} AND longitude >= {$lonW}) AND (lat != {$lat1} AND longitude != {$lon1}) AND city != ' ' ORDER BY   lat, longitude ";
         $dataReader = Yii::app()->db->createCommand($query)->query();
         $res = $dataReader->readAll();
         if (!empty($res)) {
             foreach ($res as $i => $noOfUsers) {
                 $noUsrId[] = $noOfUsers['id'];
                 //$compNam[]=$noOfUsers['company_name'];
                 $compNam[] = $noOfUsers['company_name'] . "+" . $noOfUsers['id'];
                 $latitude[] = $noOfUsers['lat'];
                 $longitude[] = $noOfUsers['longitude'];
                 $nlatitude = deg2rad($noOfUsers['lat']);
                 $nlongitude = deg2rad($noOfUsers['longitude']);
                 $delta_lat = $nlatitude - $nlat1;
                 $delta_lon = $nlongitude - $nlon1;
                 $temp = pow(sin($delta_lat / 2.0), 2) + cos($nlatitude) * cos($lat1) * pow(sin($delta_lon / 2.0), 2);
                 $EARTH_RADIUS = 3956;
                 $distance[] = $EARTH_RADIUS * 2 * atan2(sqrt($temp), sqrt(1 - $temp));
                 $compName = array_combine($distance, $compNam);
                 //$compName=array_combine($distance);
             }
             //echo "<pre>";print_r($compName);die;
             /* calculate the new price for updated fields here*/
             //echo $serTypeId;die;
             foreach ($res as $nearbycomp) {
                 $serviceTypePrice = PriceAdmin::model()->findAll(array('condition' => 'service_id=:service_id AND service_type_id=:service_type_id', 'params' => array(':service_id' => $nearbycomp['id'], ':service_type_id' => $serTypeId)));
                 foreach ($serviceTypePrice as $serP) {
                     $array[$serP['service_id']] = array('Bedrooms' => $serP['bedroom'], 'Bathrooms' => $serP['bathroom'], 'LivingRoom' => $serP['living_room'], 'KitchenStaircases' => $serP['kitchen_staircases'], 'CarpetsInteriorWindows' => $serP['carpets_interior_windows'], 'Property' => $serP['property'], 'Desk' => $serP['desk'], 'Cupboards' => $serP['cupboards'], 'Kitchen' => $serP['kitchen'], 'Staircases' => $serP['staircases'], 'Elevator' => $serP['elevator']);
                 }
                 $providerAdnlPrice = ProviderAdditionalprices::model()->findAll(array('condition' => 'service_id=:service_id AND service_type_id=:service_type_id', 'params' => array(':service_id' => $nearbycomp['id'], ':service_type_id' => $serTypeId)));
                 foreach ($providerAdnlPrice as $servicePro) {
                     $getIdSerTyAdnlPrice[$servicePro['service_id']][$servicePro['servicetype_additional_id']] = $servicePro['provider_adnlprice'];
                 }
                 //echo "<pre>";print_r($providerAdnlPrice);
             }
             //die;
             //echo "<pre>";print_r($getIdSerTyAdnlPrice);die;
             //price calculation for service types starts here
             foreach ($array as $companyId => $values) {
                 if (!empty($request['Cleaning'])) {
                     foreach ($request['Cleaning'] as $service => $number) {
                         $serviceVal = $values[$service];
                         $companyServiceSum[$companyId] += $number * $serviceVal;
                     }
                 } else {
                     //echo "<pre>";print_r($requestCleaningPage);die;
                     foreach ($requestCleaningPage['Cleaning'] as $service => $number) {
                         $serviceVal = $values[$service];
                         if (key_exists($companyId, $companyServiceSum)) {
                             $companyServiceSum[$companyId] += $number * $serviceVal;
                         }
                     }
                 }
             }
             //price calculation for service types ends here
             //echo "<pre>";print_r($_REQUEST);
             //echo "<pre>";print_r($getIdSerTyAdnlPrice);
             //echo "<pre>";print_r($companyServiceSum);
             //price calculation for additionl service having price added by company
             foreach ($getIdSerTyAdnlPrice as $cmpnyId => $priceCompAdnl) {
                 //$companyId[]=$cmpnyId;
                 if (!empty($request['Additional'])) {
                     foreach ($request['Additional'] as $key => $value) {
                         $adnlvalues = $priceCompAdnl[$key];
                         //echo "<pre>";print_r($key);
                         if (key_exists($cmpnyId, $sumCompanyAdnlser)) {
                             $sumCompanyAdnlser[$cmpnyId] += $value * $adnlvalues;
                         }
                     }
                 } else {
                     foreach ($requestCleaningPage['Additional'] as $key => $value) {
                         $adnlvalues = $priceCompAdnl[$key];
                         //echo "<pre>";print_r($key);
                         if (key_exists($cmpnyId, $sumCompanyAdnlser)) {
                             $sumCompanyAdnlser[$cmpnyId] += $value * $adnlvalues;
                         }
                     }
                 }
             }
             //echo "<pre>";print_r($sumCompanyAdnlser);
             //price calculation for additional service having price added by company
             $serTypel = ServicetypeAdditionalservices::model()->findAll(array('condition' => 'service_type_id=:service_type_id', 'params' => array(':service_type_id' => $serTypeId)));
             foreach ($res as $nearbycomp) {
                 foreach ($serTypel as $priceAdnlAdmin) {
                     //if($nearbycomp['id']!=)
                     $admnAdnlPrice[$nearbycomp['id']][$priceAdnlAdmin['id']] = $priceAdnlAdmin['additional_service_price'];
                 }
             }
             // echo $companyId;die;
             //echo "<pre>";print_r($admnAdnlPrice);die;
             //echo "<pre>";print_r($serTypel);die;
             foreach ($admnAdnlPrice as $Id => $priceAdminAdnl) {
                 //$companyId[]=$cmpnyId;
                 if (!empty($request['Additional'])) {
                     foreach ($request['Additional'] as $sky => $v) {
                         $adminadnlvalues = $priceAdminAdnl[$sky];
                         //echo "<pre>";print_r($key);
                         if (key_exists($Id, $sumadminAdnlser)) {
                             $sumadminAdnlser[$Id] += $v * $adminadnlvalues;
                         }
                     }
                 } else {
                     foreach ($requestCleaningPage['Additional'] as $sky => $v) {
                         $adminadnlvalues = $priceAdminAdnl[$sky];
                         //echo "<pre>";print_r($key);
                         if (key_exists($Id, $sumadminAdnlser)) {
                             $sumadminAdnlser[$Id] += $v * $adminadnlvalues;
                         }
                     }
                 }
             }
             //echo "<pre>";print_r($sumadminAdnlser);die;
             $finalAdnlvalues = array_replace($sumadminAdnlser, $sumCompanyAdnlser);
             // code to sum the service types and additional service
             $sums = array();
             foreach (array_keys($companyServiceSum + $finalAdnlvalues) as $key) {
                 $sums[$key] = (isset($companyServiceSum[$key]) ? $companyServiceSum[$key] : 0) + (isset($finalAdnlvalues[$key]) ? $finalAdnlvalues[$key] : 0);
             }
             //echo "<pre>";print_r($sums);
             //get the price for per mile
             $dist = DistanceCoverage::model()->findAll();
             foreach ($dist as $dkey => $dprice) {
                 $distprice[$dprice['service_id']] = $dprice['price_per_mile'];
             }
             $total = array();
             foreach (array_keys($sums + $distprice) as $k) {
                 $total[$k] = (isset($sums[$k]) ? $sums[$k] : 0) + (isset($distprice[$k]) ? $distprice[$k] : 0);
             }
             //echo "<pre>";print_r($total);die;
             // code to get the rating
             foreach ($compName as $ratingIds) {
                 $serIds = explode('+', $ratingIds);
                 $rateIds[] = $serIds['1'];
                 //echo "<pre>";print_r($rateIds);
             }
             //die;
             foreach ($rateIds as $ratingId) {
                 //echo "<pre>";print_r($ratingId);
                 $ratingsreview[$ratingId] = ServiceReview::model()->findAll(array("select" => "rating", 'condition' => 'service_id=:service_id', 'params' => array(':service_id' => $ratingId)));
                 // echo "<pre>";print_r($review);
             }
             //die;
             $res12 = array_combine($rateIds, $ratingsreview);
             //echo "<pre>";print_r($res12);
             $sumArrayRatingAvg = array();
             foreach ($res12 as $k1 => $sub) {
                 foreach ($sub as $id => $value) {
                     if (key_exists($k1, $sumArrayRatingAvg)) {
                         $sumArrayRatingAvg[$k1] += $value['rating'];
                     }
                 }
                 if (count($res12[$k1]) && key_exists($k1, $sumArrayRatingAvg)) {
                     $sumArrayRatingAvg[$k1] /= count($res12[$k1]);
                 }
             }
             //echo "<pre>";print_r($companyServiceSum);
             //echo "<pre>";print_r($finalAdnlvalues);
             // echo "<pre>";print_r($withinrange);
             //echo "<pre>";print_r($sums);die;
             /*calculate the price for updated fields ends here*/
             $this->renderPartial('miles', array('sums' => $total, 'CompanyName' => $compName, 'd' => $d, 'sumArrayRatingAvg' => $sumArrayRatingAvg, 'requestCleaningPage' => $requestCleaningPage));
             //echo $d;die;
         } else {
             $d = $_REQUEST['mile'];
             $this->renderPartial('milesEmpty', array('d' => $d));
         }
     } else {
         $d = $_REQUEST['mile'];
         $this->renderPartial('milesEmpty', array('d' => $d));
     }
 }
예제 #2
0
 public function actionDashboard()
 {
     $model = new ServiceUser();
     $msg = new ConversationMsg();
     $msgDetail = new MsgDetails();
     $admnPrice = new PriceAdmin();
     $additional = new AdditionalServicePrice();
     $globalAd = new AdditionalServices();
     $proadnlPrice = new ProviderAdditionalprices();
     $distance = new DistanceCoverage();
     //$converstion  =new MsgDetails;
     $serviceAd = new ServicetypeAdditionalservices();
     $loggedId = Yii::app()->session['loggedId'];
     //echo $loggedId;die;
     $email = $_SESSION['_registration__id'];
     //echo $email;die;
     //$rec=ServiceUser::model()->with('bookings')->findByAttributes(array('email'=>$email));
     $rec = ServiceUser::model()->with('bookings')->findByPk(array('id' => $loggedId));
     // echo "<pre>";print_r($loggedId);die;
     // echo "<pre>";print_r($rec);die;
     if (!empty($rec['bookings'])) {
         foreach ($rec['bookings'] as $to) {
             $serviceId[] = $to['customer_id'];
             $companyName[] = $to->customer['cname'] . " " . $to->customer['clname'];
             //echo "<pre>";print_r($to);
         }
         //die;
         $finalTo = array_combine($serviceId, $companyName);
     }
     $convMsg = ConversationMsg::model()->findAll(array('condition' => ' reciver_id=:id ', 'params' => array(':id' => $loggedId)));
     //echo "<pre>";print_r($convMsg);die;
     $inbox = MsgDetails::model()->findAll(array('condition' => 'tomsg=:tomsg AND inbox_dlt_status=:status', 'group' => 'conversation_id', 'params' => array(':tomsg' => $loggedId, ':status' => 0)));
     //echo "<pre>";print_r($inbox);die;
     foreach ($inbox as $conId) {
         $inboxDtal[] = MsgDetails::model()->findAll(array('condition' => 'conversation_id=:conversation_id AND inbox_dlt_status=:status', 'params' => array(':conversation_id' => $conId->conversation_id, ':status' => 0)));
         /*$count =MsgDetails::model()->findAll(array('condition'=>'conversation_id=:conversation_id AND tomsg=:tomsg','params'=>array(
                        
                          ':conversation_id'=>$conId->conversation_id,
                          ':tomsg'          =>$loggedId, 
          	)));*/
         $companyN = CustomerUser::model()->findAll(array('condition' => 'id=:id', 'params' => array(':id' => $conId->user_id)));
         //$numInbox=array_combine($count,$companyName);
         //$numInbox[]=count($count);
         //echo "<pre>";print_r($companyN);
     }
     //die;//echo "<pre>";print_r($inboxDtal);die;
     //select summ(*) as total from
     /*$inbox=MsgDetails::model()->findByAttributes(
     		    //array('to'=>$loggedId),
     		    array(
     		        'condition'=>'to=:to', 
     		        'params'=>array(':to'=>$loggedId)
     		    )
     		); */
     //$inbox=MsgDetails::model()->findByAttributes(array('to'=>$loggedId));
     //echo "<pre>";print_r($inbox);die;
     /*get the details for messages to show on dashboard ends here*/
     /*code to get the sender name here*/
     $find = ConversationMsg::model()->findAll('sender_id<>' . $loggedId);
     //echo "<pre>";print_r($find);die;
     foreach ($find as $senderId) {
         $count = MsgDetails::model()->findAll(array('condition' => 'conversation_id=:id AND user_id=:user_id', 'params' => array(':id' => $senderId['id'], ':user_id' => $loggedId)));
         //echo "<pre>";print_r($count);
         $c = count($count);
         //echo $c;
         $comName = CustomerUser::model()->findAll(array('condition' => 'id=:id', 'params' => array(':id' => $senderId['sender_id'])));
         // echo "<pre>";print_r($comName);
     }
     // die;
     //$sntMsg=ConversationMsg::model()->findAll();
     /*code to show the list for sent messages*/
     $sentMsg = ConversationMsg::model()->findAll(array('condition' => 'sender_id=:sender_id', 'params' => array(':sender_id' => $loggedId)));
     //echo "<pre>";print_r($sentMsg);die;
     $sentbox = MsgDetails::model()->findAll(array('condition' => 'user_id=:user_id', 'params' => array(':user_id' => $loggedId)));
     $sentBox = MsgDetails::model()->findAll(array('condition' => 'user_id=:user_id AND sent_dlt_status=:status', 'group' => 'conversation_id', 'params' => array(':user_id' => $loggedId, ':status' => 0)));
     /*foreach($sentBox as $conId)
       {*/
     /*$sentBoxDtl=MsgDetails::model()->findAll(array('condition'=>'conversation_id=:conversation_id',
              //'group'=>'conversation_id',    
             'params'=>array(
                          ':conversation_id'=>$conId->conversation_id,
       )));*/
     /*$sentBoxDtl=MsgDetails::model()->findAll(array('condition'=>'user_id=:user_id AND sent_dlt_status=:status',
              //'group'=>'conversation_id',    
             'params'=>array(
             	          ':status'=>0,   
                          ':user_id'=>$loggedId,
       )));*/
     foreach ($sentBox as $conId) {
         $sentBoxDtl[] = MsgDetails::model()->findAll(array('condition' => 'conversation_id=:conversation_id AND user_id=:user_id AND sent_dlt_status=:status', 'params' => array(':user_id' => $loggedId, ':conversation_id' => $conId->conversation_id, ':status' => 0)));
         $companyName = ServiceUser::model()->findAll(array('condition' => 'id=:id', 'params' => array(':id' => $conId->tomsg)));
         // echo "<pre>";print_r($companyName);
     }
     //die;
     //}
     //$sentBoxconvID =$inbox[0]['conversation_id'];
     //echo "<pre>";print_r($outbox);die;
     foreach ($sentMsg as $sender_id) {
         $sentFrm = ServiceUser::model()->findAll(array('condition' => 'id=:id', 'params' => array(':id' => $sender_id->sender_id)));
         //echo "<pre>";print_r($sentFrm);
         /*$sentFrm=CustomerUser::model()->findAll(array('condition'=>'id=:id','params'=>array(
         
                                          ':id'=>$sender_id->sender_id,
                       	)));*/
         //echo "<pre>";print_r($sentTo);
     }
     //die;
     /*code to get the new pending requests from customers*/
     $companyRequest = CompanyRequest::model()->findAll(array('order' => 'id desc', 'condition' => 'service_id=:service_id AND job_status=:job_status', 'params' => array(':service_id' => $loggedId, ':job_status' => 0)));
     $Request = CompanyRequest::model()->findAll(array('condition' => 'service_id=:service_id AND job_status=:job_status', 'params' => array(':service_id' => $loggedId, ':job_status' => 1)));
     foreach ($Request as $arrReq) {
         $request[] = $arrReq['booking_id'];
         //echo "<pre>";print_r($request);
     }
     //die;
     //echo "<pre>";print_r($companyRequest);die;
     /*code to edit the services by company from dashboard*/
     $serviceType = ServiceTypes::model()->findAll();
     $statusType = ServicestatusBycompany::model()->findAll(array('condition' => 'status=:status AND service_id=:service_id', 'params' => array(':service_id' => $loggedId, ':status' => 1)));
     $Admin = PriceAdmin::model()->findAll(array('condition' => 'service_id=:service_id', 'params' => array(':service_id' => $loggedId)));
     //echo "<pre>";print_r($Admin);die;
     /*check the price for particular starts here*/
     $additionSerPrice = AdditionalServicePrice::model()->findAll(array('condition' => 'service_id=:service_id', 'params' => array(':service_id' => $loggedId)));
     //echo "<pre>";print_r($additionSerPrice);die;
     /*code to get the details for zipcodes */
     $zip = UkPostcodes::model()->findAll();
     foreach ($zip as $z) {
         $post[] = $z->postcode;
     }
     $uniquePost = array_unique($post);
     /*code to get the details for zipcodes ends */
     /*code to get the global price for additional services starts here*/
     $gpAdditional = AdditionalServices::model()->findAll();
     $chkgPAdmin = PriceAdmin::model()->findAll(array('condition' => 'service_id=:service_id', 'params' => array(':service_id' => $loggedId)));
     //echo "<pre>";print_r($chkgPAdmin);die;
     //echo "<pre>";print_r($gpAdditional);die;
     /*code to get the global price for additional services ends here */
     $providerPrice = ProviderAdditionalprices::model()->findAll(array('condition' => 'service_id=:service_id  ', 'params' => array(':service_id' => $loggedId)));
     //$servicetypeAdnlser=ServicetypeAdditionalservices::
     // code to get the prices details for additional services for particular service type
     // code to get the price from priceadmin table and update the price by provider
     $endofTenancy = PriceAdmin::model()->find(array('condition' => 'service_id=:service_id AND service_type_id=:service_type_id', 'params' => array(':service_id' => $loggedId, ':service_type_id' => 1)));
     $domesticCleaning = PriceAdmin::model()->find(array('condition' => 'service_id=:service_id AND service_type_id=:service_type_id', 'params' => array(':service_id' => $loggedId, ':service_type_id' => 2)));
     $officeCleaning = PriceAdmin::model()->find(array('condition' => 'service_id=:service_id AND service_type_id=:service_type_id', 'params' => array(':service_id' => $loggedId, ':service_type_id' => 3)));
     $coverage = DistanceCoverage::model()->find(array('condition' => 'service_id=:service_id', 'params' => array(':service_id' => $loggedId)));
     //echo "<pre>";print_r($coverage);die;
     //echo "<pre>";print_r($domesticCleaning);die;
     // company Request find here to show the completed jobs
     $comRest = CompanyRequest::model()->findAll(array('condition' => 'service_id=:service_id AND job_status=:job_status', 'params' => array(':service_id' => $loggedId, ':job_status' => 1)));
     //echo "<pre>";print_r($comRest);die;
     $links = CmsPages::model()->findAll();
     Yii::app()->params['MyArray'] = $links;
     $this->render('dashboard', array('model' => $model, 'dashboard' => $rec, 'convMsg' => $convMsg, 'msg' => $msg, 'msgDetail' => $msgDetail, 'finalTo' => $finalTo, 'companyName' => $companyName, 'count' => $c, 'frm' => $sentFrm, 'sent' => $sentMsg, 'inbox' => $inbox, 'out' => $sentbox, 'inboxDtal' => $inboxDtal, 'sentBox' => $sentBox, 'sentBoxDtl' => $sentBoxDtl, 'numInbox' => $numInbox, 'comName' => $comName, 'companyN' => $companyN, 'companyRequest' => $companyRequest, 'request' => $request, 'serviceTy' => $serviceType, 'statusType' => $statusType, 'admnPrice' => $admnPrice, 'Admin' => $Admin, 'addnal' => $additional, 'additionSerPrice' => $additionSerPrice, 'uniquePost' => $uniquePost, 'gpAdditional' => $gpAdditional, 'chkgPAdmin' => $chkgPAdmin, 'globalAd' => $globalAd, 'serviceAd' => $serviceAd, 'providerPrice' => $providerPrice, 'endofTenancy' => $endofTenancy, 'domesticCleaning' => $domesticCleaning, 'officeCleaning' => $officeCleaning, 'distance' => $distance, 'coverage' => $coverage, 'comRest' => $comRest, 'converstion' => $converstion));
 }