예제 #1
0
 public function save(Default_Model_Pastebin $pastebin)
 {
     $shortId = $pastebin->getShortId();
     if (empty($shortId)) {
         $shortId = $this->_getShortId();
         $pastebin->setShortId($shortId);
     }
     $name = $pastebin->getName();
     $expiresTime = $pastebin->getExpires();
     $expires = null;
     if ($expiresTime != 'never') {
         $expires = new Zend_Date();
         if ($expiresTime == 'hour') {
             $expires->addHour(1);
         }
         if ($expiresTime == 'day') {
             $expires->addDay(1);
         }
         if ($expiresTime == 'week') {
             $expires->addWeek(1);
         }
         if ($expiresTime == 'month') {
             $expires->addMonth(1);
         }
         $expires = $expires->get('yyyy-MM-dd HH:mm:ss');
     }
     $data = array('short_id' => $shortId, 'name' => !empty($name) ? $name : 'Anonymous', 'code' => $pastebin->getCode(), 'language' => $pastebin->getLanguage(), 'expires' => $expires, 'ip_address' => $_SERVER['REMOTE_ADDR'], 'created' => date('Y-m-d H:i:s'));
     if (null === ($id = $pastebin->getId())) {
         unset($data['id']);
         $this->getDbTable()->insert($data);
     } else {
         $this->getDbTable()->update($data, array('id = ?' => $id));
     }
     return $shortId;
 }
예제 #2
0
 /**
  * Apply filter by card active state (based on last usage date)
  *
  * @return CLS_Paypal_Model_Resource_Customerstored_Collection
  */
 public function filterByActiveState()
 {
     $now = new Zend_Date(null);
     $now->addMonth(0 - CLS_Paypal_Model_Paypal_Config::STORED_CARD_TTL_MONTHS);
     $this->getSelect()->where('date >= ?', Varien_Date::formatDate($now, false));
     return $this;
 }
예제 #3
0
 public function testGetEntryIsEqualToPutEntry()
 {
     $this->_entryMapper->postEntry($this->_testEntry);
     $now = new Zend_Date();
     $now->addMonth(1);
     $entry = $this->_entryMapper->getEntry($this->_testEntry->getId());
     $entry->setTitle('Updated Test Entry')->setContent('Updated Test entry with' . PHP_EOL . 'multiple lines.')->setSummary('Updated Test entry summary.')->setUpdated($now);
     $this->_entryMapper->putEntry($entry);
     $this->assertTrue($entry->isEqualTo($this->_entryMapper->getEntry($entry->getId())));
 }
 public function saveAction()
 {
     $this->_isAllowed();
     if ($data = $this->getRequest()->getPost()) {
         $dateFormatIso = Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT);
         $localeCode = Mage::app()->getLocale()->getLocaleCode();
         if (empty($data['date_from'])) {
             $from = new Zend_Date();
         } else {
             $from = new Zend_Date($data['date_from'], $dateFormatIso, $localeCode);
         }
         $data['date_from'] = $from->setTimezone('utc')->toString(Varien_Date::DATE_INTERNAL_FORMAT);
         if (empty($data['date_to'])) {
             $to = new Zend_Date();
             $to->addMonth(1);
         } else {
             $to = new Zend_Date($data['date_to'], $dateFormatIso, $localeCode);
         }
         $data['date_to'] = $to->setTimezone('utc')->toString(Varien_Date::DATE_INTERNAL_FORMAT);
         if (!isset($data['store_view'])) {
             $data['store_view'][] = '0';
         }
         if ($data['store_view'][0] == '0') {
             $stores = Mage::getSingleton('adminhtml/system_store')->getStoreValuesForForm(false, true);
             foreach ($stores as $store) {
                 if (is_array($store['value'])) {
                     foreach ($store['value'] as $value) {
                         $data['store_view'][] = $value['value'];
                     }
                 }
             }
         }
         $model = Mage::getModel('promotional/promotional');
         $model->setData($data)->setId($this->getRequest()->getParam('id'));
         try {
             $model->save();
             Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('promotional')->__('Popup was successfully saved'));
             Mage::getSingleton('adminhtml/session')->setFormData(false);
             if ($this->getRequest()->getParam('back')) {
                 $this->_redirect('*/*/edit', array('id' => $model->getId()));
                 return;
             }
             $this->_redirect('*/*/');
             return;
         } catch (Exception $e) {
             Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
             Mage::getSingleton('adminhtml/session')->setFormData($data);
             $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
             return;
         }
     }
     Mage::getSingleton('adminhtml/session')->addError(Mage::helper('promotional')->__('Unable to find Popup to save'));
     $this->_redirect('*/*/');
 }
 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;
 }
 public function monthAction()
 {
     // param handling
     $year = $this->_getParam('year');
     $month = $this->_getParam('month');
     if (!$year or !$month) {
         throw new Exception('');
     }
     // start & stop date
     $startDate = new Zend_Date($year . '-' . $month . '-01', 'yyyy-M-dd');
     $stopDate = new Zend_Date($startDate);
     $stopDate->addMonth(1)->addDay(-1);
     // spacings (start & end)
     $startSpace = $startDate->get(Zend_Date::WEEKDAY_8601) - 1;
     $stopSpace = 7 - $stopDate->get(Zend_Date::WEEKDAY_8601);
     // arrays
     $calendar = array();
     $week = array();
     for ($startSpace; $startSpace >= 1; $startSpace--) {
         $spaceDate = new Zend_Date($startDate);
         $spaceDate->addDay(-$startSpace);
         $day = array('date' => $spaceDate);
         $week[] = $day;
     }
     for ($currentDay = 1; $currentDay <= $stopDate->get('d'); $currentDay++) {
         $currentDate = new Zend_Date($startDate);
         $currentDate->setDay($currentDay);
         $day = array('date' => $currentDate);
         $week[] = $day;
         if (count($week) / 7 == 1) {
             $calendar[] = array('info' => $currentDate, 'columns' => $week);
             $week = array();
         }
     }
     for ($stopSpace; $stopSpace >= 1; $stopSpace--) {
         $spaceDate = new Zend_Date($stopDate);
         $spaceDate->addDay(-$stopSpace);
         $day = array('date' => $spaceDate);
         $week[] = $day;
         if (count($week) / 7 == 1) {
             $calendar[] = array('info' => $currentDate, 'columns' => $week);
             $week = array();
         }
     }
     // view
     $this->view->rows = $calendar;
 }
