Jump to content

About showing bank details in invoicepdf in whmcs


rahulkg

Recommended Posts

Hi,

In whmcs when we view an invoice as a client from admin side, it shows all the details of bank transfer , but if you download the invoice , it wont show all the bank details in pdf; so how can we modify the download pdf of invoice and incorporate all bank details same as that invoice shown when view as client . Please let me know how to do this?

Link to comment
Share on other sites

Hi Brian,

But in the link , https://whmcs.community/topic/291657-edit-pdf-adjust-logo-add-bank-details/ you manually input the bank acc no: but what I actually need is the bank address, bank axccount no, IBAN etc should come automatically in every invoice pdf just as view invoice page viewinvoice.php?id=xxxx&view_as_client=xxx what should be the code for that and how to modify invoicepdf.php file to add bank details. please give me a solution.

Link to comment
Share on other sites

36 minutes ago, rahulkg said:

But in the link , https://whmcs.community/topic/291657-edit-pdf-adjust-logo-add-bank-details/ you manually input the bank acc no: but what I actually need is the bank address, bank axccount no, IBAN etc should come automatically in every invoice pdf just as view invoice page viewinvoice.php?id=xxxx&view_as_client=xxx what should be the code for that and how to modify invoicepdf.php file to add bank details. please give me a solution.

well that thread was originally used to add details for various payment methods - not just the details used in the "Pay To" text area from the General Settings -> General page.

however, if all you want to do is use those details, then just add the variable $payto in your template layout and that will output the details from the above textarea.

Link to comment
Share on other sites

