@extends('layouts.default')

@section('title')
	@parent
	Создать отправку :: Управление отправками
@stop

@section('modals')
@stop

@section('css')
@stop

@section('js')
	<script>
		$(document).ready(function() {
			$('#create').unbind('click').on('click', function(){
				var l = Ladda.create(this);
				l.start();
				$.post(
					$(this).data('action'),
					function(data) {
						if (data.status === 'success') {
							window.location = '/shipments';
						}
					},
					'json'
					).always(function() { l.stop(); });
				return false;
			});
		});
	</script>
@stop

@section('content')
	<div class="row">
		<div class="col-xs-12 col-sm-9 col-md-9 col-lg-9">
			<h1 class="page-title txt-color-blueDark">
				<i class="fa fa-car fa-fw"></i>
				Новая отправка
			</h1>
		</div>
	</div>

	<section id="widget-grid">
		<div class="row">
			{{--
				<article class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
					<div class="jarviswidget jarviswidget-color-blueDark" id="wid-id-0-{{ date('YmdHis') }}" data-widget-editbutton="false" data-widget-sortable="false" data-widget-deletebutton="false" data-widget-togglebutton="false">
						<header>
							<span class="widget-icon"> <i class="fa fa-user"></i> </span>
							<h2>Отправка в ShopLogistics</h2>
						</header>

						<!-- widget div-->
						<div>
							<!-- widget edit box -->
							<div class="jarviswidget-editbox">
								<!-- This area used as dropdown edit box -->
							</div>
							<!-- end widget edit box -->

							<!-- widget content -->
							<div class="widget-body">
								@if ($shipmentPost)
									<?php
										$date = explode('-', $shipmentPost->date);
										$date[2] = (int) $date[2];
										$date = "{$date[2]} {$months[$date[1]]}";
									?>
									<h3 class="alert alert-warning">Есть незавершенная отправка от <a href="{{ URL::to('/shipments/?date=' . $shipmentPost->date) }}">{{ $date }}</a></h3>
								@else
									<h3 class="alert alert-info">Заказов на отправку: {{ $partnersPost->count() }}</h3>
									<div class="table-responsive">
										<table class="table table-hover">
											<thead>
												<th>Артикул</th>
												<th>Наименование</th>
												<th>Количество</th>
											</thead>
											<tbody>
												@foreach ($productsPost as $product)
												<tr>
													<td>
														{{ $product['article'] }}
													</td>
													<td>
														{{ $product['name'] }}
													</td>
													<td>
														{{ $product['quant'] }}
													</td>
												</tr>
												@endforeach
											</tbody>
										</table>
									</div>
								@endif
							</div>
							<!-- end widget content -->
						</div>
						<!-- end widget div -->
					</div>
					<!-- end widget -->
				</article>
			--}}

				<article class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
					<div class="jarviswidget jarviswidget-color-blueDark" id="wid-id-1-{{ date('YmdHis') }}" data-widget-editbutton="false" data-widget-sortable="false" data-widget-deletebutton="false" data-widget-togglebutton="false">
						<header>
							<h2>Отправка в СДЭК</h2>
						</header>

						<!-- widget div-->
						<div>
							<!-- widget edit box -->
							<div class="jarviswidget-editbox">
								<!-- This area used as dropdown edit box -->
							</div>
							<!-- end widget edit box -->

							<!-- widget content -->
							<div class="widget-body">
								@if ($shipmentCdek)
									<?php
										$date = explode('-', $shipmentCdek->date);
										$date[2] = (int) $date[2];
										$date = "{$date[2]} {$months[$date[1]]}";
									?>
									<h3 class="alert alert-warning">Есть незавершенная отправка от <a href="{{ URL::to('/shipments/?date=' . $shipmentCdek->date) }}">{{ $date }}</a></h3>
								@else
									<h3 class="alert alert-info">Заказов на отправку: {{ $partnersCdek->count() }}</h3>
									<div class="table-responsive">
										<table class="table table-hover">
											<thead>
												<th>Артикул</th>
												<th>Наименование</th>
												<th>Количество</th>
											</thead>
											<tbody>
												@foreach ($productsCdek as $product)
												<tr>
													<td>
														{{ $product['id'] }}
													</td>
													<td>
														{{ $product['name'] }}
													</td>
													<td>
														{{ $product['quant'] }}
													</td>
												</tr>
												@endforeach
											</tbody>
										</table>
									</div>
								@endif
							</div>
							<!-- end widget content -->
						</div>
						<!-- end widget div -->
					</div>
					<!-- end widget -->
				</article>
		</div>
	</section>

	@if((isset($partnersCdek) && $partnersCdek && isset($productsCdek) && $productsCdek) || (isset($partnersPost) && $partnersPost && isset($productsPost) && $productsPost))
	<button id="create" class="btn btn-lg btn-success ladda-button" data-style="zoom-out" data-size="l" data-action="{{ action('ShipmentsController@store') }}">Сформировать документы на отправку</button>
	@endif

@stop