예제 #7
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;
 }
예제 #8
0
 /**
  * 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;
 }
예제 #9
0
 /**
  * Overrides standard getIntervals
  * @return array
  */
 public function getIntervals()
 {
     if (!$this->_intervals) {
         $this->_intervals = array();
         if (!$this->_from && !$this->_to) {
             return $this->_intervals;
         }
         $t = array();
         $diff = 0;
         if ($this->_period == 'week') {
             $firstWeekDay = Mage::getStoreConfig('general/locale/firstday');
             $dateStart = new Zend_Date($this->_from);
             $curWeekDay = $dateStart->toString('e');
             if ($curWeekDay > $firstWeekDay) {
                 $firstWeekDay += 7;
             }
             $diff = abs($curWeekDay - $firstWeekDay);
         }
         if ($this->_period == 'week' && $diff > 0) {
             $dateStart = new Zend_Date($this->_from);
             $dateStart2 = new Zend_Date($this->_from);
             $dateStart2->addDay($diff);
             $t['title'] = $dateStart->toString(Mage::app()->getLocale()->getDateFormat());
             $t['start'] = $dateStart->toString('yyyy-MM-dd 00:00:00');
             $dateStart->addDay($diff)->subDay(1);
             $t['title'] .= ' - ' . $dateStart->toString(Mage::app()->getLocale()->getDateFormat());
             $t['end'] = $dateStart->toString('yyyy-MM-dd 23:59:59');
             $dateStart->addDay(1);
             if (isset($t['title'])) {
                 $this->_intervals[$t['title']] = $t;
             }
             $dateStart2 = new Zend_Date($this->_from);
             $dateEnd = new Zend_Date($this->_to);
         } else {
             $dateStart = new Zend_Date($this->_from);
             $dateStart2 = new Zend_Date($this->_from);
             $dateEnd = new Zend_Date($this->_to);
         }
         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;
                 default:
                     Mage::throwException("Report tried to get intervals without a period.");
             }
             if (isset($t['title'])) {
                 $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'], 'yyyy-MM-dd 00:00:00');
                     $t['title'] = $date->toString(Mage::app()->getLocale()->getDateFormat());
                     unset($date);
                     $date = new Zend_Date($t['end'], 'yyyy-MM-dd 23:59:59');
                     $t['title'] .= ' - ' . $date->toString(Mage::app()->getLocale()->getDateFormat());
                     $this->_intervals[$t['title']] = $t;
                 }
             }
         }
         $this->processIntervals();
     }
     return $this->_intervals;
 }
