<?php
//include "clase.conexion.php";
class clsRegistroCompras extends clsConexion{
	public $varTitulo = "PROCESAR PRECIO PROMEDIO DE COMPRA";
	public $varMyTabla  = "_sv_compra";
	public $varMyID  	  = "id_compra";
	function FormuBusqueda() {
		$sqanio = "select distinct year(fecha_emision), year(fecha_emision) 
				   from _sv_compra where fecha_emision is not null 
				   order by year(fecha_emision) desc;";
		$sqlmes = "call spQuery_ComboMes_Compra('$_POST[anio]');";

		$varTabla=array("id"=>"tabla", "name"=>"table", "tamano"=>"400", "clase"=>"Formtitulo", "titulo"=>$this->varTitulo,
						"formu"=>array("id"=>"form", "name"=>"form", "metodo"=>"POST", "onsubmit"=>"return false;"),						
						"ocult"=>array(array("tipo"=>"oculto", "id"=>"titu", "name"=>"titu", "valor"=>$this->varTitulo)
									  ),
						"conte"=>array(array("titulo"=>"Periodo :", "clase1"=>"FormCampo1", "clase2"=>"interior",
										     "campo"=>array("tipo"=>"varios",
														    "contenido"=>array(array("tipo"=>"select", "id"=>"anio", "name"=>"anio", "valor"=>NULL,
																				     "combo"=>array("sql"=>$sqanio, "sincod"=>"SI", 
																					 "titulo"=>"--[[ANIO]]--", "ancho"=>"83", 
																					 "reload"=>"xajax_comboMesGeneraPPC(this.value)")),
																			   array("tipo"=>"select", "id"=>"mes", "name"=>"mes", "valor"=>NULL, 
																			   		 "div"=>"divMes",
																				     "combo"=>array("sql"=>$sqlmes, "titulo"=>"--[[ MES ]]--",
																					 "ancho"=>"160"))
																			   )
														   )
										    )
									   ),
						"boton"=>array(array("tipo"=>"submit", "id"=>"bcon", "name"=>"bcon", "ancho"=>"130", "texto"=>"Generar PPC",
					  					   "clase"=>"boton_guardar", "click"=>"javascript:xGrabarJS()")
									 )
						);
		return $this->setTablaForm($varTabla);
		}
 			
	function ProcesoGrabar($varForm = NULL) {
		$varUsr = (isset($_SESSION["_CUSE"]))?$_SESSION["_CUSE"]:1;
		$varAni = (isset($varForm["anio"]) && $varForm["tdoc1"]<>"Ninguno")?"'".$varForm["anio"]."'":"NULL";
		$varMes = (isset($varForm["mes"]) && $varForm["mes"]<>"Ninguno")?"'".$varForm["mes"]."'":"NULL";
	
		$sql = "call spGenera_Precio_Promedio_Compra($varAni, $varMes, $varUsr);";
		$this->AbrirConexion();
		$rs = $this->Query($sql);
		$this->CerrarConexion();
		return "OK";
		}	
	}
?>