Example #1
0
 public function _new()
 {
     $flash = Flash::Instance();
     $errors = array();
     $glaccounts = new GLAccount();
     if ($glaccounts->getCount() == 0) {
         $errors[] = 'No GL Accounts defined';
     }
     $glcentres = new GLCentre();
     if ($glcentres->getCount() == 0) {
         $errors[] = 'No GL Centres defined';
     }
     if (count($errors) > 0) {
         $flash->addErrors($errors);
         sendback();
     }
     parent::_new();
     $currency = $this->_uses[$this->modeltype];
     $glaccounts = $glaccounts->getAll();
     if (isset($_POST[$this->modeltype]['writeoff_glaccount_id'])) {
         $default_glaccount_id = $_POST[$this->modeltype]['writeoff_glaccount_id'];
     } elseif (isset($this->_data['writeoff_glaccount_id'])) {
         $default_glaccount_id = $this->_data['writeoff_glaccount_id'];
     } elseif ($currency->isLoaded()) {
         $default_glaccount_id = $currency->writeoff_glaccount_id;
     } else {
         $default_glaccount_id = key($glaccounts);
     }
     $this->view->set('glcentres', $this->getCentres($default_glaccount_id));
 }