Jump to content

[Ask] Hooks for Overwrite duedate Value on tblinvoices


Mas-J

Recommended Posts

Dear All,

My Product setting Configuration
Prorate Date: 1
Charge Next Month: 32
So, every product that client buy will have Next Due Date value on tblhosting 01/mm/yyyy on each month

My Goal: I want to make all Invoices that created by automatic cron (recurring invoice, etc) and publish to client have a duedate value 10/mm/yyyy
The Next Due Date from tblhosting do not need to be change, because I need the product period date is 1 until the end of the date of that billed month.

Is it possible to do that by create Hooks ?
If yes, which Hooks variable that I need to use to achieve it ?

If due date value from tblinvoices can be overwrite by hook, does the invoice reminder cron will follow the new due date ?

Link to comment
Share on other sites

This is my first custom hooks.
I've create this code to work for my requirement, you can modify this code to suite your needs.
It will change the due date (tblinvoices.duedate) when create recurring invoices as you wish without changing the billing period (tblhosting.nextduedate & tblhosting.nextinvoicedate)
Email Cron reminder will follow the new due date.

Backup first and please try on development server before use it on production !
Do with your own risk.

<?php

# Set Recurring Invoice Due Date to date 10 each month on actual billed period
# Created by AULtramen

if (!defined("WHMCS")) {
    die("This file cannot be accessed directly");
}

use Illuminate\Database\Capsule\Manager as Capsule;

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

function SetDueDateRecurringInvoices($vars) {
	
    #You can edit source with your needs
    if ($vars['source'] == 'autogen' || $vars['source'] == 'api') {

	#Change "16" to other value based on your Invoice Generation Date setting to Match any Due Date you want
	$duedate10 = Date('y-m-d', strtotime('+16 days'));

	Capsule::table('tblinvoices')
		->where('id', '=', $vars['invoiceid'])
		->update(['duedate' => $duedate10]);
    }
    else if ($vars['source'] == 'adminarea') {
    
	#Change "7" to other value based on your Invoice Generation Date setting to Match any Due Date you want
	$duedate7 = Date('y-m-d', strtotime('+7 days'));

	Capsule::table('tblinvoices')
		->where('id', '=', $vars['invoiceid'])
		->update(['duedate' => $duedate7]);
	
    }
    
}
Edited by Mas-J
Connection Issue, script didn't upload properly
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.

×
×
  • 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