public function test_getLatest()
 {
     $obm = \Magento\Framework\App\ObjectManager::getInstance();
     /** @var  $call \Praxigento\BonusBase\Service\Period\Call */
     $call = $obm->get(\Praxigento\BonusBase\Service\IPeriod::class);
     $req = new Request\GetLatest();
     $req->setCalcTypeId(null);
     $req->setCalcTypeCode('LOYALTY_BON_COMPRESS');
     $resp = $call->getLatest($req);
     $this->assertTrue($resp->isSucceed());
 }
 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;
 }