
<!-- templates below here -->

<script id="newLoanScheduleTemplate" type="text/x-jquery-tmpl">
<table id="repaymentschedule" class="pretty displayschedule">
	<caption>Repayment Schedule</caption>
	<thead>
		<tr>
			<th>#</th>
			<th>Date</th>
			<th>Principal</th>
			<th>Interest</th>
			<th>Total</th>
			<th>Outstanding</th>
		</tr>
	</thead>
	<tbody>
		<tr>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>{{=$ctx.money(cumulativePrincipal)}}</td>
		</tr>
		{{#each scheduledLoanInstallments}}
		<tr>
			<td>{{=$ctx.number(installmentNumber)}}</td>
			<td>{{=$ctx.globalDate(periodEnd)}}</td>
			<td>{{=$ctx.money(principalDue)}}</td>
			<td>{{=$ctx.money(interestDue)}}</td>
			<td>{{=$ctx.money(totalInstallmentDue)}}</td>
			<td>{{=$ctx.money(outStandingBalance)}}</td>
		</tr>
		{{/each}}
	</tbody>
	<tfoot class="ui-widget-header">
		<tr class="ui-widget-header">
			<th>Total</th>
			<th>&nbsp;</th>
			<th>{{=$ctx.money(cumulativePrincipal)}}</th>
			<th>{{=$ctx.money(cumulativeInterest)}}</th>
			<th>{{=$ctx.money(cumulativeTotal)}}</th>
			<th>&nbsp;</th>
		</tr>
	</tfoot>
</table>
</script>

<script id="newLoanFormTemplate" type="text/x-jquery-tmpl">
<form id="entityform">
    <div id="formerrors"></div>

	<input type="hidden" id="clientId" name="clientId" value="{{=clientId}}" />
	<input type="hidden" id="dateFormat" name="dateFormat" value="dd MMMM yyyy" />
	<input type="hidden" id="locale" name="locale" value="en" />

	<fieldset>
		<legend>Loan Information</legend>
		<div>
			<table id="productdetails">
				<tr>
					<td valign="top">
						<label for="clientname">Applicant:</label>
						<input id="clientname" name="clientName" title="" type="text" value="{{=clientName}}" disabled="disabled" />

						<label for="productId">Product:</label>
						<select name="productId" id="productId">
							<option value="-1">--Select Product--</option>
						{{#each allowedProducts}}
							{{#if $ctx.number($parent.parent.data.productId)===$ctx.number(id)}}
									<option value="{{=$ctx.number(id)}}" selected="selected">{{=name}}</option>
							{{#else}}
									<option value="{{=$ctx.number(id)}}">{{=name}}</option>
							{{/if}}
        				{{/each}}
  						</select>
						<label for="description">Description:</label>
						<textarea id="description" rows="2" cols="50" draggable="false" disabled="disabled">{{=selectedProduct.description}}</textarea>
					</td>
					<td style="text-align:right;vertical-align:bottom;width:50px;">&nbsp;</td>
					<td valign="top">
						<label for="submittedOnDate">Submitted on:</label>
						<input id="submittedOnDate" name="submittedOnDate" title="" type="text" class="datepickerfield" value="{{=$ctx.globalDate(submittedOnDate)}}" />

						<label for="submittedOnNote">Loan submittal note:</label>
						<textarea id="submittedOnNote" name="submittedOnNote" rows="2" cols="50" draggable="false">{{=submittedOnNote}}</textarea>
					</td>
				</tr>
			</table>
		</div>
	</fieldset>
	<fieldset>
		<legend>Loan Terms</legend>
		<table>
			<tr>
				<td valign="top" style="padding-right: 5px; border-right: 1px solid;">
					<table>
						<tr>
							<td>Loan amount:</td>
							<td>
								<input id="principal" name="principal" title="" type="text" value="{{=$ctx.money(selectedProduct.principal)}}" style="width: 125px;" />
								<input id="principalCurrencyCode" name="principalCurrencyCode" title="" type="text" value="{{=selectedProduct.principal.displaySymbol}}" style="width: 40px;" disabled="disabled" />
							</td>
						</tr>
						<tr>
							<td>Repaid every:</td>
							<td>
								<input id="repaymentEvery" name="repaymentEvery" title="" type="text" value="{{=$ctx.number(selectedProduct.repaymentEvery)}}" style="width: 50px;" />
								
								<select name="repaymentFrequencyType" id="repaymentFrequencyType"  title="" style="width: 121px;">
								{{#each selectedProduct.repaymentFrequencyTypeOptions}}
								{{#if $ctx.number($parent.parent.data.selectedProduct.repaymentFrequencyType.id)===$ctx.number(id)}}
									<option value="{{=$ctx.number(id)}}" selected="selected">{{=value}}</option>
								{{#else}}
									<option value="{{=$ctx.number(id)}}">{{=value}}</option>
								{{/if}}
        						{{/each}}
  								</select>
							</td>
						</tr>
						<tr>
							<td># of repayments:</td>
							<td>
								<input id="numberOfRepayments" name="numberOfRepayments" title="" type="text" value="{{=$ctx.number(selectedProduct.numberOfRepayments)}}" style="width: 50px;" />
							</td>
						</tr>
						<tr>
							<td>Expected disbursement on:</td>
							<td>
							<input id="expectedDisbursementDate" name="expectedDisbursementDate" title="" type="text" class="datepickerfield" value="{{=$ctx.globalDate(expectedDisbursementDate)}}" style="width:172px;"/>
							</td>
						</tr>
						<tr>
							<td>First repayment on:</td>
							<td>
							<input id="repaymentsStartingFromDate" name="repaymentsStartingFromDate" title="" type="text" class="datepickerfield" value="{{=$ctx.globalDate(repaymentsStartingFromDate)}}" style="width:172px;"/>
							</td>
						</tr>
					</table>
				</td>
				<!-- interest details cell -->
				<td valign="top" style="padding-left: 5px; padding-right: 5px; border-right: 1px solid;">
					<table>
						<tr>
							<td>Nominal interest rate %:</td>
							<td>
								<input id="interestRatePerPeriod" name="interestRatePerPeriod" title="" type="text" value="{{=$ctx.decimal(selectedProduct.interestRatePerPeriod, 4)}}" style="width: 60px;" />
								
								<select name="interestRateFrequencyType" id="interestRateFrequencyType"  title="" style="width: 115px;">
								{{#each selectedProduct.interestRateFrequencyTypeOptions}}
								{{#if $ctx.number($parent.parent.data.selectedProduct.interestRateFrequencyType.id)===$ctx.number(id)}}
									<option value="{{=$ctx.number(id)}}" selected="selected">{{=value}}</option>
								{{#else}}
									<option value="{{=$ctx.number(id)}}">{{=value}}</option>
								{{/if}}
        						{{/each}}
  								</select>
							</td>
						</tr>
						<tr>
							<td>Annual nominal rate %:</td>
							<td>
								<input id="interestRatePerYear" name="interestRatePerYear" title="" type="text" style="width: 60px;" disabled="disabled" />
							</td>
						</tr>
						<tr>
							<td>Amortization:</td>
							<td>
								<select name="amortizationType" id="amortizationType"  title="" style="width: 178px;">
								{{#each selectedProduct.amortizationTypeOptions}}
								{{#if $ctx.number($parent.parent.data.selectedProduct.amortizationType.id)===$ctx.number(id)}}
									<option value="{{=$ctx.number(id)}}" selected="selected">{{=value}}</option>
								{{#else}}
									<option value="{{=$ctx.number(id)}}">{{=value}}</option>
								{{/if}}
        						{{/each}}
  								</select>
							</td>
						</tr>
						<tr>
							<td>Interest method:</td>
							<td>
								<select name="interestType" id="interestType"  title="" style="width: 180px;">
								{{#each selectedProduct.interestTypeOptions}}
								{{#if $ctx.number($parent.parent.data.selectedProduct.interestType.id)===$ctx.number(id)}}
									<option value="{{=$ctx.number(id)}}" selected="selected">{{=value}}</option>
								{{#else}}
									<option value="{{=$ctx.number(id)}}">{{=value}}</option>
								{{/if}}
        						{{/each}}
  								</select>
							</td>
						</tr>
						<tr>
							<td>Interest calculation period:</td>
							<td>
							<select id="interestCalculationPeriodType" name="interestCalculationPeriodType" title="" style="width: 220px;">
								{{#each selectedProduct.interestCalculationPeriodTypeOptions}}
                                 	{{#if $ctx.number($parent.parent.data.selectedProduct.interestCalculationPeriodType.id)===$ctx.number(id)}}
										<option value="{{=$ctx.number(id)}}" selected="selected">{{=value}}</option>
									{{#else}}
										<option value="{{=$ctx.number(id)}}">{{=value}}</option>
									{{/if}}
                                {{/each}}
							</select>
							</td>
						</tr>
						<tr>
							<td>Interest charged from:</td>
							<td>
							<input id="interestChargedFromDate" name="interestChargedFromDate" title="" type="text" class="datepickerfield" value="{{=$ctx.globalDate(interestCalculatedFromDate)}}" style="width:172px;"/>
							</td>
						</tr>
						<tr>
							<td>Arrears tolerance:</td>
							<td>
								<input id="inArrearsTolerance" name="inArrearsTolerance" title="" type="text" value="{{=$ctx.money(selectedProduct.inArrearsTolerance)}}" style="width: 125px;" />
								<input id="inArrearsCurrencyCode" name="inArrearsCurrencyCode" title="" type="text" value="{{=selectedProduct.inArrearsTolerance.displaySymbol}}" style="width: 40px;" disabled="disabled" />
							</td>
						</tr>
					</table>
				</td>
				<td>
				<!-- Other options -->
					<div>
						<span id="toolbar" class="ui-widget-header ui-corner-all">
							<button type="submit" class="submitloanapp" id="submitloanapp" name="_eventId_submit"  title="Submit loan application.">Submit loan application</button>
							<button type="submit" class="cancelloanapp" id="cancelloanapp" name="_eventId_cancel" title="Cancel loan application.">Cancel</button>
						</span>
					</div>
				<!-- other options -->
				</td>
			</tr>
		</table>
	</fieldset>
</form>
</script>

<script id="newLoanFormTemplateMin" type="text/x-jquery-tmpl">
<form id="entityform">
    <div id="formerrors"></div>

	<input type="hidden" id="clientId" name="clientId" value="{{=clientId}}" />
	
	<label for="clientname">Applicant:</label>
	<input id="clientname" name="clientName" title="" type="text" value="{{=clientName}}" disabled="disabled" />

	<label for="productId">Product:</label>
	<select name="productId" id="productId">
		<option value="-1">--Select Product--</option>
{{#each allowedProducts}}
	{{#if $ctx.number($parent.parent.data.productId)===$ctx.number(id)}}
		<option value="{{=$ctx.number(id)}}" selected="selected">{{=name}}</option>
	{{#else}}
		<option value="{{=$ctx.number(id)}}">{{=name}}</option>
	{{/if}}
{{/each}}
	</select>
</form>	
</script>

<script id="noteListViewTemplate" type="text/x-jquery-tmpl">
{{#if notes.length > 0}}
	<div class="ui-widget .ui-widget-content ui-corner-all notecontainer">
		<div class="ui-widget-header">
			<span class="ui-icon ui-icon-info" style="float: left; margin-right: 5px;" ></span>
			<span>{{=title}}</span>
		</div>
		<div class="ui-widget ui-widget-content ui-corner-all">
		
		{{#each notes}}
			<div>
				<div class="notespacer">
					<span class="ui-icon ui-icon-note" style="float: left; margin-right: 5px;"></span>
					{{#if noteType.id === 100}}
					<span>Client note:</span>
					{{/if}}
					{{#if noteType.id === 200}}
					<span>Loan note:</span>
					{{/if}}
					{{#if noteType.id === 300}}
					<span>Loan transaction note:</span>
					{{/if}}
					<span><a href="#" class="editclientnote" id="editclientnotelink{{=id}}">Edit</a></span>
				</div>
				<div class="notecontent">{{=note}}</div>
				<div class="notespacer">
					<span class="ui-icon ui-icon-person" style="float: left; margin-right: 5px;" ></span>
					<span class="noteusername">{{=updatedByUsername}}</span>
					<span>&nbsp;{{=$ctx.globalDateTime(updatedOn)}}</span>
				</div>
			</div>
		{{/each}}
		</div>
	</div>
{{/if}}
</script>

<script id="noteFormTemplate" type="text/x-jquery-tmpl">
<form id="entityform">
    <div id="formerrors"></div>

	<label for="note">Note:</label>
	<textarea rows="10" cols="75" id="note" name="note" cssClass="text ui-widget-content ui-corner-all">{{=note}}</textarea>
</form>
</script>

<script id="clientSearchTabTemplate" type="text/x-jquery-tmpl">
<form method="post" id="viewClient" name="viewClient" action="switchToClient">
	<label for="client">Choose client:</label>
	<select name="client" id="client">
		<option value="0">--Select Client--</option>
		{{#each clients}}
			<option value="{{=id}}">{{=displayName}}&nbsp;-&nbsp;({{=officeName}})</option>
        {{/each}}
  	</select>
</form>	
</script>

<script id="clientFormTemplate" type="text/x-jquery-tmpl">
<form id="entityform">
    <div id="formerrors"></div>
	<label for="office">Office:</label>
	<select id="officeId" name="officeId" title="">
		<option value="">--Select Office--</option>
		{{#each allowedOffices}}
			{{#if $ctx.number($parent.parent.data.officeId)===$ctx.number(id)}}
				<option value="{{=$ctx.number(id)}}" selected="selected">{{=name}}</option>
			{{#else}}
				<option value="{{=$ctx.number(id)}}">{{=name}}</option>
			{{/if}}
        {{/each}}
	</select>

	<table>
		<tr>
			<td>
				<label for="firstname">First name:</label>
				<input id="firstname" name="firstname" title="" type="text" value="{{=firstname}}"/>
			</td>
			<td>
				<label for="lastname">Last name:</label>
				<input id="lastname" name="lastname" title="" type="text" value="{{=lastname}}"/>
			</td>
		<tr>
		<tr>
			<td colspan="2">
				<label for="clientOrBusinessName">Client or Business name:</label>
				<input id="clientOrBusinessName" name="clientOrBusinessName" title="" type="text" value="{{=fullname}}" style="width:100%"/>
			</td>
		</tr>
	</table>

	<input type="hidden" id="dateFormat" name="dateFormat" value="dd MMMM yyyy" />
	<label for="joiningDate">Joining date:</label>
	<input id="joiningDate" name="joiningDate" title="" type="text" class="datepickerfield" value="{{=$ctx.globalDate(joinedDate)}}"/>
</form>
</script>

<script id="clientAccountSummariesTemplate" type="text/x-jquery-tmpl">
{{#if $ctx.numberGreaterThanZero(anyLoanCount)}}

{{#if $ctx.numberGreaterThanZero(pendingApprovalLoanCount)}}
<div class="row">
	<span class="longrowlabel">Pending approval loans ({{=$ctx.number(pendingApprovalLoanCount)}}):</span>
	<span class="rowvalue">
	{{#each pendingApprovalLoans}}
		<span class="loanaccount"><a href="https://localhost:8443/mifosng-provider/api/v1/loans/{{=id}}?associations=ALL" id="loan{{=id}}" class="openloanaccount" title="{{=loanProductName}}: &#35;{{=id}}">{{=loanProductName}}: &#35;{{=id}}</a></span>
	{{/each}}
	</span>
</div>
{{/if}}

{{#if $ctx.numberGreaterThanZero(awaitingDisbursalLoanCount)}}
<div class="row">
	<span class="longrowlabel">Awaiting disbursal loans ({{=$ctx.number(awaitingDisbursalLoanCount)}}):</span>
	<span class="rowvalue">
	{{#each awaitingDisbursalLoans}}
		<span class="loanaccount"><a href="https://localhost:8443/mifosng-provider/api/v1/loans/{{=id}}?associations=ALL" id="loan{{=id}}" class="openloanaccount" title="{{=loanProductName}}: &#35;{{=id}}">{{=loanProductName}}: &#35;{{=id}}</a></span>
	{{/each}}
	</span>
</div>
{{/if}}

{{#if $ctx.numberGreaterThanZero(activeLoanCount)}}
<div class="row">
	<span class="longrowlabel">Active loans ({{=$ctx.number(activeLoanCount)}}):</span>
	<span class="rowvalue">
	{{#each openLoans}}
		<span class="loanaccount"><a href="https://localhost:8443/mifosng-provider/api/v1/loans/{{=id}}?associations=ALL" id="loan{{=id}}" class="openloanaccount" title="{{=loanProductName}}: &#35;{{=id}}">{{=loanProductName}}: &#35;{{=id}}</a></span>
	{{/each}}
	</span>
</div>
{{/if}}

{{#if $ctx.numberGreaterThanZero(closedLoanCount)}}
<div class="row">
	<div class="longrowlabel">Closed loans ({{=$ctx.number(closedLoanCount)}}):</div>
	<div class="rowvalue">
	{{#each closedLoans}}
		<span class="loanaccount"><a href="https://localhost:8443/mifosng-provider/api/v1/loans/{{=id}}?associations=ALL" id="loan{{=id}}" class="openloanaccount" title="{{=loanProductName}}: &#35;{{=id}}">{{=loanProductName}}: &#35;{{=id}}</a></span>
	{{/each}}
	</div>
</div>
{{/if}}

{{#else}}
<div>
	No accounts exist</div>
{{/if}}
</script>

<script id="clientDataTabTemplate" type="text/x-jquery-tmpl">
<span id="toolbar" class="ui-widget-header ui-corner-all">
    <!--
	<button id="cashflowbtn{{=id}}" class="casflowbtn">New cashflow analysis</button>
    -->
	<button id="newloanbtn{{=id}}" class="newloanbtn">New loan application</button>
	<button id="addnotebtn{{=id}}" class="addnotebtn">Add note</button>
</span>
<hr/>

<div id="clienttabcontent">
	<div id="clienttableftpane" style="float:left; max-width: 700px; width: 700px;">
		<div class="row">
			<span class="longrowlabel">Name:</span>
			<span class="rowvalue">{{=displayName}}</span>
		</div>
		<div class="row">
			<span class="longrowlabel">Branch:</span>
			<span class="rowvalue">{{=officeName}}</span>
		</div>
		<div class="row">
			<span class="longrowlabel">Joined on:</span>
			<span class="rowvalue">{{=$ctx.globalDate(joinedDate)}}</span>
		</div>

		<p><b>Account Overview</b></p>
		<div id="clientaccountssummary"></div>

		<div id="clientadditionaldata"></div>
	</div>
	<!-- end of left pane content -->

	<!-- placeholder for notes content -->
	<div id="clienttabrightpane" style="float:right;"></div>
</div>
<div style="clear: both;"></div>
</script>

<script id="loanDataTabTemplate" type="text/x-jquery-tmpl">


{{#each permissions}}
{{#if anyActionOnLoanAllowed}}
<div id="loanactions">
	<span id="toolbar" class="ui-widget-header ui-corner-all">

		
		{{#if rejectAllowed}}
		<button id="rejectbtn{{=$parent.parent.parent.data.id}}" class="rejectloan">Reject</button>
		{{/if}}
		
		{{#if withdrawnByApplicantAllowed}}
		<button id="withdrawnbyapplicantloanbtn{{=$parent.parent.parent.data.id}}" class="withdrawnbyapplicantloan">Withdrawn By Applicant</button>
		{{/if}}
		
		{{#if pendingApproval}}
		<button id="approvebtn{{=$parent.parent.parent.data.id}}" class="approveloan">Approve</button>
		{{/if}}
		
		{{#if pendingApproval}}
		<button id="deletebtn{{=$parent.parent.parent.data.id}}" class="deleteloan">Delete</button>
		{{/if}}
		
		{{#if undoApprovalAllowed}}
		<button id="undoapprovebtn{{=$parent.parent.parent.data.id}}" class="undoapproveloan">Undo Approval</button>
		{{/if}}
		
		{{#if disbursalAllowed}}
		<button id="disbursebtn{{=$parent.parent.parent.data.id}}" class="disburseloan">Disburse</button>
		{{/if}}
		
		{{#if undoDisbursalAllowed}}
		<button id="undodisbursalbtn{{=$parent.parent.parent.data.id}}" class="undodisbursalloan">Undo Disbursal</button>
		{{/if}}
		
		{{#if makeRepaymentAllowed}}
		<button id="repaymentbtn{{=$parent.parent.parent.data.id}}" class="repaymentloan">Make Repayment</button>
		{{/if}}
		
		
		{{#if waiveAllowed}}
		<button id="waivebtn{{=$parent.parent.parent.data.id}}" class="waiveloan">Waive</button>
		{{/if}}
	</span>
</div>
{{/if}}
{{/each}}

<div id="loantabs{{=id}}" class="loantabs">
	<ul>
		<li><a href="#details{{=id}}" title="details">Details</a></li>
		<li><a href="#schedule{{=id}}" title="schedule">Schedule</a></li>
		{{#if loanRepayments}}
		<li><a href="#repayments{{=id}}" title="repayments">Repayments</a></li>
		{{/if}}
	</ul>
    <!-- first loan tab -->

	<div id="details{{=id}}" style="margin-top: 5px;">
		<div class="row">
			<span class="longrowlabel">Status:</span>
			<span class="rowvalue">{{=lifeCycleStatusText}} (since {{=$ctx.globalDate(lifeCycleStatusDate)}})
{{#if $ctx.numberGreaterThanZero(summary.totalInArrears.amount)}}
	{{#if actualDisbursementDate !== null}}
		- In arrears by: {{=$ctx.moneyWithCurrency($parent.parent.data.summary.totalInArrears)}}
	{{/if}}
{{/if}}
			</span>
		</div>

		{{#if submittedOnDate !== null}}
		<div class="row">
			<span class="longrowlabel">Sumbitted on:</span>
			<span class="rowvalue">{{=$ctx.globalDate(submittedOnDate)}}</span>
		</div>
		{{/if}}

		{{#if approvedOnDate !== null}}
		<div class="row">
			<span class="longrowlabel">Approved on:</span>
			<span class="rowvalue">{{=$ctx.globalDate(approvedOnDate)}}</span>
		</div>
		{{/if}}

		{{#if actualDisbursementDate === null}}
		<div class="row">
			<span class="longrowlabel">Expected dibursement on:</span>
			<span class="rowvalue">{{=$ctx.globalDate(expectedDisbursementDate)}}</span>
		</div>
		{{/if}}

		{{#if actualDisbursementDate !== null}}
		<div class="row">
			<span class="longrowlabel">Disbursed on:</span>
			<span class="rowvalue">{{=$ctx.globalDate(actualDisbursementDate)}}</span>
		</div>
		{{/if}}

		{{#if expectedFirstRepaymentOnDate !== null}}
		<div class="row">
			<span class="longrowlabel">First repayment due on:</span>
			<span class="rowvalue">{{=$ctx.globalDate(expectedFirstRepaymentOnDate)}}</span>
		</div>
		{{/if}}

		{{#if interestChargedFromDate !== null}}
		<div class="row">
			<span class="longrowlabel">Interest charged from:</span>
			<span class="rowvalue">{{=$ctx.globalDate(interestChargedFromDate)}}</span>
		</div>
		{{/if}}

		{{#if actualDisbursementDate !== null}}
		<div class="row">
			<span class="longrowlabel">Expected to mature on:</span>
			<span class="rowvalue">{{=$ctx.globalDate(expectedMaturityDate)}}</span>
		</div>
		{{/if}}

		{{#if closedOnDate !== null}}
		<div class="row">
			<span class="longrowlabel">Closed on:</span>
			<span class="rowvalue">{{=$ctx.globalDate(closedOnDate)}}</span>
		</div>
		{{/if}}

		<div class="row">
			<span class="longrowlabel">Expected loan term:</span>
			<span class="rowvalue">{{=convenienceData.expectedLoanTermInMonths}} Months / ({{=convenienceData.expectedLoanTermInDays}} Days)</span>
		</div>

		{{#if closedOnDate !== null}}
		<div class="row">
			<span class="longrowlabel">Actual loan term:</span>
			<span class="rowvalue">{{=convenienceData.actualLoanTermInMonths}} Months / ({{=convenienceData.actualLoanTermInDays}} Days)</span>
		</div>
		{{/if}}

		<br/>
		<div class="row">
			<span class="longrowlabel">Product:</span>
			<span class="rowvalue">{{=loanProductName}}</span>
		</div>
		<div class="row">
			<span class="longrowlabel">External id:</span>
			<span class="rowvalue">{{=externalId}}</span>
		</div>
		<br/>
		<div class="row">
			<span class="longrowlabel">Currency:</span>
			<span class="rowvalue">{{=principal.defaultName}}</span>
		</div>
		<div class="row">
			<span class="longrowlabel">Principal:</span>
			<span class="rowvalue">{{=$ctx.moneyWithCurrency(principal)}}</span>
		</div>
		<div class="row">
			<span class="longrowlabel">Repayments:</span>
			<span class="rowvalue">{{=numberOfRepayments}} every {{=repaymentEvery}}&nbsp;{{=repaymentFrequencyType.value}}</span>
		</div>
		<div class="row">
			<span class="longrowlabel">Amortization:</span>
			<span class="rowvalue">{{=amortizationType.value}}</span>
		</div>
		<div class="row">
			<span class="longrowlabel">Interest:</span>
			<span class="rowvalue">{{=$ctx.decimal(annualInterestRate, 4)}}% per annum ({{=$ctx.decimal(interestRatePerPeriod, 4)}}%&nbsp; {{=interestRateFrequencyType.value}}) - {{=interestType.value}}</span>
		</div>

		<div id="loanadditionaldata{{=id}}"></div>
	</div>		

	<!-- second loan tab -->
	<div id="schedule{{=id}}" style="margin-top: 5px;">
		<table id="summarytable{{=id}}" class="pretty displayschedule">
			<caption>Summary</caption>
			<thead>
				<tr>
					<th class="empty"></th>
					<th>Original Loan</th>
					<th>Paid</th>
					<th>Waived</th>
					<th>Outstanding</th>
				</tr>
			</thead>
			<tbody>
				<tr>
					<th>Principal</th>
					<td>{{=$ctx.money(summary.originalPrincipal)}}</td>
					<td>{{=$ctx.money(summary.principalPaid)}}</td>
					<td>&nbsp;</td>
					<td>{{=$ctx.money(summary.principalOutstanding)}}</td>
				</tr>
				<tr>
					<th>Interest</th>
					<td>{{=$ctx.money(summary.originalInterest)}}</td>
					<td>{{=$ctx.money(summary.interestPaid)}}</td>
					<td>&nbsp;</td>
					<td>{{=$ctx.money(summary.interestOutstanding)}}</td>
				</tr>
			</tbody>
			<tfoot>
				<tr>
					<th>Total</th>
					<th>{{=$ctx.money(summary.originalTotal)}}</th>
					<th>{{=$ctx.money(summary.totalPaid)}}</th>
					<th>{{=$ctx.money(summary.totalWaived)}}</th>
					<th>{{=$ctx.money(summary.totalOutstanding)}}</th>
				</tr>
			</tfoot>
		</table>

		<br/>

		<table id="repaymentschedule_todate{{=id}}" class="pretty displayschedule">
			<caption>Repayment Schedule</caption>
			<colgroup span="2"></colgroup>
			<colgroup span="3">
				<col class="lefthighlightcol">
				<col>
				<col class="righthighlightcol">
			</colgroup>
			<colgroup span="3">
				<col class="lefthighlightcol">
				<col>
				<col class="righthighlightcol">
			</colgroup>
			<colgroup span="3">
				<col class="lefthighlightcol">
				<col>
				<col class="righthighlightcol">
			</colgroup>
			<thead>
				<tr>
					<th colspan="2" scope="colgroup" class="empty">&nbsp;</th>
					<th colspan="3" scope="colgroup" class="highlightcol">Principal</th>
					<th colspan="3" scope="colgroup" class="highlightcol">Interest</th>
					<th colspan="3" scope="colgroup" class="highlightcol">Total</th>
				</tr>
				<tr>
					<th scope="col">#</th>
					<th scope="col">Date</th>
					<th scope="col" class="lefthighlightcolheader">Expected</th>
					<th scope="col">Paid</th>
					<th scope="col" class="righthighlightcolheader">Outstanding</th>
					<th scope="col" class="lefthighlightcolheader">Expected</th>
					<th scope="col">Paid</th>
					<th scope="col" class="righthighlightcolheader">Outstanding</th>
					<th scope="col" class="lefthighlightcolheader">Expected</th>
					<th scope="col">Paid</th>
					<th scope="col" class="righthighlightcolheader">Outstanding</th>
				</tr>
			</thead>
			<tbody>
			{{#each repaymentSchedule.periods}}
			<tr>
				<td scope="row">{{=$ctx.number(period)}}</td>
				<td>{{=$ctx.globalDate(date)}}</td>
				<td class="lefthighlightcolheader">{{=$ctx.money(principal)}}</td>
				<td>{{=$ctx.money(principalPaid)}}</td>
				<td class="righthighlightcolheader">{{=$ctx.money(principalOutstanding)}}</td>
				<td class="lefthighlightcolheader">{{=$ctx.money(interest)}}</td>
				<td>{{=$ctx.money(interestPaid)}}</td>
				<td class="righthighlightcolheader">{{=$ctx.money(interestOutstanding)}}</td>
				<td class="lefthighlightcolheader">{{=$ctx.money(total)}}</td>
				<td>{{=$ctx.money(totalPaid)}}</td>
				<td class="righthighlightcolheader">{{=$ctx.money(totalOutstanding)}}</td>
			</tr>
			{{/each}}
			</tbody>
			<tfoot>
				<tr>
					<th colspan="2">Total</th>
					<th class="lefthighlightcolheader">{{=$ctx.money(summary.originalPrincipal)}}</th>
					<th>{{=$ctx.money(summary.principalPaid)}}</th>
					<th class="righthighlightcolheader">{{=$ctx.money(summary.principalOutstanding)}}</th>
					<th class="lefthighlightcolheader">{{=$ctx.money(summary.originalInterest)}}</th>
					<th>{{=$ctx.money(summary.interestPaid)}}</th>
					<th class="righthighlightcolheader">{{=$ctx.money(summary.interestOutstanding)}}</th>
					<th class="lefthighlightcolheader">{{=$ctx.money(summary.originalTotal)}}</th>
					<th>{{=$ctx.money(summary.totalPaid)}}</th>
					<th class="righthighlightcolheader">{{=$ctx.money(summary.totalOutstanding)}}</th>
				</tr>
			</tfoot>
		</table>
	</div>
    {{#if loanRepayments}}
	<!-- Third loan tab -->
	<div id="repayments{{=id}}" style="margin-top: 5px;">
		<table id="newrepaymentsactivity{{=id}}" class="pretty displaypayments">
		<caption>Repayment Activity</caption>
			<thead>
				<tr>
				<th>Payment Date</th>
				<th>Amount Paid</th>
				<th>Principal Portion</th>
				<th>Interest Portion</th>
				{{#if actualDisbursementDate !== null}}
				<th>Action</th>
				{{/if}}
				</tr>
			</thead>
			<tbody>
				{{#each loanRepayments}}
				<tr>
				<td>{{=$ctx.globalDate(date)}}</td>
				<td>{{=$ctx.money(total)}}</td>
				<td>{{=$ctx.money(principal)}}</td>
				<td>{{=$ctx.money(interest)}}</td>
				{{#if $parent.parent.data.actualDisbursementDate !== null}}
				<td><button id="adjustrepaymentbtn{{=$parent.parent.parent.data.id}}_{{=id}}" class="adjustloanrepayment">Adjust</button></td>
				{{/if}}
				</tr>
				{{/each}}
			</tbody>
		</table>
	</div>
	{{/if}}

</div>

</script>

<script id="stateTransitionLoanFormTemplate" type="text/x-jquery-tmpl">
<form id="entityform">
    <div id="formerrors"></div>

	<input type="hidden" id="dateFormat" name="dateFormat" value="dd MMMM yyyy" />
	<label for="eventDate">On:</label>
	<input id="eventDate" name="eventDate" title="" class="datepickerfield" />

	<label for="note">Note:</label>
	<textarea rows="3" cols="53" id="note" name="note"></textarea>
</form>
</script>

<script id="undoStateTransitionLoanFormTemplate" type="text/x-jquery-tmpl">
<form id="entityform">
    <div id="formerrors"></div>

	<label for="note">Note:</label>
	<textarea rows="6" cols="53" id="note" name="note"></textarea>
</form>
</script>

<script id="transactionLoanFormTemplate" type="text/x-jquery-tmpl">
<form id="entityform">
    <div id="formerrors"></div>

	<input type="hidden" id="dateFormat" name="dateFormat" value="dd MMMM yyyy" />
	<input type="hidden" id="locale" name="locale" value="{{=$ctx.currentLocale()}}" />

	<label for="transactionDate">Repayment on:</label>
	<input id="transactionDate" name="transactionDate" class="text ui-widget-content ui-corner-all datepickerfield" title=""d value="{{=$ctx.globalDate(date)}}"/>

	<label for="transactionAmount">Amount:</label>
	<input id="transactionAmount" name="transactionAmount" class="text ui-widget-content ui-corner-all" title="" value="{{=$ctx.money(total)}}" />

	<label for="note">Note:</label>
	<textarea rows="3" cols="53" id="note" name="note" class="text ui-widget-content ui-corner-all"></textarea>
</form>
</script>

<script id="formErrorsTemplate" type="text/x-jquery-tmpl">
<div class="ui-widget">
	<div class="ui-state-error ui-corner-all">
		<span class="ui-icon ui-icon-alert" style="float: left; margin-right: 5px;" ></span>
		<span>{{=title}}</span>
		<div style="margin-left: 5px;">
		{{#each errors}}
			<div>
				<em>{{=message}}</em>
			</div>
		{{/each}}
		</div>
	</div>
</div>
</script>