Jump to content

Apply Payments Calculator


flangefrog

Recommended Posts

I made this mod in response to another thread but I figured it would be best to cross post it here. If that's not allowed then please remove this thread.

When you add a payment manually, it will automatically apply the payment to the invoices, oldest first. It will check any invoices with an amount above zero.

E.g. if the client has three invoices - $30 and $10, and $20 and paid $37, $30 will be paid to the first invoice and $7 to the second. The third invoice will be unpaid.

 

Note: this doesn't actually add any real functionality to Blesta, it will just make it easier to apply the payments without having to work out manually how much to apply to each invoice.

 

/app/views/admin/default/admin_clients_recordpayment.pdt

 

After line 79

$(document).ready(function() {
 add:

$("#amount").change(function() {
    amountRemaining = Math.max($(this).val(), 0);
    if (!isNaN(amountRemaining)) {
        $("#invoices_to_pay").find("tr").not(".heading_row").each(function() {
            checkBoxElement = $(this).find("input[name^=\'invoice_id\']");
            applyAmountElement = $(this).find("input[name^=\'applyamount\']");
            amountDueElement = applyAmountElement.parent().next();
            amountDue = Number(amountDueElement.text().substr(1).replace(/[^0-9\.]+/g, ""));
            applyAmount = Math.min(amountRemaining, amountDue);
            amountRemaining = (amountRemaining - applyAmount).toFixed(2);
            applyAmountElement.val(applyAmount);
            checkBoxElement.prop("checked", applyAmount > 0);
            if (!amountRemaining)
                return false;
        });
    }
});
If you want the calc to run while typing, change line 80 to:

$("#amount").on("input",function() {
Just be aware that this is unsupported or buggy on older browsers.

H3fZ1cZ.gif

apply_payments_calc.xml

Link to comment
Share on other sites

  • 2 months later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...