/** * (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; }
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); } }
/** * 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 } }
/** * 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; }
/** * 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); } }
/** * 取得InfoServer数据表中某个时间段的分组数据SQL语句 * * @param integer $startTimestamp * @param integer $range * @param array|string $spec * @return Zend_Db_Select */ public function getSumGroupSelect($startTimestamp = null, $range = null, $spec = 'rTimestamp') { $select = $this->select(true)->reset(self::COLUMNS)->columns(array('rTimestamp', 'OnlineNum' => $this->_exprSumOnlineNum)); if (!empty($startTimestamp)) { $startDate = new Zend_Date($startTimestamp); $select->where('rTimestamp >= ?', $startDate->setSecond(0)->getTimestamp(), Zend_DB::INT_TYPE); if (!empty($range)) { $select->where('rTimestamp <= ?', $startDate->addMinute($range - 1)->setSecond(59)->getTimestamp(), Zend_DB::INT_TYPE); } } $select->group($spec); return $select; }
/** * @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; }
/** * (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; }
/** * 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; }
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 $config = Zend_Registry::get('config');
/** * 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 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); }
/** * 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"); } }
/** * (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; }
/** * 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)); }
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; }