Jump to content
Sign in to follow this  
TimRef

Add dedicated IP or hostname to the invoice.php page .

Recommended Posts

Hi,

Suggestion: 

Add dedicated IP or hostname to the clinet and admin invoice.php page .

That will save a lot of time.

Share this post


Link to post
Share on other sites
On 12/7/2021 at 1:48 PM, TimRef said:

Hi,

Suggestion: 

Add dedicated IP or hostname to the clinet and admin invoice.php page .

That will save a lot of time.

Hello,

Maybe we can manage a way, using a Hook file, interested in this?

Share this post


Link to post
Share on other sites
On 12/29/2021 at 8:25 PM, andrezzz said:

Hello,

Maybe we can manage a way, using a Hook file, interested in this?

Thanks for your reply . do you have any plan ? 

Share this post


Link to post
Share on other sites
Posted (edited)
On 12/31/2021 at 2:14 PM, TimRef said:

Thanks for your reply . do you have any plan ? 

Check this out :D!

<?php
/**
 *	Invoice with Primary/Dedicated IP WHMCS Hook version 1.0
 *
 *	@package     WHMCS
 *	@copyright   Andrezzz
 *	@link        https://www.andrezzz.pt
 *	@author      André Antunes <andreantunes@andrezzz.pt>
 */

if (!defined('WHMCS')) {
    exit(header('Location: https://www.andrezzz.pt'));
}

use WHMCS\Database\Capsule;

add_hook('InvoiceCreation', 1, function($vars) {
    global $_LANG;
    $invoiceItems = Capsule::table('tblinvoiceitems')->where('invoiceid', $vars['invoiceid'])->get();

    foreach ($invoiceItems as $invoiceItem) {
        if ($invoiceItem->relid === 0) return;
        
        $dedicatedIP = Capsule::table('tblhosting')->where('id', $invoiceItem->relid)->value('dedicatedip');
        if ($dedicatedIP === '') return;

        Capsule::table('tblinvoiceitems')->where('id', $invoiceItem->id)->update(array(
            'description' => $invoiceItem->description . "\n" . $_LANG['primaryIP'] . ': ' . $dedicatedIP
        ));
    }
});

It also have Language support, so that the client can understand what is that line.

Edited by andrezzz

Share this post


Link to post
Share on other sites
56 minutes ago, andrezzz said:

Check this out :D!


<?php
/**
 *	Invoice with Primary/Dedicated IP WHMCS Hook version 1.0
 *
 *	@package     WHMCS
 *	@copyright   Andrezzz
 *	@link        https://www.andrezzz.pt
 *	@author      André Antunes <andreantunes@andrezzz.pt>
 */

if (!defined('WHMCS')) {
    exit(header('Location: https://www.andrezzz.pt'));
}

use WHMCS\Database\Capsule;

add_hook('InvoiceCreation', 1, function($vars) {
    global $_LANG;
    $invoiceItems = Capsule::table('tblinvoiceitems')->where('invoiceid', $vars['invoiceid'])->get();

    foreach ($invoiceItems as $invoiceItem) {
        if ($invoiceItem->relid === 0) return;
        
        $dedicatedIP = Capsule::table('tblhosting')->where('id', $invoiceItem->relid)->value('dedicatedip');
        if ($dedicatedIP === '') return;

        Capsule::table('tblinvoiceitems')->where('id', $invoiceItem->id)->update(array(
            'description' => $invoiceItem->description . "\n" . $_LANG['primaryIP'] . ': ' . $dedicatedIP
        ));
    }
});

It also have Language support, so that the client can understand what is that line.

You need to check if invoiced item is hosting.

Share this post


Link to post
Share on other sites
Posted (edited)
33 minutes ago, pRieStaKos said:

You need to check if invoiced item is hosting.

Well, I thought like this: if you have an IP then it should appear, because many times there are services with an IP that are Other.

Edited by andrezzz

Share this post


Link to post
Share on other sites
Posted (edited)

Great work 🙂 

pRieStaKos is right, the type should be checked. The problem is, for example, if the invoice line is about a domain and the domain ID matches with an ID in tblhosting, a wrong value will be inserted.

And I have 2 general suggestions:

  • Use type casting for integers. Some servers still uses old mysqlnd drivers, which returns everything as string, even if the column is a integer. However, because of the "if ($dedicatedIP === '') return;" check it doesn't matter in this case.
  • I would trim the $dedicatedIP variable. While WHMCS automatically trims the IP field in newer versions, this was not the case in older versions and I think it is always a good idea to trim fields if it makes sense. And one never know what WHMCS admins do manually in the database. Whitespaces are conceivable.
