<div class="admin-content-wrapper">
	<div class="admin-content">

		<h1 class="restaurant-item-title">Create a Merchant Account</h1>

		<form id="restaurant-merchant" onsubmit="return false;">
			<table>
				<tr>
					<td>restaurant</td>
					<td>
						<select name="restaurant">
						<? foreach (Restaurant::q('select * from restaurant where balanced_id is null order by name') as $restaurant) : ?>
							<option value="<?=$restaurant->id_restaurant?>"><?=$restaurant->name?></option>
						<? endforeach ; ?>
						</select>
					</td>
				</tr>
				<tr>
					<td>type</td>
					<td>
						<select name="type">
							<option value="person">person</option>
							<option value="business">business</option>
						</select>
					</td>
				</tr>
				<tr>
					<td>taxid (business)</td>
					<td>
						<input type="text" name="taxid">
					</td>
				</tr>
				<tr>
					<td>person name (business)</td>
					<td>
						<input type="text" name="person">
					</td>
				</tr>
				<tr>
					<td>name (person)</td>
					<td>
						<input type="text" name="name">
					</td>
				</tr>
				<tr>
					<td>dob (person) YYYY-MM</td>
					<td>
						<input type="text" name="dob">
					</td>
				</tr>
				<tr>
					<td>address (person)</td>
					<td>
						<input type="text" name="address">
					</td>
				</tr>
				<tr>
					<td>zip (person)</td>
					<td>
						<input type="text" name="zip">
					</td>
				</tr>
				<tr>
					<td><button class="restaurant-merchant-button">submit</button></td>
				</tr>
			</table>
		</form>

		<br /><br /><br /><br /><br />
		<h1>add bank info</h1>
		<form id="restaurant-bank-info" onsubmit="return false;">
			<table>
				<tr>
					<td>restaurant</td>
					<td>
						<select name="restaurant">
						<? foreach (Restaurant::q('select * from restaurant order by name') as $restaurant) : ?>
							<option value="<?=$restaurant->id_restaurant?>"><?=$restaurant->name?></option>
						<? endforeach ; ?>
						</select>
					</td>
				</tr>
				<tr>
					<td>routing</td>
					<td>
						<input type="text" name="routing">
					</td>
				</tr>
				<tr>
					<td>account</td>
					<td>
						<input type="text" name="account">
					</td>
				</tr>
				<tr>
					<td>name on account</td>
					<td>
						<input type="text" name="name">
					</td>
				</tr>
				
				<tr>
					<td><button class="restaurant-bank-info-button">submit</button></td>
				</tr>
			</table>
		</form>

		<br /><br /><br /><br /><br />
		<h1>send money</h1>
		<form id="restaurant-pay" onsubmit="return false;">
			<table>
				<tr>
					<td>restaurant</td>
					<td>
						<select name="restaurant">
						<? foreach (Restaurant::q('select * from restaurant order by name') as $restaurant) : ?>
							<option value="<?=$restaurant->id_restaurant?>"><?=$restaurant->name?></option>
						<? endforeach ; ?>
						</select>
					</td>
				</tr>
				<tr>
					<td>amount</td>
					<td>
						<input type="text" name="amount">
					</td>
				</tr>
				<tr>
					<td>note</td>
					<td>
						<input type="text" name="note">
					</td>
				</tr>
				
				<tr>
					<td><button class="restaurant-pay-button">submit</button></td>
				</tr>
			</table>
		</form>
		<br /><br /><br /><br /><br />
		<h1>recent payments</h1>
		<table width="100%" cellpadding="4" cellspacing="4">
			<tr>
				<th>restaurant</th>
				<th>date</th>
				<th>amount</th>
				<th>note</th>
			</tr>
		<? foreach (Payment::q('select * from payment where env="'.c::env().'"') as $payment) : ?>
			<tr>
				<td><?=$payment->restaurant()->name?></td>
				<td><?=$payment->date?></td>
				<td>$<?=$payment->amount?></td>
				<td><?=$payment->note?></td>
			</tr>
		<? endforeach; ?>
		</table>
	</div>
</div>

<script>
	$(function() {
		$('.restaurant-merchant-button').click(function() {
			var form = $('#restaurant-merchant');
			$.post('/api/restaurant/' + form.find('[name="restaurant"]').val() + '/merchant', {
				type: form.find('[name="type"]').val(),
				name: form.find('[name="name"]').val(),
				address: form.find('[name="address"]').val(),
				zip: form.find('[name="zip"]').val(),
				person: form.find('[name="person"]').val(),
				taxid: form.find('[name="taxid"]').val(),
				dob: form.find('[name="dob"]').val()
			}, function() {
				alert('done');
			});
		});

		$('.restaurant-bank-info-button').click(function() {

			var form = $('#restaurant-bank-info');
			$.post('/api/restaurant/' + form.find('[name="restaurant"]').val() + '/bankinfo', {
				routing: form.find('[name="routing"]').val(),
				account: form.find('[name="account"]').val(),
				name: form.find('[name="name"]').val()
			}, function() {
				alert('done');
			});
		});

		$('.restaurant-pay-button').click(function() {
			var form = $('#restaurant-pay');
			$.post('/api/restaurant/' + form.find('[name="restaurant"]').val() + '/credit', {
				amount: form.find('[name="amount"]').val(),
				note: form.find('[name="note"]').val()
			}, function() {
				alert('done');
			});
		});

	})
</script>

