public function bonusTeam(Request\BonusTeam $request) { $result = new Response\BonusTeam(); $scheme = $this->_getCalculationsScheme($request->getScheme()); $courtesyPercent = $request->getCourtesyBonusPercent(); $teamBonusPercent = $request->getTeamBonusPercent(); $datePerformed = $request->getDatePerformed(); $dateApplied = $request->getDateApplied(); $this->_logger->info("'Team Bonus' calculation is started."); $reqGetPeriod = new PeriodGetForDependentCalcRequest(); $calcTypeBase = Cfg::CODE_TYPE_CALC_VALUE_TV; if ($scheme == Def::SCHEMA_EU) { $calcType = Cfg::CODE_TYPE_CALC_BONUS_TEAM_EU; } else { $calcType = Cfg::CODE_TYPE_CALC_BONUS_TEAM_DEF; } $reqGetPeriod->setBaseCalcTypeCode($calcTypeBase); $reqGetPeriod->setDependentCalcTypeCode($calcType); $respGetPeriod = $this->_callPeriod->getForDependentCalc($reqGetPeriod); if ($respGetPeriod->isSucceed()) { $def = $this->_manTrans->begin(); try { /* working vars */ $thisPeriodData = $respGetPeriod->getDependentPeriodData(); $thisPeriodId = $thisPeriodData[Period::ATTR_ID]; $thisCalcData = $respGetPeriod->getDependentCalcData(); $thisCalcId = $thisCalcData[Calculation::ATTR_ID]; $basePeriodData = $respGetPeriod->getBasePeriodData(); $baseDsBegin = $basePeriodData->getDstampBegin(); $baseDsEnd = $basePeriodData->getDstampEnd(); /* get the last PTC compression calc id for this period */ $ptcCompressCalcId = $this->_subDb->getLastCalculationIdForPeriod(Cfg::CODE_TYPE_CALC_COMPRESS_FOR_PTC, $baseDsBegin, $baseDsEnd); /* calculation itself */ $this->_logger->info("Processing period #{$thisPeriodId} ({$baseDsBegin}-{$baseDsEnd})"); /* get compressed data by calculation ID */ $compressPtc = $this->_subDb->getCompressedPtcData($ptcCompressCalcId); /* calculate bonus values according to DEFAULT or EU schemes */ if ($scheme == Def::SCHEMA_EU) { $updates = $this->_subCalc->bonusTeamEu($compressPtc, $teamBonusPercent); /* save operation with transactions */ $respAdd = $this->_subDb->saveOperationWalletActive($updates, Cfg::CODE_TYPE_OPER_BONUS_TEAM, $datePerformed, $dateApplied); $operId = $respAdd->getOperationId(); $transIds = $respAdd->getTransactionsIds(); /* save customers and correspondent transactions into the log */ $this->_subDb->saveLogCustomers($updates, $transIds); } else { /* get levels to calculate Personal and Team bonuses */ $levelsPersonal = $this->_subDb->getBonusLevels(Cfg::CODE_TYPE_CALC_BONUS_PERSONAL_DEF); $levelsTeam = $this->_subDb->getBonusLevels(Cfg::CODE_TYPE_CALC_BONUS_TEAM_DEF); $updates = $this->_subCalc->bonusTeamDef($compressPtc, $levelsPersonal, $levelsTeam, $courtesyPercent); /* save operation with transactions */ $respAdd = $this->_subDb->saveOperationWalletActive($updates, Cfg::CODE_TYPE_OPER_BONUS_TEAM, $datePerformed, $dateApplied); $operId = $respAdd->getOperationId(); } /* save processed operation to calculations log and mark calculation as complete */ $this->_subDb->saveLogOperations($operId, $thisCalcId); $this->_subDb->markCalcComplete($thisCalcId); /* finalize response as succeed */ $this->_manTrans->commit($def); $result->markSucceed(); $result->setPeriodId($thisPeriodId); $result->setCalcId($thisCalcId); } finally { $this->_manTrans->end($def); } } $this->_logMemoryUsage(); $this->_logger->info("'Team Bonus' calculation is completed."); return $result; }