コード例 #1
0
ファイル: PaymentController.php プロジェクト: KaranSofat/yii
 public function actionIndex()
 {
     $model = new PaymentCustomerUser();
     $booking = new CustomerBooking();
     $address = new CustomerAddress();
     $company = new CompanyRequest();
     $ses = Yii::app()->session['CleaningDetail'];
     $servicetype = Yii::app()->session['ServiceTypeId'];
     $zip = $ses['CleaningTime']['PostCode'];
     // echo "<pre>";print_r(base64_decode($_REQUEST['value']));die;
     //echo "<pre>";print_r($ses);die;
     //$myProducts = Yii::app()->session['detail'];
     $detail = Yii::app()->session['detail'];
     foreach ($detail['Additional'] as $k => $d) {
         $detailadnl[$k] = ServicetypeAdditionalservices::model()->findAll(array('condition' => 'id=:id', 'params' => array(':id' => $k)));
     }
     foreach ($detailadnl as $key => $nam) {
         // echo "<pre>";print_r($nam);
         foreach ($nam as $value) {
             $detailadnl[$key] = $value['additional_service_name'];
         }
     }
     //echo "<pre>";print_r($detail['Additional']);
     $finalDetailadnl = array_combine($detailadnl, $detail['Additional']);
     //echo "<pre>";print_r($fin);die;
     //$price         =$_REQUEST['price'];
     // code to get the method from admin %age or fiexd cost  of total amount
     $paymentAdmin = PaymentToAdmin::model()->find(array('condition' => 'status=1'));
     if (!empty($paymentAdmin)) {
         //echo "adda";die;
         if ($paymentAdmin['type_of_cost'] == 'Fixed') {
             $price = $paymentAdmin['cost_percentage'];
         } else {
             if (isset($_REQUEST['value'])) {
                 $pri = $paymentAdmin['cost_percentage'] * base64_decode($_REQUEST['value']);
                 $pce = $pri / 100;
                 $price = $pce;
             } else {
                 $price = base64_decode($_REQUEST['value1']);
             }
         }
     } else {
         $price = base64_decode($_REQUEST['value']);
     }
     //echo $price;die;
     $service_id = $_REQUEST['service_id'];
     $rec = UkPostcodes::model()->findByattributes(array('postcode' => $zip));
     // detail for logged user
     $loggedId = Yii::app()->session['loggedId'];
     $customerDetail = PaymentCustomerUser::model()->findByPk(array('id' => $loggedId));
     //echo "<pre>";print_r($customerDetail);die;
     //echo "<pre>";print_r($servicetype);die;
     if (isset($_POST['PaymentCustomerUser'])) {
         $logged = Yii::app()->session['loggedId'];
         //echo "<pre>";print_r($ses);die;
         $model->attributes = $_POST['PaymentCustomerUser'];
         if ($model->validate()) {
             // echo "<pre>";print_r($_REQUEST);die;
             $exp = $_REQUEST['PaymentCustomerUser']['expire'];
             $res = explode("/", $exp);
             $month = $res[0];
             $year = $res[1];
             $cardDetail = implode(explode(" ", trim($_REQUEST['PaymentCustomerUser']['cardDetail'])));
             /*if($_REQUEST['value']==0)
               {
               	 $price=0;
               }	*/
             $paymentInfo = array('Member' => array('first_name' => $_REQUEST['PaymentCustomerUser']['cname'], 'last_name' => $_REQUEST['PaymentCustomerUser']['clname'], 'billing_address' => $_REQUEST['PaymentCustomerUser']['caddress'], 'billing_address2' => $_REQUEST['PaymentCustomerUser']['caddress'], 'billing_country' => $_REQUEST['PaymentCustomerUser']['country'], 'billing_city' => $_REQUEST['PaymentCustomerUser']['city'], 'billing_zip' => $_REQUEST['PaymentCustomerUser']['zipcode']), 'CreditCard' => array('card_number' => $cardDetail, 'expiration_month' => trim($month), 'expiration_year' => trim($year), 'cv_code' => $_REQUEST['PaymentCustomerUser']['code'], 'credit_type' => $_REQUEST['PaymentCustomerUser']['cardType']), 'Order' => array('theTotal' => $price));
             // echo "<pre>";print_r($paymentInfo);
             $result = Yii::app()->Paypal->DoDirectPayment($paymentInfo);
             //echo http_build_query($data, 'flags_');
             //echo "<pre>";print_r($result);die;
             if ($result['ACK'] == 'Failure') {
                 $links = CmsPages::model()->findAll();
                 Yii::app()->params['MyArray'] = $links;
                 Yii::app()->user->setFlash('ack', "Please check your card details");
                 $this->render('index', array('model' => $model, 'town' => $rec, 'price' => $price, 'service_id' => $service_id));
             }
             if (!Yii::app()->Paypal->isCallSucceeded($result)) {
                 if (Yii::app()->Paypal->apiLive === true) {
                     //Live mode basic error message
                     $error = 'We were unable to process your request. Please try again later';
                 } else {
                     //Sandbox output the actual error message to dive in.
                     $error = $result['L_LONGMESSAGE0'];
                 }
                 echo $error;
             } else {
                 //Payment was completed successfully, do the rest of your stuff
                 // code to register the customer and save  transaction id in differ table
                 if (!empty($result['TRANSACTIONID'])) {
                     $model->cname = $_REQUEST['PaymentCustomerUser']['cname'];
                     $model->clname = $_REQUEST['PaymentCustomerUser']['clname'];
                     $model->caddress = $_REQUEST['PaymentCustomerUser']['caddress'];
                     $model->zipcode = $_REQUEST['PaymentCustomerUser']['zipcode'];
                     $model->phone = $_REQUEST['PaymentCustomerUser']['phone'];
                     $model->email = $_REQUEST['PaymentCustomerUser']['email'];
                     $model->city = $_REQUEST['PaymentCustomerUser']['city'];
                     $model->country = $_REQUEST['PaymentCustomerUser']['country'];
                     $model->cregistered = date('Y-m-d');
                     $email = $_REQUEST['PaymentCustomerUser']['email'];
                     $user = PaymentCustomerUser::model()->exists('email=:email', array('email' => $email));
                     // $user=PaymentCustomerUser::model()->findByAttributes(array('email'=>$email));
                     //echo "<pre>";print_r($user);die;
                     //if(count($user)<0)
                     if (empty($user)) {
                         //echo "hlo";die;
                         $cleartext_password = rand(0, 9999);
                         $model->password = md5($cleartext_password);
                         if ($model->save()) {
                             $signature = md5($model->email . $model->password);
                             $subject = 'Welcome to Wow Cleans';
                             $body = $this->renderPartial('registrationEmail', array('model' => $model, 'password' => $cleartext_password, 'url' => $this->createAbsoluteUrl('../registration/login', array('email' => $model->email, 'signature' => $signature))), true);
                             Yii::app()->mailer->send($model->email, $subject, $body);
                             // booking detail for register customer here
                             $custId = Yii::app()->db->getLastInsertID();
                             $transId = $result['TRANSACTIONID'];
                             $cust = PaymentCustomerUser::model()->findByAttributes(array('id' => $custId));
                             $companyDetail = ServiceUser::model()->findByAttributes(array('id' => $_REQUEST['service_id']));
                             //echo "<pre>";print_r($companyDetail);die;
                             // save address for customer in different table
                             $address->address = $_REQUEST['PaymentCustomerUser']['caddress'];
                             $address->zipcode = $_REQUEST['PaymentCustomerUser']['zipcode'];
                             $address->date = date('Y-m-d');
                             $address->customer_id = $custId;
                             $address->save();
                             $address_id = Yii::app()->db->getLastInsertID();
                             $re = CustomerAddress::model()->findByAttributes(array('customer_id' => $custId));
                             //echo "<pre>";print_r($re);die;
                             $addressId = $re->id;
                             $booking->customer_id = $custId;
                             $booking->service_id = $_REQUEST['service_id'];
                             $booking->service_type_id = $servicetype;
                             //$booking->price          =$_REQUEST['price'];
                             $booking->price = $price;
                             $booking->trans_id = $transId;
                             $booking->date = date('Y-m-d');
                             if (!empty($address_id)) {
                                 $booking->customer_address_id = $address_id;
                             } else {
                                 $booking->customer_address_id = $addressId;
                             }
                             $detail = Yii::app()->session['detail'];
                             // echo "<pre>";print_r($detail);die;
                             foreach ($detail['Cleaning'] as $type => $number) {
                                 $cleaningDetail .= $number . "-" . $type . ",";
                             }
                             $booking->cleaningDetail = substr($cleaningDetail, 0, -1);
                             /*foreach($detail['Additional'] as $k=>$val)
                               {
                               	  if($val!=0)
                               	  {
                               	  	 $addnl .=$val."-".$k.",";
                               	  }	
                               }	*/
                             foreach ($finalDetailadnl as $k => $val) {
                                 if ($val != 0) {
                                     $addnl .= $val . "-" . $k . ",";
                                 }
                             }
                             $booking->additional = substr($addnl, 0, -1);
                             $booking->additional_details = $detail['AdditionalCustDetail']['AdditionalCustDetail'];
                             if ($booking->save()) {
                                 //booking id for thaks page
                                 $insert_id = Yii::app()->db->getLastInsertID();
                                 $cutId = Booking::model()->findByPk(array('id' => $insert_id));
                                 $customerId = $cutId->customer_id;
                                 /*code to enter the company request details in company request table*/
                                 $company->booking_id = $insert_id;
                                 $company->service_id = $_REQUEST['service_id'];
                                 $company->customer_id = $customerId;
                                 $company->cleaningtime = $ses['CleaningTime']['time'];
                                 $company->postcode = $ses['CleaningTime']['PostCode'];
                                 $company->cleaningdate = date("Y-m-d", strtotime($ses['CleaningTime']['CleaningDate']));
                                 $company->date = date('Y-m-d');
                                 $company->no_of_hours = $ses['CleaningTime']['noOfhour'];
                                 $company->no_of_cleaners = $ses['CleaningTime']['noOfCleaners'];
                                 $company->save(false);
                                 // echo $insert_id;die;
                                 // send mail to customer
                                 $subject = 'Welcome to Wow Cleans';
                                 $body = $this->renderPartial('customerEmail', array('model' => $companyDetail, 'cust' => $_REQUEST, 'detail' => $detail, 'adnl' => $finalDetailadnl, 'price' => $price, 'trans' => $result['TRANSACTIONID']), true);
                                 Yii::app()->mailer->send($cust->email, $subject, $body);
                                 // send mail to company
                                 $subject = 'Welcome to Wow Cleans';
                                 $body = $this->renderPartial('companyEmail', array('model' => $companyDetail, 'cust' => $_REQUEST, 'detail' => $detail, 'adnl' => $finalDetailadnl, 'price' => $price, 'trans' => $result['TRANSACTIONID']), true);
                                 Yii::app()->mailer->send($companyDetail->email, $subject, $body);
                                 //$this->refresh();
                                 //$this->redirect(array('../registration/index'));
                             }
                             // booking detail for register customer ends here
                             $link = CmsPages::model()->findAll();
                             Yii::app()->params['MyArray'] = $link;
                             // $this->redirect('thanks','param1'=>$companyDetail);
                             $this->redirect(array('payment/thanks', 'param1' => $insert_id));
                             //exit();
                             //$this->refresh();
                             //$this->redirect(array('registration/registration'));
                         }
                     } else {
                         // echo "fsf";die;
                         //$price     =$_REQUEST['price'];
                         $email = $_REQUEST['PaymentCustomerUser']['email'];
                         $transId = $result['TRANSACTIONID'];
                         $rec = PaymentCustomerUser::model()->findByAttributes(array('email' => $email));
                         //echo "<pre>";print_r($rec);die;
                         $custId = $rec->id;
                         $companyDetail = ServiceUser::model()->findByAttributes(array('id' => $_REQUEST['service_id']));
                         // save address for customer in different table
                         $address->address = $_REQUEST['PaymentCustomerUser']['caddress'];
                         $address->zipcode = $_REQUEST['PaymentCustomerUser']['zipcode'];
                         $address->date = date('Y-m-d');
                         $address->customer_id = $custId;
                         if (!($user = CustomerAddress::model()->exists('address=:address', array('address' => $_REQUEST['PaymentCustomerUser']['caddress'])))) {
                             $address->save();
                             $address_id = Yii::app()->db->getLastInsertID();
                         }
                         //$address_id = Yii::app()->db->getLastInsertID();
                         $re = CustomerAddress::model()->findByAttributes(array('customer_id' => $custId));
                         //echo "<pre>";print_r($rec->id);die;
                         $addressId = $re->id;
                         $booking->customer_id = $custId;
                         $booking->service_id = $_REQUEST['service_id'];
                         $booking->service_type_id = $servicetype;
                         //$booking->price          =$_REQUEST['price'];
                         $booking->price = $price;
                         $booking->trans_id = $transId;
                         $booking->date = date('Y-m-d');
                         if (!empty($address_id)) {
                             $booking->customer_address_id = $address_id;
                         } else {
                             $booking->customer_address_id = $addressId;
                         }
                         $detail = Yii::app()->session['detail'];
                         // echo "<pre>";print_r($detail);die;
                         foreach ($detail['Cleaning'] as $type => $number) {
                             $cleaningDetail .= $number . "-" . $type . ",";
                         }
                         $booking->cleaningDetail = substr($cleaningDetail, 0, -1);
                         //echo "<pre>";print_r($detail['Additional']);die;
                         /*foreach($detail['Additional'] as $k=>$val)
                           {
                           	  if($val!=0)
                           	  {
                           	  	 $addnl .=$val."-".$k.",";
                           	  }	
                           } */
                         foreach ($finalDetailadnl as $k => $val) {
                             if ($val != 0) {
                                 $addnl .= $val . "-" . $k . ",";
                             }
                         }
                         $booking->additional = substr($addnl, 0, -1);
                         $booking->additional_details = $detail['AdditionalCustDetail']['AdditionalCustDetail'];
                         if ($booking->save(false)) {
                             $insert_id = Yii::app()->db->getLastInsertID();
                             $cutId = Booking::model()->findByPk(array('id' => $insert_id));
                             //echo "<pre>";print_r($cutId);die;
                             $customerId = $cutId->customer_id;
                             /*code to add the company request details in company request table*/
                             $company->booking_id = $insert_id;
                             $company->service_id = $_REQUEST['service_id'];
                             $company->customer_id = $customerId;
                             $company->cleaningtime = $ses['CleaningTime']['time'];
                             $company->postcode = $ses['CleaningTime']['PostCode'];
                             $company->cleaningdate = date("Y-m-d", strtotime($ses['CleaningTime']['CleaningDate']));
                             $company->date = date('Y-m-d');
                             $company->no_of_hours = $ses['CleaningTime']['noOfhour'];
                             $company->no_of_cleaners = $ses['CleaningTime']['noOfCleaners'];
                             $company->save(false);
                             // send mail to customer
                             $subject = 'Welcome to Wow Cleans';
                             $body = $this->renderPartial('customerEmail', array('model' => $companyDetail, 'cust' => $_REQUEST, 'detail' => $detail, 'adnl' => $finalDetailadnl, 'price' => $price, 'trans' => $result['TRANSACTIONID']), true);
                             Yii::app()->mailer->send($rec->email, $subject, $body);
                             // send mail to company
                             $subject = 'Welcome to Wow Cleans';
                             $body = $this->renderPartial('companyEmail', array('model' => $companyDetail, 'cust' => $_REQUEST, 'detail' => $detail, 'adnl' => $finalDetailadnl, 'price' => $price, 'trans' => $result['TRANSACTIONID']), true);
                             Yii::app()->mailer->send($companyDetail->email, $subject, $body);
                             //$this->refresh();
                             if ($logged != '') {
                                 //$this->redirect(array('../registration/customerdashboard'));
                                 $this->redirect(array('payment/thanks', 'param1' => $insert_id));
                             } else {
                                 $this->redirect(array('payment/thanks', 'param1' => $insert_id));
                                 //$this->redirect(array('../registration/index'));
                             }
                         }
                         //echo $servicetype; die;
                         //echo "<pre>";print_r($rec);die;
                     }
                 }
             }
             Yii::app()->end();
         } else {
             $errors = $model->getErrors();
             // var_dump($errors);
         }
     }
     $links = CmsPages::model()->findAll();
     Yii::app()->params['MyArray'] = $links;
     $this->render('index', array('model' => $model, 'town' => $rec, 'price' => $price, 'service_id' => $service_id, 'customerDetail' => $customerDetail));
 }