예제 #10
0
파일: DateTest.php 프로젝트: jsnshrmn/Suma
 /**
  * Test for False Month Addition
  */
 public function testGmtOffsetValues()
 {
     date_default_timezone_set('Pacific/Auckland');
     $time = time();
     $date = new Zend_Date($time);
     $stamp = $date->getGmtOffset();
     $localtime = localtime($time, true);
     $offset = mktime($localtime['tm_hour'], $localtime['tm_min'], $localtime['tm_sec'], $localtime['tm_mon'] + 1, $localtime['tm_mday'], $localtime['tm_year'] + 1900) - gmmktime($localtime['tm_hour'], $localtime['tm_min'], $localtime['tm_sec'], $localtime['tm_mon'] + 1, $localtime['tm_mday'], $localtime['tm_year'] + 1900);
     $this->assertEquals($stamp, $offset);
     $date->addMonth(6);
     $stamp = $date->getGmtOffset();
     $localtime = localtime($time, true);
     $offset = mktime($localtime['tm_hour'], $localtime['tm_min'], $localtime['tm_sec'], $localtime['tm_mon'] + 7, $localtime['tm_mday'], $localtime['tm_year'] + 1900) - gmmktime($localtime['tm_hour'], $localtime['tm_min'], $localtime['tm_sec'], $localtime['tm_mon'] + 7, $localtime['tm_mday'], $localtime['tm_year'] + 1900);
     $this->assertEquals($stamp, $offset);
 }
예제 #11
0
 /**
  * Get interval for a month
  *
  * @param Zend_Date $dateStart
  * @param Zend_Date $dateEnd
  * @param bool $firstInterval
  * @return array
  */
 protected function _getMonthInterval(Zend_Date $dateStart, Zend_Date $dateEnd, $firstInterval)
 {
     $interval = array();
     $interval['period'] = $dateStart->toString('MM/yyyy');
     $interval['start'] = $firstInterval ? $dateStart->toString('yyyy-MM-dd 00:00:00') : $dateStart->toString('yyyy-MM-01 00:00:00');
     $lastInterval = $dateStart->compareMonth($dateEnd->getMonth()) == 0;
     $interval['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);
     }
     return $interval;
 }
