/**
  * Lists all HarvestPlant models.
  * @return mixed
  */
 public function actionIndex()
 {
     $harvestPlantReportSearch = new HarvestPlantReportSearch();
     $harvestPlantReportSearch->yearStart = date('Y');
     $harvestPlantReportSearch->yearEnd = $harvestPlantReportSearch->yearStart;
     $harvestPlantReportSearch->quarterStart = 1;
     if (date('m') >= 9) {
         $harvestPlantReportSearch->quarterEnd = 4;
     } else {
         if (date('m') >= 6) {
             $harvestPlantReportSearch->quarterEnd = 3;
         } else {
             if (date('m') >= 3) {
                 $harvestPlantReportSearch->quarterEnd = 2;
             } else {
                 $harvestPlantReportSearch->quarterEnd = 1;
             }
         }
     }
     $typePlants = TypePlant::find()->all();
     $stateCount = State::find()->count();
     $years = [];
     $quarters = [];
     $states = State::find()->select('name')->column();
     $typePlants2 = TypePlant::find()->select('name')->column();
     $stateIds = [];
     if ($harvestPlantReportSearch->load(Yii::$app->request->post())) {
         $stateIds = $harvestPlantReportSearch->stateIds;
         if (!empty($stateIds)) {
             $stateCount = State::find()->where(['id' => $stateIds])->count();
             $states = State::find()->select('name')->where(['id' => $stateIds])->column();
         }
         $typePlantIds = $harvestPlantReportSearch->typePlantIds;
         if (!empty($typePlantIds)) {
             $typePlants = TypePlant::find()->where(['id' => $typePlantIds])->all();
             $typePlants2 = TypePlant::find()->select('name')->where(['id' => $typePlantIds])->column();
         }
         $yearStart = $harvestPlantReportSearch->yearStart;
         $yearEnd = $harvestPlantReportSearch->yearEnd;
         for ($i = $yearStart; $i <= $yearEnd; $i++) {
             $years[] = $i;
         }
         $quarterStart = $harvestPlantReportSearch->quarterStart;
         $quarterEnd = $harvestPlantReportSearch->quarterEnd;
         for ($i = $quarterStart; $i <= $quarterEnd; $i++) {
             $quarters[] = $i;
         }
     }
     $renders['typePlants'] = $typePlants;
     $renders['stateCount'] = $stateCount;
     $renders['stateIds'] = $stateIds;
     $renders['years'] = $years;
     $renders['quarters'] = $quarters;
     $renders['states'] = $states;
     $renders['typePlants2'] = $typePlants2;
     $session = Yii::$app->session;
     $session->set('renderHarvestPlantReport', $renders);
     $renders['harvestPlantReportSearch'] = $harvestPlantReportSearch;
     return $this->render('index', $renders);
 }
Ejemplo n.º 2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = TypePlant::find();
     // add conditions that should always apply here
     $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;
     }
     // grid filtering conditions
     $query->andFilterWhere(['id' => $this->id, 'name' => $this->name, 'sort' => $this->sort, 'created_at' => $this->created_at, 'created_by' => $this->created_by, 'updated_at' => $this->updated_at, 'updated_by' => $this->updated_by]);
     $query->andFilterWhere(['like', 'params', $this->params])->andFilterWhere(['like', 'units', $this->units]);
     return $dataProvider;
 }
Ejemplo n.º 3
0
?>
</h3>
     </div>
     <div class="panel-body">

    <?php 
// echo $this->render('_search', ['model' => $searchModel]);
?>

    <p>
        <?php 
echo Html::a('<span class=\'glyphicon glyphicon-plus-sign\'></span>  ' . Yii::t('app', 'Create'), ['create'], ['class' => 'btn btn-success']);
?>
    </p>

    <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], ['attribute' => 'type_plant_id', 'format' => 'raw', 'value' => function ($data) {
    if ($data->type_plant_id > 0) {
        return \app\models\TypePlant::findOne($data->type_plant_id)->name;
    } else {
        return "-";
    }
}], 'name', 'sort', ['attribute' => 'updated_at', 'headerOptions' => ['style' => 'width:125px;', 'class' => 'text-center'], 'contentOptions' => ['class' => 'text-center'], 'filter' => false, 'format' => ['date', 'php:d/m/y H:i']], ['attribute' => 'updated_by', 'headerOptions' => ['style' => 'width:100px;', 'class' => 'text-center'], 'contentOptions' => ['class' => 'text-center'], 'filter' => false, 'value' => function ($data) {
    return @\app\models\User::findOne($data->updated_by)->username;
}], ['class' => 'yii\\grid\\ActionColumn', 'header' => 'Actions', 'headerOptions' => ['style' => 'width:100px;', 'class' => 'text-center'], 'contentOptions' => ['class' => 'text-center']]]]);
?>

    </div>
  </div>
</div>
Ejemplo n.º 4
0
 /**
  * Finds the TypePlant model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return TypePlant the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = TypePlant::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Ejemplo n.º 5
0
use kartik\widgets\Select2;
use yii\helpers\ArrayHelper;
use app\models\TypePlant;
/* @var $this yii\web\View */
/* @var $model app\models\Plant */
/* @var $form yii\widgets\ActiveForm */
?>

<div class="plant-form">

    <?php 
$form = ActiveForm::begin();
?>

    <?php 
$data = ArrayHelper::map(TypePlant::find()->select(['id', 'name'])->asArray()->all(), 'id', 'name');
echo $form->field($model, 'type_plant_id')->widget(Select2::classname(), ['data' => $data, 'options' => ['placeholder' => 'Pilih Type Plant ...'], 'pluginOptions' => ['allowClear' => true]]);
?>

    <?php 
echo $form->field($model, 'name')->textInput(['maxlength' => true]);
?>

    <?php 
echo $form->field($model, 'sort')->textInput();
?>

    <div class="form-group">
        <?php 
echo Html::a('<span class="glyphicon glyphicon-step-backward" aria-hidden="true"></span> Back', ['index'], ['class' => 'btn btn-default']);
?>
Ejemplo n.º 6
0
 /**
  * Updates an existing HarvestPlant model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     $typePlant = null;
     if ($model->plant_id > 0) {
         $plant = Plant::findOne($model->plant_id);
         $typePlant = TypePlant::findOne($plant->type_plant_id);
     }
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('update', ['model' => $model, 'typePlant' => $typePlant]);
     }
 }