<?php
session_start();
include('../config.php');
include($rutaPhp.$rutaHtml.'/maqueta/includes.php');

if($_POST['orden']) foreach($_SESSION['ordenesPicking'] as $orden) if($orden['Orden']==$_POST['orden']) $_SESSION['ordenPicking']=$orden;

?>
<h3>Detalle de Productos</h3>
<table class="tablaFormateada">
	<tr>
		<th>Código</th>
 		<th>Descripción</th>
 		<th>Cant.</th>
 	</tr>
	<?php
	foreach(arreglaArrayPXMobileProxiumResult($_SESSION['ordenPicking']['Productos']) as $producto) {
		?>
		<tr>
			<td><?php echo $producto['Codigo']; ?></td>
			<td align="left"><?php echo $producto['Descripcion']; ?></td>
			<td align="right"><?php echo number_format($producto['Cantidad'],0,',','.'); ?></td>
		</tr>
		<?php
    }
	?>
</table>
<p><input name="cerrarPicking" id="cerrarPicking" type="button" value="Cerrar Picking" class="boton"/></p>
<p><input name="anularPicking" id="anularPicking" type="button" value="Anular Orden" class="boton reducido"/></p>

<script>

	$(document).ready(function() {
	
		$('#cerrarPicking').on("click",function(){
		
			$('#popupCargando').show();
		
			$.post( "<?php echo $rutaHtml; ?>/contenidos/orden-picking-iniciar.php" )
			.done(function(data) {
				window.location="orden-picking-proceso.php";
			});
			
		});
	
		$('#anularPicking').on("click",function(){
		
			confirm("Se va a proceder a anular la Orden de Picking Nº <?php echo $_SESSION['ordenPicking']['Orden']; ?>." ).done( function(){
			
				$('#popupCargando').show();
				
				$.post( "<?php echo $rutaHtml; ?>/contenidos/orden-picking-anular.php", { orden: "<?php echo $_SESSION['ordenPicking']['Orden']; ?>" } )
					.done(function(data) {
						
						$('#popupCargando').hide();
						
						var resultado=data.split('#');
						
						if(resultado[0]=='0') {
							alert( resultado[1] ).done( function(){
								$('#popupCargando').show();
								window.location="ordenes-picking.php";
							});
						}
						else alert('ERROR: '+resultado[1]);
				});
			
			});
			
		});
	
	});

</script>