<!--add-->
<?php if(!isset($entrada)):?>
<div class="form-group" id="multiple-entrada-producto-info">
	<div class="col-sm-2">
		<label>SKU</label>
		<div class="input-group">
			<input type="text"  id="multiple-entrada-producto-sku" class="form-control frame-control frame-producto-sku">
			<input type="hidden" id="multiple-entrada-producto-id" class="frame-control frame-producto-id">
			<input type="hidden" id="multiple-entrada-presentacion-id" class="frame-control frame-presentacion-id">
			<input type="hidden" id="multiple-entrada-unidades-representativas" class="frame-control frame-unidades-representativas">
			<span class="input-group-btn">
				<button type="button" id="multiple-entrada-producto-buscar" class="btn btn-primary"><i class="fa fa-search"></i></button>
			</span>
		</div>
	</div>
	<div class="col-sm-4">
		<label>Descripci&oacute;n</label>
		<input type="text" id="multiple-entrada-producto-desc" class="form-control frame-control frame-producto-desc" readonly>
	</div>
	<div class="col-sm-2">
		<label>Cantidad</label>
		<input type="text" id="multiple-entrada-producto-cant" class="form-control frame-control frame-producto-cant">
	</div>
	<div class="col-sm-2">
		<label>Costo</label>
		<input type="text" class="form-control frame-control frame-producto-costo-ultimo">
	</div>
	<div class="col-sm-2">
		<button type="button" id="multiple-entrada-producto-agregar" class="btn btn-info btn-md m-t-md frame-producto-add-btn">Agregar</button>
	</div>
</div>
<?php endif;?>
<!--table header-->
<div class="row">
	<table class="table table-hover" style="margin:0px;">
		<thead>
			<tr>
				<th style="width:15%">SKU</th>
				<th style="width:45%">Nombre</th>
				<th style="width:10%">Cant.</th>
				<th style="width:10%">Costo.</th>
				<th style="width:10%">Total.</th>
				<th style="width:10%">Quitar</th>
			</tr>
		</thead>
	</table>
</div>
<div class="row">
	<div id="multiple-entrada-productos-wrapper">
		<table class="table table-hover" id="multiple-entrada-productos-table">
			<tbody>
			<?php if(isset($entrada)):if(count($productos)>0):foreach($productos as $producto):?>
				<tr>
					<td class='table-sku' data-value='<?php echo $producto->sku;?>'><?php echo $producto->sku;?></td>
					<td class='table-desc' data-value='<?php echo $producto->desc;?>'><?php echo $producto->desc;?></td>
					<td class='table-cant' data-value='<?php echo $producto->cant;?>'><?php echo $producto->cant;?></td>
					<td class='table-costo' data-value='<?php echo $producto->costo;?>'><?php echo $producto->costo;?></td>
					<td class='table-total' data-value='<?php echo $producto->cant*$producto->costo;?>'><?php echo $producto->cant*$producto->costo;?></td>
					<td class='table-del'></td>
				</tr>
			<?php endforeach;endif;endif;?>
			</tbody>
		</table>
	</div>
</div>
<!--totales-->
<div class="row">
	<div class="col-sm-8">
		<h3 class="m-lg transacction-item-counter">Items en la entrada: <b>0</b></h3>
	</div>
	<div class="col-sm-4">
		<table class="table" id="multiple-entrada-totales-wrapper">
			<tbody>			
			</tbody>
		</table>
	</div>
</div>
<!--Botones-->
<?php if(!isset($entrada)):?>
<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" class="btn btn-primary btn-rounded" onclick="entradas.guardarEntradaMultiple(event)" id="guardar-entradas">Registrar entrada</button>
</div>
<?php endif;?>
<script>
	var toolsMultipleEntrada = new Transaccionestools('<?php echo base_url();?>');
	toolsMultipleEntrada.setProductFrame($("#multiple-entrada-producto-info"));
	toolsMultipleEntrada.setProductTable($("#multiple-entrada-productos-wrapper > table"));
	toolsMultipleEntrada.setTotalTable($("#multiple-entrada-totales-wrapper"));
	toolsMultipleEntrada.SetTotalsProfile('sumas,total','sumas',true);
	
	 $('#multiple-entrada-productos-wrapper').slimScroll({
		height: '200px'
	});
	$('#multiple-entrada-producto-buscar').click(function(e){
		e.preventDefault();
		Custombox.open({
			target:'<?php echo base_url("productos/buscarproductos");?>?field=multiple-entrada-producto-sku&enter=true', 
			effect: 'fadein',
		});
	});
	$("#multiple-entrada-producto-sku").keypress(function(e) {
		if(e.which == 13) {
			e.preventDefault();
			toolsMultipleEntrada.getProductInfoBySKU('descripcion',$(this).val(),$("#multiple-entrada-producto-cant"));
		}
	});
	$("#multiple-entrada-producto-agregar").click(function(e){
		toolsMultipleEntrada.addProductToTable('data:.frame-producto-id@data-id,data:.frame-presentacion-id@data-pre,data:.frame-unidades-representativas@data-uequiv,field:.frame-producto-sku@table-sku,field:.frame-producto-desc@table-desc,field:.frame-producto-cant@table-cant,field:.frame-producto-costo-ultimo@table-costo,operation:.frame-producto-cant|*|.frame-producto-costo-ultimo@table-total,command:remove@table-del');
	});
	$("#multiple-entrada-productos-wrapper").on('click','table tr td.table-del',function(){
		var tr = $(this).closest('tr');
		toolsMultipleEntrada.removeProductToTable($(tr));
	});
</script>