Feature Requests
Share ideas, discuss and vote on requests from other users in community
 

Payment before - Invoice Due Date

wsd shared this idea 5 years ago
Under Consideration

Our customers pay via a variety of payment options, and some of them can take up to 8-12 days before we see the deposit, we have put all our service to create an invoice 30 days before the Next Due Date, but it does not help something when there's going to be the same Due Date on the invoice.

Example a service going from 01.01.2013 to 01.07.2013 so there will be issued a new invoice on 01.06.2013, but there is still Due Date 01.07.2013 which is the date when service stops and we see first payment on 12.07.2013 as the service will be suspended 8-12 days, we receive payment approx. 12 days So we need an opportunity to set the number of days of Payment before.

So the invoice is issued on 01.06.2013 can get a payment date of 14 days as final due payment will be the 15.06.2013 there will be time to record payment before suspended date 01.07.2013 + 0 to 4 days.

This would be great if it was made so it could be put to customer groups.

Comments (13)

photo
1

I can see from the code that he's using a hook - so it will be automatic. It's quite clever and I'll be using this as I want payment terms of 14 days for all Bank Transfers. I'll be able to change his code to look up the Payment Method and set the due date if the Payment Method = Bank Transfer.

https://developers.whmcs.com/hooks-reference/invoices-and-quotes/#invoicecreationpreemail

That's the hook that's being used. It's a shame there's not a comprehensive API so the read and update database operations can be changed into API calls.

Either way, thanks a bunch U2 Pas!

photo
1

Here is an updated hook code that uses the whmcs 7 API.

it basically does this:

if the due date of an invoice would be behind the invoice date then set the due date to invoice date+days set in the settings that invoices are normally generated before a due date:

  1. function setDueDate($vars) {

    //Get current invoice and due date

    $params = array(

    "invoiceid" => $vars["invoiceid"]

    );

    $result = localAPI("GetInvoice",$params);

    $format = "Y-m-d";

    $duedate = date_create_from_format($format, $result["duedate"]);

    $date = date_create_from_format($format, $result["date"]);

    //get how many days are normally between due date and invoice date:

    $result = localAPI("GetConfigurationValue",array("setting" => "CreateInvoiceDaysBefore"));

    $days = $result["value"];

    if($duedate<=$date){

    $duedate = date_add($date,date_interval_create_from_date_string($days.' days'));

    $duedate_sql = date_format($duedate, 'Y-m-d');

    $params = array(

    "invoiceid" => $vars["invoiceid"],

    "duedate" => $duedate_sql

    );

    $result = localAPI("UpdateInvoice",$params);

    }

    }

    add_hook("InvoiceCreation",1,"setDueDate");

photo
1

I am upgrading to the latest WHMCS and am updating all my hooks. I re-wrote this one to use the Internal API. It sets the due date for all bank transfers based on defined payment term.


  1. <?php
    function setDueDate($vars)
    {
    // Number of days client has to pay an invoice
    $PAYMENT_TERM = 14;
    // Get the invoice id
    $invoiceId = $vars['invoiceid'];
    $params = array(
    'invoiceid' => $invoiceId
    );
    // Get invoice and cast to an Object (I prefer working with objects)
    $invoice = (object) localAPI('GetInvoice', $params);
    if ($invoice->result == 'success' && $invoice->paymentmethod == 'banktransfer') {
    // Calculate the due date
    $dueDate = new DateTime($invoice->date);
    $dueDate->add(new DateInterval('P' . $PAYMENT_TERM . 'D'));
    // Update the invoice
    $params = array(
    'invoiceid' => $invoiceId,
    'duedate' => $dueDate->format('Y-m-d')
    );
    $result = (object) localAPI('UpdateInvoice', $params);
    }
    }
    // Update due date when invoice is created or gateway is changed
    add_hook("InvoiceCreationPreEmail", 1, "setDueDate");
    add_hook("InvoiceChangeGateway", 1, "setDueDate");