1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26: class Mage_Adminhtml_Block_Tax_Rule_Grid extends Mage_Adminhtml_Block_Widget_Grid
27: {
28:
29: public function __construct()
30: {
31: parent::__construct();
32: $this->setDefaultSort('tax_rule_id');
33: $this->setId('taxRuleGrid');
34: $this->setDefaultDir('asc');
35: $this->setSaveParametersInSession(true);
36: }
37:
38: protected function _prepareCollection()
39: {
40: $collection = Mage::getModel('tax/calculation_rule')
41: ->getCollection();
42: $this->setCollection($collection);
43: parent::_prepareCollection();
44: if ($this->getCollection()) {
45: $this->getCollection()
46: ->addCustomerTaxClassesToResult()
47: ->addProductTaxClassesToResult()
48: ->addRatesToResult();
49: }
50: return $this;
51: }
52:
53: protected function _addColumnFilterToCollection($column)
54: {
55: if ($this->getCollection()) {
56: switch ($column->getId()) {
57: case 'tax_rates':
58: $this->getCollection()->joinCalculationData('rate');
59: break;
60:
61: case 'customer_tax_classes':
62: $this->getCollection()->joinCalculationData('ctc');
63: break;
64:
65: case 'product_tax_classes':
66: $this->getCollection()->joinCalculationData('ptc');
67: break;
68:
69: }
70: }
71: return parent::_addColumnFilterToCollection($column);
72: }
73:
74: protected function _prepareColumns()
75: {
76: $this->addColumn('code',
77: array(
78: 'header'=>Mage::helper('tax')->__('Name'),
79: 'align' =>'left',
80: 'index' => 'code',
81: 'filter_index' => 'code',
82: )
83: );
84:
85: $this->addColumn('customer_tax_classes',
86: array(
87: 'header'=>Mage::helper('tax')->__('Customer Tax Class'),
88: 'sortable' => false,
89: 'align' =>'left',
90: 'index' => 'customer_tax_classes',
91: 'filter_index' => 'ctc.customer_tax_class_id',
92: 'type' => 'options',
93: 'show_missing_option_values' => true,
94: 'options' => Mage::getModel('tax/class')->getCollection()->setClassTypeFilter(Mage_Tax_Model_Class::TAX_CLASS_TYPE_CUSTOMER)->toOptionHash(),
95: )
96: );
97:
98: $this->addColumn('product_tax_classes',
99: array(
100: 'header'=>Mage::helper('tax')->__('Product Tax Class'),
101: 'sortable' => false,
102: 'align' =>'left',
103: 'index' => 'product_tax_classes',
104: 'filter_index' => 'ptc.product_tax_class_id',
105: 'type' => 'options',
106: 'show_missing_option_values' => true,
107: 'options' => Mage::getModel('tax/class')->getCollection()->setClassTypeFilter(Mage_Tax_Model_Class::TAX_CLASS_TYPE_PRODUCT)->toOptionHash(),
108: )
109: );
110:
111: $this->addColumn('tax_rates',
112: array(
113: 'sortable' => false,
114: 'header' => Mage::helper('tax')->__('Tax Rate'),
115: 'align' => 'left',
116: 'index' => 'tax_rates',
117: 'filter_index' => 'rate.tax_calculation_rate_id',
118: 'type' => 'options',
119: 'show_missing_option_values' => true,
120: 'options' => Mage::getModel('tax/calculation_rate')->getCollection()->toOptionHashOptimized(),
121: )
122: );
123:
124: $this->addColumn('priority',
125: array(
126: 'header'=>Mage::helper('tax')->__('Priority'),
127: 'width' => '50px',
128: 'index' => 'priority'
129: )
130: );
131:
132: $this->addColumn('position',
133: array(
134: 'header'=>Mage::helper('tax')->__('Sort Order'),
135: 'width' => '50px',
136: 'index' => 'position'
137: )
138: );
139:
140: $actionsUrl = $this->getUrl('*/*/');
141:
142: return parent::_prepareColumns();
143: }
144:
145: public function getRowUrl($row)
146: {
147: return $this->getUrl('*/*/edit', array('rule' => $row->getId()));
148: }
149:
150: }
151: