<?php

include '../ReglasNegocio/bodega.php';
include '../ReglasNegocio/unidad.php';
include "../ReglasNegocio/asociado.php";
$asociado = new asociado();
$folio = $asociado->GetMayor() + 1;
$unidad = new unidad();
$bodega = new bodega();
$boton = "verifica()";
$boton2 = "verifica2()";
?>
<script LANGUAGE="JavaScript">

function verifica()
{
	if (document.miform.NInventario.value.length==0)
   {
		alert("Debe ingresar un Numero de Inventario");
		document.miform.MInventario.focus();
      	return 0;
	}
	if(document.miform.NombreI.value.length==0){
		alert("Debe ingresar un Nombre de Inventario");
		document.miform.NombreI.focus();
      	return 0;
	}
	if(document.miform.periodo.value.length==0){
		alert("Debe ingresar un Periodo, si es indefinido ingrese '-1'");
		document.miform.periodo.focus();
      	return 0;
    include "../ReglasNegocio/es_retirado.php";
    include "../ReglasNegocio/retiros_custodia.php";
    $nombre = $_POST['NombreRC'];
    $obs = $_POST['obs'];
    if ($nombre == "" || $obs == "") {
        $_SESSION["mensaje"] = "NO HA INGRESADO NOMBRE U OBSERVACION";
    } else {
        $arr = $_SESSION["rcustodia"];
        if (count($arr) == 0) {
            $_SESSION["mensaje"] = "NO HAY MATERIAL PARA INGRESAR";
        } else {
            $retiros = new retiros_custodia();
            $fecha = time();
            $fechaactual = date("Y-m-d h:m:s", $fecha);
            $retiros->Add($nombre, $obs, $fechaactual);
            $listaretiro = $retiros->Select($nombre, $obs, $fechaactual);
            $rowretiros = mysql_fetch_array($listaretiro);
            $id_retiro = $rowretiros["ID_RETIRO_CUSTODIA"];
            $material = new material();
            $asociado = new asociado();
            $folio = $_SESSION["folio_rcustodia"];
            $es_retirado = new es_retirado();
            for ($i = 0; $i < count($arr); $i++) {
                $asociado->Update($arr[$i][0]);
                $material->Update2($arr[$i][0]);
                $es_retirado->Add($arr[$i][0], $id_retiro, $folio, $fechaactual);
            }
        }
    }
    header("Location: paso.php?c=6");
}
 if ($_POST['reservado'] == "on") {
     $reservado = 1;
 }
 //arreglo lista de materiales en custodia
 $arr = $_SESSION["custodia"];
 if (count($arr) == 0) {
     $_SESSION["MensajeIC"] = "NO HAY MATERIAL PARA INGRESAR A CUSTODIA";
 } else {
     //insertar en custodia
     $custodia->Add($ingresado_por, $fechaactual, $tipo, $observacion, $reservado);
     //obtener id custodia
     $selectcustodia = $custodia->Select2($ingresado_por, $fechaactual, $tipo, $observacion, $reservado);
     $rowcustodia = mysql_fetch_array($selectcustodia);
     $id_custodia = $rowcustodia["ID_CUSTODIA"];
     //obtener id de area dependiendo del estado del material
     $asociado = new asociado();
     $material = new material();
     for ($i = 0; $i < count($arr); $i++) {
         //asignar area
         $area = "resago";
         if ($arr[$i][3] == "usado" || $arr[$i][3] == "nuevo") {
             $area = "usado";
         }
         $id_area = 2;
         //	agregar a material si es que no esta
         $selectmaterial = $material->Select($arr[$i][0]);
         $rowmaterial = mysql_fetch_array($selectmaterial);
         if ($rowmaterial == null) {
             $material->Add($arr[$i][0], $arr[$i][1], 0, "un");
         }
         //agregar a asociado
<?php

include "../AccesoDatos/Controller.php";
include "../ReglasNegocio/custodia.php";
include "../ReglasNegocio/asociado.php";
include "../ReglasNegocio/material.php";
$custodia = new custodia();
$asociado = new asociado();
$sasocuado = $asociado->getAll2();
$rowas = mysql_fetch_array($sasocuado);
?>

<script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
<script language="javascript">
$(document).ready(function() {
	$(".botonExcel").click(function(event) {
		$("#datos_a_enviar").val( $("<div>").append( $("#Exportar_a_Excel").eq(0).clone()).html());
		$("#form1").submit();
	});
});
</script>
<style type="text/css">
.botonExcel{cursor:pointer;}
</style>
<body>
<form name="form1" id="form1" method="post" action="ficheroExcel.php">
<p align="center" class="tituloHead">Reporte de Custodias</p>
<table id="Exportar_a_Excel" align="center" class="filaPar" width="700" >
<tr>
<td class="titulosTabla" align="center">Unidad</td>
<td align="center" class="titulosTabla">area</td>