Jump to content

add link only on paid invoices


Evgeny

Recommended Posts

Hello,

We try to add link in template (six) ->clientareainvoices.tpl in foreach section.

{foreach key=num item=invoice from=$invoices}
                <tr onclick="clickableSafeRedirect(event, 'viewinvoice.php?id={$invoice.id}', false)">
                    <td>{$invoice.invoicenum}
                    <br><a href="/index.php?m=mymodule&id={$invoice.id}" target="_blank"><u>Contract</u></a>
                    </td>
                    <td><span class="hidden">{$invoice.normalisedDateCreated}</span>{$invoice.datecreated}</td>
                    <td><span class="hidden">{$invoice.normalisedDateDue}</span>{$invoice.datedue}</td>
                    <td data-order="{$invoice.totalnum}">{$invoice.total}</td>
                    <td><span class="label status status-{$invoice.statusClass}">{$invoice.status}</span></td>
                    <td class="responsive-edit-button" style="display: none;">
                        <a href="viewinvoice.php?id={$invoice.id}" class="btn btn-block btn-info">
                            {$LANG.invoicesview}
                        </a>
                    </td>
                </tr>
            {/foreach}

This line

<br><a href="/index.php?m=mymodule&id={$invoice.id}" target="_blank"><u>Contract</u></a>

And link have added in all invoices, but we want to show this link only in Paid invoices.  How it make, we try add if $status="Paid", but it doesn’t work, we do something wrong, help me how it should look. Thanks.

Link to comment
Share on other sites

if you were going to do it in the template, you could do something like the code below and that should only show a contract link for paid invoices...

    <table id="tableInvoicesList" class="table table-list hidden">
        <thead>
            <tr>
                <th>{$LANG.invoicestitle}</th>
                <th>{$LANG.invoicesdatecreated}</th>
                <th>{$LANG.invoicesdatedue}</th>
                <th>{$LANG.invoicestotal}</th>
                <th>{$LANG.invoicesstatus}</th>
                <th></th>
            </tr>
        </thead>
        <tbody>
            {foreach key=num item=invoice from=$invoices}
                <tr onclick="clickableSafeRedirect(event, 'viewinvoice.php?id={$invoice.id}', false)">
                    <td>{$invoice.invoicenum}</td>
                    <td><span class="hidden">{$invoice.normalisedDateCreated}</span>{$invoice.datecreated}</td>
                    <td><span class="hidden">{$invoice.normalisedDateDue}</span>{$invoice.datedue}</td>
                    <td data-order="{$invoice.totalnum}">{$invoice.total}</td>
                    <td><span class="label status status-{$invoice.statusClass}">{$invoice.status}</span></td>
                    <td class="text-center">{if $invoice.rawstatus eq 'paid'}<a href="index.php?m=mymodule&id={$invoice.id}" target="_blank"><u>Contract</u></a>{/if}</td>
                </tr>
            {/foreach}
        </tbody>
    </table>

ZAulnNy.png

Link to comment
Share on other sites

On 29/07/2020 at 12:50, Evgeny said:

please tell me how to add one more condition here. Those. show a link for paid invoices only for payment gateway bank transfer. 

the array used on that invoices page doesn't include the gateway of each invoice, so you would have to adjust it with a hook...

<?php

# Add Gateway To Paid Invoices Array Hook
# Written by brian!

use WHMCS\Database\Capsule;

function add_gateway_to_invoices_array_hook($vars)
{
	$invoices = $vars['invoices'];	
	foreach ($invoices as $key => $invoice) {
		$paymentmethod = Capsule::table('tblinvoices')->where('id',$invoice['id'])->value('paymentmethod');
		if ($invoice['rawstatus'] == 'paid' && $paymentmethod == 'banktransfer') {
			$invoices[$key]['gateway'] = $paymentmethod;
		}
	}
	return array("invoices" => $invoices);
}
add_hook("ClientAreaPageInvoices", 1, "add_gateway_to_invoices_array_hook");

that allows you to change your if statement in the template from...

<td class="text-center">{if $invoice.rawstatus eq 'paid'}<a href="index.php?m=mymodule&id={$invoice.id}" target="_blank"><u>Contract</u></a>{/if}</td>
                

to...

<td class="text-center">{if $invoice.gateway}<a href="index.php?m=mymodule&id={$invoice.id}" target="_blank"><u>Contract</u></a>{/if}</td>
                

and then the  link will open appear for paid invoice using banktransfer.

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