Jump to content

Billable Items set due date


ask21900

Recommended Posts

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 by ask21900
Forgot php tags
Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • 2 weeks later...
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.

Link to comment
Share on other sites

  • 1 month later...
  • 6 months later...

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.

Link to comment
Share on other sites

  • 2 months later...
  • 2 weeks later...
  • 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.

  • 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