<div class="form-group">
	<label class="control-label col-sm-1">Proveedor:</label>
	<div class="col-sm-6">
		<select id="dev-proveedor-proveedor"class="form-control" <?php if(isset($salida)) echo 'disabled';?>>
			<?php if(isset($salida)):?>
			<option selected data-type="<?php echo $proveedor->clasificacion;?>"><?php echo $proveedor->nproveedor.' - '.$proveedor->rproveedor;?></option>
			<?php else:?>
			<option disabled selected>Seleccione uno...</option>
			<?php if(count($proveedores)>0):
				foreach($proveedores as $proveedor):?>
				<option value="<?php echo $proveedor->id_proveedor;?>"><?php echo $proveedor->nombre_proveedor." - ".$proveedor->razonsocial_proveedor;?></option>
			<?php endforeach;endif;?>
			<?php endif;?>
		</select>
	</div>
</div>
<!--add-->
<?php if(!isset($salida)):?>
<div class="form-group" id="dev-proveedor-producto-info">
	<div class="col-sm-2">
		<label>SKU</label>
		<div class="input-group">
			<input type="text"  id="dev-proveedor-producto-sku" class="form-control frame-control frame-producto-sku">
			<input type="hidden" id="dev-proveedor-producto-id" class="frame-control frame-producto-id">
			<span class="input-group-btn">
				<button type="button" id="dev-proveedor-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" class="form-control frame-control frame-producto-desc" readonly>
	</div>
	<div class="col-sm-2">
		<label>Cantidad</label>
		<input type="text" id="dev-proveedor-producto-cant" class="form-control frame-control frame-producto-cant" data-valid-type="number">
	</div>
	<div class="col-sm-2">
		<label>Costo</label>
		<input type="text" class="form-control frame-control frame-producto-costo" data-valid-type="number">
	</div>
	<div class="col-sm-2">
		<button type="button" id="dev-proveedor-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
<!--tabla body-->
<div class="row">
	<div id="dev-proveedor-productos-wrapper">
		<table class="table table-hover" id="dev-proveedor-productos-table">
			<tbody>
			<?php if(isset($salida)):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 devolucion: <b>0</b></h3>
	</div>
	<div class="col-sm-4">
		<table class="table" id="dev-proveedor-totales-wrapper">
			<tbody>
			</tbody>
		</table>
	</div>
</div>
<!--totales-->
<?php if(!isset($salida)):?>
<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="salidas.guardarDevoluvionProveedor(event);" id="guardar-salidas">Registrar salida</button>
</div>
<?php endif;?>
<script>
	var toolsDevProveedor = new Transaccionestools('<?php echo base_url();?>');
	 toolsDevProveedor.setProductFrame($("#dev-proveedor-producto-info"));
	toolsDevProveedor.setProductTable($("#dev-proveedor-productos-wrapper > table"));
	toolsDevProveedor.setTotalTable($("#dev-proveedor-totales-wrapper"));
	toolsDevProveedor.SetTotalsProfile('sumas,total','sumas',true);
	 $('#dev-proveedor-productos-wrapper').slimScroll({
		height: '150px'
	}); 
	$("#dev-proveedor-proveedor").chosen({
		no_results_text: "No se encontro ningun resultado",
		allow_single_deselect: true
	});
	$("#dev-proveedor-producto-buscar").click(function(e){
		e.preventDefault();
		Custombox.open({
			target:'<?php echo base_url("productos/buscarproductos");?>?field=dev-proveedor-producto-sku&enter=true', 
			effect: 'fadein',
			complete:function(){
				$(".modal-body input:text").first().focus();
			}
		});
	});
	$("#dev-proveedor-producto-sku").keypress(function(e) {
		if(e.which == 13) {
			e.preventDefault();
			toolsDevProveedor.getProductInfoBySKU('desc_producto',$(this).val(),$("#dev-proveedor-producto-cant"));
		}
	});
	$("#dev-proveedor-producto-agregar").click(function(e){
		toolsDevProveedor.addProductToTable('data:.frame-producto-id@data-id,field:.frame-producto-sku@table-sku,field:.frame-producto-desc@table-desc,field:.frame-producto-cant@table-cant,field:.frame-producto-costo@table-costo,operation:.frame-producto-cant|*|.frame-producto-costo@table-total,command:remove@table-del');
	});
	$("#dev-proveedor-productos-wrapper").on('click','table tr td.table-del',function(){
		var tr = $(this).closest('tr');
		toolsDevProveedor.removeProductToTable($(tr));
	});
</script>