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

{if phpaga_user_hasperm($smarty.const.PHPAGA_PERM_MANAGE_INVOICES) and !$percustomer}
{literal}
<script type="text/javascript">

    $(document).ready(function() {

            $('.createinvoice').click(function() { 

                p = $(this).parent().attr('title');

                prj_id = p.replace(/\|.*$/, '');
                cpn_id = p.replace(/^.*\|/, '');

                $("#prj_id").val(prj_id);
                $("#cpn_id").val(cpn_id);

                $("#invoicebox").dialog( "open" ); }) ;

        $('#chk_manhours').click(function() {
                if ($(this).attr('checked'))
                    $('#sm1,#sm2').removeAttr('disabled');
                else
                    $('#sm1,#sm2').attr('disabled', 'disabled');
                    });

        $("#invoicebox").dialog({
                autoOpen: false,
                height: 300,
                width: 600,
                modal: true,
                buttons: {
                    "{/literal}{t}Create invoice{/t}{literal}": function() {
                       $('#invoiceboxfrm').submit(); 
                    },
                    Cancel: function() {
                        $( this ).dialog( "close" );
                    }
                },
                close: function() {
                }
        });
    });

</script>
{/literal}

<div id="invoicebox" title="{t}Create invoice{/t}">

    <form action="add_bill.php" method="get" id="invoiceboxfrm" name="invoiceboxfrm">
        <input type="hidden" name="prj_id" id="prj_id" value="" />
        <input type="hidden" name="cpn_id" id="cpn_id" value="" />
        <input type="hidden" name="action" value="{$smarty.const.ACTION_BILL_FROMPROJECT}" />
        <input type="hidden" name="op_billabletype" value="0" />

        <table cellspacing="0">
            <tr>
                <td class="label">{t}Add unbilled material{/t}</td>
                <td class="data">
                    <input type="checkbox" name="add_material" />
                </td>
            </tr>
            <tr>
                <td class="label">{t}Add unbilled expenses{/t}</td>
                <td class="data">
                    <input type="checkbox" name="add_expenses" />
                </td>
            </tr>
            <tr>
                <td class="label">{t}Add unbilled manhours{/t}</td>
                <td class="data">
                    <input type="checkbox" name="add_manhours" id="chk_manhours" /> <br />
                    <input type="radio" name="singlemulti" value="1" id="sm1" disabled="disabled"> {t}Single line item for all tasks{/t} <br />
                    <input type="radio" name="singlemulti" value="2" id="sm2" checked="checked" disabled="disabled"> {t}One line item for each task{/t}
                </td>
            </tr>
            <tr>
                <td class="label">{t}Additional information to add{/t}</td>
                <td class="data">
                    <input type="text" name="bill_additional_line" id="additional_line" size="40" maxlength="255" value="{$config.LETTERHEAD_ADDITIONAL_LINE}" /> <br />
                </td>
            </tr>
        </table>

    </form>
</div>
{/if}
        
<form action="{$smarty.const.PHPAGA_SELF}" method="get">

    {if (count($summary.rows) > 0)}
    <table cellspacing="0">
        <caption><em>{t}Unbilled hours{/t}</em>
            {t}Group by{/t}:
            <select name="groupby">
                {html_options options=$phpaga_groupby selected=$groupby_sel}
            </select>
            <input type="submit" value="{t}Search{/t}" />
        </caption>
        <thead>
            <tr>
                <th> {t}Customer{/t} </th>
                {if !$percustomer}
                <th> {t}Project{/t} </th>
                {/if}
                <th class="time"> {t}Hours{/t} </th>
                <th class="number"> {t}Amount{/t} </th>
                <th class="number"> {t}Materials{/t} </th>
                <th class="time"> {t}Between{/t} </th>
                <th class="time"> {t}And{/t} </th>
                <th> {t}Actions{/t} </th>
            </tr>
        </thead>
        <tbody>
            {section name=i loop=$summary.rows}
            <tr>
                <td> <a href="company.php?id={$summary.rows[i].cpn_id}">{$summary.rows[i].cpn_name|wash}</a> </td>
                {if !$percustomer}
                <td{if ((strlen($summary.rows[i].prj_title) > $smarty.const.PHPAGA_SHOWPRJTITLELENGHT))} class="tTip" title="{$summary.rows[i].prj_title|phpaga_popup_sanitizestr}"{/if}>
                    <a href="project.php?id={$summary.rows[i].prj_id}"> {$summary.rows[i].prj_title|wash|trnc:$smarty.const.PHPAGA_SHOWPRJTITLELENGHT:"...":true} </a>
                </td>
                {/if}
                <td class="time"> {$summary.rows[i].prj_duration|phpaga_minutes2duration} </td>
                <td class="number"> {$config.MONETARY_SYMBOL|wash}{$summary.rows[i].prj_amount|phpaga_formatamount|default:"&nbsp;"} </td>
                {if $summary.rows[i].material_price}
                <td class="number"> {$config.MONETARY_SYMBOL|wash}{$summary.rows[i].material_price|phpaga_formatamount|default:"&nbsp;"} </td>
                {else}
                <td class="number"></td>
                {/if}
                <td class="time"> {$summary.rows[i].op_min_start|date_format:$smarty.const.PHPAGA_DATEFORMAT_SHORT} </td>
                <td class="time"> {$summary.rows[i].op_max_end|date_format:$smarty.const.PHPAGA_DATEFORMAT_SHORT} </td>
                <td class="actions" title="{$summary.rows[i].prj_id}|{$summary.rows[i].cpn_id}">
                    {if phpaga_user_hasperm($smarty.const.PHPAGA_PERM_MANAGE_INVOICES)}<a href="add_bill.php?{if !$percustomer}prj_id={$summary.rows[i].prj_id}{else}cpn_id={$summary.rows[i].cpn_id}{/if}&amp;op_billed={$smarty.const.PHPAGA_BILL_NOTBILLED}&amp;prj_billabletype=0&amp;op_billabletype=0&amp;action={$smarty.const.ACTION_BILL_WITHOPERATIONS}">{t}Create invoice{/t}</a> | {/if}
                    {if phpaga_user_hasperm($smarty.const.PHPAGA_PERM_MANAGE_INVOICES) and !$percustomer}<a class="createinvoice" href="#">{t}Show Choices{/t}</a> | {/if}
                    <a href="operations.php?{if !$percustomer}prj_id={$summary.rows[i].prj_id}{else}cpn_id={$summary.rows[i].cpn_id}{/if}&amp;op_billed={$smarty.const.PHPAGA_BILL_NOTBILLED}">{t}View tasks{/t}</a>
                </td>
            </tr>
            {/section}
        </tbody>
        <tfoot>
            <tr>
                <td{if !$percustomer} colspan="2"{/if}> &nbsp;</td>
                <td class="time"> {$summary.sum_duration|phpaga_minutes2duration} </td>
                <td class="number"> {$config.MONETARY_SYMBOL|wash}{$summary.sum_amount|phpaga_formatamount|default:"&nbsp;"} </td>
                {if $summary.sum_material}
                <td class="number"> {$config.MONETARY_SYMBOL|wash}{$summary.sum_material|phpaga_formatamount|default:"&nbsp;"} </td>
                {else}
                <td class="number"></td>
                {/if}
                <td colspan="4"> &nbsp; </td>
            </tr>
        </tfoot>
    </table>
</form>
{else}
<div class="msg">{t}Currently there are no unbilled hours.{/t}</div>
{/if}

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