<?php
	include("finance_func.php");
	$hddnFinanceId = $_SESSION['caller']['args'][1];
	if ($_SESSION['user']['access_level'] < SABLE_ACCESS_MANAGER)
	{
		SableGeneralFunctions::divertFromPage();
	}
	$row = $sableDB->getRow("select * from finance where finance_id = ".$hddnFinanceId);
	$txndate = new DateTime($row['txn_date']);
	$row['txn_amount'] = abs($row['txn_amount']);
?>
<script src="<?php SableGeneralFunctions::printModuleJS('finance'); ?>"></script>

<!--// Finance -->
<form id="frmFinance" name="frmFinance" autocomplete="on">
	<input type="hidden" value="<?php echo(SableSystem::sableEncode($hddnFinanceId)); ?>" id="hddnFinanceId" name="hddnFinanceId" />
	<div class="forms">
		<div class="container forms-grids">
			<div class="row forms-grid">
				<div class="col-md-12">
					<h3 class="title"><i class="fa fa-edit" aria-hidden="true"></i>&nbsp;Modify Finance</h3>
					<p></p>
				</div>
			</div>
			<!--// edtTxnDate -->
			<div class="row forms-grid">
				<div class="col-md-4 forms-grid">
					<input name="edtTxnDate" type="date" id="edtTxnDate" onfocus="showHint('edtTxnDate'); validate_edtTxnDate();" onblur="hideHint('edtTxnDate');" placeholder="Txn Date" onkeypress="handleEnter(this, event);" value="<?php echo($txndate->format('Y-m-d')); ?>" >
				</div>
				<div class="col-md-8">
					<div class="fieldHint" id="hint_edtTxnDate">Txn Date</div>
				</div>
			</div>
			<p></p>
			<!-- edtTxnDate //-->
			<p></p>
			<!--// edtClientName -->
			<div class="row forms-grids">
				<div class="col-md-4 forms-grid">
					<input type="text" id="edtClientName" name="edtClientName" placeholder="SEARCH..." onKeyUp="doClientRefinement(this)" style="border-bottom: none;" autocomplete="off"/>
				</div>
				<div class="col-md-8">
					<div class="fieldHint" id="hint_edtClientName">Search by name or cell no.</div>
				</div>   
			</div>
			<!-- edtClientName //-->			
			<!--// selClientId -->
			<div class="row forms-grid">
				<div class="col-md-4 forms-grid">
					<div class="dropdown">
						<select name="selClientId" type="select" id="selClientId" onfocus="showHint('selClientId');" onblur="hideHint('selClientId');"
								onkeypress="handleEnter(this, event)" placeholder="Client" size="6" class="noArrow"  onClick="setClientName()">
						<?php echo(SableDBFunctions::getOptions("client", "client_id", "concat(client_name, ' ', client_surname, ' [', client_cell, ']')", $row['client_id'], $clientWhere)); ?>
						</select>
					</div>
				</div>
				<div class="col-md-8">
					
				</div>
			</div>
			<div class="row forms-grid">
				<div class="col-md-4 forms-grid">
					<div class="fieldHint hintUnder" id="hint_selClientId">Client</div>
				</div>
				<div class="col-md-8">
					
				</div>
			</div>
			<p></p>
			<!-- selClientId //-->
			<p></p>
			<!--// selTxnTypeId -->
			<div class="row forms-grid">
				<div class="col-md-4 forms-grid">
					<div class="dropdown">
						<select name="selTxnTypeId" type="select" id="selTxnTypeId" onfocus="showHint('selTxnTypeId');" onblur="hideHint('selTxnTypeId'); validate_selTxnTypeId()" onkeypress="handleEnter(this, event)" placeholder="Transaction Type">
<?php echo(SableDBFunctions::getOptions("txn_type", "txn_type_id", "txn_type_name", $row['txn_type_id'])); ?>
						</select>
					</div>
				</div>
				<div class="col-md-8">
					<div class="fieldHint" id="hint_selTxnTypeId">Transaction Type</div>
				</div>
			</div>
			<p></p>
			<!-- selTxnTypeId //-->
			<p></p>
			<!--// selPmId -->
			<div class="row forms-grid">
				<div class="col-md-4 forms-grid">
					<div class="dropdown">
						<select name="selPmId" type="select" id="selPmId" onfocus="showHint('selPmId');" onblur="hideHint('selPmId'); validate_selPmId()" onkeypress="handleEnter(this, event)" placeholder="Pay Method">
