{var $dayNames = array(
	1 => 'Pondělí',
	2 => 'Úterý',
	3 => 'Středa',
	4 => 'Čtvrtek',
	5 => 'Pátek',
	6 => 'Sobota',
	7 => 'Neděle',
)}

{var $isIndividualDefault = (bool) ($orderModal->customer->delivery_type == \App\Models\CustomerModel::DELIVERY_TYPE_IND)}
{var $isIndividual = array(
	'default' => $isIndividualDefault,
	'days' => array(
		1 => $isIndividualDefault,
		2 => $isIndividualDefault,
		3 => $isIndividualDefault,
		4 => $isIndividualDefault,
		5 => $isIndividualDefault,
		6 => $isIndividualDefault,
		7 => $isIndividualDefault,
	),
	'daysb' => array(
		1 => $isIndividualDefault,
		2 => $isIndividualDefault,
		3 => $isIndividualDefault,
		4 => $isIndividualDefault,
		5 => $isIndividualDefault,
		6 => $isIndividualDefault,
		7 => $isIndividualDefault,
	),
)}

{form orderForm}

	{* Set default values *}
	{? $orderModal->orderForm['date']->setDefaultValue($orderModal->date->format('Y-m-d'))}
	{? $orderModal->orderForm['id_customer']->setDefaultValue($orderModal->customer->id)}

	{for $day = 1; $day <= 5; $day++}

		{if isset($orderModal->orders[$orderModal->customer->id][$orderModal->date->modifyClone("+ $day days")->format('j')])}

			{var $oneOrder = $orderModal->orders[$orderModal->customer->id][$orderModal->date->modifyClone("+ $day days")->format('j')]}
			{var $isIndividual['days'][$day] = (bool) $oneOrder->individual}
			{var $isIndividual['daysb'][$day] = (bool) $oneOrder->individual_b}

			{? $orderModal->orderForm['days'][$day]['type_1_amount']->setDefaultValue($oneOrder->type_1_amount)}
			{? $orderModal->orderForm['days'][$day]['type_2_amount']->setDefaultValue($oneOrder->type_2_amount)}
			{? $orderModal->orderForm['days'][$day]['type_3_amount']->setDefaultValue($oneOrder->type_3_amount)}
			{? $orderModal->orderForm['days'][$day]['type_4_amount']->setDefaultValue($oneOrder->type_4_amount)}
			{? $orderModal->orderForm['days'][$day]['type_5_amount']->setDefaultValue($oneOrder->type_5_amount)}
			{? $orderModal->orderForm['days'][$day]['type_6_amount']->setDefaultValue($oneOrder->type_6_amount)}
			{? $orderModal->orderForm['days'][$day]['type_7_amount']->setDefaultValue($oneOrder->type_7_amount)}
			{? $orderModal->orderForm['days'][$day]['type_8_amount']->setDefaultValue($oneOrder->type_8_amount)}

			{? $orderModal->orderForm['days'][$day]['order_e_amount']->setDefaultValue($oneOrder->order_e_amount)}
			{? $orderModal->orderForm['days'][$day]['order_ebp_amount']->setDefaultValue($oneOrder->order_ebp_amount)}
			{? $orderModal->orderForm['days'][$day]['order_k_amount']->setDefaultValue($oneOrder->order_k_amount)}
			{? $orderModal->orderForm['days'][$day]['order_kbp_amount']->setDefaultValue($oneOrder->order_kbp_amount)}
			{? $orderModal->orderForm['days'][$day]['order_p_amount']->setDefaultValue($oneOrder->order_p_amount)}

			{? $orderModal->orderForm['days'][$day]['individual']->setDefaultValue($isIndividual['days'][$day])}

			{? $orderModal->orderForm['days'][$day]['type_1b_amount']->setDefaultValue($oneOrder->type_1b_amount)}
			{? $orderModal->orderForm['days'][$day]['type_2b_amount']->setDefaultValue($oneOrder->type_2b_amount)}
			{? $orderModal->orderForm['days'][$day]['type_3b_amount']->setDefaultValue($oneOrder->type_3b_amount)}
			{? $orderModal->orderForm['days'][$day]['type_4b_amount']->setDefaultValue($oneOrder->type_4b_amount)}
			{? $orderModal->orderForm['days'][$day]['type_5b_amount']->setDefaultValue($oneOrder->type_5b_amount)}
			{? $orderModal->orderForm['days'][$day]['type_6b_amount']->setDefaultValue($oneOrder->type_6b_amount)}
			{? $orderModal->orderForm['days'][$day]['type_7b_amount']->setDefaultValue($oneOrder->type_7b_amount)}
			{? $orderModal->orderForm['days'][$day]['type_8b_amount']->setDefaultValue($oneOrder->type_8b_amount)}

			{? $orderModal->orderForm['days'][$day]['order_e_amount_b']->setDefaultValue($oneOrder->order_e_amount_b)}
			{? $orderModal->orderForm['days'][$day]['order_ebp_amount_b']->setDefaultValue($oneOrder->order_ebp_amount_b)}
			{? $orderModal->orderForm['days'][$day]['order_k_amount_b']->setDefaultValue($oneOrder->order_k_amount_b)}
			{? $orderModal->orderForm['days'][$day]['order_kbp_amount_b']->setDefaultValue($oneOrder->order_kbp_amount_b)}
			{? $orderModal->orderForm['days'][$day]['order_p_amount_b']->setDefaultValue($oneOrder->order_p_amount_b)}

			{? $orderModal->orderForm['days'][$day]['individual_b']->setDefaultValue($isIndividual['daysb'][$day])}

		{else}

			{? $orderModal->orderForm['days'][$day]['type_1_amount']->setDefaultValue(0)}
			{? $orderModal->orderForm['days'][$day]['type_2_amount']->setDefaultValue(0)}
			{? $orderModal->orderForm['days'][$day]['type_3_amount']->setDefaultValue(0)}
			{? $orderModal->orderForm['days'][$day]['type_4_amount']->setDefaultValue(0)}
			{? $orderModal->orderForm['days'][$day]['type_5_amount']->setDefaultValue(0)}
			{? $orderModal->orderForm['days'][$day]['type_6_amount']->setDefaultValue(0)}
			{? $orderModal->orderForm['days'][$day]['type_7_amount']->setDefaultValue(0)}
			{? $orderModal->orderForm['days'][$day]['type_8_amount']->setDefaultValue(0)}

			{? $orderModal->orderForm['days'][$day]['order_e_amount']->setDefaultValue(0)}
			{? $orderModal->orderForm['days'][$day]['order_ebp_amount']->setDefaultValue(0)}
			{? $orderModal->orderForm['days'][$day]['order_k_amount']->setDefaultValue(0)}
			{? $orderModal->orderForm['days'][$day]['order_kbp_amount']->setDefaultValue(0)}
			{? $orderModal->orderForm['days'][$day]['order_p_amount']->setDefaultValue(0)}

			{? $orderModal->orderForm['days'][$day]['individual']->setDefaultValue($isIndividual['days'][$day])}

			{? $orderModal->orderForm['days'][$day]['type_1b_amount']->setDefaultValue(0)}
			{? $orderModal->orderForm['days'][$day]['type_2b_amount']->setDefaultValue(0)}
			{? $orderModal->orderForm['days'][$day]['type_3b_amount']->setDefaultValue(0)}
			{? $orderModal->orderForm['days'][$day]['type_4b_amount']->setDefaultValue(0)}
			{? $orderModal->orderForm['days'][$day]['type_5b_amount']->setDefaultValue(0)}
			{? $orderModal->orderForm['days'][$day]['type_6b_amount']->setDefaultValue(0)}
			{? $orderModal->orderForm['days'][$day]['type_7b_amount']->setDefaultValue(0)}
			{? $orderModal->orderForm['days'][$day]['type_8b_amount']->setDefaultValue(0)}

			{? $orderModal->orderForm['days'][$day]['order_e_amount_b']->setDefaultValue(0)}
			{? $orderModal->orderForm['days'][$day]['order_ebp_amount_b']->setDefaultValue(0)}
			{? $orderModal->orderForm['days'][$day]['order_k_amount_b']->setDefaultValue(0)}
			{? $orderModal->orderForm['days'][$day]['order_kbp_amount_b']->setDefaultValue(0)}
			{? $orderModal->orderForm['days'][$day]['order_p_amount_b']->setDefaultValue(0)}

			{? $orderModal->orderForm['days'][$day]['individual_b']->setDefaultValue($isIndividual['daysb'][$day])}

		{/if}

	{/for}

	<div id="customerOrderModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="customerOrderModalLabel">
		<div class="modal-header">
			<h3 id="customerOrderModalLabel">
				{$orderModal->customer->id}{if $orderModal->customer->name} - {$orderModal->customer->name}{/if}{if $orderModal->customer->contact_name} - {$orderModal->customer->contact_name}{/if}
			</h3>
		</div>

		<div class="modal-body">
			<table class="order-detail" style="text-align: center; margin: 20px auto;">
				<thead>
					<tr>
						<th class="space-right"></th>
						<th></th>
						<th>&#9312;</th>
						<th>&#9313;</th>
						<th>&#9314;</th>
						<th>&#9315;</th>
						<th>&#9316;</th>
						<th>&#9317;</th>
						<th>&#9318;</th>
						<th class="space-right" style="border-right: 1px solid #000000;">&#9319;</th>
						<th class="space-left">E</th>
						<th>EBP</th>
						<th>K</th>
						<th>KBP</th>
						<th class="space-right" style="border-right: 1px solid #000000;">Jen P</th>
						<th class="space-left">IND</th>
					</tr>
				</thead>

				<tbody>
					{for $day = 1; $day <= 5; $day++}
						<tr class="{if $day % 2 == 0}rowEven{else}rowOdd{/if} withPadding">
							<td class="space-right" rowspan="2">
								{$dayNames[$day]}
							</td>

							<td><strong>&#9398;</strong></td>
							<td class="type-food">
								<div class="input-append spinner">
									{input days-$day-type_1_amount, data-min => 0, data-step => 1}
									<div class="add-on">
										<a href="#" class="spin-up no-decoration" data-spin="up"><i class="icon-sort-up"></i></a>
										<a href="#" class="spin-down no-decoration" data-spin="down"><i class="icon-sort-down"></i></a>
									</div>
								</div>
							</td>

							<td class="type-food">
								<div class="input-append spinner">
									{input days-$day-type_2_amount, data-min => 0, data-step => 1}
									<div class="add-on">
										<a href="#" class="spin-up no-decoration" data-spin="up"><i class="icon-sort-up"></i></a>
										<a href="#" class="spin-down no-decoration" data-spin="down"><i class="icon-sort-down"></i></a>
									</div>
								</div>
							</td>

							<td class="type-food">
								<div class="input-append spinner">
									{input days-$day-type_3_amount, data-min => 0, data-step => 1}
									<div class="add-on">
										<a href="#" class="spin-up no-decoration" data-spin="up"><i class="icon-sort-up"></i></a>
										<a href="#" class="spin-down no-decoration" data-spin="down"><i class="icon-sort-down"></i></a>
									</div>
								</div>
							</td>

							<td class="type-food">
								<div class="input-append spinner">
									{input days-$day-type_4_amount, data-min => 0, data-step => 1}
									<div class="add-on">
										<a href="#" class="spin-up no-decoration" data-spin="up"><i class="icon-sort-up"></i></a>
										<a href="#" class="spin-down no-decoration" data-spin="down"><i class="icon-sort-down"></i></a>
									</div>
								</div>
							</td>

							<td class="type-food">
								<div class="input-append spinner">
									{input days-$day-type_5_amount, data-min => 0, data-step => 1}
									<div class="add-on">
										<a href="#" class="spin-up no-decoration" data-spin="up"><i class="icon-sort-up"></i></a>
										<a href="#" class="spin-down no-decoration" data-spin="down"><i class="icon-sort-down"></i></a>
									</div>
								</div>
							</td>

							<td class="type-food">
								<div class="input-append spinner">
									{input days-$day-type_6_amount, data-min => 0, data-step => 1}
									<div class="add-on">
										<a href="#" class="spin-up no-decoration" data-spin="up"><i class="icon-sort-up"></i></a>
										<a href="#" class="spin-down no-decoration" data-spin="down"><i class="icon-sort-down"></i></a>
									</div>
								</div>
							</td>

							<td class="type-food">
								<div class="input-append spinner">
									{input days-$day-type_7_amount, data-min => 0, data-step => 1}
									<div class="add-on">
										<a href="#" class="spin-up no-decoration" data-spin="up"><i class="icon-sort-up"></i></a>
										<a href="#" class="spin-down no-decoration" data-spin="down"><i class="icon-sort-down"></i></a>
									</div>
								</div>
							</td>

							<td class="type-food space-right" style="border-right: 1px solid #000000;">
								<div class="input-append spinner">
									{input days-$day-type_8_amount, data-min => 0, data-step => 1}
									<div class="add-on">
										<a href="#" class="spin-up no-decoration" data-spin="up"><i class="icon-sort-up"></i></a>
										<a href="#" class="spin-down no-decoration" data-spin="down"><i class="icon-sort-down"></i></a>
									</div>
								</div>
							</td>

							<td n:class="$orderModal->customer->delivery_type === \App\Models\CustomerModel::DELIVERY_TYPE_E ? delivery-food-total, delivery-food, space-left">
								<div class="input-append spinner">
									{if $isIndividual['days'][$day]}
										{input days-$day-order_e_amount, data-min => 0, data-step => 1}
									{else}
										{input days-$day-order_e_amount, data-min => 0, data-step => 1, readonly => readonly}
									{/if}
									<div class="add-on">
										<a href="#" class="spin-up no-decoration" data-spin="up"><i class="icon-sort-up"></i></a>
										<a href="#" class="spin-down no-decoration" data-spin="down"><i class="icon-sort-down"></i></a>
									</div>
								</div>
							</td>

							<td n:class="$orderModal->customer->delivery_type === \App\Models\CustomerModel::DELIVERY_TYPE_EBP ? delivery-food-total, delivery-food">
								<div class="input-append spinner">
									{if $isIndividual['days'][$day]}
										{input days-$day-order_ebp_amount, data-min => 0, data-step => 1}
									{else}
										{input days-$day-order_ebp_amount, data-min => 0, data-step => 1, readonly => readonly}
									{/if}
									<div class="add-on">
										<a href="#" class="spin-up no-decoration" data-spin="up"><i class="icon-sort-up"></i></a>
										<a href="#" class="spin-down no-decoration" data-spin="down"><i class="icon-sort-down"></i></a>
									</div>
								</div>
							</td>

							<td n:class="$orderModal->customer->delivery_type === \App\Models\CustomerModel::DELIVERY_TYPE_K ? delivery-food-total, delivery-food">
								<div class="input-append spinner">
									{if $isIndividual['days'][$day]}
										{input days-$day-order_k_amount, data-min => 0, data-step => 1}
									{else}
										{input days-$day-order_k_amount, data-min => 0, data-step => 1, readonly => readonly}
									{/if}
									<div class="add-on">
										<a href="#" class="spin-up no-decoration" data-spin="up"><i class="icon-sort-up"></i></a>
										<a href="#" class="spin-down no-decoration" data-spin="down"><i class="icon-sort-down"></i></a>
									</div>
								</div>
							</td>

							<td n:class="$orderModal->customer->delivery_type === \App\Models\CustomerModel::DELIVERY_TYPE_KBP ? delivery-food-total, delivery-food">
								<div class="input-append spinner">
									{if $isIndividual['days'][$day]}
										{input days-$day-order_kbp_amount, data-min => 0, data-step => 1}
									{else}
										{input days-$day-order_kbp_amount, data-min => 0, data-step => 1, readonly => readonly}
									{/if}
									<div class="add-on">
										<a href="#" class="spin-up no-decoration" data-spin="up"><i class="icon-sort-up"></i></a>
										<a href="#" class="spin-down no-decoration" data-spin="down"><i class="icon-sort-down"></i></a>
									</div>
								</div>
							</td>

							<td n:class="$orderModal->customer->delivery_type === \App\Models\CustomerModel::DELIVERY_TYPE_P ? delivery-food-total, delivery-food, space-right" style="border-right: 1px solid #000000;">
								<div class="input-append spinner">
									{if $isIndividual['days'][$day]}
										{input days-$day-order_p_amount, data-min => 0, data-step => 1}
									{else}
										{input days-$day-order_p_amount, data-min => 0, data-step => 1, readonly => readonly}
									{/if}
									<div class="add-on">
										<a href="#" class="spin-up no-decoration" data-spin="up"><i class="icon-sort-up"></i></a>
										<a href="#" class="spin-down no-decoration" data-spin="down"><i class="icon-sort-down"></i></a>
									</div>
								</div>
							</td>

							<td class="delivery-food-individual space-left">
								{input days-$day-individual}
							</td>
						</tr>


						<tr class="{if $day % 2 == 0}rowEven{else}rowOdd{/if}">
							<td><strong>&#9399;</strong></td>

							<td class="type-food">
								<div class="input-append spinner">
									{input days-$day-type_1b_amount, data-min => 0, data-step => 1}
									<div class="add-on">
										<a href="#" class="spin-up no-decoration" data-spin="up"><i class="icon-sort-up"></i></a>
										<a href="#" class="spin-down no-decoration" data-spin="down"><i class="icon-sort-down"></i></a>
									</div>
								</div>
							</td>

							<td class="type-food">
								<div class="input-append spinner">
									{input days-$day-type_2b_amount, data-min => 0, data-step => 1}
									<div class="add-on">
										<a href="#" class="spin-up no-decoration" data-spin="up"><i class="icon-sort-up"></i></a>
										<a href="#" class="spin-down no-decoration" data-spin="down"><i class="icon-sort-down"></i></a>
									</div>
								</div>
							</td>

							<td class="type-food">
								<div class="input-append spinner">
									{input days-$day-type_3b_amount, data-min => 0, data-step => 1}
									<div class="add-on">
										<a href="#" class="spin-up no-decoration" data-spin="up"><i class="icon-sort-up"></i></a>
										<a href="#" class="spin-down no-decoration" data-spin="down"><i class="icon-sort-down"></i></a>
									</div>
								</div>
							</td>

							<td class="type-food">
								<div class="input-append spinner">
									{input days-$day-type_4b_amount, data-min => 0, data-step => 1}
									<div class="add-on">
										<a href="#" class="spin-up no-decoration" data-spin="up"><i class="icon-sort-up"></i></a>
										<a href="#" class="spin-down no-decoration" data-spin="down"><i class="icon-sort-down"></i></a>
									</div>
								</div>
							</td>

							<td class="type-food">
								<div class="input-append spinner">
									{input days-$day-type_5b_amount, data-min => 0, data-step => 1}
									<div class="add-on">
										<a href="#" class="spin-up no-decoration" data-spin="up"><i class="icon-sort-up"></i></a>
										<a href="#" class="spin-down no-decoration" data-spin="down"><i class="icon-sort-down"></i></a>
									</div>
								</div>
							</td>

							<td class="type-food">
								<div class="input-append spinner">
									{input days-$day-type_6b_amount, data-min => 0, data-step => 1}
									<div class="add-on">
										<a href="#" class="spin-up no-decoration" data-spin="up"><i class="icon-sort-up"></i></a>
										<a href="#" class="spin-down no-decoration" data-spin="down"><i class="icon-sort-down"></i></a>
									</div>
								</div>
							</td>

							<td class="type-food">
								<div class="input-append spinner">
									{input days-$day-type_7b_amount, data-min => 0, data-step => 1}
									<div class="add-on">
										<a href="#" class="spin-up no-decoration" data-spin="up"><i class="icon-sort-up"></i></a>
										<a href="#" class="spin-down no-decoration" data-spin="down"><i class="icon-sort-down"></i></a>
									</div>
								</div>
							</td>

							<td class="type-food space-right" style="border-right: 1px solid #000000;">
								<div class="input-append spinner">
									{input days-$day-type_8b_amount, data-min => 0, data-step => 1}
									<div class="add-on">
										<a href="#" class="spin-up no-decoration" data-spin="up"><i class="icon-sort-up"></i></a>
										<a href="#" class="spin-down no-decoration" data-spin="down"><i class="icon-sort-down"></i></a>
									</div>
								</div>
							</td>

							<td n:class="$orderModal->customer->delivery_type === \App\Models\CustomerModel::DELIVERY_TYPE_E ? delivery-food-total, delivery-food, space-left">
								<div class="input-append spinner">
									{if $isIndividual['daysb'][$day]}
										{input days-$day-order_e_amount_b, data-min => 0, data-step => 1}
									{else}
										{input days-$day-order_e_amount_b, data-min => 0, data-step => 1, readonly => readonly}
									{/if}
									<div class="add-on">
										<a href="#" class="spin-up no-decoration" data-spin="up"><i class="icon-sort-up"></i></a>
										<a href="#" class="spin-down no-decoration" data-spin="down"><i class="icon-sort-down"></i></a>
									</div>
								</div>
							</td>

							<td n:class="$orderModal->customer->delivery_type === \App\Models\CustomerModel::DELIVERY_TYPE_EBP ? delivery-food-total, delivery-food">
								<div class="input-append spinner">
									{if $isIndividual['daysb'][$day]}
										{input days-$day-order_ebp_amount_b, data-min => 0, data-step => 1}
									{else}
										{input days-$day-order_ebp_amount_b, data-min => 0, data-step => 1, readonly => readonly}
									{/if}
									<div class="add-on">
										<a href="#" class="spin-up no-decoration" data-spin="up"><i class="icon-sort-up"></i></a>
										<a href="#" class="spin-down no-decoration" data-spin="down"><i class="icon-sort-down"></i></a>
									</div>
								</div>
							</td>

							<td n:class="$orderModal->customer->delivery_type === \App\Models\CustomerModel::DELIVERY_TYPE_K ? delivery-food-total, delivery-food">
								<div class="input-append spinner">
									{if $isIndividual['daysb'][$day]}
										{input days-$day-order_k_amount_b, data-min => 0, data-step => 1}
									{else}
										{input days-$day-order_k_amount_b, data-min => 0, data-step => 1, readonly => readonly}
									{/if}
									<div class="add-on">
										<a href="#" class="spin-up no-decoration" data-spin="up"><i class="icon-sort-up"></i></a>
										<a href="#" class="spin-down no-decoration" data-spin="down"><i class="icon-sort-down"></i></a>
									</div>
								</div>
							</td>

							<td n:class="$orderModal->customer->delivery_type === \App\Models\CustomerModel::DELIVERY_TYPE_KBP ? delivery-food-total, delivery-food">
								<div class="input-append spinner">
									{if $isIndividual['daysb'][$day]}
										{input days-$day-order_kbp_amount_b, data-min => 0, data-step => 1}
									{else}
										{input days-$day-order_kbp_amount_b, data-min => 0, data-step => 1, readonly => readonly}
									{/if}
									<div class="add-on">
										<a href="#" class="spin-up no-decoration" data-spin="up"><i class="icon-sort-up"></i></a>
										<a href="#" class="spin-down no-decoration" data-spin="down"><i class="icon-sort-down"></i></a>
									</div>
								</div>
							</td>

							<td n:class="$orderModal->customer->delivery_type === \App\Models\CustomerModel::DELIVERY_TYPE_P ? delivery-food-total, delivery-food, space-right" style="border-right: 1px solid #000000;">
								<div class="input-append spinner">
									{if $isIndividual['daysb'][$day]}
										{input days-$day-order_p_amount_b, data-min => 0, data-step => 1}
									{else}
										{input days-$day-order_p_amount_b, data-min => 0, data-step => 1, readonly => readonly}
									{/if}
									<div class="add-on">
										<a href="#" class="spin-up no-decoration" data-spin="up"><i class="icon-sort-up"></i></a>
										<a href="#" class="spin-down no-decoration" data-spin="down"><i class="icon-sort-down"></i></a>
									</div>
								</div>
							</td>

							<td class="delivery-food-individual space-left">
								{input days-$day-individual_b}
							</td>
						</tr>
					{/for}
				</tbody>
			</table>
		</div>

		<div class="modal-footer">
			{input submit}
			<button class="btn" data-dismiss="modal" aria-hidden="true">Zavřít</button>
		</div>
	</div>
{/form}

