/**
  * Defined by Zend_Validate_Interface
  *
  * Returns true if and only if a field name has been set, the field name is available in the
  * context, and the value of that field name matches the provided value.
  *
  * @param  string $value
  * @param array $context
  *
  * @return boolean
  */
 public function isValid($value, $context = null)
 {
     $this->_setValue($value);
     $fieldValue = $this->getFieldValue($context);
     if (null === $fieldValue) {
         return false;
     }
     $date = new Zend_Date($value, Zend_Date::ISO_8601);
     $date2 = new Zend_Date($fieldValue, Zend_Date::ISO_8601);
     if ($date->compare($date2) < 0 || !$this->_allowEqual && $date->compare($date2) == 0) {
         $this->_error(self::NOT_GREATER, $date2);
         return false;
     }
     return true;
 }
Example #2
0
 /**
  * (non-PHPdoc)
  * @see library/Oara/Network/Oara_Network_Publisher_Interface#getTransactionList($aMerchantIds, $dStartDate, $dEndDate)
  */
 public function getTransactionList($merchantList = null, Zend_Date $dStartDate = null, Zend_Date $dEndDate = null, $merchantMap = null)
 {
     $totalTransactions = array();
     $report = $this->_adsense->reports->generate($dStartDate->toString("YYYY-MM-dd"), $dEndDate->toString("YYYY-MM-dd"), array("dimension" => "DATE", "metric" => array("PAGE_VIEWS", "CLICKS", "EARNINGS"), "sort" => "DATE"));
     $firstDayMonth = new Zend_Date();
     $firstDayMonth->setDay(1);
     $firstDayMonth->setHour("00");
     $firstDayMonth->setMinute("00");
     $firstDayMonth->setSecond("00");
     if (isset($report["rows"])) {
         foreach ($report["rows"] as $row) {
             $obj = array();
             $obj['merchantId'] = 1;
             $tDate = new Zend_Date($row[0], "yyyy-MM-dd");
             $tDate->setHour("00");
             $tDate->setMinute("00");
             $tDate->setSecond("00");
             $obj['date'] = $tDate->toString("yyyy-MM-dd HH:mm:ss");
             $obj['impression_number'] = (int) Oara_Utilities::parseDouble($row[1]);
             $obj['click_number'] = Oara_Utilities::parseDouble($row[2]);
             if ($firstDayMonth->compare($tDate) <= 0) {
                 $obj['amount'] = Oara_Utilities::parseDouble($row[3]);
                 $obj['commission'] = Oara_Utilities::parseDouble($row[3]);
                 $obj['status'] = Oara_Utilities::STATUS_PENDING;
             } else {
                 $obj['amount'] = Oara_Utilities::parseDouble($row[3]);
                 $obj['commission'] = Oara_Utilities::parseDouble($row[3]);
                 $obj['status'] = Oara_Utilities::STATUS_CONFIRMED;
             }
             $totalTransactions[] = $obj;
         }
     }
     return $totalTransactions;
 }
 /**
  * Unset array element with '__empty' key
  *
  */
 protected function _beforeSave()
 {
     $value = $this->getValue();
     if (is_array($value)) {
         unset($value['__empty']);
     }
     $arr = array();
     foreach ($value as $key => $val) {
         if (isset($val['min_order_qty']) && isset($val['max_order_qty']) && isset($val['point_value_referrer']) && isset($val['calculation_type_referrer']) && isset($val['point_value_referred']) && isset($val['calculation_type_referred']) && isset($val['date_from']) && isset($val['date_end'])) {
             if (is_float($val['point_value_referrer']) && (int) $val['point_value_referrer'] != 0) {
                 Mage::getSingleton('adminhtml/session')->addError('Referrer Point/Ratio values issue. Value must be an integer.');
             }
             if (is_float($val['point_value_referred']) && (int) $val['point_value_referred'] != 0) {
                 Mage::getSingleton('adminhtml/session')->addError('Referred Point/Ratio values issue. Value must be an integer.');
             }
             $fromDate = $toDate = null;
             $data = $this->_filterDates($val, array('date_from', 'date_end'));
             $fromDate = $data['date_from'];
             $toDate = $data['date_end'];
             if ($fromDate && $toDate) {
                 $fromDate = new Zend_Date($fromDate, Varien_Date::DATE_INTERNAL_FORMAT);
                 $toDate = new Zend_Date($toDate, Varien_Date::DATE_INTERNAL_FORMAT);
                 if ($fromDate->compare($toDate) === 1) {
                     Mage::getSingleton('adminhtml/session')->addError('End Date must be greater than Start Date.');
                 }
             }
             $arr[$key] = $data;
         }
     }
     $this->setValue($arr);
     //$this->setValue($value);
     parent::_beforeSave();
 }
 public function pruneOldBackups()
 {
     $current_bucket = Mage::getStoreConfig('system/cloudbackup/bucket_name');
     if (!$current_bucket) {
         $this->log("No bucket is set, we cannot prune old backups.");
         return;
     }
     $s3 = Mage::helper('cloudbackup')->getS3Client();
     try {
         $bucket_contents = $s3->getBucket($current_bucket);
         $cutoff_date = new Zend_Date();
         $cutoff_date->sub($this->NUM_MONTHS, Zend_Date::MONTH);
         foreach ($bucket_contents as $key) {
             $bucket_date = new Zend_Date($key['time'], Zend_Date::TIMESTAMP);
             if ($bucket_date->compare($cutoff_date) == -1) {
                 $this->log($key['name'] . " was created on {$bucket_date} and is older than " . $this->NUM_MONTHS . " months, deleting.");
                 $s3->deleteObject($current_bucket, $key['name']);
             }
         }
     } catch (Exception $e) {
         Mage::logException($e);
         $this->log("Failed to while pruning old backups - please see exception.log for details.");
         return;
     }
 }
 /**
  * Update auto generated Specific Coupon if it's rule changed
  *
  * @param Mage_SalesRule_Model_Rule $rule
  * @return Mage_SalesRule_Model_Resource_Coupon
  */
 public function updateSpecificCoupons(Mage_SalesRule_Model_Rule $rule)
 {
     if (!$rule || !$rule->getId() || !$rule->hasDataChanges()) {
         return $this;
     }
     $updateArray = array();
     if ($rule->dataHasChangedFor('uses_per_coupon')) {
         $updateArray['usage_limit'] = $rule->getUsesPerCoupon();
     }
     if ($rule->dataHasChangedFor('uses_per_customer')) {
         $updateArray['usage_per_customer'] = $rule->getUsesPerCustomer();
     }
     $ruleNewDate = new Zend_Date($rule->getToDate());
     $ruleOldDate = new Zend_Date($rule->getOrigData('to_date'));
     if ($ruleNewDate->compare($ruleOldDate)) {
         $updateArray['expiration_date'] = $rule->getToDate();
     }
     if (!empty($updateArray)) {
         $this->_getWriteAdapter()->update($this->getTable('salesrule/coupon'), $updateArray, array('rule_id = ?' => $rule->getId(), 'generated_by_dotmailer is null'));
     }
     //update coupons added by dotmailer. not to change expiration date
     $dotmailerUpdateArray = $updateArray;
     unset($dotmailerUpdateArray['expiration_date']);
     if (!empty($dotmailerUpdateArray)) {
         $this->_getWriteAdapter()->update($this->getTable('salesrule/coupon'), $dotmailerUpdateArray, array('rule_id = ?' => $rule->getId(), 'generated_by_dotmailer is 1'));
     }
     return $this;
 }
 protected function _addSarpInfo($buyRequest, $product)
 {
     $Period = Mage::getModel('sarp/period');
     /* We should add custom options that doesnt exist */
     if ($buyRequest->getAwSarpSubscriptionType()) {
         if ($Period->load($buyRequest->getAwSarpSubscriptionType())->getId()) {
             $product->addCustomOption('aw_sarp_subscription_type', $Period->getId());
         }
     }
     if ($buyRequest->getAwSarpSubscriptionStart() && $Period->getId()) {
         $date = new Zend_Date($buyRequest->getAwSarpSubscriptionStart(), Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT));
         // Check date
         // Never check if start date
         //$performDateCompare = !!Mage::getSingleton('customer/session')->getCustomer()->getId();
         $performDateCompare = !AW_Sarp_Model_Cron::$isCronSession;
         $today = new Zend_Date();
         if (!$this->isVirtual($product)) {
             $today->addDayOfYear($Period->getPaymentOffset());
         }
         if ($performDateCompare && ($date->compare($today, Zend_Date::DATE_SHORT) < 0 || !$Period->isAllowedDate($date, $product))) {
             throw new Mage_Core_Exception(Mage::helper('sarp')->__("Selected date is not valid for specified period"));
         }
     } else {
         $date = Mage::app()->getLocale()->date();
     }
     $product->addCustomOption('aw_sarp_subscription_start', $date->toString('Y-MM-dd'));
 }
 public function getIntervals()
 {
     if (!$this->_intervals) {
         $this->_intervals = array();
         if (!$this->_from && !$this->_to) {
             return $this->_intervals;
         }
         $dateStart = new Zend_Date($this->_from);
         $dateEnd = new Zend_Date($this->_to);
         $t = array();
         $firstInterval = true;
         /** START AITOC FIX **/
         if (in_array((string) $this->_period, array('day', 'month', 'year'))) {
             /** END AITOC FIX **/
             while ($dateStart->compare($dateEnd) <= 0) {
                 switch ($this->_period) {
                     case 'day':
                         $t['title'] = $dateStart->toString(Mage::app()->getLocale()->getDateFormat());
                         $t['start'] = $dateStart->toString('yyyy-MM-dd HH:mm:ss');
                         $t['end'] = $dateStart->toString('yyyy-MM-dd 23:59:59');
                         $dateStart->addDay(1);
                         break;
                     case 'month':
                         $t['title'] = $dateStart->toString('MM/yyyy');
                         $t['start'] = $firstInterval ? $dateStart->toString('yyyy-MM-dd 00:00:00') : $dateStart->toString('yyyy-MM-01 00:00:00');
                         $lastInterval = $dateStart->compareMonth($dateEnd->getMonth()) == 0;
                         $t['end'] = $lastInterval ? $dateStart->setDay($dateEnd->getDay())->toString('yyyy-MM-dd 23:59:59') : $dateStart->toString('yyyy-MM-' . date('t', $dateStart->getTimestamp()) . ' 23:59:59');
                         $dateStart->addMonth(1);
                         if ($dateStart->compareMonth($dateEnd->getMonth()) == 0) {
                             $dateStart->setDay(1);
                         }
                         $firstInterval = false;
                         break;
                     case 'year':
                         $t['title'] = $dateStart->toString('yyyy');
                         $t['start'] = $firstInterval ? $dateStart->toString('yyyy-MM-dd 00:00:00') : $dateStart->toString('yyyy-01-01 00:00:00');
                         $lastInterval = $dateStart->compareYear($dateEnd->getYear()) == 0;
                         $t['end'] = $lastInterval ? $dateStart->setMonth($dateEnd->getMonth())->setDay($dateEnd->getDay())->toString('yyyy-MM-dd 23:59:59') : $dateStart->toString('yyyy-12-31 23:59:59');
                         $dateStart->addYear(1);
                         if ($dateStart->compareYear($dateEnd->getYear()) == 0) {
                             $dateStart->setMonth(1)->setDay(1);
                         }
                         $firstInterval = false;
                         break;
                 }
                 $this->_intervals[$t['title']] = $t;
             }
             /** START AITOC FIX **/
         }
         /** END AITOC FIX **/
     }
     return $this->_intervals;
 }
