public function test_getDependedCalc_complete()
 {
     /** === Test Data === */
     $RESULT = new \Praxigento\BonusBase\Service\Period\Response\GetForDependentCalc();
     $BASE_PERIOD_ID = 2;
     $BASE_TYPE_CODE = 'base';
     $BASE_DS_BEGIN = 'begin';
     $BASE_DS_END = 'end';
     $DEP_TYPE_CODE = 'depend';
     $DEP_TYPE_ID = 4;
     /** === Mock object itself === */
     $this->obj = \Mockery::mock(Depended::class . '[_getForCompleteBase]', $this->objArgs);
     /** === Setup Mocks === */
     // $baseCalcData = $this->_repoService->getLastCalcForPeriodById($basePeriodId);
     $mBaseCalcData = new ECalculation();
     $mBaseCalcData->setState(Cfg::CALC_STATE_COMPLETE);
     $this->mRepoService->shouldReceive('getLastCalcForPeriodById')->once()->with($BASE_PERIOD_ID)->andReturn($mBaseCalcData);
     // $this->_getForCompleteBase(...)
     $this->obj->shouldReceive('_getForCompleteBase')->once()->andReturn($RESULT, $BASE_TYPE_CODE, $BASE_DS_BEGIN, $BASE_DS_END, $DEP_TYPE_CODE, $DEP_TYPE_ID);
     /** === Call and asserts  === */
     $this->obj->getDependedCalc($RESULT, $BASE_PERIOD_ID, $BASE_TYPE_CODE, $BASE_DS_BEGIN, $BASE_DS_END, $DEP_TYPE_CODE, $DEP_TYPE_ID);
 }
 /**
  * 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;
 }