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; } }
/** * 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 function actionDelete($id = '') { if ($id != '') { if (Yii::app()->request->isPostRequest) { // we only allow deletion via POST request RateDomestic::model()->findByPk($id)->delete(); // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser if (!isset($_GET['ajax'])) { $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin')); } } else { throw new CHttpException(400, 'Invalid request. Please do not repeat this request again.'); } } }
* 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 function getTransitTime($service_type, $service_id = '', $receiver_zone_code = '', $receiver_city_code = '', $receiver_country_id = '') { $trans_date = ''; $trans_time = ''; switch ($service_type) { case 'domestic': $rate = RateDomestic::model()->findByAttributes(array('service_id' => $service_id, 'origin_id' => 1, 'zone_id' => $receiver_zone_code, 'district_id' => $receiver_city_code)); if ($rate instanceof RateDomestic) { $trans_date = Yii::app()->dateFormatter->format('MM/dd/yyyy', strtotime('+' . $rate->transit_time . ' day')); $trans_time = $rate->transit_time; } break; case 'city': $city_type = IntraCityTypes::model()->findByPk($service_id); if ($city_type instanceof IntraCityTypes) { $trans_date = Yii::app()->dateFormatter->format('MM/dd/yyyy', strtotime('+' . $city_type->transit_time . ' day')); $trans_time = $city_type->transit_time; } break; case 'international': $zone_country = ZoneInternational::model()->findByPk($receiver_country_id); if ($zone_country instanceof ZoneInternational) { $trans_date = Yii::app()->dateFormatter->format('MM/dd/yyyy', strtotime('+' . $zone_country->transit_time . ' day')); $trans_time = $zone_country->transit_time; } break; } return array('trans_date' => $trans_date, 'trans_time' => $trans_time); }