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:
27: 28: 29: 30: 31: 32: 33:
34:
35: class Mage_Adminhtml_Block_Tax_Rate_Form extends Mage_Adminhtml_Block_Widget_Form
36: {
37: protected $_titles = null;
38:
39: public function __construct()
40: {
41: parent::__construct();
42: $this->setDestElementId('rate_form');
43: $this->setTemplate('tax/rate/form.phtml');
44: }
45:
46: protected function _prepareForm()
47: {
48: $rateObject = new Varien_Object(Mage::getSingleton('tax/calculation_rate')->getData());
49: $form = new Varien_Data_Form();
50:
51: $countries = Mage::getModel('adminhtml/system_config_source_country')->toOptionArray();
52: unset($countries[0]);
53:
54: if (!$rateObject->hasTaxCountryId()) {
55: $rateObject->setTaxCountryId(Mage::getStoreConfig(Mage_Tax_Model_Config::CONFIG_XML_PATH_DEFAULT_COUNTRY));
56: }
57:
58: if (!$rateObject->hasTaxRegionId()) {
59: $rateObject->setTaxRegionId(Mage::getStoreConfig(Mage_Tax_Model_Config::CONFIG_XML_PATH_DEFAULT_REGION));
60: }
61:
62: $regionCollection = Mage::getModel('directory/region')
63: ->getCollection()
64: ->addCountryFilter($rateObject->getTaxCountryId());
65:
66: $regions = $regionCollection->toOptionArray();
67: if ($regions) {
68: $regions[0]['label'] = '*';
69: } else {
70: $regions = array(array('value' => '', 'label' => '*'));
71: }
72:
73: $fieldset = $form->addFieldset('base_fieldset', array('legend' => Mage::helper('tax')->__('Tax Rate Information')));
74:
75: if ($rateObject->getTaxCalculationRateId() > 0) {
76: $fieldset->addField('tax_calculation_rate_id', 'hidden', array(
77: 'name' => 'tax_calculation_rate_id',
78: 'value' => $rateObject->getTaxCalculationRateId()
79: ));
80: }
81:
82: $fieldset->addField('code', 'text', array(
83: 'name' => 'code',
84: 'label' => Mage::helper('tax')->__('Tax Identifier'),
85: 'title' => Mage::helper('tax')->__('Tax Identifier'),
86: 'class' => 'required-entry',
87: 'required' => true,
88: ));
89:
90: $fieldset->addField('tax_country_id', 'select', array(
91: 'name' => 'tax_country_id',
92: 'label' => Mage::helper('tax')->__('Country'),
93: 'required' => true,
94: 'values' => $countries
95: ));
96:
97: $fieldset->addField('tax_region_id', 'select', array(
98: 'name' => 'tax_region_id',
99: 'label' => Mage::helper('tax')->__('State'),
100: 'values' => $regions
101: ));
102:
103: $fieldset->addField('zip_is_range', 'select', array(
104: 'name' => 'zip_is_range',
105: 'label' => Mage::helper('tax')->__('Zip/Post is Range'),
106: 'options' => array(
107: '0' => Mage::helper('tax')->__('No'),
108: '1' => Mage::helper('tax')->__('Yes'),
109: )
110: ));
111:
112: if (!$rateObject->hasTaxPostcode()) {
113: $rateObject->setTaxPostcode(Mage::getStoreConfig(Mage_Tax_Model_Config::CONFIG_XML_PATH_DEFAULT_POSTCODE));
114: }
115:
116: $fieldset->addField('tax_postcode', 'text', array(
117: 'name' => 'tax_postcode',
118: 'label' => Mage::helper('tax')->__('Zip/Post Code'),
119: 'note' => Mage::helper('tax')->__("'*' - matches any; 'xyz*' - matches any that begins on 'xyz' and not longer than %d.", Mage::helper('tax')->getPostCodeSubStringLength()),
120: ));
121:
122: $fieldset->addField('zip_from', 'text', array(
123: 'name' => 'zip_from',
124: 'label' => Mage::helper('tax')->__('Range From'),
125: 'required' => true,
126: 'maxlength' => 9,
127: 'class' => 'validate-digits'
128: ));
129:
130: $fieldset->addField('zip_to', 'text', array(
131: 'name' => 'zip_to',
132: 'label' => Mage::helper('tax')->__('Range To'),
133: 'required' => true,
134: 'maxlength' => 9,
135: 'class' => 'validate-digits'
136: ));
137:
138: $fieldset->addField('rate', 'text', array(
139: 'name' => 'rate',
140: 'label' => Mage::helper('tax')->__('Rate Percent'),
141: 'title' => Mage::helper('tax')->__('Rate Percent'),
142: 'required' => true,
143: 'class' => 'validate-not-negative-number'
144: ));
145:
146: $form->setAction($this->getUrl('*/tax_rate/save'));
147: $form->setUseContainer(true);
148: $form->setId('rate_form');
149: $form->setMethod('post');
150:
151: if (!Mage::app()->isSingleStoreMode()) {
152: $form->addElement(Mage::getBlockSingleton('adminhtml/tax_rate_title_fieldset')->setLegend(Mage::helper('tax')->__('Tax Titles')));
153: }
154:
155: $rateData = $rateObject->getData();
156: if ($rateObject->getZipIsRange()) {
157: list($rateData['zip_from'], $rateData['zip_to']) = explode('-', $rateData['tax_postcode']);
158: }
159: $form->setValues($rateData);
160: $this->setForm($form);
161:
162: $this->setChild(
163: 'form_after',
164: $this->getLayout()->createBlock('adminhtml/widget_form_element_dependence')
165: ->addFieldMap('zip_is_range', 'zip_is_range')
166: ->addFieldMap('tax_postcode', 'tax_postcode')
167: ->addFieldMap('zip_from', 'zip_from')
168: ->addFieldMap('zip_to', 'zip_to')
169: ->addFieldDependence('zip_from', 'zip_is_range', '1')
170: ->addFieldDependence('zip_to', 'zip_is_range', '1')
171: ->addFieldDependence('tax_postcode', 'zip_is_range', '0')
172: );
173:
174: return parent::_prepareForm();
175: }
176: }
177: