Jump to content

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


TimRef

Recommended Posts

  • 3 weeks later...
  • Replies 52
  • Created
  • Last Reply

Top Posters In This Topic

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

Link to comment
Share on other sites

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
Link to comment
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)
        ));
    }
});

 

Link to comment
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 

Link to comment
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 ?  

Link to comment
Share on other sites

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
Link to comment
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

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

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

Link to comment
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?

Link to comment
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

Link to comment
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

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.

  • 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