Jump to content

Showing dedicated IP in Paid Invoice and WHMCS billing


vpshove

Recommended Posts

So far I've hooked dedicated ip from tblhosting to viewinvoice.tpl and is assigned to paid services accordingly.

invoice.thumb.JPG.a49286d6ac1ea652f9f16ffae0246865.JPG

What I'm trying to figure out :

-> To show dedicated ip assigned in WHMCS Billing for -> Where you can view dedicated ip in the description as well. ( To help our billing member search for dedicated ip to be cancelled at ease by looking at customer's invoice items in WHMCS->Billing)

For example :

description.thumb.JPG.4407f6ea235a608d961fc5a7151042fd.JPG

 

 

What is in my mind :

How do I query the database tblhosting [dedicatedip] into WHMC->Billing->Invoices->Any customer's Invoice id description as shown above ?

As far as I know, WHMCS admin .php file is encoded where we do not able to edit.

Hopefully and I believe there is a way to append to show the dedicated ip !

 

Edited by leeyondking
Link to comment
Share on other sites

19 hours ago, leeyondking said:

Hopefully and I believe there is a way to append to show the dedicated ip !

if you already know how to get the dedicatedip value from tblhosting, then really all you need to do is append the tblinvoiceitems record with that value and update the database... if you can do that, you won't need the modification to viewinvoice and it would automatically be shown on the admin invoice page.

Link to comment
Share on other sites

11 hours ago, brian! said:

if you already know how to get the dedicatedip value from tblhosting, then really all you need to do is append the tblinvoiceitems record with that value and update the database... if you can do that, you won't need the modification to viewinvoice and it would automatically be shown on the admin invoice page.

May I assume that this can be done using the following hook as in https://docs.whmcs.com/Billing_Logic#Renewal_Invoices ?

I am confused for which add_hook type for this purpose.

Plus that I am not sure which www.yourdomain.com/system/templatefile.tpl I can debug with to verify. Could it still be viewinvoice.tpl ? Thanks ❤️

Edited by leeyondking
Link to comment
Share on other sites

18 hours ago, amit177 said:

I don't think there's a way to do that, since you can't find the service id based on the invoice id as far as I know.

you can - you already know the invoice number, so you can look that up in the tblinvoiceitems database table - for each item on that invoice, when the "type" value equals "Hosting", then that relid value will equal the ID value in tblhosting. (aka the service id).

18 hours ago, amit177 said:

What you might be able to do instead tho, is a hook that changes the "Domain" field to the dedicated IP when the module create action runs (since the domain field is added to invoices automatically).

I wouldn't go down that road.

11 hours ago, leeyondking said:

I am confused for which add_hook type for this purpose.

for newly created invoices, not existing invoices, i'd probably go down the InvoiceCreationPreEmail route - that way, you know the invoice has been created, but it hasn't been sent to the client yet - so any changes you make to it at this stage will be updated before the client ever sees the invoice.

if you update the tblinvoiceitems record, then it will be automatically visible everywhere that shows the description - so certainly the two clientarea invoice templates (PDF & HTML) and probably the invoice emails too... plus the admin invoice page.

Link to comment
Share on other sites

12 hours ago, brian! said:

for newly created invoices, not existing invoices, i'd probably go down the InvoiceCreationPreEmail route - that way, you know the invoice has been created, but it hasn't been sent to the client yet - so any changes you make to it at this stage will be updated before the client ever sees the invoice.

if you update the tblinvoiceitems record, then it will be automatically visible everywhere that shows the description - so certainly the two clientarea invoice templates (PDF & HTML) and probably the invoice emails too... plus the admin invoice page.

I've finally adapted laravel db query syntax other than standard sql. 😁

I get to update the tblinvoiceitems->description

However, in this case. It just a normal viewinvoice event hook.

I might change to InvoiceCreationPreEmail as youve mentioned.

Here's my code unoptimized version :

1. Beforehand, pls create new db table, tblflagPaid (id (Primary Key Auto Increment) , relid (int),  status (varchar) )

tblflagPaid consist of column named 'relid' where in tblhosting is named (id) and tblinvoiceitems is named (relid). [ id in tblhosting == relid ]

For status, it's up to you for what datatype to be kept. In my case I just leave it varchar holds an empty value.

Quote

function IP_to_desc($vars) 
{
    GLOBAL $smarty;
    $statuschk = $smarty->getVariable('status');
    
    if($statuschk == 'Paid')
    {
        $invoiceitems = $vars['invoiceitems'];
        
        foreach($invoiceitems as $key => $invoice)
        {
            $fetchip = Capsule::table('tblhosting')->where('id',$invoice['relid'])->value('dedicatedip'); */
            
            $chkflag = Capsule::table('tblflagPaid')->where('relid',$invoice['relid'])->value('status'); */
                
            $descriptionNew = Capsule::table('tblinvoiceitems')->where('relid',$invoice['relid'])->value('description')  */
            
            if($chkflag == '')
            {
                 $updateddesc = Capsule::table('tblinvoiceitems')
                ->where('relid', $invoice['relid'])
                ->update(
                    [
                        'description' => $descriptionNew."\n".$fetchip
                    ]
                ); 
                
               Capsule::table('tblflagPaid')
                ->insert(array("relid" => $invoice['relid'], "status" => "true")); 
            }
        }
    }
}

add_hook("ClientAreaPageViewInvoice", 1, "IP_to_desc");

?>

Hope someone can optimized it

Edited by leeyondking
Link to comment
Share on other sites

Sorry for dumb question.

Is InvoiceCreationPreEmail not related to viewinvoice.tpl ? Such that viewinvoice.tpl carry a array variable $invoiceitems...

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

I am not sure where I can debug for InvoiceCreationPreEmail

Edited by leeyondking
Link to comment
Share on other sites

 
 
 
 
 
 
 
5
On 3/9/2020 at 7:59 PM, brian! said:

you can - you already know the invoice number, so you can look that up in the tblinvoiceitems database table - for each item on that invoice, when the "type" value equals "Hosting", then that relid value will equal the ID value in tblhosting. (aka the service id).

Ah, I wasn't aware of that.

That's a much better route than the one I suggested then.

Link to comment
Share on other sites

On 10/03/2020 at 06:02, leeyondking said:

However, in this case. It just a normal viewinvoice event hook.

that wouldn't be the best way to do it - as it would run every time you view an invoice.

also, there are multiple errors in the code, e.g., you wouldn't need a separate database table to store whether the description has been updated; $fetchip is trying to pull a dedicated ip value regardless of whether the invoice item is of a hosting type - so if it were a domain, it would still try to pull a dedip value, and the only reason it's not adding it is that you're luckily not hitting an id value in thbhosting that has one; also, there's no need to get descriptionnew from the database as you're already looping through the invoiceitems array and the description value will be in there (though you would if you were using ICPE).

21 hours ago, leeyondking said:

Sorry for dumb question.

as someone once told me, there are no such thing as dumb questions - only dumb answers! 🙂

22 hours ago, leeyondking said:

Is InvoiceCreationPreEmail not related to viewinvoice.tpl ? Such that viewinvoice.tpl carry a array variable $invoiceitems...

the way to think of it is that the viewinvoice.tpl template is just outputting what is in the database; what invoicecreationpreemail is used for is to modify what's in the database before the client ever sees it.

I assume the way it's setup now on your install, a user buys a hosting product and gets an invoice that won't include a dedip value; you then edit the invoice, your hook adds a dedip and then you resend the invoice to them again.

with ICPE, the dedip is added to the invoiceitem desc before the invoice is ever sent to the client with no intervention by you.

22 hours ago, leeyondking said:

I am not sure where I can debug for InvoiceCreationPreEmail

you debug by creating invoices and seeing how the hook is affecting the content.... but in reality, you'll be able to do a lot without resorting to doing that because you know how to update a table now, you know how to pull values from tables, you know how to modify descriptions... so you just need to ensure that you're only modifying hosting items.

Link to comment
Share on other sites

On 3/11/2020 at 7:41 PM, brian! said:

with ICPE, the dedip is added to the invoiceitem desc before the invoice is ever sent to the client with no intervention by you.

Thanks for the courage trying the others ! 

I've intentionally use others as well

Hook :

ICPE, InvoiceCreation, and InvoiceCreated. [I get the idea of them are being triggered by cron]

These InvoiceCreation and InvoiceCreated are for having for when a cron generate and update the description having an IP for next coming invoice [Renewal]. *will remove one of them

They're working.. Both having the same codes and appended an dedicated IP onto invoices description in WHMCS. [Results two IPs appended in description]

Here's the code :

Quote

function PCronJOB2($vars){
    
    $invoiceid = $vars['invoiceid'];
        
    $descriptionNew = Capsule::table('tblinvoiceitems')->where('invoiceid',$invoiceid)->value('description');
    
    $relidno = Capsule::table('tblinvoiceitems')->where('invoiceid',$invoiceid)->value('relid');
        
    $fetchip = Capsule::table('tblhosting')->where('id',$relidno)->value('dedicatedip');
            
    $updateddesc = Capsule::table('tblinvoiceitems')->where('invoiceid',$invoiceid)->update(['description' => $descriptionNew."\nDedicated IP: ".$fetchip]); 
}

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

Similarly for InvoiceCreated.

However, when it comes to an Invoice of two/multiple items, the dedicated IP of item 1 will be shown on item 2's description as well.

Basically there's involve loop of array here and my variable $relidno doesn't get to fetch the next one.

So I comes up with a another code with a loop structure fetching for next relid. The no ip shown hmmmm interesting in this case. 

Quote

 function PCronJOB2($vars){

        $invoiceid = $vars['invoiceid'];
        
        $invoicedata = Capsule::table('tblinvoiceitems')->where('invoiceid',$invoiceid)->get();
        
        foreach($invoicedata as $data)
        {
            $relid[] = $data->relid;
            
            $descriptionNew = Capsule::table('tblinvoiceitems')->where('relid',$relid)->value('description'); 
            
            $fetchip = Capsule::table('tblhosting')->where('id',$relidno)->value('dedicatedip');
            
            $updateddesc = Capsule::table('tblinvoiceitems')->where('relid',$relid)->update(['description' => $descriptionNew."\nDedicated IP: ".$fetchip]);
        }

}

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

 

Edited by leeyondking
Link to comment
Share on other sites

On 3/11/2020 at 7:41 PM, brian! said:

$fetchip is trying to pull a dedicated ip value regardless of whether the invoice item is of a hosting type

Very true! I will take note on this 🤣 The text "Dedicated IP:" floating around with no value in web hosting.

 

Link to comment
Share on other sites

  • 1 year later...
  • 1 year 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.

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