<?php echo(SableDBFunctions::getOptions("payment_method", "pm_id", "pm_name", $row['pm_id'])); ?>
						</select>
					</div>
				</div>
				<div class="col-md-8">
					<div class="fieldHint" id="hint_selPmId">Pay Method</div>
				</div>
			</div>
			<p></p>
			<!-- selPmId //-->
			<p></p>
			<!--// edtTxnAmount -->
			<div class="row forms-grid">
				<div class="col-md-4 forms-grid">
					<input name="edtTxnAmount" type="number" id="edtTxnAmount" class="mod"  onfocus="showHint('edtTxnAmount'); validate_edtTxnAmount();" onblur="hideHint('edtTxnAmount');" placeholder="Amount" onkeypress="handleEnter(this, event);" value="<?php echo($row['txn_amount']); ?>" >
				</div>
				<div class="col-md-8">
					<div class="fieldHint" id="hint_edtTxnAmount">Amount</div>
				</div>
			</div>
			<p></p>
			<!-- edtTxnAmount //-->
			<p></p>
			<!--// cbTxnPaid -->
			<div class="row forms-grid">
				<div class="col-md-4 forms-grid">
					<?php $cbTxnPaid = $row['txn_paid']; ?>
					<div class="switch">
					<input name="cbTxnPaid" type="checkbox" id="cbTxnPaid" class="form-toggle form-toggle-yes-no" onfocus="showHint('cbTxnPaid');" onblur="hideHint('cbTxnPaid'); validate_cbTxnPaid()"  placeholder="Txn Paid" onkeypress="handleEnter(this, event)"<?php if($cbTxnPaid) echo("checked='checked'"); ?> />
<label for="cbTxnPaid" data-on="Yes" data-off="No"></label>
					</div>
				</div>
				<div class="col-md-8">
					<div class="fieldHint" id="hint_cbTxnPaid">Txn Paid</div>
				</div>
			</div>
			<p></p>
			<!-- cbTxnPaid //-->
			<p></p>
			<!--// txtTxnNotes -->
			<div class="row forms-grid">
				<div class="col-md-4 forms-grid">
			<textarea name="txtTxnNotes" type="textarea" id="txtTxnNotes" 
onfocus="showHint('txtTxnNotes');" onblur="hideHint('txtTxnNotes'); validate_txtTxnNotes()"
 placeholder="Notes"	
><?php echo($row['txn_notes'])?></textarea>
				</div>
				<div class="col-md-8">
					<div class="fieldHint" id="hint_txtTxnNotes">Notes</div>
				</div>
			</div>
			<p></p>
			<!-- txtTxnNotes //-->
			<p></p>
			<!--// selBsId -->
			<div class="row forms-grid">
				<div class="col-md-4 forms-grid">
					<div class="dropdown">
						<select name="selBsId" type="select" id="selBsId" onfocus="showHint('selBsId');" onblur="hideHint('selBsId'); validate_selBsId()" onkeypress="handleEnter(this, event)" placeholder="Booking Schedule">
<?php echo(SableDBFunctions::getOptions("booking_schedule", "bs_id", "booking_time", $row['bs_id'])); ?>
						</select>
					</div>
				</div>
				<div class="col-md-8">
					<div class="fieldHint" id="hint_selBsId">Booking Schedule</div>
				</div>
			</div>
			<p></p>
			<!-- selBsId //-->
			<p></p>
		<!--// buttons -->
			<div class="row forms-grid">
				<div class="col-md-2">
					<input type="button" id="btnCancel" value="Cancel"
					class="submit" onclick="window.location = '<?php SableSystem::printCallPageLink('/finance/'); ?>'"/>
				</div>
				<div class="col-md-2 forms-grid">
					<input id="btnOk" type="button" onclick="modifyFinance();" value="Update Finance" class="submit"/>
				</div>
			</div>
		<!-- buttons //-->
		</div>
	</div>
</form>
<!-- Finance //-->
<script>setClientName();</script>