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

<c:set var="uiid" value="${u:uiid()}"/>
<c:set var="inst" value="${frd.instance}"/>
<c:set var="reloadScript">$$.ajax.loadContent('${form.requestUrl}');</c:set>

<h3 class="mb1">${l.l('Ожидающие поступления')}
	<c:if test="${not empty inst}"> — ${inst.title}</c:if>
</h3>

<c:url var="backUrl" value="/admin/plugin/sync1c/instance.do"/>
<button type="button" class="btn-white mr1"
	onclick="$$.ajax.loadContent('${backUrl}')">&larr; ${l.l('Назад')}</button>

<p:check action="/admin/plugin/sync1c/instance:importApplyAll">
	<c:if test="${not empty frd.pendingList}">
		<c:url var="applyAllUrl" value="/admin/plugin/sync1c/instance.do">
			<c:param name="method" value="importApplyAll"/>
			<c:param name="instanceId" value="${inst.id}"/>
		</c:url>
		<button type="button" class="btn-white"
			onclick="$$.ajax.post('${applyAllUrl}', {control: this}).done((r) => {
				alert(r.data.count + ' ${l.l('Позиций проведено')}');
				${reloadScript}
			})">
			${l.l('Провести всё')}
		</button>
	</c:if>
</p:check>

<div id="${uiid}" class="mt1">
	<c:choose>
		<c:when test="${empty frd.pendingList}">
			<p class="hint">${l.l('Нет ожидающих поступлений')}</p>
		</c:when>
		<c:otherwise>
			<table class="data hl">
				<tr>
					<td width="120">&#160;</td>
					<td>${l.l('Монтажник')}</td>
					<td>${l.l('Номенклатура')}</td>
					<td>${l.l('Склад')}</td>
					<td width="90" class="center">${l.l('Кол-во 1С')}</td>
					<td width="90" class="center">${l.l('Кол-во ERP')}</td>
					<td width="90" class="center">${l.l('Резерв')}</td>
					<td width="90" class="center">${l.l('Разница')}</td>
					<td width="130">${l.l('Импортировано')}</td>
				</tr>
				<c:forEach var="p" items="${frd.pendingList}">
					<c:url var="applyUrl" value="/admin/plugin/sync1c/instance.do">
						<c:param name="method" value="importApply"/>
						<c:param name="id" value="${p.id}"/>
					</c:url>
					<c:url var="rejectUrl" value="/admin/plugin/sync1c/instance.do">
						<c:param name="method" value="importReject"/>
						<c:param name="id" value="${p.id}"/>
					</c:url>
					<tr>
						<td nowrap="nowrap">
							<p:check action="/admin/plugin/sync1c/instance:importApply">
								<button type="button" class="btn-white btn-small"
									onclick="$$.ajax.post('${applyUrl}', {control: this}).done(() => { ${reloadScript} })">
									${l.l('Провести')}
								</button>
							</p:check>
							<p:check action="/admin/plugin/sync1c/instance:importReject">
								<button type="button" class="btn-white btn-small"
									onclick="$$.ajax.post('${rejectUrl}', {control: this}).done(() => { ${reloadScript} })">
									${l.l('Отклонить')}
								</button>
							</p:check>
						</td>
						<td><ui:user-link id="${p.ewUserId}"/></td>
						<td>${p.itemTitle}</td>
						<td>${p.storeTitle}</td>
						<td class="center">${p.quantity}</td>
						<td class="center">${p.currentQuantity}</td>
						<td class="center">${p.currentReserved}</td>
						<td class="center">${p.diff}</td>
						<td>${tu.format(p.importedAt, 'ymd_hms')}</td>
					</tr>
				</c:forEach>
			</table>
		</c:otherwise>
	</c:choose>
</div>

<shell:title text="${l.l('Ожидающие поступления')}"/>