<script type="text/javascript">
	$(document).ready(function() {
		$('#customerOrderModal').modal({
			keyboard: false,
			backdrop: 'static',
			show: true
		});

		// Button spinner + counter
		$('#customerOrderModal .order-detail .spinner').spinner('changed', function(event, newVal, oldVal) {
			countDeliveryFoodTotal($(this));
		});

		// Mouse spinner
		$('.spinner input').on('mouseover', function() {
			var $this = $(this);

			if ($this.attr('disabled') === 'disabled' || $this.attr('readonly') === 'readonly') {
				return;
			}

			$this.on('mousewheel DOMMouseScroll', function(event) {

				var delta = (event.originalEvent.wheelDelta || -event.originalEvent.deltaY || -event.originalEvent.detail);

				event.stopPropagation();
				event.preventDefault();

				if (delta > 0) {

					$this.val(parseInt($this.val(), 10) + 1);

				} else {

					if (parseInt($this.val()) > 0) {

						$this.val(parseInt($this.val(), 10) - 1);

					}

				}

				// Recount value
				countDeliveryFoodTotal($this);

				return false;
			});
		});

		// Counter
		$('#customerOrderModal .order-detail .type-food input').on('keyup', function() {
			countDeliveryFoodTotal($(this));
		});

		$('#customerOrderModal .order-detail .delivery-food-individual input').on('change', function() {
			var $this = $(this),
				$tr = $this.parent('label').parent('td').parent('tr');

			$tr.children('td.delivery-food').children('div').children('input').each(function() {

				if ($this.prop('checked')) {

					$(this).removeAttr('readonly');

				} else {

					$(this).attr('readonly', 'readonly');

				}

			});

			// Recount value
			countDeliveryFoodTotal($this);
		});
	});

	function countDeliveryFoodTotal($input)
	{
		var $tr = $input.parent('div').parent('td').parent('tr'),
			$individual = $tr.children('td.delivery-food-individual').children('label').children('input'),
			$totalInput = $tr.children('td.delivery-food-total').children('div').children('input'),
			totalValue = 0;

		// Count values
		$tr.children('td.type-food').children('div').children('input').each(function() {
			var value = (this.value ? this.value : 0);
			totalValue += parseInt(value);
		});

		// Set value only if it is not individual
		if ($individual.prop('checked') == false) {

			// Reset other inputs
			$tr.children('td.delivery-food').children('div').children('input').each(function() {
				$(this).val(0);
			});

			$totalInput.val(parseInt(totalValue));

		}
	}
</script>
