Exemplo n.º 1
0
 public static function useDefault($search_data = null, &$errors = array(), $defaults = null)
 {
     $search = new VatSearch($defaults);
     $search->addSearchField('box', 'Box', 'hidden', '', 'hidden');
     $default_year = date('Y');
     $default_tax_period = 1;
     $glperiod = GLPeriod::getPeriod(date('Y-m-d'));
     if ($glperiod && count($glperiod) > 0) {
         $default_year = $glperiod['year'];
         $default_tax_period = $glperiod['tax_period'];
     }
     $search->addSearchField('year', 'Year', 'select', $default_year, 'basic');
     $search->addSearchField('tax_period', 'Tax Period', 'select', $default_tax_period, 'basic');
     $glperiods = new GLPeriodCollection();
     $sh = new SearchHandler($glperiods, false);
     $sh->setOrderBy('year');
     $glperiods->load($sh);
     $glperiods = $glperiods->getContents();
     $options = array();
     foreach ($glperiods as $glperiod) {
         if (!array_key_exists($glperiod->year, $options)) {
             $options[$glperiod->year] = $glperiod->year;
         }
     }
     $search->setOptions('year', $options);
     $tax_periods = GLPeriod::getTaxPeriods();
     $options = array_combine($tax_periods, $tax_periods);
     $search->setOptions('tax_period', $options);
     $search->setSearchData($search_data, $errors);
     return $search;
 }
Exemplo n.º 2
0
 public function inputDataGrid()
 {
     // THIS ISN'T GENERIC, BUT IT PROBABLY SHOULD BE :-)
     // set variables
     $flash = Flash::Instance();
     $errors = array();
     $basic_search = array();
     $rows = array();
     $cols = array();
     if (isset($_SESSION['di_search'])) {
         $this->_data['Search'] = $_SESSION['di_search'];
         unset($_SESSION['di_search']);
     }
     // search
     // get years
     $years_collection = new GLBudgetYearCollection(new GLBudgetYear());
     $sh = new SearchHandler($years_collection, false);
     $sh->setOrderby('year');
     $years_collection->load($sh);
     // construct years array for search
     foreach ($years_collection->getArray() as $key => $value) {
         $years[$value['year']] = $value['year'];
     }
     // get / set current selected year
     if (isset($this->_data['Search']['year']) && !isset($this->_data['Search']['clear'])) {
         $current_year = $this->_data['Search']['year'];
     } else {
         $current_year = key($years);
     }
     $basic_search['year'] = $current_year;
     if (empty($years)) {
         $errors[] = "No years to base data on";
     }
     if (empty($errors)) {
         // get centres
         $centres_collection = new GLCentreCollection(new GLCentre());
         $sh = new SearchHandler($centres_collection, false);
         $sh->setOrderby('cost_centre');
         $centres_collection->load($sh);
         // construct centres array for search
         $centres = array();
         foreach ($centres_collection->getArray() as $key => $value) {
             $centres[$value['id']] = $value['cost_centre'] . " - " . $value['description'];
         }
         // get / set current selected centre
         if (isset($this->_data['Search']['centres']) && !isset($this->_data['Search']['clear'])) {
             $current_centre = $this->_data['Search']['centres'];
         } else {
             $current_centre = key($centres);
         }
         $basic_search['centres'] = $current_centre;
         if (empty($centres)) {
             $errors[] = "No centres to base data on";
         }
     }
     if (empty($errors)) {
         // columns
         $column = new GLPeriodCollection(new GLPeriod());
         $sh = new SearchHandler($column, false);
         $sh->addConstraint(new Constraint('year', '=', $current_year));
         $sh->setOrderby('period');
         $column->load($sh);
         $cols = $column->getArray();
         $glperiod_ids = array();
         if (!empty($cols)) {
             foreach ($cols as $key => $value) {
                 $glperiod_ids[] = $value['id'];
             }
         }
         if (empty($glperiod_ids)) {
             $errors[] = "No periods to base data on";
         }
     }
     if (empty($errors)) {
         // rows
         $row = new GLAccountCentreCollection(new GLAccountCentre());
         $sh = new SearchHandler($row, false);
         $sh->addConstraint(new Constraint('glcentre_id', '=', $current_centre));
         $sh->setOrderby('glaccount');
         $row->load($sh);
         $rows = $row->getArray();
         $glaccount_ids = array();
         if (!empty($rows)) {
             foreach ($rows as $key => $value) {
                 $glaccount_ids[] = $value['glaccount_id'];
             }
         }
         if (empty($glaccount_ids)) {
             $errors[] = "No accounts to base data on";
         }
     }
     if (empty($errors)) {
         // grid data
         $data_collection = new GLBudgetCollection(new GLBudget());
         $sh = new SearchHandler($data_collection, false);
         $sh->addConstraint(new Constraint('glcentre_id', '=', $current_centre));
         $sh->addConstraint(new Constraint('glaccount_id', 'IN', '(' . implode(',', $glaccount_ids) . ')'));
         $sh->addConstraint(new Constraint('glperiods_id', 'IN', '(' . implode(',', $glperiod_ids) . ')'));
         $data_collection->load($sh);
         $data_arr = $data_collection->getArray();
         $data = array();
         if (count($data_arr) > 0) {
             foreach ($data_arr as $key => $value) {
                 $data[$value['glperiods_id']][$value['glaccount_id']] = array('value' => $value['value'], 'id' => $value['id']);
             }
         }
     }
     if (!empty($errors)) {
         $flash->addErrors($errors);
         $this->view->set('errors', true);
     }
     // search
     $search = new BaseSearch();
     $search->addSearchField('year', 'Year', 'select', $current_year, 'basic');
     $search->setOptions('year', $years);
     $search->addSearchField('centres', 'GL Centres', 'select', $current_centre, 'basic');
     $search->setOptions('centres', $centres);
     // output vars
     $this->view->set('basic_search', $basic_search);
     $this->view->set('search', $search);
     $this->view->set('columns', $cols);
     $this->view->set('rows', $rows);
     $this->view->set('data', $data);
     $this->view->set('do_name', 'GLBudgetCollection');
     $this->view->set('search_centre', $current_centre);
 }
Exemplo n.º 3
0
 static function createPeriods(&$errors)
 {
     $period = DataObjectFactory::Factory('GLPeriod');
     $period->getCurrentPeriod();
     // Get the current period
     if (!$period->isLoaded()) {
         // If it doesn't exist, get the most recent period
         $period->getMaximumPeriod();
     }
     $glparams = DataObjectFactory::Factory('GLParams');
     // If the loaded period is less than the number of periods in the year
     // assume that we want to create periods for this year
     if ($period->period < $glparams->number_of_periods_in_year()) {
         $startperiod = $period->period + 1;
         $oldyear = $period->year - 1;
     } else {
         // otherwise we want to create periods for next year
         $startperiod = 1;
         $oldyear = $period->year;
     }
     // Get all the periods for the latest existing year
     $currentperiods = new GLPeriodCollection(DataObjectFactory::Factory('GLPeriod'));
     $sh = new SearchHandler($currentperiods, false);
     $sh->addConstraint(new Constraint('period', '>=', $startperiod));
     $sh->addConstraint(new Constraint('year', '=', $oldyear));
     $currentperiods->load($sh);
     foreach ($currentperiods as $current) {
         // create new periods 12 months on from the existing
         $result = self::createNew($current, $errors);
         if (!$result || count($errors) > 0) {
             break;
         }
     }
 }