/** * @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; }
/** * * @return Gpf_DateTime_Range */ public function getDateRange(Gpf_DateTime $now = null) { if($now === null) { $now = new Gpf_DateTime(); } if ($this->getDate() == Pap_Features_PerformanceRewards_Rule::DATE_ALL_TIME || $this->getDate() == Pap_Features_PerformanceRewards_Rule::DATE_ALL_UNPAID_COMMISSIONS) { $range = new Gpf_DateTime_Range(); return $range; } if ($this->getDate() == Pap_Features_PerformanceRewards_Rule::DATE_SINCE_DAY_OF_LAST_MONTH) { $from = $now->getMonthStart(); $from->addMonth(-1); $from->addDay($this->getSince() - 1); $to = $now->getMonthStart(); $to->addDay(-1); return new Gpf_DateTime_Range($from, $to); } $filter = new Gpf_SqlBuilder_Filter(); $result = $filter->decodeDatePreset($this->getDate()); return new Gpf_DateTime_Range(new Gpf_DateTime($result['dateFrom']), new Gpf_DateTime($result['dateTo'])); }