Edited by string

Share this post


Link to post
Share on other sites
31 minutes ago, string said:

Great work 🙂 

pRieStaKos is right, the type should be checked. The problem is, for example, if the invoice line is about a domain and the domain ID matches with an ID in tblhosting, a wrong value will be inserted.

And I have 2 general suggestions:

  • Use type casting for integers. Some servers still uses old mysqlnd drivers, which returns everything as string, even if the column is a integer. However, because of the "if ($dedicatedIP === '') return;" check it doesn't matter in this case.
  • I would trim the $dedicatedIP variable. While WHMCS automatically trims the IP field in newer versions, this was not the case in older versions and I think it is always a good idea to trim fields if it makes sense. And one never know what WHMCS admins do manually in the database. Whitespaces are conceivable.

You and @pRieStaKos are right, sorry.
Thank you so much for your suggestions 😊!

Check this newer version! In my case, I rather prefer choosing this type of Item.

<?php
/**
 *	Invoice with Primary/Dedicated IP WHMCS Hook version 1.1
 *
 *	@package     WHMCS
 *	@copyright   Andrezzz
 *	@link        https://www.andrezzz.pt
 *	@author      André Antunes <andreantunes@andrezzz.pt>
 */

if (!defined('WHMCS')) {
    exit(header('Location: https://www.andrezzz.pt'));
}

use WHMCS\Database\Capsule;

add_hook('InvoiceCreation', 1, function($vars) {
    global $_LANG;
    $typeOfItems = array('Hosting', 'Setup', 'PromoHosting', 'Upgrade');
    $invoiceItems = Capsule::table('tblinvoiceitems')->where('invoiceid', $vars['invoiceid'])->get();

    foreach ($invoiceItems as $invoiceItem) {
        if ($invoiceItem->relid === 0) return;
        if (!in_array($invoiceItem->type, $invoiceItem)) return;
        
        $dedicatedIP = Capsule::table('tblhosting')->where('id', $invoiceItem->relid)->value('dedicatedip');

        Capsule::table('tblinvoiceitems')->where('id', $invoiceItem->id)->update(array(
            'description' => $invoiceItem->description . "\n" . $_LANG['primaryIP'] . ': ' . trim($dedicatedIP)
        ));
    }
});

 

Share this post


Link to post
Share on other sites
1 hour ago, andrezzz said:

You and @pRieStaKos are right, sorry.
Thank you so much for your suggestions 😊!

Check this newer version! In my case, I rather prefer choosing this type of Item.


<?php
/**
 *	Invoice with Primary/Dedicated IP WHMCS Hook version 1.1
 *
 *	@package     WHMCS
 *	@copyright   Andrezzz
 *	@link        https://www.andrezzz.pt
 *	@author      André Antunes <andreantunes@andrezzz.pt>
 */

if (!defined('WHMCS')) {
    exit(header('Location: https://www.andrezzz.pt'));
}

use WHMCS\Database\Capsule;

add_hook('InvoiceCreation', 1, function($vars) {
    global $_LANG;
    $typeOfItems = array('Hosting', 'Setup', 'PromoHosting', 'Upgrade');
    $invoiceItems = Capsule::table('tblinvoiceitems')->where('invoiceid', $vars['invoiceid'])->get();

    foreach ($invoiceItems as $invoiceItem) {
        if ($invoiceItem->relid === 0) return;
        if (!in_array($invoiceItem->type, $invoiceItem)) return;
        
        $dedicatedIP = Capsule::table('tblhosting')->where('id', $invoiceItem->relid)->value('dedicatedip');

        Capsule::table('tblinvoiceitems')->where('id', $invoiceItem->id)->update(array(
            'description' => $invoiceItem->description . "\n" . $_LANG['primaryIP'] . ': ' . trim($dedicatedIP)
        ));
    }
});

 

Thanks all you guys , you are all so kind . thanks very very a lot .  and also thanks for  @pRieStaKos and @string 

Share this post


Link to post
Share on other sites
1 hour ago, andrezzz said:

You and @pRieStaKos are right, sorry.
Thank you so much for your suggestions 😊!

Check this newer version! In my case, I rather prefer choosing this type of Item.


<?php
/**
 *	Invoice with Primary/Dedicated IP WHMCS Hook version 1.1
 *
 *	@package     WHMCS
 *	@copyright   Andrezzz
 *	@link        https://www.andrezzz.pt
 *	@author      André Antunes <andreantunes@andrezzz.pt>
 */

if (!defined('WHMCS')) {
    exit(header('Location: https://www.andrezzz.pt'));
}

use WHMCS\Database\Capsule;

add_hook('InvoiceCreation', 1, function($vars) {
    global $_LANG;
    $typeOfItems = array('Hosting', 'Setup', 'PromoHosting', 'Upgrade');
    $invoiceItems = Capsule::table('tblinvoiceitems')->where('invoiceid', $vars['invoiceid'])->get();

    foreach ($invoiceItems as $invoiceItem) {
        if ($invoiceItem->relid === 0) return;
        if (!in_array($invoiceItem->type, $invoiceItem)) return;
        
        $dedicatedIP = Capsule::table('tblhosting')->where('id', $invoiceItem->relid)->value('dedicatedip');

        Capsule::table('tblinvoiceitems')->where('id', $invoiceItem->id)->update(array(
            'description' => $invoiceItem->description . "\n" . $_LANG['primaryIP'] . ': ' . trim($dedicatedIP)
        ));
    }
});

 

I will test this in my page  , and  Need I do anything in the clientaraeinvoices.php ?  

Share this post


Link to post
Share on other sites
Just now, TimRef said:

I will test this in my page  , and  Need I do anything in the clientaraeinvoices.php ?  

Nothing to edit, just create a file in your Hooks folder (`/whmcspath/includes/hooks`).

Share this post


Link to post
Share on other sites
Just now, andrezzz said:

Nothing to edit, just create a file in your Hooks folder (`/whmcspath/includes/hooks`).

Thanks 

after check , the page shows blank page ./clientarea.php?action=invoices

maybe met some issues. 

Share this post


Link to post
Share on other sites
2 minutes ago, TimRef said:

Thanks 

after check , the page shows blank page ./clientarea.php?action=invoices

maybe met some issues. 

Do you have Discord or Anydesk, so that I can help you further more?

Share this post


Link to post
Share on other sites
13 minutes ago, TimRef said:

if (!in_array($invoiceItem->type, $invoiceItem)) return;

Array is $typeOfItems. Not $invoiceItem

Share this post


Link to post
Share on other sites
Posted (edited)
4 minutes ago, pRieStaKos said:

Array is $typeOfItems. Not $invoiceItem

Omg, I'm sleeping standing up, updated it.

Update: I can't edit the message, so I will let it here.

<?php
/**
 *	Invoice with Primary/Dedicated IP WHMCS Hook version 1.1
 *
 *	@package     WHMCS
 *	@copyright   Andrezzz
 *	@link        https://www.andrezzz.pt
 *	@author      André Antunes <andreantunes@andrezzz.pt>
 */

if (!defined('WHMCS')) {
    exit(header('Location: https://www.andrezzz.pt'));
}

use WHMCS\Database\Capsule;

add_hook('InvoiceCreation', 1, function($vars) {
    global $_LANG;
    $typeOfItems = array('Hosting', 'Setup', 'PromoHosting', 'Upgrade');
    $invoiceItems = Capsule::table('tblinvoiceitems')->where('invoiceid', $vars['invoiceid'])->get();

    foreach ($invoiceItems as $invoiceItem) {
        if ($invoiceItem->relid === 0) return;
        if (!in_array($invoiceItem->type, $typeOfItems)) return;
        
        $dedicatedIP = Capsule::table('tblhosting')->where('id', $invoiceItem->relid)->value('dedicatedip');

        Capsule::table('tblinvoiceitems')->where('id', $invoiceItem->id)->update(array(
            'description' => $invoiceItem->description . "\n" . $_LANG['primaryIP'] . ': ' . trim($dedicatedIP)
        ));
    }
});

 

Edited by andrezzz

Share this post


Link to post
Share on other sites
5 minutes ago, pRieStaKos said:

Array is $typeOfItems. Not $invoiceItem

Thanks . I replaced all $invoiceItem to $typeOfItems . also shows blank page . 

in the phpmyadmin `tblerrorlog` , I found this error

file name : vendor/whmcs/whmcs-foundation/lib/Admin/Setup/General/UriManagement/ConfigurationController.php

message: strpos(): Empty needle

Share this post


Link to post
Share on other sites
5 minutes ago, andrezzz said:

Omg, I'm sleeping standing up, updated it.

Thanks for your help . 🤞

Share this post


Link to post
Share on other sites
1 minute ago, TimRef said:

Thanks . I replaced all $invoiceItem to $typeOfItems . also shows blank page . 

in the phpmyadmin `tblerrorlog` , I found this error

