public function calculatePeriod() { $curDate = $this->getCurDate(); $last1Year = $this->getModifyDate('-1 year'); $last3Year = $this->getModifyDate('-3 year'); $actualTwr = new Actual(); // NET $model = new PortfolioTwrPeriodModel(); $model->setNetMtd($actualTwr->rule(new PortfolioActualNetRule($this->getKey(), Util::firstDayOf('month', $curDate), $curDate))); $model->setNetQtd($actualTwr->rule(new PortfolioActualNetRule($this->getKey(), Util::firstDayOf('quarter', $curDate), $curDate))); $model->setNetYtd($actualTwr->rule(new PortfolioActualNetRule($this->getKey(), Util::firstDayOf('year', $curDate), $curDate))); $model->setNetYr1($actualTwr->rule(new PortfolioActualNetRule($this->getKey(), $last1Year, $curDate))); $model->setNetYr3($actualTwr->rule(new PortfolioActualNetRule($this->getKey(), $last3Year, $curDate))); $model->setNetSinceInception($actualTwr->rule(new PortfolioActualNetRule($this->getKey()))); // GROSS $model->setGrossMtd($actualTwr->rule(new PortfolioActualGrossRule($this->getKey(), Util::firstDayOf('month', $curDate), $curDate))); $model->setGrossQtd($actualTwr->rule(new PortfolioActualGrossRule($this->getKey(), Util::firstDayOf('quarter', $curDate), $curDate))); $model->setGrossYtd($actualTwr->rule(new PortfolioActualGrossRule($this->getKey(), Util::firstDayOf('year', $curDate), $curDate))); $model->setGrossYr1($actualTwr->rule(new PortfolioActualGrossRule($this->getKey(), $last1Year, $curDate))); $model->setGrossYr3($actualTwr->rule(new PortfolioActualGrossRule($this->getKey(), $last3Year, $curDate))); $model->setGrossSinceInception($actualTwr->rule(new PortfolioActualGrossRule($this->getKey()))); $model->setClientId($this->getKey()); // Save portfolio period return $this->periodRepo->save($model); }
/** * @param PortfolioTwrPeriod $model * @return mixed */ public function save(PortfolioTwrPeriod $model) { $result = $this->fpdo->from($this->table)->where('client_id', $model->getClientId())->limit(1)->fetch('id'); return $result ? $this->update($result, $model) : $this->insert($model); }