/**
  * @param Request\Bonus $req
  *
  * @return Response\Bonus
  */
 public function bonus(Request\Bonus $req)
 {
     $result = new Response\Bonus();
     $datePerformed = $req->getDatePerformed();
     $dateApplied = $req->getDateApplied();
     $this->_logger->info("'Loyalty Bonus' calculation is started. Performed at: {$datePerformed}, applied at: {$dateApplied}.");
     $reqGetPeriod = new PeriodGetForDependentCalcRequest();
     $calcTypeBase = Cfg::CODE_TYPE_CALC_QUALIFICATION;
     $calcType = Cfg::CODE_TYPE_CALC_BONUS;
     $reqGetPeriod->setBaseCalcTypeCode($calcTypeBase);
     $reqGetPeriod->setDependentCalcTypeCode($calcType);
     $respGetPeriod = $this->_callBasePeriod->getForDependentCalc($reqGetPeriod);
     if ($respGetPeriod->isSucceed()) {
         $def = $this->_manTrans->begin();
         try {
             $periodDataDepend = $respGetPeriod->getDependentPeriodData();
             $calcDataDepend = $respGetPeriod->getDependentCalcData();
             $calcIdDepend = $calcDataDepend->getId();
             $dsBegin = $periodDataDepend->getDstampBegin();
             $dsEnd = $periodDataDepend->getDstampEnd();
             /* collect data to process bonus */
             $calcTypeIdCompress = $this->_repoBonusTypeCalc->getIdByCode(Cfg::CODE_TYPE_CALC_COMPRESSION);
             $calcDataCompress = $this->_repoBonusService->getLastCalcForPeriodByDates($calcTypeIdCompress, $dsBegin, $dsEnd);
             $calcIdCompress = $calcDataCompress->getId();
             $params = $this->_repoMod->getConfigParams();
             $percents = $this->_repoMod->getBonusPercents();
             $treeCompressed = $this->_repoMod->getCompressedTreeWithQualifications($calcIdCompress);
             $orders = $this->_repoMod->getSalesOrdersForPeriod($dsBegin, $dsEnd);
             /* calculate bonus */
             $updates = $this->_subBonus->calc($treeCompressed, $orders, $params, $percents);
             /* create new operation with bonus transactions and save sales log */
             $respAdd = $this->_createBonusOperation($updates);
             $transLog = $respAdd->getTransactionsIds();
             $this->_repoMod->saveLogSaleOrders($transLog);
             /* mark calculation as completed and finalize bonus */
             $this->_repoBonusService->markCalcComplete($calcIdDepend);
             $this->_manTrans->commit($def);
             $result->setPeriodId($periodDataDepend->getId());
             $result->setCalcId($calcIdDepend);
             $result->markSucceed();
         } finally {
             $this->_manTrans->end($def);
         }
     }
     $this->_logger->info("'Loyalty Bonus' calculation is complete.");
     return $result;
 }