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: class Mage_Adminhtml_Block_Customer_Sales_Order_Address_Form_Renderer_Vat
35: extends Mage_Adminhtml_Block_Widget_Form_Renderer_Fieldset_Element
36: {
37: 38: 39: 40: 41:
42: protected $_validateButton = null;
43:
44: 45: 46:
47: protected function _construct()
48: {
49: $this->setTemplate('customer/sales/order/create/address/form/renderer/vat.phtml');
50: }
51:
52: 53: 54: 55: 56:
57: public function getValidateButton()
58: {
59: if (is_null($this->_validateButton)) {
60:
61: $form = $this->_element->getForm();
62:
63: $vatElementId = $this->_element->getHtmlId();
64:
65: $countryElementId = $form->getElement('country_id')->getHtmlId();
66: $validateUrl = Mage::getSingleton('adminhtml/url')
67: ->getUrl('*/customer_system_config_validatevat/validateAdvanced');
68:
69: $groupSuggestionMessage = Mage::helper('customer')->__('The customer is currently assigned to Customer Group %s.')
70: . ' ' . Mage::helper('customer')->__('Would you like to change the Customer Group for this order?');
71:
72: $vatValidateOptions = Mage::helper('core')->jsonEncode(array(
73: 'vatElementId' => $vatElementId,
74: 'countryElementId' => $countryElementId,
75: 'groupIdHtmlId' => 'group_id',
76: 'validateUrl' => $validateUrl,
77: 'vatValidMessage' => Mage::helper('customer')->__('The VAT ID is valid. The current Customer Group will be used.'),
78: 'vatValidAndGroupChangeMessage' => Mage::helper('customer')->__('Based on the VAT ID, the customer would belong to the Customer Group %s.')
79: . "\n" . $groupSuggestionMessage,
80: 'vatInvalidMessage' => Mage::helper('customer')->__('The VAT ID entered (%s) is not a valid VAT ID. The customer would belong to Customer Group %s.')
81: . "\n" . $groupSuggestionMessage,
82: 'vatValidationFailedMessage' => Mage::helper('customer')->__('There was an error validating the VAT ID. The customer would belong to Customer Group %s.')
83: . "\n" . $groupSuggestionMessage,
84: 'vatErrorMessage' => Mage::helper('customer')->__('There was an error validating the VAT ID.')
85: ));
86:
87: $optionsVarName = $this->getJsVariablePrefix() . 'VatParameters';
88: $beforeHtml = '<script type="text/javascript">var ' . $optionsVarName . ' = ' . $vatValidateOptions
89: . ';</script>';
90: $this->_validateButton = $this->getLayout()->createBlock('adminhtml/widget_button')->setData(array(
91: 'label' => Mage::helper('customer')->__('Validate VAT Number'),
92: 'before_html' => $beforeHtml,
93: 'onclick' => 'order.validateVat(' . $optionsVarName . ')'
94: ));
95: }
96: return $this->_validateButton;
97: }
98: }
99: