/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Kurir::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['ID' => $this->ID, 'TOTALWEIGHT' => $this->TOTALWEIGHT, 'HARGA' => $this->HARGA]); $query->andFilterWhere(['like', 'KURIR', $this->KURIR])->andFilterWhere(['like', 'KATEGORI', $this->KATEGORI])->andFilterWhere(['like', 'KURIRKATEGORI', $this->KURIRKATEGORI])->andFilterWhere(['like', 'ORIGINPROV', $this->ORIGINPROV])->andFilterWhere(['like', 'DESPROV', $this->DESPROV])->andFilterWhere(['like', 'ORIGINCITY', $this->ORIGINCITY])->andFilterWhere(['like', 'DESCITY', $this->DESCITY])->andFilterWhere(['like', 'POSTALCODEORIGIN', $this->POSTALCODEORIGIN])->andFilterWhere(['like', 'POSTALCODEDESC', $this->POSTALCODEDESC]); return $dataProvider; }
public function actionPrice() { $provinsi = new Provinsi(); $kota = new Kota(); $harga = new Harga(); $model2 = new Kurir(); $data = Yii::$app->request->post(); error_reporting(0); $origin = $data['Harga']['ORIGIN_CITY']; $destination = $data['Harga']['DES_CITY']; $weight = $data['Harga']['HARGA']; $curl = curl_init(); curl_setopt_array($curl, array(CURLOPT_URL => "http://rajaongkir.com/api/starter/cost", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "POST", CURLOPT_POSTFIELDS => "origin={$origin}&destination={$destination}&weight={$weight}", CURLOPT_HTTPHEADER => array("key:f23794936f254ee0738d79110c112ad0"))); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { echo "cURL Error #:" . $err; } else { $data = json_decode($response, true); } ?> <?php $coun = Kurir::find()->count(); if ($coun > 0) { $db = \Yii::$app->db; $db->createCommand('DELETE FROM b0001')->execute(); for ($i = 0; $i < count($data['rajaongkir']['results']); $i++) { // echo strtoupper($data['rajaongkir']['results'][$i]['name']).'<br>'; for ($j = 0; $j < count($data['rajaongkir']['results'][$i]['costs']); $j++) { $province_id = $data['rajaongkir']['origin_details']['province_id'] . '<br/>'; $originprov = $data['rajaongkir']['origin_details']['province']; $origincity = $data['rajaongkir']['origin_details']['city_name']; $postalcodeorigin = $data['rajaongkir']['origin_details']['postal_code']; $desprov = $data['rajaongkir']['destination_details']['province']; $descity = $data['rajaongkir']['destination_details']['city_name']; $postalcodedes = $data['rajaongkir']['destination_details']['postal_code']; $weight = $data['rajaongkir']['query']['weight']; $province_id_des = $data['rajaongkir']['destination_details']['province_id'] . '<br/>'; $city_id_desc = $data['rajaongkir']['destination_details']['city_id'] . '<br/>'; $nama_kurir = $data['rajaongkir']['results'][$i]['name']; $servis_kurir = $data['rajaongkir']['results'][$i]['costs'][$j]['service']; $description = $data['rajaongkir']['results'][$i]['costs'][$j]['description']; //echo $data['rajaongkir']['results'][$i]['costs'][$j]['cost'][0]['etd'].'<br><br>'; $harga1 = $data['rajaongkir']['results'][$i]['costs'][$j]['cost'][0]['value']; $db = \Yii::$app->db; $prov_id = $row->province_id; $prov = $row->province; $db->createCommand()->batchInsert('b0001', ['KURIR', 'KATEGORI', 'KATEGORI_DETAIL', 'KURIRKATEGORI', 'ORIGINPROV', 'DESPROV', 'ORIGINCITY', 'DESCITY', 'POSTALCODEORIGIN', 'POSTALCODEDESC', 'TOTALWEIGHT', 'HARGA'], [[$nama_kurir, $servis_kurir, $description, $nama_kurir . " " . $servis_kurir, $originprov, $desprov, $origincity, $descity, $postalcodeorigin, $postalcodedes, $weight, $harga1]])->execute(); } } } else { for ($i = 0; $i < count($data['rajaongkir']['results']); $i++) { // echo strtoupper($data['rajaongkir']['results'][$i]['name']).'<br>'; for ($j = 0; $j < count($data['rajaongkir']['results'][$i]['costs']); $j++) { $province_id = $data['rajaongkir']['origin_details']['province_id'] . '<br/>'; $originprov = $data['rajaongkir']['origin_details']['province']; $origincity = $data['rajaongkir']['origin_details']['city_name']; $postalcodeorigin = $data['rajaongkir']['origin_details']['postal_code']; $desprov = $data['rajaongkir']['destination_details']['province']; $descity = $data['rajaongkir']['destination_details']['city_name']; $postalcodedes = $data['rajaongkir']['destination_details']['postal_code']; $weight = $data['rajaongkir']['query']['weight']; $province_id_des = $data['rajaongkir']['destination_details']['province_id'] . '<br/>'; $city_id_desc = $data['rajaongkir']['destination_details']['city_id'] . '<br/>'; $nama_kurir = $data['rajaongkir']['results'][$i]['name']; $servis_kurir = $data['rajaongkir']['results'][$i]['costs'][$j]['service']; $desc = $data['rajaongkir']['results'][$i]['costs'][$j]['description']; //echo $data['rajaongkir']['results'][$i]['costs'][$j]['cost'][0]['etd'].'<br><br>'; $harga1 = $data['rajaongkir']['results'][$i]['costs'][$j]['cost'][0]['value']; $db = \Yii::$app->db; $prov_id = $row->province_id; $prov = $row->province; $db->createCommand()->batchInsert('b0001', ['KURIR', 'KATEGORI', 'KATEGORI_DETAIL', 'KURIRKATEGORI', 'ORIGINPROV', 'DESPROV', 'ORIGINCITY', 'DESCITY', 'POSTALCODEORIGIN', 'POSTALCODEDESC', 'TOTALWEIGHT', 'HARGA'], [[$nama_kurir, $servis_kurir, $desc, $nama_kurir . " " . $servis_kurir, $originprov, $desprov, $origincity, $descity, $postalcodeorigin, $postalcodedes, $weight, $harga1]])->execute(); } } } return $this->render('view', ['provinsi' => $provinsi, 'kota' => $kota, 'model' => $harga, 'model2' => $model2, 'data' => $data, 'province_id' => $province_id, 'city_id' => $city_id, 'province_id_des' => $province_id_des, 'city_id_desc' => $city_id_desc, 'nama_kurir' => $nama_kurir, 'servis_kurir' => $servis_kurir, 'harga' => $harga1]); }
} ?> </table> <div class="row"> <?php $form = ActiveForm::begin(['method' => 'post', 'action' => ['site/act']]); ?> <div class="col-md-7" style="background-color:#f6f6f6;"> <table class="table row"style="margin-bottom:0px;"> <tbody> <tr> <td> <?php echo $form->field($model2, 'KURIR')->widget(Select2::classname(), ['data' => ArrayHelper::map(Kurir::find()->all(), 'ID', 'KURIRKATEGORI'), 'language' => 'en', 'options' => ['placeholder' => '--Pilih Kurir--', 'id' => 'KURIR'], 'pluginOptions' => ['allowClear' => true]]); ?> <?php echo $form->field($model2, 'HARGA')->textInput(['maxlength' => true])->label('Values Checking'); ?> </td> </tr> <tr> <td> <b>Details :</b> </td> </tr>