Jump to content

Credits not showing on invoice email that was paid by it


Recommended Posts

Client has a small overpayment. It was added as a transaction and the next invoice was paid using it. 
The invoice is marked as paid, but the line says this in the email: Credit Applied: $0.00 USD. The ledger on the invoice shows it was applied, but strangely:
Type: Client Account Debit, with "Applied Credit Note funded by Client Credit" for the description.

As far as the client  could see, it was paid, but no idea how. My clients don't typically log in and review, but just look for the email. 
This used to work back in the day, quite simply. Now it's confusing for admins, and worse, clients. Can it be made to show this (latest version WHMCS)? Not seeing any merge fields that might do it.

Link to comment
Share on other sites

There is no way we have found. Occasionally customers double pay the same invoice. 

In v8 it would put the account in credit, then the credit balance would get used and shown on the invoice (not as the transaction at the bottom). 
 

v9 has changed this behaviour. And transactions are applied different ways and shown differently in the emails and PDFs  

Have you tried viewing the client account statement? 

Link to comment
Share on other sites

Posted (edited)

Fun. 
 

Quote

Error: Call to a member function lte() on false in /home/xxxx/public_html/clients/modules/reports/client_statement.php:194
Stack trace:
#0 /home/xxxx/public_html/clients/xxxx/reports.php(0): unknown()
#1 {main}

Looks like it may be just the one client has the error, but don't see how this will help resolve the confusion.

Edited by bear
Link to comment
Share on other sites

Sadly it doesn't resolve the confusion. It does contribute to showing that it's broken.

I had to look at the transactions list to be able to make some sense of these changes. Customising the email templates is something I did to reduce confusion.

Link to comment
Share on other sites

Likely have to do the same with the templates. Something akin to "if your invoice is marked as paid while you hadn't yet submitted a new payment...."
Was WHMCS made aware of this, do you know?

A search reveals the error may be caused by malformed dates in either transactions or invoices. Searching this client, they have two old invoices (long before v9) that were canceled when they decided to drop a few domains. The canceled ones have date paid as "0000-00-00" (along with timestamp of zeros), which might be causing it. No way to fix it, since invoices are immutable within WHMCS now, even to the point of deleting canceled ones. Also can't add a date in that paid field, since that would indicate it's paid....
What a mess. 

Link to comment
Share on other sites

  • 3 months later...

This caught me out after moving to 9 as well. The 9.0 docs page on Credit and Debit Notes explains what changed: when client credit is applied to an invoice (by hand, or automatically when the invoice is generated), WHMCS now creates a credit note for that amount and settles the invoice through the ledger. That's where your "Applied Credit Note funded by Client Credit" line comes from. The old {$invoice_credit} merge field doesn't seem to follow it, so the email shows 0.00 even though the credit did the paying.

 

Until WHMCS maps this into the template, my workaround is to work the figure out in an EmailPreSend hook and hand it to the template as a new merge field. EmailPreSend can return extra merge fields, so something like this in /includes/hooks/invoice_credit_mergefield.php:

 

<?php

add_hook('EmailPreSend', 1, function ($vars) {

    if (!in_array($vars['messagename'], ['Invoice Payment Confirmation', 'Invoice Created'])) {

        return [];

    }

    $inv = localAPI('GetInvoice', ['invoiceid' => (int) $vars['relid']]);

    if (($inv['result'] ?? '') !== 'success') {

        return [];

    }

    $paid = 0.0;

    foreach ($inv['transactions']['transaction'] ?? [] as $t) {

        $paid += (float) $t['amountin'] - (float) $t['amountout'];

    }

    $covered = max(0, (float) $inv['total'] - $paid - (float) $inv['balance']);

    return ['invoice_credit_applied' => number_format($covered, 2)];

});

 

Then in the template: Credit Applied: {$invoice_credit_applied}

 

One thing to check before you rely on it: run GetInvoice on one of the affected invoices and see whether the credit application shows up in the transactions array. If 9 records it there as a transaction (your "Client Account Debit" type suggests it might), the subtraction above will come out as 0. In that case, sum just those rows by their gateway/description instead. Test it on a dev copy or with a test client first, because a broken EmailPreSend hook affects every outgoing email.

 

About the statement error: "lte() on false" means a date comparison ran on a date that failed to parse, so the 0000-00-00 datepaid on those old cancelled invoices is a very likely cause. I'd send WHMCS support that stack trace along with the two invoice IDs and report it as a bug, rather than editing the rows in the database. In 9 the ledger and the immutability checks depend on those records.

 

Link to comment
Share on other sites

1 hour ago, Waqas Ahmed Waseer said:

my workaround

Though I appreciate the response, I also could have asked AI and copy/pasted the entire thing. All all of your replies I checked appear to be 100% AI generated, please don't bother replying to my posts, if possible. 

Link to comment
Share on other sites

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.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated