Jump to content

Add Other Product (Service) username to PDF invoice


Recommended Posts

Hi

 

I need to add the service username to PDF invoice, I believe this can be done via a hook, but a bit beyond me.

 

I have re-sellers that have several clients, and at the moment when an invoice is created and sent, it does not include any reference to which one of their clients the invoice is for.

 

Thanks

 

Steven

Link to comment
Share on other sites

Hi Steven,

 

I need to add the service username to PDF invoice, I believe this can be done via a hook, but a bit beyond me.

I have re-sellers that have several clients, and at the moment when an invoice is created and sent, it does not include any reference to which one of their clients the invoice is for.

for something like this, it's easier to modify the invoicepdf.tpl template and add the required code in there.

 

so at the top of the file, you need to enable Capsule so that you can query the database...

 

<?php
use Illuminate\Database\Capsule\Manager as Capsule;

 

and then in the # Invoice Items block of code, you can change...

 

foreach ($invoiceitems as $item) {
   $tblhtml .= '
   <tr bgcolor="#fff">
       <td align="left">' . nl2br($item['description']) . '<br /></td>
       <td align="center">' . $item['amount'] . '</td>
   </tr>';
}

to...

 

foreach ($invoiceitems as $item) {

   $serviceusername = Capsule::table('tblhosting')
                       ->where('userid',$userid)
                       ->where('id',$item['relid'])
                       ->pluck('username');

   if ($serviceusername) {

       $tblhtml .= '
       <tr bgcolor="#fff">
           <td align="left">' . nl2br($item['description']) . '<br />'. Lang::trans('serverusername'). ': ' . $serviceusername .'<br /></td>
           <td align="center">' . $item['amount'] . '</td>
       </tr>';
   } else {                        
       $tblhtml .= '
       <tr bgcolor="#fff">
           <td align="left">' . nl2br($item['description']) . '<br /></td>
           <td align="center">' . $item['amount'] . '</td>
       </tr>';
   }
}

i'm not sure how you wanted to output the username, so for those product(s) that have a service username, it should now be displayed in the invoice for each applicable product below the description of the product. :idea:

 

note - if you're going to use this on WHMCS v7, modify the code by changing 'pluck' to 'value'.

Edited by brian!
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