コード例 #1
0
 public function actionGetExtRoutingCode()
 {
     $result = array('status' => 'error', 'data' => '');
     $data = array();
     if (isset($_GET['country']) && isset($_GET['postal'])) {
         $country = ucfirst($_GET['country']);
         $postal = $_GET['postal'];
         if ($country != 'Indonesia') {
             $routings = RateCompany::model()->findAllByAttributes(array('is_international' => 1));
             if (count($routings) != 0) {
                 foreach ($routings as $routing) {
                     array_push($data, array('code' => $routing->code));
                 }
                 $result = array('status' => 'success', 'data' => $data, 'service_type' => 'International');
             }
         } else {
             $routing = IntraCityRouting::model()->findByAttributes(array('postcode' => $postal));
             if ($routing instanceof IntraCityRouting) {
                 array_push($data, array('code' => $routing->code));
                 $result = array('status' => 'success', 'data' => $data, 'service_type' => 'City Courier');
             } else {
                 $area = Area::getZoneID($postal);
                 if (!!$area) {
                     $routings = RateCompany::model()->findAllByAttributes(array('is_domestic' => 1));
                     if (count($routings) != 0) {
                         foreach ($routings as $routing) {
                             array_push($data, array('code' => $routing->code));
                         }
                         $result = array('status' => 'success', 'data' => $data, 'service_type' => 'Domestic');
                     }
                 }
             }
         }
         echo CJSON::encode($result);
         Yii::app()->end();
     }
 }
コード例 #2
0
 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));
 }
コード例 #3
0
ファイル: Shipment.php プロジェクト: aantonw/dcourier.system
 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);
 }
コード例 #4
0
 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();
     }
 }