<section class="container">
	<?php if (isset($filter)) { ?>
	<div class="row">
		<div class="col-xs-12">
			<?php
			foreach ($filter as $key => $value) {
				$length = strlen(ltrim(rtrim($key)));
				$tab = "\t\t\t";
				if ($length <= 3) {
					$tab = "\t\t";
				}  else if ($length <5) {
					$tab = "\t\t\t";
				}else if ($length <=8) {
					$tab = "\t\t";
				} else {
					$tab = "\t";
				}
			?>
			<div class="row">
				<pre class="col"><?php echo ltrim(rtrim($key)).$tab; ?>: <?php echo $value; ?></pre>
			</div>
			<?php
			}
			?>
		</div>
	</div>
	<?php } ?>
	<?php if (isset($table)) { ?>
	<div class="row">
		<div class="col-xs-12 table-responsive">
			<table width="100%">
				<?php if (isset($table['header'])) { ?>
				<thead>
					<tr>
						<th class="tac">#</th>
						<?php
						$index = 0;
						foreach ($table['header'] as $header) {
						?>
						<th class="<?php echo (isset($table['right-column']) && in_array(++$index, $table['right-column'])) ? 'tar' : ''; ?>"><?php echo $header; ?></th>
						<?php
						}
						?>
					</tr>
				</thead>
				<?php } ?>
				<?php if (isset($table['body'])) { ?>
				<tbody>
					<?php
					$row = 0;
					$sum = array();
					$grandTotal = array();
					if (isset($table['total-column'])) {
						foreach ($table['total-column'] as $total) {
							$sum[$total] = 0;
						}
					}
					if (isset($table['footer']['total-column'])) {
						foreach ($table['footer']['total-column'] as $total) {
							$grandTotal[$total] = 0;
						}
					}
					foreach ($table['body'] as $data) {
						if (is_object($data)) {
							$data = get_object_vars($data);
						}
					?>
					<tr>
						<td class="tac"><?php echo ++$row; ?></td>
						<?php
						$index = 0;
						foreach ($data as $key => $value) {
						?>
						<td class="<?php echo (isset($table['right-column']) && in_array(++$index, $table['right-column'])) ? 'tar' : ''; ?>">
							<?php
							if (isset($table['right-column']) && in_array($index, $table['right-column'])) {
								echo number_format(floatval($value), 2);
							} else {
								echo nl2br($value);
							}
							?>
						</td>
						<?php
							if (count($sum) > 0 && array_key_exists($index, $sum)) {
								$sum[$index] += floatval($value);
							}
							if (count($grandTotal) > 0 && array_key_exists($index, $grandTotal)) {
								$grandTotal[$index] += floatval($value);
							}
						}
						?>
					</tr>
					<?php
					}
					?>
				</tbody>
				<?php } ?>
				<?php
				if (isset($table['footer']['total-column'])) {
					$footer = sizeof($table['footer']['total-column']);
				?>
				<tfoot>
					<tr>
						<td>&nbsp;</td>
						<td colspan="<?php echo sizeof($table['header']) - sizeof($grandTotal); ?>" class="tar"><?php echo $table['footer']['title']; ?></td>
						<?php foreach ($grandTotal as $total) { ?>
						<td class="tar"><?php echo number_format($total, 2); ?></td>
						<?php } ?>
					</tr>
				</tfoot>
				<?php } ?>
			</table>
		</div>
	</div><br>
	<?php } ?>
	<?php if (isset($table['total-title'])) { ?>
	<div class="row">
		<div class="col-xs-12">
			<div class="col-xs-6 col-sm-5 col-md-4 pull-right grand-total form-horizontal">
				<?php
				if (isset($table['total-title']) && count($table['total-title'] == count($sum))) {
					foreach ($table['total-title'] as $title) {
				?>
				<div class="form-group">
					<label class="col-xs-7 total-title"><?php echo $title; ?>:</label>
					<div class="col-xs-5">
						<span class="total-value"><?php echo number_format(array_shift($sum), 2); ?></span>
					</div>
				</div>
				<?php
					}
				}
				?>
			</div>
		</div>
	</div>
	<?php } ?>
</section>
