/**
  * 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);
     }
 }
Ejemplo n.º 2
0
 public function getLatest(Request\GetLatest $request)
 {
     $result = new Response\GetLatest();
     $calcTypeId = $request->getCalcTypeId();
     $calcTypeCode = $request->getCalcTypeCode();
     $msgParams = is_null($calcTypeId) ? "type code '{$calcTypeCode}'" : "type ID #{$calcTypeId}";
     $this->_logger->info("'Get latest calculation period' operation is started with {$msgParams} in bonus base module.");
     if (is_null($calcTypeId)) {
         /* get calculation type ID by type code */
         $calcTypeId = $this->_repoTypeCalc->getIdByCode($calcTypeCode);
         $this->_logger->info("There is only calculation type code ({$calcTypeCode}) in request, calculation type id = {$calcTypeId}.");
     }
     $periodLatest = $this->_repoService->getLastPeriodByCalcType($calcTypeId);
     if ($periodLatest) {
         $result->setPeriodData($periodLatest);
         /* add period calculations to result set */
         $periodId = $periodLatest->getId();
         $calcLatest = $this->_repoService->getLastCalcForPeriodById($periodId);
         $result->setCalcData($calcLatest);
     }
     $result->markSucceed();
     $this->_logger->info("'Get latest calculation period' operation is completed in bonus base module.");
     return $result;
 }