

<?php $__env->startSection('pageTitle'); ?>
	<div class="page-head">
		<div class="container">
			<!-- BEGIN PAGE TITLE -->
			<div class="page-title">
				<h1>Pedidos <small>gerenciamento de pedidos de venda</small></h1>
			</div>
			<!-- END PAGE TITLE -->
		</div>
	</div>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('breadcrumb'); ?>
	<li>
		<a href="<?php echo e(action('HomeController@index')); ?>">Tela Inicial</a>
		<i class="fa fa-circle"></i>
	</li>
	<li class="active">Pedidos de venda</li>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('content'); ?>
	<?php echo Form::open(['action' => 'PedidoController@index', 'method' => 'GET', 'class' => 'form-inline form-group']); ?>

		<?php echo Form::text('client', old('client'), ['class' => 'form-control', 'placeholder' => 'Busque um cliente']); ?>

		<?php echo Form::submit('Pesquisar', ['class' => 'btn btn-primary', 'data-loading-text' => 'Carregando...', 'data-loading']); ?>

	<?php echo Form::close(); ?>

	<?php if(Session::has('success')): ?>
		<div class="alert alert-success">
			<p><?php echo e(Session::get('success')); ?></p>
		</div>
	<?php endif; ?>
	<?php if(Session::has('error')): ?>
		<div class="alert alert-danger">
			<p><?php echo e(Session::get('error')); ?></p>
		</div>
	<?php endif; ?>
	<div class="table-responsive">
		<table class="table table-striped table-bordered table-advance table-hover">
			<thead>
			<tr>
				<th>
					Pedido
				</th>
				<th>
					Emissão
				</th>
				<th>
					Cliente
				</th>
				<th class="text-center">
					Tabela
				</th>
				<th>
					Pagamento
				</th>
				<th>
					Ordem de compra
				</th>
				<th>
					Observação
				</th>
				<th style="white-space: nowrap">
					E-mail
				</th>
				<th>
					Clonar
				</th>
			</tr>
			</thead>
			<tbody>
			<?php $__empty_1 = true; foreach($pedidos as $pedido): $__empty_1 = false; ?>
				<tr>
					<td>
						<?php echo e($pedido->ZP_PEDIDO); ?>

					</td>
					<td class="text-center">
						<?php echo e($pedido->ZP_EMISSAO); ?>

					</td>
					<td>
						<?php echo e($pedido->ZP_CLIENTE.' - '.$pedido->ZP_LOJA); ?> <br />
						<?php echo e(\App\Cliente::getNameEmp($pedido->ZP_CLIENTE,$pedido->ZP_LOJA)->A1_NREDUZ); ?>

					</td>
					<td class="text-center">
						<?php echo e($pedido->ZP_TABELA); ?>

					</td>
					<td class="text-center">
						<?php echo e($pedido->condicaoPagamento->E4_DESCRI); ?>

					</td>
					<td>
						<?php if(!empty(trim($pedido->ZP_ORDCOMP))): ?>
							<?php echo e($pedido->ZP_ORDCOMP); ?>

						<?php else: ?>
							<span class="label label-warning">Não possui</span>
						<?php endif; ?>
					</td>
					<td>
						<?php if(!empty(trim($pedido->ZP_OBSERV))): ?>
							<?php echo e($pedido->ZP_OBSERV); ?>

						<?php else: ?>
							<span class="label label-warning">Não possui</span>
						<?php endif; ?>
					</td>
					<td class="text-center">
						<button
							class="popovers modal_re_send_email"
							data-placement="top"
							data-toggle="modal"
							data-target=".bs-example-modal-sm"
							data-container="body"
							data-html="true"
							data-trigger="hover"
							data-pedido="<?php echo e($pedido->ZP_PEDIDO); ?>"
							data-recno="<?php echo e($pedido->R_E_C_N_O_); ?>"
							data-client="<?php echo e($pedido->ZP_CLIENTE); ?>"
							data-ordemCompra="<?php echo e((!empty(trim($pedido->ZP_ORDCOMP))) ? $pedido->ZP_ORDCOMP : 'Sem ordem de compra'); ?>"
							data-observacao="<?php echo e((!empty(trim($pedido->ZP_OBSERV))) ? $pedido->ZP_OBSERV : 'Sem observação'); ?>"
							data-content='E-mail'>
							<i class="icon-envelope"></i>
						</button>
					</td>
					<td class="text-center">
						<?php echo Form::open(['action' => 'PedidoController@cloneOrder', 'method' => 'POST']); ?>

						<input type="hidden" name="orderId" value="<?php echo e($pedido->ZP_PEDIDO); ?>">
						
						<button class="popovers" data-container="body" data-original-title="Itens"
						   data-placement="top" data-html="true" data-trigger="hover"
						   data-content='
								<ul>
									<?php $__empty_2 = true; foreach($pedido->itensPedido as $item): $__empty_2 = false; ?>
										<li>
											<span class="badge badge-info">
												<?php echo e($item->ZQ_QUANT); ?>

											</span>
											<?php if(isset($item->produto)): ?>
												<?php echo e($item->produto->B1_DESC); ?>

											<?php endif; ?> -
								   			<strong>R$ <?php echo e(\KsiHelper::formatarDinheiro($item->ZQ_QUANT * $item->ZQ_VLUNIT)); ?></strong>
										</li>
									<?php endforeach; if ($__empty_2): ?>
										<li><span class="label label-warning">Nenhum item encontrado</span></li>
									<?php endif; ?>
							   </ul>
						   '>

							<i class="icon-info"></i>
						</button>
						<?php echo Form::close(); ?>

					</td>
				</tr>
			<?php endforeach; if ($__empty_1): ?>
				<tr class="active">
					<td colspan="8">
						Nenhum resultado encontrado
					</td>
				</tr>
			<?php endif; ?>
			</tbody>
		</table>

		<?php echo $pedidos->render(); ?>

	</div>

	<div class="modal fade bs-example-modal-sm"
		 id="mySmallModal"
		 tabindex="-1"
		 role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal">
						<span aria-hidden="true">&times;</span>
						<span class="sr-only">Close</span>
					</button>
					<h4 class="modal-title" id="exampleModalLabel">Cópia do pedido</h4>
				</div>
				<?php echo Form::open(['action' => 'PedidoController@reEnviarmail', 'method' => 'POST']); ?>

				<div class="modal-body">
					<div class="row">
						<div class="form-group">
							<label for="recipient-name" class="control-label col-4 col-lg-4 col-sm-4 col-md-4">
								Selecione um contato:
							</label>
							<div class="col-8 col-lg-8 col-sm-8 col-md-8">
								<input type="checkbox"
									   id="todos"
									   name="todos"
									   value="todos"
									   checked="checked"
								>
								<label for="todos">Enviar para todos?</label><br>
								<input type="checkbox"
									   class="campos"
									   id="vendasFlora"
									   name="vendasFlora"
									   value="vendas@florapack.ind.br"
									   checked="checked"
								>
								<label for="vendasFlorapack1">vendas@florapack.ind.br</label><br>
								<input type="checkbox"
									   class="campos"
									   id="vendasFlorapack"
									   name="vendasFlorapack"
									   value="vendas02@florapack.ind.br"
									   checked="checked"
								>
								<label for="vendasFlorapack2">vendas02@florapack.ind.br</label><br>
								<input type="checkbox"
									   class="campos"
									   id="representante"
									   name="representante"
									   value="representante"
									   checked="checked"
								>
								<label for="representante"><?php echo e(Auth::user()->A3_EMAIL); ?></label><br>
							</div>
						</div>
					</div>
					<div class="form-group">
						<label for="message-text" class="control-label">Outros contatos:</label>
						<input type="text" class="form-control" id="outros" name="outros">
						<span class="text-danger h6">Para mais de um e-mail, separar por (;) ponto e vírgula.</span>
					</div>
				</div>
				<div class="modal-footer">
					<input type="hidden" id="pedido" name="pedido">
					<input type="hidden" id="client" name="client">
					<input type="hidden" id="recno" name="recno">
					<input type="hidden" id="ordemCompra" name="ordemCompra">
					<input type="hidden" id="observacao" name="observacao">
					<button type="button" class="btn btn-default" data-dismiss="modal">Fechar</button>
					<button type="submit" class="btn btn-primary">Enviar e-mail</button>
				</div>
				<?php echo Form::close(); ?>

			</div>
		</div>
	</div>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('javascript'); ?>
	<script>
		$(document).ready(function () {
			$('.modal_re_send_email').click(function () {
				var pedido = $(this).data('pedido');
				$('#pedido').val(pedido);
				$('#recno').val($(this).data('recno'));
				$('#client').val($(this).data('client'));
				$('#ordemCompra').val($(this).data('ordemcompra'));
				$('#observacao').val($(this).data('observacao'));
			})
		});

		$(document).ready(function () {
			$('#todos').click(function() {
				var vendasFlora = document.getElementById("uniform-vendasFlora");
				var filhosVendasFlora = vendasFlora.children;
				var vendasFlorapack = document.getElementById("uniform-vendasFlorapack");
				var filhosVendasFlorapack = vendasFlorapack.children;
				var representante = document.getElementById("uniform-representante");
				var filhosRepresentante = representante.children;

				if ($(this).is(':checked')) {
					filhosVendasFlora[0].className = "checked";
                    $('#vendasFlora').prop('checked', true);
					filhosVendasFlorapack[0].className = "checked";
					$('#vendasFlorapack').prop('checked', true);
					filhosRepresentante[0].className = "checked";
					$('#representante').prop('checked', true);
				} else {
					filhosVendasFlora[0].className = "";
					$('#vendasFlora').prop('checked', false);
					filhosVendasFlorapack[0].className = "";
					$('#vendasFlorapack').prop('checked', false);
					filhosRepresentante[0].className = "";
					$('#representante').prop('checked', false);
				}

			})
		});

		$(document).ready(function () {
			$('.modal').on('hidden.bs.modal', function () {
				$(this).find('form')[0].reset();
			})
		});
	</script>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('partials.master', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>