<div class="row" id="<?php $windowid= date('YmdHis'); echo $windowid;?>">
	<form autocomplete='off' class='form-horizontal' name=''  method='post' action='' onsubmit="">
		<div class="panel blank-panel">
			<div class="panel-body">
				<!--Venta info-->
				<input type="hidden" id="id-ventaapp" value="<?php echo (isset($venta)?$venta->id_transaccion:'');?>">
				<div class="form-group">
					<!--Cliente-->
					<label class="control-label col-sm-1">Cliente:</label>
					<div class="col-sm-5">
						<div class="input-group">
							<input type="text" id="nueva-venta-app-cliente-text" value="<?php echo(isset($venta))?$venta->cliente_nombre:"";?>" data-credito="<?php echo(isset($venta))?$venta->cliente_credito:"";?>" class="form-control" data-type="<?php echo(isset($venta))?$venta->cliente_clasificacion:"";?>">
							<span class="input-group-btn">
								<button class="btn btn-info" id="nueva-venta-app-cliente-buscar-btn" type="button" data-function="set"><i class="fa fa-search"></i></button>
							</span>
						</div>
						<input type="hidden"  id="nueva-venta-app-cliente" value="<?php echo (isset($venta) && $venta->cliente_id)?$venta->cliente_id:"";?>">
					</div>
					<!--condicion-->
					<label class="control-label col-sm-1">Condici&oacute;n:</label>
					<div class="col-sm-2">
						<select class="form-control" id="nueva-venta-app-condicion">
							<option value="0" <?php if(isset($venta)&&$venta->venta_condicion==0) echo 'selected';?>>Contado</option>
							<option value="1" <?php if(isset($venta)&&$venta->venta_condicion==1) echo 'selected';?>>Credito</option>
						</select>
					</div>
					<!--documento-->
					<label class="control-label col-sm-1">Documento:</label>
					<div class="col-sm-2">
						<select class="form-control" id="nueva-venta-app-documento">
							<option value="" selected disabled>Seleccione uno</option>
							<option value="0" <?php if(isset($venta)&&$venta->venta_doc==0) echo 'selected';?>>Ninguno</option>
							<option value="1" <?php if(isset($venta)&&$venta->venta_doc==1) echo 'selected';?>>Factura</option>
							<option value="2" <?php if(isset($venta)&&$venta->venta_doc==2) echo 'selected';?>>Comprobante de cr&eacute;dito fiscal</option>
							<option value="3" <?php if(isset($venta)&&$venta->venta_doc==3) echo 'selected';?>>Ticket</option>
							<option value="4" <?php if(isset($venta)&&$venta->venta_doc==4) echo 'selected';?>>Nota de remisi&oacute;n</option>
							<option value="5" <?php if(isset($venta)&&$venta->venta_doc==5) echo 'selected';?>>Nota de envio</option>
						</select>
					</div>
				</div>
				<!--Agregar productos-->
				<div class="form-group" id="nueva-venta-app-producto-info">
					<!--sku-->
					<div class="col-sm-2">
						<label>SKU</label>
						<div class="input-group">
							<input type="text" id="nueva-venta-app-producto-sku" class="form-control frame-control frame-producto-sku" tabindex="-1">
							<input type="hidden" id="nueva-venta-app-producto-id" class="frame-control frame-producto-id">
							<input type="hidden" id="nueva-venta-app-presentacion-id" class="frame-control frame-presentacion-id">
							<input type="hidden" id="nueva-venta-app-unidades-representativas" class="frame-control frame-unidades-representativas">
							<input type="hidden" id="nueva-venta-app-producto-existencias" class="frame-control frame-producto-existencias">
							<input type="hidden" id="nueva-venta-app-producto-tipoventa" class="frame-control frame-producto-tipoventa">
							<span class="input-group-btn">
								<button type="button" id="ventas-buscar-app-producto-btn" class="btn btn-primary"><i class="fa fa-search"></i></button>
							</span>
						</div>
					</div>
					<!--Descripcion--->
					<div class="col-sm-4">
						<label>Descripci&oacute;n</label>
						<input type="text" id="nueva-venta-app-producto-desc" class="form-control  frame-control frame-producto-desc" readonly>
					</div>
					<!--Cantidad-->
					<div class="col-sm-2">
						<label>Cantidad</label>
						<input type="number" id="nueva-venta-app-producto-cant" min="1" class="form-control frame-control frame-producto-cant" data-valid-type="number">
					</div>
					<!--Precios-->
					<div class="col-sm-2">
						<label>Precio</label><small class="frame-producto-price-indicator"></small>
						<div class="input-group date">
							<span class="input-group-addon price-navigation-btn" data-role="previus" style="padding:6px 3px;" id="nueva-venta-precio-previo-btn"> <i class="fa fa-chevron-left"></i></span>
							<input type="text" id="nueva-venta-app-producto-costo" data-active-price='0' class="form-control frame-control frame-producto-precio" data-valid-type="number">
							<span class="input-group-addon price-navigation-btn" data-role="next" style="padding:6px 3px;" id="nueva-venta-precio-siguente-btn"><i class="fa fa-chevron-right"></i></span>
						</div>
						<input type="hidden" id="nueva-venta-app-producto-precios" class="frame-control frame-producto-precios">
						<input type="hidden" id="nueva-venta-app-producto-precio-bajo" class="frame-control frame-producto-precio-bajo">
					</div>
					<!--Agregar boton-->
					<div class="col-sm-2">
						<button type="button" id="nueva-venta-app-producto-agregar" class="btn btn-info btn-md m-t-md frame-producto-add-btn">Agregar</button>
					</div>
				</div>
				<!--Tabla de productos-->
				<div class="row">
				<!--table header-->
					<table class="table table-hover" style="margin:0px;">
						<thead>
							<tr>
								<th style="width:15%">SKU</th>
								<th style="width:40%">Nombre</th>
								<th style="width:10%">Cant.</th>
								<th style="width:10%">Costo.</th>
								<th style="width:10%">Total.</th>
								<th style="width:5%"></th>
								<th style="width:10%">Quitar</th>
							</tr>
						</thead>
					</table>
				</div>
				<div class="row">
				<!--tabla body-->
					<div id="nueva-venta-app-productos-wrapper" style="height:150px; overflow:hidden;border-bottom:solid 2px #DDD;">
						<table class="table table-hover">
							<tbody>
							<?php if(isset($productos)): if(count($productos)>0): foreach($productos as $producto):?>
								<tr data-id="<?php echo $producto->id;?>" data-pre="<?php echo $producto->id_pre;?>" data-uequiv="<?php echo $producto->uequiv;?>">
									<td class="table-sku" data-value="<?php echo $producto->sku;?>"><?php echo $producto->sku;?></td>
									<td class="table-desc" data-value="<?php echo $producto->nombre;?>"><?php echo $producto->nombre;?></td>
									<td class="table-cant" data-value="<?php echo $producto->cant;?>"><?php echo $producto->cant;?></td>
									<td class="table-precio" data-value="<?php echo $producto->precio;?>"><?php echo $producto->precio;?></td>
									<td class="table-total" data-value="<?php echo $producto->cant*$producto->precio;?>"><?php echo $producto->cant*$producto->precio;?></td>
									<td class="table-tipoventa" data-value="<?php echo $producto->tipo;?>"><?php switch($producto->tipo){case 0: echo 'G';break;case 1:echo 'E';break;case 2:echo 'NS';break;case 3: echo 'E';break;}?></td>
									<td class="table-del"><button type="button" class="btn btn-danger btn-xs btn-rounded"><i class="fa fa-times"></i></button></td>
								</tr>
							<?php endforeach;endif;endif;?>
							</tbody>
						</table>
					</div>
				</div>
				<input type="hidden" id="nueva-venta-app-perfil-precios" value="0"><!--0 incluye iva,1 mas iva-->
				<!--Ocultos-->
				<div>
					<input type="hidden" id="nueva-venta-app-vendedor" value="<?php echo (isset($venta)?$venta->venta_vendedor:'');?>">
				</div>
				<!--totales-->
				<div class="row" style="min-height:195px;">
					<div class="col-sm-8">
						<h3 class="m-lg transacction-item-counter">Items en la venta: <b>0</b></h3>
					</div>
					<div class="col-sm-4">
						<table class="table" id="nueva-venta-app-totales-wrapper">
							<tbody>
							</tbody>
						</table>
					</div>
				</div>
				<!--Buttons-->
				<div class="form-group" style="margin:0; text-align:center;">
					<button type="button" class="btn btn-danger btn-rounded" onclick="Custombox.close();">Cancelar</button>
					<button type="button" id="guardar-venta-app-btn" class="btn btn-primary btn-rounded">Guardar [F10]</button>
				</div>
				<!--modales-->
				<div>
					<!--Cliente info-->
					<div class="modal inmodal fade" id="nueva-venta-cliente-docs" tabindex="-1" role="dialog"  aria-hidden="true">
						<div class="modal-dialog modal-sm">
							<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="">Documentos del cliente</h4>
								</div>
								<div class="modal-body">
									<div class="form-group">
										<label class="control-label">DUI:</label>
										<input type="text" class="form-control" id="nueva-venta-cliente-dui" value="<?php echo (isset($venta)?$venta->cliente_dui:'');?>">
									</div>
									<div class="form-group">
										<label class="control-label">NIT:</label>
										<input type="text" class="form-control" id="nueva-venta-cliente-nit" value="<?php echo (isset($venta)?$venta->cliente_nit:'');?>">
									</div>
									<div class="form-group">
										<label class="control-label">NRC:</label>
										<input type="text" class="form-control" id="nueva-venta-cliente-nrc" value="<?php echo (isset($venta)?$venta->cliente_nrc:'');?>">
									</div>
								</div>
								<div class="modal-footer">
									<button type="button" id="nueva-venta-doc-cancel-btn" class="btn btn-white" data-dismiss="modal">Cancelar</button>
									<button type="button" id="nueva-venta-doc-guardar-btn" class="btn btn-primary">Aceptar</button>
								</div>
							</div>
						</div>
					</div>
					<!--Confirmar-->
					<div class="modal inmodal fade" id="nueva-venta-confirmar" tabindex="-1" role="dialog"  aria-hidden="true">
						<div class="modal-dialog modal-sm">
							<div class="modal-content">
								<div class="modal-header">
									<h4 class="">Confirmar venta</h4>
								</div>
								<div class="modal-body">
									<h1 class="text-center"  id="nueva-venta-procesar-status-icon"><i class="fa fa-question-circle fa-5x" style="color:#23C6C8;"></i></h1>
									<h3 class="text-muted text-center" id="nueva-venta-procesar-status-text">&iquest;Desea guardar esta venta?</h3>
									
									<div style='margin:20px'>
										<table class='table'>
											<tr>
												<td><h3 style='line-height:normal;font-weight:normal;margin:0px;'>Total</h3></td>
												<td><h3 style='line-height:normal;font-weight:normal;margin:0px;'>$</h3></td>
												<td><h3 style='line-height:normal;font-weight:normal;margin:0px; text-align:right;' id="nueva-venta-confirm-total"></h3></td>
											</tr>
										</table>
									</div>
								</div>
								<div class="modal-footer" id="nueva-venta-confirmar-buttons">
									<button type="button" id="nueva-venta-cancelar-guardar-btn" class="btn btn-white" data-dismiss="modal">Cancelar</button>
									<button type="button" id="nueva-venta-confirmar-guardar-btn" class="btn btn-primary">Guardar venta</button>
									<button type='button' style="display:none" id='nueva-venta-confirmar-salir-btn' class='btn btn-danger'>Salir</button>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</form>
</div>
<script>
	$(function(){
		var transacciones_ventas_nueva=new Transacciones_ventas_nueva();
		transacciones_ventas_nueva.initializeEnviroment("<?php echo base_url();?>","<?php echo $windowid;?>"); 
		transacciones_ventas_nueva.initializeTools();
		transacciones_ventas_nueva.initializeListeners();
		<?php if(isset($venta)):?>
		transacciones_ventas_nueva.updateVentaInfo();
		<?php endif;?>
	});
</script>