예제 #12
0
 public function successAction()
 {
     try {
         //            $userWalletMapper = new Application_Model_UserWalletMapper();
         //            $userWallet = new Application_Model_UserWallet();
         //            $userPackagesMapper = new Application_Model_UserPackagesMapper();
         //            $userPackages = new Application_Model_UserPackages();
         $userTrackMapper = new Application_Model_UserTrackMapper();
         $userTrack = new Application_Model_UserTrack();
         $ordersMapper = new Application_Model_OrdersMapper();
         //            $packagesMapper = new Application_Model_PackagesMapper();
         $userTransactionsMapper = new Application_Model_UserTransactionsMapper();
         $userTransactions = new Application_Model_UserTransactions();
         $request = $this->getRequest();
         $status = $request->getParam("status");
         $fname = $request->getParam("firstname");
         $amount = $request->getParam("amount");
         $txnid = $request->getParam("txnid");
         $posted_hash = $request->getParam("hash");
         $product_info = $request->getParam("productinfo");
         $key = $request->getParam("key");
         $email = $request->getParam("email");
         $code = $request->getParam("bankcode");
         $salt = "dwf1Ltip";
         //test salt
         $salt = "GQs7yium";
         $retHashSeq = $salt . '|' . $status . '|||||||||||' . $email . '|' . $fname . '|' . $product_info . '|' . $amount . '|' . $txnid . '|' . $key;
         $hash = hash("sha512", $retHashSeq);
         $infos = explode("|", $product_info);
         $transaction_type = explode(":", $infos[0]);
         $transaction_type = $transaction_type[1];
         //echo $transaction_type;exit;
         $user_id = explode(":", $infos[1]);
         $user_id = $user_id[1];
         $id = explode(":", $infos[2]);
         $id = $id[1];
         $package_id = explode(":", $infos[3]);
         $package_id = $package_id[1];
         if ($user_id != 0) {
             $userTransactions->__set("trnx_user_id", $user_id);
             $userTransactions->__set("other_details", $transaction_type);
             $userTransactions->__set("gateway_transaction_id", $txnid);
             $userTransactions->__set("trnx_amount", $amount);
             $userTransactions->__set("trnx_method", $code);
             $userTransactions->__set("trnx_status", $status);
             $userTransactions->__set("trnx_order_id", $id);
             $userTransactionsMapper->addNewUserTransaction($userTransactions);
         }
         if ($hash != $posted_hash) {
             throw new Exception("Invalid Transaction");
         } else {
             $flag = TRUE;
             $this->view->flag = $flag;
             if ($transaction_type == "Package") {
                 //echo "in";
                 $package = $packagesMapper->getPackageById($package_id);
                 $number_clothes = $package->__get("no_of_clothes");
                 $number_pickups = $package->__get("no_of_pickups");
                 //echo $number_pickups;exit;
                 $validity = $package->__get("validity");
                 //echo $validity;exit;
                 $zend_date = new Zend_Date();
                 $date = $zend_date->addMonth($validity);
                 $new_date = $date->toString("dd-MM-yyyy");
                 $userTrack->__set("usertrack_user_id", $user_id);
                 $userTrack->__set("track_type", 'package');
                 $userTrack->__set("usertrack_package_id", $package_id);
                 $userTrack->__set("clothes_left", $number_clothes);
                 $userTrack->__set("clothes_availed", $number_clothes);
                 $userTrack->__set("pickups_left", $number_pickups);
                 $userTrack->__set("pickups_availed", $number_pickups);
                 $userTrack->__set("usertrack_start_date", date('Y-m-d'));
                 $userTrack->__set("usertrack_expiry_date", $new_date);
                 if ($userTrackMapper->addNewTrack(addNewTrack)) {
                     $this->view->hasMessage = true;
                     $this->view->messageType = "success";
                     $this->view->message = "Profile Updated successfully";
                 } else {
                     $this->view->hasMessage = true;
                     $this->view->messageType = "danger";
                     $this->view->message = "Error while updating";
                 }
             } elseif ($transaction_type == "Online") {
                 $order = $ordersMapper->getOrderById($id);
                 $order->__set("order_payment_status", "Paid");
                 $ordersMapper->updateOrder($order);
             }
             $this->_redirect('index/orderlist');
         }
     } catch (Exception $e) {
         $e->getMessage();
     }
 }
