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

<form action="{$FORM_ACTION}" method="get">
  <fieldset class="search">
    <legend>{t}Select fiscal year and currency{/t}</legend>

    <label>{t}Fiscal year{/t}:</label>
    {html_select_date reverse_years=true time=$time start_year=$minYear end_year=$maxYear display_months=false display_days=false prefix=fin_}
    <br>

    <label for="curr_id">{t}Currency{/t}:</label>
    <select id="curr_id" name="curr_id">
      {html_options options=$currencies selected=$curr_id}
    </select>
    <br>

    <input type="submit" value="{t}Search{/t}">
  </fieldset>
</form>

{if !count($cpndetails.details)}
<div class="msg">{t}No data matching your search criteria was found.{/t}</div>
{else}
<script type="text/javascript" >
    {literal}
    $(document).ready(function() { 
        $.getJSON("data_service.php?req=fin_bpc&year={/literal}{$YEAR}&currency={$CURRENCY}{literal}", 
            function(data) { get_pie_chart('bpc', data); 
        });

        $.getJSON("data_service.php?req=fin_bprpm&year={/literal}{$YEAR}&currency={$CURRENCY}{literal}", 
            function(data) { get_multi_bar_chart('bprpm', data); 
        });
    });
    {/literal}
</script>

<div class="dcaption"><em>{t escape="0" 1=$curr_name 2=$YEAR 3=$fy_dates.start 4=$fy_dates.end}Amounts invoiced and received in %1, FY %2 (%3-%4){/t}</em>&nbsp;</div>

<div class="floatcontainer">
    <div id="bpc" class="bpcchart flleft"></div>
    <div id="bprpm" class="bpcchart flleft"></div>
</div>
<div class="spacer"></div>

{if count($cpndetails) > 0}
<table cellspacing="0">
    <caption><em>{t}Per customer{/t}</em></caption>
    <thead>
        <tr>
            <th> {t}Customer{/t} </th>
            <th class="number"> {t escape="0" 1=$YEAR}Invoiced in FY %1{/t} </th>
            <th class="number"> {t escape="0" 1=$YEAR}Received in FY %1{/t} </th>
            <th class="number"> {t}Still unpaid{/t} </th>
        </tr>
    </thead>
    <tbody>
        {section name=i loop=$cpndetails.details}
        <tr>
            <td class="desc"> <a href="company.php?id={$cpndetails.details[i].cpn_id}">{$cpndetails.details[i].cpn_name|wash}</a> </td>
            <td class="number"> {$config.MONETARY_SYMBOL|wash}{$cpndetails.details[i].sum_billed|phpaga_formatamount} </td>
            <td class="number"> {$config.MONETARY_SYMBOL|wash}{$cpndetails.details[i].sum_paid|phpaga_formatamount} </td>
            <td class="number"> {$config.MONETARY_SYMBOL|wash}{$cpndetails.details[i].sum_missing|phpaga_formatamount} </td>
        </tr>
        {/section}
    </tbody>
    <tfoot>
        <tr class="summary">
            <td class="desc"> {t}Totals{/t} </td>
            <td class="number"> {$config.MONETARY_SYMBOL|wash}{$cpndetails.totals.billed|phpaga_formatamount} </td>
            <td class="number"> {$config.MONETARY_SYMBOL|wash}{$cpndetails.totals.paid|phpaga_formatamount} </td>
            <td class="number"> {$config.MONETARY_SYMBOL|wash}{$cpndetails.totals.missing|phpaga_formatamount} </td>
        </tr>
    </tfoot>
</table>
{/if}
{/if}

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