
<?php $__env->startSection('title'); ?>
	@parent
	Продукты проекта <?php echo $project->name; ?>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('js'); ?>
	<script src="<?php echo asset('js/products.js'); ?>"></script>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('content'); ?>
<div class="row">
  <div class="col-md-12">
		<h4>Продукты проекта <?php echo $project->name; ?> <small><a href="<?php echo action('ProductsController@export', array($project->id)); ?>" target="_blank">экспорт в Excel</a></small></h4>
		<div class="btn-group btn-group-search-input">
			<input id="partnerProductsSearch" type="text" class="form-control" placeholder="Поиск" autocomplete="off" autofocus>
			<span class="btn-search-clear glyphicon glyphicon-remove-circle"></span>
		</div>
		<div class="table-responsive">
			<table id="partnerProducts" class="table table-striped table-hover">
				<thead>
					<th>Название</th>
					<th>Цена</th>
					<th class="text-center">Доступно (забронировано)</th>
					<th>Действия</th>
				</thead>
				<tbody>
					<?php
					  $productGroupQuant = $project->getProductGroupQuant();
					?>
					<?php foreach ($project->products as $product): ?>
					<tr>
						<td>
							<span class="to-search"><?php echo $product->mark->name; ?> <?php echo $product->name; ?></span>
							<br/>
							<small><?php echo $product->year_start; ?> - <?php echo $product->year_end; ?></small>
						</td>
						<td class="td-nobr">
							<?php
								$prices = $product->getPrices();
							?>
							<?php foreach (ProductType::all() as $productType): ?>
								<?php if ((isset($prices[$productType->id]['price']) && $prices[$productType->id]['price']) || (isset($prices[$productType->id]['price_back']) && $prices[$productType->id]['price_back'])): ?>
									<?php echo $productType->name; ?> / <span class="to-humanize"><?php echo $prices[$productType->id]['price']; ?></span> <i class="fa fa-rub"></i> / <span class="to-humanize"><?php echo $prices[$productType->id]['price_back']; ?></span> <i class="fa fa-rub"></i> / <span class="to-humanize"><?php echo $prices[$productType->id]['price_opt']; ?></span> <i class="fa fa-rub"></i>, <?php echo $prices[$productType->id]['plates']; ?>/<?php echo $prices[$productType->id]['hooks']; ?>/<?php echo $prices[$productType->id]['splates']; ?><br/>
								<?php endif; ?>
							<?php endforeach; ?>
						</td>
						<?php
						  $quantProductType = $product->getQuant();
							$noProduction     = $product->no_production;
						?>
						<td class="text-center td-nobr">
							<?php if ($noProduction == 0): ?>	
								<?php foreach (ProductType::all() as $productType): ?>
									<?php if ((isset($prices[$productType->id]['price']) && $prices[$productType->id]['price']) || (isset($prices[$productType->id]['price_back']) && $prices[$productType->id]['price_back'])): ?>
									<?php
									  $groupId = $prices[$productType->id]['product_group_id'];
										$quantBlocked = 0;
										$quant        = 0;
										$groupName    = '';
										if($groupId){
										  $quantBlocked = $productGroupQuant[$groupId]['quant_blocked'];
										  $quant        = $productGroupQuant[$groupId]['quant'];
											$groupName    = $productGroupQuant[$groupId]['name'];;
										}
									?>
									  <?php if($groupId): ?>
										<a href="#" class="td-nobr-block"><i class="fa fa-caret-down fa-2x product-quant-list setQuantGroupDown" data-action="<?php echo action('ProductsGroupController@updateQuant', array($project->id, $groupId, "down")); ?>"></i></a>
										<span class="to-humanize td-nobr-block text-bold text-success productQuant" data-product-group-id="<?php echo $groupId; ?>" title="Группа: <?php echo $groupName; ?>"><?php echo $quant - $quantBlocked; ?></span>
										<a href="#" class="td-nobr-block"><i class="fa fa-caret-up fa-2x product-quant-list setQuantGroupUp" data-action="<?php echo action('ProductsGroupController@updateQuant', array($project->id, $groupId, "up")); ?>"></i></a>
										<span class="to-humanize td-nobr-block">(<?php echo $quantBlocked; ?>)</span><br>
									  <?php else: ?>
										<a href="#" class="td-nobr-block"><i class="fa fa-caret-down fa-2x product-quant-list setQuantProductTypeDown" data-action="<?php echo action('ProductsController@updateQuant', array($project->id,  $product->id, $productType->id, "down")); ?>"></i></a>
											<span class="to-humanize td-nobr-block productQuant"><?php echo $quantProductType[$productType->id]['quant'] - $quantProductType[$productType->id]['quant_blocked']; ?></span>
										<a href="#" class="td-nobr-block"><i class="fa fa-caret-up fa-2x product-quant-list setQuantProductTypeUp" data-action="<?php echo action('ProductsController@updateQuant', array($project->id,  $product->id, $productType->id, "up")); ?>"></i></a>
										<span class="to-humanize td-nobr-block">(<?php echo ($quantProductType[$productType->id]['quant_blocked'])? $quantProductType[$productType->id]['quant_blocked']:0; ?>)</span><br>
										<?php endif; ?>
									<?php endif; ?>
								<?php endforeach; ?>
							<?php endif; ?>
						</td>
						<td>
							<button class="btn btn-sm btn-default btn-block" onClick="location.href ='<?php echo action('ProductsController@edit', array($project->id, $product->id)); ?>'"> &nbsp;Редактировать&nbsp; </button>
							<button class="btn btn-sm btn-default btn-block action_confirm" type="button" data-method="delete" href="<?php echo action('ProductsController@destroy', array($project->id, $product->id)); ?>"> Удалить </button>
						</td>
					</tr>
					<?php endforeach; ?>
				</tbody>
			</table>
		</div>
		<button class="btn btn-primary" onClick="location.href ='<?php echo URL::to('projects'); ?>/<?php echo $project->id; ?>/products/create'">Добавить продукт</button>
	</div>
</div>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.default', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>