public function actionIndex() { // master value $fmShortDatePhp = DateTimeUtils::getDateFormat(DateTimeUtils::FM_KEY_PHP, null); $fmShortDateJui = DateTimeUtils::getDateFormat(DateTimeUtils::FM_KEY_JUI, null); $arrPurchaseType = MasterValueUtils::getArrData('oef_purchase_type'); OefPurchase::$_PHP_FM_SHORTDATE = $fmShortDatePhp; $searchModel = new OefPurchase(); // submit data $postData = Yii::$app->request->post(); // populate model attributes with user inputs $searchModel->load($postData); // init value $today = DateTimeUtils::getNow(); if (Yii::$app->request->getIsGet()) { $tdInfo = getdate($today->getTimestamp()); $searchModel->purchase_date_to = $today->format($fmShortDatePhp); $searchModel->purchase_date_from = DateTimeUtils::parse($tdInfo[DateTimeUtils::FN_KEY_GETDATE_YEAR] - 1 . '0101', DateTimeUtils::FM_DEV_DATE, $fmShortDatePhp); } $searchModel->scenario = MasterValueUtils::SCENARIO_LIST; // sum purchase, fee, stock $sumPurchaseValue = false; // query for dataprovider $dataQuery = null; if ($searchModel->validate()) { $dataQuery = OefPurchase::find()->where(['delete_flag' => MasterValueUtils::MV_FIN_FLG_DELETE_FALSE]); $sumPurchaseQuery = (new Query())->select(['SUM(purchase) AS purchase', 'SUM(purchase_fee) AS purchase_fee', 'SUM(found_stock_sold) AS found_stock_sold', 'SUM(found_stock) AS found_stock', 'SUM(transfer_fee) AS transfer_fee', 'SUM(other_fee) AS other_fee'])->from('oef_purchase')->where(['delete_flag' => MasterValueUtils::MV_FIN_FLG_DELETE_FALSE]); if (!empty($searchModel->purchase_date_from)) { $dataQuery->andWhere(['>=', 'purchase_date', $searchModel->purchase_date_from]); $sumPurchaseQuery->andWhere(['>=', 'purchase_date', $searchModel->purchase_date_from]); } if (!empty($searchModel->purchase_date_to)) { $dataQuery->andWhere(['<=', 'purchase_date', $searchModel->purchase_date_to]); $sumPurchaseQuery->andWhere(['<=', 'purchase_date', $searchModel->purchase_date_to]); } $dataQuery->orderBy('purchase_date DESC'); $sumPurchaseValue = $sumPurchaseQuery->createCommand()->queryOne(); } else { $dataQuery = OefNav::find()->where(['id' => -1]); } // render GUI $renderData = ['searchModel' => $searchModel, 'fmShortDateJui' => $fmShortDateJui, 'dataQuery' => $dataQuery, 'sumPurchaseValue' => $sumPurchaseValue, 'arrPurchaseType' => $arrPurchaseType]; return $this->render('index', $renderData); }
/** * @param OefFundCertificate $condition * @param String $fmShortDatePhp * @return array */ private function getFundCertificate4Sell($condition, $fmShortDatePhp) { $condition->sum_sell_certificate = 0; $condition->investment = 0; $condition->sellable_certificate = 0; $condition->revenue = 0; $condition->sell_fee = 0; $condition->profit_before_taxes = 0; $condition->income_tax = 0; $condition->profit_after_taxes = 0; $condition->investment_result = 0; $sqlLimit = 3; $sqlOffset = 0; $results = []; $condition->sell_date_obj = DateTimeUtils::parse($condition->sell_date, $fmShortDatePhp); $running = true; while ($running) { $arrOefPurchase = OefPurchase::find()->where(['delete_flag' => MasterValueUtils::MV_FIN_FLG_DELETE_FALSE])->andWhere('found_stock > found_stock_sold')->addOrderBy(['purchase_date' => SORT_ASC])->offset($sqlOffset)->limit($sqlLimit)->all(); $running = count($arrOefPurchase) > 0; if ($running) { foreach ($arrOefPurchase as $oefPurchase) { $result = null; switch ($oefPurchase->purchase_type) { case MasterValueUtils::MV_OEF_PERCHASE_TYPE_NORMAL: $result = new OefFundCertificateNormal(); break; case MasterValueUtils::MV_OEF_PERCHASE_TYPE_SIP: $result = new OefFundCertificateSip(); break; case MasterValueUtils::MV_OEF_PERCHASE_TYPE_DIVIDEND: $result = new OefFundCertificateDividend(); break; case MasterValueUtils::MV_OEF_PERCHASE_TYPE_IPO: $result = new OefFundCertificateIpo(); break; } if (!is_null($result)) { $result->initialize($oefPurchase, $condition); $results[] = $result; $condition->investment += $result->investment; $condition->sellable_certificate += $result->sellable_certificate; $condition->sum_sell_certificate += $result->sell_certificate; $condition->revenue += $result->revenue; $condition->sell_fee += $result->sell_fee; $condition->profit_before_taxes += $result->profit_before_taxes; $condition->income_tax += $result->income_tax; $condition->profit_after_taxes += $result->profit_after_taxes; $condition->investment_result += $result->investment_result; $running = $condition->sum_sell_certificate < $condition->sell_certificate; if (!$running) { break; } } } $sqlOffset += $sqlLimit; } } return $results; }