/** * @param AccountTwrPeriod $model * @return mixed */ public function save(AccountTwrPeriod $model) { $result = $this->fpdo->from($this->table)->where('account_number', $model->getAccountNumber())->limit(1)->fetch('id'); return $result ? $this->update($result, $model) : $this->insert($model); }
/** * @param SystemClientAccountModel $account */ public function calculatePeriod(SystemClientAccountModel $account) { $curDate = $this->getCurDate(); $last1Year = $this->getModifyDate('-1 year'); $last3Year = $this->getModifyDate('-3 year'); $actualTwr = new Actual(); // NET $model = new AccountTwrPeriodModel(); $model->setNetMtd($actualTwr->rule(new AccountActualNetRule($account->getAccountNumber(), Util::firstDayOf('month', $curDate), $curDate))); $model->setNetQtd($actualTwr->rule(new AccountActualNetRule($account->getAccountNumber(), Util::firstDayOf('quarter', $curDate), $curDate))); $model->setNetYtd($actualTwr->rule(new AccountActualNetRule($account->getAccountNumber(), Util::firstDayOf('year', $curDate), $curDate))); $model->setNetYr1($actualTwr->rule(new AccountActualNetRule($account->getAccountNumber(), $last1Year, $curDate))); $model->setNetYr3($actualTwr->rule(new AccountActualNetRule($account->getAccountNumber(), $last3Year, $curDate))); $model->setNetSinceInception($actualTwr->rule(new AccountActualNetRule($account->getAccountNumber(), $account->getPerformanceInceptionAsDateTime()))); // GROSS $model->setGrossMtd($actualTwr->rule(new AccountActualGrossRule($account->getAccountNumber(), Util::firstDayOf('month', $curDate), $curDate))); $model->setGrossQtd($actualTwr->rule(new AccountActualGrossRule($account->getAccountNumber(), Util::firstDayOf('quarter', $curDate), $curDate))); $model->setGrossYtd($actualTwr->rule(new AccountActualGrossRule($account->getAccountNumber(), Util::firstDayOf('year', $curDate), $curDate))); $model->setGrossYr1($actualTwr->rule(new AccountActualGrossRule($account->getAccountNumber(), $last1Year, $curDate))); $model->setGrossYr3($actualTwr->rule(new AccountActualGrossRule($account->getAccountNumber(), $last3Year, $curDate))); $model->setGrossSinceInception($actualTwr->rule(new AccountActualGrossRule($account->getAccountNumber(), $account->getPerformanceInceptionAsDateTime()))); $model->setAccountNumber($account->getAccountNumber()); // Save $this->periodRepo->save($model); }