/**
  * 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);
 }
Beispiel #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;
 }
Beispiel #3
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']);
?>