Jump to content

Date paid as Invoice date


molcomp

Recommended Posts

4 hours ago, molcomp said:

Does anyone knows what is the best way to setup date paid to be the invoice date.? 

it looks like I wrote a hook back in Dec 2018 to do this - can't see that I published it publicly, so must have been requested privately - I see no reason why it wouldn't still work (though if I wrote it again now, I could clean up the code!)...

<?php

/**
* Update Paid Invoices Due Date Hook
* @author brian!
*/

use WHMCS\Database\Capsule;

function update_paid_invoice_duedate_hook($vars) {
   $invoiceid = $vars['invoiceid'];
   $invoicedate = Capsule::table('tblinvoices')->where('id', $invoiceid)->value('date');
   $paymentdate = Capsule::table('tblinvoices')->where('id', $invoiceid)->value('datepaid');
   $duedate = date ("Y-m-d", strtotime ($paymentdate ."+15 days"));
   if (isset($paymentdate)) {
       try {
           $updatedInvoiceNumber = Capsule::table('tblinvoices')
                                   ->where('id', $invoiceid)
                                   ->update(['date' => $paymentdate,'duedate' => $duedate,]);
       }
       catch (\Exception $e) {
           // Deal with error
       }
   }
}
add_hook("InvoicePaidPreEmail",1,"update_paid_invoice_duedate_hook");
?>

the hook works after the invoice is marked as paid, but before the email being sent to the client - it will update the invoice date to the paid date, and change due date to 15 days later (though not changing duedate can be disabled by removing that from the ->update line of code.

note that this will only change the dates on these dates on the email/pdf, it's not going to change any dates in the line items of the invoice.

Link to comment
Share on other sites

Thank you Brian I will try it over the wknd.  Now that you mentioned it 🙂 I think I was using it for some time just I guess it was gone after a new install of whmcs. Maybe I will find some backup copy to locate the  hook. Thanks again.

 

The reason for why is needed is because of two  related issues. One is that we are using pro forma invoicing and second in our fiscal year we have tax periods one month , three months or annuay.  So for example if we issue a pro forma invoice in ond tax period client might pay in the folllowing tax period.  When we enter the payment in whmcs the invoice generated gets date from ghe pro forma invoice thus becoming invoice issued in the past tax period and we cannot wright it in the books.  That is why we need the invoice date to be the paid date so we can submit/wright the invoice in the curreng active running tax period.

Hope I explained it 🙂

 

Thank you both for the help 

Alex

Link to comment
Share on other sites

6 hours ago, molcomp said:

When we enter the payment in whmcs the invoice generated gets date from ghe pro forma invoice thus becoming invoice issued in the past tax period and we cannot wright it in the books.

As far as I know WHMCS has a feature that automatically makes payment date equal to invoice date. It should be Setup > Payments > Tax Configuration > VAT Settings > Set Invoice Date on Payment.

I could be wrong here but I'm pretty sure it works. The thing is that I coded many things for WHMCS billing and I can no longer distinguish between what's is mine and what is WHMCS.

Link to comment
Share on other sites

Hello

 

Thank you Kian you are correct it is present in the settings.  I guess I used  the hook in the past and after an update/new install forgot about the hook.  I did acticate the set invoice date on payments just need to see now why it does not work .   Maybe it will work from here on and not on the past invoice.

 

Thank you

Alex

Link to comment
Share on other sites

7 hours ago, Kian said:

As far as I know WHMCS has a feature that automatically makes payment date equal to invoice date. It should be Setup > Payments > Tax Configuration > VAT Settings > Set Invoice Date on Payment.

good spot - though I assume VAT would have to be enabled in settings to use it.

16 hours ago, steven99 said:

For the code clean up task in the future, using internal classes would likely be the only thing.

that 15 days annoys me - can't still why I specified it unless I was originally asked to do so.

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