Exemplo n.º 1
0
    public function process(Pap_Common_TransactionCompoundContext $context) {

        $transaction = $context->getTransaction();
        $context->getContext()->debug("SubaffiliateFirstSaleBonus started");
        if($transaction->getTier() != 2) {
            $context->getContext()->debug("SubaffiliateFirstSaleBonus ended - Not 2. tier");
            return;
        }

        $row = $this->getChildAffiliateInfo($transaction);

        $date = new Gpf_DateTime(time());
        $date->addDay(-Gpf_Settings::get(SubaffiliateFirstSaleBonus_Config::VALIDITY_DAYS));

        if(Gpf_Common_DateUtils::getDateTime($date->toTimeStamp()) > $row->get(Pap_Db_Table_Users::DATEINSERTED)) {
            $context->getContext()->debug("SubaffiliateFirstSaleBonus ended - Date Inserted is older than defined days.");
            return;
        }

        if($this->getChildAffiliateTransactionsCount($row->get(Pap_Db_Table_Transactions::USER_ID)) > 1) {
            $context->getContext()->debug("SubaffiliateFirstSaleBonus ended - Not user's first transaction.");
            return;
        }

        if(Gpf_Settings::get(SubaffiliateFirstSaleBonus_Config::BONUS_TYPE) == '%') {
            $transaction->setCommission($transaction->getCommission()+(Gpf_Settings::get(SubaffiliateFirstSaleBonus_Config::BONUS_AMOUNT)/100)*$transaction->getTotalCost());
        } else{
            $transaction->setCommission(Gpf_Settings::get(SubaffiliateFirstSaleBonus_Config::BONUS_AMOUNT)+$transaction->getCommission());
        }
        $context->getContext()->debug("SubaffiliateFirstSaleBonus ended - Success.");
        return;
    }
Exemplo n.º 2
0
 /**
  * @param $request
  * @param $groupId
  * @param $validTo
  * @return string
  */
 public function __construct(Gpf_Rpc_Request $request, Gpf_DateTime $validTo = null)
 {
     parent::__construct();
     $json = new Gpf_Rpc_Json();
     if ($validTo === null) {
         $validTo = new Gpf_DateTime();
         $validTo->addDay(30);
     }
     $this->setAccountId(Gpf_Session::getInstance()->getAuthUser()->getAccountId());
     $this->setGroupId('');
     $this->setRequest($json->encode($request->toObject()));
     $this->setValidTo($validTo->toDateTime());
     $this->insert();
     return $this;
 }
Exemplo n.º 3
0
 public function loadHistoricalRates()
 {
     $rawXmlData = file_get_contents('http://www.ecb.europa.eu/stats/eurofxref/eurofxref-hist.xml');
     $xml = new SimpleXMLElement($rawXmlData);
     $lastDate = null;
     $lastRates = null;
     Gpf_Log::debug('Loading to db...');
     foreach ($xml->{"Cube"}->{"Cube"} as $dailyRates) {
         $attr = $dailyRates->attributes();
         $date = new Gpf_DateTime($attr['time']);
         Gpf_Log::debug('Loading rates for ' . $date->toDate());
         $dayBefore = new Gpf_DateTime($attr['time']);
         $dayBefore->addDay(1);
         if ($lastDate !== null && $dayBefore->toDate() != $lastDate->toDate()) {
             Gpf_Log::debug('Last date was ' . $lastDate->toDate() . '! Extending last saved rates validFrom parameters...');
             foreach ($lastRates as $rate) {
                 Gpf_Log::debug('Extending validFrom for currency ' . $rate->getValidFrom() . ' - ' . $rate->getValidTo() . ' - ' . $rate->getTargetCurrency() . ' to value ' . $dayBefore->toDate() . ' 00:00:00');
                 $rate->setValidFrom($dayBefore->toDate() . ' 00:00:00');
                 $rate->update(array(Gpf_Db_Table_CurrencyRates::VALID_FROM));
             }
         }
         Gpf_Log::debug('Saving rates for ' . $date->toDate());
         $lastRates = array();
         foreach ($dailyRates->{"Cube"} as $currencyRate) {
             $info = $currencyRate->attributes();
             Gpf_Log::debug('Saving EUR to ' . $info['currency'] . ', rate=' . $info['rate']);
             $rate = $this->saveDailyRate($date, (string) $info['currency'], (double) $info['rate']);
             $lastRates[] = $rate;
         }
         $lastDate = new Gpf_DateTime($attr['time']);
     }
     Gpf_Log::debug('Load complete');
 }
Exemplo n.º 4
0
    /**
     * @throws Gpf_DbEngine_NoRowException
     * @param $accountId
     * @return String
     */
    public function getNextInvoiceDateFrom($accountId) {
		$lastInvoiceDateTo = $this->getLastInvoiceVariable($accountId, self::DATE_TO);
		$date = new Gpf_DateTime($lastInvoiceDateTo);
        $date->addDay(1);
        return $date->getDayStart()->toDateTime();
    }
Exemplo n.º 5
0
 private function getNextTimeProgress($timestamp) {
     $time = new Gpf_DateTime((int)$timestamp);
     $time->addDay(-1);
     return $time->toTimeStamp();
 }
 /**
  * @param $daysCount
  * @return Gpf_DateTime
  */
 protected function getLastDate($daysCount)
 {
     $date = new Gpf_DateTime();
     $date->addDay($daysCount * -1);
     return $date;
 }