/** * * @param array $templates */ public function addFromTemplate($templates = [], $description = false) { $items = $this->glDetails; foreach ($templates as $code => $amount) { /* @var $es EntriSheet */ $es = EntriSheet::findOne(['code' => $code]); if ($description === true) { $this->description .= "\n" . $es->name; } $items[] = ['coa_id' => $es->d_coa_id, 'amount' => $amount]; $items[] = ['coa_id' => $es->k_coa_id, 'amount' => -1 * $amount]; } if (is_string($description)) { $this->description .= "\n{$description}"; } $this->glDetails = $items; }
public function actionTestEntriJournal() { $model = new EntriSheet(); $dPost = Yii::$app->request->post(); if (!empty($dPost)) { $model = EntriSheet::findOne($dPost['EntriSheet']['id']); $model->amount = $dPost['EntriSheet']['amount']; $newGl = new GlHeader(); $newGl->reff_type = 0; $newGl->reff_id = null; $newGl->date = date('Y-m-d'); $newDtls = []; foreach ($model->entriSheetDtls as $ddtl) { $ndtl = new \backend\models\accounting\GlDetail(); $ndtl->coa_id = $ddtl->coa_id; $ndtl->header_id = null; $ndtl->amount = $ddtl->dk == $ddtl::DK_CREDIT ? -1 * $model->amount : $model->amount; $newDtls[] = $ndtl; } $newGl->status = $newGl::STATUS_RELEASED; $activePeriode = \backend\models\accounting\AccPeriode::find()->active()->one(); $newGl->periode_id = $activePeriode->id; $newGl->branch_id = 1; $newGl->description = $model->name; $newGl->glDetails = $newDtls; if (!$newGl->save()) { // print_r($newGl->getErrors()); // print_r($newGl->getRelatedErrors()); return $this->redirect(['/accounting/general-ledger/view', 'id' => $model->id]); } } return $this->render('test', ['model' => $model]); }