Beispiel #1
0
 public function actionTool()
 {
     // master value
     $fmShortDatePhp = DateTimeUtils::getDateFormat(DateTimeUtils::FM_KEY_PHP, null);
     $fmShortDateJui = DateTimeUtils::getDateFormat(DateTimeUtils::FM_KEY_JUI, null);
     $arrPurchaseType = MasterValueUtils::getArrData('oef_purchase_type');
     OefFundCertificate::$_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 = new OefFundCertificate();
     $model->load($postData);
     // init value
     $model->scenario = MasterValueUtils::SCENARIO_TOOL;
     if (Yii::$app->request->getIsGet()) {
         $today = DateTimeUtils::getNow();
         $model->sell_date = $today->format($fmShortDatePhp);
         $model->income_tax_rate = ParamUtils::getIncomeTaxRateSale();
         $sumPurchaseQuery = (new Query())->select(['SUM(found_stock) AS found_stock', 'SUM(found_stock_sold) AS found_stock_sold']);
         $sumPurchaseQuery->from('oef_purchase')->where(['delete_flag' => MasterValueUtils::MV_FIN_FLG_DELETE_FALSE])->andWhere('found_stock > found_stock_sold');
         $sumPurchaseData = $sumPurchaseQuery->createCommand()->queryOne();
         if (!is_null($sumPurchaseData['found_stock']) && !is_null($sumPurchaseData['found_stock_sold'])) {
             $model->sell_certificate = $sumPurchaseData['found_stock'] - $sumPurchaseData['found_stock_sold'];
         }
     }
     $isValidSellDate = $model->validate(['sell_date']);
     if ($isValidSellDate && empty($model->nav)) {
         $sellDate = DateTimeUtils::parse($model->sell_date, $fmShortDatePhp);
         $oefNavModel = OefNav::findOne(['delete_flag' => MasterValueUtils::MV_FIN_FLG_DELETE_FALSE, 'trade_date' => $sellDate->format(DateTimeUtils::FM_DB_DATE)]);
         if (!is_null($oefNavModel)) {
             $model->nav = $oefNavModel->nav_value;
         }
     }
     // render GUI
     $renderView = 'tool';
     $renderData = ['model' => $model, 'fmShortDateJui' => $fmShortDateJui, 'arrPurchaseType' => $arrPurchaseType, 'arrFundCertificate4Sell' => false];
     switch ($submitMode) {
         case MasterValueUtils::SM_MODE_INPUT:
             $isValid = $model->validate();
             if ($isValid) {
                 $arrFundCertificate4Sell = $this->getFundCertificate4Sell($model, $fmShortDatePhp);
                 $renderData['arrFundCertificate4Sell'] = $arrFundCertificate4Sell;
             }
             break;
         default:
             break;
     }
     // render GUI
     return $this->render($renderView, $renderData);
 }
 /**
  * @param OefPurchase $purchase
  * @param OefFundCertificate $condition
  */
 public function initialize($purchase, $condition)
 {
     parent::initialize($purchase, $condition);
 }
 /**
  * @param OefPurchase $purchase
  * @param OefFundCertificate $condition
  */
 public function initialize($purchase, $condition)
 {
     $this->sip_date = DateTimeUtils::getDateFromDB($purchase->sip_date);
     $this->sip_months = DateTimeUtils::diffMonths($this->sip_date, $condition->sell_date_obj);
     parent::initialize($purchase, $condition);
 }