'HTML Representation'

def html(self, r, **attr):

    T = current.T
    s3db = current.s3db
    response = current.response
    NONE = current.messages['NONE']
    record = r.record
    (dates, years, goals) = self._extract(r, **attr)
    colspan = (((2 * len(dates)) + (2 * len(years))) + 3)
    header_row = TR(TD(T('Number'), _rowspan=2, _class='tal'), TD(T('Indicators'), _rowspan=2, _class='tal'), TD(T('Total    Target'), _rowspan=2))
    if (not years):
        item = TABLE(header_row, _class='indicator_summary_report')
        response.warning = T('No    Indicator    Data    available')
    else:
        happend = header_row.append
        represent = s3db.project_indicator_data.end_date.represent
        y = 0
        year = years[y]
        for d in dates:
            if (d.year != year):
                happend(TD(year, _colspan=2))
                y += 1
                year = years[y]
            happend(TD(represent(d), _colspan=2))
        happend(TD(year, _colspan=2))
        happend(TD(T('Actual    Total'), _rowspan=2))
        happend(TD(T('%    Achieved'), _rowspan=2))
        item = TABLE(header_row, _class='indicator_summary_report')
        iappend = item.append
        row_2 = TR()
        rappend = row_2.append
        TARGET = T('Target')
        ACTUAL = T('Actual')
        for d in dates:
            rappend(TD(TARGET))
            rappend(TD(ACTUAL))
        for y in years:
            rappend(TD(TARGET))
            rappend(TD(ACTUAL))
        iappend(row_2)
        for goal_id in goals:
            goal = goals[goal_id]
            row = TR(TD(('%s:    %s' % (T('Goal'), goal['code'])), _class='tal'), TD(goal['name'], _class='tal', _colspan=colspan), TD(project_status_represent(goal['status'])), _class='project_goal')
            iappend(row)
            outcomes = goal['outcomes']
            for outcome_id in outcomes:
                outcome = outcomes[outcome_id]
                row = TR(TD(('%s:    %s' % (T('Outcome'), outcome['code'])), _class='tal'), TD(outcome['name'], _class='tal', _colspan=colspan), TD(project_status_represent(outcome['status'])), _class='project_outcome')
                iappend(row)
                outputs = outcome['outputs']
                for output_id in outputs:
                    output = outputs[output_id]
                    row = TR(TD(('%s:    %s' % (T('Output'), output['code'])), _class='tal'), TD(output['name'], _class='tal', _colspan=colspan), TD(project_status_represent(output['status'])), _class='project_output')
                    iappend(row)
                    indicators = output['indicators']
                    for i in indicators:
                        indicator = indicators[i]
                        row = TR(TD(('%s:    %s' % (T('Indicator'), indicator['code'])), _class='tal'), TD(indicator['name'], _class='tal'), _class='project_indicator')
                        rappend = row.append
                        rappend(TD(indicator['target']))
                        y = 0
                        year = years[y]
                        for d in dates:
                            if (d.year != year):
                                iyear = indicator['years'].get(year)
                                if iyear:
                                    rappend(TD(iyear['target']))
                                    rappend(TD(iyear['actual']))
                                else:
                                    rappend(TD(NONE))
                                    rappend(TD(NONE))
                                y += 1
                                year = years[y]
                            date = indicator['dates'].get(d)
                            if date:
                                rappend(TD(date['target']))
                                rappend(TD(date['actual']))
                            else:
                                rappend(TD(NONE))
                                rappend(TD(NONE))
                        iyear = indicator['years'].get(year)
                        if iyear:
                            rappend(TD(iyear['target']))
                            rappend(TD(iyear['actual']))
                        else:
                            rappend(TD(NONE))
                            rappend(TD(NONE))
                        rappend(TD(indicator['actual']))
                        rappend(TD(project_status_represent(indicator['status'])))
                        iappend(row)
        iappend(TR(TD(T('Overall    Project    Status'), _colspan=(colspan + 1), _class='tar'), TD(project_status_represent(record.overall_status_by_indicators))))
    output = dict(item=item)
    output['title'] = T('Summary    of    Progress    Indicators    for    Outcomes    and    Indicators')
    output['subtitle'] = ('%s:    %s' % (T('Project'), s3db.project_project_represent(None, record)))
    if ('rheader' in attr):
        rheader = attr['rheader'](r)
        if rheader:
            output['rheader'] = rheader
    response.view = 'simple.html'
    response.s3.jquery_ready.append("$('.custom-export').on('click',    function()    {var    url    =    $(this).data('url');window.open(url)})")
    return output