Example #8
0
 public function filterLs($lsResult, $io)
 {
     $_lsResult = array();
     foreach ($lsResult as $r) {
         if ($io->getUdbatchGrep() && !fnmatch($io->getUdbatchGrep(), $r['text']) || $io->isDir($r['text'])) {
             continue;
         }
         $_lsResult[] = $r;
     }
     $lsResult = $_lsResult;
     if ($io->getUdbatch() && ($dateFilter = $io->getUdbatch()->getDatetimeFilter())) {
         $filterFrom = null;
         if ('0000-00-00 00:00:00' != $dateFilter[0] && !empty($dateFilter[0])) {
             $filterFrom = new Zend_Date();
             $filterFrom->setTimezone(Mage_Core_Model_Locale::DEFAULT_TIMEZONE);
             $filterFrom->set($dateFilter[0], Varien_Date::DATETIME_INTERNAL_FORMAT);
             $filterFrom->setTimezone($dateFilter[2]);
         }
         $filterTo = null;
         if ('0000-00-00 00:00:00' != $dateFilter[1] && !empty($dateFilter[1])) {
             $filterTo = new Zend_Date();
             $filterTo->setTimezone(Mage_Core_Model_Locale::DEFAULT_TIMEZONE);
             $filterTo->set($dateFilter[1], Varien_Date::DATETIME_INTERNAL_FORMAT);
             $filterTo->setTimezone($dateFilter[2]);
         }
         $_lsResult = array();
         foreach ($lsResult as $r) {
             $filter = new Zend_Date();
             $filter->setTimezone($dateFilter[2]);
             $filter->set($io->mdtm($r['text']));
             if ((empty($filterFrom) || $filter->compare($filterFrom) >= 0) && (empty($filterTo) || $filter->compare($filterTo) == -1)) {
                 $_lsResult[] = $r;
             }
         }
         $lsResult = $_lsResult;
     }
     return $lsResult;
 }
Example #9
0
 public function isValid($value, $context = null)
 {
     $value = (string) $value;
     $this->_setValue($value);
     if (isset($context)) {
         $date = new Zend_Date($value);
         $departureTime = new Zend_Date($context['departureTime']);
         if ($date->compare($departureTime) <= 0) {
             $this->_error(self::INVALID);
             return false;
         }
     }
     return true;
 }
Example #10
0
 public function getMagentoCronStatusToHtml($fieldName = 'scheduled_at')
 {
     $scheduleCollection = Mage::getModel('cron/schedule')->getCollection();
     $scheduleCollection->setOrder($fieldName);
     $scheduleModel = $scheduleCollection->getFirstItem();
     $result = sprintf(self::ERROR_RESULT, $this->__('Never'));
     if ($scheduleModel->getId() && $scheduleModel->getData($fieldName) != '0000-00-00 00:00:00') {
         $findDate = new Zend_Date($scheduleModel->getData($fieldName), Varien_Date::DATETIME_INTERNAL_FORMAT);
         $today = new Zend_Date(null, Zend_Date::DATE_SHORT);
         $result = sprintf(self::SUCCESS_RESULT, $findDate->toString(Varien_Date::DATETIME_INTERNAL_FORMAT));
         if ($findDate->compare($today, Zend_Date::DATE_SHORT) < 0) {
             $result = sprintf(self::ERROR_RESULT, $findDate->toString(Varien_Date::DATETIME_INTERNAL_FORMAT));
         }
     }
     return $result;
 }
