Display Dedicated IP into viewinvoice.tpl and invoicepdf.tpl in WHMCS?

女生的网名这么多〃 提交于 2019-12-01 13:14:09

问题


Hi stack i have one issue that dont know how to resolve. I want to show Dedicated IP from customer order to show like this:

I make a short check, and found that need to be done into viewinvoice.tpl and invoicepdf.tpl files. i found that dedicated ip is stores into tblhosting table in database.

I found this code:

{php}
$clienthosting = $this->get_template_vars(service);
$dbid = $clienthosting['id'];  
$query = mysql_query("SELECT dedicatedip FROM tblhosting WHERE id = $dbid");  
$result = mysql_fetch_array($query); 
$dedicatedip = $result["dedicatedip"];   
$this->assign("dedicatedip", $dedicatedip); 
{/php} 

and finally to print:

           <td>{if $dedicatedip gt 0} - {$dedicatedip}{/if}{/if}</td>

and this is code from invoice.tpl where is printing data from customer purchase:

<tbody>
                            {foreach from=$invoiceitems item=item}
                                <tr>
                                    <td>{$item.description}{if $item.taxed eq "true"} *{/if}</td>
                                    <td class="text-center">{$item.amount}</td>
                                </tr>
                            {/foreach}



                            <tr>
                                <td class="total-row text-right"><strong>{$LANG.invoicessubtotal}</strong></td>
                                <td class="total-row text-center">{$subtotal}</td>
                            </tr>
                            {if $taxrate}
                                <tr>
                                    <td class="total-row text-right"><strong>{$taxrate}% {$taxname}</strong></td>
                                    <td class="total-row text-center">{$tax}</td>
                                </tr>
                            {/if}
                            {if $taxrate2}
                                <tr>
                                    <td class="total-row text-right"><strong>{$taxrate2}% {$taxname2}</strong></td>
                                    <td class="total-row text-center">{$tax2}</td>
                                </tr>
                            {/if}
                            <tr>
                                <td class="total-row text-right"><strong>{$LANG.invoicescredit}</strong></td>
                                <td class="total-row text-center">{$credit}</td>
                            </tr>
                            <tr>
                                <td class="total-row text-right"><strong>{$LANG.invoicestotal}</strong></td>
                                <td class="total-row text-center">{$total}</td>
                            </tr>
                        </tbody>

But this seems that generate white screen only when try to execute. Any help here?


回答1:


Create php file in whmcs_dir/includes/hooks/ (say: dedicated_ip.php) and add the following code:

<?php
use WHMCS\Database\Capsule as DB;
add_hook('ClientAreaPageViewInvoice', 1, function($vars) { 
    $dedicatedIps = [];

    foreach ($vars['invoiceitems'] as $k => $item) {
        $ip = '';
        if ($item['type'] == 'Hosting') {
            $hosting = DB::table('tblhosting')->select('dedicatedip')->where('id', $item['relid'])->first();
            if (!is_null($hosting)) {
                $ip = $hosting->dedicatedip;
            }
        } 
        $dedicatedIps[$k] = $ip;

    }
    return ['dedicatedIps' => $dedicatedIps];
});

This code will run only in the invoice view page, and adds an array of dedicated IPs for each invoice items. Domains for example will have empty ip.

Then in viewinvoice.tpl update the invoice items loop as following:

{foreach from=$invoiceitems item=item key=key}
    <tr>
        <td>
        {$item.description}{if $item.taxed eq "true"} *{/if}
        {if $key|in_array:$dedicatedIps}
        <br>IP: {$dedicatedIps[$key]}

        {/if}
        </td>
        <td class="text-center">{$item.amount}</td>
    </tr>
{/foreach}


来源:https://stackoverflow.com/questions/49162313/display-dedicated-ip-into-viewinvoice-tpl-and-invoicepdf-tpl-in-whmcs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!