<!-- BEGIN {$smarty.template} -->


<script type="text/javascript">
    {literal}
    $(document).ready(function() { 

            var prjplot = null;
            var peplot = null;
            var ocplot = null;

            $.getJSON("data_service.php?req=summary&type=prj", function(data) { prjplot = get_simple_bar_chart('sumprj', data); });
            $.getJSON("data_service.php?req=summary&type=pe", function(data) { peplot = get_simple_bar_chart('sumpe', data); });
            $.getJSON("data_service.php?req=opcat", function(data) { ocplot = get_opcat_plot('allopcat', data); });

            {/literal}{foreach from=$summary.customers item=cust}{literal}
            var cu{/literal}{$cust.curr_id}{literal}plot=null;
            $.getJSON("data_service.php?req=summary&type=cu&{/literal}curr_id={$cust.curr_id}{literal}", 
                function(data) { cu{/literal}{$cust.curr_id}{literal}plot=get_simple_bar_chart('sumcu{/literal}{$cust.curr_name}{literal}', data); }
                );
            {/literal}{/foreach}{literal}



            $("#tab_container").tabs();
            $('#tab_container').bind('tabsshow', function(event, ui) {
               if (ui.panel.id == "sum-projects")
                    prjplot.replot();
                if (ui.panel.id == "sum-persons")
                    peplot.replot();
                if (ui.panel.id == "sum-opcat")
                    ocplot.replot();
                if (ui.panel.id == "sum-customers") {
                    {/literal}{foreach from=$summary.customers item=cust}{literal}
                    cu{/literal}{$cust.curr_id}{literal}plot.replot();
                    {/literal}{/foreach}{literal}
                }
                });
    });
{/literal}
</script>

<h2>{t}Summary{/t}</h2>

