function getSum($periods, $glaccount_id = '', $glcentre_id = '') { $cc = new ConstraintChain(); // constrain glperiods_id by either a single, or an array of ids if (is_array($periods)) { $cc->add(new Constraint('glperiods_id', 'in', '(' . implode(',', $periods) . ')')); } else { $cc->add(new Constraint('glperiods_id', '=', $periods)); } // constrain glaccount_id if ($glaccount_id != '') { $cc->add(new Constraint('glaccount_id', '=', $glaccount_id)); } // constrain glcentre_id if ($glcentre_id != '') { $cc->add(new Constraint('glcentre_id', '=', $glcentre_id)); } return parent::getSum('value', $cc, 'gl_balances'); }