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]); }
/** * * @param string $name Entri Sheet name * @param array $values * @return array * @throws UserException */ public static function entriSheetToGlMaps($name, $values) { $gl_dtls = []; $esheet = EntriSheet::findOne(['nm_esheet' => $name]); if ($esheet) { foreach ($esheet->entriSheetDtls as $eDtl) { $coa = $eDtl->id_coa; $nm = $eDtl->nm_esheet_dtl; $dc = $eDtl->idCoa->normal_balance == 'D' ? 1 : -1; if (isset($values[$nm])) { $ammount = $dc * $values[$nm]; } else { throw new UserException("Required account {$nm} "); } $gl_dtls[] = ['id_coa' => $coa, 'ammount' => $ammount]; } } else { throw new UserException("Entrysheet {$name} not found"); } return $gl_dtls; }
/** * @return \yii\db\ActiveQuery */ public function getIdEsheet() { return $this->hasOne(EntriSheet::className(), ['id_esheet' => 'id_esheet']); }
/** * Finds the EntriSheet model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return EntriSheet the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = EntriSheet::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }