<?php include('casa/setup.casa.php');
include('inc_scripts.php');
$title = 'Control de Inventario';
echo "<title>".AppName.' - '.$title."</title>";
?>
<script src="<?php echo PATH_HOME.'assets/js/core/jquery.3.2.1.min.js';?>"></script>	
<script src="<?php echo PATH_HOME.'assets/js/jspdf.debug.js';?>"></script>	
<script src="<?php echo PATH_HOME.'assets/js/word/FileSaver.js';?>"></script> 
<script src="<?php echo PATH_HOME.'assets/js/word/jquery.wordexport.js';?>"></script> 
<style>
[type=checkbox] {
  width: 22px;
  height: 22px;
  vertical-align: middle;
  -webkit-appearance: none;
  background: none;
  border: 0;
  outline: 0;
  flex-grow: 0;
  border-radius: 30%;
  background-color: #FFFFFF;
  transition: background 900ms;
  cursor: pointer;
}


/* Pseudo element for check styling */

[type=checkbox]::before {
  content: "";
  color: transparent;
  display: block;
  width: inherit;
  height: inherit;
  border-radius: inherit;
  border: 0;
  background-color: transparent;
  background-size: contain;
  box-shadow: inset 0 0 0 1px green;
}


/* Checked */

[type=checkbox]:checked {
  background-color: green;
}

[type=checkbox]:checked::before {
  box-shadow: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24'%3E %3Cpath d='M15.88 8.29L10 14.17l-1.88-1.88a.996.996 0 1 0-1.41 1.41l2.59 2.59c.39.39 1.02.39 1.41 0L17.3 9.7a.996.996 0 0 0 0-1.41c-.39-.39-1.03-.39-1.42 0z' fill='%23fff'/%3E %3C/svg%3E");
}


/* Disabled */

[type=checkbox]:disabled {
  background-color: #CCD3D8;
  opacity: 0.84;
  cursor: not-allowed;
}	
</style>
</head>
<body>
	<div class="wrapper">		
	<?php include('inc_menu.php');?>
		<div class="main-panel">
			<div class="content">
				
			<div class="page-inner">
					
					<div class="row">						
						<div class="col-md-12">
							<div class="card">
								<div class="card-header">
									<div class="d-flex align-items-center">
										<h3 class="card-title"><?php echo $title?></h3>																																									
									</div>
								</div>
								
								<div class="card-body">		
																									
									<div class="table-responsive">
										<div class="row" style='width:97%' align='left'>
											<div class="col-sm-12">
												<b>Ubicaciones:</b>
												<select id="cmbSucursales" class="btn btn-primary" style='color:white;text-align:left;'>
													<?php
													if(isset($_GET['ubica'])) $ubica = $_GET['ubica'];
													$sql = "SELECT * FROM inventarios_ubicaciones
													WHERE ubica_estado='1'
													ORDER BY ubica_nombre;";
													$db = new DB();
													$db->dbSQL($sql);
													$html = '';
													$i = 0;
													while($db->next()){
													$i++;
													   $ubica_id = $db->dbField("ubica_id");
													   $ubica_codigo = $db->dbField("ubica_codigo");
													   $ubica_nombre = $db->dbField("ubica_nombre");
													   $ubica_color = $db->dbField("ubica_color");
													   if($ubica==$ubica_codigo)
													   	$html.='<option selected value="'.$ubica_codigo.'">'.$ubica_nombre.'</option>';
													   else 
													    $html.='<option value="'.$ubica_codigo.'">'.$ubica_nombre.'</option>';
													   
													}
													echo $html;
													?>
												</select><br>
												<b>
												<form id="form">
												<input type="checkbox" name="cap[]" value="1" onclick="EnviarChk()"> FOTO
												<input type="checkbox" name="cap[]" value="2" onclick="EnviarChk()"> DESCRIPCION
												<input type="checkbox" name="cap[]" value="3" onclick="EnviarChk()"> CAJAS UBICACION
												<input type="checkbox" name="cap[]" value="4" onclick="EnviarChk()"> CANTIDAD
												<input type="checkbox" name="cap[]" value="5" onclick="EnviarChk()"> OBSERVACIONES
												<br>
												<input type="checkbox" name="cap[]" value="6" onclick="EnviarChk()"> Ordenar por Item									
												<input type="checkbox" name="cap[]" value="7" onclick="EnviarChk()"> Ordenar por Descripción</b>													
												</form>
											</div>																																					
										</div>	
										<div id="controlinventario"></div>
										
										<div align="center">
											<button id="btnWord" class="btn btn-primary" style='color:white;'>GENERAR ARCHIVO</button>
										</div>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
				
			</div>
			<?php include('inc_pie.php');?>
		</div>
		
		
	</div>
</body>
</html>
<script>
$(document).ready(function() {			
	$('#add-row').DataTable({
		"pageLength": 25,
	});
});	
$('#cmbSucursales').change(function(){
    let codegen = $(this).val();
    if(codegen == '') codegen ='ver';
    //self.location="<?php echo PATH_HOME.'control.php?ubica=' ?>"+codegen;
	$('#controlinventario').load('control-inventario.php?ubica='+codegen+'&sel=0');
});

$("#btnWord").click(function() {
    $("#control").wordExport("<?php echo 'controlinventarios';?>");
});
var ff=0;
function EnviarChk(){	
	ff=ff+1;
    let codegen = $('#cmbSucursales').val();
    if(codegen == ''){
		alert('Seleccione una Sucursal!!!');
	}else{
		var selected = [];    
        $('#form input[type=checkbox]').each(function(){
            if (this.checked)
                selected.push($(this).val());
			else 
             	selected.push('0');
        }); 
    	$('#controlinventario').load('control-inventario.php?ubica='+codegen+'&sel='+selected+'&ff='+ff);
	}
}
</script>