コード例 #2
0
ファイル: UserController.php プロジェクト: KaranSofat/yii
 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));
     }
 }
コード例 #3
0
 public function actionEdit()
 {
     $model = new CleaningTime();
     $service = new ServiceTypes();
     $list = CleaningTime::model()->findAll();
     $zip = UkPostcodes::model()->findAll();
     //echo "<pre>";print_r($zip);die;
     foreach ($zip as $z) {
         $post[] = $z->postcode;
     }
     $uniquePost = array_unique($post);
     $record = CompanyRequest::model()->find(array('condition' => 'booking_id=:booking_id AND job_status=:job_status', 'params' => array(':booking_id' => $_REQUEST['id'], ':job_status' => 1)));
     //echo "<pre>";print_r($rec->booking);die;
     $ser = ServiceTypes::model()->findAll();
     foreach ($ser as $se) {
         $ids[] = $se['id'];
         $serNam[] = $se['service_name'];
         $serName = array_combine($ids, $serNam);
     }
     //echo "<pre>";print_r($serName);die;
     if (isset($_POST['CleaningTime'])) {
         //echo "<pre>";print_r($_REQUEST);die;
         $id = $_REQUEST['book'];
         $re = CompanyRequest::model()->find(array('condition' => 'booking_id=:booking_id ', 'params' => array(':booking_id' => $_REQUEST['book'])));
         $re->postcode = $_REQUEST['CleaningTime']['PostCode'];
         $re->cleaningtime = $_REQUEST['CleaningTime']['time'];
         $re->cleaningdate = date('y-m-d', strtotime($_REQUEST['CleaningTime']['CleaningDate']));
         $re->save(false);
         $booking = Booking::model()->findByPk(array('id' => $id));
         $service_type_id = $_REQUEST['ServiceTypes']['service_name'];
         $booking->service_type_id = $service_type_id;
         /*if(!empty($_REQUEST['Booking']))
           {  */
         if ($service_type_id == 3) {
             foreach ($_REQUEST['Booking'] as $key => $value) {
                 //$r.=$value."-".$key.",";
                 $newAr[] = $value . "-" . $key;
             }
             $data = implode(',', $newAr);
             //echo "<pre>";print_r($data);die;
             $booking->cleaningDetail = $data;
         } else {
             foreach (array_slice($_REQUEST['Booking'], 0, 2) as $key => $value) {
                 //$r.=$value."-".$key.",";
                 $newAr[] = $value . "-" . $key;
             }
             $data = implode(',', $newAr);
             //echo "<pre>";print_r($data);die;
             $booking->cleaningDetail = $data;
         }
         //}
         //echo "<pre>";print_r($r);die;
         if (!empty($_REQUEST['Additional'])) {
             //$booking->cleaningDetail=$r;
             foreach ($_REQUEST['Additional'] as $key => $value) {
                 //echo "<pre>";print_r($value);
                 $res[] = $value . "-" . $key;
             }
             $data1 = implode(',', $res);
             $booking->additional = $data1;
         }
         /*email to customer starts here*/
         $subject = 'Welcome to Wow Cleans';
         $body = $this->renderPartial('updatedquoteEmail', array('model' => $booking), true);
         Yii::app()->mailer->send($booking->service['email'], $subject, $body);
         /*email to customer ends here */
         $booking->save(false);
         $this->redirect(array('customerdashboard'));
     }
     $links = CmsPages::model()->findAll();
     Yii::app()->params['MyArray'] = $links;
     $this->render('edit', array('list' => $list, 'model' => $model, 'Post' => $uniquePost, 'rec' => $record, 'serName' => $serName, 'service' => $service));
 }