<?php $this->load->view('checkout/style'); ?>

<div class="content-wrapper">
	<div class="content">
		<div class="row section-title text-center">
			<div class="col">
				<h1><?php echo $this->lang->line('title'); ?></h1>
				<p><?php echo $this->lang->line('desc'); ?></p>
			</div>
		</div>
		<div class="row">
			<?php if($current){ ?>
				<div class="col-sm-12">
					<div class="panel panel-default">
						<div class="panel-body">
							<div class="col-sm-8 col-sm-offset-2">
								<div class="item-name p-1-b">
									<h2><?php echo $this->lang->line('overview'); ?></h2>
								</div>
								<div class="item-overview table-responsive">
									<table class="table table-striped table-bordered table-hover">
										<tr>
											<th><?php echo $this->lang->line('name'); ?></th>
											<td><?php echo $current['title']; ?></td>
										</tr>
										<tr>
											<th><?php echo $this->lang->line('date'); ?></th>
											<td><?php echo $current['startTime'].' - '.$current['endTime']; ?></td>
										</tr>
										<tr>
											<th><?php echo $this->lang->line('venue'); ?></th>
											<td><?php echo $current['venue']; ?></td>
										</tr>
										<tr>
											<th><?php echo $this->lang->line('status'); ?></th>
											<td><?php echo $current['detail']['status']; ?></td>
										</tr>
										<tr>
											<th><?php echo $this->lang->line('totalVoters'); ?></th>
											<td><?php echo count($current['detail']['voters']); ?></td>
										</tr>



										<tr class="total bg-blue" id="totalCost">
											<th><?php echo $this->lang->line('totalCost'); ?></th>
											<td data-toggle="tooltip" data-container="body" title="Click to show details" class="text-right"><?php echo number_format($current['detail']['totalCost'], 2); ?></td>
										</tr>
										<tr id="hdnTotalCost" hidden>
											<th><?php echo $this->lang->line('cost'); ?></th>
											<td>
												<table class="table table-striped table-bordered table-hover calc">
													<tr <?php if($current['detail']['status'] == 'Free Trial') echo 'hidden'; ?> >
														<th></th>
														<td class="text-right"><?php echo number_format($current['detail']['basePrice'], 2) ?></td>
													</tr>
													 <?php if($current['detail']['status'] == 'Free Trial'){ ?>
														<tr>
															<th><?php echo $this->lang->line('basePrice'); ?></th>
															<td class="text-right"><b><?php echo $this->lang->line('free'); ?></b></td>
														</tr>
													<?php } ?>
													<?php if(isset($current['detail']['tier1'])){ ?>
														<tr class="">
															<th><?php echo $this->lang->line('lowTier'); ?> (<?php echo $current['detail']['tier1']['voters'].' voters x RM'.number_format($current['detail']['tier1']['rate'], 2); ?>)</th>
															<td class="text-right"><?php echo number_format($current['detail']['tier1']['cost'], 2); ?></td>
														</tr>
													<?php } ?>
													<?php if(isset($current['detail']['tier2'])){ ?>
														<tr>
															<th><?php echo $this->lang->line('midTier'); ?> (<?php echo $current['detail']['tier2']['voters'].' voters x RM'.number_format($current['detail']['tier2']['rate'], 2); ?>)</th>
															<td class="text-right"><?php echo number_format($current['detail']['tier2']['cost'], 2); ?></td>
														</tr>
													<?php } ?>
													<?php if(isset($current['detail']['tier3'])){ ?>
														<tr>
															<th><?php echo $this->lang->line('topTier'); ?> (<?php echo $current['detail']['tier3']['voters'].' voters x RM'.number_format($current['detail']['tier3']['rate'], 2); ?>)</th>
															<td class="text-right"><?php echo number_format($current['detail']['tier3']['cost'], 2); ?></td>
														</tr>
													<?php } ?>
													<!--<?php if(isset($current['detail']['totalCharges'])){ ?>
														<tr>
															<th>Total Transaction Charges</th>
															<td class="text-right"><?php echo number_format($current['detail']['totalCharges'], 2); ?></td>
														</tr>
													<?php } ?>-->
												</table>
											</td>
										</tr>



										<?php if($current['detail']['status'] == 'Paid'){ ?>
											<tr class="total bg-green" id="paidCost">
												<th><?php echo $this->lang->line('totalPaid'); ?></th>
												<td data-toggle="tooltip" data-container="body" title="Click to show details" id="" class="text-right"><?php echo number_format($current['detail']['totalPaidCost'], 2); ?></td>
											</tr>
											<tr id="hdnPaidCost" hidden>
												<th></th>
												<td>
													<?php if($current['detail']['bills']){ 
														foreach($current['detail']['bills'] as $bill){ ?>
															<!--<button type="button" onclick="showBill('<?php echo $bill['billID']; ?>')" class="btn btn-primary col-sm-3">Bill</button>-->
															<a href="<?php echo base_url(); ?>checkout/mybill/<?php echo $bill['billID']; ?>" target="_blank" class="btn btn-primary col-sm-3">Bill</a>
													<?php } } ?>
												</td>
											</tr>
										<?php } ?>



										<?php if($current['detail']['status'] == 'Not Paid'){ ?>
											<tr class="total bg-red" id="unpaidCost">
												<th><?php echo $this->lang->line('totalUnpaid'); ?></th>
												<td id="" data-toggle="tooltip" data-container="body" title="Click to show details" id="" class="text-right"><?php echo number_format($current['detail']['totalUnpaidCost'], 2); ?></td>
											</tr>
											<tr id="hdnUnpaidCost" hidden>
												<th><?php echo $this->lang->line('cost'); ?></th>
												<td>
													<table class="table table-striped table-bordered table-hover calc">
														<tr>
															<th><?php echo $this->lang->line('basePrice'); ?></th>
															<td class="text-right"><?php echo number_format($current['detail']['basePrice'], 2) ?></td>
														</tr>
														<?php if(isset($current['detail']['tier1'])){ ?>
															<tr class="">
																<th>Low Tier (<?php echo $current['detail']['tier1']['voters'].' voters x RM'.number_format($current['detail']['tier1']['rate'], 2); ?>)</th>
																<td class="text-right"><?php echo number_format($current['detail']['tier1']['cost'], 2); ?></td>
															</tr>
														<?php } ?>
														<?php if(isset($current['detail']['tier2'])){ ?>
															<tr>
																<th>Mid Tier (<?php echo $current['detail']['tier2']['voters'].' voters x RM'.number_format($current['detail']['tier2']['rate'], 2); ?>)</th>
																<td class="text-right"><?php echo number_format($current['detail']['tier2']['cost'], 2); ?></td>
															</tr>
														<?php } ?>
														<?php if(isset($current['detail']['tier3'])){ ?>
															<tr>
																<th>Top Tier (<?php echo $current['detail']['tier3']['voters'].' voters x RM'.number_format($current['detail']['tier3']['rate'], 2); ?>)</th>
																<td class="text-right"><?php echo number_format($current['detail']['tier3']['cost'], 2); ?></td>
															</tr>
														<?php } ?>
													</table>
												</td>
											</tr>
										<?php } ?>



									</table>
								</div>
							</div>
							<div class="col-sm-8 col-sm-offset-2">
								<div class="item-name p-1-b">
									<h3><?php echo $this->lang->line('checkInfo'); ?></h3>
								</div>
								<div class="item-overview table-responsive">
									<table class="table table-striped table-bordered table-hover">
										<tr>
											<th><?php echo $this->lang->line('name'); ?></th>
											<td>
												<input type="text" class="form-control" id="userName" placeholder="Name" value="<?php echo $user['username']; ?>" disabled />
											</td>
										</tr>
										<tr>
											<th><?php echo $this->lang->line('email'); ?></th>
											<td>
												<input type="email" class="form-control" id="userEmail" placeholder="E-Mail" value="<?php echo $userBilling['email']; ?>" disabled />
											</td>
										</tr>
										<tr>
											<th><?php echo $this->lang->line('phoneNo'); ?></th>
											<td>
												<input type="text" class="form-control" id="userNum" placeholder="Phone Number" value="<?php echo $userBilling['phoneNo']; ?>" disabled />
											</td>
										</tr>
									</table>
								</div>
								<div class="item-checkout">
									<!--<div class="checkbox pull-left">
										<label><input id="userVerification" type="checkbox">I hereby confirm the provided information are true unless stated otherwise.</label>
									</div>-->
									<div class="pull-right">
										<button id="checkoutBtn" class="btn btn-primary" onclick="return checkout()" <?php if($current['detail']['status'] === 'Free Trial' || $current['detail']['status'] === 'Paid' || $current['detail']['status'] === 'No Voters') echo "disabled"; ?>>Checkout</button>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
			<?php } ?>
		</div>
	</div>
</div>

<div id="billModal" class="modal fade" role="dialog">
	<div class="modal-dialog">
    	<div class="modal-content">
      		<div class="modal-header">
        		<button type="button" class="close" data-dismiss="modal">&times;</button>
        		<h4 class="modal-title">Bill Modal</h4>
      		</div>
      		<div class="modal-body">
        		<p>Bill Data</p>
      		</div>
      		<div class="modal-footer">
        		<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
      		</div>
    	</div>
  	</div>
</div>

<?php $this->load->view('checkout/script', $current); ?>