Jump to content

Custom Invoice Based On Clients Group


Code-Storm

Recommended Posts

12 minutes ago, Code-Storm said:

Is it possible to customize default invoice template  based on different clients group. like when i select clients group 1 it will show the different logo instead the default branded logo

yes - I do it myself... you just need to use $clientsdetails['groupid'] == '1' in one of the if statements in the logo block of code..

 

Link to comment
Share on other sites

# Logo
if ($clientsdetails['groupid'] == '1') {
	if (file_exists(ROOTDIR.'/assets/img/brian.png')) $pdf->Image(ROOTDIR.'/assets/img/brian.png',20,15,36);	
}
else {
if (file_exists(ROOTDIR.'/assets/img/logo.png')) $pdf->Image(ROOTDIR.'/assets/img/logo.png',20,25,75);
elseif (file_exists(ROOTDIR.'/assets/img/logo.jpg')) $pdf->Image(ROOTDIR.'/assets/img/logo.jpg',20,25,75);
else $pdf->Image(ROOTDIR.'/assets/img/placeholder.png',20,25,75);
}

the tricky part will be if the logos are different sizes - mine are... so that's when you'll have to play with the 20,25,75 values... if they're the same size, then you could use the code that's already in the template and just add the groupid check to one of the if statements.

Edited by brian!
Link to comment
Share on other sites

1 hour ago, brian! said:

# Logo
if ($clientsdetails['groupid'] == '1') {
	if (file_exists(ROOTDIR.'/assets/img/brian.png')) $pdf->Image(ROOTDIR.'/assets/img/brian.png',20,15,36);	
}
else {
if (file_exists(ROOTDIR.'/assets/img/logo.png')) $pdf->Image(ROOTDIR.'/assets/img/logo.png',20,25,75);
elseif (file_exists(ROOTDIR.'/assets/img/logo.jpg')) $pdf->Image(ROOTDIR.'/assets/img/logo.jpg',20,25,75);
else $pdf->Image(ROOTDIR.'/assets/img/placeholder.png',20,25,75);
}

the tricky part will be if the logos are different sizes - mine are... so that's when you'll have to play with the 20,25,75 values... if they're the same size, then you could use the code that's already in the template and just add the groupid check to one of the if statements.

Hello Brian!

Thank you very much for your code.

however i paste your code to invoicepdf.tpl  and save it but when i download or view the invoice from clients or admin panel still it's showing with default logo .

whmcs.jpg

Link to comment
Share on other sites

16 hours ago, Code-Storm said:

however i paste your code to invoicepdf.tpl  and save it but when i download or view the invoice from clients or admin panel still it's showing with default logo .

you don't know it yet, but this is good news as I know that it's working. 😎

you've added a (or haven't removed an existing) line of code that doesn't need to be there, that I didn't give you(!) and isn't showing in your screenshot of the code above. 😲

in your invoicepdf.tpl template, you currently have...

# Logo
$logoFilename = 'placeholder.png';
if ($clientsdetails['groupid'] == '4') {
	if (file_exists(ROOTDIR.'/assets/img/sl.png')) $pdf->Image(ROOTDIR.'/assets/img/sl.png',15,25,75);	
}
else {
if (file_exists(ROOTDIR . '/assets/img/logo.png')) {
    $logoFilename = 'logo.png';
} elseif (file_exists(ROOTDIR . '/assets/img/logo.jpg')) {
    $logoFilename = 'logo.jpg';
}
}
$pdf->Image(ROOTDIR . '/assets/img/' . $logoFilename, 15, 25, 75);

for clients in group #4, it is displaying your new sl.png logo, but then that last line is displaying logo or placeholder directly on top of it... so your custom logo is there, but is being overlayed by another image.

the solution would be to use the code I gave you, or if you're going to use your existing code, move that last line before the closing brackets and into the IF statement. 🙂

# Logo
$logoFilename = 'placeholder.png';
if ($clientsdetails['groupid'] == '4') {
	if (file_exists(ROOTDIR.'/assets/img/sl.png')) $pdf->Image(ROOTDIR.'/assets/img/sl.png',15,25,75);	
}
else {
if (file_exists(ROOTDIR . '/assets/img/logo.png')) {
    $logoFilename = 'logo.png';
} elseif (file_exists(ROOTDIR . '/assets/img/logo.jpg')) {
    $logoFilename = 'logo.jpg';
}
$pdf->Image(ROOTDIR . '/assets/img/' . $logoFilename, 15, 25, 75);
}
Link to comment
Share on other sites

8 hours ago, brian! said:

you don't know it yet, but this is good news as I know that it's working. 😎

you've added a (or haven't removed an existing) line of code that doesn't need to be there, that I didn't give you(!) and isn't showing in your screenshot of the code above. 😲

in your invoicepdf.tpl template, you currently have...