Example #11
0
 public function getPredefinedStartDate()
 {
     $_editableOptions = $this->getProduct()->getPreconfiguredValues();
     if (isset($_editableOptions['aw_sarp_subscription_start'])) {
         $date = $_editableOptions['aw_sarp_subscription_start'];
         $zDate = new Zend_Date();
         $zDate->setDate($date);
         $today = new Zend_Date();
         $period = Mage::getModel('sarp/period')->load($_editableOptions['aw_sarp_subscription_type']);
         if ($zDate->compare($today, Zend_Date::DATE_SHORT) < 0 || !$period->isAllowedDate($zDate, $this->getProduct())) {
             $zDate = $period->getNearestAvailableDay();
         }
         $date = $zDate->toString(preg_replace(array('/M+/', '/d+/'), array('MM', 'dd'), Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT)));
         return $date;
     }
     return null;
 }
Example #12
0
 /**
  * Checks if content published
  *
  * @return bool true if published
  */
 private function _checkPublished()
 {
     if ($this->_container === null) {
         return true;
     }
     if (!$this->_container->getPublished()) {
         if ($this->_container->getPublishingDate()) {
             $zDate = new Zend_Date();
             $result = $zDate->compare(strtotime($this->_container->getPublishingDate()));
             if ($result == 0 || $result == 1) {
                 $this->_container->setPublishingDate('')->setPublished(true);
                 Application_Model_Mappers_ContainerMapper::getInstance()->save($this->_container);
             }
         }
     }
     return (bool) $this->_container->getPublished();
 }
Example #13
0
 public function saveAction()
 {
     if ($data = $this->getRequest()->getPost()) {
         try {
             $redirectBack = $this->getRequest()->getParam('back', false);
             if (!Mage::helper('points')->magentoLess14()) {
                 //_filterDates convert dates in array from localized to internal format only for magento > 1.4
                 $data = $this->_filterDates($data, array('from_date', 'to_date'));
                 if (isset($data['from_date']) && $data['from_date'] instanceof Zend_Date) {
                     $data['from_date'] = $data['from_date']->toString(VARIEN_DATE::DATE_INTERNAL_FORMAT);
                 }
                 if (isset($data['to_date']) && $data['to_date'] instanceof Zend_Date) {
                     $data['to_date'] = $data['to_date']->toString(VARIEN_DATE::DATE_INTERNAL_FORMAT);
                 }
             }
             if (!empty($data['from_date']) && !empty($data['to_date'])) {
                 $fromDate = new Zend_Date($data['from_date'], VARIEN_DATE::DATE_INTERNAL_FORMAT);
                 $toDate = new Zend_Date($data['to_date'], VARIEN_DATE::DATE_INTERNAL_FORMAT);
                 if ($fromDate->compare($toDate) === 1) {
                     throw new Exception($this->__("'To Date' must be equal or more than 'From Date'"));
                 }
             }
             $model = Mage::getModel('points/rule');
             $data['conditions'] = $data['rule']['conditions'];
             unset($data['rule']);
             $model->loadPost($data);
             if ($this->getRequest()->getParam('_save_as_flag')) {
                 $model->setId(null);
             }
             $model->save();
             Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('points')->__('Rule was successfully saved'));
             if ($redirectBack) {
                 $this->_redirect('*/*/edit', array('id' => $model->getId(), '_current' => true));
                 return;
             }
             return $this->_redirect('*/*/');
         } catch (Exception $e) {
             Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
             Mage::getSingleton('adminhtml/session')->setPageData($data);
             $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('rule_id')));
             return;
         }
     }
     $this->_redirect('*/*/');
 }
 public function validateAge($value)
 {
     $parts = @explode('-', $value);
     // Error if not filled out
     if (count($parts) < 3 || count(array_filter($parts)) < 3) {
         //$this->addError('Please fill in your birthday.');
         return false;
     }
     $value = mktime(0, 0, 0, $parts[1], $parts[2], $parts[0]);
     // Error if too low
     $date = new Zend_Date($value);
     $date->add((int) $this->min_age, Zend_Date::YEAR);
     if ($date->compare(new Zend_Date()) > 0) {
         //$this->addError('You are not old enough.');
         return false;
     }
     return true;
 }
Example #15
0
 public function getIntervals()
 {
     if (!$this->_intervals) {
         $this->_intervals = array();
         if (!$this->_from && !$this->_to) {
             return $this->_intervals;
         }
         $dateStart = new Zend_Date($this->_from);
         $dateStart2 = new Zend_Date($this->_from);
         $dateEnd = new Zend_Date($this->_to);
         $t = array();
         while ($dateStart->compare($dateEnd) <= 0) {
             switch ($this->_period) {
                 case 'day':
                     $t['title'] = $dateStart->toString(Mage::app()->getLocale()->getDateFormat());
                     $t['start'] = $dateStart->toString('yyyy-MM-dd HH:mm:ss');
                     $t['end'] = $dateStart->toString('yyyy-MM-dd 23:59:59');
                     $dateStart->addDay(1);
                     break;
                 case 'month':
                     $t['title'] = $dateStart->toString('MM/yyyy');
                     $t['start'] = $dateStart->toString('yyyy-MM-01 00:00:00');
                     $t['end'] = $dateStart->toString('yyyy-MM-' . date('t', $dateStart->getTimestamp()) . ' 23:59:59');
                     $dateStart->addMonth(1);
                     break;
                 case 'year':
                     $t['title'] = $dateStart->toString('yyyy');
                     $t['start'] = $dateStart->toString('yyyy-01-01 00:00:00');
                     $t['end'] = $dateStart->toString('yyyy-12-31 23:59:59');
                     $dateStart->addYear(1);
                     break;
             }
             $this->_intervals[$t['title']] = $t;
         }
         if ($this->_period != 'day') {
             $titles = array_keys($this->_intervals);
             if (count($titles) > 0) {
                 $this->_intervals[$titles[0]]['start'] = $dateStart2->toString('yyyy-MM-dd 00:00:00');
                 $this->_intervals[$titles[count($titles) - 1]]['end'] = $dateEnd->toString('yyyy-MM-dd 23:59:59');
             }
         }
     }
     return $this->_intervals;
 }
Example #16
0
 public function show()
 {
     date_default_timezone_set('America/New_York');
     $fileContents = file_get_contents(realpath(__DIR__) . '/../../../logs/visitors.xml');
     $xml = '<root>' . $fileContents . '</root>';
     $report = "-------" . PHP_EOL . "Visitors" . PHP_EOL . "Timezone: " . date('e') . PHP_EOL;
     $xmlElements = simplexml_load_string($xml);
     $firstRequestTime = $xmlElements->children()->visitor[0]->REQUEST_TIME;
     $firstDate = new Zend_Date($firstRequestTime);
     foreach ($xmlElements as $visitor) {
         $curDate = new Zend_Date((string) $visitor->REQUEST_TIME);
         if ($curDate->compare($firstDate->get(Zend_Date::DATES), Zend_Date::DATES)) {
             $report .= '===== NEW DATE =====' . PHP_EOL;
         }
         $report .= date('d-M-Y h:i:s', (string) $visitor->REQUEST_TIME) . ': ' . $visitor->HTTP_USER_AGENT . PHP_EOL;
         $firstDate = $curDate;
     }
     $this->_registry->getResponse()->appendContent($report);
 }
 /**
  * Retrieve array of intervals
  *
  * @param string $from
  * @param string $to
  * @param string $period
  * @return array
  */
 public function getIntervals($from, $to, $period = self::REPORT_PERIOD_TYPE_DAY)
 {
     $intervals = array();
     if (!$from && !$to) {
         return $intervals;
     }
     $start = new Zend_Date($from, Varien_Date::DATE_INTERNAL_FORMAT);
     if ($period == self::REPORT_PERIOD_TYPE_DAY) {
         $dateStart = $start;
     }
     if ($period == self::REPORT_PERIOD_TYPE_MONTH) {
         $dateStart = new Zend_Date(date("Y-m", $start->getTimestamp()), Varien_Date::DATE_INTERNAL_FORMAT);
     }
     if ($period == self::REPORT_PERIOD_TYPE_YEAR) {
         $dateStart = new Zend_Date(date("Y", $start->getTimestamp()), Varien_Date::DATE_INTERNAL_FORMAT);
     }
     $dateEnd = new Zend_Date($to, Varien_Date::DATE_INTERNAL_FORMAT);
     while ($dateStart->compare($dateEnd) <= 0) {
         switch ($period) {
             case self::REPORT_PERIOD_TYPE_DAY:
                 $t = $dateStart->toString('yyyy-MM-dd');
                 $dateStart->addDay(1);
                 break;
             case self::REPORT_PERIOD_TYPE_MONTH:
                 $t = $dateStart->toString('yyyy-MM');
                 $dateStart->addMonth(1);
                 break;
             case self::REPORT_PERIOD_TYPE_YEAR:
                 $t = $dateStart->toString('yyyy');
                 $dateStart->addYear(1);
                 break;
         }
         $intervals[] = $t;
     }
     return $intervals;
 }
