<!--// $Id$ //-->
{box title="Your subscriptions"}
{$show_speeds = ConfigHelper::checkConfig('userpanel.show_speeds')}
{$show_period = ConfigHelper::checkConfig('userpanel.show_period')}
{$show_discount = ConfigHelper::checkConfig('userpanel.show_discount')}
{$show_discounted_value = ConfigHelper::checkConfig('userpanel.show_discounted_value')}
{$show_invoice_flag = ConfigHelper::checkConfig('userpanel.show_invoice_flag')}
{$show_all_assignments = ConfigHelper::checkConfig('userpanel.show_all_assignments')}
{$speed_unit_type = ConfigHelper::getConfig('userpanel.speed_unit_type')}
{$speed_unit_aggregation_threshold = ConfigHelper::getConfig('userpanel.speed_unit_aggregation_threshold')}
<table style="width: 100%;" cellpadding="3">
	<tr class="darkest">
		<td width="93%" class="nobr"><strong>{trans("Subscription:")}</strong></td>
		<td width="1%" class="nobr" align="right">{trans("Value:")}</td>
		{if $show_discount}
			<td width="1%" class="nobr" align="right">{trans("Discount:")}</td>
		{/if}
		<td width="1%" class="nobr">{trans("Accounting day:")}</td>
		{if $show_speeds}
			<td width="1%" class="nobr" align="right">{trans("Downrate (ceil):")}</td>
			<td width="1%" class="nobr" align="right">{trans("Uprate (ceil):")}</td>
		{/if}
		{if $show_invoice_flag}
			<td width="1%" class="nobr">{trans("Invoice:")}</td>
		{/if}
		{if $show_period}
			<td width="1%" class="nobr">{trans("Period:")}</td>
		{/if}
	</tr>
	{$total_real_value = array()}
	{$total_real_disc_value = array()}
	{$total_real_downrate = 0}
	{$total_real_uprate = 0}
	{$total_real_downceil = 0}
	{$total_real_upceil = 0}
	{foreach $assignments as $assignment}
	{if ($assignment.tariffid || $assignment.liabilityid) && !$assignment.suspended
		&& ($show_all_assignments || ($assignment.datefrom <= $smarty.now && (empty($assignment.dateto) || $assignment.dateto >= $smarty.now)))}
	<tr class="dark">
		<td><strong>{if ConfigHelper::checkConfig('userpanel.show_tariffname')}{$assignment.name}{/if}</strong></td>
		{if $show_discounted_value}
			<td class="nobr" align="right">
				{moneyf($assignment.discounted_value, $assignment.currency)}
				{if !isset($total_real_value[$assignment.currency])}
					{$total_real_value[$assignment.currency] = 0}
				{/if}
				{if $assignment.datefrom <= $smarty.now && (empty($assignment.dateto) || $assignment.dateto >= $smarty.now)}
					{$total_real_value[$assignment.currency] = $total_real_value[$assignment.currency] + $assignment.discounted_value}
				{/if}
			</td>
		{else}
			<td class="nobr" align="right">
				{moneyf($assignment.real_value, $assignment.currency)}
				{if !isset($total_real_value[$assignment.currency])}
					{$total_real_value[$assignment.currency] = 0}
				{/if}
				{if $assignment.datefrom <= $smarty.now && (empty($assignment.dateto) || $assignment.dateto >= $smarty.now)}
					{$total_real_value[$assignment.currency] = $total_real_value[$assignment.currency] + $assignment.real_value}
				{/if}
			</td>
		{/if}
		{if $show_discount}
			<td class="nobr" align="right">
				{if $assignment.pdiscount > 0}
					{$assignment.pdiscount}%
				{else}
					{if $assignment.vdiscount > 0}
						{moneyf($assignment.vdiscount, $assignment.currency)}
					{else}
						-
					{/if}
				{/if}
				{if !isset($total_real_disc_value[$assignment.currency])}
					{$total_real_disc_value[$assignment.currency] = 0}
				{/if}
				{if $assignment.datefrom <= $smarty.now && (empty($assignment.dateto) || $assignment.dateto >= $smarty.now)}
					{$total_real_disc_value[$assignment.currency] = $total_real_disc_value[$assignment.currency] + $assignment.real_disc_value}
				{/if}
			</td>
		{/if}
		<td class="nobr">{$assignment.payday}</td>
		{if $show_speeds}
			<td class="nobr" align="right">
				{if empty($assignment.downrate)}
					-
				{else}
					{convert_to_units($assignment.downrate * $speed_unit_type, $speed_unit_aggregation_threshold, $speed_unit_type)}/s
					{if $assignment.datefrom <= $smarty.now && (empty($assignment.dateto) || $assignment.dateto >= $smarty.now)}
						{$total_real_downrate = $total_real_downrate + $assignment.downrate}
					{/if}
				{/if}
				({if empty($assignment.downceil)}
					-
				{else}
					{convert_to_units($assignment.downceil * $speed_unit_type, $speed_unit_aggregation_threshold, $speed_unit_type)}/s
					{if $assignment.datefrom <= $smarty.now && (empty($assignment.dateto) || $assignment.dateto >= $smarty.now)}
						{$total_real_downceil = $total_real_downceil + $assignment.downceil}
					{/if}
				{/if})
			</td>
			<td class="nobr" align="right">
				{if empty($assignment.uprate)}
					-
				{else}
					{convert_to_units($assignment.uprate * $speed_unit_type, $speed_unit_aggregation_threshold, $speed_unit_type)}/s
					{if $assignment.datefrom <= $smarty.now && (empty($assignment.dateto) || $assignment.dateto >= $smarty.now)}
						{$total_real_uprate = $total_real_uprate + $assignment.uprate}
					{/if}
				{/if}
				({if empty($assignment.upceil)}
					-
				{else}
					{convert_to_units($assignment.upceil * $speed_unit_type, $speed_unit_aggregation_threshold, $speed_unit_type)}/s
					{if $assignment.datefrom <= $smarty.now && (empty($assignment.dateto) || $assignment.dateto >= $smarty.now)}
						{$total_real_upceil = $total_real_upceil + $assignment.upceil}
					{/if}
				{/if})
			</td>
		{/if}
		{if $show_invoice_flag}
			<td>{if $assignment.invoice}{trans("yes")}{else}&nbsp;{/if}</td>
		{/if}
		{if $show_period}
			<td>
				{if $assignment.datefrom}<span class="nobr">{trans("from")} {$assignment.datefrom|date_format:"Y-m-d"}</span>{/if}
				{if $assignment.dateto}<span class="nobr">{trans("to")} {$assignment.dateto|date_format:"Y-m-d"}</span>{/if}
			</td>
		{/if}
	</tr>
	{/if}
	{foreachelse}
	<tr>
		<td class="text-wrap" width="100%" colspan="{if $show_speeds}{if $show_period}8{else}7{/if}{else}{if $show_period}6{else}5{/if}{/if}">
			<p>&nbsp;</p>
			<p><strong>{trans("You haven't got any assigned subscriptions.")}</strong></p>
			<p>&nbsp;</p>
		</td>
	</tr>
	{/foreach}
	<tr class="darkest">
		<td align="right"><strong>{trans("Total:")}</strong></td>
		<td class="nobr" align="right">
			{foreach $total_real_value as $currency => $total_value}
				{if !$total_value@first}<br>{/if}
				{moneyf($total_value, $currency)}
			{/foreach}
		</td>
		{if $show_discount}
			<td class="nobr" align="right">
				({foreach $total_real_disc_value as $currency => $total_disc_value}{if !$total_disc_value@first}<br>{/if}{moneyf($total_disc_value, $currency)}{foreachelse}-{/foreach})
			</td>
		{/if}
		<td>&nbsp;</td>
		{if $show_speeds}
			<td class="nobr" align="right">
				{if $total_real_downrate}
					{convert_to_units($total_real_downrate * $speed_unit_type, $speed_unit_aggregation_threshold, $speed_unit_type)}/s
				{else}
					-
				{/if}
				({if $total_real_downceil}
					{convert_to_units($total_real_downceil * $speed_unit_type, $speed_unit_aggregation_threshold, $speed_unit_type)}/s
				{else}
					-
				{/if})
			</td>
			<td class="nobr" align="right">
				{if $total_real_uprate}
					{convert_to_units($total_real_uprate * $speed_unit_type, $speed_unit_aggregation_threshold, $speed_unit_type)}/s
				{else}
					-
				{/if}
				({if $total_real_upceil}
					{convert_to_units($total_real_upceil * $speed_unit_type, $speed_unit_aggregation_threshold, $speed_unit_type)}/s
				{else}
					-
				{/if})
			</td>
		{/if}
		{if $show_invoice_flag}
			<td>&nbsp;</td>
		{/if}
		{if $show_period}
			<td class="nobr" align="right">&nbsp;</td>
		{/if}
	</tr>
</table>
{/box}
