<?php 
$months = __('months', true);
ksort($months);
$short_days = __('short_days', true);
$booking_statuses = __('booking_statuses', true);
$get = $controller->_get->raw();
?>
<div id="datePickerOptions" style="display:none;" data-wstart="<?php echo (int) $tpl['option_arr']['o_week_start']; ?>" data-format="<?php echo $tpl['date_format']; ?>" data-months="<?php echo implode("_", $months);?>" data-days="<?php echo implode("_", $short_days);?>"></div>
<div class="row wrapper border-bottom white-bg page-heading">
	<div class="col-sm-12">
		<div class="row">
			<div class="col-sm-10">
				<h2><?php __('infoReportsTitle');?></h2>
			</div>
		</div><!-- /.row -->

		<p class="m-b-none"><i class="fa fa-info-circle"></i><?php __('infoReportsDesc');?></p>
	</div><!-- /.col-md-12 -->
</div>

<div class="wrapper wrapper-content animated fadeInRight">
	<div class="row">
		<div class="col-lg-12">
			<div class="ibox float-e-margins">
				<div class="ibox-content">
					<form id="frmReport" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="get">
						<input type="hidden" name="controller" value="pjAdminReports" />
						<input type="hidden" name="action" value="pjActionIndex" />
						<label><?php __('lblSpaces');?></label>
						<div class="row m-b-md">
							<div class="col-md-3">
								<select name="space_id" class="form-control">
									<option value="">-- <?php __('lblAll')?> --</option>
									<?php foreach ($tpl['all_space_arr'] as $v) { ?>
										<option value="<?php echo $v['id'];?>" <?php echo isset($get['space_id']) && $get['space_id'] == $v['id'] ? 'selected="selected"' : null;?>><?php echo pjSanitize::html($v['name']);?></option>
									<?php } ?>
								</select>
							</div><!-- /.col-sm-3 -->
	
							<div class="col-md-6">
								<div class="form-group">
									<div class="row">
										<div class="col-sm-5">
											<div class="input-group">
												<input type="text" name="date_from" value="<?php echo isset($get['date_from']) ? $get['date_from'] : date($tpl['option_arr']['o_date_format'], time());?>" class="form-control datepick" readonly="readonly">
	
												<span class="input-group-addon"><i class="fa fa-calendar"></i></span> 
											</div>
										</div><!-- /.col-md-5 -->
	
										<div class="col-sm-2 text-center">
											<label class="control-label m-t-xs"><?php __('lblTo'); ?></label>
										</div><!-- /.col-md-2 -->
	
										<div class="col-sm-5">
											<div class="input-group">
												<input type="text" name="date_to" value="<?php echo isset($get['date_to']) ? $get['date_to'] : date($tpl['option_arr']['o_date_format'], time());?>" class="form-control datepick" readonly="readonly">
	
												<span class="input-group-addon"><i class="fa fa-calendar"></i></span> 
											</div>
										</div><!-- /.col-md-5 -->
									</div><!-- /.row -->
								</div><!-- /.form-group -->
							</div>
	
							<div class="col-md-3">
								<button type="submit" class="ladda-button btn btn-primary btn-phpjabbers-loader" data-style="zoom-in">
        							<span class="ladda-label"><?php __('btnReport', false, true); ?></span>
        							<?php include $controller->getConstant('pjBase', 'PLUGIN_VIEWS_PATH') . 'pjLayouts/elements/button-animation.php'; ?>
        						</button>
							</div><!-- /.col-md-6 -->
						</div><!-- /.row -->
					</form>

					<div class="hr-line-dashed"></div>

					<div class="table-responsive table-responsive-secondary">
						<table class="table table-striped table-hover">
							<thead>
								<tr>
									<th></th>
									<th><?php echo $booking_statuses['confirmed'];?></th>
									<th><?php echo $booking_statuses['pending'];?></th>
									<th><?php echo $booking_statuses['cancelled'];?></th>
								</tr>
							</thead>

							<tbody>
								<tr>
									<td><strong><?php __('lblTotalBookings');?></strong></td>
									<td><?php echo $tpl['cnt_confirmed'];?> / <?php echo pjCurrency::formatPrice($tpl['total_confirmed']);?></td>
									<td><?php echo $tpl['cnt_pending'];?> / <?php echo pjCurrency::formatPrice($tpl['total_pending']);?></td>
									<td><?php echo $tpl['cnt_cancelled'];?> / <?php echo pjCurrency::formatPrice($tpl['total_cancelled']);?></td>
								</tr>
								<?php foreach($tpl['space_arr'] as $k => $v) { ?>
								<tr>
									<td><?php echo pjSanitize::html($v['name']);?></td>
									<td><?php echo $v['cnt_confirmed'];?> / <?php echo pjCurrency::formatPrice($v['total_confirmed']);?></td>
									<td><?php echo $v['cnt_pending'];?> / <?php echo pjCurrency::formatPrice($v['total_pending']);?></td>
									<td><?php echo $v['cnt_cancelled'];?> / <?php echo pjCurrency::formatPrice($v['total_cancelled']);?></td>
								</tr>
								<?php } ?>
								<?php if(!empty($tpl['extra_arr'])) { 
									$cnt_confirmed = 0;
									$cnt_pending = 0;
									$cnt_cancelled = 0;
									$total_confirmed = 0;
									$total_pending = 0;
									$total_cancelled = 0;
									foreach($tpl['extra_arr'] as $k => $v)
									{
										$cnt_confirmed += intval($v['cnt_confirmed']);
										$cnt_pending += intval($v['cnt_pending']);
										$cnt_cancelled += intval($v['cnt_cancelled']);
										
										$total_confirmed += $v['total_confirmed'];
										$total_pending += $v['total_pending'];
										$total_cancelled += $v['total_cancelled'];
									}
									?>
									<tr>
										<td colspan="4">&nbsp;</td>
									</tr>
	
									 <tr>
										<td><strong><?php __('lblTotalExtras');?></strong></td>
										<td><?php echo $cnt_confirmed; ?> / <?php echo pjCurrency::formatPrice($total_confirmed);?></td>
										<td><?php echo $cnt_pending; ?> / <?php echo pjCurrency::formatPrice($total_pending);?></td>
										<td><?php echo $cnt_cancelled; ?> / <?php echo pjCurrency::formatPrice($total_cancelled);?></td>
									</tr>
									<?php foreach($tpl['extra_arr'] as $k => $v) { ?>
										<tr>
											<td><?php echo pjSanitize::html($v['name']);?></td>
											<td><?php echo intval($v['cnt_confirmed']);?> / <?php echo pjCurrency::formatPrice($v['total_confirmed']);?></td>
											<td><?php echo intval($v['cnt_pending']);?> / <?php echo pjCurrency::formatPrice($v['total_pending']);?></td>
											<td><?php echo intval($v['cnt_cancelled']);?> / <?php echo pjCurrency::formatPrice($v['total_cancelled']);?></td>
										</tr>
									<?php } ?>
								<?php } ?>
							</tbody>
						</table>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>