public function actionIndex() { $arrAccount = JarAccount::find()->where(['delete_flag' => MasterValueUtils::MV_FIN_FLG_DELETE_FALSE, 'account_type' => MasterValueUtils::MV_JAR_ACCOUNT_TYPE_JAR])->orderBy('status, order_num')->all(); $tempAccount = JarAccount::findOne(9); $sumAccountQuery = (new Query())->select(['SUM(useable_balance) AS useable_balance, SUM(real_balance) AS real_balance, SUM(share_unit) AS share'])->from('jar_account')->where(['delete_flag' => MasterValueUtils::MV_FIN_FLG_DELETE_FALSE, 'status' => MasterValueUtils::MV_JAR_ACCOUNT_STATUS_ON, 'account_type' => MasterValueUtils::MV_JAR_ACCOUNT_TYPE_JAR]); $sumAccountValue = $sumAccountQuery->createCommand()->queryOne(); // render GUI $renderData = ['arrAccount' => $arrAccount, 'tempAccount' => $tempAccount, 'sumAccountValue' => $sumAccountValue]; return $this->render('index', $renderData); }
public function actionUpdate($id) { $this->objectId = $id; // master value $fmShortDatePhp = DateTimeUtils::getDateFormat(DateTimeUtils::FM_KEY_PHP, null); $fmShortDateJui = DateTimeUtils::getDateFormat(DateTimeUtils::FM_KEY_JUI, null); JarPayment::$_PHP_FM_SHORTDATE = $fmShortDatePhp; $model = JarPayment::findOne(['id' => $id, 'delete_flag' => MasterValueUtils::MV_FIN_FLG_DELETE_FALSE]); $renderView = 'update'; if (is_null($model)) { $model = false; $renderData = ['model' => $model]; Yii::$app->session->setFlash(MasterValueUtils::FLASH_ERROR, Yii::t('common', 'The requested {record} does not exist.', ['record' => Yii::t('jar.models', 'Payment')])); } else { if ($model->share_id > 0) { return Yii::$app->getResponse()->redirect(Url::to(['/jar/distribute/update', 'id' => $model->share_id])); } // master value $arrAccount = ModelUtils::getArrData(JarAccount::find()->select(['account_id', 'account_name'])->where(['delete_flag' => MasterValueUtils::MV_FIN_FLG_DELETE_FALSE])->orderBy('account_type, order_num'), 'account_id', 'account_name'); $arrEntryLog = MasterValueUtils::getArrData('jar_payment_status'); // submit data $postData = Yii::$app->request->post(); $submitMode = isset($postData[MasterValueUtils::SM_MODE_NAME]) ? $postData[MasterValueUtils::SM_MODE_NAME] : false; // populate model attributes with user inputs $model->load($postData); // init value $model->scenario = MasterValueUtils::SCENARIO_UPDATE; // render GUI $renderData = ['model' => $model, 'fmShortDatePhp' => $fmShortDatePhp, 'fmShortDateJui' => $fmShortDateJui, 'arrAccount' => $arrAccount, 'arrEntryLog' => $arrEntryLog]; switch ($submitMode) { case MasterValueUtils::SM_MODE_INPUT: $isValid = $model->validate(); if ($isValid) { $renderView = 'confirm'; $renderData['formMode'] = [MasterValueUtils::PG_MODE_NAME => MasterValueUtils::PG_MODE_EDIT]; } break; case MasterValueUtils::SM_MODE_CONFIRM: $isValid = $model->validate(); if ($isValid) { $result = $this->updatePayment($model, $fmShortDatePhp); if ($result === true) { Yii::$app->session->setFlash(MasterValueUtils::FLASH_SUCCESS, Yii::t('common', '{record} has been saved successfully.', ['record' => Yii::t('jar.models', 'Payment')])); return Yii::$app->getResponse()->redirect(Url::to(['update', 'id' => $id])); } else { // restore Data for View $model->entry_date = DateTimeUtils::parse($model->entry_date, DateTimeUtils::FM_DB_DATE, $fmShortDatePhp); // render View Yii::$app->session->setFlash(MasterValueUtils::FLASH_ERROR, $result); $renderView = 'confirm'; $renderData['formMode'] = [MasterValueUtils::PG_MODE_NAME => MasterValueUtils::PG_MODE_EDIT]; } } break; case MasterValueUtils::SM_MODE_BACK: break; default: break; } } // render GUI return $this->render($renderView, $renderData); }
/** * get list of JarShareDetail * @param $share JarShare * @param $backup boolean * @return array JarShareDetail */ private function initShareDetail($share, $backup = false) { $results = null; if (is_null($share->share_id)) { $results = []; $arrAccount = JarAccount::find()->where(['delete_flag' => MasterValueUtils::MV_FIN_FLG_DELETE_FALSE, 'account_type' => MasterValueUtils::MV_JAR_ACCOUNT_TYPE_JAR, 'status' => MasterValueUtils::MV_JAR_ACCOUNT_STATUS_ON])->orderBy('order_num')->all(); $per = 1.0 * $share->share_value / 100; foreach ($arrAccount as $account) { $item = new JarShareDetail(); $item->account_id = $account->account_id; $item->account_name = $account->account_name; $item->share_unit = $account->share_unit; $item->share_value = NumberUtils::rounds($per * $account->share_unit); $results[] = $item; } } else { $results = JarShareDetail::find()->select('d.*, a.account_name, p.entry_value AS share_value')->from('jar_share_detail d, jar_account a, jar_payment p')->where(['d.share_id' => $share->share_id, 'd.delete_flag' => MasterValueUtils::MV_FIN_FLG_DELETE_FALSE])->andWhere('d.account_id = a.account_id AND d.share_id = p.share_id AND a.account_id = p.account_target')->orderBy('a.order_num')->all(); if ($backup) { $per = 1.0 * $share->share_value / 100; foreach ($results as $result) { $result->share_value_old = $result->share_value; $result->share_value = NumberUtils::rounds($per * $result->share_unit); } } } return $results; }