public function actionTesInquiry()
 {
     $model = new InquiryForm();
     if (isset($_POST['InquiryForm'])) {
         $model->setAttributes($_POST['InquiryForm']);
         $model->validate();
     }
     $this->render('tesInquiry', array('model' => $model));
 }
 public function actionGetGroceryRate()
 {
     $inquiry = new InquiryForm('api-rate-grocery');
     $req = Yii::app()->request;
     $inquiryMap = new CMap();
     $inquiryMap->add('receiver_postal', $req->getQuery('receiver_postal'));
     $inquiryMap->add('service_code', $req->getQuery('service_code'));
     $inquiry->setAttributes($inquiryMap->toArray());
     if (!$inquiry->validate()) {
         echo CJSON::encode($this->statusError($inquiry->getErrors()));
         Yii::app()->end();
     }
     $service_code = ProductService::model()->findByAttributes(array('code' => strtoupper($inquiry->service_code)));
     if (!$service_code instanceof ProductService) {
         echo CJSON::encode($this->statusError('No Service Available'));
         Yii::app()->end();
     } else {
         if ($service_code->code != 'LSX' && $service_code->code != 'HRX') {
             echo CJSON::encode($this->statusError('This service is not available'));
             Yii::app()->end();
         }
     }
     $routing = IntraCityRouting::model()->findByAttributes(array('postcode' => $inquiry->receiver_postal));
     if ($routing instanceof IntraCityRouting) {
         $area = Area::getZoneID($inquiry->receiver_postal, 'postcode');
         if (!$area) {
             echo CJSON::encode($this->statusError('No Available Service'));
             Yii::app()->end();
         }
         $rates = RateCity::getCityRate(ProductService::ProductCityCourier, $routing->code, 5);
         $rate = array();
         foreach ($rates as $key) {
             if ($key['service_code'] == $inquiry->service_code) {
                 $rate = $key;
             }
         }
         $product = 'City Courier';
         echo CJSON::encode($this->statusSuccess(array('service_type' => $product, 'rate' => $rate)));
         Yii::app()->end();
     } else {
         $result = array('status' => 'success', 'result' => $data);
     }
     echo CJSON::encode($result);
     Yii::app()->end();
 }
 public function actionGetRates()
 {
     if (Yii::app()->request->isAjaxRequest && isset($_GET['Cek'])) {
         $inquiry = new InquiryForm('api-rate');
         $inquiry->setAttributes($_GET['Cek']);
         $customer_id = null;
         $use_rate = array();
         $rates = array();
         if (isset($_GET['customer_id']) && is_numeric($_GET['customer_id'])) {
             $customer_id = $_GET['customer_id'];
             $customer = Customer::model()->findByPk($customer_id);
             if ($customer instanceof Customer) {
                 $customer_id = $customer->id;
                 $customer_rates = CustomerDiscount::model()->findAllByAttributes(array('customer_id' => $customer->id, 'use_rate' => 1));
                 foreach ($customer_rates as $cus_rate) {
                     array_push($use_rate, $cus_rate->service_id);
                 }
             }
         }
         if (strtolower($inquiry->receiver_country) != 'indonesia') {
             $country = ZoneInternational::model()->findByAttributes(array('country' => strtolower($inquiry->receiver_country)));
             if ($country instanceof ZoneInternational) {
                 $rates = RateInternational::getServices($inquiry->package_weight, $country->zone, $country->transit_time, $customer_id, $use_rate);
                 $product = 'International';
             }
         } else {
             $routing = IntraCityRouting::model()->findByAttributes(array('postcode' => $inquiry->receiver_postal));
             if ($routing instanceof IntraCityRouting) {
                 $rates1 = RateCity::getCityRate(ProductService::ProductCityCourier, $routing->code, $inquiry->package_weight, $customer_id, $use_rate);
                 $rates2 = array();
                 $area = Area::getZoneID($inquiry->receiver_postal, 'postcode');
                 if ($area) {
                     $rates2 = RateDomestic::getServiceList(1, $area['district_id'], $area['zone_id'], $inquiry->package_weight, ProductService::ProductCityCourier, $customer_id, $use_rate);
                     $rates = array_merge($rates1, $rates2);
                 } else {
                     $rates = $rates1;
                 }
                 $product = 'City Courier';
             } else {
                 $area = Area::getZoneID($inquiry->receiver_postal, 'postcode');
                 if ($area) {
                     $rates = RateDomestic::getServiceList(1, $area['district_id'], $area['zone_id'], $inquiry->package_weight, ProductService::ProductDomestic, $customer_id, $use_rate);
                 }
                 $product = 'Domestic';
             }
         }
         $data = new CArrayDataProvider($rates);
         //			CVarDumper::dump($rates,10,true);exit;
         $this->renderPartial('_rates', array('rates' => $data, 'product' => $product, 'customer_id' => $customer_id, 'postal' => $inquiry->receiver_postal, 'country' => $inquiry->receiver_country, 'product' => $product, 'package_weight' => $inquiry->package_weight), false, true);
         Yii::app()->end();
     }
 }