예제 #1
0
 protected function calculate()
 {
     $this->sip_exit_fee_rate = 0;
     $this->sell_fee_discount_rate = ParamUtils::getSaleFeeDiscountRate($this->purchase_type);
     $saleFeeRate = ParamUtils::getSaleFeeRate($this->kept_months);
     $this->sell_fee_rate = ($saleFeeRate + $this->sip_exit_fee_rate) * (1 - $this->sell_fee_discount_rate / 100);
     $this->sell_fee = $this->sell_fee_rate * $this->revenue / 100;
     $this->profit_before_taxes = $this->revenue - $this->sell_fee;
     $this->income_tax = $this->profit_before_taxes * $this->income_tax_rate / 100;
     $this->profit_after_taxes = $this->profit_before_taxes - $this->income_tax;
     $this->investment_result = $this->profit_after_taxes - $this->investment;
 }
예제 #2
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);
 }
예제 #3
0
 public function calculate()
 {
     $this->purchase_fee_rate = ParamUtils::getPurchaseFeeRate($this->purchase);
     $this->discount_rate = ParamUtils::getPurchaseFeeDiscountRate($this->purchase_type);
     $this->total_fee_rate = $this->purchase_fee_rate * (100 - $this->discount_rate) / 100;
     $this->purchase_fee_rule = ParamUtils::getPurchaseFeeRule();
     $this->purchase_fee = NumberUtils::rounds($this->purchase * $this->total_fee_rate / 100, $this->purchase_fee_rule);
     $this->real_purchase = $this->purchase - $this->purchase_fee;
     $this->found_stock_rule = ParamUtils::getFoundStockRule();
     $this->found_stock = NumberUtils::rounds(100 * ($this->real_purchase / $this->nav), $this->found_stock_rule) / 100;
     $this->investment = $this->purchase + $this->transfer_fee + $this->other_fee;
     if ($this->purchase_type == MasterValueUtils::MV_OEF_PERCHASE_TYPE_DIVIDEND) {
         $this->fin_entry_id = 0;
         $this->jar_payment_id = 0;
     }
 }