Example #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = HarvestPlant::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, 'plant_id' => $this->plant_id, 'state_id' => $this->state_id, 'year' => $this->year, 'quarter' => $this->quarter, 'param1' => $this->param1, 'param2' => $this->param2, 'param3' => $this->param3, 'param4' => $this->param4, 'param5' => $this->param5, 'created_at' => $this->created_at, 'created_by' => $this->created_by, 'updated_at' => $this->updated_at, 'updated_by' => $this->updated_by]);
     $query->andFilterWhere(['like', 'note1', $this->note1])->andFilterWhere(['like', 'note2', $this->note2])->andFilterWhere(['like', 'note3', $this->note3])->andFilterWhere(['like', 'note4', $this->note4])->andFilterWhere(['like', 'note5', $this->note5]);
     return $dataProvider;
 }
Example #2
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getHarvestPlants()
 {
     return $this->hasMany(HarvestPlant::className(), ['plant_id' => 'id']);
 }
Example #3
0
 echo '<h3>' . $typePlant->name . '</h3>';
 $plants = \app\models\Plant::find()->where(['type_plant_id' => $typePlant->id])->all();
 $idx_plant = 0;
 foreach ($plants as $plant) {
     echo '<h4>' . ++$idx_plant . '. ' . $plant->name . '</h4>';
     $where['plant_id'] = $plant->id;
     if (!empty($years)) {
         $where['year'] = $years;
     }
     if (!empty($quarters)) {
         $where['quarter'] = $quarters;
     }
     if (!empty($harvestPlantReportSearch->stateIds)) {
         $where['state_id'] = $harvestPlantReportSearch->stateIds;
     }
     $harvestPlants = \app\models\HarvestPlant::find()->select("\n                    sum(param1) as sparam1,\n                    sum(param2) as sparam2,\n                    sum(param3) as sparam3,\n                    sum(param4) as sparam4,\n                    sum(param5) as sparam5,\n                    group_concat(note1) as gcnote1,\n                    group_concat(note2) as gcnote2,\n                    group_concat(note3) as gcnote3,\n                    group_concat(note4) as gcnote4,\n                    group_concat(note5) as gcnote5,\n                    count(state_id) as cstate,\n                  ")->where($where)->asArray()->one();
     $params = explode('|', $typePlant->params);
     $units = explode('|', $typePlant->units);
     if (count($params) > 0 and count($units) > 0 and count($params) == count($units)) {
         $combines = array_combine($params, $units);
         ?>
               <table class="table table-condensed table-striped">
                 <tr>
                   <th style="width:20px;" class="text-center">No</th>
                   <th style="width:200px;" class="text-center">Parameter</th>
                   <th style="width:150px;" class="text-center">Nilai</th>
                   <th style="width:50px;" class="text-center">Satuan</th>
                   <th class="text-center">Keterangan</th>
                   <th style="width:100px;" class="text-center">Data Masuk</th>
                 </tr>
                 <tbody>
 /**
  * Finds the HarvestPlant model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return HarvestPlant the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = HarvestPlant::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 public function actionExportExcel()
 {
     //$searchModel = new SecuritasSearch();
     //$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
     $session = Yii::$app->session;
     $renderHarvestPlantReport = $session->get('renderHarvestPlantReport');
     $objReader = \PHPExcel_IOFactory::createReader('Excel2007');
     $template = Yii::getAlias('@app/views/' . $this->id) . '/_export.xlsx';
     $objPHPExcel = $objReader->load($template);
     $activeSheet = $objPHPExcel->getActiveSheet();
     $border_style = ['borders' => ['allborders' => ['style' => \PHPExcel_Style_Border::BORDER_THIN, 'color' => ['argb' => '000000']]]];
     $text_center = ['horizontal' => \PHPExcel_Style_Alignment::HORIZONTAL_CENTER];
     $font_bold9 = ['font' => ['bold' => true, 'color' => ['rgb' => '000000'], 'size' => 9, 'name' => 'Calibri']];
     $font_bold8 = ['font' => ['bold' => true, 'color' => ['rgb' => '000000'], 'size' => 8, 'name' => 'Calibri']];
     $bg_gray = ['fill' => ['type' => \PHPExcel_Style_Fill::FILL_SOLID, 'color' => ['rgb' => 'dddddd']]];
     $activeSheet->setCellValue('G2', 'print at ' . date('d-M-Y H:i:s'));
     $years = 'Semua';
     if (!empty($renderHarvestPlantReport['years'])) {
         $years = implode(', ', $renderHarvestPlantReport['years']);
     }
     $activeSheet->setCellValue('C3', $years);
     $quarters = 'Semua';
     if (!empty($renderHarvestPlantReport['quarters'])) {
         $quarters = implode(', ', $renderHarvestPlantReport['quarters']);
     }
     $activeSheet->setCellValue('C4', $quarters);
     $states = 'Semua';
     if (!empty($renderHarvestPlantReport['states'])) {
         $states = implode(', ', $renderHarvestPlantReport['states']);
     }
     $activeSheet->setCellValue('C5', $states);
     $typePlants2 = 'Semua';
     if (!empty($renderHarvestPlantReport['typePlants2'])) {
         $typePlants2 = implode(', ', $renderHarvestPlantReport['typePlants2']);
     }
     $activeSheet->setCellValue('C7', $typePlants2);
     $typePlants = $renderHarvestPlantReport['typePlants'];
     $stateCount = $renderHarvestPlantReport['stateCount'];
     $startRow = 11;
     $i = 0;
     foreach ($typePlants as $typePlant) {
         if ($i == 0) {
             $row = $startRow + $i;
         } else {
             $row++;
         }
         //$activeSheet->insertNewRowBefore($row,1);
         $activeSheet->setCellValue('A' . $row, Helpers::columnLetter($i + 1));
         $activeSheet->setCellValue('B' . $row, $typePlant->name);
         $activeSheet->getStyle("A" . $row . ":B" . $row)->applyFromArray($font_bold9);
         $activeSheet->getStyle("A" . $row . ":A" . $row)->getAlignment()->applyFromArray($text_center);
         $plants = Plant::find()->where(['type_plant_id' => $typePlant->id])->all();
         $idx_plant = 0;
         foreach ($plants as $plant) {
             //$activeSheet->insertNewRowBefore($row,1);
             $row++;
             $activeSheet->setCellValue('B' . $row, $idx_plant + 1);
             $activeSheet->setCellValue('C' . $row, $plant->name);
             $activeSheet->getStyle("B" . $row . ":C" . $row)->applyFromArray($font_bold8);
             $activeSheet->getStyle("B" . $row . ":B" . $row)->getAlignment()->applyFromArray($text_center);
             $where['plant_id'] = $plant->id;
             if (!empty($renderHarvestPlantReport['years'])) {
                 $where['year'] = $renderHarvestPlantReport['years'];
             }
             if (!empty($renderHarvestPlantReport['quarters'])) {
                 $where['quarter'] = $renderHarvestPlantReport['quarters'];
             }
             if (!empty($renderHarvestPlantReport['stateIds'])) {
                 $where['state_id'] = $renderHarvestPlantReport['stateIds'];
             }
             $harvestPlants = HarvestPlant::find()->select("\n                    sum(param1) as sparam1,\n                    sum(param2) as sparam2,\n                    sum(param3) as sparam3,\n                    sum(param4) as sparam4,\n                    sum(param5) as sparam5,\n                    group_concat(note1) as gcnote1,\n                    group_concat(note2) as gcnote2,\n                    group_concat(note3) as gcnote3,\n                    group_concat(note4) as gcnote4,\n                    group_concat(note5) as gcnote5,\n                    count(state_id) as cstate\n                  ")->where($where)->asArray()->one();
             $params = explode('|', $typePlant->params);
             $units = explode('|', $typePlant->units);
             if (count($params) > 0 and count($units) > 0 and count($params) == count($units)) {
                 $combines = array_combine($params, $units);
                 $idx = 1;
                 $row++;
                 $starRowTable = $row;
                 $activeSheet->setCellValue('B' . $row, 'NO');
                 $activeSheet->setCellValue('C' . $row, 'PARAMETER');
                 $activeSheet->setCellValue('D' . $row, 'NILAI');
                 $activeSheet->setCellValue('E' . $row, 'SATUAN');
                 $activeSheet->setCellValue('F' . $row, 'KETERANGAN');
                 $activeSheet->setCellValue('G' . $row, 'DATA MASUK');
                 $activeSheet->getStyle('B' . $row . ':G' . $row)->applyFromArray($bg_gray);
                 foreach ($combines as $param => $unit) {
                     $row++;
                     $activeSheet->setCellValue('B' . $row, $idx);
                     $activeSheet->setCellValue('C' . $row, $param);
                     $activeSheet->setCellValue('D' . $row, $harvestPlants['sparam' . $idx]);
                     $activeSheet->setCellValue('E' . $row, $unit);
                     //$activeSheet->getStyle("F".$row)->getAlignment()->setWrapText(true);
                     //$activeSheet->getDefaultRowDimension()->setRowHeight(-1);
                     $activeSheet->getRowDimension($row)->setRowHeight(-1);
                     $activeSheet->setCellValue('F' . $row, $harvestPlants['gcnote' . $idx] . ' lorem ipsum sit dolor amet lorem ipsum sit dolor amet lorem ipsum sit dolor amet lorem ipsum sit dolor amet ');
                     $data = number_format($harvestPlants['cstate'] / $stateCount * 100, 2);
                     $activeSheet->setCellValue('G' . $row, $data . '%');
                     $idx++;
                 }
                 $activeSheet->getStyle("B" . $starRowTable . ":G" . $row)->applyFromArray($border_style);
                 $activeSheet->getStyle("B" . $starRowTable . ":G" . $row)->getAlignment()->applyFromArray($text_center);
                 $activeSheet->getStyle("F" . ($starRowTable + 1) . ":F" . $row)->getAlignment()->setWrapText(true);
             }
             $row++;
             $idx_plant++;
         }
         $i++;
     }
     header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
     header('Content-Disposition: attachment;filename="' . $this->id . '_' . date('YmdHis') . '.xlsx"');
     header('Cache-Control: max-age=0');
     $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, "Excel2007");
     $objWriter->save('php://output');
     exit;
 }