Filters for "Manage Invoices"
  • January 1970 Edit

    One feature i liked in another invoice application was the ability to filter invoices based on open/closed/overdue. I've spent a bit of time making this modification, and would like to share with anyone that would care to see.

    ./modules/invoices/manage.php (line 90, just before the end curly } bracket) I added the lines:

    // Filter options
    if ($invoice['owing'] == 0 && (!isset($_GET['filter']) || $_GET['filter'] == 'unpaid'))
    unset($invoices[$i]); // By default, do not show paid invoices
    elseif ($_GET['filter'] == 'overdue' && $overdue_days <= 14)
    unset($invoices[$i]); // Hide invoices that are not overdue
    elseif ($_GET['filter'] == 'paid' && $invoice['owing'] != 0)
    unset($invoices[$i]);
    // else show all


    Note that by default I am showing only unpaid invoices. The largest change was in the file:
    ./templates/default/invoices/manage.tpl

    I replaced the code at the top:
    {if $invoices == null }
    <P><em>{$LANG.no_invoices}.</em></p>
    {else}

    <div style="text-align:center;">
    <b>{$LANG.manage_invoices}</b> ::
    <a href="index.php?module=invoices&view=total">{$LANG.add_new_invoice} - {$LANG.total_style}</a> ::
    <a href="index.php?module=invoices&view=itemised">{$LANG.add_new_invoice} - {$LANG.itemised_style}</a> ::
    <a href="index.php?module=invoices&view=consulting">{$LANG.add_new_invoice} - {$LANG.consulting_style}</a>
    </div>

    <hr />


    With this:
    <div style="text-align:center;">
    <b>{$LANG.manage_invoices}</b> ::
    <a href="index.php?module=invoices&view=total">{$LANG.add_new_invoice} - {$LANG.total_style}</a> ::
    <a href="index.php?module=invoices&view=itemised">{$LANG.add_new_invoice} - {$LANG.itemised_style}</a> ::
    <a href="index.php?module=invoices&view=consulting">{$LANG.add_new_invoice} - {$LANG.consulting_style}</a>
    </div>

    <div style="text-align:center;">
    <form method="GET" action="index.php" onchange="this.submit();">
    {foreach from=$smarty.get key=k item=v}
    {if $k != 'filter'}
    <input type="hidden" name="{$k|escape:'html'}" value="{$v|escape:'html'}" />
    {/if}
    {/foreach}
    <b>{$LANG.view}</b>:
    <label for="filter_unpaid">{$LANG.owing} </label><input type="radio" name="filter" value="unpaid" id="filter_unpaid" {if $smarty.get.filter == 'unpaid' || $smarty.get.filter == ''}checked="checked"{/if} /> |
    <label for="filter_overdue">14+ {$LANG.days} </label><input type="radio" id="filter_overdue" name="filter" value="overdue" {if $smarty.get.filter == 'overdue'}checked="checked"{/if} /> |
    <label for="filter_paid">{$LANG.paid} </label><input type="radio" id="filter_paid" name="filter" value="paid" {if $smarty.get.filter == 'paid'}checked="checked"{/if} /> |
    <label for="filter_all">{$LANG.total} </label><input type="radio" id="filter_all" name="filter" value="all" {if $smarty.get.filter == 'all'}checked="checked"{/if} />
    </form>
    </div>

    <hr />


    {if $invoices == null }
    <P><em>{$LANG.no_invoices}.</em></p>
    {else}


    Unfortunately I wasn't able to find equivalents in the language file for the words "Unpaid" (or "Open" or "Pending payment", I guess "Owing" will do), "Overdue" (best match was "14+ days") and "All" ("Total" just doesn't seem to fit). So the wording is a bit clumsy, but I guess it'll do. Probably a lot easier than editing the language file for all 14 languages.

    I'd appreciate any improvements or feedback on this little snippet. I'm also getting a little worried about a couple of these modifications I'm doing ... the code is very easy to understand and tweak (which encourages me to tweak away), but upgrades are obviously going to wreck my changes. Is there a "right way" to program in add-ons?

  • justinjustin October 2007

    Thanks Stephen!!!!

    i'll test this modification

    re is there a right way
    - not at the moment unfortunately :(
    -- if the change isnt incorporated into the standard Simple Invoices then after each release you'll have to reapply the add-on
    - but hopefully soon we can sort out a nice system like firefox when adds-ons dont get wrecked etc with upgrades and they cann all live together nicely

    Cheers

    Justin

    SmarterInvoices.com :: Simple Invoices hosting | Kelly.org.au :: Simple Invoices custom development | justin.kelly.org.au

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In Apply for Membership

Categories