static function close($periodid, &$errors) { $result = false; $errors = array(); $period = DataObjectFactory::Factory('GLPeriod'); $period->load($periodid); if ($period->isLoaded()) { // Check for any unposted journals for the period to be closed $journal_header = DataObjectFactory::Factory('GLTransactionHeader'); $cc = new ConstraintChain(); $cc->add(new Constraint('glperiods_id', '=', $period->{$period->idField})); $cc->add(new Constraint('status', '=', $journal_header->newStatus())); $cc->add(new Constraint('type', '=', $journal_header->standardJournal())); if ($journal_header->getCount($cc) > 0) { $errors[] = 'Cannot close period due to unposted journals'; return FALSE; } // Ensure all assets are depreciated for the the period assetHandling::depreciateAll($errors); // Close the period if no errors if (count($errors) === 0) { $result = $period->update($period->id, 'closed', 'true'); } if ($result) { // Rollup year-to-datebalances $periodendbalances = new GLPeriodEndBalanceCollection(DataObjectFactory::Factory('GLPeriodEndBalance')); if ($periodendbalances->create($period) === FALSE) { $errors[] = 'Error creating period end balances'; } } else { $errors[] = 'Error closing period'; } // Create the new period for next year $newperiod = DataObjectFactory::Factory('GLPeriod'); $nextyear = date(DATE_FORMAT, strtotime('+12 months', strtotime($period->enddate))); $newperiod->loadPeriod($nextyear); if ($result && count($errors) === 0 && !$newperiod->isLoaded()) { if (!self::createNew($period, $errors)) { $errors[] = 'Error creating new period for next year'; } } // If closing last period of the year, do year end $glparams = DataObjectFactory::Factory('GLParams'); if (!is_numeric($glparams->number_of_periods_in_year())) { $errors[] = 'GL Parameters No.of periods in year not defined'; } if ($result && count($errors) === 0 && $period->period == $glparams->number_of_periods_in_year()) { self::yearEnd($period, $errors); } return $period; } else { $errors[] = 'Error loading period details'; return false; } }
public function depreciation() { $flash = Flash::Instance(); $db = DB::Instance(); $errors = array(); $db->StartTrans(); if (isset($this->_data['id'])) { assetHandling::depreciateOne($this->_data['id'], $errors); } else { assetHandling::depreciateAll($errors); } if (count($errors) > 0) { $flash->addErrors($errors); $db->FailTrans(); } else { $db->CompleteTrans(); } if (isset($this->_data['id'])) { sendTo($this->name, 'view', $this->_modules, array('id' => $this->_data['id'])); } else { sendTo($this->name, 'index', $this->_modules); } }