public function glbalance() { // return last unclosed period, year $glperiod = DataObjectFactory::Factory('GLPeriod'); $glperiod->getCurrentPeriod(); $year = $glperiod->year; // get future periods from the last period 0 $temp_future_periods = $glperiod->getFuturePeriods(-1, $year); // reconstruct periods array, as we cannot send a value (year + period), but period_id $future_periods = array_keys($temp_future_periods); array_fill_keys($future_periods, NULL); // get sum of periods $sum = GLBalance::getSum($future_periods, $this->_data['glaccount_id'], $this->_data['glcentre_id']); return $sum; }
public function updateBalance(&$errors = array()) { $db = DB::Instance(); $db->StartTrans(); $glbalance = DataObjectFactory::Factory('GLBalance'); $cc = new ConstraintChain(); // then we start a chain $cc->add(new Constraint('glaccount_id', '=', $this->glaccount_id)); $cc->add(new Constraint('glcentre_id', '=', $this->glcentre_id)); $cc->add(new Constraint('glperiods_id', '=', $this->glperiods_id)); $glbalance = $glbalance->loadby($cc); $data = array(); $data['glaccount_id'] = $this->glaccount_id; $data['glcentre_id'] = $this->glcentre_id; $data['glperiods_id'] = $this->glperiods_id; $data['value'] = $this->value; $data['lastupdated'] = $glbalance->lastupdated; //concurrency control if ($glbalance !== false) { $data['id'] = $glbalance->id; $data['value'] = bcadd($data['value'], $glbalance->value); } $newerrors = array(); $glbalance = GLBalance::Factory($data, $newerrors, 'GLBalance'); if (count($newerrors) > 0) { $errors += $newerrors; $db->FailTrans(); } elseif ($glbalance !== false) { $result = $glbalance->save(); if ($result === false) { $errors[] = 'Error updating GL Balance : ' . ${$db}->ErrorMsg(); $db->FailTrans(); } } return $db->CompleteTrans(); }