public function countRecords($module, array $whereCriteras = array(), $deleted = false)
    {
        $bean = $this->getBean($module);
        // build the where
        $where = ($deleted ? 'WHERE 1 = 1' : 'WHERE deleted = 0');
        if (!empty($whereCriteras)) {
            $where.= ' AND ' . implode(' AND ', $whereCriteras);
        }
        $this->getLogger()->info($this->logPrefix . "Going to count the record with '{$where}'.");

        // shot the query
        $sql = "SELECT * FROM {$bean->table_name} $where";
        $countSql = $bean->create_list_count_query($sql);
        $countRes = (int)$bean->db->getOne($countSql);

        if ($bean->db->database->error) {
            throw new \RuntimeException('The query to Count records failed');
        }

        if ($countRes === 0) {
            $this->getLogger()->info($this->logPrefix . "Query '$sql' gave 0 result.");
        }

        return $countRes;
    }