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

<c:set var="uiid" value="${u:uiid()}"/>
<c:set var="s" value="${frd.store}"/>

<div id="${uiid}">
	<h3>${s.title}</h3>
	<table class="data">
		<tr>
			<td class="label">${l.l('Тип склада')}</td>
			<td>${empty frd.storeType ? '—' : frd.storeType.title}</td>
		</tr>
		<tr>
			<td class="label">${l.l('Статус')}</td>
			<td>${empty frd.storeStatus ? '—' : frd.storeStatus.title}</td>
		</tr>
		<tr>
			<td class="label">${l.l('Владелец')}</td>
			<td>
				<c:choose>
					<c:when test="${s.userId gt 0}">
						${l.l('Личный склад')}: <ui:user-link id="${s.userId}"/>
					</c:when>
					<c:otherwise>${l.l('Общий склад')}</c:otherwise>
				</c:choose>
			</td>
		</tr>
	</table>

	<c:if test="${not empty frd.paramList}">
		<h4 class="mt1">${l.l('Параметры')}</h4>
		<c:set var="list" value="${frd.paramList}"/>
		<c:set var="id" value="${s.id}"/>
		<c:set var="tableId" value="${u:uiid()}"/>
		<%@ include file="/WEB-INF/jspf/parameter_list.jsp"%>
	</c:if>

	<h4 class="mt1">${l.l('Остатки на складе')}
		<p:check action="/admin/plugin/sync1c/instance:importFileForm">
			<c:url var="importCsvUrl" value="/admin/plugin/sync1c/instance.do">
				<c:param name="method" value="importFileForm"/>
				<c:param name="storeId" value="${s.id}"/>
				<c:param name="userTier" value="1"/>
			</c:url>
			<button type="button" class="btn-white btn-small ml1" onclick="$$.ajax.loadContent('${importCsvUrl}')">
				<i class="ti-upload"></i> ${l.l('Загрузить CSV')}</button>
		</p:check>
	</h4>
	<c:choose>
		<c:when test="${not empty frd.balanceList}">
			<table class="data hl">
				<tr>
					<td width="100%">${l.l('Номенклатура')}</td>
					<td class="nowrap">${l.l('Количество')}</td>
					<td class="nowrap">${l.l('Зарезервировано')}</td>
				</tr>
				<c:forEach var="row" items="${frd.balanceList}">
					<tr>
						<td>${row.itemTitle}</td>
						<td class="nowrap">${row.quantity}</td>
						<td class="nowrap">${row.reserved}</td>
					</tr>
				</c:forEach>
			</table>
		</c:when>
		<c:otherwise>
			<p class="inv-empty">${l.l('Склад пуст')}</p>
		</c:otherwise>
	</c:choose>

	<h4 class="mt1">${l.l('Движения ТМЦ')}</h4>
	<table class="data hl">
		<tr>
			<td>ID</td>
			<td>${l.l('Дата операции')}</td>
			<td>${l.l('Тип операции')}</td>
			<td>${l.l('Номенклатура')}</td>
			<td>${l.l('Количество')}</td>
			<td>${l.l('Комментарий')}</td>
		</tr>
		<c:forEach var="m" items="${frd.movementList}">
			<tr>
				<td>${m.id}</td>
				<td class="nowrap">${tu.format(m.dt, 'ymdhms')}</td>
				<td>
					<c:choose>
						<c:when test="${m.type eq 'reserve'}">${l.l('Резерв')}</c:when>
						<c:when test="${m.type eq 'unreserve'}">${l.l('Снятие резерва')}</c:when>
						<c:when test="${m.type eq 'writeoff'}">${l.l('Списание')}</c:when>
						<c:when test="${m.type eq 'receipt'}">${l.l('Приход')}</c:when>
						<c:when test="${m.type eq 'return'}">${l.l('Возврат')}</c:when>
						<c:when test="${m.type eq 'transfer'}">${l.l('Перемещение')}</c:when>
						<c:when test="${m.type eq 'adjustment'}">${l.l('Корректировка')}</c:when>
						<c:otherwise>${m.type}</c:otherwise>
					</c:choose>
				</td>
				<td>${m.itemTitle}</td>
				<td>${m.quantity}</td>
				<td>${m.comment}</td>
			</tr>
		</c:forEach>
		<c:if test="${empty frd.movementList}">
			<tr><td colspan="6" class="center">${l.l('Нет данных')}</td></tr>
		</c:if>
	</table>

	<button type="button" class="btn-white mt1"
		onclick="var $f=$('#storeQueueFilter form'); if($f.length){$$.ajax.load($f,$('#storeQueueData'),{control:this});}else{$$.ajax.loadContent('/user/plugin/inventory/store.do');}">
		&larr; ${l.l('Назад')}
	</button>
</div>
