<?php
class TaxGroupsController extends AppController {

	var $name = 'TaxGroups';
var $uses = array('TaxGroup');
var $components = array('RequestHandler');

	function index() {
		$this->TaxGroup->recursive = 0;
		$this->set('items', $this->paginate());
	}

	function view($id = null) {
		if (!$id  || !($item = $this->TaxGroup->read(null, $id))) {
			$this->Session->setFlash(__('Invalid TaxGroup', true) . ($id ? " #{$id}" : ""), 'default', array('class' => 'error'));
			$this->redirect(array('action' => 'index'));
		}
		$this->set('item', $item);
	}

	function add() {
		if (!empty($this->data)) {
			$this->TaxGroup->create();
			if ($this->TaxGroup->save($this->data)) {
				$this->Session->setFlash(__('The Tax group has been saved', true), 'default', array('class' => 'success'));
		   //$x=$this->params['isAjax'];		
  if ($this->RequestHandler->isAjax()) {
  //die(print_r($this->params['nyro']));		
  $this->nyro = array(
						'close' => true, 'reload' => false, 'hide_content' => true,
						'js_callback' => 'after_add_Tax_group',
						'js_callback_param' => $this->TaxGroup->read(null, $this->TaxGroup->getLastInsertID()),
					);
				} 			

			else
			
			$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The Tax group could not be saved. Please, try again.', true), 'default', array('class' => 'error'));
			}
		}
		$products = $this->TaxGroup->Product->getGrouped();
		$this->set(compact('products'));
	}

	function edit($id = null) {
		if ((!$id && empty($this->data)) || ($id && !($item = $this->TaxGroup->read(null, $id)))) {
			$this->Session->setFlash(__('Invalid TaxGroup', true) . ($id ? " #{$id}" : ""), 'default', array('class' => 'error'));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			$this->TaxGroup->data = null;	// unset model data so modified field can be updated automagically
			if ($this->TaxGroup->save($this->data)) {
				$this->Session->setFlash(__('The Tax group has been saved', true), 'default', array('class' => 'success'));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The Tax group could not be saved. Please, try again.', true), 'default', array('class' => 'error'));
			}
		}
		if (empty($this->data)) {
			$this->data = $item;
		}
		$products = $this->TaxGroup->Product->getGrouped();
		$this->set(compact('products'));
	}

	function delete($id = null) {
		if (!$id || !$this->TaxGroup->read(null, $id)) {
			$this->Session->setFlash(__('Invalid TaxGroup', true) . ($id ? " #{$id}" : ""), 'default', array('class' => 'error'));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->TaxGroup->delete($id)) {
			$this->Session->setFlash(__('TaxGroup deleted', true), 'default', array('class' => 'success'));
			$this->redirect(array('action'=>'index'));
		}
		$this->Session->setFlash(__('TaxGroup delete failed. Please, try again.', true), 'default', array('class' => 'error'));
		$this->redirect(array('action' => 'index'));
	}
}
?>