Example #18
0
 /**
  * Update auto generated Specific Coupon if it's rule changed
  *
  * @param Mage_SalesRule_Model_Rule $rule
  * @return Mage_SalesRule_Model_Resource_Coupon
  */
 public function updateSpecificCoupons(Mage_SalesRule_Model_Rule $rule)
 {
     if (!$rule || !$rule->getId() || !$rule->hasDataChanges()) {
         return $this;
     }
     $updateArray = array();
     if ($rule->dataHasChangedFor('uses_per_coupon')) {
         $updateArray['usage_limit'] = $rule->getUsesPerCoupon();
     }
     if ($rule->dataHasChangedFor('uses_per_customer')) {
         $updateArray['usage_per_customer'] = $rule->getUsesPerCustomer();
     }
     $ruleNewDate = new Zend_Date($rule->getToDate());
     $ruleOldDate = new Zend_Date($rule->getOrigData('to_date'));
     if ($ruleNewDate->compare($ruleOldDate)) {
         $updateArray['expiration_date'] = $rule->getToDate();
     }
     if (!empty($updateArray)) {
         $this->_getWriteAdapter()->update($this->getTable('salesrule_coupon'), $updateArray, array('rule_id = ?' => $rule->getId()));
     }
     return $this;
 }
 /**
  * Overrides standard getIntervals
  * @return array
  */
 public function getIntervals()
 {
     if (!$this->_intervals) {
         $this->_intervals = array();
         if (!$this->_from && !$this->_to) {
             return $this->_intervals;
         }
         $dateStart = new Zend_Date($this->_from);
         $dateStart2 = new Zend_Date($this->_from);
         $dateEnd = new Zend_Date($this->_to);
         $t = array();
         while ($dateStart->compare($dateEnd) <= 0) {
             switch ($this->_period) {
                 case 'day':
                     $t['title'] = $dateStart->toString(Mage::app()->getLocale()->getDateFormat());
                     $t['start'] = $dateStart->toString('yyyy-MM-dd HH:mm:ss');
                     $t['end'] = $dateStart->toString('yyyy-MM-dd 23:59:59');
                     $dateStart->addDay(1);
                     break;
                 case 'week':
                     $t['title'] = $dateStart->toString(Mage::app()->getLocale()->getDateFormat());
                     $t['start'] = $dateStart->toString('yyyy-MM-dd 00:00:00');
                     $dateStart->addWeek(1)->subDay(1);
                     $t['title'] .= ' - ' . $dateStart->toString(Mage::app()->getLocale()->getDateFormat());
                     $t['end'] = $dateStart->toString('yyyy-MM-dd 23:59:59');
                     $dateStart->addDay(1);
                     break;
                 case 'month':
                     $t['title'] = $dateStart->toString('MM/yyyy');
                     $t['start'] = $dateStart->toString('yyyy-MM-01 00:00:00');
                     $t['end'] = $dateStart->toString('yyyy-MM-' . date('t', $dateStart->getTimestamp()) . ' 23:59:59');
                     $dateStart->addMonth(1);
                     break;
                 case 'quarter':
                     $month = (int) $dateStart->toString('MM');
                     $num = round($month / 3) + 1;
                     $t['title'] = Mage::helper('advancedreports')->__('Q') . $num . $dateStart->toString('/yyyy');
                     $t['start'] = $dateStart->toString('yyyy-MM-01 00:00:00');
                     $dateStart->addMonth(2);
                     $t['end'] = $dateStart->toString('yyyy-MM-' . date('t', $dateStart->getTimestamp()) . ' 23:59:59');
                     $dateStart->addMonth(1);
                     break;
                 case 'year':
                     $t['title'] = $dateStart->toString('yyyy');
                     $t['start'] = $dateStart->toString('yyyy-01-01 00:00:00');
                     $t['end'] = $dateStart->toString('yyyy-12-31 23:59:59');
                     $dateStart->addYear(1);
                     break;
             }
             $this->_intervals[$t['title']] = $t;
             //		echo $t['start'].' - '.$t['end'].'<hr>';
         }
         if ($this->_period != 'day') {
             $titles = array_keys($this->_intervals);
             if (count($titles) > 0) {
                 $this->_intervals[$titles[0]]['start'] = $dateStart2->toString('yyyy-MM-dd 00:00:00');
                 $this->_intervals[$titles[count($titles) - 1]]['end'] = $dateEnd->toString('yyyy-MM-dd 23:59:59');
                 if ($this->_period == 'week') {
                     $t = $this->_intervals[$titles[count($titles) - 1]];
                     unset($this->_intervals[$titles[count($titles) - 1]]);
                     $date = new Zend_Date($t['start']);
                     $t['title'] = $date->toString(Mage::app()->getLocale()->getDateFormat());
                     unset($date);
                     $date = new Zend_Date($t['end']);
                     $t['title'] .= ' - ' . $date->toString(Mage::app()->getLocale()->getDateFormat());
                     $this->_intervals[$t['title']] = $t;
                 }
             }
         }
     }
     return $this->_intervals;
 }
Example #20
0
 public function hasSpecialPrice()
 {
     $has = false;
     $product = $this->getProduct();
     if ($this->getSpecialPrice() <= 0) {
         return $has;
     }
     if (is_empty_date($product->getSpecialFromDate())) {
         return $has;
     }
     $cDate = Mage::app()->getLocale()->date(null, null, Mage::app()->getLocale()->getDefaultLocale());
     $timezone = Mage::app()->getStore($this->getStoreId())->getConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_TIMEZONE);
     $fromDate = new Zend_Date(null, null, Mage::app()->getLocale()->getDefaultLocale());
     if ($timezone) {
         $fromDate->setTimezone($timezone);
     }
     $fromDate->setDate(substr($product->getSpecialFromDate(), 0, 10), 'yyyy-MM-dd');
     $fromDate->setTime(substr($product->getSpecialFromDate(), 11, 8), 'HH:mm:ss');
     $toDate = new Zend_Date(null, null, Mage::app()->getLocale()->getDefaultLocale());
     if (!is_empty_date($product->getSpecialToDate())) {
         if ($timezone) {
             $toDate->setTimezone($timezone);
         }
         $toDate->setDate(substr($product->getSpecialToDate(), 0, 10), 'yyyy-MM-dd');
         $toDate->setTime('23:59:59', 'HH:mm:ss');
     } else {
         if ($timezone) {
             $toDate->setTimezone($timezone);
         }
         $toDate->setDate($cDate->toString('yyyy-MM-dd'), 'yyyy-MM-dd');
         $toDate->setTime('23:59:59', 'HH:mm:ss');
         $toDate->add(7, Zend_Date::DAY);
     }
     if (($fromDate->compare($cDate) == -1 || $fromDate->compare($cDate) == 0) && ($toDate->compare($cDate) == 1 || $toDate->compare($cDate) == 0)) {
         $has = true;
     }
     return $has;
 }
