/**
  * Create new period record and related calculation record.
  *
  * @param $calcTypeId
  * @param $dsBegin
  * @param $dsEnd
  *
  * @return DataObject
  */
 public function addNewPeriodAndCalc($calcTypeId, $dsBegin, $dsEnd)
 {
     $result = new DataObject();
     /* add new period */
     $periodData = [Period::ATTR_CALC_TYPE_ID => $calcTypeId, Period::ATTR_DSTAMP_BEGIN => $dsBegin, Period::ATTR_DSTAMP_END => $dsEnd];
     $periodId = $this->_repoBasic->addEntity(Period::ENTITY_NAME, $periodData);
     $this->_logger->info("New period #{$periodId} for calculation type #{$calcTypeId} is registered ({$dsBegin}-{$dsEnd}).");
     $periodData[Period::ATTR_ID] = $periodId;
     $result->setData(self::DATA_PERIOD, $periodData);
     /* add related calculation */
     $dateStarted = $this->_toolDate->getUtcNowForDb();
     $calcData = [Calculation::ATTR_PERIOD_ID => $periodId, Calculation::ATTR_DATE_STARTED => $dateStarted, Calculation::ATTR_DATE_ENDED => null, Calculation::ATTR_STATE => Cfg::CALC_STATE_STARTED];
     $calcId = $this->_repoBasic->addEntity(Calculation::ENTITY_NAME, $calcData);
     $this->_logger->info("New calculation #{$calcId} for period #{$periodId} is registered.");
     $calcData[Calculation::ATTR_ID] = $calcId;
     $result->setData(self::DATA_CALC, $calcData);
     return $result;
 }
Example #2
0
 public function setOdooId($data)
 {
     parent::setData(static::AS_ODOO_ID, $data);
 }
 public function setValue($data)
 {
     parent::setData(self::AS_VALUE, $data);
 }
 public function test_compressPtc_isPeriod()
 {
     /** === Test Data === */
     $CALC_ID = 21;
     /** === Mocks === */
     $mLogger = $this->_mockLogger();
     $mConn = $this->_mockConnection();
     $mDba = $this->_mockDbAdapter(null, $mConn);
     $mToolDate = $this->_mockFor('Praxigento\\Core\\Tool\\IDate');
     $mToolPeriod = $this->_mockFor('Praxigento\\Core\\Tool\\IPeriod');
     $mToolbox = $this->_mockToolbox(null, $mToolDate, null, $mToolPeriod);
     $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();
     // $calcData = $respGetPeriod->getCalcData();
     $mRespGetPeriod->setCalcData([Calculation::ATTR_ID => $CALC_ID]);
     // $this->_conn->beginTransaction();
     $mConn->expects($this->once())->method('beginTransaction');
     // $updates = $this->_subCalc->compressPtc($downlineSnap, $transData, $compressLevel);
     $mUpdates = new DataObject();
     $mUpdates->setData(Sub\Calc::DATA_SNAP, []);
     $mUpdates->setData(Sub\Calc::DATA_PV, []);
     $mSubCalc->expects($this->once())->method('compressPtc')->willReturn($mUpdates);
     // $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\CompressPtc();
     $resp = $call->compressPtc($req);
     $this->assertTrue($resp->isSucceed());
 }
 public function setType($data)
 {
     parent::setData(self::AS_TYPE, $data);
 }
 public function setWebsiteId($data)
 {
     parent::setData(self::AS_WEBSITE_ID, $data);
 }
 public function setId($data)
 {
     parent::setData(self::AS_ID, $data);
 }
 public function setPvUnit($data)
 {
     parent::setData(static::AS_PV_UNIT, $data);
 }