<!-- BEGIN {$smarty.template} -->
{literal}
<script type="text/javascript">
function confirm_delete_recurrbill(rbill_id, el) {
    if (window.confirm(rbill_id+': {/literal}{t}If you remove this recurring invoice, its related invoices will not be deleted, but their reference to this recurring invoice is removed. Are you sure you want to delete this recurring invoice?{/t}{literal}')) {
        location.href = el.href;
    }
    return false;
}
</script>
{/literal}

<script type="text/javascript" src="js/table.js"></script>

<form action="recurrbills.php" method="get">
  <fieldset class="search">
    <legend>{t}Search recurring invoices{/t}</legend>

    <label for="rbill_id">{t}Number{/t}:</label>
    <input class="tinput number" id="rbill_id" type="text" name="id" value="{$billInfo.rbill_id}" size="6" maxlength="12">
    <br>

    <label for="rbill_type">{t}Type{/t}:</label>
    <select id="rbill_type" name="rbill_type">
      {html_options options=$select_rbill_types selected=$billInfo.rbill_type}
    </select>
    <br>

    <label for="rbill_status">{t}Status{/t}:</label>
    <select id="rbill_status" name="rbill_status">
      {html_options options=$select_rbill_status selected=$billInfo.rbill_status}
    </select>
    <br>

    <label for="cpn_id">{t}Recipient (company){/t}:</label>
    <select id="cpn_id" name="cpn_id">
      {html_options options=$select_cpn selected=$billInfo.cpn_id}
    </select>
    <br>

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

  </fieldset>
</form>

  <fieldset class="search">
    <legend>{t}Generate recurring invoices{/t}</legend>

    {if is_array($duelist) && count($duelist)}
    <table class="table-autosort table-autostripe table-stripeclass:even" cellspacing="0">
        <caption><em>{t}Recurring invoices to be created{/t}</em></caption>
        <thead>
            <tr>
                <th class="table-sortable:default"> {t}Number{/t} </th>
                <th class="table-sortable:default"> {t}Type{/t} </th>
                <th class="table-sortable:date"> {t}Start{/t} </th>
                <th class="table-sortable:date"> {t}End{/t} </th>
                <th class="table-sortable:default"> {t}Recipient (company){/t} </th>
                <th class="number"> {t}Last invoice number{/t} </th>
                <th class="number"> {t}Last invoice amount{/t} </th>
                <th class="table-sortable:date"> {t}Last invoice date{/t} </th>
                <th> {t}Actions{/t} </th>
            </tr>
        </thead>
        <tbody>
            {foreach from=$duelist item=d}
            <tr>
                <td class="number">{$d.rbill_id|wash}</td>
                <td>{$d.rbill_type_text|wash}</td>
                <td class="time">{$d.rbill_start|wash|date_format:$smarty.const.PHPAGA_DATEFORMAT_SHORT}</td>
                <td class="time">{$d.rbill_end|wash|date_format:$smarty.const.PHPAGA_DATEFORMAT_SHORT}</td>
                <td>{$d.cpn_name|wash}</td>
                <td class="number"> <a href="bill.php?id={$d.bill_id}">{$d.bill_number|wash}</a> </td>
                <td class="number"> {$d.bill_endsum|wash|phpaga_formatamount} {$d.curr_name|default:"&nbsp;"} </td>
                <td class="time">{$d.bill_date|wash|date_format:$smarty.const.PHPAGA_DATEFORMAT_SHORT}</td>
                <td class="actions"><a href="add_bill.php?id={$d.bill_id}&amp;action={$smarty.const.ACTION_CLONE}&amp;rbill_id={$d.rbill_id}">{t}Create invoice{/t}</a></td>
            </tr>
            {/foreach}
        </tbody>
    </table>
    {else}
    {t}Currently no recurring invoices need to be created.{/t}
    {/if}

  </fieldset>

<form action="bill_pdf.php" method="get" onsubmit="hideElement('printbill');">
{include file="bill_print.tpl.html"}

<table cellspacing="0">
    <caption><em>{t}Recurring invoices{/t}</em></caption>
    {if (count($rows) > 0)}
    <thead>
        <tr>
            <th class="number"> {t}Number{/t} </th>
            <th> {t}Type{/t} </th>
            <th> {t}Status{/t} </th>
            <th> {t}Recipient (company){/t} </th>
            <th class="time"> {t}Start{/t} </th>
            <th class="time"> {t}End{/t} </th>
            <th> {t}Actions{/t} </th>
        </tr>
    </thead>
    <tbody>
        {section name=invoices loop=$rows}
        <tr>
            <td class="number">{$rows[invoices].rbill_id|wash}</td>
            <td>{$rows[invoices].rbill_type_text|wash}</td>
            <td class="enabled{$rows[invoices].rbill_status}">{$rows[invoices].rbill_status_text|wash}</td>
            <td> <a href="company.php?id={$rows[invoices].cpn_id}">{$rows[invoices].cpn_name|wash}</a> </td>
            <td class="time"> {$rows[invoices].rbill_start|wash|date_format:$smarty.const.PHPAGA_DATEFORMAT_SHORT} </td>
            <td class="time"> {$rows[invoices].rbill_end|wash|date_format:$smarty.const.PHPAGA_DATEFORMAT_SHORT} </td>
            <td class="actions">
                {if $rows[invoices].rbill_status == $smarty.const.PHPAGA_RBILL_STATUS_ENABLED}
                <a href="recurrbills.php?id={$rows[invoices].rbill_id}&amp;action={$smarty.const.ACTION_DISABLE}">{t}Disable{/t}</a>
                {else}
                <a href="recurrbills.php?id={$rows[invoices].rbill_id}&amp;action={$smarty.const.ACTION_ENABLE}">{t}Enable{/t}</a>
                {/if}
                <a href="recurrbills.php?id={$rows[invoices].rbill_id}&amp;action={$smarty.const.ACTION_DELETE}" onclick="confirm_delete_recurrbill({$rows[invoices].rbill_id}, this); return false;">{t}Delete{/t}</a>
            </td>
        </tr>
        {/section}
    </tbody>
    {else}
    <tr>
        <td class="last" colspan="6"> {t}No recurring invoices matching your search criteria were found.{/t} </td>
    </tr>
    {/if}
    {if strlen($BROWSE)}
    <tfoot>
        <tr>
            <td class="browse" colspan="6"> {$BROWSE} </td>
        </tr>
    </tfoot>
    {/if}
</table>

</form>

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