/** * (non-PHPdoc) * @see library/Oara/Network/Oara_Network_Publisher_Interface#getTransactionList($aMerchantIds, $dStartDate, $dEndDate, $sTransactionStatus) */ public function getTransactionList($merchantList = null, Zend_Date $dStartDate = null, Zend_Date $dEndDate = null, $merchantMap = null) { $totalTransactions = array(); $urls = array(); $exportParams = array(new Oara_Curl_Parameter('agentcode', $this->_credentials['user']), new Oara_Curl_Parameter('pword', $this->_credentials['password']), new Oara_Curl_Parameter('fromdate', $dStartDate->toString("dd-MM-yyyy")), new Oara_Curl_Parameter('todate', $dEndDate->toString("dd-MM-yyyy")), new Oara_Curl_Parameter('rqtype', "report")); $urls[] = new Oara_Curl_Request('https://www.parkandgo.co.uk/agents/', $exportParams); $exportReport = $this->_client->post($urls); $today = new Zend_Date(); $today->setHour(0); $today->setMinute(0); $exportData = str_getcsv($exportReport[0], "\n"); $num = count($exportData); for ($i = 1; $i < $num; $i++) { $transactionExportArray = str_getcsv($exportData[$i], ","); $arrivalDate = new Zend_Date($transactionExportArray[3], 'yyyy-MM-dd 00:00:00', 'en'); $transaction = array(); $transaction['merchantId'] = 1; $transaction['unique_id'] = $transactionExportArray[0]; $transactionDate = new Zend_Date($transactionExportArray[2], 'yyyy-MM-dd 00:00:00', 'en'); $transaction['date'] = $transactionDate->toString("yyyy-MM-dd HH:mm:ss"); unset($transactionDate); $transaction['status'] = Oara_Utilities::STATUS_PENDING; if ($today > $arrivalDate) { $transaction['status'] = Oara_Utilities::STATUS_CONFIRMED; } $transaction['amount'] = Oara_Utilities::parseDouble($transactionExportArray[6]); $transaction['commission'] = Oara_Utilities::parseDouble($transactionExportArray[7]); $totalTransactions[] = $transaction; } return $totalTransactions; }
/** * (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; }
protected function _convertDate($date, $locale) { $dateObj = new Zend_Date(); //set begining of day $dateObj->setHour(00); $dateObj->setMinute(00); $dateObj->setSecond(00); //set date with applying timezone of store $dateObj->set($date, Zend_Date::DATE_SHORT, $locale); return $dateObj; }
/** * Prepare product and its configuration to be added to some products list. * Perform standard preparation process and then add Configurable specific options. * * @param Varien_Object $buyRequest * @param Mage_Catalog_Model_Product $product * @param string $processMode * @return array|string */ protected function _prepareProduct(Varien_Object $buyRequest, $product, $processMode) { if (!$product->getAwSarpEnabled()) { return; } Mage::getModel('sarp/product_type_default')->checkPeriod($product, $buyRequest); $Period = Mage::getModel('sarp/period'); /* We should add custom options that doesn't exist */ if ($buyRequest->getAwSarpSubscriptionType()) { if ($Period->load($buyRequest->getAwSarpSubscriptionType())->getId()) { $product->addCustomOption('aw_sarp_subscription_type', $Period->getId()); } } if ((empty($options['aw_sarp_subscription_start']['month']) || empty($options['aw_sarp_subscription_start']['day']) || empty($options['aw_sarp_subscription_start']['year'])) && $buyRequest->getAwSarpSubscriptionType() != AW_Sarp_Model_Period::PERIOD_TYPE_NONE) { $date = new Zend_Date(); $buyRequest->setAwSarpSubscriptionStart($date->toString(Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT))); } if (isset($options['aw_sarp_subscription_start']) && is_array($options['aw_sarp_subscription_start']) && $buyRequest->getAwSarpSubscriptionType() != AW_Sarp_Model_Period::PERIOD_TYPE_NONE && !empty($options['aw_sarp_subscription_start']['month']) && !empty($options['aw_sarp_subscription_start']['day']) && !empty($options['aw_sarp_subscription_start']['year'])) { $subscriptionStart = $options['aw_sarp_subscription_start']; $date = new Zend_Date(); $date->setMinute(0)->setHour(0)->setSecond(0)->setDay($subscriptionStart['day'])->setMonth($subscriptionStart['month'])->setYear($subscriptionStart['year']); $buyRequest->setAwSarpSubscriptionStart($date->toString(Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT))); } if (!is_null($buyRequest->getAwSarpSubscriptionStart()) && $Period->getId()) { $start = $buyRequest->getAwSarpSubscriptionStart(); if (!empty($start)) { $date = new Zend_Date($start, Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT)); } else { $date = $Period->getNearestAvailableDay(); } $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))) { $date = $Period->getNearestAvailableDay(); } } else { $date = Mage::app()->getLocale()->date(); } $product->addCustomOption('aw_sarp_subscription_start', $date->toString('Y-MM-dd')); $_result = parent::_prepareProduct($buyRequest, $product, $processMode); if (is_array($_result)) { if ($buyRequest->getAwSarpSubscriptionType()) { if ($Period->getId()) { $_result[0]->addCustomOption('aw_sarp_subscription_start', $date->toString('Y-MM-dd')); $_result[0]->addCustomOption('aw_sarp_subscription_type', $Period->getId()); } } return $_result; } return $this->getSpecifyOptionMessage(); }
public function getDateRange($range, $customStart, $customEnd, $returnObjects = false) { $dateEnd = new Zend_Date(Mage::getModel('core/date')->gmtTimestamp()); $dateStart = clone $dateEnd; // go to the end of a day $dateEnd->setHour(23); $dateEnd->setMinute(59); $dateEnd->setSecond(59); $dateStart->setHour(0); $dateStart->setMinute(0); $dateStart->setSecond(0); switch ($range) { case '24h': $dateEnd = new Zend_Date(Mage::getModel('core/date')->gmtTimestamp()); $dateEnd->addHour(1); $dateStart = clone $dateEnd; $dateStart->subDay(1); break; case '7d': // substract 6 days we need to include // only today and not hte last one from range $dateStart->subDay(6); break; case '1m': $dateStart->setDay(Mage::getStoreConfig('reports/dashboard/mtd_start')); break; case 'custom': $dateStart = $customStart ? $customStart : $dateEnd; $dateEnd = $customEnd ? $customEnd : $dateEnd; break; case '1y': case '2y': $startMonthDay = explode(',', Mage::getStoreConfig('reports/dashboard/ytd_start')); $startMonth = isset($startMonthDay[0]) ? (int) $startMonthDay[0] : 1; $startDay = isset($startMonthDay[1]) ? (int) $startMonthDay[1] : 1; $dateStart->setMonth($startMonth); $dateStart->setDay($startDay); if ($range == '2y') { $dateStart->subYear(1); } break; } if ($returnObjects) { return array($dateStart, $dateEnd); } else { return array('from' => $dateStart, 'to' => $dateEnd, 'datetime' => true); } }
public function getDateRange($range, $customStart, $customEnd, $returnObjects = false) { $dateEnd = new Zend_Date(Mage::getModel('core/date')->gmtTimestamp()); $dateStart = clone $dateEnd; // go to the end of a day $dateEnd->setHour(23); $dateEnd->setMinute(59); $dateEnd->setSecond(59); $dateStart->setHour(0); $dateStart->setMinute(0); $dateStart->setSecond(0); switch ($range) { case '24h': $dateEnd = new Zend_Date(Mage::getModel('core/date')->gmtTimestamp()); $dateEnd->addHour(1); $dateStart = clone $dateEnd; $dateStart->subDay(1); break; case '7d': // substract 6 days we need to include // only today and not hte last one from range $dateStart->subDay(6); break; case '1m': $dateStart->setDay(1); break; case 'custom': $dateStart = $customStart ? $customStart : $dateEnd; $dateEnd = $customEnd ? $customEnd : $dateEnd; break; case '1y': $dateStart->setMonth(1); $dateStart->setDay(1); break; case '2y': $dateStart->setMonth(1); $dateStart->setDay(1); $dateStart->subYear(1); break; } if ($returnObjects) { return array($dateStart, $dateEnd); } else { return array('from' => $dateStart, 'to' => $dateEnd, 'datetime' => true); } }
/** * (non-PHPdoc) * @see library/Oara/Network/Oara_Network_Publisher_Interface#getTransactionList($aMerchantIds, $dStartDate, $dEndDate, $sTransactionStatus) */ public function getTransactionList($merchantList = null, Zend_Date $dStartDate = null, Zend_Date $dEndDate = null, $merchantMap = null) { $totalTransactions = array(); $today = new Zend_Date(); $today->setHour(0); $today->setMinute(0); $urls = array(); $exportParams = array(new Oara_Curl_Parameter('data[query][agent]', $this->_agent), new Oara_Curl_Parameter('data[query][date1]', $dStartDate->toString("yyyy-MM-dd")), new Oara_Curl_Parameter('data[query][date2]', $dEndDate->toString("yyyy-MM-dd")), new Oara_Curl_Parameter('data[query][api_key]', $this->_apiKey)); $urls[] = new Oara_Curl_Request('http://www.skyparksecure.com/api/v4/jsonp/getSales?', $exportParams); $exportReport = $this->_client->get($urls); $report = substr($exportReport[0], 1, strlen($exportReport[0]) - 3); $exportData = json_decode($report); foreach ($exportData->result as $booking) { $transaction = array(); $transaction['merchantId'] = 1; $transaction['unique_id'] = $booking->booking_ref; $transaction['metadata'] = $booking->product_name; $transaction['custom_id'] = $booking->custom_id; $transactionDate = new Zend_Date($booking->booking_date, 'yyyy.MMM.dd HH:mm:00', 'en'); $pickupDate = new Zend_Date($booking->dateA, 'yyyy.MMM.dd HH:mm:00', 'en'); $transaction['date'] = $transactionDate->toString("yyyy-MM-dd HH:mm:ss"); $transaction['metadata'] = $booking->product_id; if ($booking->booking_mode == "Booked" || $booking->booking_mode == "Amended") { $transaction['status'] = Oara_Utilities::STATUS_PENDING; if ($today > $pickupDate) { $transaction['status'] = Oara_Utilities::STATUS_CONFIRMED; } } else { if ($booking->booking_mode == "Cancelled") { $transaction['status'] = Oara_Utilities::STATUS_DECLINED; } else { throw new Exception("New status found"); } } $transaction['amount'] = Oara_Utilities::parseDouble(preg_replace('/[^0-9\\.,]/', "", $booking->sale_price)) / 1.2; $transaction['commission'] = Oara_Utilities::parseDouble(preg_replace('/[^0-9\\.,]/', "", $booking->commission_affiliate)) / 1.2; $totalTransactions[] = $transaction; } return $totalTransactions; }
/** * Returns all Shipping Costs * * @return array */ public function getShippingCostsAction() { $dispatchID = $this->Request()->getParam('dispatchID', null); $limit = $this->Request()->getParam('limit', 20); $offset = $this->Request()->getParam('start', 0); $sort = $this->Request()->getParam('sort', array(array('property' => 'dispatch.name', 'direction' => 'ASC'))); $filter = $this->Request()->getParam('filter', null); if (is_array($filter) && isset($filter[0]['value'])) { $filter = $filter[0]['value']; } $query = $this->getRepository()->getShippingCostsQuery($dispatchID, $filter, $sort, $limit, $offset); $shippingCosts = $query->getArrayResult(); $shippingCostsResult = array(); foreach ($shippingCosts as $shippingCost) { if (!empty($shippingCost['bindTimeFrom'])) { $date = new Zend_Date(); $date->setMinute(0); $date->setHour(0); $date->setSecond(0); $shippingCost['bindTimeFrom'] = $date->addSecond($shippingCost['bindTimeFrom'])->toString("HH:mm"); } if (!empty($shippingCost['bindTimeTo'])) { $date = new Zend_Date(); $date->setMinute(0); $date->setHour(0); $date->setSecond(0); $shippingCost['bindTimeTo'] = $date->addSecond($shippingCost['bindTimeTo'])->toString("HH:mm"); } $shippingCostsResult[] = $shippingCost; } //returns the total count of the query $totalResult = $this->getManager()->getQueryCount($query); $this->View()->assign(array('success' => true, 'data' => $shippingCostsResult, 'total' => $totalResult)); }
/** * Prepares product for cart according to buyRequest. * * @param Varien_Object $buyRequest * @param object $product [optional] * @return */ public function prepareForCart(Varien_Object $buyRequest, $product = null, $old = false) { if (!$product->getAwSarpEnabled()) { if (!$old) { return parent::prepareForCart($buyRequest, $product); } return; } Mage::getModel('sarp/product_type_default')->checkPeriod($product, $buyRequest); /* * For creating order from admin * If product is added to cart from admin, we doesn't add sart custom options to it. */ $Period = Mage::getModel('sarp/period'); if ($product->getAwSarpPeriod()) { if (count(explode(",", $product->getAwSarpPeriod())) === 1) { $date = Mage::getModel('sarp/period')->load($product->getAwSarpPeriod())->getNearestAvailableDay(); $product->setAwSarpSubscriptionType($product->getAwSarpPeriod()); $product->setAwSarpSubscriptionStart($date->toString(), Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT)); } } /* 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()); } } else { if ($product->getAwSarpSubscriptionType()) { $buyRequest->setAwSarpSubscriptionType($product->getAwSarpSubscriptionType()); $product->addCustomOption('aw_sarp_subscription_type', $product->getAwSarpSubscriptionType()); $Period->setId($product->getAwSarpSubscriptionStart()); } } if ($this->requiresSubscriptionOptions($product) && !$Period->getId()) { $date = Mage::app()->getLocale()->date(); } $options = $buyRequest->getOptions(); if (isset($options['aw_sarp_subscription_start']) && is_array($options['aw_sarp_subscription_start']) && !empty($options['aw_sarp_subscription_start']['day']) && !empty($options['aw_sarp_subscription_start']['month']) && !empty($options['aw_sarp_subscription_start']['year'])) { $subscriptionStart = $options['aw_sarp_subscription_start']; $date = new Zend_Date(); $date->setMinute(0)->setHour(0)->setSecond(0)->setDay($subscriptionStart['day'])->setMonth($subscriptionStart['month'])->setYear($subscriptionStart['year']); $buyRequest->setAwSarpSubscriptionStart($date->toString(Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT))); } if (!is_null($buyRequest->getAwSarpSubscriptionStart()) && $Period->getId()) { $start = $buyRequest->getAwSarpSubscriptionStart(); if (!empty($start)) { $date = new Zend_Date($start, Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT)); } else { $date = $Period->getNearestAvailableDay(); } // 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))) { $date = $Period->getNearestAvailableDay(); } } else { $date = Mage::app()->getLocale()->date(); } $product->addCustomOption('aw_sarp_subscription_start', $date->toString('Y-MM-dd')); if (!$old) { return parent::prepareForCart($buyRequest, $product); } }
/** * (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); $affjetNetClickDao = Dao_Factory_Doctrine::createDoctrineDaoInstance('AffjetNetClick'); $criteriaList = array(); $criteriaList[] = new Dao_Doctrine_Criteria_Restriction_Select('AffjetNetUserRAffjetNetMerchant->AffjetNetMerchant->id', "_merchantId"); $criteriaList[] = new Dao_Doctrine_Criteria_Restriction_Select('date', "_date"); $criteriaList[] = new Dao_Doctrine_Criteria_Restriction_Select('COUNT(*)', "_clickNumber", true); $criteriaList[] = new Dao_Doctrine_Criteria_Restriction_In('AffjetNetUserRAffjetNetMerchant->AffjetNetMerchant->id', $merchantList, false); $criteriaList[] = new Dao_Doctrine_Criteria_Restriction_Eq('AffjetNetUserRAffjetNetMerchant->AffjetNetMerchant->AffjetNetPartner->id', $this->_partnerId); if (!$this->_isAdmin) { $criteriaList[] = new Dao_Doctrine_Criteria_Restriction_Eq('AffjetNetUserRAffjetNetMerchant->AffjetNetUser->id', $this->_userId); } $criteriaList[] = new Dao_Doctrine_Criteria_Restriction_Ge('date', $dStartDate->toString("yyyy-MM-dd HH:mm:ss")); $criteriaList[] = new Dao_Doctrine_Criteria_Restriction_Le('date', $dEndDate->toString("yyyy-MM-dd HH:mm:ss")); $criteriaList[] = new Dao_Doctrine_Criteria_Restriction_Groupby('AffjetNetUserRAffjetNetMerchant->AffjetNetMerchant->id'); $criteriaList[] = new Dao_Doctrine_Criteria_Restriction_Groupby('date', 'DAY'); $criteriaList[] = new Dao_Doctrine_Criteria_Restriction_Groupby('date', 'MONTH'); $criteriaList[] = new Dao_Doctrine_Criteria_Restriction_Groupby('date', 'YEAR'); $affjetNetClickList = $affjetNetClickDao->findBy($criteriaList); foreach ($affjetNetClickList as $affjetNetClick) { $overview = array(); $overviewDate = new Zend_Date($affjetNetClick->_date, "yyyy-MM-dd HH:mm:ss"); $overviewDate->setHour(0); $overviewDate->setMinute(0); $overviewDate->setSecond(0); $overview['merchantId'] = $affjetNetClick->_merchantId; $overview['date'] = $overviewDate->toString("yyyy-MM-dd HH:mm:ss"); $overview['click_number'] = $affjetNetClick->_clickNumber; $overview['impression_number'] = 0; $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; $transactionList = Oara_Utilities::getDayFromArray($affjetNetClick->_merchantId, $transactionArray, $overviewDate); foreach ($transactionList 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']; } } } } $totalOverviews[] = $overview; } return $totalOverviews; }
define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../')); define('APPLICATION_ENV', 'development'); set_include_path(implode(PATH_SEPARATOR, array(realpath(APPLICATION_PATH . '/../vendor/ZendFramework/library'), get_include_path()))); require_once 'Zend/Application.php'; $application = new Zend_Application(APPLICATION_ENV, APPLICATION_PATH . '/configs/application.ini'); $application->bootstrap(); // the needed resources $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
/** * Set the start date for this event * * @param Zend_Date $date * @param boolean $wholeDay * @return Zym_Calendar_Event */ public function setStartDate(Zend_Date $date, $wholeDay = false) { if ($wholeDay) { $date->setHour(0); $date->setMinute(0); $date->setSecond(0); $date->setMilliSecond(0); $endDate = clone $date; $endDate->setHour(23); $endDate->setMinute(59); $endDate->setSecond(59); $this->setEndDate($endDate); } $this->_startDate = $date; return $this; }
/** * Calculate date * * @param number $value * @param string $unit * @param number $roundDate * @return Zend_Date */ public function calcDate($value, $unit, $roundDate = null, $sign = '-') { // validate unit if (!key_exists($unit, $this->getTimeUnitOptions())) { return null; } $timestamp = strtotime("{$sign}{$value} {$unit}"); if ($timestamp) { // don't calculate with extrem high numbers (preformance) $timestamp = min(max($timestamp, 0), 10000000000.0); $date = new Zend_Date(); $date->setTimestamp($timestamp); if ($roundDate === self::DAY_START) { $date->setHour(0); $date->setMinute(0); $date->setSecond(0); } else { if ($roundDate === self::DAY_END) { $date->setHour(23); $date->setMinute(59); $date->setSecond(59); } } return $date; } return null; }
/** * (non-PHPdoc) * @see library/Oara/Network/Oara_Network_Interface#getOverviewList($aMerchantIds, $dStartDate, $dEndDate) */ public function getOverviewList($transactionList = null, $merchantList = null, Zend_Date $dStartDate = null, Zend_Date $dEndDate = null) { $overviewArray = array(); $firstDayMonth = new Zend_Date(); $firstDayMonth->setDay(1); $firstDayMonth->setHour("00"); $firstDayMonth->setMinute("00"); $firstDayMonth->setSecond("00"); $modeArray = array("AdSense for Content", "AdSense for Search", "AdSense for Feeds", "AdSense for Domains"); $valuesExport = array(); $valuesExport[] = new Oara_Curl_Parameter('d', $dStartDate->toString("yyyy/M/d") . "-" . $dEndDate->toString("yyyy/M/d")); $valuesExportReport[] = new Oara_Curl_Parameter('ag', 'date'); $valuesExport[] = new Oara_Curl_Parameter('oc', 'earnings'); $valuesExport[] = new Oara_Curl_Parameter('oo', 'descending'); $valuesExport[] = new Oara_Curl_Parameter('hl', 'en_GB'); $urls = array(); $valuesExportReport = Oara_Utilities::cloneArray($valuesExport); $valuesExportReport[] = new Oara_Curl_Parameter('dd', '1YproductY1YAFCYAdSense for Content'); $urls[] = new Oara_Curl_Request('https://www.google.com/adsense/v3/gwt/exportCsv?', $valuesExportReport); $valuesExportReport = Oara_Utilities::cloneArray($valuesExport); $valuesExportReport[] = new Oara_Curl_Parameter('dd', '1YproductY1YAFSYAdSense for Search'); $urls[] = new Oara_Curl_Request('https://www.google.com/adsense/v3/gwt/exportCsv?', $valuesExportReport); $valuesExportReport = Oara_Utilities::cloneArray($valuesExport); $valuesExportReport[] = new Oara_Curl_Parameter('dd', '1YproductY1YAFFYAdSense for Feeds'); $urls[] = new Oara_Curl_Request('https://www.google.com/adsense/v3/gwt/exportCsv?', $valuesExportReport); $valuesExportReport = Oara_Utilities::cloneArray($valuesExport); $valuesExportReport[] = new Oara_Curl_Parameter('dd', '1YproductY1YAFDYAdSense for Domains'); $urls[] = new Oara_Curl_Request('https://www.google.com/adsense/v3/gwt/exportCsv?', $valuesExportReport); $content = $this->_client->post($urls); for ($i = 0; $i < count($content); $i++) { $exportData = str_getcsv(@iconv('UTF-16', 'UTF-8', $content[$i]), "\n"); for ($j = 1; $j < count($exportData); $j++) { $overviewExportArray = str_getcsv($exportData[$j], "\t"); $obj = array(); $obj['merchantId'] = 1; $overviewDate = new Zend_Date($overviewExportArray[0], "yyyy-MM-dd"); $overviewDate->setHour("00"); $overviewDate->setMinute("00"); $overviewDate->setSecond("00"); $obj['date'] = $overviewDate->toString("yyyy-MM-dd HH:mm:ss"); $obj['link'] = $modeArray[$i]; $obj['transaction_number'] = 0; $obj['transaction_confirmed_commission'] = 0; $obj['transaction_confirmed_value'] = 0; $obj['transaction_pending_commission'] = 0; $obj['transaction_pending_value'] = 0; $obj['transaction_declined_commission'] = 0; $obj['transaction_declined_value'] = 0; $obj['impression_number'] = (int) Oara_Utilities::parseDouble($overviewExportArray[1]); $obj['click_number'] = Oara_Utilities::parseDouble($overviewExportArray[2]); if ($firstDayMonth->compare($overviewDate) <= 0) { $obj['transaction_pending_commission'] = Oara_Utilities::parseDouble($overviewExportArray[6]); $obj['transaction_pending_value'] = Oara_Utilities::parseDouble($overviewExportArray[6]); } else { $obj['transaction_confirmed_commission'] = Oara_Utilities::parseDouble($overviewExportArray[6]); $obj['transaction_confirmed_value'] = Oara_Utilities::parseDouble($overviewExportArray[6]); } if (Oara_Utilities::checkRegister($obj)) { $overviewArray[] = $obj; } } } unset($urls); return $overviewArray; }
public function prepareForCartAdvanced(Varien_Object $buyRequest, $product = null, $processMode = null) { Mage::getModel('sarp/product_type_default')->checkPeriod($product, $buyRequest); $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()); } } $options = $buyRequest->getOptions(); if (isset($options['aw_sarp_subscription_start']) && is_array($options['aw_sarp_subscription_start'])) { $subscriptionStart = $options['aw_sarp_subscription_start']; $date = new Zend_Date(); $date->setMinute(0)->setHour(0)->setSecond(0)->setDay($subscriptionStart['day'])->setMonth($subscriptionStart['month'])->setYear($subscriptionStart['year']); $buyRequest->setAwSarpSubscriptionStart($date->toString(Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT))); } 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')); if ($attributes = $buyRequest->getSuperAttribute()) { $result = Mage_Catalog_Model_Product_Type_Abstract::prepareForCartAdvanced($buyRequest, $product); if (is_array($result)) { $product = $this->getProduct($product); /** * $attributes = array($attributeId=>$attributeValue) */ if ($subProduct = $this->getProductByAttributes($attributes, $product)) { $product->addCustomOption('attributes', serialize($attributes)); $product->addCustomOption('product_qty_' . $subProduct->getId(), 1, $subProduct); $product->addCustomOption('simple_product', $subProduct->getId(), $subProduct); $_result = $subProduct->getTypeInstance(true)->prepareForCartAdvanced($buyRequest, $subProduct); if (is_string($_result) && !is_array($_result)) { return $_result; } if (!isset($_result[0])) { return Mage::helper('checkout')->__('Can not add item to shopping cart'); } /** * Adding parent product custom options to child product * to be sure that it will be unique as its parent */ if ($optionIds = $product->getCustomOption('option_ids')) { $optionIds = explode(',', $optionIds->getValue()); foreach ($optionIds as $optionId) { if ($option = $product->getCustomOption('option_' . $optionId)) { $_result[0]->addCustomOption('option_' . $optionId, $option->getValue()); } } } if ($buyRequest->getAwSarpSubscriptionType()) { if ($Period->getId()) { $_result[0]->addCustomOption('aw_sarp_subscription_start', $date->toString('Y-MM-dd')); $_result[0]->addCustomOption('aw_sarp_subscription_type', $Period->getId()); } } $_result[0]->setParentProductId($product->getId())->addCustomOption('parent_product_id', $product->getId())->setCartQty(1); $result[] = $_result[0]; return $result; } } } return $this->getSpecifyOptionMessage(); }
/** * Export orders */ public function exportOrdersAction() { $this->Front()->Plugins()->Json()->setRenderer(false); $format = strtolower($this->Request()->getParam('format', 'csv')); /** @var \Shopware\Models\Order\Repository $repository */ $repository = $this->getManager()->getRepository('Shopware\\Models\\Order\\Order'); /** @var \Shopware\Components\Model\ModelRepository $currencyRepostiroy */ $currencyRepository = $this->getManager()->getRepository('Shopware\\Models\\Shop\\Currency'); $builder = $repository->createQueryBuilder('orders'); $orderState = $this->Request()->getParam('orderstate'); if (is_numeric($orderState)) { $builder->andWhere('orders.status = :orderstate'); $builder->setParameter('orderstate', $orderState); } $paymentState = $this->Request()->getParam('paymentstate'); if (is_numeric($paymentState)) { $builder->andWhere('orders.cleared = :paymentstate'); $builder->setParameter('paymentstate', $paymentState); } $orderNumberFrom = $this->Request()->getParam('ordernumberFrom'); if (is_numeric($orderNumberFrom)) { $builder->andWhere('orders.number > :orderNumberFrom'); $builder->setParameter('orderNumberFrom', $orderNumberFrom); } $dateFrom = $this->Request()->getParam('dateFrom'); if ($dateFrom) { $dateFrom = new \DateTime($dateFrom); $builder->andWhere('orders.orderTime >= :dateFrom'); $builder->setParameter('dateFrom', $dateFrom); } $dateTo = $this->Request()->getParam('dateTo'); if ($dateTo) { $dateTo = new Zend_Date($dateTo); $dateTo->setHour('23'); $dateTo->setMinute('59'); $dateTo->setSecond('59'); $builder->andWhere('orders.orderTime <= :dateTo'); $builder->setParameter('dateTo', $dateTo->get('yyyy-MM-dd HH:mm:ss')); } if ($format == 'xml') { $selectFields = array('orders', 'details', 'documents', 'payment', 'customer', 'shipping', 'billing', 'billingCountry', 'shippingCountry', 'shop', 'dispatch', 'paymentStatus', 'orderStatus', 'documentType'); } if ($format == 'csv' || $format == 'excel') { $selectFields = array('orders.id as orderId', 'orders.number as ordernumber', 'orders.orderTime as ordertime', 'orders.customerId as customerID', 'orders.paymentId as paymentID', 'orders.transactionId as transactionID', 'orders.partnerId as partnerID', 'orders.cleared as clearedID', 'orders.status as statusID', 'dispatch.id as dispatchID', 'orders.shopId as subshopID', 'orders.invoiceAmount as invoice_amount', 'orders.invoiceAmountNet as invoice_amount_net', 'orders.invoiceShipping as invoice_shipping', 'orders.invoiceShippingNet as invoice_shipping_net', 'orders.net as netto', 'paymentStatus.description as cleared_description', 'orderStatus.description as status_description', 'payment.description as payment_description', 'dispatch.description as dispatch_description', 'orders.id as currency_description', 'orders.referer as referer', 'orders.clearedDate as cleareddate', 'orders.trackingCode as trackingcode', 'orders.languageIso as language', 'orders.currency as currency', 'orders.currencyFactor as currencyFactor', 'orders.id as count_positions', 'details.id as orderdetailsID', 'details.articleId as articleID', 'details.articleNumber as articleordernumber', 'details.articleName as name', 'details.price as price', 'details.quantity as quantity', 'details.ean as ean', 'details.unit as unit', 'details.packUnit as packUnit', 'details.price * details.quantity as invoice', 'details.releaseDate as releasedate', 'taxes.tax as tax', 'details.esdArticle as esd', 'details.mode as modus', 'customerBilling.number as customernumber', 'billing.company as billing_company', 'billing.department as billing_department', 'billing.salutation as billing_salutation', 'billing.firstName as billing_firstname', 'billing.lastName as billing_lastname', 'billing.street as billing_street', 'billing.streetNumber as billing_streetnumber', 'billing.zipCode as billing_zipcode', 'billing.city as billing_city', 'billingCountry.name as billing_country', 'billingCountry.isoName as billing_countryen', 'billingCountry.iso as billing_countryiso', 'shipping.company as shipping_company', 'shipping.department as shipping_department', 'shipping.salutation as shipping_salutation', 'shipping.firstName as shipping_firstname', 'shipping.lastName as shipping_lastname', 'shipping.street as shipping_street', 'shipping.streetNumber as shipping_streetnumber', 'shipping.zipCode as shipping_zipcode', 'shipping.city as shipping_city', 'shippingCountry.name as shipping_country', 'shippingCountry.isoName as shipping_countryen', 'shippingCountry.iso as shipping_countryiso', 'billing.vatId as ustid', 'billing.phone as phone', 'billing.fax as fax', 'customer.email as email', 'customer.groupKey as customergroup', 'customer.newsletter as newsletter', 'customer.affiliate as affiliate'); $builder->addGroupBy('orderdetailsID'); } $builder->select($selectFields); $builder->leftJoin('orders.details', 'details')->leftJoin('details.tax', 'taxes')->leftJoin('orders.documents', 'documents')->leftJoin('documents.type', 'documentType')->leftJoin('orders.payment', 'payment')->leftJoin('orders.paymentStatus', 'paymentStatus')->leftJoin('orders.orderStatus', 'orderStatus')->leftJoin('orders.customer', 'customer')->leftJoin('customer.billing', 'customerBilling')->leftJoin('orders.billing', 'billing')->leftJoin('billing.country', 'billingCountry')->leftJoin('orders.shipping', 'shipping')->leftJoin('orders.shop', 'shop')->leftJoin('orders.dispatch', 'dispatch')->leftJoin('shipping.country', 'shippingCountry'); $builder->addOrderBy('orders.orderTime'); $query = $builder->getQuery(); $result = $query->getArrayResult(); $updateStateId = $this->Request()->getParam('updateOrderstate'); if (!empty($updateStateId)) { $orderIds = array(); if ($format == 'csv' || $format == 'excel') { foreach ($result as $item) { $orderIds[] = $item['orderId']; } $orderIds = array_unique($orderIds); } if ($format == 'xml') { foreach ($result as $item) { $orderIds[] = $item['id']; } } $this->updateOrderStatus($orderIds, $updateStateId); } if ($format == 'csv' || $format == 'excel') { $builder = $repository->createQueryBuilder('orders'); $builder->select(array('count(details.id) as count_positions')); $builder->leftJoin('orders.details', 'details')->andWhere('details.orderId = :orderId')->groupBy('orders.id'); foreach ($result as &$item) { $builder->setParameter('orderId', $item['orderId']); try { $item['count_positions'] = $builder->getQuery()->getSingleScalarResult(); } catch (\Exception $e) { $item['count_positions'] = 0; } $currencyModel = $currencyRepository->findOneBy(array('currency' => $item['currency'])); if ($currencyModel) { $item['currency_description'] = $currencyModel->getName(); } else { $item['currency_description'] = ''; } // Format tax $item['tax'] = (double) $item['tax']; } array_walk_recursive($result, function (&$value) { if ($value instanceof DateTime) { $value = $value->format('Y-m-d H:i:s'); } }); if ($format === 'excel') { $this->Response()->setHeader('Content-Type', 'application/vnd.ms-excel;charset=UTF-8'); $this->Response()->setHeader('Content-Disposition', 'attachment; filename="export.orders.' . date("Y.m.d") . '.xls"'); $this->Response()->setHeader('Content-Transfer-Encoding', 'binary'); $excel = new Shopware_Components_Convert_Excel(); $excel->setTitle('Orders Export'); $excel->addRow(array_keys(reset($result))); $excel->addArray($result); echo $excel->getAll(); } if ($format == 'csv') { $this->Response()->setHeader('Content-Type', 'text/x-comma-separated-values;charset=utf-8'); $this->Response()->setHeader('Content-Disposition', 'attachment; filename="export.orders.' . date("Y.m.d") . '.csv"'); $this->Response()->setHeader('Content-Transfer-Encoding', 'binary'); $convert = new Shopware_Components_Convert_Csv(); $convert->sSettings['newline'] = "\r\n"; echo ""; // UTF-8 BOM echo $convert->encode($result); } } if ($format == 'xml') { array_walk_recursive($result, function (&$value) { if ($value instanceof DateTime) { $value = $value->format('Y-m-d H:i:s'); } }); $orders = array("shopware" => array("orders" => array("order" => $result))); $convert = new Shopware_Components_Convert_Xml(); $this->Response()->setHeader('Content-Type', 'text/xml;charset=utf-8'); $this->Response()->setHeader('Content-Disposition', 'attachment; filename="export.orders.' . date("Y.m.d") . '.xml"'); $this->Response()->setHeader('Content-Transfer-Encoding', 'binary'); echo $convert->encode($orders); } }
/** * 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"); } }
/** * Filters the displayed fields by the passed filter value. * * @param \Doctrine\ORM\QueryBuilder $builder * @param array|null $filters * @return \Doctrine\ORM\QueryBuilder */ protected function filterListQuery(\Doctrine\ORM\QueryBuilder $builder, $filters = null) { $expr = Shopware()->Models()->getExpressionBuilder(); if (!empty($filters)) { foreach ($filters as $filter) { if (empty($filter['property']) || $filter['value'] === null || $filter['value'] === '') { continue; } switch ($filter['property']) { case "free": $builder->andWhere($expr->orX($expr->like('orders.number', '?1'), $expr->like('orders.invoiceAmount', '?1'), $expr->like('orders.transactionId', '?1'), $expr->like('payment.description', '?1'), $expr->like('dispatch.name', '?1'), $expr->like('orderStatus.description', '?1'), $expr->like('paymentStatus.description', '?1'), $expr->like('orders.orderTime', '?2'), $expr->like('billing.company', '?3'), $expr->like('customer.email', '?3'), $expr->like('billing.lastName', '?3'), $expr->like('billing.firstName', '?3'), $expr->like('shop.name', '?3'), $expr->like('orders.comment', '?3'), $expr->like('orders.customerComment', '?3'), $expr->like('orders.internalComment', '?3'))); $builder->setParameter(1, $filter['value'] . '%'); $builder->setParameter(2, '%' . $filter['value']); $builder->setParameter(3, '%' . $filter['value'] . '%'); break; case "from": $tmp = new \DateTime($filter['value']); $builder->andWhere($expr->gte('orders.orderTime', $tmp->format('Ymd'))); break; case "to": $tmp = new \Zend_Date($filter['value']); $tmp->setHour('23'); $tmp->setMinute('59'); $tmp->setSecond('59'); $builder->andWhere('orders.orderTime <= :orderTimeTo'); $builder->setParameter('orderTimeTo', $tmp->get('yyyy-MM-dd HH:mm:ss')); break; case 'details.articleNumber': $builder->andWhere('details.articleNumber LIKE :articleNumber'); $builder->setParameter('articleNumber', $filter['value'] . "%"); break; case 'customer.groupKey': $builder->andWhere($expr->eq($filter['property'], "'" . $filter['value'] . "'")); break; default: $builder->andWhere($expr->eq($filter['property'], $filter['value'])); } } } return $builder; }
/** * (non-PHPdoc) * @see Oara/Network/Oara_Network_Publisher_Base#getPaymentHistory() */ public function getPaymentHistory() { $paymentHistory = array(); //Set the webservice //At first, we need to be sure that there are some data. $auxStartDate = new Zend_Date("01-01-1990", "dd-MM-yyyy"); $auxStartDate->setHour("00"); $auxStartDate->setMinute("00"); $auxStartDate->setSecond("00"); $auxEndDate = new Zend_Date(); $params = array('CredentialToken' => $this->_token, 'PublisherId' => $this->_user, 'StartDate' => strtotime($auxStartDate->toString("yyyy-MM-dd")), 'EndDate' => strtotime($auxEndDate->toString("yyyy-MM-dd"))); $accountServiceUrl = 'https://api.affili.net/V2.0/AccountService.svc?wsdl'; $accountService = new Oara_Import_Soap_Client($accountServiceUrl, array('compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP | SOAP_COMPRESSION_DEFLATE, 'soap_version' => SOAP_1_1)); $paymentList = self::affilinetCall('payment', $accountService, $params); if (isset($paymentList->PaymentInformationCollection) && !is_array($paymentList->PaymentInformationCollection)) { $paymentList->PaymentInformationCollection = array($paymentList->PaymentInformationCollection); } if (isset($paymentList->PaymentInformationCollection)) { foreach ($paymentList->PaymentInformationCollection as $payment) { $obj = array(); $obj['method'] = $payment->PaymentType; $obj['pid'] = $payment->PaymentId; $obj['value'] = $payment->GrossTotal; $obj['date'] = $payment->PaymentDate; $paymentHistory[] = $obj; } } $this->_paymentHistory = $paymentHistory; return $paymentHistory; }
/** * 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 } }
public function calculaExpiracao($vencimentoBoleto, $diasExpiracao) { //$dataTeste = date("Y-m-d H:i:s", Mage::getModel('core/date')->timestamp(time())); //$dataAtual = Mage::getModel('core/date')->date('Y-m-d H:i:s'); $dataHoraVencimentoBoleto = new Zend_Date($vencimentoBoleto); $dataHoraVencimentoBoleto->setHour(23); $dataHoraVencimentoBoleto->setMinute(59); $dataHoraVencimentoBoleto->setSecond(59); $dataHoraVencimentoBoleto = $dataHoraVencimentoBoleto->get('yyyy-MM-dd HH:mm:ss'); //Ideasa_Base_Helper_LogUtils::varDump($dataAtual); //$soma = ($validade + $diasUteis); //$dataVencimentoBoleto = Mage::helper('base/date')->addDaysToUs($soma, $dataAtual); return Mage::helper('base/date')->addDaysToUs($diasExpiracao, $dataHoraVencimentoBoleto); }
/** * Prepares product for cart according to buyRequest. * * @param Varien_Object $buyRequest * @param object $product [optional] * @return */ public function prepareForCart(Varien_Object $buyRequest, $product = null) { if (!$product->getAwSarpEnabled()) { return parent::prepareForCart($buyRequest, $product); } Mage::getModel('sarp/product_type_default')->checkPeriod($product, $buyRequest); /* * For creating order from admin * If product is added to cart from admin, we doesn't add sart custom options to it. */ $req = Mage::app()->getFrontController()->getRequest(); $product = $this->getProduct($product); $productsInfo = $buyRequest->getSuperGroup(); $options = $buyRequest->getOptions(); if (isset($options['aw_sarp_subscription_start']) && is_array($options['aw_sarp_subscription_start'])) { $subscriptionStart = $options['aw_sarp_subscription_start']; $date = new Zend_Date(); $date->setMinute(0)->setHour(0)->setSecond(0)->setDay($subscriptionStart['day'])->setMonth($subscriptionStart['month'])->setYear($subscriptionStart['year']); $buyRequest->setAwSarpSubscriptionStart($date->toString(Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT))); } if (!empty($productsInfo) && is_array($productsInfo)) { $products = array(); $associatedProducts = $this->getAssociatedProducts($product); if ($associatedProducts) { foreach ($associatedProducts as $subProduct) { if (isset($productsInfo[$subProduct->getId()])) { $qty = $productsInfo[$subProduct->getId()]; if (!empty($qty) && is_numeric($qty)) { $this->_addSarpInfo($buyRequest, $subProduct); $_result = $subProduct->getTypeInstance(true)->prepareForCart($buyRequest, $subProduct); if (is_string($_result) && !is_array($_result)) { return $_result; } if (!isset($_result[0])) { return Mage::helper('checkout')->__('Cannot add the item to shopping cart.'); } $_result[0]->setCartQty($qty); $_result[0]->addCustomOption('product_type', self::TYPE_CODE, $product); $sarpSubscriptionStart = $sarpSubscriptionType = null; if ($subProduct->getCustomOption('aw_sarp_subscription_start')) { //$sarpSubscriptionStart = $subProduct->getCustomOption('aw_sarp_subscription_start')->getValue(); $sarpSubscriptionStart = new Zend_Date($subProduct->getCustomOption('aw_sarp_subscription_start')->getValue(), Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT)); $sarpSubscriptionStart = $sarpSubscriptionStart->toString(preg_replace(array('/M/', '/d/'), array('MM', 'dd'), Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT))); } if ($subProduct->getCustomOption('aw_sarp_subscription_type')) { $sarpSubscriptionType = $subProduct->getCustomOption('aw_sarp_subscription_type')->getValue(); } $_result[0]->addCustomOption('info_buyRequest', serialize(array('super_product_config' => array('product_type' => self::TYPE_CODE, 'product_id' => $product->getId()), 'options' => $buyRequest->getOptions(), 'aw_sarp_subscription_start' => $sarpSubscriptionStart, 'aw_sarp_subscription_type' => $sarpSubscriptionType))); $products[] = $_result[0]; } } } } if (count($products)) { return $products; } } return Mage::helper('catalog')->__('Please specify the quantity of product(s).'); }
/** * @return Zend_Date current date, with unit reset depending of current lifetime. * @todo lifetime should be a parameter */ protected function _getDate() { $lifetime = Centurion_Config_Manager::get('ticket.lifetime'); list(, $lifetimeUnit) = sscanf($lifetime, '%d%s'); $date = new Zend_Date(); //We reset all unit that are below the ticket lifetime //Ex: if the lifetime if 1d, we reset hours, minute, second switch ($lifetimeUnit) { case 'j': case 'd': $date->setHour(0); case 'h': $date->setMinute(0); case 'm': default: $date->setSecond(0); } return $date; }
public function isValid($ticket = null, $actionUrl = null, $lifeTime = null) { if (null === $ticket) { $ticket = Zend_Controller_Front::getInstance()->getRequest()->getParam('ticket'); if (null === $ticket) { return false; } } $actionUrl = $this->_getActionUrl($actionUrl); if (null === $lifeTime) { $lifeTime = Centurion_Config_Manager::get('ticket.lifetime'); } list($lifetimeValue, $lifetimeUnit) = sscanf($lifeTime, '%d%s'); $lifetimeUnit = strtolower($lifetimeUnit); $date = new Zend_Date(); switch ($lifetimeUnit) { case 'j': case 'd': $date->setHour(0); case 'h': $date->setMinute(0); case 'm': default: $date->setSecond(0); } for ($i = 0; $i < $lifetimeValue; $i++) { if ($ticket === $this->getKey($actionUrl, $date)) { return true; } switch ($lifetimeUnit) { case 'j': $date->subDay(1); break; case 'h': $date->subHour(1); break; case 'm': default: $date->subMinute(1); break; } } return false; }
/** * @param Centurion_Db_Table_Row_Abstract $row * @param string $key * @param $effect * @return bool */ public function isValidKey($row, $key, $effect) { $lifetime = Centurion_Config_Manager::get('media.key_lifetime'); list($lifetimeValue, $lifetimeUnit) = sscanf($lifetime, '%d%s'); $lifetimeUnit = strtolower($lifetimeUnit); $date = new Zend_Date(); switch ($lifetimeUnit) { case 'j': $date->setHour(0); case 'h': $date->setMinute(0); case 'm': default: $date->setSecond(0); } for ($i = 0; $i < $lifetimeValue; $i++) { if ($key === $row->getTemporaryKey($effect, $date)) { return true; } switch ($lifetimeUnit) { case 'j': $date->subDay(1); break; case 'h': $date->subHour(1); break; case 'm': default: $date->subMinute(1); break; } } return false; }