/** * This function is created for CRAP reducing and is used from this class only. * * @param \Praxigento\BonusBase\Service\Period\Response\GetForDependentCalc $result * @param string $baseCalcTypeCode * @param string $baseDsBegin * @param string $baseDsEnd * @param string $dependentCalcTypeCode * @param int $dependentCalcTypeId */ public function _getForCompleteBase(\Praxigento\BonusBase\Service\Period\Response\GetForDependentCalc $result, $baseCalcTypeCode, $baseDsBegin, $baseDsEnd, $dependentCalcTypeCode, $dependentCalcTypeId) { $dependPeriodData = $this->_repoService->getLastPeriodByCalcType($dependentCalcTypeId); if (is_null($dependPeriodData)) { /* there is no dependent period, create new period and calc */ $msg = "There is no period data for calculation '{$dependentCalcTypeCode}'." . " New period and related calculation will be created."; $this->_logger->warning($msg); /* create new period for given calculation type */ $period = new EPeriod(); $period->setCalcTypeId($dependentCalcTypeId); $period->setDstampBegin($baseDsBegin); $period->setDstampEnd($baseDsEnd); $periodId = $this->_repoPeriod->create($period); $period->setId($periodId); /* create related calculation */ $calc = new ECalculation(); $calc->setPeriodId($periodId); $dateStarted = $this->_toolDate->getUtcNowForDb(); $calc->setDateStarted($dateStarted); $calc->setState(Cfg::CALC_STATE_STARTED); $calcId = $this->_repoCalc->create($calc); $calc->setId($calcId); /* place newly created objects into the response */ $result->setDependentPeriodData($period); $result->setDependentCalcData($calc); } else { /* there is depended period, place period data into response */ $result->setDependentPeriodData($dependPeriodData); /* then analyze base/depended periods begin/end */ $dependentDsBegin = $dependPeriodData->getDstampBegin(); $dependentDsEnd = $dependPeriodData->getDstampEnd(); $this->_getDependedCalcForExistingPeriod($result, $baseCalcTypeCode, $baseDsBegin, $baseDsEnd, $dependentCalcTypeCode, $dependentCalcTypeId, $dependentDsBegin, $dependentDsEnd); } }
/** * * Get PV related period data if no period yet exist. * * @param \Praxigento\BonusBase\Service\Period\Response\GetForPvBasedCalc $result * @param string $periodType * @param int $calcTypeId * @return \Praxigento\BonusBase\Service\Period\Response\GetForPvBasedCalc */ public function getNewPeriodDataForPv(\Praxigento\BonusBase\Service\Period\Response\GetForPvBasedCalc $result, $periodType, $calcTypeId) { /* we should lookup for first PV transaction and calculate first period range */ $firstDate = $this->_repoService->getFirstDateForPvTransactions(); if ($firstDate === false) { $this->_logger->warning("There is no PV transactions yet. Nothing to do."); $result->setErrorCode($result::ERR_HAS_NO_PV_TRANSACTIONS_YET); } else { $this->_logger->info("First PV transaction was performed at '{$firstDate}'."); $periodMonth = $this->_toolPeriod->getPeriodCurrent($firstDate, $periodType); $dsBegin = $this->_toolPeriod->getPeriodFirstDate($periodMonth); $dsEnd = $this->_toolPeriod->getPeriodLastDate($periodMonth); /* create new period for given calculation type */ $period = new EPeriod(); $period->setCalcTypeId($calcTypeId); $period->setDstampBegin($dsBegin); $period->setDstampEnd($dsEnd); $periodId = $this->_repoPeriod->create($period); $period->setId($periodId); /* create related calculation */ $calc = new ECalculation(); $calc->setPeriodId($periodId); $dateStarted = $this->_toolDate->getUtcNowForDb(); $calc->setDateStarted($dateStarted); $calc->setState(Cfg::CALC_STATE_STARTED); $calcId = $this->_repoCalc->create($calc); $calc->setId($calcId); /* place newly created objects into the response */ $result->setPeriodData($period); $result->setCalcData($calc); } return $result; }