예제 #13
0
 /**
  * test looseBehaviour
  */
 public function testLoose()
 {
     $date = new Zend_Date(0, 'de');
     try {
         $date->set(null, Zend_Date::YEAR);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     $date->set(10, 'de');
     $this->assertEquals($date->getTimestamp(), 10);
     try {
         $date->add(null, Zend_Date::YEAR);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     $date->add(10, 'de');
     $this->assertEquals($date->getTimestamp(), 20);
     try {
         $date->sub(null, Zend_Date::YEAR);
         $this->fail();
     } catch (Zend_Date_Exception $e) {
         // success
     }
     $date->sub(10, 'de');
     $this->assertEquals($date->getTimestamp(), 10);
     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
     }
 }
예제 #14
0
 /**
  * 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;
 }
예제 #15
0
 /**
  * 
  * @param array $filters
  * @return array
  */
 public function chartSentDay(array $filters = array())
 {
     $date = new Zend_Date();
     // Set the date to search the current month
     $filters['date_ini'] = $date->setDay(1)->toString('yyyy-MM-dd');
     $filters['date_fin'] = $date->addMonth(1)->subDay(1)->toString('yyyy-MM-dd');
     // Search just the sending successfully
     $filters['status'] = 'S';
     $sent = $this->sentByDays($filters);
     // Search the erros with errors
     $filters['status'] = 'E';
     $errors = $this->sentByDays($filters);
     $months = array();
     foreach ($sent as $row) {
         $months[] = $row->day;
     }
     foreach ($errors as $row) {
         $months[] = $row->day;
     }
     $months = array_fill_keys(array_unique($months), array('errors' => 0, 'sent' => 0));
     foreach ($sent as $row) {
         $months[$row->day]['sent'] = $row->sent;
     }
     foreach ($errors as $row) {
         $months[$row->day]['errors'] = $row->sent;
     }
     $data = array('months' => array_keys($months), 'errors' => array(), 'sent' => array());
     foreach ($months as $row) {
         $data['errors'][] = (int) $row['errors'];
         $data['sent'][] = (int) $row['sent'];
     }
     return $data;
 }
예제 #16
0
$frontController = $application->getBootstrap()->getResource('FrontController');
$view = $application->getBootstrap()->getResource('View');
// init request
$request = new Zend_Controller_Request_Http();
$request->setControllerName('partner-usage');
$request->setActionName('export-csv');
$fromDate = new Zend_Date();
$fromDate->setHour(0);
$fromDate->setMinute(0);
$fromDate->setSecond(0);
$fromDate->setDay(1);
$fromDate->addMonth(-1);
$request->setParam('from_date', $fromDate->getTimestamp());
// beginning of last month
$toDate = new Zend_Date($fromDate);
$toDate->addMonth(1);
$toDate->addSecond(-1);
$request->setParam('to_date', $toDate->getTimestamp());
// end of last month
// init response
$response = new Zend_Controller_Response_Cli();
// dispatch
$frontController->getDispatcher()->dispatch($request, $response);
// send mail
$config = Zend_Registry::get('config');
$sentToArray = explode(',', $config->settings->monthlyUsageSendTo);
$mail = new Zend_Mail();
$mail->setSubject($view->translate('Monthly Report'));
$mail->setFrom($config->settings->monthlyUsageSendFrom);
$mail->setBodyText($view->translate('CSV file attached.'));
// the attachment
예제 #17
0
 /**
  * Creates a ending date
  * @param $year
  * @param $month
  */
 public function setEndDate($year, $month)
 {
     $endDate = new Zend_Date($year . '-' . $month . '-01', 'yyyy-M-d');
     $endDate->addMonth(1)->addDay(-1);
     $this->_endDate = $endDate;
 }
예제 #18
0
 /**
  * Check original order and return specific data (order ID, transaction ID)
  *
  * @return  array|null
  */
 protected function _getOriginalOrderData()
 {
     // Check original order
     /** @var $session Mage_Adminhtml_Model_Session_Quote */
     $session = Mage::getSingleton('adminhtml/session_quote');
     if (($originalOrderId = $session->getPreviousOrderId()) || ($originalOrderId = $session->getOrderId())) {
         // Get original order data
         /** @var $originalOrder Mage_Sales_Model_Order */
         $originalOrder = Mage::getModel('sales/order')->load($originalOrderId);
         if ($originalOrder->getId()) {
             $originalOrderPayment = $originalOrder->getPayment();
             /** @var $helper CLS_Paypal_Helper_Data */
             $helper = Mage::helper('cls_paypal');
             // Check payment method for compatibility
             if ($originalOrderPayment->getId() && $helper->isSupportedPaymentMethodFull($originalOrderPayment->getMethod()) && $helper->isValidParentPaymentMethod($this->_callerMethod->getCode(), $originalOrderPayment->getMethod())) {
                 // Select the last valid order's transaction
                 /** @var $transactionCollection Mage_Sales_Model_Resource_Order_Payment_Transaction_Collection */
                 $transactionCollection = Mage::getResourceModel('sales/order_payment_transaction_collection');
                 $pastDate = new Zend_Date(null);
                 $pastDate->addMonth(0 - CLS_Paypal_Model_Paypal_Config::STORED_CARD_TTL_MONTHS);
                 $transactionCollection->addOrderIdFilter($originalOrder->getId())->addPaymentIdFilter($originalOrderPayment->getId())->addAttributeToFilter('main_table.created_at', array('gt' => Mage::getModel('core/date')->gmtDate(null, $pastDate->toValue())))->setOrder('main_table.created_at', Varien_Data_Collection::SORT_ORDER_DESC);
                 $transaction = false;
                 foreach ($transactionCollection as $trans) {
                     if ($trans->getTxnType() !== Mage_Sales_Model_Order_Payment_Transaction::TYPE_REFUND && $trans->getTxnType() !== Mage_Sales_Model_Order_Payment_Transaction::TYPE_VOID) {
                         $transaction = $trans;
                         break;
                     }
                 }
                 if ($transaction && !Mage::helper('cls_paypal')->transactionIsVoided($transaction)) {
                     return array('order_id' => $originalOrderId, 'transaction_id' => $transaction->getTxnId());
                 }
             }
         }
     }
     return null;
 }