public function search($params) { $query = EntriSheetModel::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id_esheet' => $this->id_esheet, 'create_by' => $this->create_by, 'update_by' => $this->update_by]); $query->andFilterWhere(['like', 'cd_esheet', $this->cd_esheet])->andFilterWhere(['like', 'nm_esheet', $this->nm_esheet])->andFilterWhere(['like', 'create_date', $this->create_date])->andFilterWhere(['like', 'update_date', $this->update_date]); return $dataProvider; }
/** * Creates a new GlHeader model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate($es = null) { $sheets = EntriSheet::find()->asArray()->all(); $sheets = \yii\helpers\ArrayHelper::map($sheets, 'id_esheet', 'nm_esheet'); $model = new GlHeader(); $details = []; if (!empty($es)) { foreach (EntriSheetDtl::findAll(['id_esheet' => $es]) as $eDtl) { /* @var $eDtl EntriSheetDtl */ $glDtl = new GlDetail(['id_coa' => $eDtl->id_coa]); $details[$eDtl->nm_esheet_dtl] = $glDtl; } $post = Yii::$app->request->post(); if ($model->load($post) && Model::loadMultiple($details, $post)) { $transaction = Yii::$app->db->beginTransaction(); try { $amount = 0.0; $model->status = 1; if ($model->save()) { $id_hdr = $model->id_gl; foreach ($details as $detail) { $amount += $detail->amount; $detail->id_gl = $id_hdr; if (!$detail->save()) { throw new \Exception(implode("\n", $detail->firstErrors)); } } if ($amount != 0.0) { throw new \Exception('Not balance'); } $transaction->commit(); return $this->redirect(['view', 'id' => $model->id_gl]); } else { $transaction->rollBack(); } } catch (\Exception $exc) { $transaction->rollBack(); $model->addError('', $exc->getMessage()); } } } return $this->render('create', ['model' => $model, 'details' => $details, 'es' => $es, 'sheets' => $sheets]); }