file name : vendor/whmcs/whmcs-foundation/lib/Admin/Setup/General/UriManagement/ConfigurationController.php

message: strpos(): Empty needle

Go to Configuration and enable Display Errors to see what is wrong.

Share this post


Link to post
Share on other sites
7 minutes ago, andrezzz said:

Omg, I'm sleeping standing up, updated it.

Update: I can't edit the message, so I will let it here.


<?php
/**
 *	Invoice with Primary/Dedicated IP WHMCS Hook version 1.1
 *
 *	@package     WHMCS
 *	@copyright   Andrezzz
 *	@link        https://www.andrezzz.pt
 *	@author      André Antunes <andreantunes@andrezzz.pt>
 */

if (!defined('WHMCS')) {
    exit(header('Location: https://www.andrezzz.pt'));
}

use WHMCS\Database\Capsule;

add_hook('InvoiceCreation', 1, function($vars) {
    global $_LANG;
    $typeOfItems = array('Hosting', 'Setup', 'PromoHosting', 'Upgrade');
    $invoiceItems = Capsule::table('tblinvoiceitems')->where('invoiceid', $vars['invoiceid'])->get();

    foreach ($invoiceItems as $invoiceItem) {
        if ($invoiceItem->relid === 0) return;
        if (!in_array($invoiceItem->type, $typeOfItems)) return;
        
        $dedicatedIP = Capsule::table('tblhosting')->where('id', $invoiceItem->relid)->value('dedicatedip');

        Capsule::table('tblinvoiceitems')->where('id', $invoiceItem->id)->update(array(
            'description' => $invoiceItem->description . "\n" . $_LANG['primaryIP'] . ': ' . trim($dedicatedIP)
        ));
    }
});

 

update to this , but still not working , also shows blank page . 

Share this post


Link to post
Share on other sites
1 minute ago, pRieStaKos said:

Go to Configuration and enable Display Errors to see what is wrong.

already enabled , but still shows blank . 

11111.png

Share this post


Link to post
Share on other sites
2 minutes ago, TimRef said:

already enabled , but still shows blank . 

11111.png

Activity log will show the issue on smarty. Go to Admin Area and follow the smarty error

Share this post


Link to post
Share on other sites
8 minutes ago, TimRef said:

Thanks . I replaced all $invoiceItem to $typeOfItems . also shows blank page . 

in the phpmyadmin `tblerrorlog` , I found this error

file name : vendor/whmcs/whmcs-foundation/lib/Admin/Setup/General/UriManagement/ConfigurationController.php

message: strpos(): Empty needle

That error, doesn't come from my Hook, do you have any other recent Hook?

Share this post


Link to post
Share on other sites
Just now, pRieStaKos said:

Activity log will show the issue on smarty. Go to Admin Area and follow the smarty error

did't get any errors in admin area activty log .

 

And I got this error in phpmyadmin 

#0 /home/wwwroot/my.xxx.com/vendor/whmcs/whmcs-foundation/lib/Invoice.php(0): WHMCS\Invoice->loadData()
#1 /home/wwwroot/my.xxx.com/vendor/whmcs/whmcs-foundation/lib/Invoice.php(0): WHMCS\Invoice->getData()
#2 /home/wwwroot/my.xxx.com/viewinvoice.php(0): WHMCS\Invoice->getModel()
#3 {main}

Message :Invalid invoice id provided

Class : WHMCS\Exception\Module\NotServicable

the attachment is for admin activity log . 

 

222.png

Share this post


Link to post
Share on other sites

seems the hook page is Loaded , but not working . 

on page /clientarea.php?action=invoices . not showing anything  . its a blank page .

Share this post


Link to post
Share on other sites
3 minutes ago, TimRef said:

did't get any errors in admin area activty log .

 

And I got this error in phpmyadmin 

#0 /home/wwwroot/my.xxx.com/vendor/whmcs/whmcs-foundation/lib/Invoice.php(0): WHMCS\Invoice->loadData()
#1 /home/wwwroot/my.xxx.com/vendor/whmcs/whmcs-foundation/lib/Invoice.php(0): WHMCS\Invoice->getData()
#2 /home/wwwroot/my.xxx.com/viewinvoice.php(0): WHMCS\Invoice->getModel()
#3 {main}

Message :Invalid invoice id provided

Class : WHMCS\Exception\Module\NotServicable

the attachment is for admin activity log . 

 

222.png

Do you have this two enabled?

image.png.27e7df1efaf091ddf434d005969ca22f.png

Share this post


Link to post
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.

Sign in to follow this  

  • 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