<div id="tab_container">
    <ul class="tab_items">
        <li><a href="#sum-projects" rel="sum-projects">{t}Projects{/t}</a></li>
        <li><a href="#sum-persons" rel="sum-persons">{t}Persons{/t}</a></li>
        <li><a href="#sum-opcat" rel="sum-opcat">{t}Task categories{/t}</a></li>
        <li><a href="#sum-customers" rel="sum-customers">{t}Customers{/t}</a></li>
    </ul>

    <div id="sum-projects" class="tab_content">


        {if (count($summary.projects.rows) > 0)}
        <div class="floatcontainer">

            <div id="sumprj" class="sumchart flleft"></div>

            <table class="summary w20 flleft" cellspacing="0">
                <caption><em>{t}Projects{/t}</em><a name="projects"></a></caption>
                <thead>
                    <tr>
                        <th rowspan="2"> {t}Project{/t} </th>
                        <th colspan="3" class="c"> {t}Duration{/t} </th>
                        <th colspan="3" class="c"> {t}Manhours costs{/t} </th>
                        <th colspan="3" class="c"> {t}Material costs{/t} </th>
                        <th colspan="3" class="c"> {t}Total costs{/t} </th>
                    </tr>
                    <tr>
                        <th class="time"> {t}Planned{/t} </th>
                        <th class="time"> {t}Tracked{/t} </th>
                        <th class="time"> % </th>
                        <th class="time"> {t}Planned{/t} </th>
                        <th class="time"> {t}Tracked{/t} </th>
                        <th class="time"> % </th>
                        <th class="time"> {t}Planned{/t} </th>
                        <th class="time"> {t}Tracked{/t} </th>
                        <th class="time"> % </th>
                        <th class="time"> {t}Planned{/t} </th>
                        <th class="time"> {t}Tracked{/t} </th>
                        <th class="time"> % </th>
                    </tr>
                </thead>
                <tbody>
                    {section name=r loop=$summary.projects.rows}
                    <tr>
                        <td> <a href="project.php?id={$summary.projects.rows[r].prj_id}">{$summary.projects.rows[r].prj_title|wash}</a></td>
                        <td class="time"> {if ($summary.projects.rows[r].prj_planned_manhours > 0)}{$summary.projects.rows[r].prj_planned_manhours|phpaga_minutes2duration}{else}&nbsp;{/if} </td>
                        <td class="time"> {$summary.projects.rows[r].prj_tracked_manhours|phpaga_minutes2duration|default:"&nbsp;"} </td>
                        <td class="rb number{if $summary.projects.rows[r].prj_perc_manhours > 100} warn{/if}"> {$summary.projects.rows[r].prj_perc_manhours|phpaga_formatpercentage|default:"&nbsp;"} </td>

                        <td class="time"> {$summary.projects.rows[r].prj_planned_cost_manhours|phpaga_formatamount|default:"&nbsp;"} </td>
                        <td class="time"> {$summary.projects.rows[r].prj_tracked_cost_manhours|phpaga_formatamount|default:"&nbsp;"} </td>
                        <td class="rb number{if $summary.projects.rows[r].prj_perc_cost_manhours > 100} warn{/if}"> {$summary.projects.rows[r].prj_perc_cost_manhours|phpaga_formatpercentage|default:"&nbsp;"} </td>

                        <td class="time"> {$summary.projects.rows[r].prj_planned_cost_material|phpaga_formatamount|default:"&nbsp;"} </td>
                        <td class="time"> {$summary.projects.rows[r].prj_tracked_cost_material|phpaga_formatamount|default:"&nbsp;"} </td>
                        <td class="rb number{if $summary.projects.rows[r].prj_perc_cost_material > 100} warn{/if}"> {$summary.projects.rows[r].prj_perc_cost_material|phpaga_formatpercentage|default:"&nbsp;"} </td>

                        <td class="time sumrow"> {if ($summary.projects.rows[r].planned_cost_total > 0)}{$summary.projects.rows[r].planned_cost_total|phpaga_formatamount}{else}&nbsp;{/if} </td>
                        <td class="time sumrow"> {$summary.projects.rows[r].tracked_cost_total|phpaga_formatamount|default:"&nbsp;"} </td>
                        <td class="number{if $summary.projects.rows[r].perc_cost_total > 100} warn{/if}"> {$summary.projects.rows[r].perc_cost_total|phpaga_formatpercentage|default:"&nbsp;"} </td>

                    </tr>
                    {/section}
                </tbody>
                <tfoot>
                    <tr class="summary r">
                        <td>&nbsp;</td>
                        <td> {$summary.projects.planned_duration|phpaga_minutes2duration|default:"&nbsp;"} </td>
                        <td> {$summary.projects.tracked_duration|phpaga_minutes2duration|default:"&nbsp;"} </td>
                        <td> &nbsp; </td>
                        <td> {$summary.projects.planned_cost_manhours|phpaga_formatamount|default:"&nbsp;"} </td>
                        <td> {$summary.projects.tracked_cost_manhours|phpaga_formatamount|default:"&nbsp;"} </td>
                        <td> &nbsp; </td>
                        <td> {$summary.projects.planned_cost_material|phpaga_formatamount|default:"&nbsp;"} </td>
                        <td> {$summary.projects.tracked_cost_material|phpaga_formatamount|default:"&nbsp;"} </td>
                        <td> &nbsp; </td>
                        <td> {$summary.projects.planned_cost_total|phpaga_formatamount|default:"&nbsp;"} </td>
                        <td> {$summary.projects.tracked_cost_total|phpaga_formatamount|default:"&nbsp;"} </td>
                        <td> &nbsp; </td>
                    </tr>
                </tfoot>
            </table>

        </div>
        <div class="spacer"></div>
        {/if}
    </div>

    <div id="sum-persons" class="tab_content">
        {if (count($summary.persons.rows) > 0)}
        <div class="floatcontainer">

            <table class="summary w20 flleft" cellspacing="0">
                <caption><em>{t}Persons{/t}</em><a name="persons"></a></caption>
                <thead>
                    <tr>
                        <th> {t}Person{/t} </th>
                        <th class="time"> {t}Duration{/t} </th>
                    </tr>
                </thead>
                <tbody>
                    {section name=p loop=$summary.persons.rows}
                    <tr>
                        <td> <a href="person.php?id={$summary.persons.rows[p].pe_id}">{$summary.persons.rows[p].pe_person|wash}</a></td>
                        <td class="time"> {$summary.persons.rows[p].sum_duration|phpaga_minutes2duration|default:"&nbsp;"} </td>
                    </tr>
                    {/section}
                </tbody>
                <tfoot>
                    <tr class="summary">
                        <td colspan="2" class="time"> {$summary.persons.duration|phpaga_minutes2duration|default:"&nbsp;"} </td>
                    </tr>
                </tfoot>
            </table>
            <div id="sumpe" class="sumchart flleft"></div>


        </div>
        <div class="spacer"></div>
        {/if}
    </div>

    <div id="sum-opcat" class="tab_content">

        {if (count($summary.opcats.rows) > 0)}
        <div class="floatcontainer">

            <table class="opcat w20 flleft" cellspacing="0">
                <caption><em>{t}Task categories{/t}</em><a name="opcat"></a></caption>
                <thead>
                    <tr>
                        <th> {t}Task category{/t} </th>
                        <th class="time"> {t}Duration{/t} </th>
                    </tr>
                </thead>
                <tbody>
                    {section name=o loop=$summary.opcats.rows}
                    <tr>
                        <td> {$summary.opcats.rows[o].opcat_title|wash}</td>
                        <td class="time"> {$summary.opcats.rows[o].sum_duration|phpaga_minutes2duration|default:"&nbsp;"} </td>
                    </tr>
                    {/section}
                </tbody>
                <tfoot>
                    <tr class="summary">
                        <td colspan="2" class="time"> {$summary.opcats.duration|phpaga_minutes2duration|default:"&nbsp;"} </td>
                    </tr>
                </tfoot>
            </table>

            <div id="allopcat" class="opcatchart flleft"></div>
        </div>
        <div class="spacer"></div>
        {/if}
    </div>


    <div id="sum-customers" class="tab_content">
        {if (count($summary.customers) > 0)}
        <div class="dcaption"><em>{t}Invoiced per customer and currency{/t}</em><a name="customers"></a>&nbsp;</div>


        {foreach from=$summary.customers item=cust}
        <div class="floatcontainer">

            <table class="summary w20 flleft" cellspacing="0">
                <caption><em>{t}Currency{/t}: {$cust.curr_name}</em></caption>
                <thead>
                    <tr>
                        <th> {t}Customer{/t} </th>
                        <th class="number"> {t}Invoiced{/t} </th>
                    </tr>
                </thead>
                <tbody>
                    {section name=cu loop=$cust.rows}
                    <tr>
                        <td> <a href="company.php?id={$cust.rows[cu].cpn_id}">{$cust.rows[cu].cpn_name|wash}</a></td>
                        <td class="number nowrap"> {$cust.rows[cu].sum_amount|phpaga_formatamount|default:"&nbsp;"} {$cust.rows[cu].curr_name|default:"&nbsp;"} </td>
                    </tr>
                    {/section}
                </tbody>
                <tfoot>
                    <tr class="summary">
                        <td colspan="2" class="time">{$cust.amount|phpaga_formatamount|default:"&nbsp;"} {$cust.curr_name}</td>
                    </tr>
                </tfoot>
            </table>

            <div id="sumcu{$cust.curr_name}" class="sumchart flleft"></div>

        </div>
        <div class="spacer"></div>
        {/foreach}

        {/if}
    </div>
</div>

<!-- END {$smarty.template} -->
