<%@ page contentType="text/html; charset=UTF-8"%><%@ include file="/WEB-INF/jspf/include/taglibs.jsp"%>

<div class="bgToolBarButtons">
	<div><img src="${pageContext.request.contextPath}/img/left.png" height="32" style="vertical-align: middle;" onclick="showBlock( 'balanceRoot', 'balanceInfo', balanceQuery );"></div>
</div>

<div class="tile">

	<bg:blockTitle title="Перераспределение средств" marginBotttom="1"/>

	<form>
		<div class="titleFont2" style="text-align: right; margin-bottom: 1rem; margin-right: 1rem;">Доступно: <fmt:formatNumber type="number" pattern="###,###,##0.00" value="${freeAmount}"/> <span class="CUR"></span></div>
		
		<c:forEach var="item" varStatus="status" items="${subContracts}">
		<div class="flexRow" style="margin: 1rem 1rem;">
			<div>Договор: <br><span class="titleFont2">${item[1]}</span></div>
			<div style="text-align: right;">
				<div style="margin: 10px 0;">Баланс\сальдо: <fmt:formatNumber type="number" pattern="###,###,##0.00" value="${item[3]}"/> <span class="CUR"></span></div>
				<div>Сумма: <input type="text" size="10" style="text-align: center;" name="${item[0]}"> <span class="CUR"></span>
				</div>
			</div>
		</div>
		<c:if test="${not status.last}"><div class="line"></div></c:if>
		</c:forEach>
		<div style="text-align: right; margin: 2rem 1rem;"><button class="btn btn-primary" onclick="return getSum( this.form );">Распределить</button></div>
	</form>
</div>

<script>
function getSum( form )
{
	let a = { ...balanceQuery, commit: 1 };
	Array.from(form.elements).forEach((input) => { a[input.name] = input.value; } );
	showBlock( 'balanceRoot', 'distributeBalance', a );
	return false;
}
</script>