Not understand fully, you mean add bank details in payto textarea in whmcs General settings->General tab. So it will display in invoicepdf if  and only if the clients payment gateway is banktransfer ? or to achieve this (to show bank details if the client's payment gateway is banktransfer and otherwise not just as in viewinvoice) any condition to be written in invoicepdf file. please clarify this also.

Currently what I added is $pdf->writeHTML($payto, true, false, false, false, ''); in our invoicepdf file but it outputs our address instead of bankransfer.

Edited by rahulkg
Link to comment
Share on other sites

1 hour ago, rahulkg said:

Not understand fully, you mean add bank details in payto textarea in whmcs General settings->General tab.

sorry no - I was distracted and ended up pointing you in the wrong direction! 🙄

to get the bank transfer information you want, you'd have to pull it from the database...

use WHMCS\Database\Capsule;
$banktransfer = Capsule::table('tblpaymentgateways')->where('gateway','banktransfer')->where('setting','instructions')->value('value');

that above code can go anywhere in the invoicepdf.tpl file after <?php and before the place you need to output it.

taking the code from the previous thread...

if ($status!="Unpaid") {
# Transactions
$pdf->SetFont($pdfFont, 'B', 12);
$pdf->Cell(0, 4, Lang::trans('invoicestransactions'), 0, 1);

$pdf->Ln(5);

$pdf->SetFont($pdfFont, '', 9);

$tblhtml = '<table width="100%" bgcolor="#ccc" cellspacing="1" cellpadding="2" border="0">
    <tr height="30" bgcolor="#efefef" style="font-weight:bold;text-align:center;">
        <td width="25%">' . Lang::trans('invoicestransdate') . '</td>
        <td width="25%">' . Lang::trans('invoicestransgateway') . '</td>
        <td width="30%">' . Lang::trans('invoicestransid') . '</td>
        <td width="20%">' . Lang::trans('invoicestransamount') . '</td>
    </tr>';

if (!count($transactions)) {
    $tblhtml .= '
    <tr bgcolor="#fff">
        <td colspan="4" align="center">' . Lang::trans('invoicestransnonefound') . '</td>
    </tr>';
} else {
    foreach ($transactions AS $trans) {
        $tblhtml .= '
        <tr bgcolor="#fff">
            <td align="center">' . $trans['date'] . '</td>
            <td align="center">' . $trans['gateway'] . '</td>
            <td align="center">' . $trans['transid'] . '</td>
            <td align="center">' . $trans['amount'] . '</td>
        </tr>';
    }
}
$tblhtml .= '
    <tr height="30" bgcolor="#efefef" style="font-weight:bold;">
        <td colspan="3" align="right">' . Lang::trans('invoicesbalance') . '</td>
        <td align="center">' . $balance . '</td>
    </tr>
</table>';

$pdf->writeHTML($tblhtml, true, false, false, false, '');
} elseif ($paymentmethod=="Bank Transfer") { // The "visible name" of the payment method 

#Payment Method

$pdf->SetFont($pdfFont,'B',12);
$pdf->Cell(0,4,"Payment",0,1);

$pdf->Ln(5);

$pdf->SetFont($pdfFont,'',8); 

$paymethhtml = '<table width="100%" bgcolor="#ccc" cellspacing="1" cellpadding="2" border="0">
    <tr height="30" !bgcolor="#efefef" !style="font-weight:bold;text-align:center;">
        <td width="33%" bgcolor="#efefef" style="text-align:center;"><strong>Bank Transfer</strong></td>
        <td width="67%" bgcolor="#ffffff" style="text-align:center;">'.nl2br($banktransfer).'</td>
    </tr>
	</table>';

$pdf->writeHTML($paymethhtml, true, false, false, false, '');
	
}

so if an invoice is not unpaid, it displays the transactions table.... if the invoice is currently unpaid, and the gateway is Bank Transfer, then it will display the table that shows the payto methods for the Bank Transfer method pulled from the database (which is what you enter into the instructions textarea in the payment gateways setting for that gateway.

Link to comment
Share on other sites

  • 1 month later...

Hi Brian ,

But the code breaks when whmcs upgraded to 7.8.3.

even after adding 

use WHMCS\Database\Capsule;
$banktransfer = Capsule::table('tblpaymentgateways')->where('gateway','banktransfer')->where('setting','instructions')->value('value');

line after php opening tag it says "OOPS error message". Could you please check and update me.

Link to comment
Share on other sites

18 hours ago, rahulkg said:

line after php opening tag it says "OOPS error message".

when that happens, you need to enable Display Errors in setup -> general settings -> other and it will tell you what and where the error is... that is useful info for me to know so that I can debug it.

I don't think there is anything wrong with the actual code - try the attached file in your v7.8.3 install.

invoicepdf.tpl

Link to comment
Share on other sites

  • 1 year later...
On 8/7/2019 at 2:02 PM, brian! said:

sorry no - I was distracted and ended up pointing you in the wrong direction! 🙄

to get the bank transfer information you want, you'd have to pull it from the database...


use WHMCS\Database\Capsule;
$banktransfer = Capsule::table('tblpaymentgateways')->where('gateway','banktransfer')->where('setting','instructions')->value('value');

that above code can go anywhere in the invoicepdf.tpl file after <?php and before the place you need to output it.

taking the code from the previous thread...


if ($status!="Unpaid") {
# Transactions
$pdf->SetFont($pdfFont, 'B', 12);
$pdf->Cell(0, 4, Lang::trans('invoicestransactions'), 0, 1);

$pdf->Ln(5);

$pdf->SetFont($pdfFont, '', 9);

$tblhtml = '<table width="100%" bgcolor="#ccc" cellspacing="1" cellpadding="2" border="0">
    <tr height="30" bgcolor="#efefef" style="font-weight:bold;text-align:center;">
        <td width="25%">' . Lang::trans('invoicestransdate') . '</td>
        <td width="25%">' . Lang::trans('invoicestransgateway') . '</td>
        <td width="30%">' . Lang::trans('invoicestransid') . '</td>
        <td width="20%">' . Lang::trans('invoicestransamount') . '</td>
    </tr>';

if (!count($transactions)) {
    $tblhtml .= '
    <tr bgcolor="#fff">
        <td colspan="4" align="center">' . Lang::trans('invoicestransnonefound') . '</td>
    </tr>';
} else {
    foreach ($transactions AS $trans) {
        $tblhtml .= '
        <tr bgcolor="#fff">
            <td align="center">' . $trans['date'] . '</td>
            <td align="center">' . $trans['gateway'] . '</td>
            <td align="center">' . $trans['transid'] . '</td>
            <td align="center">' . $trans['amount'] . '</td>
        </tr>';
    }
}
$tblhtml .= '
    <tr height="30" bgcolor="#efefef" style="font-weight:bold;">
        <td colspan="3" align="right">' . Lang::trans('invoicesbalance') . '</td>
        <td align="center">' . $balance . '</td>
    </tr>
</table>';

$pdf->writeHTML($tblhtml, true, false, false, false, '');
} elseif ($paymentmethod=="Bank Transfer") { // The "visible name" of the payment method 

#Payment Method

$pdf->SetFont($pdfFont,'B',12);
$pdf->Cell(0,4,"Payment",0,1);

$pdf->Ln(5);

$pdf->SetFont($pdfFont,'',8); 

$paymethhtml = '<table width="100%" bgcolor="#ccc" cellspacing="1" cellpadding="2" border="0">
    <tr height="30" !bgcolor="#efefef" !style="font-weight:bold;text-align:center;">
        <td width="33%" bgcolor="#efefef" style="text-align:center;"><strong>Bank Transfer</strong></td>
        <td width="67%" bgcolor="#ffffff" style="text-align:center;">'.nl2br($banktransfer).'</td>
    </tr>
	</table>';

$pdf->writeHTML($paymethhtml, true, false, false, false, '');
	
}

so if an invoice is not unpaid, it displays the transactions table.... if the invoice is currently unpaid, and the gateway is Bank Transfer, then it will display the table that shows the payto methods for the Bank Transfer method pulled from the database (which is what you enter into the instructions textarea in the payment gateways setting for that gateway.

Brian, how to use this in whmcs 8 ? tblpaymentgateways/banktransfer/instructions is obfuscated ... tnx

Link to comment
Share on other sites

On 29/01/2021 at 23:42, Phasma said:

Brian, how to use this in whmcs 8 ? tblpaymentgateways/banktransfer/instructions is obfuscated ... tnx

instead of using capsule...

use WHMCS\Database\Capsule;
$banktransfer = Capsule::table('tblpaymentgateways')->where('gateway','banktransfer')->where('setting','instructions')->value('value');

in v8, you could use this...

require_once ROOTDIR . '/includes/gatewayfunctions.php';
$banktransfer = getGatewayVariables('banktransfer');

... and then where you previously had...

<td width="67%" bgcolor="#ffffff" style="text-align:center;">'.nl2br($banktransfer).'</td>

you change it to...

<td width="67%" bgcolor="#ffffff" style="text-align:center;">'.nl2br($banktransfer['instructions']).'</td>
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