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_Adminhtml_Tax_Class_CustomerController extends Mage_Adminhtml_Controller_Action
00036 {
00037
00038
00039
00040
00041 public function indexAction()
00042 {
00043 $this->_initAction()
00044 ->_addContent($this->getLayout()->createBlock('adminhtml/tax_class')->setClassType('CUSTOMER'))
00045 ->renderLayout();
00046 }
00047
00048
00049
00050
00051
00052 public function newAction()
00053 {
00054 $this->_forward('edit');
00055 }
00056
00057
00058
00059
00060
00061 public function editAction()
00062 {
00063 $classId = $this->getRequest()->getParam('id');
00064 $model = Mage::getModel('tax/class');
00065 if ($classId) {
00066 $model->load($classId);
00067 if (!$model->getId() || $model->getClassType() != 'CUSTOMER') {
00068 Mage::getSingleton('adminhtml/session')->addError(Mage::helper('tax')->__('This class no longer exists'));
00069 $this->_redirect('*/*/');
00070 return;
00071 }
00072 }
00073
00074 $data = Mage::getSingleton('adminhtml/session')->getClassData(true);
00075 if (!empty($data)) {
00076 $model->setData($data);
00077 }
00078
00079 Mage::register('tax_class', $model);
00080
00081 $this->_initAction()
00082 ->_addBreadcrumb($classId ? Mage::helper('tax')->__('Edit Class') : Mage::helper('tax')->__('New Class'), $classId ? Mage::helper('tax')->__('Edit Class') : Mage::helper('tax')->__('New Class'))
00083 ->_addContent($this->getLayout()->createBlock('adminhtml/tax_class_edit')->setData('action', $this->getUrl('*/tax_class/save'))->setClassType('CUSTOMER'))
00084 ->renderLayout();
00085 }
00086
00087
00088
00089
00090
00091 public function deleteAction()
00092 {
00093 $classId = $this->getRequest()->getParam('id');
00094 $classModel = Mage::getModel('tax/class')
00095 ->load($classId);
00096
00097 if (!$classModel->getId() || $classModel->getClassType() != 'CUSTOMER') {
00098 Mage::getSingleton('adminhtml/session')->addError(Mage::helper('tax')->__('This class no longer exists'));
00099 $this->_redirect('*/*/');
00100 return;
00101 }
00102
00103 $ruleCollection = Mage::getModel('tax/calculation_rule')
00104 ->getCollection()
00105 ->setClassTypeFilter('CUSTOMER', $classId);
00106
00107 if ($ruleCollection->getSize() > 0) {
00108 Mage::getSingleton('adminhtml/session')->addError(Mage::helper('tax')->__('You cannot delete this tax class as it is used in Tax Rules. You have to delete the rules it is used in first.'));
00109 $this->_redirectReferer();
00110 return;
00111 }
00112
00113 $customerGroupCollection = Mage::getModel('customer/group')
00114 ->getCollection()
00115 ->addFieldToFilter('tax_class_id', $classId);
00116 $groupCount = $customerGroupCollection->getSize();
00117
00118 if ($groupCount > 0) {
00119 Mage::getSingleton('adminhtml/session')->addError(Mage::helper('tax')->__('You cannot delete this tax class as it is used for %d customer groups.', $groupCount));
00120 $this->_redirectReferer();
00121 return;
00122 }
00123
00124 try {
00125 $classModel->delete();
00126
00127 Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('tax')->__('Tax class was successfully deleted'));
00128 $this->getResponse()->setRedirect($this->getUrl("*/*/"));
00129 return ;
00130 }
00131 catch (Mage_Core_Exception $e) {
00132 Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
00133 }
00134 catch (Exception $e) {
00135 Mage::getSingleton('adminhtml/session')->addError(Mage::helper('tax')->__('Error while deleting this class. Please try again later.'));
00136 }
00137
00138 $this->_redirectReferer();
00139 }
00140
00141
00142
00143
00144
00145
00146 protected function _initAction()
00147 {
00148 $this->loadLayout()
00149 ->_setActiveMenu('sales/tax/tax_class_customer')
00150 ->_addBreadcrumb(Mage::helper('tax')->__('Sales'), Mage::helper('tax')->__('Sales'))
00151 ->_addBreadcrumb(Mage::helper('tax')->__('Tax'), Mage::helper('tax')->__('Tax'))
00152 ->_addBreadcrumb(Mage::helper('tax')->__('Manage Customer Tax Classes'), Mage::helper('tax')->__('Manage Customer Tax Classes'))
00153 ;
00154 return $this;
00155 }
00156
00157
00158
00159
00160
00161
00162 protected function _isAllowed()
00163 {
00164 return Mage::getSingleton('admin/session')->isAllowed('sales/tax/classes_customer');
00165 }
00166 }