Example #21
0
 /**
  * Validates data for rule
  * @param Varien_Object $object
  * @returns boolean|array - returns true if validation passed successfully. Array with error
  * description otherwise
  */
 public function validateData(Varien_Object $object)
 {
     if ($object->getData('from_date') && $object->getData('to_date')) {
         $dateStart = new Zend_Date($object->getData('from_date'), Varien_Date::DATE_INTERNAL_FORMAT);
         $dateEnd = new Zend_Date($object->getData('to_date'), Varien_Date::DATE_INTERNAL_FORMAT);
         if ($dateStart->compare($dateEnd) === 1) {
             return array(Mage::helper('rule')->__("End Date should be greater than Start Date"));
         }
     }
     return true;
 }
 /**
  * This method check's if the passed serialz is
  * valid.
  *
  * @param string $serialz The serialz to check
  * @return boolen TRUE if the serial is valid for the actual customer
  */
 public function isValid($serialz)
 {
     // decrypt the passed licence
     $this->decrypt($serialz);
     // check the start date of the serialz
     $from = new Zend_Date($this->_toIsoDate($this->_validFrom), Zend_Date::ISO_8601);
     if ($from->compare(Zend_Date::now()) == 1) {
         Mage::log('Runtime starts on ' . $from);
         return false;
     }
     // check the runtime for the serialz
     $then = new Zend_Date($this->_toIsoDate($this->_validThru), Zend_Date::ISO_8601);
     if ($then->compare(Zend_Date::now()) == -1) {
         Mage::log('Runtime ends on ' . $then);
         return false;
     }
     // check for the customer ID
     if ($this->_customerId != $this->_number + $this->_getCustomerId()) {
         Mage::log('Customer ID ' . $this->_customerId . ' does not match');
         return false;
     }
     // check fot the product ID
     if ($this->_productId != $this->_number + $this->_getProductId()) {
         Mage::log('Product ID ' . $this->_productId . ' does not match');
         return false;
     }
     // return TRUE if the serialz is valid
     return true;
 }
Example #23
0
 /**
  * (non-PHPdoc)
  * @see library/Oara/Network/Oara_Network_Interface#getTransactionList($aMerchantIds, $dStartDate, $dEndDate, $sTransactionStatus)
  */
 public function getTransactionList($merchantList = null, Zend_Date $dStartDate = null, Zend_Date $dEndDate = null)
 {
     $dStartDate = clone $dStartDate;
     $dStartDate->setHour("00");
     $dStartDate->setMinute("00");
     $dStartDate->setSecond("00");
     $dEndDate = clone $dEndDate;
     $dEndDate->setHour("23");
     $dEndDate->setMinute("59");
     $dEndDate->setSecond("59");
     $valuesFromExport = Oara_Utilities::cloneArray($this->_exportTransactionParameters);
     $valuesFromExport[] = new Oara_Curl_Parameter('Year', $dStartDate->get(Zend_Date::YEAR));
     $valuesFromExport[] = new Oara_Curl_Parameter('Month', $dStartDate->get(Zend_Date::MONTH));
     $valuesFromExport[] = new Oara_Curl_Parameter('Day', $dStartDate->get(Zend_Date::DAY));
     $valuesFromExport[] = new Oara_Curl_Parameter('EndYear', $dEndDate->get(Zend_Date::YEAR));
     $valuesFromExport[] = new Oara_Curl_Parameter('EndMonth', $dEndDate->get(Zend_Date::MONTH));
     $valuesFromExport[] = new Oara_Curl_Parameter('EndDay', $dEndDate->get(Zend_Date::DAY));
     $transactions = array();
     $urls = array();
     $urls[] = new Oara_Curl_Request('https://admin.omgpm.com/v2/reports/affiliate/leads/leadsummaryexport.aspx?', $valuesFromExport);
     $exportReport = $this->_client->get($urls);
     $xml = self::loadXml($exportReport[0]);
     if (isset($xml->Report->Report_Details_Group_Collection->Report_Details_Group)) {
         foreach ($xml->Report->Report_Details_Group_Collection->Report_Details_Group as $transaction) {
             $date = new Zend_Date(self::findAttribute($transaction, 'TransactionTime'), "yyyy-MM-ddTHH:mm:ss");
             if (in_array((int) self::findAttribute($transaction, 'MID'), $merchantList) && $date->compare($dStartDate) >= 0 && $date->compare($dEndDate) <= 0) {
                 $obj['merchantId'] = self::findAttribute($transaction, 'MID');
                 $obj['date'] = $date->toString("yyyy-MM-dd HH:mm:ss");
                 $obj['amount'] = 0;
                 $obj['commission'] = 0;
                 if (self::findAttribute($transaction, 'UID') == null) {
                     $obj['custom_id'] = self::findAttribute($transaction, 'UID');
                 }
                 if (self::findAttribute($transaction, 'Status') == 'Validated') {
                     $obj['status'] = Oara_Utilities::STATUS_CONFIRMED;
                     if (self::findAttribute($transaction, 'TransactionValue') != null) {
                         $obj['amount'] = self::findAttribute($transaction, 'TransactionValue');
                     }
                     if (self::findAttribute($transaction, 'VR') != null) {
                         $obj['commission'] = self::findAttribute($transaction, 'VR');
                     }
                 } else {
                     if (self::findAttribute($transaction, 'Status') == 'Pending') {
                         $obj['status'] = Oara_Utilities::STATUS_PENDING;
                         if (self::findAttribute($transaction, 'NVR') != null) {
                             $obj['commission'] = self::findAttribute($transaction, 'NVR');
                         }
                     } else {
                         if (self::findAttribute($transaction, 'Status') == 'Rejected') {
                             $obj['status'] = Oara_Utilities::STATUS_DECLINED;
                             if (self::findAttribute($transaction, 'TransactionValue') != null) {
                                 $obj['amount'] = self::findAttribute($transaction, 'TransactionValue');
                             }
                             if (self::findAttribute($transaction, 'VR') != null) {
                                 $obj['commission'] = self::findAttribute($transaction, 'VR');
                             }
                         } else {
                             throw new Exception('Problem with the status');
                         }
                     }
                 }
                 $transactions[] = $obj;
             }
         }
     }
     return $transactions;
 }
Example #24
0
 /**
  * The affjet cli , read the arguments and build the report requested
  * @param array arguments, Map of the cli arguments
  * * @param network, the affiliate network
  * @return none
  */
 public static function affjetCli($arguments, $network)
 {
     //Start date, the first two months ago
     $startDate = new Zend_Date($arguments['s'], "dd/MM/yyyy");
     $startDate->setHour(00);
     $startDate->setMinute(00);
     $startDate->setSecond(00);
     //Yesterday, some networks don't give us the data for the same day, then is the safer way to have our data
     $endDate = new Zend_Date($arguments['e'], "dd/MM/yyyy");
     $endDate->setHour(23);
     $endDate->setMinute(59);
     $endDate->setSecond(59);
     //are we connected?
     fwrite(STDERR, "\nAccessing to your account \n\n");
     if ($network->checkConnection()) {
         fwrite(STDERR, "Connected successfully \n\n");
         if (!isset($arguments['t']) || $arguments['t'] == 'payment') {
             fwrite(STDERR, "Getting payments, please wait \n\n");
             //Get all the payments for this network.
             $paymentsList = $network->getPaymentHistory();
             fwrite(STDERR, "Number of payments: " . count($paymentsList) . "\n\n");
             fwrite(STDERR, "------------------------------------------------------------------------\n");
             fwrite(STDERR, "ID\t\t\tDATE\t\t\t\t\tVALUE\n");
             fwrite(STDERR, "------------------------------------------------------------------------\n");
             foreach ($paymentsList as $payment) {
                 $paymentDate = new Zend_Date($payment['date'], "yyyy-MM-dd HH:mm:ss");
                 if ($paymentDate->compare($startDate) >= 0 && $paymentDate->compare($endDate) <= 0) {
                     fwrite(STDERR, $payment['pid'] . "\t\t\t" . $payment['date'] . "\t\t\t" . $payment['value'] . " \n");
                 }
             }
             if (isset($arguments['t']) && $arguments['t'] == 'payment') {
                 return null;
             }
         }
         //Get all the Merhcants
         fwrite(STDERR, "\nGetting merchants, please wait \n\n");
         $merchantList = $network->getMerchantList(array());
         if (!isset($arguments['t']) || $arguments['t'] == 'merchant') {
             fwrite(STDERR, "Number of merchants: " . count($merchantList) . "\n\n");
             fwrite(STDERR, "--------------------------------------------------\n");
             fwrite(STDERR, "ID\t\t\tNAME\n");
             fwrite(STDERR, "--------------------------------------------------\n");
             foreach ($merchantList as $merchant) {
                 fwrite(STDERR, $merchant['cid'] . "\t\t\t" . $merchant['name'] . " \n");
             }
             if (isset($arguments['t']) && $arguments['t'] == 'merchant') {
                 return null;
             }
         }
         // Building the array of merchant Id we want to retrieve data from.
         $merchantIdList = array();
         foreach ($merchantList as $merchant) {
             $merchantIdList[] = $merchant['cid'];
         }
         //If we have joined any merchant
         if (!empty($merchantIdList)) {
             $merchantMap = array();
             foreach ($merchantList as $merchant) {
                 $merchantMap[$merchant['name']] = $merchant['cid'];
             }
             //Split the dates monthly, Most of the network don't allow us to retrieve more than a month data
             $dateArray = Oara_Utilities::monthsOfDifference($startDate, $endDate);
             for ($i = 0; $i < count($dateArray); $i++) {
                 // Calculating the start and end date for the current month
                 $monthStartDate = clone $dateArray[$i];
                 $monthEndDate = null;
                 if ($i != count($dateArray) - 1) {
                     $monthEndDate = clone $dateArray[$i];
                     $monthEndDate->setDay(1);
                     $monthEndDate->addMonth(1);
                     $monthEndDate->subDay(1);
                 } else {
                     $monthEndDate = $endDate;
                 }
                 $monthEndDate->setHour(23);
                 $monthEndDate->setMinute(59);
                 $monthEndDate->setSecond(59);
                 fwrite(STDERR, "\n*Importing data from " . $monthStartDate->toString("dd-MM-yyyy HH:mm:ss") . " to " . $monthEndDate->toString("dd-MM-yyyy HH:mm:ss") . "\n\n");
                 fwrite(STDERR, "Getting transactions, please wait \n\n");
                 $transactionList = $network->getTransactionList($merchantIdList, $monthStartDate, $monthEndDate, $merchantMap);
                 if (!isset($arguments['t']) || $arguments['t'] == 'transaction') {
                     fwrite(STDERR, "Number of transactions: " . count($transactionList) . "\n\n");
                     $totalAmount = 0;
                     $totalCommission = 0;
                     foreach ($transactionList as $transaction) {
                         $totalAmount += $transaction['amount'];
                         $totalCommission += $transaction['commission'];
                     }
                     fwrite(STDERR, "--------------------------------------------------\n");
                     fwrite(STDERR, "TOTAL AMOUNT\t\t{$totalAmount}\n");
                     fwrite(STDERR, "TOTAL COMMISSION\t{$totalCommission}\n");
                     fwrite(STDERR, "--------------------------------------------------\n\n");
                 }
             }
         }
         fwrite(STDERR, "Import finished \n\n");
     } else {
         fwrite(STDERR, "Error connecting to the network, check credentials \n\n");
     }
 }
Example #25
0
 /**
  * Validate rule data
  *
  * @param Varien_Object $object
  *
  * @return bool|array - return true if validation passed successfully. Array with errors description otherwise
  */
 public function validateData(Varien_Object $object)
 {
     $result = array();
     $fromDate = $toDate = null;
     if ($object->hasFromDate() && $object->hasToDate()) {
         $fromDate = $object->getFromDate();
         $toDate = $object->getToDate();
     }
     if ($fromDate && $toDate) {
         $fromDate = new Zend_Date($fromDate, Varien_Date::DATE_INTERNAL_FORMAT);
         $toDate = new Zend_Date($toDate, Varien_Date::DATE_INTERNAL_FORMAT);
         if ($fromDate->compare($toDate) === 1) {
             $result[] = Mage::helper('rule')->__('End Date must be greater than Start Date.');
         }
     }
     if ($object->hasWebsiteIds()) {
         $websiteIds = $object->getWebsiteIds();
         if (empty($websiteIds)) {
             $result[] = Mage::helper('rule')->__('Websites must be specified.');
         }
     }
     if ($object->hasCustomerGroupIds()) {
         $customerGroupIds = $object->getCustomerGroupIds();
         if (empty($customerGroupIds)) {
             $result[] = Mage::helper('rule')->__('Customer Groups must be specified.');
         }
     }
     return !empty($result) ? $result : true;
 }
