0

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:

enter image description here

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?

Dr.MTR
  • 207
  • 7
  • 19

1 Answers1

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}
wesamly
  • 1,484
  • 1
  • 16
  • 23
  • Hi your asnwer seems to work, but when try to see invoice, dont show dedicated IP for all orders.. See image.. Most of orders have dedicated IP, but not shown in invoice when try to see. https://i.imgur.com/5t0QZXa.png – Dr.MTR Mar 13 '18 at 10:49
  • I gave you the general idea how to do it, you have the starting point, use error_log(print_r($item, true), 3, __DIR__.'/file.log'); to check if ip is given. – wesamly Mar 13 '18 at 11:51
  • Where to put that? – Dr.MTR Mar 13 '18 at 11:54
  • 1
    in the hook loop inside if(...) – wesamly Mar 13 '18 at 11:55
  • SHowing me error when try po put there. https://i.imgur.com/cBQmxrH.png?1 See also table data: For only one order that show me: https://i.stack.imgur.com/1EZDY.png and table where is visible that almost every order have DedyIP : https://i.stack.imgur.com/SZsdJ.png – Dr.MTR Mar 13 '18 at 11:59
  • Also see this situation.. Its printing Dedicated IP: but there is not any IP adress.. Weird. https://i.imgur.com/YeaU57M.png?1 – Dr.MTR Mar 13 '18 at 12:15
  • you're not php developer? – wesamly Mar 13 '18 at 12:48
  • error_log(print_r($item, true), 3, DIR.'/file.log'); without use – wesamly Mar 13 '18 at 12:49
  • 1
    change {if $key|in_array:$dedicatedIps} to {if $key|in_array:$dedicatedIps && $dedicatedIps[$key] != ''} – wesamly Mar 13 '18 at 12:52
  • After inserting your code from before, again is not shown Dedicated IP into invocies.. See https://i.imgur.com/XH8yDZx.png?1 there have IP, but when check invoices, it not shown there. What can be problem? – Dr.MTR Mar 13 '18 at 13:02
  • 1
    in phpmyadmin run SELECT DISTINCT(type) from `tblinvoiceitems` and let me know the output – wesamly Mar 14 '18 at 06:30
  • After executing this SQL query from phpmyadmin: `SELECT DISTINCT(type) FROM tblinvoiceitems;` i got this result: https://i.imgur.com/rEQNp2c.png?1 – Dr.MTR Mar 14 '18 at 12:27
  • ok, change line: if ($item['type'] == 'Hosting') { to if (in_array($item['type'], ['Hosting', 'PromoHosting'])) { – wesamly Mar 14 '18 at 14:03
  • Updated that line, but looks like still not show everywhere. For example: Order #27 database data tblhosting: https://i.imgur.com/PMAHvLn.png?1 When check order 27 from whmcs, i dont see Dedicated IP.. See: https://i.imgur.com/FJqc3SU.png?1 – Dr.MTR Mar 14 '18 at 14:23