# Logo
$logoFilename = 'placeholder.png';
if ($clientsdetails['groupid'] == '4') {
	if (file_exists(ROOTDIR.'/assets/img/sl.png')) $pdf->Image(ROOTDIR.'/assets/img/sl.png',15,25,75);	
}
else {
if (file_exists(ROOTDIR . '/assets/img/logo.png')) {
    $logoFilename = 'logo.png';
} elseif (file_exists(ROOTDIR . '/assets/img/logo.jpg')) {
    $logoFilename = 'logo.jpg';
}
}
$pdf->Image(ROOTDIR . '/assets/img/' . $logoFilename, 15, 25, 75);

for clients in group #4, it is displaying your new sl.png logo, but then that last line is displaying logo or placeholder directly on top of it... so your custom logo is there, but is being overlayed by another image.

the solution would be to use the code I gave you, or if you're going to use your existing code, move that last line before the closing brackets and into the IF statement. 🙂


# Logo
$logoFilename = 'placeholder.png';
if ($clientsdetails['groupid'] == '4') {
	if (file_exists(ROOTDIR.'/assets/img/sl.png')) $pdf->Image(ROOTDIR.'/assets/img/sl.png',15,25,75);	
}
else {
if (file_exists(ROOTDIR . '/assets/img/logo.png')) {
    $logoFilename = 'logo.png';
} elseif (file_exists(ROOTDIR . '/assets/img/logo.jpg')) {
    $logoFilename = 'logo.jpg';
}
$pdf->Image(ROOTDIR . '/assets/img/' . $logoFilename, 15, 25, 75);
}

Hello Brain,

Sorry for misunderstood! actually i am using your code , that you gave me and you already saw. but still it's showing default logo while i view the invoices but when i download it it will show the group id logo.

Link to comment
Share on other sites

17 hours ago, Code-Storm said:

Sorry for misunderstood! actually i am using your code , that you gave me and you already saw. but still it's showing default logo while i view the invoices but when i download it it will show the group id logo.

did you try changing the code to the updated version that you quoted ?

Link to comment
Share on other sites

5 hours ago, brian! said:

did you try changing the code to the updated version that you quoted ?

No I didn't. just use the below code and it's works fine when i download invoice

<?php

# Logo
if ($clientsdetails['groupid'] == '6') {
    if (file_exists(ROOTDIR.'/assets/img/sl-logo.png')) $pdf->Image(ROOTDIR.'/assets/img/sl-logo.png',20,25,52);    
}
else {
if (file_exists(ROOTDIR.'/assets/img/logo.png')) $pdf->Image(ROOTDIR.'/assets/img/logo.png',20,25,75);
elseif (file_exists(ROOTDIR.'/assets/img/logo.jpg')) $pdf->Image(ROOTDIR.'/assets/img/logo.jpg',20,25,75);
else $pdf->Image(ROOTDIR.'/assets/img/placeholder.png',20,25,75);
}


# Invoice Status

what i need to do if i have different usergroup like affiliate group, general group, xyz group

Edited by Code-Storm
Link to comment
Share on other sites

15 hours ago, Code-Storm said:

what i need to do if i have different usergroup like affiliate group, general group, xyz group

you would expand the first if statement...

# Logo
if ($clientsdetails['groupid'] == '6' && file_exists(ROOTDIR.'/assets/img/sl-logo.png')) {
$pdf->Image(ROOTDIR.'/assets/img/sl-logo.png',20,25,52);
}
elseif ($clientsdetails['groupid'] == '1' && file_exists(ROOTDIR.'/assets/img/sl-logo1.png')) {
$pdf->Image(ROOTDIR.'/assets/img/sl-logo1.png',20,25,52);
}
elseif ($clientsdetails['groupid'] == '2' && file_exists(ROOTDIR.'/assets/img/sl-logo2.png')) {
$pdf->Image(ROOTDIR.'/assets/img/sl-logo2.png',20,25,52);
}
else {
if (file_exists(ROOTDIR.'/assets/img/logo.png')) $pdf->Image(ROOTDIR.'/assets/img/logo.png',20,25,75);
elseif (file_exists(ROOTDIR.'/assets/img/logo.jpg')) $pdf->Image(ROOTDIR.'/assets/img/logo.jpg',20,25,75);
else $pdf->Image(ROOTDIR.'/assets/img/placeholder.png',20,25,75);
} 

remembering that the image filenames and 20,25,52 (x,y,width) will need to be adjusted for each client group.

Link to comment
Share on other sites

1 minute ago, brian! said:

you would expand the first if statement...


# Logo
if ($clientsdetails['groupid'] == '6' && file_exists(ROOTDIR.'/assets/img/sl-logo.png')) {
$pdf->Image(ROOTDIR.'/assets/img/sl-logo.png',20,25,52);
}
elseif ($clientsdetails['groupid'] == '1' && file_exists(ROOTDIR.'/assets/img/sl-logo1.png')) {
$pdf->Image(ROOTDIR.'/assets/img/sl-logo1.png',20,25,52);
}
elseif ($clientsdetails['groupid'] == '2' && file_exists(ROOTDIR.'/assets/img/sl-logo2.png')) {
$pdf->Image(ROOTDIR.'/assets/img/sl-logo2.png',20,25,52);
}
else {
if (file_exists(ROOTDIR.'/assets/img/logo.png')) $pdf->Image(ROOTDIR.'/assets/img/logo.png',20,25,75);
elseif (file_exists(ROOTDIR.'/assets/img/logo.jpg')) $pdf->Image(ROOTDIR.'/assets/img/logo.jpg',20,25,75);
else $pdf->Image(ROOTDIR.'/assets/img/placeholder.png',20,25,75);
} 

