2

I'm using WHMCS 8.x and Smarty PHP is already enabled.

I hope to use some code or hook function to let the dedicated ip or hostname to display on the page clientareainvoices.tpl (/clientarea.php?action=invoices) list . I hope anyone can help me with this . Thanks alot .

I have search a lot of plan , but all not working . I don't know whether this can be done with hook .

Hope someone of genius can help me about this .

the function like this in the picture .

enter image description here thanks thanks thanks.

I tried to use a hook file to do this . and tried to connect the database tables use left join . like : the file is like :

select * from tblinvoices t1 
left join tblinvoiceitems t2 on t1.id=t2.invoiceid
left join tblhosting t3 on t2.relid=t3.id
WHERE t3.dedicatedIP = value

And I add this into the hook file .

<?php

if (!defined("WHMCS")) {
    die("This file cannot be accessed directly");
}

use WHMCS\Database\Capsule as DB;

add_hook('ClientAreaPageInvoices', 1, function($vars) {
    
    $invoices = DB::table('tblinvoices')->where('invoicenum', $vars['invoicenum'])->get();

        $fieldId = 'invoicenum';
        $csVals = [];
        foreach ($invoices as $invoice) {
            $fieldVal = '';
            $data = DB::table('tblinvoices AS t1')
            ->leftJoin('tblinvoiceitems AS t2', 't1.invoicenum', '=', 't2.invoiceid')
            ->leftJoin('tblhosting AS t3', 't2.relid', '=', 't3.id')
            ->select('t3.domain')
            ->where('t1.invoicenum', $fieldId)->where('t3.domain', $invoice['invoicenum'])
            ->first();
            if (!is_null($data)) {
                $fieldVal = $data->value;
            }
            $csVals[$invoice['invoicenum']] = $fieldVal;
        }
        return ['domain' => $csVals];

});

But all not working for this . it shows a result "Array" , hope anybody can hlep me . thanks in advance .

Ref
  • 21
  • 2
  • I know I should creating a hook to pass the variable to .tpl and adjust the table code to present it, but I just don't know how to do it exactly . hope anyone can help . – Ref Jan 08 '22 at 01:35

1 Answers1

0

First you don't need to query invoices again, since the invoices are available in $vars['invoices'] variable.

$invoices = $vars['invoices'];

The code should work, you just need to edit the file clientareainvoices.tpl in your active template and replace:

<td>{$invoice.invoicenum}</td> with

<td>{$invoice.invoicenum} - {$domain[$invoice.invoicenum]}</td>

wesamly
  • 1,484
  • 1
  • 16
  • 23
  • thanks for reply , Wesamly . I have resolve this . the problem of this code is $data->value should be the domain table name .thanks. – Ref Jan 11 '22 at 08:05
  • @Ref Glad you solved your issue, and welcome :) – wesamly Jan 11 '22 at 10:21