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)); }
public static function useDefault(&$search_data = null, &$errors = array(), $defaults = null) { $search = new glbalancesSearch($defaults); // Search by Account $search->addSearchField('glaccount_id', 'Account', 'multi_select', array(), 'advanced'); $glaccount = new GLAccount(); $search->setOptions('glaccount_id', $glaccount->getAll()); // Search by Centre $search->addSearchField('glcentre_id', 'Centre', 'multi_select', array(), 'advanced'); $glcentre = new GLCentre(); $search->setOptions('glcentre_id', $glcentre->getAll()); // Search by Period $currentPeriod = new GLPeriod(); $currentPeriod->getCurrentPeriod(); if ($currentPeriod) { $default_period = array($currentPeriod->id); } else { $default_period = array(); } $search->addSearchField('glperiods_id', 'Period', 'multi_select', $default_period, 'advanced'); $glperiod = new GLPeriod(); $search->setOptions('glperiods_id', $glperiod->getAll()); $search->setSearchData($search_data, $errors); return $search; }
public function _new() { parent::_new(); $account = $this->_uses[$this->modeltype]; $centres = new GLCentre(); $centres_list = $centres->getAll(); $this->view->set('centres', $centres_list); $this->view->set('actypes', $account->getEnumOptions('actype')); if ($account->isLoaded()) { $this->view->set('selected_centres', $account->getCentreIds()); $this->view->set('selected_actype', $account->getEnumValue('actype')); } else { $this->view->set('selected_centres', array()); $this->view->set('selected_actype', ''); } }