Example #26
0
 /**
  * test looseBehaviour
  */
 public function testLoose()
 {
     $date = new Zend_Date(0, 'de_DE');
     try {
         $date->set(null, Zend_Date::YEAR);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     $date->set(10, 'de_DE');
     $this->assertEquals(10, $date->getTimestamp());
     try {
         $date->add(null, Zend_Date::YEAR);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     $date->add(10, 'de_DE');
     $this->assertEquals(20, $date->getTimestamp());
     try {
         $date->sub(null, Zend_Date::YEAR);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     $date->sub(10, 'de_DE');
     $this->assertEquals(10, $date->getTimestamp());
     try {
         $date->compare(null, Zend_Date::YEAR);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->equals(null, Zend_Date::YEAR);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->isEarlier(null, Zend_Date::YEAR);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->isLater(null, Zend_Date::YEAR);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->setTime(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->addTime(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->subTime(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->compareTime(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->setDate(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->addDate(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->subDate(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->compareDate(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->setIso(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->addIso(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->subIso(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->compareIso(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->setArpa(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->addArpa(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->subArpa(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->compareArpa(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->setYear(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->addYear(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->subYear(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->compareYear(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->setMonth(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->addMonth(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->subMonth(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->compareMonth(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->setDay(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->addDay(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->subDay(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->compareDay(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->setWeekday(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->addWeekday(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->subWeekday(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->compareWeekday(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->setDayOfYear(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->addDayOfYear(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->subDayOfYear(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->compareDayOfYear(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->setHour(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->addHour(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->subHour(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->compareHour(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->setMinute(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->addMinute(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->subMinute(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->compareMinute(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->setSecond(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->addSecond(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->subSecond(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->compareSecond(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->setWeek(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->addWeek(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->subWeek(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     try {
         $date->compareWeek(null);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
 }
Example #27
0
 /**
  * (non-PHPdoc)
  * @see library/Oara/Network/Oara_Network_Base#getOverviewList($merchantId, $dStartDate, $dEndDate)
  */
 public function getOverviewList($transactionList = null, $merchantList = null, Zend_Date $dStartDate = null, Zend_Date $dEndDate = null)
 {
     $totalOverviews = array();
     $transactionArray = Oara_Utilities::transactionMapPerDay($transactionList);
     $mothOverviewUrls = array();
     $valuesFormExport = Oara_Utilities::cloneArray($this->_exportOverviewParameters);
     if ($this->_dateFormat == 'dd/MM/yy') {
         $valuesFormExport[] = new Oara_Curl_Parameter('startDate', $dStartDate->toString('dd/MM/yy'));
         $valuesFormExport[] = new Oara_Curl_Parameter('endDate', $dEndDate->toString('dd/MM/yy'));
     } else {
         if ($this->_dateFormat == 'M/d/yy') {
             $valuesFormExport[] = new Oara_Curl_Parameter('startDate', $dStartDate->toString('M/d/yy'));
             $valuesFormExport[] = new Oara_Curl_Parameter('endDate', $dEndDate->toString('M/d/yy'));
         } else {
             if ($this->_dateFormat == 'd/MM/yy') {
                 $valuesFormExport[] = new Oara_Curl_Parameter('startDate', $dStartDate->toString('d/MM/yy'));
                 $valuesFormExport[] = new Oara_Curl_Parameter('endDate', $dEndDate->toString('d/MM/yy'));
             } else {
                 if ($this->_dateFormat == 'tt.MM.uu') {
                     $valuesFormExport[] = new Oara_Curl_Parameter('startDate', $dStartDate->toString('dd.MM.yy'));
                     $valuesFormExport[] = new Oara_Curl_Parameter('endDate', $dEndDate->toString('dd.MM.yy'));
                 } else {
                     throw new Exception("\n Date Format not supported " . $this->_dateFormat . "\n");
                 }
             }
         }
     }
     $urls = array();
     $urls[] = new Oara_Curl_Request('http://www.tradedoubler.com/pan/aReport3Internal.action?', $valuesFormExport);
     $exportReport = $this->_client->get($urls);
     $exportReport[0] = self::checkReportError($exportReport[0], $urls[0]);
     $exportData = str_getcsv($exportReport[0], "\r\n");
     $num = count($exportData);
     if ($num > 3) {
         $dateArray = Oara_Utilities::daysOfDifference($dStartDate, $dEndDate);
         $dateArraySize = sizeof($dateArray);
         for ($i = 0; $i < $dateArraySize; $i++) {
             $valuesFormExport = Oara_Utilities::cloneArray($this->_exportOverviewParameters);
             if ($this->_dateFormat == 'dd/MM/yy') {
                 $valuesFormExport[] = new Oara_Curl_Parameter('startDate', $dateArray[$i]->toString('dd/MM/yy'));
                 $valuesFormExport[] = new Oara_Curl_Parameter('endDate', $dateArray[$i]->toString('dd/MM/yy'));
             } else {
                 if ($this->_dateFormat == 'M/d/yy') {
                     $valuesFormExport[] = new Oara_Curl_Parameter('startDate', $dateArray[$i]->toString('M/d/yy'));
                     $valuesFormExport[] = new Oara_Curl_Parameter('endDate', $dateArray[$i]->toString('M/d/yy'));
                 } else {
                     if ($this->_dateFormat == 'd/MM/yy') {
                         $valuesFormExport[] = new Oara_Curl_Parameter('startDate', $dateArray[$i]->toString('d/MM/yy'));
                         $valuesFormExport[] = new Oara_Curl_Parameter('endDate', $dateArray[$i]->toString('d/MM/yy'));
                     } else {
                         if ($this->_dateFormat == 'tt.MM.uu') {
                             $valuesFormExport[] = new Oara_Curl_Parameter('startDate', $dateArray[$i]->toString('dd.MM.yy'));
                             $valuesFormExport[] = new Oara_Curl_Parameter('endDate', $dateArray[$i]->toString('dd.MM.yy'));
                         } else {
                             throw new Exception("\n Date Format not supported " . $this->_dateFormat . "\n");
                         }
                     }
                 }
             }
             $mothOverviewUrls[] = new Oara_Curl_Request('http://www.tradedoubler.com/pan/aReport3Internal.action?', $valuesFormExport);
         }
     }
     $exportReport = $this->_client->get($mothOverviewUrls);
     $exportReportNumber = count($exportReport);
     for ($i = 0; $i < $exportReportNumber; $i++) {
         $exportReport[$i] = self::checkReportError($exportReport[$i], $mothOverviewUrls[$i]);
         $exportData = str_getcsv($exportReport[$i], "\r\n");
         $num = count($exportData);
         for ($j = 2; $j < $num - 1; $j++) {
             $overviewExportArray = str_getcsv($exportData[$j], ";");
             $parameter = $mothOverviewUrls[$i]->getParameter(39);
             $overviewDate = $parameter->getValue();
             if ($this->_dateFormat == 'dd/MM/yy') {
                 $overviewDate = new Zend_Date($overviewDate, "dd/MM/yy");
             } else {
                 if ($this->_dateFormat == 'M/d/yy') {
                     $overviewDate = new Zend_Date($overviewDate, "M/d/yy");
                 } else {
                     if ($this->_dateFormat == 'd/MM/yy') {
                         $overviewDate = new Zend_Date($overviewDate, "d/MM/yy");
                     } else {
                         if ($this->_dateFormat == 'tt.MM.uu') {
                             $overviewDate = new Zend_Date($overviewDate, "dd.MM.yy");
                         } else {
                             throw new Exception("\n Date Format not supported " . $this->_dateFormat . "\n");
                         }
                     }
                 }
             }
             if (!isset($overviewExportArray[2])) {
                 throw new Exception('Problem getting overview\\n\\n');
             }
             if ($overviewDate->compare($dStartDate) >= 0 && $overviewDate->compare($dEndDate) <= 0 && isset($overviewExportArray[2]) && in_array((int) $overviewExportArray[2], $merchantList)) {
                 $overview = array();
                 $overview['merchantId'] = (int) $overviewExportArray[2];
                 $overview['date'] = $overviewDate->toString("yyyy-MM-dd HH:mm:ss");
                 $overview['click_number'] = (int) $overviewExportArray[4];
                 $overview['impression_number'] = (int) $overviewExportArray[3];
                 $overview['transaction_number'] = 0;
                 $overview['transaction_confirmed_value'] = 0;
                 $overview['transaction_confirmed_commission'] = 0;
                 $overview['transaction_pending_value'] = 0;
                 $overview['transaction_pending_commission'] = 0;
                 $overview['transaction_declined_value'] = 0;
                 $overview['transaction_declined_commission'] = 0;
                 $transactionDateArray = Oara_Utilities::getDayFromArray($overview['merchantId'], $transactionArray, $overviewDate);
                 foreach ($transactionDateArray as $transaction) {
                     $overview['transaction_number']++;
                     if ($transaction['status'] == Oara_Utilities::STATUS_CONFIRMED) {
                         $overview['transaction_confirmed_value'] += $transaction['amount'];
                         $overview['transaction_confirmed_commission'] += $transaction['commission'];
                     } else {
                         if ($transaction['status'] == Oara_Utilities::STATUS_PENDING) {
                             $overview['transaction_pending_value'] += $transaction['amount'];
                             $overview['transaction_pending_commission'] += $transaction['commission'];
                         } else {
                             if ($transaction['status'] == Oara_Utilities::STATUS_DECLINED) {
                                 $overview['transaction_declined_value'] += $transaction['amount'];
                                 $overview['transaction_declined_commission'] += $transaction['commission'];
                             }
                         }
                     }
                 }
                 if (Oara_Utilities::checkRegister($overview)) {
                     $totalOverviews[] = $overview;
                 }
             }
         }
     }
     return $totalOverviews;
 }
Example #28
0
 /**
  * Generates events for purchasing to subscription
  * @return AW_Sarp_Model_Subscription
  */
 protected function _generateSubscriptionEvents()
 {
     // Delete all sequencies
     if ($this->_origData['date_start'] != $this->_data['date_start'] || $this->_origData['period_type'] != $this->_data['period_type'] || !$this->getIsNew() && $this->getIsReactivated()) {
         Mage::getResourceModel('sarp/sequence')->deleteBySubscriptionId($this->getId());
         $Date = new Zend_Date(strtotime($this->getDateStart()), Zend_Date::TIMESTAMP);
         Zend_Date::setOptions(array('extend_month' => true));
         // Fix Zend_Date::addMonth unexpected result
         switch ($this->getPeriod()->getPeriodType()) {
             case 'day':
                 $method = 'addDayOfYear';
                 break;
             case 'month':
                 $method = 'addMonth';
                 break;
             case 'week':
                 $method = 'addWeek';
                 break;
             case 'year':
                 $method = 'addYear';
                 break;
             default:
                 throw new Mage_Core_Exception("Unknown subscription period type for #" . $this->getPeriod()->getId());
         }
         switch ($this->getPeriod()->getExpireType()) {
             case 'day':
                 $method_expire = 'addDayOfYear';
                 break;
             case 'month':
                 $method_expire = 'addMonth';
                 break;
             case 'week':
                 $method_expire = 'addWeek';
                 break;
             case 'year':
                 $method_expire = 'addYear';
                 break;
             default:
                 throw new Mage_Core_Exception("Unknown subscription expire period type for #" . $this->getPeriod()->getId());
         }
         $ExpireDate = clone $Date;
         $expireMultiplier = $this->getPeriod()->getExpireValue();
         if (!$expireMultiplier) {
             // 0 means infinite expiration date
             $expireMultiplier = 3;
             // 0 means expire_method = method
             $method_expire = $method;
             $_Date = $this->getLastPaidDate();
             if (is_object($_Date)) {
                 $ExpireDate = clone $_Date;
             }
         }
         $ExpireDate = call_user_func(array($ExpireDate, $method_expire), $expireMultiplier);
         // Substract delivery offset. This is
         $Date->addDayOfYear(0 - $this->getPeriod()->getPaymentOffset());
         $ExpireDate->addDayOfYear(0 - $this->getPeriod()->getPaymentOffset());
         try {
             $this->getPeriod()->validate();
             while ($Date->compare($ExpireDate) == -1) {
                 $Date = call_user_func(array($Date, $method), $this->getPeriod()->getPeriodValue());
                 Mage::getModel('sarp/sequence')->setSubscriptionId($this->getId())->setDate($Date->toString(self::DB_DATE_FORMAT))->save();
             }
         } catch (AW_Sarp_Exception $e) {
             $this->log('Unable create sequences to subscription #' . $this->getId(), AW_Core_Model_Logger::LOG_SEVERITY_WARNING, 'Unable create sequences to subscription. Message: "' . $e->getMessage() . '"');
         }
     }
     return $this;
 }
 /**
  * Atualiza a situação das guias conforme uma coleção de numpre e numpar informados
  *
  * @param array $aGuias
  * @return array
  * @throws Exception
  */
 public static function atualizaSituacaoGuias(array $aGuias)
 {
     $aResultado = array();
     // Agrupa os Numpres e Numpars do Contribuinte
     foreach ($aGuias as $oGuia) {
         $sChaveNumpreNumpar = "{$oGuia->getNumpre()}/{$oGuia->getMesComp()}";
         $aDadosSituacao[$sChaveNumpreNumpar]['iNumpre'] = $oGuia->getNumpre();
         $aDadosSituacao[$sChaveNumpreNumpar]['iNumpar'] = $oGuia->getMesComp();
     }
     if (isset($aDadosSituacao)) {
         $aSitucao = Contribuinte_Model_GuiaEcidade::pesquisaSituacaoGuias($aDadosSituacao);
         // Altera a situacao da guia conforme as situacoes encontradas na pesquisa
         foreach ($aGuias as $oGuia) {
             $sChaveNumpreNumpar = "{$oGuia->getNumpre()}/{$oGuia->getMesComp()}";
             $sSituacao = $aSitucao[$sChaveNumpreNumpar];
             if (!isset(self::$WS_NFSE_SITUACAO[$sSituacao])) {
                 throw new Exception("Situação de débito {$sSituacao} não mapeada para o modelo Guia");
             }
             $oGuia->setSituacao(self::$WS_NFSE_SITUACAO[$sSituacao]);
             $oComparaData = new Zend_Date("01-{$oGuia->getMesComp()}-{$oGuia->getAnoComp()}");
             $oComparaData->add(1, 'MM');
             // Verifica se a guia de débito foi cancelada no E-cidade remove o vinculo da guia, caso seja NFSE e não
             // estiver um mês retroativo apenas exibe como "Quitada Manualmente"
             if ($oComparaData->compare(new Zend_Date(), 'MM/yyyy') == 0 && $oGuia->getTipoDocumentoOrigem() == self::$DOCUMENTO_ORIGEM_NFSE || $oGuia->getTipoDocumentoOrigem() == self::$DOCUMENTO_ORIGEM_DMS) {
                 if (!empty($sSituacao) && $sSituacao == 'CANCELADO') {
                     $aAtributos = array('set' => array('guia' => NULL), 'where' => array('guia' => $oGuia->getEntity()));
                     Contribuinte_Model_DesifContaGuia::update($aAtributos['set'], $aAtributos['where']);
                     Contribuinte_Model_Guia::removeGuiaCancelada($oGuia);
                 } else {
                     $aResultado[] = $oGuia;
                 }
             } else {
                 $aResultado[] = $oGuia;
             }
         }
     }
     return $aResultado;
 }
Example #30
0
 /**
  * Test for compare
  */
 public function testCompare()
 {
     $locale = new Zend_Locale('de_AT');
     $date = new Zend_Date(0, null, $locale);
     $d2 = new Zend_Date(1010101010, null, $locale);
     //03.01.2002 15:36:50
     $retour = $date->set(1234567890);
     //13.02.2009 15:31:30
     $this->assertSame((string) $retour, '1234567890');
     $this->assertSame($date->compare(1234567890), 0);
     $this->assertSame($date->compare(1234567800), 1);
     $this->assertSame($date->compare(1234567899), -1);
     $date->set($d2);
     //03.01.2002 15:36:50
     $this->assertSame($date->compare(3, Zend_Date::DAY), 1);
     $this->assertSame($date->compare(4, Zend_Date::DAY), 0);
     $this->assertSame($date->compare(5, Zend_Date::DAY), -1);
     $this->assertSame($date->compare('Mon', Zend_Date::WEEKDAY_SHORT), 1);
     $this->assertSame($date->compare('Sam', Zend_Date::WEEKDAY_SHORT), -1);
     $date->set($d2);
     //03.01.2002 15:36:50
     $this->assertSame($date->compare(0, Zend_Date::MILLISECOND), 0);
 }