/** * get data as an Array [value_code=>locale] * @param type $code * @return Array */ public static function getArrData($code) { $locale = 'en'; $arrData = ModelUtils::getArrData(MasterValue::find()->select(['value', 'label'])->where(['delete_flag' => self::MV_FIN_FLG_DELETE_FALSE, 'value_code' => $code, 'locale' => $locale])->orderBy('order'), 'value', 'label'); return $arrData; }
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); }
public function actionCopy($id) { $this->objectId = $id; $model = FinTimeDepositTran::findOne(['transactions_id' => $id, 'delete_flag' => MasterValueUtils::MV_FIN_FLG_DELETE_FALSE]); $renderView = 'copy'; 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('fin.models', 'Fixed Deposit')])); } else { // master value $phpFmShortDate = DateTimeUtils::getPhpDateFormat(); $arrTimedepositTrantype = MasterValueUtils::getArrData('fin_timedeposit_trantype'); $arrSavingAccount = ModelUtils::getArrData(FinAccount::find()->select(['account_id', 'account_name'])->where(['delete_flag' => 0, 'account_type' => 4])->orderBy('account_type, order_num'), 'account_id', 'account_name'); $arrCurrentAssets = ModelUtils::getArrData(FinAccount::find()->select(['account_id', 'account_name'])->where(['delete_flag' => 0, 'account_type' => [1, 2]])->orderBy('account_type, order_num'), 'account_id', 'account_name'); // 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); // reset value if (Yii::$app->request->getIsGet()) { $openingDate = DateTimeUtils::getDateFromDB($model->opening_date); $closingDate = DateTimeUtils::getDateFromDB($model->closing_date); $dateDiff = $closingDate->diff($openingDate); $interval = 'P' . $dateDiff->m . 'M'; DateTimeUtils::addDateTime($closingDate, $interval, null, false); $model->opening_date = $model->closing_date; $model->closing_date = $closingDate->format(DateTimeUtils::FM_DB_DATE); $model->interest_add = 0; $model->add_flag = MasterValueUtils::MV_FIN_TIMEDP_TRANTYPE_ADDING; } // init value FinTimeDepositTran::$_PHP_FM_SHORTDATE = $phpFmShortDate; FinTimeDepositTran::$_ARR_SAVING_ACOUNT = $arrSavingAccount; $model->scenario = MasterValueUtils::SCENARIO_COPY; $renderData = ['model' => $model, 'phpFmShortDate' => $phpFmShortDate, 'arrTimedepositTrantype' => $arrTimedepositTrantype, 'arrSavingAccount' => $arrSavingAccount, 'arrCurrentAssets' => $arrCurrentAssets]; switch ($submitMode) { case MasterValueUtils::SM_MODE_INPUT: $isValid = $model->validate(); if ($isValid) { $renderView = 'confirm'; $renderData['formMode'] = [MasterValueUtils::PG_MODE_NAME => MasterValueUtils::PG_MODE_COPY]; } break; case MasterValueUtils::SM_MODE_CONFIRM: $isValid = $model->validate(); if ($isValid) { $result = $this->copyFixedDeposit($model); if ($result === true) { Yii::$app->session->setFlash(MasterValueUtils::FLASH_SUCCESS, Yii::t('common', '{record} has been saved successfully.', ['record' => Yii::t('fin.models', 'Fixed Deposit')])); return Yii::$app->getResponse()->redirect(Url::to(['index'])); } else { Yii::$app->session->setFlash(MasterValueUtils::FLASH_ERROR, $result); $renderView = 'confirm'; $renderData['formMode'] = [MasterValueUtils::PG_MODE_NAME => MasterValueUtils::PG_MODE_COPY]; } } break; case MasterValueUtils::SM_MODE_BACK: break; default: break; } } // render GUI return $this->render($renderView, $renderData); }
public function actionUpdate($id) { $this->objectId = $id; // master value $fmShortDatePhp = DateTimeUtils::getDateFormat(DateTimeUtils::FM_KEY_PHP, null); NetBill::$_PHP_FM_SHORTDATE = $fmShortDatePhp; NetBillDetail::$_PHP_FM_SHORTDATE = $fmShortDatePhp; // 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 = $this->loadBill($id, $postData, $fmShortDatePhp); $renderView = 'update'; if ($model === false) { $renderData = ['model' => $model]; Yii::$app->session->setFlash(MasterValueUtils::FLASH_ERROR, Yii::t('common', 'The requested {record} does not exist.', ['record' => Yii::t('fin.models', 'Bill')])); } else { // master value $fmShortDateJui = DateTimeUtils::getDateFormat(DateTimeUtils::FM_KEY_JUI, null); $arrNetCustomer = ModelUtils::getArrData(NetCustomer::find()->select(['id', 'name'])->where(['delete_flag' => MasterValueUtils::MV_FIN_FLG_DELETE_FALSE, 'status' => MasterValueUtils::MV_NET_CUSTOMER_STATUS_ON])->orderBy('order_num'), 'id', 'name'); $billDetail = new NetBillDetail(); // populate model attributes with user inputs $billDetail->load($postData); $arrBillDetail = $this->loadBillDetails($id, $postData, $fmShortDatePhp); // init value $model->scenario = MasterValueUtils::SCENARIO_UPDATE; $renderData = ['model' => $model, 'billDetail' => $billDetail, 'fmShortDatePhp' => $fmShortDatePhp, 'arrBillDetail' => $arrBillDetail, 'fmShortDateJui' => $fmShortDateJui, 'arrNetCustomer' => $arrNetCustomer]; switch ($submitMode) { case MasterValueUtils::SM_MODE_ADD_ITEM: $itemNo = empty($billDetail->item_no) ? count($arrBillDetail) + 1 : $billDetail->item_no; $billDetail->item_no = $itemNo; $arrBillDetail[$itemNo] = $billDetail; $isValid = $this->validate($model, $arrBillDetail, false); if ($isValid !== true) { $renderData['isValid'] = $isValid; } $renderData['model'] = $model; $renderData['arrBillDetail'] = $arrBillDetail; break; case MasterValueUtils::SM_MODE_DEL_ITEM: $arrBillDetail[$billDetail->item_no]->delete_flag = MasterValueUtils::MV_FIN_FLG_DELETE_TRUE; $renderData['arrBillDetail'] = $arrBillDetail; break; case MasterValueUtils::SM_MODE_INPUT: $isValid = $this->validate($model, $arrBillDetail); if ($isValid === true) { $renderView = 'confirm'; $renderData['formMode'] = [MasterValueUtils::PG_MODE_NAME => MasterValueUtils::PG_MODE_EDIT]; } else { $renderData['isValid'] = $isValid; } $renderData['model'] = $model; $renderData['arrBillDetail'] = $arrBillDetail; break; case MasterValueUtils::SM_MODE_CONFIRM: $isValid = $this->validate($model, $arrBillDetail); if ($isValid === true) { $result = $this->updateBill($model, $arrBillDetail, $fmShortDatePhp); if ($result === true) { Yii::$app->session->setFlash(MasterValueUtils::FLASH_SUCCESS, Yii::t('common', '{record} has been saved successfully.', ['record' => Yii::t('fin.models', 'Bill')])); return Yii::$app->getResponse()->redirect(Url::to(['update', 'id' => $id])); } else { // restore Data for View $this->restoreData4View($model, $arrBillDetail, $fmShortDatePhp); // render View Yii::$app->session->setFlash(MasterValueUtils::FLASH_ERROR, $result); $renderView = 'confirm'; $renderData['formMode'] = [MasterValueUtils::PG_MODE_NAME => MasterValueUtils::PG_MODE_EDIT]; } } else { $renderData['isValid'] = $isValid; $renderData['model'] = $model; $renderData['arrBillDetail'] = $arrBillDetail; } break; case MasterValueUtils::SM_MODE_BACK: break; default: break; } } // render GUI return $this->render($renderView, $renderData); }
public function actionCopy($id) { $this->objectId = $id; $model = FinAccountEntry::findOne(['entry_id' => $id, 'entry_status' => MasterValueUtils::MV_FIN_ENTRY_TYPE_SIMPLE, 'delete_flag' => MasterValueUtils::MV_FIN_FLG_DELETE_FALSE]); $renderView = 'copy'; 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('fin.models', 'Payment')])); } else { // master value $phpFmShortDate = DateTimeUtils::getPhpDateFormat(); $arrFinAccount = ModelUtils::getArrData(FinAccount::find()->select(['account_id', 'account_name'])->where(['delete_flag' => 0, 'account_type' => [1, 2, 3, 5, 6, 7]])->orderBy('account_type, order_num'), 'account_id', 'account_name'); $arrEntryLog = MasterValueUtils::getArrData('fin_entry_log'); // reset value $model->entry_date = DateTimeUtils::formatNow($phpFmShortDate); // 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); if (is_null($model->arr_entry_log)) { $model->arr_entry_log = StringUtils::unserializeArr($model->description); } // init value FinAccountEntry::$_PHP_FM_SHORTDATE = $phpFmShortDate; $model->scenario = MasterValueUtils::SCENARIO_COPY; $renderData = ['model' => $model, 'phpFmShortDate' => $phpFmShortDate, 'arrFinAccount' => $arrFinAccount, '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_COPY]; } break; case MasterValueUtils::SM_MODE_CONFIRM: $isValid = $model->validate(); if ($isValid) { $result = $this->copyPayment($model); if ($result === true) { Yii::$app->session->setFlash(MasterValueUtils::FLASH_SUCCESS, Yii::t('common', '{record} has been saved successfully.', ['record' => Yii::t('fin.models', 'Payment')])); return Yii::$app->getResponse()->redirect(Url::to(['index'])); } else { Yii::$app->session->setFlash(MasterValueUtils::FLASH_ERROR, $result); $renderView = 'confirm'; $renderData['formMode'] = [MasterValueUtils::PG_MODE_NAME => MasterValueUtils::PG_MODE_COPY]; } } break; case MasterValueUtils::SM_MODE_BACK: break; default: break; } } // render GUI return $this->render($renderView, $renderData); }