<?php

class ModelGLCOA extends HModel {

    protected function getTable() {
        return 'coa_level3';
    }

    protected function getView() {
        return 'vw_coa';
    }

    protected function getPrimaryKey() {
        return 'coa_id';
    }

    public function getCOAs($filter=array(), $sort_order=array()) {
        $sql = "SELECT *";
        $sql .= " FROM " . DB_PREFIX . 'vw_gl0_coa_all';
        if($filter) {
            if(is_array($filter)) {
                //$table_columns = $this->getTableColumns($this->getTable());
                $implode = array();
                foreach($filter as $column => $value) {
                    //if(in_array($column,$table_columns)) {
                    $implode[] = "`$column`='$value'";
                    //}
                }
                if($implode)
                    $sql .= " WHERE " . implode(" AND ", $implode);
            } else {
                $sql .= " WHERE " . $filter;
            }
        }

        if($sort_order) {
            $sql .= " ORDER BY " . implode(',',$sort_order);
        }
        //d("ME HERE");
        $query = $this->conn->query($sql);
        return $query->rows;
    }
}

?>