コード例 #1
0
 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);
 }
コード例 #2
0
 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);
 }