{block content}
	<div class="span12">
		<div class="box-content">
			<div class="filter">
				{form filterForm, class => 'form-inline', style => 'float: left; width: 100%;'}
					<i class="icon-search fs20"></i>&nbsp;{input search, class => 'input-large'}&nbsp;&nbsp;&nbsp;&nbsp;
					{input show_critical}&nbsp;&nbsp;&nbsp;&nbsp;
					{input show_warn}&nbsp;&nbsp;&nbsp;&nbsp;
					{input show_over}&nbsp;&nbsp;&nbsp;&nbsp;
					{input id_stock_item_category}&nbsp;&nbsp;&nbsp;&nbsp;
					{input submit}
					{input reset}
					<a n:href="addItem" class="btn btn-primary" style="float: right;">
						<i class="icon-plus icon-white"></i>&nbsp;Přidat skladovou položku
					</a>
				{/form}
				<div class="clear"></div>
			</div>

			<div class="row-fluid">
				<div n:foreach="$flashes as $flash" class="alert alert-{$flash->type}">{$flash->message}</div>

				{*{if $customerForm->hasErrors()}*}
					{*<div n:foreach="$customerForm->errors as $error" class="alert alert-error">{$error}</div>*}
				{*{/if}*}

				{form stockItemForm}
					{if $form->hasErrors()}
						<div n:foreach="$form->errors as $error" class="alert alert-error">{$error}</div>
					{/if}

					<div class="clear"></div>

					<div class="span6" style="margin-left: 0;">
						<table style="margin-left: 30px; margin-bottom: 50px; margin-top: 20px;">
							<tr>
								<td style="padding-right: 10px; text-align: right;">{label title /}</td>
								<td colspan="3">{input title}</td>
							</tr>
							<tr>
								<td style="padding-right: 10px; text-align: right;">{label code /}</td>
								<td>{input code, class => 'input-medium'}</td>
								<td style="padding: 0 10px 0 20px; text-align: right;">{label unit /}</td>
								<td>{input unit, class => 'input-mini'}</td>
							</tr>
							<tr>
								<td style="padding-right: 10px; text-align: right;">{label location /}</td>
								<td colspan="3">{input location}</td>
							</tr>
							<tr>
								<td style="padding-right: 10px; text-align: right;">{label id_stock_item_category /}</td>
								<td colspan="3">{input id_stock_item_category}</td>
							</tr>
						</table>
					</div>

					<div class="span6">
						<table style="margin-left: 30px; margin-bottom: 50px; margin-top: 20px;">
							<tr>
								<td style="padding-right: 10px; text-align: right;">Skladem</td>
								<td>{$stockItem->in_stock} {\App\Models\StockItemModel::$UNIT_LIST[$stockItem->unit]}</td>
								<td></td>
								<td style="padding-right: 10px; text-align: right;">Zásoba</td>
								<td>
									<div class="limit-box limit-box-small {if $stockItem->stock_level === 'critical'}bg-critical{/if}"></div>
									<div class="limit-box limit-box-small {if $stockItem->stock_level === 'warn'}bg-warn{/if}"></div>
									<div class="limit-box limit-box-small {if $stockItem->stock_level === 'ideal'}bg-ideal{/if}"></div>
									<div class="limit-box limit-box-small {if $stockItem->stock_level === 'over'}bg-over{/if}"></div>
								</td>
							</tr>
							<tr>
								<td colspan="5">&nbsp;</td>
							</tr>
							<tr>
								<td style="padding-right: 10px; text-align: right;">Limity</td>
								<td>
									<div class="limit-box">
										<span class="label bg-critical">Kritický</span>
										<span class="values">&lt;0 - {input limit_critical}></span>
									</div>
								</td>
								<td>
									<div class="limit-box">
										<span class="label bg-warn">Varovný</span>
										<span class="values">(<span data-ref="limit_critical">{$form['limit_critical']->getValue()}</span> - {input limit_warn}&gt;</span>
									</div>
								</td>
								<td>
									<div class="limit-box">
										<span class="label bg-ideal">Ideální</span>
										<span class="values">(<span data-ref="limit_warn">{$form['limit_warn']->getValue()}</span> - {input limit_ideal}&gt;</span>
									</div>
								</td>
								<td>
									<div class="limit-box">
										<span class="label bg-over">Příliš</span>
										<span class="values">(<span data-ref="limit_ideal">{$form['limit_ideal']->getValue()}</span> - &#8734;)</span>
									</div>
								</td>
							</tr>
							{*<tr>*}
								{*<td style="padding-right: 10px; text-align: right;">{label location /}</td>*}
								{*<td colspan="3">{input location}</td>*}
							{*</tr>*}
						</table>
					</div>


					<div class="clear" style="text-align: center; padding-top: 10px;">
						{input submit}
					</div>
				{/form}
			</div>
			<hr />
			<h2>Skladové pohyby
				<a n:href="showStockItemMoveModal! 'idStockItem' => $stockItem->id" class="ajax" style="margin-left: 20px; font-size: 0.8em; font-weight: normal;"><i class="icon-plus-sign"/> skladový pohyb</a>
			</h2>
			{if ($stockItemMoveList && count($stockItemMoveList))}
				<table class="table" style="margin-top: 30px;">
					<thead>
						<tr>
							<th>Datum</th>
							<th>Množství</th>
							<th>Dodavatel</th>
							<th>Cena za {\App\Models\StockItemModel::$UNIT_LIST[$stockItem->unit]}</th>
							<th>Poznámka</th>
							<th>Uživatel</th>
							<th></th>
						</tr>
					</thead>
					<tbody>
						<tr n:foreach="$stockItemMoveList as $stockItemMove">
							<td><a n:href="showStockItemMoveModal! 'idStockItem' => $stockItem->id, 'idStockItemMove' => $stockItemMove->id" class="ajax">{$stockItemMove->created_at|date:'d.m.Y'}</a></td>
							<td><a n:href="showStockItemMoveModal! 'idStockItem' => $stockItem->id, 'idStockItemMove' => $stockItemMove->id" class="ajax">{$stockItemMove->amount} {\App\Models\StockItemModel::$UNIT_LIST[$stockItem->unit]}</a></td>
							<td>{$stockItemMove->supplier_title}</td>
							<td>{$stockItemMove->price_unit} Kč/{\App\Models\StockItemModel::$UNIT_LIST[$stockItem->unit]}</td>
							<td class="ellipsis" title="{$stockItemMove->note}">{$stockItemMove->note}</td>
							<td>{$stockItemMove->user_fullname}</td>
							<td>
								<a n:href="showStockItemMoveModal! 'idStockItem' => $stockItem->id, 'idStockItemMove' => $stockItemMove->id" class="ajax"><i class="icon-pencil"></i></a>
							</td>
						</tr>
					</tbody>
				</table>
			{/if}
		</div>
	</div>

{snippet stockItemMoveModal}
	{if isset($stockItemMoveModal)}
		{include '@stockItemMoveForm.latte'}
	{/if}
{/snippet}

<script>
    $(function() {
		$('input[name="limit_critical"], input[name="limit_warn"], input[name="limit_ideal"]').on('input', function() {
		    var inputName = $(this).attr('name');
		    $('[data-ref="' + inputName + '"]').html($(this).val());
		})
    });
</script>
