<div class="admin-content-wrapper">
	<div class="admin-content admin-content-credits">
		<h1 class="credit-item-title">Credit</h1>
		<br /><br />
		<table class="admin-credit-form">
			<tr>
				<td class="label-primary">Credit:</td>
				<td class="content-primary">
					<div class="check-wrap">
						<div class="check-content">
							<table style="width:90%;">
								<tbody>
									<tr>
										<td class="label-sub">Value:</td>
										<td class="content-sub"><div class="input-faker">$<?=$this->credit->value;?></div></td>
									</tr>
									<tr>
										<td class="label-sub">Credit left:</td>
										<td class="content-sub"><div class="input-faker">$<?=$this->credit->creditLeft();?></div></td>
									</tr>
									<tr>
										<td class="label-sub">Type:</td>
										<td class="content-sub"><div class="input-faker"><?=$this->credit->type;?></div></td>
									</tr>
									<?php if( $this->credit->id_order ) { ?>
									<tr>
										<td class="label-sub">Order:</td>
										<td class="content-sub"><div class="input-faker">
											<a href="/vieworder/<?php echo $this->credit->order()->uuid; ?>">#<?=$this->credit->id_order;?></a>
										</div></td>
									</tr>
									<?php } ?>
								<?php if( $this->credit->id_order_reference ) { ?>
									<tr>
										<td class="label-sub">Order reference:</td>
										<td class="content-sub"><div class="input-faker">
											<a href="/vieworder/<?php echo $this->credit->order_reference()->uuid; ?>">#<?=$this->credit->id_order_reference;?></a>
										</div></td>
									</tr>
									<?php } ?>
								</tbody>
							</table>
						</div>
					</div>
				</td>
			</tr>
			<?php if( $this->credit->restaurant()->name ) { ?>
			<tr>
				<td class="label-primary">Place:</td>
				<td class="content-primary">
					<div class="check-wrap">
						<div class="check-content">
							<table style="width:90%;">
								<tbody>
									<tr>
										<td class="label-sub">Restaurant:</td>
										<td class="content-sub"><div class="input-faker"><?=$this->credit->restaurant()->name;?></div></td>
									</tr>
								</tbody>
							</table>
						</div>
					</div>
				</td>
			</tr>
			<?php } ?>

			<tr>
				<td class="label-primary">More information:</td>
				<td class="content-primary">
					<div class="check-wrap">
						<div class="check-content">
							<table style="width:90%;">
								<tbody>
									<?php if( $this->credit->user()->id_user ) { ?>
									<tr>
										<td class="label-sub">User ID:</td>
										<td class="content-sub"><div class="input-faker"><?=$this->credit->user()->id_user;?></div></td>
									</tr>
									<tr>
										<td class="label-sub">User name:</td>
										<td class="content-sub"><div class="input-faker"><?=$this->credit->user()->name;?></div></td>
									</tr>
									<?php } ?>
									<tr>
										<td class="label-sub">Date:</td>
										<td class="content-sub"><div class="input-faker"><?=$this->credit->date()->format('M jS Y')?> - <?=$this->credit->date()->format('g:i:s A')?></div></td>
									</tr>
									<?php if( $this->credit->note ) { ?>
									<tr>
										<td class="label-sub">Note:</td>
										<td class="content-sub"><div class="input-faker"><?=nl2br( $this->credit->note );?></div></td>
									</tr>
									<?php } ?>
									<?php if( $this->credit->paid_by ) { ?>
									<tr>
										<td class="label-sub">Paid by:</td>
										<td class="content-sub"><div class="input-faker"><?=$this->credit->paid_by;?></div></td>
									</tr>
									
									<?php } ?>
									<?php if( $this->credit->restaurant_paid_by()->id_restaurant ) { ?>
									<tr>
										<td class="label-sub">Paid by restaurant:</td>
										<td class="content-sub"><div class="input-faker"><?=$this->credit->restaurant_paid_by()->name;?></div></td>
									</tr>
									<?php } ?>
								</tbody>
							</table>
						</div>
					</div>
				</td>
			</tr>
			<?php  
				$debits = $this->credit->debitHistory(); 
				if( $debits->count() > 0 ){
			?>
			<tr>
				<td class="label-primary">History:</td>
				<td class="content-primary">
					<div class="check-wrap">
						<div class="check-content">
							<table style="width:90%;">
								<tbody>
									<?php foreach( $debits as $debit ){ ?>
										<tr>
											<td class="label-sub">Order:</td>
											<td class="content-sub"><div class="input-faker"><a href="/vieworder/<?php echo $debit->order()->uuid; ?>"><?=$debit->order()->id_order;?></a></div></td>
										</tr>
										<tr>
											<td class="label-sub">Charged:</td>
											<td class="content-sub"><div class="input-faker">$<?php if( $debit->value ){ echo $debit->value; } else { echo 0;};?></div></td>
										</tr>
										<?php if( $debit->note ) { ?>
										<tr>
											<td class="label-sub">Note:</td>
											<td class="content-sub"><div class="input-faker"><?php echo $debit->note;?></div></td>
										</tr>
										<?php } ?>
										<tr>
											<td>&nbsp;</td>
											<td align="right">--------------------------------------------------------------------</td>
										</tr>
									<?php } ?>
								</tbody>
							</table>
						</div>
					</div>
				</td>
			</tr>
			<?php } ?>
			<?php if( $this->credit->promo()->id_promo ) { ?>
			<tr>
				<td class="label-primary">Gift Card:</td>
				<td class="content-primary">
					<div class="check-wrap">
						<div class="check-content">
							<table style="width:90%;">
								<tbody>
									<tr>
										<td class="label-sub">Code:</td>
										<td class="content-sub"><div class="input-faker"><a href="/giftcards/<?=$this->credit->promo()->id_promo;?>"><?=$this->credit->promo()->code;?></a></div></td>
									</tr>
									<tr>
										<td class="label-sub">Created at:</td>
										<td class="content-sub"><div class="input-faker"><?=$this->credit->date()->format('M jS Y')?> - <?=$this->credit->date()->format('g:i:s A')?></div></td>
									</tr>
								</tbody>
							</table>
						</div>
					</div>
				</td>
			</tr>
			<?php } ?>
		</table>
	</div>
</div>