public function test_bonusTeam_isPeriod_Eu() { /** === Test Data === */ $OPERATION_ID = 3; /** === Mocks === */ $mLogger = $this->_mockLogger(); $mConn = $this->_mockConnection(); $mDba = $this->_mockDbAdapter(null, $mConn); $mToolbox = $this->_mockToolbox(); $mCallRepo = $this->_mockCallRepo(); $mCallAccount = $this->_mockFor('Praxigento\\Accounting\\Service\\IAccount'); $mCallBonusPersonalPeriod = $this->_mockFor('Praxigento\\Bonus\\Hybrid\\Lib\\Service\\IPeriod'); $mSubDb = $this->_mockFor('Praxigento\\Bonus\\Hybrid\\Lib\\Service\\Calc\\Sub\\Db'); $mSubCalc = $this->_mockFor('Praxigento\\Bonus\\Hybrid\\Lib\\Service\\Calc\\Sub\\Calc'); // $respGetPeriod = $this->_callPeriod->getForDependentCalc($reqGetPeriod); $mRespGetPeriod = new BonusPersonalPeriodGetForDependentCalcResponse(); $mCallBonusPersonalPeriod->expects($this->once())->method('getForDependentCalc')->willReturn($mRespGetPeriod); // if($respGetPeriod->isSucceed()) $mRespGetPeriod->markSucceed(); // $respAdd = $this->_subDb->saveOperationWalletActive(..) $mRespAdd = new DataObject(); $mSubDb->expects($this->once())->method('saveOperationWalletActive')->willReturn($mRespAdd); // $operId = $respAdd->getOperationId(); $mRespAdd->setOperationId($OPERATION_ID); // $this->_conn->commit(); $mConn->expects($this->once())->method('commit'); /** * Prepare request and perform call. */ /** @var $call Call */ $call = new Call($mLogger, $mDba, $mToolbox, $mCallRepo, $mCallAccount, $mCallBonusPersonalPeriod, $mSubDb, $mSubCalc); $req = new Request\BonusTeam(); $req->setScheme(Def::SCHEMA_EU); $resp = $call->bonusTeam($req); $this->assertTrue($resp->isSucceed()); }
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; }
public function test_bonusTeam_Eu() { $obm = \Magento\Framework\App\ObjectManager::getInstance(); /** @var $call \Praxigento\Bonus\Hybrid\Lib\Service\ICalc */ $call = $obm->get('Praxigento\\Bonus\\Hybrid\\Lib\\Service\\ICalc'); $request = new Request\BonusTeam(); $request->setScheme(Def::SCHEMA_EU); $request->setTeamBonusPercent(self::TEAM_BONUS_PERCENT_EU); $response = $call->bonusTeam($request); $this->assertTrue($response->isSucceed()); }