{block content}
	<div class="span12">
		<div class="box-content">
			<div class="filter">
				{form filterForm, class => 'form-inline', style => 'float: left;'}
					<i class="icon-search fs20"></i>&nbsp;{input search, class => 'input-large'}&nbsp;&nbsp;
					<i class="icon-truck fs20"></i>&nbsp;{input driver, class => 'input-medium'}&nbsp;&nbsp;
					<i class="icon-user fs20"></i>&nbsp;{input expedition, class => 'input-medium'}&nbsp;&nbsp;{input submit}
				{/form}
				<table style="float: right;">
					<tr>
						<td rowspan="2" style="padding-right: 8px;">
							{if $showBackButton !== TRUE}
								<a href="#" class="btn btn-warning disabled" style="color: #000000; font-size: 40px;">
									&#9666;
								</a>
							{else}
								<a n:href="prevWeek!" class="btn btn-warning" style="color: #000000; font-size: 40px;">
									&#9666;
								</a>
							{/if}
						</td>

						<td style="font-weight: bold; font-size: 12px;">
							{$date|date:'d.m.Y'}
						</td>

						<td rowspan="2" style="padding-left: 8px;">
							{if $showNextButton !== TRUE}
								<a href="#" class="btn btn-warning" style="color: #000000; vertical-align: top; font-size: 40px;">
									&#9656;
								</a>
							{else}
								<a n:href="nextWeek!" class="btn btn-warning" style="color: #000000; vertical-align: top; font-size: 40px;">
									&#9656;
								</a>
							{/if}
						</td>
					</tr>

					<tr>
						 <td style="font-weight: bold; font-size: 12px;">
						 	{$date->modifyClone('+ 6 days')|date:'d.m.Y'}
						 </td>
					</tr>
				</table>

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

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

			<div class="alert alert-info alert-no-margin" n:if="$customersSum <= 0">
				Nic nebylo nalezeno, zkuste jiné nastavení filtru.
			</div>

			<table class="table table-hover table-order-list" style="border-collapse: collapse;" n:snippet="orderList" n:if="$customersSum > 0">
				<thead>
					<tr>
						<th style="width: 25px;"></th>
						{* <th>Id&nbsp;<a n:href='this, orderBy => id, orderWay => asc' class="order"><i class='icon-circle-arrow-up'></i></a>&nbsp;<a n:href='this, orderBy => id, orderWay => desc' class="order"><i class='icon-circle-arrow-down'></i></a></th> *}
						<th>Platba&nbsp;<a n:href='this, orderBy => payment, orderWay => asc' class="order"><i class='icon-circle-arrow-up'></i></a>&nbsp;<a n:href='this, orderBy => payment, orderWay => desc' class="order"><i class='icon-circle-arrow-down'></i></a></th>
						<th>Název&nbsp;<a n:href='this, orderBy => name, orderWay => asc' class="order"><i class='icon-circle-arrow-up'></i></a>&nbsp;<a n:href='this, orderBy => name, orderWay => desc' class="order"><i class='icon-circle-arrow-down'></i></a></th>
						<th>Jméno&nbsp;/&nbsp;Firma&nbsp;<a n:href='this, orderBy => contact_name, orderWay => asc' class="order"><i class='icon-circle-arrow-up'></i></a>&nbsp;<a n:href='this, orderBy => contact_name, orderWay => desc' class="order"><i class='icon-circle-arrow-down'></i></a></th>
						<th>Město&nbsp;<a n:href='this, orderBy => city, orderWay => asc' class="order"><i class='icon-circle-arrow-up'></i></a>&nbsp;<a n:href='this, orderBy => city, orderWay => desc' class="order"><i class='icon-circle-arrow-down'></i></a></th>
						<th>Řidič&nbsp;<a n:href='this, orderBy => nameDriver, orderWay => asc' class="order"><i class='icon-circle-arrow-up'></i></a>&nbsp;<a n:href='this, orderBy => nameDriver, orderWay => desc' class="order"><i class='icon-circle-arrow-down'></i></a></th>
						<th>Expedice&nbsp;<a n:href='this, orderBy => nameExpedition, orderWay => asc' class="order"><i class='icon-circle-arrow-up'></i></a>&nbsp;<a n:href='this, orderBy => nameExpedition, orderWay => desc' class="order"><i class='icon-circle-arrow-down'></i></a></th>
						<th class="type">E</th>
						<th class="type">EBP</th>
						<th class="type">K</th>
						<th class="type">KBP</th>
						<th class="type">P</th>
					</tr>
				</thead>

				<tbody n:inner-foreach="$customers as $detail">
					{var $customerOrderSum = (isset($customerOrders[$detail->id]) ? $customerOrders[$detail->id] : FALSE)}
					{var $customerOrderSumBg = ($customerOrderSum !== FALSE && ($customerOrderSum->order_e_amount > 0 || $customerOrderSum->order_ebp_amount > 0 || $customerOrderSum->order_k_amount > 0 || $customerOrderSum->order_kbp_amount > 0 || $customerOrderSum->order_p_amount > 0))}

					<tr n:class="$customerOrderSumBg === TRUE ? bg-green" data-href="{link //showOrderModal!}" data-id="{$detail->id}">
						<td n:inner-if="$customerOrderSum !== FALSE">
							<input type="checkbox" name="paid" class="order-paid-input" data-no-uniform="true" data-href="{plink changePaid!}" data-customer="{$detail->id}" data-year="{$presenter->getParameter('year')}" data-week="{$presenter->getParameter('week')}"{if $customerOrderSum->paid == TRUE} checked="checked"{/if}>
						</td>
						{* <td class="order-form-modal-line">
							{$detail->id}
						</td> *}
						<td class="order-form-modal-line">
							{if isset($paymentLetters[$detail->payment])}{$paymentLetters[$detail->payment]}{/if}
						</td>
						<td class="order-form-modal-line" style="font-weight: bold;">
							{$detail->name}
						</td>
						<td class="order-form-modal-line">
							{$detail->contact_name}
						</td>
						<td class="order-form-modal-line">
							{$detail->city}
						</td>
						<td class="order-form-modal-line">
							<i class="icon-truck"></i>&nbsp;{$detail->nameDriver}
						</td>
						<td class="order-form-modal-line">
							<i class="icon-user"></i>&nbsp;{$detail->nameExpedition}
						</td>
						<td class="order-form-modal-line type">
							{$customerOrderSum !== FALSE ? $customerOrderSum->order_e_amount : 0}
						</td>
						<td class="order-form-modal-line type">
							{$customerOrderSum !== FALSE ? $customerOrderSum->order_ebp_amount : 0}
						</td>
						<td class="order-form-modal-line type">
							{$customerOrderSum !== FALSE ? $customerOrderSum->order_k_amount : 0}
						</td>
						<td class="order-form-modal-line type">
							{$customerOrderSum !== FALSE ? $customerOrderSum->order_kbp_amount : 0}
						</td>
						<td class="order-form-modal-line type">
							{$customerOrderSum !== FALSE ? $customerOrderSum->order_p_amount : 0}
						</td>
					</tr>
				</tbody>
			</table>

			<table style="width: 100%;">
				<tr>
					<td style="width: 85%;">
						{control VisualPaginator}
					</td>
					<td></td>
				</tr>
			</table>
		</div>
	</div>

	{snippet customerOrderModal}
		{if isset($orderModal->customer)}
			{include '@orderForm.latte'}
		{elseif isset($orderModal) && $orderModal === FALSE} {* After ajax remove backdrop *}
			<script type="text/javascript">
				$(document).ready(function() {
					$('.modal-backdrop').remove();
				});
			</script>
		{/if}
	{/snippet}

	<script type="text/javascript">
		$(document).ready(function() {

			$('.table-order-list .order-form-modal-line').on('click', function() {
				var $this = $(this),
					$tr = $this.parents('tr');

				$.nette.ajax({
					url: $tr.data('href'),
					method: 'GET',
					data: {
						customer: $tr.data('id')
					}
				});
			});

			$('.order-paid-input').on('change', function() {
				var $this = $(this);

				$.nette.ajax({
					url: $this.data('href'),
					method: 'GET',
					data: {
						customer: $this.data('customer'),
						year: $this.data('year'),
						week: $this.data('week'),
						paid: ($this.prop('checked') == true ? 1 : 0)
					}
				});
			});

		});
	</script>
