/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = DetailModel::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, 'tgl' => $this->tgl, 'jml' => $this->jml, 'data_time' => $this->data_time, 'hidden' => $this->hidden]); $query->andFilterWhere(['like', 'jenis', $this->jenis]); return $dataProvider; }
// echo $this->render('_search', ['model' => $searchModel]); ?> <p> <?php echo Html::button('Tambah Data', ['class' => 'btn btn-success', 'data-toggle' => 'modal', 'data-target' => '#j-modal-detail']); ?> </p> <?php Pjax::begin(['id' => 'pjax-detail']); ?> <div class="table-small"> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], ['attribute' => 'tgl', 'value' => function ($data) { return FunctionModel::tglIndo($data->tgl); }, 'footer' => 'Total', 'footerOptions' => ['style' => 'text-align : center']], ['attribute' => 'jumlah', 'contentOptions' => ['class' => 'right'], 'format' => ['Decimal', 0], 'footer' => number_format(DetailModel::getTotal(), 0)], ['class' => 'yii\\grid\\ActionColumn', 'template' => '{detail}', 'buttons' => ['detail' => function ($url, $model, $key) { return Html::a('detail', Yii::$app->urlManager->createUrl(['detail/detil', "tgl" => $model->tgl]), ['title' => 'lihat detail pengeluaran']); }], 'contentOptions' => ['class' => 'middle']]], 'showFooter' => TRUE, 'footerRowOptions' => ['class' => 'right', 'style' => 'font-weight:bold']]); ?> </div> <?php Pjax::end(); ?> </div> <!-- Modal --> <div class="modal fade" id="j-modal-detail" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" data-backdrop="static"> <div class="modal-dialog" role="document"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h1><?php echo Html::encode($this->title, false); ?> </h1> <p><?php echo FunctionModel::tglIndo($data['tgl']); ?> </p> <?php // echo $this->render('_search', ['model' => $searchModel]); ?> <p> <?php echo Html::a('Create Detail Model', ['create'], ['class' => 'btn btn-success']); ?> </p> <?php Pjax::begin(['id' => 'pjax-detail']); ?> <div class="table-medium"> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], ['attribute' => 'jenis', 'footer' => 'Total', 'footerOptions' => ['style' => 'text-align : center']], ['attribute' => 'jml', 'contentOptions' => ['class' => 'right'], 'footer' => number_format(DetailModel::getDetailTotal($data['tgl']), 0), 'format' => ['Decimal', 0]], ['class' => 'yii\\grid\\ActionColumn', 'contentOptions' => ['class' => 'middle']]], 'showFooter' => TRUE, 'footerRowOptions' => ['class' => 'right', 'style' => 'font-weight:bold']]); ?> </div> <?php Pjax::end(); ?> </div>
public static function getTotal() { $model = DetailModel::find()->select('sum(jml) as jumlah')->where("hidden = 1")->one(); return $model->jumlah; }
/** * Finds the DetailModel model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return DetailModel the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = DetailModel::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }