<!DOCTYPE html>
<html lang="{Localisation::getCurrentUiLanguage()}">

	<head>
		<meta content="text/html; charset={Localisation::getCurrentHtmlCharset()}" http-equiv="content-type">
		<style>

			body {
				font-family: Arial, Helvetica, Verdana;
				font-size: 8pt;
			}

			table {
				width: 100%;
				border-spacing: 0;
				margin-top: 0.5em;
				margin-bottom: 1em;
				break-inside: avoid;
			}

			table > caption {
				font-weight: bold;
				margin-bottom: 0.5em;
			}

			.caption {
				font-weight: bold;
				margin-bottom: 0.5em;
				text-align: center;
			}

			table > thead {
				font-weight: bold;
				background-color: lightgrey;
			}

			table > tbody {
			}

			table td {
				padding: 0.3em;
				border-left: 1px solid black;
				text-align: center;
			}

			table td:last-child {
				border-right: 1px solid black;
			}

			table thead td {
				border-top: 1px solid black;
				border-bottom: 1px solid black;
			}

			table tbody td {
				border-bottom: 1px solid black;
			}

			table tr.summary td {
				font-weight: bold;
			}

		</style>
	</head>

	{$show_netto_column = false}

	<body>
		{foreach $minibilling as $phone => $types}
			<p class="caption">
				{t a=$phone b=$datefrom c=$dateto}Minibilling for number $a (period{if $datefrom} from $b{/if}{if $dateto} to $c{/if}){/t}
			</p>
			{foreach $types as $type => $mb}
				<table>
					<thead>
						<tr>
							<td>
								{if $type == $smarty.const.BILLING_RECORD_TYPE_VOICE_CALL}
									{trans("<!minibilling>Call type")}
								{elseif $type == $smarty.const.BILLING_RECORD_TYPE_SMS}
									{trans("<!minibilling>SMS type")}
								{elseif $type == $smarty.const.BILLING_RECORD_TYPE_MMS}
									{trans("<!minibilling>MMS type")}
								{elseif $type == $smarty.const.BILLING_RECORD_TYPE_DATA_TRANSFER}
									{trans("<!minibilling>Data transfer type")}
								{elseif $type == $smarty.const.BILLING_RECORD_TYPE_VIDEO_CALL}
									{trans("<!minibilling>Video call type")}
								{/if}
							</td>
							{if $type != $smarty.const.BILLING_RECORD_TYPE_SMS
								&& $type != $smarty.const.BILLING_RECORD_TYPE_MMS}
								<td>
									{if $type == $smarty.const.BILLING_RECORD_TYPE_VOICE_CALL}
										{trans("<!minibilling>Call time")}
									{elseif $type == $smarty.const.BILLING_RECORD_TYPE_SMS}
										{trans("<!minibilling>Count")}
									{elseif $type == $smarty.const.BILLING_RECORD_TYPE_MMS}
										{trans("<!minibilling>Count")}
									{elseif $type == $smarty.const.BILLING_RECORD_TYPE_DATA_TRANSFER}
										{trans("<!minibilling>Volume")}
									{elseif $type == $smarty.const.BILLING_RECORD_TYPE_VIDEO_CALL}
										{trans("<!minibilling>Video call time")}
									{/if}
								</td>
							{/if}
							<td>
								{trans("<!minibilling>Count")}
							</td>
							{if $show_netto_column}
								<td>
									{trans("<!minibilling>Net value")}
								</td>
							{/if}
							<td>
								{trans("<!minibilling>Gross value")}
							</td>
						</tr>
					</thead>
					<tbody>
						{$summary.total = 0}
						{$summary.billed = 0}
						{$summary.count = 0}
						{$summary.brutto = 0}
						{foreach $mb as $group => $row}
							<tr>
								<td>
									{$group}
								</td>
								{if $type != $smarty.const.BILLING_RECORD_TYPE_SMS
									&& $type != $smarty.const.BILLING_RECORD_TYPE_MMS}
									<td>
										{if $type == $smarty.const.BILLING_RECORD_TYPE_VOICE_CALL}
											{$row.billed|duration_format}
										{elseif $type == $smarty.const.BILLING_RECORD_TYPE_SMS}
											{$row.billed}
										{elseif $type == $smarty.const.BILLING_RECORD_TYPE_MMS}
											{$row.billed}
										{elseif $type == $smarty.const.BILLING_RECORD_TYPE_DATA_TRANSFER}
											{$row.billed|size_format}
										{elseif $type == $smarty.const.BILLING_RECORD_TYPE_VIDEO_CALL}
											{$row.billed|duration_format}
										{/if}
									</td>
								{/if}
								<td>
									{t a=$row.count}<!minibilling>$a pcs.{/t}
								</td>
								{if $show_netto_column}
									<td>
										{moneyf($row.brutto / 1.23)}
									</td>
								{/if}
								<td>
									{moneyf($row.brutto)}
								</td>
							</tr>
							{$summary.billed = $summary.billed + $row.billed}
							{$summary.total = $summary.total + $row.time}
							{$summary.count = $summary.count + $row.count}
							{$summary.brutto = $summary.brutto + $row.brutto}
							{if !isset($summaries[$type][$group])}
								{$summaries[$type][$group].billed = 0}
								{$summaries[$type][$group].total = 0}
								{$summaries[$type][$group].count = 0}
								{$summaries[$type][$group].brutto = 0}
							{/if}
							{$summaries[$type][$group].billed = $summaries[$type][$group].billed + $row.billed}
							{$summaries[$type][$group].total = $summaries[$type][$group].total + $row.time}
							{$summaries[$type][$group].count = $summaries[$type][$group].count + $row.count}
							{$summaries[$type][$group].brutto = $summaries[$type][$group].brutto + $row.brutto}
						{/foreach}
						<tr class="summary">
							<td>
								{trans("<!minibilling>Total")}
							</td>
							{if $type != $smarty.const.BILLING_RECORD_TYPE_SMS
								&& $type != $smarty.const.BILLING_RECORD_TYPE_MMS}
								<td>
									{if $type == $smarty.const.BILLING_RECORD_TYPE_VOICE_CALL}
										{$summary.billed|duration_format}
									{elseif $type == $smarty.const.BILLING_RECORD_TYPE_SMS}
										{$summary.billed}
									{elseif $type == $smarty.const.BILLING_RECORD_TYPE_MMS}
										{$summary.billed}
									{elseif $type == $smarty.const.BILLING_RECORD_TYPE_DATA_TRANSFER}
										{$summary.billed|size_format}
									{elseif $type == $smarty.const.BILLING_RECORD_TYPE_VIDEO_CALL}
										{$summary.billed|duration_format}
									{/if}
								</td>
							{/if}
							<td>
								{t a=$summary.count}<!minibilling>$a pcs.{/t}
							</td>
							{if $show_netto_column}
								<td>
									{moneyf($summary.brutto / 1.23)}
								</td>
							{/if}
							<td>
								{moneyf($summary.brutto)}
							</td>
						</tr>
					</tbody>
				</table>
			{/foreach}
		{/foreach}

		{if isset($summaries) && count($minibilling) > 1}
			<p class="caption">
				{t a=$datefrom b=$dateto}Minibilling summary (period{if $datefrom} from $a{/if}{if $dateto} to $b{/if}){/t}
			</p>
			{foreach $summaries as $type => $summarygroups}
				<table>
					<thead>
						<tr>
							<td>
								{if $type == $smarty.const.BILLING_RECORD_TYPE_VOICE_CALL}
									{trans("<!minibilling>Call type")}
								{elseif $type == $smarty.const.BILLING_RECORD_TYPE_SMS}
									{trans("<!minibilling>SMS type")}
								{elseif $type == $smarty.const.BILLING_RECORD_TYPE_MMS}
									{trans("<!minibilling>MMS type")}
								{elseif $type == $smarty.const.BILLING_RECORD_TYPE_DATA_TRANSFER}
									{trans("<!minibilling>Data transfer type")}
								{elseif $type == $smarty.const.BILLING_RECORD_TYPE_VIDEO_CALL}
									{trans("<!minibilling>Video call type")}
								{/if}
							</td>
							{if $type != $smarty.const.BILLING_RECORD_TYPE_SMS
								&& $type != $smarty.const.BILLING_RECORD_TYPE_MMS}
								<td>
									{if $type == $smarty.const.BILLING_RECORD_TYPE_VOICE_CALL}
										{trans("<!minibilling>Call time")}
									{elseif $type == $smarty.const.BILLING_RECORD_TYPE_SMS}
										{trans("<!minibilling>Count")}
									{elseif $type == $smarty.const.BILLING_RECORD_TYPE_MMS}
										{trans("<!minibilling>Count")}
									{elseif $type == $smarty.const.BILLING_RECORD_TYPE_DATA_TRANSFER}
										{trans("<!minibilling>Volume")}
									{elseif $type == $smarty.const.BILLING_RECORD_TYPE_VIDEO_CALL}
										{trans("<!minibilling>Video call time")}
									{/if}
								</td>
							{/if}
							<td>
								{trans("<!minibilling>Count")}
							</td>
							{if $show_netto_column}
								<td>
									{trans("<!minibilling>Net value")}
								</td>
							{/if}
							<td>
								{trans("<!minibilling>Gross value")}
							</td>
						</tr>
					</thead>
					<tbody>
						{$summary.billed = 0}
						{$summary.total = 0}
						{$summary.count = 0}
						{$summary.brutto = 0}
						{foreach $summarygroups as $group => $row}
							<tr>
								<td>
									{$group}
								</td>
								{if $type != $smarty.const.BILLING_RECORD_TYPE_SMS
									&& $type != $smarty.const.BILLING_RECORD_TYPE_MMS}
									<td>
										{if $type == $smarty.const.BILLING_RECORD_TYPE_VOICE_CALL}
											{$row.billed|duration_format}
										{elseif $type == $smarty.const.BILLING_RECORD_TYPE_SMS}
											{$row.billed}
										{elseif $type == $smarty.const.BILLING_RECORD_TYPE_MMS}
											{$row.billed}
										{elseif $type == $smarty.const.BILLING_RECORD_TYPE_DATA_TRANSFER}
											{$row.billed|size_format}
										{elseif $type == $smarty.const.BILLING_RECORD_TYPE_VIDEO_CALL}
											{$row.billed|duration_format}
										{/if}
									</td>
								{/if}
								<td>
									{t a=$row.count}<!minibilling>$a pcs.{/t}
								</td>
								{if $show_netto_column}
									<td>
										{moneyf($row.brutto / 1.23)}
									</td>
								{/if}
								<td>
									{moneyf($row.brutto)}
								</td>
							</tr>
							{$summary.billed = $summary.billed + $row.billed}
							{$summary.total = $summary.total + $row.total}
							{$summary.count = $summary.count + $row.count}
							{$summary.brutto = $summary.brutto + $row.brutto}
						{/foreach}
						<tr class="summary">
							<td>
								{trans("<!minibilling>Total")}
							</td>
							{if $type != $smarty.const.BILLING_RECORD_TYPE_SMS
								&& $type != $smarty.const.BILLING_RECORD_TYPE_MMS}
								<td>
									{if $type == $smarty.const.BILLING_RECORD_TYPE_VOICE_CALL}
										{$summary.billed|duration_format}
									{elseif $type == $smarty.const.BILLING_RECORD_TYPE_SMS}
										{$summary.billed}
									{elseif $type == $smarty.const.BILLING_RECORD_TYPE_MMS}
										{$summary.billed}
									{elseif $type == $smarty.const.BILLING_RECORD_TYPE_DATA_TRANSFER}
										{$summary.billed|size_format}
									{elseif $type == $smarty.const.BILLING_RECORD_TYPE_VIDEO_CALL}
										{$summary.billed|duration_format}
									{/if}
								</td>
							{/if}
							<td>
								{t a=$summary.count}<!minibilling>$a pcs.{/t}
							</td>
							{if $show_netto_column}
								<td>
									{moneyf($summary.brutto / 1.23)}
								</td>
							{/if}
							<td>
								{moneyf($summary.brutto)}
							</td>
						</tr>
					</tbody>
				</table>
			{/foreach}
		{/if}
	</body>

</html>
