00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 class Mage_Reports_Model_Mysql4_Tax_Collection extends Mage_Sales_Model_Entity_Order_Collection
00036 {
00037 public function _construct()
00038 {
00039 parent::_construct();
00040 $this->setRowIdFieldName('tax_id');
00041 }
00042
00043 public function setDateRange($from, $to)
00044 {
00045 $this->_reset();
00046
00047 $this->addAttributeToFilter('created_at', array('from' => $from, 'to' => $to))
00048 ->addExpressionAttributeToSelect('orders', 'COUNT(DISTINCT({{entity_id}}))', array('entity_id'))
00049 ->getSelect()
00050 ->join(array('tax_table' => $this->getTable('sales/order_tax')), 'e.entity_id = tax_table.order_id')
00051 ->group('tax_table.code')
00052 ->order(array('process', 'priority'));
00053
00054 return $this;
00055 }
00056
00057 public function setStoreIds($storeIds)
00058 {
00059 $vals = array_values($storeIds);
00060 if (count($storeIds) >= 1 && $vals[0] != '') {
00061 $this->getSelect()
00062 ->where('e.store_id in (?)', (array)$storeIds)
00063 ->from('', array('tax'=>'SUM(tax_table.base_real_amount)'));
00064 } else {
00065 $this->addExpressionAttributeToSelect(
00066 'tax',
00067 'SUM(tax_table.base_real_amount*{{base_to_global_rate}})',
00068 array('base_to_global_rate'));
00069 }
00070
00071 return $this;
00072 }
00073
00074 public function getSelectCountSql()
00075 {
00076 $countSelect = clone $this->getSelect();
00077 $countSelect->reset(Zend_Db_Select::ORDER);
00078 $countSelect->reset(Zend_Db_Select::LIMIT_COUNT);
00079 $countSelect->reset(Zend_Db_Select::LIMIT_OFFSET);
00080 $countSelect->reset(Zend_Db_Select::COLUMNS);
00081 $countSelect->reset(Zend_Db_Select::GROUP);
00082 $countSelect->reset(Zend_Db_Select::HAVING);
00083 $countSelect->from("", "count(DISTINCT e.entity_id)");
00084 $sql = $countSelect->__toString();
00085 return $sql;
00086 }
00087 }