/** * this function used to generate the text fied in the rate_price * * @param type $attribute * @param type $csid * @param type $oid * @param type $zid * @param type $did * @param type $getId * @return type */ public function getRatePriceTextField($attribute, $csid = '', $oid = '', $zid = '', $did = '', $getId = false) { $hidenFieldId = ''; $hiddenZoneId = ''; $hiddenDistrictId = ''; $model = RateDomestic::model()->findByAttributes(array('service_id' => $csid, 'origin_id' => $oid, 'zone_id' => $zid, 'district_id' => $did)); if (!$model) { $model = new RateDomestic(); } else { $model->{$attribute} = str_replace('.00', '', $model->{$attribute}); if ($attribute == 'first_kg') { $hidenFieldId = CHtml::activeHiddenField($model, 'id', array('rel' => 'RatePriceTextField', 'name' => str_replace('RateDomestic', 'RateDomestic[' . $this->id . ']', CHtml::activeName($model, 'id')), 'class' => 'RatePrice_' . $this->id)); } } if ($attribute == 'next_kg') { $hiddenZoneId = CHtml::hiddenField('RateDomestic[' . $this->id . '][zone_id]', $this->id); $hiddenDistrictId = CHtml::hiddenField('RateDomestic[' . $this->id . '][district_id]', $this->district_id); } $transitWidth = $attribute == 'transit_time' ? 'style' : null; $transitWidthValue = $attribute == 'transit_time' ? 'width:50px' : null; if ($getId) { return $model->primaryKey; } else { if (!$getId) { return CHtml::tag('span', array('class' => 'row'), CHtml::activeTextField($model, $attribute, array('rel' => 'RatePriceTextField', 'name' => str_replace('RateDomestic', 'RateDomestic[' . $this->id . ']', CHtml::activeName($model, $attribute)), 'class' => 'RatePrice_' . $this->id, $transitWidth => $transitWidthValue)) . $hidenFieldId . $hiddenZoneId . $hiddenDistrictId . CHtml::openTag('span', array('id' => CHtml::activeId($model, $attribute) . '_em', 'class' => 'RatePrice_' . $this->id)) . CHtml::closeTag('span')); } } }
public static function checkZoneId($serviceId, $originId, $zoneId) { $criteria = new CDbCriteria(); $criteria->condition = "service_id=:service_id AND origin_id=:origin_id AND zone_id=:zone_id"; $criteria->params = array(':service_id' => $serviceId, ':origin_id' => $originId, ':zone_id' => $zoneId); $check = RateDomestic::model()->count($criteria); if ($check == 0) { return false; } else { return true; } }
public function actionRequestOrder() { if (!isset($_POST['Shipment'])) { echo CJSON::encode($this->statusError('Must be in POST method')); Yii::app()->end(); } $shipment = new Shipment('api-requestpickup'); $shipment->attributes = $_POST['Shipment']; $shipment->created = time(); $routing_code = IntraCityRouting::model()->findByAttributes(array('postcode' => $shipment->shipper_postal)); if ($routing_code instanceof IntraCityRouting) { $shipment->origin_code = $routing_code->code; } $price = 0; $price_vendor = 0; $trans = Yii::app()->db->beginTransaction(); try { if ($this->token instanceof Token) { $customer = Customer::model()->findByPk($this->token->customer_id); if (!$customer instanceof Customer) { throw new ServiceControllerException('You have to login first'); } if (!!$customer->accountnr) { $shipment->awb = '70' . rand(10000000, 99999999); while (!$shipment->validate()) { $shipment->awb = '70' . rand(10000000, 99999999); } } $shipment->customer_id = $this->token->customer_id; } else { $email = ''; $shipment->setScenario('cekemail'); if ($shipment->validate()) { if ($shipment->payer == 'shipper' && $shipment->shipper_email) { $email = Contact::model()->findByAttributes(array('email' => $shipment->shipper_email)); } elseif ($shipment->payer == 'consignee' && $shipment->receiver_email) { $email = Contact::model()->findByAttributes(array('email' => $shipment->receiver_email)); } } else { throw new ServiceControllerException($shipment->getErrors()); } $shipment->setScenario('api-requestpickup'); if (!$email instanceof Contact) { $customer = new Customer(); if ($shipment->payer == 'shipper') { $customer->name = $shipment->shipper_name; } elseif ($shipment->payer == 'consignee') { $customer->name = $shipment->receiver_name; } $customer->type = 'personal'; $customer->accountnr = 'WEB' . time(); if ($customer->save()) { $contact = new Contact(); $contact->parent_id = $customer->id; $contact->parent_model = 'Customer'; if ($shipment->payer == 'shipper') { $contact->full_name = $shipment->shipper_name; $contact->address = $shipment->shipper_address; $contact->country = $shipment->shipper_country; $contact->city = $shipment->shipper_city; $contact->postal = $shipment->shipper_postal; $contact->email = $shipment->shipper_email; } elseif ($shipment->payer == 'consignee') { $contact->full_name = $shipment->receiver_name; $contact->address = $shipment->receiver_address; $contact->country = $shipment->receiver_country; $contact->city = $shipment->receiver_city; $contact->postal = $shipment->receiver_postal; $contact->email = $shipment->receiver_email; } if ($contact->save()) { $shipment->customer_id = $customer->id; } else { throw new ServiceControllerException($contact->getErrors()); } } else { throw new ServiceControllerException($customer->getErrors()); } } else { throw new ServiceControllerException('Your email is currently registered as a member, please login to create order'); } } if ($shipment->validate()) { $customer_rate = CustomerDiscount::getCustomerDiscountRate($shipment->service_id, $shipment->customer_id); switch ($shipment->service_type) { case 'City Courier': $rate = RateCity::model()->findByAttributes(array('service_id' => $shipment->service_id)); if ($rate instanceof RateCity) { if ($customer_rate['harga_invoice'] != 0) { $price = $customer_rate['harga_invoice'] * RateCity::increment($shipment->package_weight, $rate->weight_inc); } else { $price = ($rate->price - $rate->price * ($customer_rate['discount'] / 100)) * RateCity::increment($shipment->package_weight, $rate->weight_inc); } $price_vendor = ($rate->price - $rate->price * ($customer_rate['vendor_discount'] / 100)) * RateCity::increment($shipment->package_weight, $rate->weight_inc); } else { $area = Area::getZoneID($shipment->receiver_postal); if (!$area) { throw new ServiceControllerException('No services available'); } $price = RateDomestic::getRatePrice($shipment->service_id, 1, $area['district_id'], $area['zone_id'], $shipment->package_weight, $customer_rate['discount']); $price_vendor = RateDomestic::getRatePrice($shipment->service_id, 1, $area['district_id'], $area['zone_id'], $shipment->package_weight, $customer_rate['vendor_discount']); } break; case 'Domestic': $area = Area::getZoneID($shipment->receiver_postal); if (!$area) { throw new ServiceControllerException('No services available'); } $price = RateDomestic::getRatePrice($shipment->service_id, 1, $area['district_id'], $area['zone_id'], $shipment->package_weight, $customer_rate['discount']); $price_vendor = RateDomestic::getRatePrice($shipment->service_id, 1, $area['district_id'], $area['zone_id'], $shipment->package_weight, $customer_rate['vendor_discount']); break; case 'International': $zone = FALSE; if ($shipment->service_code == 'IEX') { $country = $shipment->receiver_country; } else { if ($shipment->service_code == 'IMX') { $country = $shipment->shipper_country; } } $zone = ZoneInternational::getZoneCountryData($country); if (!!$zone) { $price = RateInternational::getRatePrice($shipment->service_id, $shipment->package_weight, $shipment->type, $zone, $customer_rate['discount']); $price_vendor = RateInternational::getRatePrice($shipment->service_id, $shipment->package_weight, $shipment->type, $zone, $customer_rate['vendor_discount']); } break; case '': continue; } $shipment->shipping_charges = $price; $shipment->vendor_charge = $price_vendor; if (!$shipment->save()) { throw new ServiceControllerException($shipment->getErrors()); } $sum_add_cost = ShipmentAdditionalCharge::initSurcharges($shipment); /** * temporary disabling additional cost */ $sum_add_cost = 0; $shipment->charges = $shipment->shipping_charges + $sum_add_cost; $list_add_cost = $shipment->getAdditionalCharges(); if (!$shipment->save()) { throw new ServiceControllerException($shipment->getErrors()); } } else { throw new ServiceControllerException($shipment->getErrors()); } if (isset($_GET['confirm']) && $_GET['confirm'] == 1) { $trans->commit(); $data = array('shipment_id' => $shipment->id, 'status' => $shipment->shipping_status, 'time' => date('Y-m-d H:i:s', $shipment->created), 'charges' => $shipment->charges, 'awb' => $shipment->awb); } elseif (isset($_GET['confirm']) && $_GET['confirm'] == 0 || !isset($_GET['confirm'])) { $data = array('confirm' => 0, 'additional_cost' => $list_add_cost, 'shipping_charges' => $shipment->shipping_charges, 'total' => $shipment->charges, 'shipper_name' => $shipment->shipper_name, 'shipper_address' => $shipment->shipper_address, 'shipper_city' => $shipment->shipper_city, 'shipper_postal' => $shipment->shipper_postal, 'shipper_country' => $shipment->shipper_country, 'receiver_name' => $shipment->receiver_name, 'receiver_address' => $shipment->receiver_address, 'receiver_city' => $shipment->receiver_city, 'receiver_postal' => $shipment->receiver_postal, 'receiver_country' => $shipment->receiver_country, 'goods_desc' => $shipment->goods_desc, 'shipment_value' => $shipment->package_value, 'weight' => $shipment->package_weight, 'pieces' => $shipment->pieces, 'pay_bay' => $shipment->pay_by, 'payer' => $shipment->payer, 'customer_id' => $customer->id); $trans->rollback(); } } catch (ServiceControllerException $e) { $errors = $e->errors; $trans->rollback(); echo CJSON::encode($this->statusError($errors)); Yii::app()->end(); } catch (CDbException $e) { $trans->rollback(); echo CJSON::encode($this->statusError($e)); Yii::app()->end(); } echo CJSON::encode($this->statusSuccess($data)); Yii::app()->end(); }
* this is hidden field for string service_id and origin_id */ echo CHtml::hiddenField('service_id', $csid, array('id' => 'hd_service_id')); echo CHtml::hiddenField('origin_id', $oid, array('id' => 'hd_origin_id')); ?> <?php if ($mode == 'district') { ?> <div class="grid"> <?php $this->widget('zii.widgets.grid.CGridView', array('dataProvider' => $district, 'htmlOptions' => array('class' => 'hastable'), 'columns' => array(array('name' => 'Propinsi', 'value' => '$data->province->name'), array('name' => 'Kota / Kabupaten', 'value' => '$data->name'), array('value' => '$data->getRatePriceTextField("first_kg",' . $csid . ',' . $oid . ',$data->id)', 'type' => 'raw', 'header' => RateDomestic::model()->getAttributeLabel("first_kg")), array('value' => '$data->getRatePriceTextField("next_kg",' . $csid . ',' . $oid . ',$data->id)', 'type' => 'raw', 'header' => RateDomestic::model()->getAttributeLabel("next_kg")), array('value' => '$data->getRatePriceTextField("transit_time",' . $csid . ',' . $oid . ',$data->id)', 'type' => 'raw', 'header' => RateDomestic::model()->getAttributeLabel("transit_time")), array('class' => 'CButtonColumn', 'header' => 'Opsi', 'template' => '{delete}', 'buttons' => array('delete' => array('url' => 'Yii::app()->controller->createUrl("/ratePrice/delete/".$data->getRatePriceTextField("id",' . $csid . ',' . $oid . ',$data->id,true))')))))); ?> </div> <?php } ?> <br /> <div class="grid"> <?php $this->widget('zii.widgets.grid.CGridView', array('dataProvider' => $zones, 'htmlOptions' => array('class' => 'hastable'), 'columns' => array(array('name' => 'Propinsi', 'value' => '$data->district->province->name'), array('name' => 'Kota/Kabupaten', 'value' => '$data->district->Name'), array('header' => 'Kecamatan', 'value' => '$data->name', 'name' => 'name'), array('value' => '$data->getRatePriceTextField("first_kg",' . $csid . ',' . $oid . ',$data->id,$data->district_id)', 'type' => 'raw', 'header' => RateDomestic::model()->getAttributeLabel("first_kg")), array('value' => '$data->getRatePriceTextField("next_kg",' . $csid . ',' . $oid . ',$data->id,$data->district_id)', 'type' => 'raw', 'header' => RateDomestic::model()->getAttributeLabel("next_kg")), array('value' => '$data->getRatePriceTextField("transit_time",' . $csid . ',' . $oid . ',$data->id,$data->district_id)', 'type' => 'raw', 'header' => RateDomestic::model()->getAttributeLabel("transit_time")), array('class' => 'CButtonColumn', 'header' => 'Opsi', 'template' => '{copytoall} {delete}', 'buttons' => array('delete' => array('url' => 'Yii::app()->controller->createUrl("/ratePrice/delete/".$data->getRatePriceTextField("id",' . $csid . ',' . $oid . ',$data->id,$data->district_id,true))'), 'copytoall' => array('label' => 'Salin ke semua', 'imageUrl' => Yii::app()->theme->baseUrl . '/images/icons/copytoall.png', 'click' => "js:function(){\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tvar thisRow=\$(this).parents('tr');\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tvar firstkgInputValue=thisRow.find('input[type=text]:eq(0)');\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tvar nextkgInputValue=thisRow.find('input[type=text]:eq(1)');\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tvar transitTimeInputValue=thisRow.find('input[type=text]:eq(2)');\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tvar serviceTypeValue=thisRow.find('input[type=text]:eq(3)');\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tvar firstkg=\$('table.items tr:has(input[type=text][name*=first])').find('input[type=text]:eq(0)');\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tvar nextkg=\$('table.items tr:has(input[type=text][name*=first])').find('input[type=text]:eq(1)');\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tvar transitTime=\$('table.items tr:has(input[type=text][name*=first])').find('input[type=text]:eq(2)');\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tif(firstkgInputValue.parents('span').attr('class')=='row success'){\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tfirstkg.val(firstkgInputValue.val());};\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tif(nextkgInputValue.parents('span').attr('class')=='row success'){nextkg.val(nextkgInputValue.val())};\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tif(transitTimeInputValue.parents('span').attr('class')=='row success'){\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\ttransitTime.val(transitTimeInputValue.val());\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\$('table.items span.row:has(input[name*=RateDomestic])').addClass('success');\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t}")))))); ?> </div> <?php echo CHtml::ajaxButton('Simpan', $this->createUrl('submitGrid'), array('data' => 'js:$("span.row.success input").serialize()+"&' . $tokenName . '=' . $token . '&service_id=' . $csid . '&origin_id=' . $oid . '"', 'dataType' => 'json', 'type' => 'post', 'beforeSend' => 'function(){jQuery("<div id=notifsave> Sedang menyimpan data </div>").dialog({"modal":true,"closeOnEscape":false,"beforeClose":function(event,ui){$("span.row.success").removeClass("success");}})}', 'success' => 'setTimeout(function(r){jQuery("div#notifsave").dialog("close");$.fn.yiiGridView.update("yw0");},800)'), array('id' => 'save', 'name' => 'save')); ?> <?php $this->endWidget(); } ?> </div>
public static function bulkOrder($rawdatas, $customer, $contact, $routing_code) { $failed = array(); $success = array(); $line_error = array(); $counter = 0; $column = array(); foreach ($rawdatas as $data) { $valid_area = true; if ($counter++ == 0) { continue; } $column = explode(',', $data); $shipment = new Shipment(); if (count($column) == 21) { //account detail $shipment->setAttribute('customer_id', $customer->id); $shipment->setAttribute('origin_code', $routing_code); //shipper_detail $shipment->setAttribute('shipper_name', trim($column[2])); $shipment->setAttribute('shipper_company_name', trim($column[1])); $shipment->setAttribute('shipper_address', trim($column[3])); $shipment->setAttribute('shipper_city', trim($column[5])); $shipment->setAttribute('shipper_country', trim($column[6])); $shipment->setAttribute('shipper_postal', trim($column[7])); $shipment->setAttribute('shipper_phone', trim($column[4])); //receiver_detail $shipment->setAttribute('receiver_name', trim($column[9])); $shipment->setAttribute('receiver_company_name', trim($column[8])); $shipment->setAttribute('receiver_address', trim($column[10])); $shipment->setAttribute('receiver_city', trim($column[12])); $shipment->setAttribute('receiver_country', trim($column[13])); $shipment->setAttribute('receiver_postal', trim($column[14])); $shipment->setAttribute('receiver_phone', trim($column[11])); //shipment_detail $shipment->setAttribute('type', 'document'); $shipment->setAttribute('payer', 'shipper'); $shipment->setAttribute('payby', 'account'); $shipment->setAttribute('pieces', trim($column[15])); $shipment->setAttribute('package_weight', trim($column[16])); $shipment->setAttribute('package_value', trim($column[17])); $shipment->setAttribute('service_type', trim($column[18])); $shipment->setAttribute('service_id', trim($column[19])); $shipment->setAttribute('service_code', trim($column[20])); $shipment->setAttribute('destination_code', trim($column[0])); $customer_rate = CustomerDiscount::getCustomerDiscountRate($shipment->service_id, $shipment->customer_id); if (!!$customer_rate) { if ($customer_rate['discount'] == null) { $customer_rate['discount'] = 0; } switch ($shipment->service_type) { case 'City Courier': $rate = RateCity::model()->findByAttributes(array('service_id' => $shipment->service_id)); if ($rate instanceof RateCity) { if ($customer_rate['harga_invoice'] != 0) { $price = $customer_rate['harga_invoice'] * RateCity::increment($shipment->package_weight, $rate->weight_inc); } else { $price = ($rate->price - $rate->price * ($customer_rate['discount'] / 100)) * RateCity::increment($shipment->package_weight, $rate->weight_inc); } $price_vendor = ($rate->price - $rate->price * ($customer_rate['vendor_discount'] / 100)) * RateCity::increment($shipment->package_weight, $rate->weight_inc); } else { $area = Area::getZoneID($shipment->receiver_postal); if (!$area) { $price = 0; $price_vendor = 0; $valid_area = false; } else { $price = RateDomestic::getRatePrice($shipment->service_id, 1, $area['district_id'], $area['zone_id'], $shipment->package_weight, $customer_rate['discount']); $price_vendor = RateDomestic::getRatePrice($shipment->service_id, 1, $area['district_id'], $area['zone_id'], $shipment->package_weight, $customer_rate['vendor_discount']); } } break; case 'Domestic': $area = Area::getZoneID($shipment->receiver_postal); if (!$area) { $price = 0; $price_vendor = 0; $valid_area = false; } else { $price = RateDomestic::getRatePrice($shipment->service_id, 1, $area['district_id'], $area['zone_id'], $shipment->package_weight, $customer_rate['discount']); $price_vendor = RateDomestic::getRatePrice($shipment->service_id, 1, $area['district_id'], $area['zone_id'], $shipment->package_weight, $customer_rate['vendor_discount']); } break; case 'International': $zone = FALSE; if ($shipment->service_code == 'IEX') { $country = $shipment->receiver_country; } else { if ($shipment->service_code == 'IMX') { $country = $shipment->shipper_country; } } $zone = ZoneInternational::getZoneCountryData($country); if (!!$zone) { $price = RateInternational::getRatePrice($shipment->service_id, $shipment->package_weight, $shipment->type, $zone, $customer_rate['discount']); $price_vendor = RateInternational::getRatePrice($shipment->service_id, $shipment->package_weight, $shipment->type, $zone, $customer_rate['vendor_discount']); } else { $price = 0; $price_vendor = 0; $valid_area = false; } break; case '': continue; } $shipment->shipping_charges = $price; $shipment->vendor_charge = $price_vendor; $shipment->awb = '90' . rand(10000000, 99999999); while (!$shipment->validate(array('awb'))) { $shipment->awb = '90' . rand(10000000, 99999999); } if ($shipment->save()) { $additional_costs = ShipmentAdditionalCharge::initSurcharges($shipment); $shipment->charges = $shipment->shipping_charges + $additional_costs; $shipment->save(); array_push($success, $counter); } else { CVarDumper::dump($shipment->attributes, 10, true); CVarDumper::dump($shipment->getErrors(), 10, true); array_push($failed, array('counter' => $counter, 'message' => $shipment->getErrors())); } } else { array_push($failed, array('counter' => $counter, 'message' => array('this service is not available'))); } } else { array_push($failed, array('counter' => $counter, 'message' => array('wrong delimiter format'))); } } return array('success' => $success, 'failed' => $failed); }
public function actionImportCSV() { ini_set('max_execution_time', 300); $this->layout = '//layouts/column2'; $model = new UserImportForm(); $failed_to_insert = array(); $exist_postcode = array(); $next_kg = -1; $first_kg = -1; $min_trans = -1; $max_trans = -1; $zone_id = -1; $district_id = -1; if (isset($_POST['UserImportForm'])) { $model->attributes = $_POST['UserImportForm']; if ($model->validate()) { $csvFile = CUploadedFile::getInstance($model, 'file'); $tempLoc = $csvFile->getTempName(); $rawdatas = file($tempLoc); try { $connection = Yii::app()->db; $transaction = $connection->beginTransaction(); $sql = "INSERT INTO rate_domestic (service_id, origin_id, first_kg, next_kg, min_transit_time,max_transit_time,zone_id,district_id) VALUES(:service_id, :origin_id, :first_kg, :next_kg, :min_transit_time, :max_transit_time,:zone_id,:district_id)"; $command = $connection->createCommand($sql); $command->bindValue(":service_id", $model->service_id, PDO::PARAM_INT); $command->bindValue(":origin_id", $model->origin_id, PDO::PARAM_INT); $command->bindParam(':zone_id', $zone_id); $command->bindParam(':district_id', $district_id); $command->bindParam(':first_kg', $first_kg); $command->bindParam(':next_kg', $next_kg); $command->bindParam(':min_transit_time', $min_trans); $command->bindParam(':max_transit_time', $max_trans); foreach ($rawdatas as $rates) { $rate = explode(',', $rates); if (!in_array($rate[0], $exist_postcode, true)) { $exist_postcode[] = $rate[0]; // var_dump($rate[1]); // if (!is_numeric($rate[1]) || !is_numeric($rate[2]) || !is_numeric($rate[3])) // { // $failed_to_insert[] = $rate[0]; // continue; // } $postcode_data = Area::getZoneID($rate[0]); $checkZoneId = RateDomestic::checkZoneId($model->service_id, $model->origin_id, $postcode_data['zone_id']); if ($checkZoneId) { continue; } $first_kg = $rate[1]; $next_kg = $rate[2]; $min_trans = $rate[3]; $max_trans = $rate[4]; $zone_id = $postcode_data['zone_id']; $district_id = $postcode_data['district_id']; if (!!$postcode_data) { $exec = $command->execute(); } } } $transaction->commit(); } catch (Exception $e) { CVarDumper::dump($e, 10, TRUE); exit; $transaction->rollBack(); } } } $this->render("importcsv", array('model' => $model)); }
public function actionGetExtRate() { if (Yii::app()->request->isAjaxRequest) { $result = array('status' => 'error', 'data' => ''); $data = array(); if (isset($_POST['Shipment'])) { $shipment = new Shipment(); $shipment->setAttributes($_POST['Shipment']); switch ($shipment->service_type) { case 'City Courier': $rate = RateCity::model()->findByAttributes(array('service_id' => $shipment->service_id)); if ($rate instanceof RateCity) { $price = $rate->price * RateCity::increment($shipment->package_weight, $rate->weight_inc); } else { $area = Area::getZoneID($shipment->receiver_postal); $price = RateDomestic::getRatePrice($shipment->service_id, 1, $area['district_id'], $area['zone_id'], $shipment->package_weight); } $result = array('status' => 'success', 'data' => $price); break; case 'Domestic': $area = Area::getZoneID($shipment->receiver_postal); $price = RateDomestic::getRatePrice($shipment->service_id, 1, $area['district_id'], $area['zone_id'], $shipment->package_weight); $result = array('status' => 'success', 'data' => $price); break; case 'International': $zone = FALSE; if ($shipment->service_code == 'IEX') { $country = $shipment->receiver_country; } else { if ($shipment->service_code == 'IMX') { $country = $shipment->shipper_country; } } $zone = ZoneInternational::getZoneCountryData($country); if (!!$zone) { $price = RateInternational::getRatePrice($shipment->service_id, $shipment->package_weight, $shipment->type, $zone); $result = array('status' => 'success', 'data' => $price); } break; case '': continue; } } echo CJSON::encode($result); Yii::app()->end(); } }