Hacked solution for discounts.
  • switzerbadenswitzerbaden February 8

    After installing, setting up and modifying Simple Invoices, I noticed a few major issues that prevent this from being a truly great invoicing tool. This is how I solved: How can I give a client a discount?!

    After reading through the forum, it seems that this has been on the 'dev timeline' since 2008. Well, it's now 2012....so this is how I hacked a solution together for Discounts.

    1. Create a new product. Be sure to give it a Product Description that includes the word 'Discount'. I used Discount 1.
    2. Give the Product Unit Price a value of -1
    3. Assign the standard Default Tax, if desired and save.

    If you are using the default template, stop now and learn how to create your own template. You really don't want to be making changes to the default template. Figured out how to create your own template? Good! Let's continue.

    Open up your invoice template file located at: templates > invoices > your_template_directory > template.tpl
    Open it in a text editor or IDE like Komodo Edit. Not Photoshop. Not Sticky Notes or any other program that uses the .tpl extentions... thank you Smarty. I would rather learn Ruby on Rails than Smarty. But Smarty it is. Moving on...

    change the bit of code that looks like this:

    {foreach from=$invoiceItems item=invoiceItem}

    <tr class="" >
    <td class="">{$invoiceItem.quantity|siLocal_number_trim}</td>
    <td class="" colspan="3">{$invoiceItem.product.description|htmlsafe}</td>
    <td class="" align="right">{$preference.pref_currency_sign|htmlsafe}{$invoiceItem.unit_price|siLocal_number}</td>
    <td class="" align="right">{$preference.pref_currency_sign|htmlsafe}{$invoiceItem.gross_total|siLocal_number}</td>
    </tr>
    {if $invoiceItem.description != null}
    <tr class="">
    <td class=""></td>
    <td class="" colspan="5">{$LANG.description}: {$invoiceItem.description|htmlsafe}</td>
    </tr>
    {/if}

    <tr class="tbl1-bottom">
    <td class=""></td>
    <td class="" colspan="5">
    <table width="100%">
    <tr>

    {inv_itemised_cf label=$customFieldLabels.product_cf1 field=$invoiceItem.product.custom_field1}
    {do_tr number=1 class="blank-class"}
    {inv_itemised_cf label=$customFieldLabels.product_cf2 field=$invoiceItem.product.custom_field2}
    {do_tr number=2 class="blank-class"}
    {inv_itemised_cf label=$customFieldLabels.product_cf3 field=$invoiceItem.product.custom_field3}
    {do_tr number=3 class="blank-class"}
    {inv_itemised_cf label=$customFieldLabels.product_cf4 field=$invoiceItem.product.custom_field4}
    {do_tr number=4 class="blank-class"}

    </tr>
    </table>
    </td>
    </tr>
    {/foreach}


    To this:


    {foreach from=$invoiceItems item=invoiceItem}
    {if stristr($invoiceItem.product.description, 'discount') === FALSE}
    <tr>
    <td class="">{$invoiceItem.quantity|siLocal_number_trim}</td>
    <td class="" colspan="3">{$invoiceItem.product.description|htmlsafe}</td>
    <td class="" align="right">{$preference.pref_currency_sign|htmlsafe}{$invoiceItem.unit_price|siLocal_number}</td>
    <td class="" align="right">{$preference.pref_currency_sign|htmlsafe}{$invoiceItem.gross_total|siLocal_number}</td>
    </tr>
    {if $invoiceItem.description != null}
    <tr>
    <td class=""></td>
    <td class="" colspan="5">{$invoiceItem.description|htmlsafe}</td>
    </tr>
    {/if}

    <tr class="tbl1-bottom">
    <td class=""></td>
    <td class="" colspan="5">
    <table width="100%">
    <tr>

    {inv_itemised_cf label=$customFieldLabels.product_cf1 field=$invoiceItem.product.custom_field1}
    {do_tr number=1 class="blank-class"}
    {inv_itemised_cf label=$customFieldLabels.product_cf2 field=$invoiceItem.product.custom_field2}
    {do_tr number=2 class="blank-class"}
    {inv_itemised_cf label=$customFieldLabels.product_cf3 field=$invoiceItem.product.custom_field3}
    {do_tr number=3 class="blank-class"}
    {inv_itemised_cf label=$customFieldLabels.product_cf4 field=$invoiceItem.product.custom_field4}
    {do_tr number=4 class="blank-class"}

    </tr>
    </table>
    </td>
    </tr>
    {else}
    <tr class="discount" >
    <td class="">&nbsp;</td>
    {if $invoiceItem.description != null}
    <td class="" colspan="4">{$invoiceItem.description|htmlsafe}</td>
    {else}
    <td class="" colspan="4">{$invoiceItem.product.description|htmlsafe}</td>
    {/if}
    <td class="" align="right">{$preference.pref_currency_sign|htmlsafe}{$invoiceItem.gross_total|siLocal_number}</td>
    </tr>
    <tr class="tbl1-bottom">
    <td class=""></td>
    <td class="" colspan="5">
    <table width="100%">
    <tr>
    {inv_itemised_cf label=$customFieldLabels.product_cf1 field=$invoiceItem.product.custom_field1}
    {do_tr number=1 class="blank-class"}
    {inv_itemised_cf label=$customFieldLabels.product_cf2 field=$invoiceItem.product.custom_field2}
    {do_tr number=2 class="blank-class"}
    {inv_itemised_cf label=$customFieldLabels.product_cf3 field=$invoiceItem.product.custom_field3}
    {do_tr number=3 class="blank-class"}
    {inv_itemised_cf label=$customFieldLabels.product_cf4 field=$invoiceItem.product.custom_field4}
    {do_tr number=4 class="blank-class"}

    </tr>
    </table>
    </td>
    </tr>
    {/if}
    {/foreach}


    Finally, you should add something like the following to the style.css file located in the same folder as your template.tpl file:

    .discount {
    background: #eaf0a6;
    }


    Hope it works for you!

  • modirmodir February 9

    Thank you for the contribution. I will test it out one day and commit it if it is working well.

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

Tagged