ask21900 Posted January 30, 2011 Share Posted January 30, 2011 (edited) Problem: My company does a lot of custom app development. We bill clients at certain points in their project. Their invoice terms are usually net 30. With WHMCS, the only way to achieve this using the billable items feature is to bill according to invoice due date, and then set the due date for all billable items. When we don't know when we will be billing the item(s) it is impossible to tell when the due date will be. When a client has several billable items, it can be quite a pain to adjust each due date to match the desired result. Clicking "Invoice these items now" causes the due date to be the date the invoice was created (now). Solution: I developed an action hook that will set the due date to be X days after invoice creation. While that is nice, what if you still want your orders to be due immediately? No problem! The hook only effects invoices that are for billable items. But wait! There's more! You can specify a default number of days before due date, or have it overwritten by a custom field. Instructions: Create a custom client field in your WHMCS install. Create a file in the includes/hooks/ folder. Paste the following code into the file. Change the $CUSTOM_FIELD_NAME in the top of the file to be the name of the field you set up. Change the $DEFAULT_DAYS to a number of your choice. Save. That's it! You have now completed installation of my mod. <?php /* * Checks to see if an invoice contains billable items, * and if so, sets the invoice due date to be X days * from now */ $CUSTOM_FIELD_NAME = 'Your Custom Field Name'; $DEFAULT_DAYS = 30; function setDueDate($vars) { global $CUSTOM_FIELD_NAME, $DEFAULT_DAYS; $invoiceId = $vars['invoiceid']; $sql = "SELECT bi.userid FROM tblinvoiceitems AS ii JOIN tblbillableitems AS bi ON ii.relid = bi.id WHERE ii.invoiceid = ".$invoiceId; $result = mysql_query($sql); $numrows = mysql_num_rows($result); if ($numrows > 0) { $numdays = $DEFAULT_DAYS; // Get clients id $clientId = mysql_fetch_array($result); $clientId = $clientId[0]; // Find number of days before due date for client $sql = "SELECT DISTINCT cv.value FROM tblcustomfieldsvalues AS cv JOIN tblcustomfields AS cf ON cv.fieldid = cf.id WHERE cf.fieldname LIKE '".$CUSTOM_FIELD_NAME."' AND cv.relid = ".$clientId; $result = mysql_query($sql); while ($row = mysql_fetch_array($result)) { if (!empty($row['value'])) $numdays = $row['value']; } // Get new date sql style $newdate = time() + ($numdays * 86400); $newdate = date("Y-m-d", $newdate); // Update due date $sql = "UPDATE tblinvoices SET duedate = '".$newdate."' WHERE id = ".$invoiceId; mysql_query($sql); } } add_hook("InvoiceCreationPreEmail",1,"setDueDate"); ?> Edited January 30, 2011 by ask21900 Forgot php tags 0 Quote Link to comment Share on other sites More sharing options...
sfsolutions Posted February 3, 2011 Share Posted February 3, 2011 Hi, this sounds like the solution, that i am searching for month now. ATM i create a billable Item with don't invoice for every task i do for a project. For example that are 100. ATm when i klick them and tell to invoice them on next cron run it creates 100 invoices. And with your mod, i get them how it should be on one invoice ? Many thanks and best wishes Niels 0 Quote Link to comment Share on other sites More sharing options...
ask21900 Posted February 15, 2011 Author Share Posted February 15, 2011 Hi, this sounds like the solution, that i am searching for month now. ATM i create a billable Item with don't invoice for every task i do for a project. For example that are 100. ATm when i klick them and tell to invoice them on next cron run it creates 100 invoices. And with your mod, i get them how it should be on one invoice ? Many thanks and best wishes Niels If I understand you correctly, you want to cause the billable items to show up on one invoice? If that is what you are trying to do, then it can be done with my mod. I'm not sure that it can't be done without it too. When adding a billable select "Don't invoice for now". When you are ready to invoice, check the item(s) you want to invoice and click "Invoice now". This will cause all items selected to be added to a single invoice. 0 Quote Link to comment Share on other sites More sharing options...
Lemni Posted February 16, 2011 Share Posted February 16, 2011 Wow... thanks for this... have been struggling with billable item invoice due dates for a while now. 0 Quote Link to comment Share on other sites More sharing options...
cnasal Posted April 11, 2011 Share Posted April 11, 2011 ask21900, I just wanted to say thanks for this little hook. It was exactly what I was looking for and only took a minute to integrate. Thanks for saving me an hour or more trying to reproduce it. Carl 0 Quote Link to comment Share on other sites More sharing options...
Brainchild Labs Pty Ltd Posted November 5, 2011 Share Posted November 5, 2011 Just wondering how to confirm this is working ? I added a php file called setduedate.php in the hooks directory added a Custom Field called Test. Then put Test inside the 'Your custom field name here' saved it. Went to billable items, created a new billable item, that screen everything seems normal. What am i suppose to be seeing and what relations does that Custom Field Name have to this mod ? Sorry for the ignorance still getting used to WHMCS. Thanks. 0 Quote Link to comment Share on other sites More sharing options...
wonderland Posted January 26, 2012 Share Posted January 26, 2012 (edited) I'm also wondering about this. Does this at all work with whmcs 5.0.3 ? Does this apply only to billable items of manually generated invoices as well ? I did everything in instructions, but it doesn't seem to work. Edited January 26, 2012 by wonderland 0 Quote Link to comment Share on other sites More sharing options...
krwsolutions Posted February 6, 2012 Share Posted February 6, 2012 This is fantastic! EXACTLY what I needed. This should be a feature built into WHMCS. 0 Quote Link to comment Share on other sites More sharing options...
h.kuenen@bizzonweb.info Posted May 1, 2012 Share Posted May 1, 2012 Hi ask21900, Can you confirm that the hook still works as I just followed the instructions and it doesn't seem to do anything. If it should still work, could you confirm what the hook filename should be or what else might go wrong please Thanks 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.