public function test_bonusInfinity_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\BonusInfinity(); $request->setScheme(Def::SCHEMA_EU); $response = $call->bonusInfinity($request); $this->assertTrue($response->isSucceed()); }
public function bonusInfinity(Request\BonusInfinity $request) { $result = new Response\BonusInfinity(); $scheme = $this->_getCalculationsScheme($request->getScheme()); $datePerformed = $request->getDatePerformed(); $dateApplied = $request->getDateApplied(); $this->_logger->info("'Infinity Bonus' calculation is started ({$scheme} scheme)."); if ($scheme == Def::SCHEMA_EU) { $calcTypeBase = Cfg::CODE_TYPE_CALC_COMPRESS_FOR_OI_EU; $calcType = Cfg::CODE_TYPE_CALC_BONUS_INFINITY_EU; } else { $calcTypeBase = Cfg::CODE_TYPE_CALC_COMPRESS_FOR_OI_DEF; $calcType = Cfg::CODE_TYPE_CALC_BONUS_INFINITY_DEF; } $reqGetPeriod = new PeriodGetForDependentCalcRequest(); $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(); $baseCalcData = $respGetPeriod->getBaseCalcData(); $baseCalcId = $baseCalcData->getId(); /* calculation itself */ $this->_logger->info("Processing period #{$thisPeriodId} ({$baseDsBegin}-{$baseDsEnd})"); /* get compressed data by calculation ID */ $compressOi = $this->_subDb->getCompressedOiData($baseCalcId); /* get configuration for Override and Infinity bonuses */ $cfgParams = $this->_subDb->getCfgParams(); /* calculate bonus amounts */ $updates = $this->_subCalc->bonusInfinity($compressOi, $scheme, $cfgParams); /* prepare update data */ $updatesForWallets = []; $updatesForPvInf = []; foreach ($updates as $custId => $item) { $pv = $item[Calc::A_PV]; $bonusEntries = $item[Calc::A_ENTRIES]; $updatesForPvInf[$custId] = [OiCompress::ATTR_PV_INF => $pv]; foreach ($bonusEntries as $entry) { $bonus = $entry[Calc::A_VALUE]; $childId = $entry[Calc::A_OTHER_ID]; if ($bonus > Cfg::DEF_ZERO) { $updatesForWallets[] = [Calc::A_CUST_ID => $custId, Calc::A_VALUE => $bonus, Calc::A_OTHER_ID => $childId]; } } } unset($updates); /* update wallets */ $respAdd = $this->_subDb->saveOperationWalletActive($updatesForWallets, Cfg::CODE_TYPE_OPER_BONUS_INFINITY, $datePerformed, $dateApplied); $operId = $respAdd->getOperationId(); $transIds = $respAdd->getTransactionsIds(); /* save orders and correspondent transactions into the log */ $this->_subDb->saveLogCustomers($updatesForWallets, $transIds); unset($updatesForWallets); /* update OI Compressed data */ $this->_subDb->saveUpdatesOiCompress($updatesForPvInf, $baseCalcId); /* 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("'Infinity Bonus' calculation is completed."); return $result; }
public function test_bonusInfinity_noPeriod_Eu() { /** === Test Data === */ /** === 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); /** * Prepare request and perform call. */ /** @var $call Call */ $call = new Call($mLogger, $mDba, $mToolbox, $mCallRepo, $mCallAccount, $mCallBonusPersonalPeriod, $mSubDb, $mSubCalc); $req = new Request\BonusInfinity(); $req->setScheme(Def::SCHEMA_EU); $resp = $call->bonusInfinity($req); $this->assertFalse($resp->isSucceed()); }