public function calc(Request\Calc $request)
 {
     $result = new Response\Calc();
     $assetTypeId = $request->getAssetTypeId();
     $dateTo = $request->getDateTo();
     /* get the last balance date */
     $reqLastDate = new Request\GetLastDate();
     $reqLastDate->setData(Request\GetLastDate::ASSET_TYPE_ID, $assetTypeId);
     $respLastDate = $this->getLastDate($reqLastDate);
     $lastDate = $respLastDate->getLastDate();
     $balances = $this->_repoMod->getBalancesOnDate($assetTypeId, $lastDate);
     /* get transactions for period */
     $dtFrom = $this->_toolPeriod->getTimestampFrom($lastDate, IPeriod::TYPE_DAY);
     $dtTo = $this->_toolPeriod->getTimestampTo($dateTo, IPeriod::TYPE_DAY);
     $trans = $this->_repoMod->getTransactionsForPeriod($assetTypeId, $dtFrom, $dtTo);
     $updates = $this->_subCalcSimple->calcBalances($balances, $trans);
     $this->_repoMod->updateBalances($updates);
     $result->markSucceed();
     return $result;
 }
 /**
  * Calculate downline snapshots up to requested date (including).
  *
  * @param Request\Calc $request
  *
  * @return Response\Calc
  */
 public function calc(Request\Calc $request)
 {
     $result = new Response\Calc();
     $this->_logger->info("New downline snapshot calculation is requested.");
     $periodTo = $request->getDatestampTo();
     $def = $this->_manTrans->begin();
     try {
         /* get the last date with calculated snapshots */
         $reqLast = new Request\GetLastDate();
         /** @var  $resp Response\GetLastDate */
         $respLast = $this->getLastDate($reqLast);
         $lastDatestamp = $respLast->getLastDate();
         /* get the snapshot on the last date */
         $snapshot = $this->_repoSnap->getStateOnDate($lastDatestamp);
         /* get change log for the period */
         $tsFrom = $this->_toolPeriod->getTimestampNextFrom($lastDatestamp);
         $tsTo = $this->_toolPeriod->getTimestampTo($periodTo);
         $changelog = $this->_repoChange->getChangesForPeriod($tsFrom, $tsTo);
         /* calculate snapshots for the period */
         $updates = $this->_subCalc->calcSnapshots($snapshot, $changelog);
         /* save new snapshots in DB */
         $this->_repoSnap->saveCalculatedUpdates($updates);
         $this->_manTrans->commit($def);
         $result->markSucceed();
     } finally {
         $this->_manTrans->end($def);
     }
     return $result;
 }