public static function createFromEntrysheet($data, $model = null) { $es = $data['entry_sheet']; if (!$es instanceof EntriSheet) { $es = EntriSheet::findOne($es); } $values = $data['values']; unset($data['entry_sheet'], $data['values']); $details = []; foreach ($es->entriSheetDtls as $esDetail) { $nm = $esDetail->cd_esheet_dtl; if (isset($values[$nm])) { $details[] = ['id_coa' => $esDetail->id_coa, 'amount' => $values[$nm]]; } else { throw new UserException("Required account \"{$nm}\" "); } } $data['details'] = $details; return static::create($data, $model); }
/** * * @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; }
/** * 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.'); } }