Пример #1
0
 public function getLastDate(Request\GetLastDate $request)
 {
     $result = new Response\GetLastDate();
     $assetTypeId = $request->getAssetTypeId();
     $assetTypeCode = $request->getAssetTypeCode();
     if (is_null($assetTypeId)) {
         $assetTypeId = $this->_repoTypeAsset->getIdByCode($assetTypeCode);
     }
     /* get the maximal date for balance */
     $balanceMaxDate = $this->_repoMod->getBalanceMaxDate($assetTypeId);
     if ($balanceMaxDate) {
         /* there is balance data */
         $dayBefore = $this->_toolPeriod->getPeriodPrev($balanceMaxDate, IPeriod::TYPE_DAY);
         $result->setData([Response\GetLastDate::LAST_DATE => $dayBefore]);
         $result->markSucceed();
     } else {
         /* there is no balance data yet, get transaction with minimal date */
         $transactionMinDate = $this->_repoMod->getTransactionMinDateApplied($assetTypeId);
         if ($transactionMinDate) {
             $period = $this->_toolPeriod->getPeriodCurrent($transactionMinDate);
             $dayBefore = $this->_toolPeriod->getPeriodPrev($period, IPeriod::TYPE_DAY);
             $result->setData([Response\GetLastDate::LAST_DATE => $dayBefore]);
             $result->markSucceed();
         }
     }
     return $result;
 }
Пример #2
0
 /**
  * @param Request\GetRepresentative $request
  *
  * @return Response\GetRepresentative
  */
 public function getRepresentative(Request\GetRepresentative $request)
 {
     $result = new Response\GetRepresentative();
     $typeId = $request->getAssetTypeId();
     $typeCode = $request->getAssetTypeCode();
     $this->_logger->info("'Get representative account' operation is called.");
     if (is_null($typeId)) {
         $typeId = $this->_repoTypeAsset->getIdByCode($typeCode);
     }
     if (!is_null($typeId)) {
         if (isset($this->_cachedRepresentAccs[$typeId])) {
             $result->setData($this->_cachedRepresentAccs[$typeId]);
             $result->markSucceed();
         } else {
             /* there is no cached data yet */
             /* get representative customer ID */
             $customerId = $this->_repoMod->getRepresentativeCustomerId();
             /* get all accounts for the representative customer */
             $accounts = $this->_repoAccount->getAllByCustomerId($customerId);
             if ($accounts) {
                 $mapped = [];
                 foreach ($accounts as $one) {
                     $mapped[$one->getAssetTypeId()] = $one;
                 }
                 $this->_cachedRepresentAccs = $mapped;
             }
             /* check selected accounts */
             if (isset($this->_cachedRepresentAccs[$typeId])) {
                 $result->setData($this->_cachedRepresentAccs[$typeId]);
                 $result->markSucceed();
             } else {
                 /* there is no accounts yet */
                 $req = new Request\Get();
                 $req->setCustomerId($customerId);
                 $req->setAssetTypeId($typeId);
                 $req->setCreateNewAccountIfMissed();
                 $resp = $this->get($req);
                 $accData = $resp->getData();
                 $this->_cachedRepresentAccs[$accData[Account::ATTR_ASSET_TYPE_ID]] = new Account($accData);
                 $result->setData($accData);
                 $result->markSucceed();
             }
         }
     } else {
         $this->_logger->error("Asset type is not defined (asset code: {$typeCode}).");
     }
     if ($result->isSucceed()) {
         $repAccId = $result->getId();
         $this->_logger->info("Representative account #{$repAccId} is found.");
     }
     $this->_logger->info("'Get representative account' operation is completed.");
     return $result;
 }
Пример #3
0
 public function cacheReset()
 {
     $this->_cachedRepresentAccs = [];
     $this->_repoMod->cacheReset();
 }