<?php
   $target='orden';
   include("funciones/funciones_backup.php");   
   include("conexion/conexion.php");
   include("Menu/menu_inicio.php");  
   include("Ordenes/ordenes.php"); 
   
   $nombrepagina = "CREACION DE ORDENES DE SERVICIO";
   encabezado($target); 
   $user=$_SESSION['validar'];
   $filas=1;   
   if($filas == 1){ 
		class llamado{
			var $menuObj;
	      	function validar1($id_user,$id_sucursal){
	 			$this->menuObj=new menu_inicio();
				$this->menuObj->menu2($id_user,$id_sucursal);
	  	  	}
	 	}
		$llamadoObj=new llamado();
	 	$llamadoObj->validar1($_GET['id_user'],$_GET['suc']);
	 	entrada($user,$_GET['id_user'],$_GET['suc']);
	 	echo"</td>";	 
	 	echo"<td width=79% background=\"imagenes/bg3.jpg\" valign=top>";
	 	mostrar_cabeza_trabajo($nombrepagina);	 
?>
<script type="text/javascript">
function calcular(frm) {
  n1 = parseFloat(frm.tu.value);
  n2 = parseFloat(frm.tn.value);
  n3 = parseFloat(frm.ti.value);
  n4 = parseFloat(frm.tp.value);
  if(isNaN(n1)) n1=0;
  if(isNaN(n2)) n2=0;
  if(isNaN(n3)) n3=0;
  if(isNaN(n3)) n4=0;
  frm.tg.value = n1 + n2 + n3 + n4;
}
</script>
<CENTER>
<form action="" method="POST" name="backup">
<table width="300" border="0" class="primaria">
<tr class=miTable_tr>
<td colspan="2" class=miTable_th1><div align="center">..:: Creacion Ordenes de Servicio ::..</div></td>
</tr>
<tr class="miTable_tr">
<td width="180" valign=top height="42" class=miTable_td2>
No Orden:</td>
<td width="150" valign=top height="42" class="miTable_td">
<input type="text" name="orden" class="inputbox" size="25">
<input type="hidden" name="id" value="<? echo $_GET['id_user'];?>" class="inputbox" size="25">
</td>
</tr>
<tr class="miTable_tr">
<td width="180" class="miTable_td2">
Cliente:</td>
<td width="150" class="miTable_td">
<select name="cliente" class="inputbox">
<?
get_cliente($_GET['suc']);
?>
</select>
</td>
</tr>
<tr class="miTable_tr">
<td width="180" valign=top height="42" class=miTable_td2>
Producto:</td>
<td width="150" valign=top height="42" class="miTable_td">
<input type="text" name="producto" class="inputbox" size="25">
</td>
</tr>
<tr class="miTable_tr">
<td width="180" valign=top height="42" class=miTable_td>
Total Urbano:</td>
<td width="150" valign=top height="42" class="miTable_td">
<input type="text" name="tu" value="0" class="inputbox" size="10" onkeyup="calcular(this.form)">
</td>
</tr>
<tr class="miTable_tr">
<td width="180" class="miTable_td">
Total Nacional:</td>
<td width="150" class="miTable_td">
<input type="text" name="tn" value="0" class="inputbox" size="10" onkeyup="calcular(this.form)">
</td>
</tr>
<tr class="miTable_tr">
<td width="180" class="miTable_td">
Total Internacional:</td>
<td width="150" class="miTable_td">
<input type="text" name="ti" value="0" class="inputbox" size="10" onkeyup="calcular(this.form)">
</td>
</tr>
<tr class="miTable_tr">
<td width="180" class="miTable_td">
Total Poblaciones:</td>
<td width="150" class="miTable_td">
<input type="text" name="tp" value="0" class="inputbox" size="10" onkeyup="calcular(this.form)">
</td>
</tr>
<tr class="miTable_tr">
<td width="180" class="miTable_td">
Total General:</td>
<td width="150" class="miTable_td">
<input type="text" name="tg" value="0" class="inputbox" size="10">
</td>
</tr>
<tr class="miTable_tr">
<td width="180" class="miTable_td">
Cantidad Reportada:</td>
<td width="150" class="miTable_td">
<input type="text" name="crep" class="inputbox" size="10">
</td>
</tr>
<tr class="miTable_tr">
<td width="180" class="miTable_td">
Base de Datos:</td>
<td width="150" class="miTable_td">
<input type="checkbox" name="bd" value="1" class="inputbox">
</td>
</tr>
<tr class="miTable_tr">
<td width="180" class="miTable_td">
Impresion:</td>
<td width="150" class="miTable_td">
<input type="checkbox" name="imp" value="1" class="inputbox">
</td>
</tr>
<tr class="miTable_tr">
<td width="180" class="miTable_td">
Empaque:</td>
<td width="150" class="miTable_td">
<input type="checkbox" name="emp" value="1" class="inputbox">
</td>
</tr>
<tr class="miTable_tr">
<td width="180" class="miTable_td">
Labels:</td>
<td width="150" class="miTable_td">
<input type="checkbox" name="lab" value="1" class="inputbox">
</td>
</tr>
<tr class="miTable_tr">
<td width="180" class="miTable_td">
Bolsa:</td>
<td width="150" class="miTable_td">
<input type="checkbox" name="bol" value="1" class="inputbox">
</td>
</tr>
<tr class="miTable_tr">
<td width="180" class="miTable_td">
Otros:</td>
<td width="150" class="miTable_td">
<input type="checkbox" name="otr" value="1" class="inputbox">
</td>
</tr>
<tr class="miTable_tr">
<td width="180" class="miTable_td">
Observaciones:</td>
<td width="150" class="miTable_td">
<input type="text" name="observ" class="inputbox" size="25">
</td>
</tr>
<tr class="miTable_tr">
<td width="180" class="miTable_td">
Peso:</td>
<td width="150" class="miTable_td">
<input type="text" name="peso" class="inputbox" size="15">
</td>
</tr>
<tr class="miTable_tr">
<td width="180" class="miTable_td">
Valor:</td>
<td width="150" class="miTable_td">
<input type="text" name="val" class="inputbox" size="15">
</td>
</tr>
<tr class="miTable_tr">
<td width="180" class="miTable_td">
Sucursal:</td>
<td width="150" class="miTable_td">
<?
get_sucursal($_SESSION['perfil'],$_GET['suc']);
?>
</td>
</tr>
<tr class=miTable_tr>
<td class=miTable_th1 colspan="2">
<div align="center">
<input type="submit" name="Registrar" value="Registrar" class="inputbox">
</div>
</td>
</tr>
</table>
</form>
</CENTER>
	 <?
	 if(!isset($Registrar)){

     }else{
		class crearSucursal{
	  		var $crearObj;
	  		var $conexionObj;
	  		var $estado;
	  		function setCrear($orden,$prod,$crep,$tn,$tu,$ti,$tp,$tg,$bd,$imp,$emp,$lab,$bol,$otr,$observ,$suc,$id,$cliente,$peso,$val){
	  			$id_user=$_GET['id_user'];
			 	$id_suc=$_GET['suc'];
			 	if($orden=='' || $prod=='' || $suc=='' || $cliente==''){
			 		$msgBOX2 = "Algunos Campos Requeridos Estan Vacios.";
	  		    	echo "<script>
					setTimeout(location.href='crear_orden.php?id_user=$id_user&suc=$id_suc', 100);
	            	alert('$msgBOX2');
	  		  		</script>";
			 	}else{
	  		 		$this->crearObj=new ordenes();
	  		 		$this->crearObj->setOrden($orden);
			 		$this->crearObj->setProducto($prod);
			 		$this->crearObj->setCrep($crep);
			 		$this->crearObj->setTn($tn);
			 		$this->crearObj->setTu($tu);
			 		$this->crearObj->setTi($ti);
			 		$this->crearObj->setTp($tp);
			 		$this->crearObj->setTg($tg);
			 		$this->crearObj->setBd($bd);
			 		$this->crearObj->setImp($imp);
			 		$this->crearObj->setEmp($emp);
			 		$this->crearObj->setLab($lab);
			 		$this->crearObj->setBol($bol);
			 		$this->crearObj->setOtr($otr);
			 		$this->crearObj->setObserv($observ);
			 		$this->crearObj->setSuc($suc);
			 		$this->crearObj->setId_user($id);
			 		$this->crearObj->setCliente($cliente);
			 		$this->crearObj->setPeso($peso);
			 		$this->crearObj->setVal($val);
			    }     
	  		}
			function getCrear(){
		    	return $this->crearObj;
			}
			function validar(){
				$this->conexionObj= new conexion();
				$this->conexionObj->conectarse();
				$rst_validar=$this->conexionObj->consultar("SELECT * FROM ordenes WHERE orden='".$this->crearObj->getOrden()."'");
				if(mysql_num_rows($rst_validar)>=1){
					$msgBOX2 = "Orden Existe en Sistema.";
	  		    	echo "<script>
	             	  alert('$msgBOX2');
	  		  	      </script>";
				}else{
					$orden=$this->crearObj->getOrden();
					$prod=$this->crearObj->getProducto();
					$crep=$this->crearObj->getCrep();
					$tu=$this->crearObj->getTu();
					$tn=$this->crearObj->getTn();
					$ti=$this->crearObj->getTi();
					$tp=$this->crearObj->getTp();
					$tg=$this->crearObj->getTg();
					$bd=$this->crearObj->getBd();
					$imp=$this->crearObj->getImp();
					$emp=$this->crearObj->getEmp();
					$lab=$this->crearObj->getLab();
					$bol=$this->crearObj->getBol();
					$otr=$this->crearObj->getOtr();
					$observ=$this->crearObj->getObserv();
					$suc=$this->crearObj->getSuc();
					$id=$this->crearObj->getId_user();
					$cliente=$this->crearObj->getCliente();
					$peso=$this->crearObj->getPeso();
					$val=$this->crearObj->getVal();
					$this->insertarDatos($orden,$prod,$crep,$tn,$tu,$ti,$tp,$tg,$bd,$imp,$emp,$lab,$bol,$otr,$observ,$suc,$id,$cliente,$peso,$val);
			    }
	       }
		   function insertarDatos($orden,$prod,$crep,$tn,$tu,$ti,$tp,$tg,$bd,$imp,$emp,$lab,$bol,$otr,$observ,$suc,$id,$cliente,$peso,$val){
	 	   		$rst_insertar=$this->conexionObj->modificar("INSERT INTO ordenes VALUES (NULL,'".$orden."', current_date(), current_time(),'".$prod."','".$crep."','".$tn."','".$tu."','".$ti."','".$tp."','".$tg."','".$bd."','".$imp."','".$emp."','".$lab."','".$bol."','".$otr."','".$observ."',NULL,NULL,NULL,0,0,NULL,NULL,'".$suc."','".$id."','".$cliente."','".$peso."','".$val."',1,1,0,0)");

				$affected_rows=mysql_affected_rows();
				if($affected_rows>=1){
			    	$msgBOX2 = "Orden Creada Exitosamente.";
	  		    	echo "<script>
	             	  alert('$msgBOX2');
	  		  	      </script>";
				}else{
			    	$msgBOX2 = "Orden No Pudo ser Creada.";
	  		    	echo "<script>
	             	  alert('$msgBOX2');
	  		  	      </script>";
				}
		   }
	
}// FIN DE LA CLASE CREARUSUARIO
// CREACION DEL OBJETO
$crearSucursalObj=new crearSucursal();
// CONFIGURANDO LAS PROPIEDADES DEL OBJETO
$crearSucursalObj->setCrear($_POST['orden'],$_POST['producto'],$_POST['crep'],$_POST['tn'],$_POST['tu'],$_POST['ti'],$_POST['tp'],$_POST['tg'],$_POST['bd'],$_POST['imp'],$_POST['emp'],$_POST['lab'],$_POST['bol'],$_POST['otr'],$_POST['observ'],$_POST['sucursal'],$_POST['id'],$_POST['cliente'],$_POST['peso'],$_POST['val']);
// LAMANDO EL METODO DE NEGOCIO
$crearSucursalObj->validar();

}

 mostrar_pie();
} 
	echo"</td>";
	echo"</tr>";   
	echo"</table>";     
	echo"<table width=503 border=0 align=center cellpadding=0 cellspacing=0>";
	echo"<tbody><tr>";
	echo"<td></td>";
	echo"</tr>";
	echo"<tr>";
	echo"<td height=7 background=imagenes/lineas_pie.jpg><img src=index2_files/spacer.html width=1 height=15></td>";
	echo"</tr>";
	echo"<tr>";
?>
<td>
<center>
<?
        pie_de_pagina();
        ?>
</center>
</td>
<?php
	echo"</tr>";
	echo"</tbody></table>";
	echo"</center>";
	echo"</body>";
	echo"</html>";
?>