remembering that the image filenames and 20,25,52 (x,y,width) will need to be adjusted for each client group.

Hello Brian,

Thank you very much!

so every time i need to extend this line  if i add more client group in my system

----------------

elseif ($clientsdetails['groupid'] == '2' && file_exists(ROOTDIR.'/assets/img/sl-logo2.png')) {
$pdf->Image(ROOTDIR.'/assets/img/sl-logo2.png',20,25,52);
}

---------------------

but yet when i view the invoice it's showing me the default logo instead clients-group logo . 

Link to comment
Share on other sites

6 minutes ago, Code-Storm said:

Viewing the HTML Invoice in browser  with this link   https://www.example.com/clients/viewinvoice.php?id=42653&view_as_client=1

aah I thought that might be what you were doing - the changes we've talked about in this thread only relate to invoicepdf.tpl and will therefore only affect the PDF invoices.

if you wanted to do the same with the HTML invoices, then you're either looking at editing viewinvoice.tpl and using similar if statements (though tweaked for Smarty rather than PHP/TCPDF), or you use an action hook to change the company logo array based on the value of the client group ID.

Link to comment
Share on other sites

2 minutes ago, brian! said:

aah I thought that might be what you were doing - the changes we've talked about in this thread only relate to invoicepdf.tpl and will therefore only affect the PDF invoices.

if you wanted to do the same with the HTML invoices, then you're either looking at editing viewinvoice.tpl and using similar if statements (though tweaked for Smarty rather than PHP/TCPDF), or you use an action hook to change the company logo array based on the value of the client group ID.

Hello Brian,

i thought if i change the code to file then it will work for both viewinvoice & download invoice. but here things different and i acknowledge that i have not knowledge in Smarty PHP. can you brian help me with those line of that i need to change in files.

Link to comment
Share on other sites

13 minutes ago, Code-Storm said:

i thought if i change the code to file then it will work for both viewinvoice & download invoice.

no they're entirely different beasts and independent of each other... if you need to change the logos on both HTML and PDF, then you'll need two solutions...

sadly, there's no magic bullet to fix both at the same time - not least because you can't use action hooks with the invoicepdf.tpl template.

13 minutes ago, Code-Storm said:

can you brian help me with those line of that i need to change in files.

as an action hook, it would be along the lines of...

<?php

# Change Company Logo Based On Client Group Hook
# Written by brian!

add_hook('ClientAreaPageViewInvoice', 1, function($vars) {
	
	$systemurl = $vars['systemurl'].'assets/img/';
	$clientgroup = $vars['clientsdetails']['groupid'];
	if ($clientgroup == '6') {
		$companylogo = $systemurl.'sl-logo.png';
		return array("logo" => $companylogo);
	}
	elseif ($clientgroup == '1') {
		$companylogo = $systemurl.'sl-logo1.png';
		return array("logo" => $companylogo);
	}	
});

for now, i'm going to assume that all the logos you are going to use are in your /assets/img/ folder... just create a .php file in /includes/hooks, give it a filename and paste the above code into it.

as with the PDF template, you can just keep expanding those elseif statements to cover the client groups you want to use a custom logo.

if a client is not in any client group, or in a client group that you don't want to use a custom logo with, then they will see the usual company logo as specified in your general settings... the hook could specify a logo for these users if it had to, but out of the box it will make no changes for them.

Edited by brian!
Link to comment
Share on other sites

7 minutes ago, brian! said:

no they're entirely different beasts and independent of each other... if you need to change the logos on both HTML and PDF, then you'll need two solutions... there's no magic bullet to fix both at the same time - not least because you can't use action hooks with teh invoicepdf.tpl template.

as an action hook, it would be along the lines of...


<?php

# Change Coampany Logo Based On Client Group Hook
# Written by brian!

add_hook('ClientAreaPageViewInvoice', 1, function($vars) {
	
	$systemurl = $vars['systemurl'].'assets/img/';
	$clientgroup = $vars['clientsdetails']['groupid'];
	if ($clientgroup == '6') {
		$companylogo = $systemurl.'sl-logo.png';
		return array("logo" => $companylogo);
	}
	elseif ($clientgroup == '1') {
		$companylogo = $systemurl.'sl-logo1.png';
		return array("logo" => $companylogo);
	}	
});

for now, i'm going to assume that all the logos you are going to use are in your /assets/img/ folder... just create a .php file in /includes/hooks, give it a filename and paste the above code into it.

as with the PDF template, you can just keep expanding those elseif statements to cover the client groups you want to use a custom logo.

if a client is not in any client group, or in a client group that you don't want to use a custom logo with, then they will see the usual company logo as specified in your general settings... the hook could specify a logo for these users if it had to, but out of the box it will make no changes for them.

Hello Brian!

Thanks a lot and and above code will be enough for me. and it's working perfectly

Thank you very much

Edited by Code-Storm
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