/** * Analyze depended calculation data and to the results if state is incomplete. * * This function is created for CRAP reducing and is used from this class only. * * @param \Praxigento\BonusBase\Service\Period\Response\GetForDependentCalc $result * @param string $dependentCalcTypeCode * @param int $dependentCalcTypeId * @param string $dependentDsBegin * @param string $dependentDsEnd */ public function _analyzeDependedCalc(\Praxigento\BonusBase\Service\Period\Response\GetForDependentCalc $result, $dependentCalcTypeCode, $dependentCalcTypeId, $dependentDsBegin, $dependentDsEnd) { $dependentCalcData = $this->_repoService->getLastCalcForPeriodByDates($dependentCalcTypeId, $dependentDsBegin, $dependentDsEnd); if ($dependentCalcData && $dependentCalcData->getState() == Cfg::CALC_STATE_COMPLETE) { /* complete dependent period for complete base period */ $this->_logger->warning("There is '{$dependentCalcTypeCode}' period with complete calculation. No more '{$dependentCalcTypeCode}' could be calculated."); } else { /* incomplete dependent period for complete base period */ $this->_logger->warning("There is '{$dependentCalcTypeCode}' period without complete calculation. Continue calculation for this period."); $result->setDependentCalcData($dependentCalcData); } }
/** * @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; }