protected function execute() { $json = new Gpf_Rpc_Json(); $processor = new Pap_Features_CompressedCommissionPlacementModel_Processor(); if ($this->isPending('initAffiliatesList', $this->_('Initialization affiliates list'))) { $this->debug('initAffiliatesList'); $this->userIds = $processor->initAffiliates(); $this->setParams($json->encode($this->userIds)); $this->setDone(); } if ($this->isPending('initTransactionsList', $this->_('Initialization transactions list'))) { $this->debug('initTransactionsList'); $this->userIds = $json->decode($this->getParams()); $this->affectedTransactions = $processor->initTransactions($this->userIds); $this->setParams($json->encode($this->getTransactionIdsFromCollection($this->affectedTransactions))); $this->setDone(); } $affectedTransactionIds = $this->getCollectionFromIds($json->decode($this->getParams())); $this->debug('process transactions'); while ($affectedTransactionIds->getSize() > 0) { if ($this->isPending($this->getFirstElement($affectedTransactionIds)->getId(), $this->_('Compressed transaction: %s', $this->getFirstElement($affectedTransactionIds)->getId()))) { $processor->processFirstTransaction($affectedTransactionIds); $this->setDone(); } else { $processor->removeByTransactionId($this->getFirstElement($affectedTransactionIds)->getId(), $affectedTransactionIds); } } $this->debug('finish task'); $this->forceFinishTask(); }
/** * * @param $message * @param $simulation * @return Gpf_Rpc_Form */ private function action(Gpf_Rpc_Params $params, $message = '', $simulation = false) { $data = new Gpf_Rpc_Data($params); $filters = new Gpf_Rpc_FilterCollection($params); if ($filters->getFilterValue('reachedCondition') == Gpf::YES) { $data->setValue('message', $message); return $data; } $compressedCommissionProcesor = new Pap_Features_CompressedCommissionPlacementModel_Processor(); $output = $compressedCommissionProcesor->recalculate($params->get('filters'), $simulation); $data->setValue('message', $output); return $data; }
/** * @param array $userIds * @param array $orderIds * @return Gpf_DbEngine_Row_Collection */ public function getAffectedTransactionsList($userIds, $orderIds = array()) { $select = new Gpf_SqlBuilder_SelectBuilder(); $select->select->addAll(Pap_Db_Table_Transactions::getInstance()); $select->from->add(Pap_Db_Table_Transactions::getName()); $dateRangeFilter = new Gpf_SqlBuilder_Filter(); $dateRange = $dateRangeFilter->decodeDatePreset(Pap_Features_CompressedCommissionPlacementModel_Processor::getRecurrencePreset()); $select->where->add(Pap_Db_Table_Transactions::DATE_INSERTED, '>', $dateRange['dateFrom']); $select->where->add(Pap_Db_Table_Transactions::DATE_INSERTED, '<', $dateRange['dateTo']); $select->where->add(Pap_Db_Table_Transactions::USER_ID, 'IN', $userIds); if (!is_null($orderIds) && count($orderIds) > 0) { $compoundCondition = new Gpf_SqlBuilder_CompoundWhereCondition(); foreach ($orderIds as $orderId) { $compoundCondition->add(Pap_Db_Table_Transactions::ORDER_ID, 'LIKE', '%'.$orderId.'%', 'OR'); } $select->where->addCondition($compoundCondition); } $select->orderBy->add(Pap_Db_Table_Transactions::TIER); $transaction = new Pap_Db_Transaction(); $transactionsRecordSet = $select->getAllRows(); $unpaidTransactions = new Gpf_Data_RecordSet(); $unpaidTransactions->setHeader($transactionsRecordSet->getHeader()); foreach ($transactionsRecordSet as $trans) { if ($trans->get(Pap_Db_Table_Transactions::PAYOUT_STATUS) == Pap_Common_Constants::PSTATUS_UNPAID) { $unpaidTransactions->add($trans); } else { $this->log('Removing paid transaction from affected transactions: ' . $trans->get(Pap_Db_Table_Transactions::TRANSACTION_ID)); } } return $transaction->loadCollectionFromRecordset($unpaidTransactions); }
/** * @return Pap_Stats_Params */ protected function getStatsParameters() { $params = new Pap_Stats_Params(); $dateRangeFilter = new Gpf_SqlBuilder_Filter(); $dateRange = $dateRangeFilter->decodeDatePreset(Pap_Features_CompressedCommissionPlacementModel_Processor::getRecurrencePreset()); $params->setDateRange($dateRange['dateFrom'], $dateRange['dateTo']); $params->setStatus($this->getStatuses()); return $params; }