Jump to content

I have two Different SAC code for hosting and domains and want two show them on invoices.


bagfuloz

Recommended Posts

Hello Guys,

 

Facing issue with statement code under invoices. so issue is -

 

I have two Different SAC code for hosting and domains and want to show them on invoices.

 

Ex - For Domain - SAC: 12345

Ex - For Hosting - SAC: 45154

 

So I want show it on view invoice but if client raise order for domain, so it should show Domain Sac code else Hosting Sac code.

 

I have added custom code - check the same.

 

{if $invoiceitems.1.type = 'Domain'}

<td class="total-row text-center">{$LANG.invoicessacdom}</td>

{elseif $invoiceitems.1.type = 'Hosting'}

<td class="total-row text-center">{$LANG.invoicessachost}</td>

{/if}

 

I have created two lang in lang/English.php file check the same -

 

$_LANG['invoicessachost'] = "Hosting SAC: 998315 | Domain SSAC: N/A";

 

$_LANG['invoicessacdom'] = "SAC: N/A";

 

But its showing only one output, that is " invoicessacdom "

 

can you tell me, how to get this done?

Link to comment
Share on other sites

I would probably be inclined to modify the {foreach} loop and extend the description table row...

 

{foreach from=$invoiceitems item=item}
   <tr>
       <td>{$item.description}{if $item.taxed eq "true"} *{/if}<br>{if $item.type eq 'Hosting'}{$LANG.invoicessachost}{elseif $item.type eq 'DomainRegister'}{$LANG.invoicessacdom}{/if}</td>
       <td class="text-center">{$item.amount}</td>
   </tr>
{/foreach}

 

8u5C3lb.png

 

also, note that your code isn't checking for domain transfers, addons etc - so you might need to expand the code to check for that. :idea:

Link to comment
Share on other sites

Thanks for the reply Brian, Its working. and how done same on pdf invoices ?

it's going to be fairly similar, except you move the IF statement before the output...

 

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) {

   if ($item['type'] == "Hosting") {
       $typeoutput = Lang::trans('invoicessachost').'<br />';
   }
   elseif ($item['type'] == "DomainRegister") {
       $typeoutput = Lang::trans('invoicessacdom').'<br />';
   }
   else {
       $typeoutput = "";
   }

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

sEMAfU5.png

 

and when you want to add more conditions (transfers, addfunds, addons etc), you can just add more elseif conditions (before the final else) to the code.

Link to comment
Share on other sites

sorry, perhaps I should have explained clearer...

 

the first {foreach} block of code that I posted above already exists in invoicepdf.tpl - what you need to do is replace it with the second block of code...

 

so don't add it separately after Notes, replace the foreach loop that is already there... do that and it should work. :idea:

Link to comment
Share on other sites

if you haven't modified/expanded the above code - as a temporary test, can you change..

 

<td align="left">' . nl2br($item['description']) . '<br />' . $typeoutput . '</td>

to..

<td align="left">' . nl2br($item['description']) . '<br />' . $item['type'] . '</td>

because I think they may not be considered 'Hosting' products in the database - I think they'll be 'server' and/or 'other' and if so, that's why the code isn't outputting anything.

 

what the above code should do is output the type of the product as stored in the database, e.g DomainRegister, Hosting, Server, Other, AddFunds etc.. if so, then just add more elseif statements to check for these other product types.

Link to comment
Share on other sites

why is the output (SAC: 998315) outside of the foreach loop as per my code?

 

if the output is going to be there then it will use the last value of the foreach loop - which in the first image is going to be "hosting"; and in the second, I assume those products aren't using the hosting type and therefore display nothing.

 

so the problem is not the number of items in the invoice, it's the location of the output... or if you intend to only show one SAC code per invoice, then the code will need to change.

 

I bet if you change your code to...

if ($item['type'] == "Hosting") {
       $typeoutput = Lang::trans('invoicessachost').'<br />';
   }
   elseif ($item['type'] == "DomainRegister") {
       $typeoutput = Lang::trans('invoicessacdom').'<br />';
   }
   else {
       $typeoutput = "Brian";
   }

... on the 2 product invoice, it will show the word "Brian" as the output.

Link to comment
Share on other sites

Sorry Brian, Sorry for my silly mistake, next time i will be-careful with this. Now i have clear idea, about it.

 

Here product is Custom Dedicated hosting, so i try searching it in template variables by using {debug}, but not getting relevant search for custom dedicated or dedicated hosting variables. Please can you suggest some?

 

 

 

Thanks

Link to comment
Share on other sites

As per my knowledge, I have added this code elseif ($customfields['type'] == "customfield") {

$typeoutput = Lang::trans('invoicessachost').'<br />';

}

 

 

but no luck. need right variable here.

Edited by bagfuloz
Link to comment
Share on other sites

Sorry Brian, Sorry for my silly mistake, next time i will be-careful with this. Now i have clear idea, about it.

Here product is Custom Dedicated hosting, so i try searching it in template variables by using {debug}, but not getting relevant search for custom dedicated or dedicated hosting variables. Please can you suggest some?

if we're still talking about invoicepdf.tpl, using {debug} won't get you anywhere as it's not a Smarty template... there would be alternate ways of displaying the variables, but you won't need to as i've already told you the code to use..

 

https://forum.whmcs.com/showthread.php?131233-I-have-two-Different-SAC-code-for-hosting-and-domains-and-want-two-show-them-on-invoices&p=524941#post524941

 

you could replace the foreach loop with this...

 

foreach ($invoiceitems as $item) {

   if ($item['type'] == "Hosting") {
       $typeoutput = Lang::trans('invoicessachost').'<br />';
   }
   elseif ($item['type'] == "DomainRegister") {
       $typeoutput = Lang::trans('invoicessacdom').'<br />';
   }
   else {
       $typeoutput = "";
   }

   $tblhtml .= '
   <tr bgcolor="#fff">
       <td align="left">' . nl2br($item['description']) . '<br /><span style="background-color: #FFFF00">' . $item['type'] . '</span></td> 
       <td align="center">' . $item['amount'] . '</td>
   </tr>';
}

that will [highlight]highlight in yellow[/highlight] the product/service type text you need to use...

 

SnxLZYE.png

 

then once you know the value for your dedicated hosting product, you can change the foreach code back to the previous version... e.g let's say we add DomainTransfer as an option...

 

foreach ($invoiceitems as $item) {

   if ($item['type'] == "Hosting") {
       $typeoutput = Lang::trans('invoicessachost').'<br />';
   }
   elseif ($item['type'] == "DomainRegister") {
       $typeoutput = Lang::trans('invoicessacdom').'<br />';
   }
   elseif ($item['type'] == "DomainTransfer") {
       $typeoutput = Lang::trans('invoicessacdom').'<br />';
   }    
   else {
       $typeoutput = "";
   }

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

Link to comment
Share on other sites

Thanks for valuable reply Brian, Its also done,

 

Here is the Final code -

 

# Invoice Items

$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="80%">' . Lang::trans('invoicesdescription') . '</td>

<td width="20%">' . Lang::trans('quotelinetotal') . '</td>

</tr>';

foreach ($invoiceitems as $item) {

if ($item['type'] == "Hosting") {

$typeoutput = Lang::trans('invoicessachost').'<br />';

}

elseif ($item['type'] == "DomainRegister") {

$typeoutput = Lang::trans('invoicessacdom').'<br />';

}

elseif ($item['type'] == "DomainTransfer") {

$typeoutput = Lang::trans('invoicessacdom').'<br />';

 

}

elseif ($item['type'] == "DomainRenew") {

$typeoutput = Lang::trans('invoicessacdom').'<br />';

}

 

elseif ($item['type'] == "DomainRenewal") {

$typeoutput = Lang::trans('invoicessacdom').'<br />';

 

}

 

else {

$typeoutput = "N/A";

}

 

$tblhtml .= '

<tr bgcolor="#fff">

<td align="left">' . nl2br($item['description']) . '<br />' . $typeoutput . '</td>

<td align="center">' . $item['amount'] . '</td>

</tr>';

 

 

 

 

Thanks & Kind Regards

Madan Malhotra

Edited by bagfuloz
Link to comment
Share on other sites

Now, Other logic came in the picture, That We got one more SAC code for SMS services and SMS services Sac code is diffrent than Domain and Hosting Code, As we all know SMS Services, it's come under Other Product and service type.

 

But in debug variable -

 

$invoiceitems

Origin: "Smarty object"

Value

Array (1)

0 => Array (7)

id => 92170

type => "Hosting"

relid => 8550

description => "Small"

rawamount => "27.94"

amount => "$27.94"

taxed => true

 

 

It's showing Type hosting. How to deal with this, How to define SMS service as other or any?

 

For your information -

 

Hosting, Emails, SSL, Spam Experts, Backup Services - SAC 998315 (Its done)

 

Domain -SAC 998319 (Its done)

 

SMS - SAC 440366 (Remaining)

Link to comment
Share on other sites

It's showing Type hosting. How to deal with this, How to define SMS service as other or any?

oh 'eck... this is going to get messy!

 

without resorting to hooks, I suspect you're going to have to filter on descriptions... SMS (and any hosting products that you don't want to be hosting) will need to be checked before hosting...

foreach ($invoiceitems as $item) {

   if ($item['description'] == "Small" {
       $typeoutput = Lang::trans('invoicessacsms').'<br />';
       }
   elseif ($item['type'] == "Hosting") {
       $typeoutput = Lang::trans('invoicessachost').'<br />';
   }
   elseif ($item['type'] == "DomainRegister" or $item['type'] == "DomainRegister" or $item['type'] == "DomainRegister" or $item['type'] == "DomainRenewal") {
       $typeoutput = Lang::trans('invoicessacdom').'<br />';
   }
   else {
       $typeoutput = "N/A";
   }

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

Link to comment
Share on other sites

As per requirement. Hope it will help others.

 

if (($item['description'] == 'S1') || ($item['description'] == 'M1') || ($item['description'] == 'L1') || ($item['description'] == 'EL1')) {

$typeoutput = Lang::trans('invoicessacsms').'<br />';

}

 

elseif ($item['type'] == "Hosting") {

$typeoutput = Lang::trans('invoicessachost').'<br />';

}

 

elseif ($item['type'] == "DomainRegister") {

$typeoutput = Lang::trans('invoicessacdom').'<br />';

}

elseif ($item['type'] == "DomainTransfer") {

$typeoutput = Lang::trans('invoicessacdom').'<br />';

 

}

elseif ($item['type'] == "DomainRenew") {

$typeoutput = Lang::trans('invoicessacdom').'<br />';

}

 

elseif ($item['type'] == "DomainRenewal") {

$typeoutput = Lang::trans('invoicessacdom').'<br />';

 

}

 

else {

$typeoutput = "N/A";

}

 

$tblhtml .= '

<tr bgcolor="#fff">

<td align="left">' . nl2br($item['description']) . '<br />' . $typeoutput . '</td>

<td align="center">' . $item['amount'] . '</td>

</tr>';

 

 

 

Thanks for kind knowledge and support Brian :)

Link to comment
Share on other sites

  • 2 weeks later...
oh 'eck... this is going to get messy!

 

without resorting to hooks, I suspect you're going to have to filter on descriptions... SMS (and any hosting products that you don't want to be hosting) will need to be checked before hosting...

foreach ($invoiceitems as $item) {

   if ($item['description'] == "Small" {
       $typeoutput = Lang::trans('invoicessacsms').'<br />';
       }
   elseif ($item['type'] == "Hosting") {
       $typeoutput = Lang::trans('invoicessachost').'<br />';
   }
   elseif ($item['type'] == "DomainRegister" or $item['type'] == "DomainRegister" or $item['type'] == "DomainRegister" or $item['type'] == "DomainRenewal") {
       $typeoutput = Lang::trans('invoicessacdom').'<br />';
   }
   else {
       $typeoutput = "N/A";
   }

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

 

Hello Brian, How this same should be done on viewinvoice.tpl file?

 

correct me if i am wrong -

 

{foreach from=$invoiceitems item=item}

<tr>

<td>{if $item.description eq 'S1'||'M1'||'L1'||'EL1'}{$LANG.invoicessacsms}{/if}

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